]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
ia64/pv_ops/xen: paravirtualize read/write ar.itc and ar.itm
authorIsaku Yamahata <yamahata@valinux.co.jp>
Wed, 4 Mar 2009 12:05:39 +0000 (21:05 +0900)
committerTony Luck <tony.luck@intel.com>
Thu, 26 Mar 2009 17:50:32 +0000 (10:50 -0700)
paravirtualize ar.itc and ar.itm in order to support save/restore.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
Signed-off-by: Tony Luck <tony.luck@intel.com>
arch/ia64/include/asm/xen/inst.h
arch/ia64/include/asm/xen/interface.h
arch/ia64/include/asm/xen/minstate.h
arch/ia64/include/asm/xen/privop.h
arch/ia64/kernel/asm-offsets.c
arch/ia64/xen/xen_pv_ops.c

index e8e01b28d2ae369a917c7a5ffc4c7c7edccf9086..90537dc15efe98bc0d7886c40196ecfc4409249b 100644 (file)
 .endm
 #define MOV_FROM_PSR(pred, reg, clob)  __MOV_FROM_PSR pred, reg, clob
 
+/* assuming ar.itc is read with interrupt disabled. */
+#define MOV_FROM_ITC(pred, pred_clob, reg, clob)               \
+(pred) movl clob = XSI_ITC_OFFSET;                             \
+       ;;                                                      \
+(pred) ld8 clob = [clob];                                      \
+(pred) mov reg = ar.itc;                                       \
+       ;;                                                      \
+(pred) add reg = reg, clob;                                    \
+       ;;                                                      \
+(pred) movl clob = XSI_ITC_LAST;                               \
+       ;;                                                      \
+(pred) ld8 clob = [clob];                                      \
+       ;;                                                      \
+(pred) cmp.geu.unc pred_clob, p0 = clob, reg;                  \
+       ;;                                                      \
+(pred_clob)    add reg = 1, clob;                              \
+       ;;                                                      \
+(pred) movl clob = XSI_ITC_LAST;                               \
+       ;;                                                      \
+(pred) st8 [clob] = reg
+
 
 #define MOV_TO_IFA(reg, clob)  \
        movl clob = XSI_IFA;    \
index f00fab40854d1951b473b88ec201adee9b03a41a..e951e740bdf21514c8622f9b8ba875ada702e450 100644 (file)
@@ -209,6 +209,15 @@ struct mapped_regs {
                        unsigned long krs[8];   /* kernel registers */
                        unsigned long tmp[16];  /* temp registers
                                                   (e.g. for hyperprivops) */
+
+                       /* itc paravirtualization
+                        * vAR.ITC = mAR.ITC + itc_offset
+                        * itc_last is one which was lastly passed to
+                        * the guest OS in order to prevent it from
+                        * going backwords.
+                        */
+                       unsigned long itc_offset;
+                       unsigned long itc_last;
                };
        };
 };
index 4d92d9bbda7be19dd419107a34c08f344edfbff1..c57fa910f2c937e7473a9ea63e5ac9a7be74c86c 100644 (file)
@@ -1,3 +1,12 @@
+
+#ifdef CONFIG_VIRT_CPU_ACCOUNTING
+/* read ar.itc in advance, and use it before leaving bank 0 */
+#define XEN_ACCOUNT_GET_STAMP          \
+       MOV_FROM_ITC(pUStk, p6, r20, r2);
+#else
+#define XEN_ACCOUNT_GET_STAMP
+#endif
+
 /*
  * DO_SAVE_MIN switches to the kernel stacks (if necessary) and saves
  * the minimum state necessary that allows us to turn psr.ic back
        ;;                                                                                      \
 .mem.offset 0,0; st8.spill [r16]=r2,16;                                                                \
 .mem.offset 8,0; st8.spill [r17]=r3,16;                                                                \
-       ACCOUNT_GET_STAMP                                                                       \
+       XEN_ACCOUNT_GET_STAMP                                                                   \
        adds r2=IA64_PT_REGS_R16_OFFSET,r1;                                                     \
        ;;                                                                                      \
        EXTRA;                                                                                  \
index 71ec7546e100d5a5f549874057caead44c4809e5..2261dda578ff28f137c8390ac61fd7d8e716b96a 100644 (file)
@@ -55,6 +55,8 @@
 #define XSI_BANK1_R16                  (XSI_BASE + XSI_BANK1_R16_OFS)
 #define XSI_BANKNUM                    (XSI_BASE + XSI_BANKNUM_OFS)
 #define XSI_IHA                                (XSI_BASE + XSI_IHA_OFS)
+#define XSI_ITC_OFFSET                 (XSI_BASE + XSI_ITC_OFFSET_OFS)
+#define XSI_ITC_LAST                   (XSI_BASE + XSI_ITC_LAST_OFS)
 #endif
 
 #ifndef __ASSEMBLY__
index 742dbb1d5a4fb06cd8cfd3a2f63358b48e20535e..af56501690432110a1f27847bea9dffd60737b81 100644 (file)
@@ -316,5 +316,7 @@ void foo(void)
        DEFINE_MAPPED_REG_OFS(XSI_BANK1_R16_OFS, bank1_regs[0]);
        DEFINE_MAPPED_REG_OFS(XSI_B0NATS_OFS, vbnat);
        DEFINE_MAPPED_REG_OFS(XSI_B1NATS_OFS, vnat);
+       DEFINE_MAPPED_REG_OFS(XSI_ITC_OFFSET_OFS, itc_offset);
+       DEFINE_MAPPED_REG_OFS(XSI_ITC_LAST_OFS, itc_last);
 #endif /* CONFIG_XEN */
 }
index fe72308321b6a9fbc88b288c4a4b7f1ce83be3d9..d91336114344a1ff112d3324678a7d74e7cef81e 100644 (file)
@@ -183,6 +183,75 @@ struct pv_fsys_data xen_fsys_data __initdata = {
  * intrinsics hooks.
  */
 
+static void
+xen_set_itm_with_offset(unsigned long val)
+{
+       /* ia64_cpu_local_tick() calls this with interrupt enabled. */
+       /* WARN_ON(!irqs_disabled()); */
+       xen_set_itm(val - XEN_MAPPEDREGS->itc_offset);
+}
+
+static unsigned long
+xen_get_itm_with_offset(void)
+{
+       /* unused at this moment */
+       printk(KERN_DEBUG "%s is called.\n", __func__);
+
+       WARN_ON(!irqs_disabled());
+       return ia64_native_getreg(_IA64_REG_CR_ITM) +
+               XEN_MAPPEDREGS->itc_offset;
+}
+
+/* ia64_set_itc() is only called by
+ * cpu_init() with ia64_set_itc(0) and ia64_sync_itc().
+ * So XEN_MAPPEDRESG->itc_offset cal be considered as almost constant.
+ */
+static void
+xen_set_itc(unsigned long val)
+{
+       unsigned long mitc;
+
+       WARN_ON(!irqs_disabled());
+       mitc = ia64_native_getreg(_IA64_REG_AR_ITC);
+       XEN_MAPPEDREGS->itc_offset = val - mitc;
+       XEN_MAPPEDREGS->itc_last = val;
+}
+
+static unsigned long
+xen_get_itc(void)
+{
+       unsigned long res;
+       unsigned long itc_offset;
+       unsigned long itc_last;
+       unsigned long ret_itc_last;
+
+       itc_offset = XEN_MAPPEDREGS->itc_offset;
+       do {
+               itc_last = XEN_MAPPEDREGS->itc_last;
+               res = ia64_native_getreg(_IA64_REG_AR_ITC);
+               res += itc_offset;
+               if (itc_last >= res)
+                       res = itc_last + 1;
+               ret_itc_last = cmpxchg(&XEN_MAPPEDREGS->itc_last,
+                                      itc_last, res);
+       } while (unlikely(ret_itc_last != itc_last));
+       return res;
+
+#if 0
+       /* ia64_itc_udelay() calls ia64_get_itc() with interrupt enabled.
+          Should it be paravirtualized instead? */
+       WARN_ON(!irqs_disabled());
+       itc_offset = XEN_MAPPEDREGS->itc_offset;
+       itc_last = XEN_MAPPEDREGS->itc_last;
+       res = ia64_native_getreg(_IA64_REG_AR_ITC);
+       res += itc_offset;
+       if (itc_last >= res)
+               res = itc_last + 1;
+       XEN_MAPPEDREGS->itc_last = res;
+       return res;
+#endif
+}
+
 static void xen_setreg(int regnum, unsigned long val)
 {
        switch (regnum) {
@@ -194,11 +263,14 @@ static void xen_setreg(int regnum, unsigned long val)
                xen_set_eflag(val);
                break;
 #endif
+       case _IA64_REG_AR_ITC:
+               xen_set_itc(val);
+               break;
        case _IA64_REG_CR_TPR:
                xen_set_tpr(val);
                break;
        case _IA64_REG_CR_ITM:
-               xen_set_itm(val);
+               xen_set_itm_with_offset(val);
                break;
        case _IA64_REG_CR_EOI:
                xen_eoi(val);
@@ -222,6 +294,12 @@ static unsigned long xen_getreg(int regnum)
                res = xen_get_eflag();
                break;
 #endif
+       case _IA64_REG_AR_ITC:
+               res = xen_get_itc();
+               break;
+       case _IA64_REG_CR_ITM:
+               res = xen_get_itm_with_offset();
+               break;
        case _IA64_REG_CR_IVR:
                res = xen_get_ivr();
                break;