ia64/xen-unstable

changeset 6553:277025502616

Tracing hooks for VMX domains

The low level asm instrumentation is needed to get precise TSC counts.
trace=n should have precisely 0 overhead because of this patch.

Signed-off-by: Yunfeng Zhai <yunfeng.zhao@intel.com>
Signed-off-by: Arun Sharma <arun.sharma@intel.com>
author adsharma@los-vmm.sc.intel.com
date Thu Aug 25 13:27:03 2005 -0700 (2005-08-25)
parents a9873d384da4
children de3576a1c62c
files tools/xentrace/formats xen/arch/x86/vmx.c xen/arch/x86/x86_32/entry.S xen/include/public/trace.h
line diff
     1.1 --- a/tools/xentrace/formats	Thu Aug 25 12:24:48 2005 -0700
     1.2 +++ b/tools/xentrace/formats	Thu Aug 25 13:27:03 2005 -0700
     1.3 @@ -15,3 +15,7 @@ 0x0002000d	CPU%(cpu)d	%(tsc)d		dom_timer
     1.4  0x00080001	CPU%(cpu)d      %(tsc)d		VMX_VMEXIT		[ domid = 0x%(1)08x, eip = 0x%(2)08x, reason = 0x%(3)08x ]
     1.5  0x00080002	CPU%(cpu)d      %(tsc)d		VMX_VECTOR		[ domid = 0x%(1)08x, eip = 0x%(2)08x, vector = 0x%(3)08x ]
     1.6  0x00080003	CPU%(cpu)d      %(tsc)d		VMX_INT			[ domid = 0x%(1)08x, trap = 0x%(2)08x, va = 0x%(3)08x ]
     1.7 +
     1.8 +0x00090001      CPU%(cpu)d      %(tsc)d         VMENTRY                 0x%(1)08x 0x%(2)08x 0x%(3)08x 0x%(4)08x 0x%(5)08x
     1.9 +0x00090002      CPU%(cpu)d      %(tsc)d         VMEXIT                  0x%(1)08x 0x%(2)08x 0x%(3)08x 
    1.10 +
     2.1 --- a/xen/arch/x86/vmx.c	Thu Aug 25 12:24:48 2005 -0700
     2.2 +++ b/xen/arch/x86/vmx.c	Thu Aug 25 13:27:03 2005 -0700
     2.3 @@ -50,6 +50,13 @@ int vmcs_size;
     2.4  unsigned int opt_vmx_debug_level = 0;
     2.5  integer_param("vmx_debug", opt_vmx_debug_level);
     2.6  
     2.7 +#ifdef TRACE_BUFFER
     2.8 +static unsigned long trace_values[NR_CPUS][4];
     2.9 +#define TRACE_VMEXIT(index,value) trace_values[current->processor][index]=value
    2.10 +#else
    2.11 +#define TRACE_VMEXIT(index,value) ((void)0)
    2.12 +#endif
    2.13 +
    2.14  #ifdef __x86_64__
    2.15  static struct msr_state percpu_msr[NR_CPUS];
    2.16  
    2.17 @@ -381,6 +388,7 @@ static int vmx_do_page_fault(unsigned lo
    2.18  
    2.19      if (!vmx_paging_enabled(current)){
    2.20          handle_mmio(va, va);
    2.21 +        TRACE_VMEXIT (2,2);
    2.22          return 1;
    2.23      }
    2.24      gpa = gva_to_gpa(va);
    2.25 @@ -393,12 +401,13 @@ static int vmx_do_page_fault(unsigned lo
    2.26              __update_guest_eip(inst_len);
    2.27              return 1;
    2.28          }
    2.29 +        TRACE_VMEXIT (2,2);
    2.30          handle_mmio(va, gpa);
    2.31          return 1;
    2.32      }
    2.33  
    2.34      result = shadow_fault(va, regs);
    2.35 -
    2.36 +    TRACE_VMEXIT (2,result);
    2.37  #if 0
    2.38      if ( !result )
    2.39      {
    2.40 @@ -608,6 +617,7 @@ static void vmx_io_instruction(struct cp
    2.41          addr = (exit_qualification >> 16) & (0xffff);
    2.42      else
    2.43          addr = regs->edx & 0xffff;
    2.44 +    TRACE_VMEXIT (2,addr);
    2.45  
    2.46      vio = get_vio(d->domain, d->vcpu_id);
    2.47      if (vio == 0) {
    2.48 @@ -1282,13 +1292,20 @@ static int vmx_cr_access(unsigned long e
    2.49      case TYPE_MOV_TO_CR:
    2.50          gp = exit_qualification & CONTROL_REG_ACCESS_REG;
    2.51          cr = exit_qualification & CONTROL_REG_ACCESS_NUM;
    2.52 +        TRACE_VMEXIT(1,TYPE_MOV_TO_CR);
    2.53 +        TRACE_VMEXIT(2,cr);
    2.54 +        TRACE_VMEXIT(3,gp);
    2.55          return mov_to_cr(gp, cr, regs);
    2.56      case TYPE_MOV_FROM_CR:
    2.57          gp = exit_qualification & CONTROL_REG_ACCESS_REG;
    2.58          cr = exit_qualification & CONTROL_REG_ACCESS_NUM;
    2.59 +        TRACE_VMEXIT(1,TYPE_MOV_FROM_CR);
    2.60 +        TRACE_VMEXIT(2,cr);
    2.61 +        TRACE_VMEXIT(3,gp);
    2.62          mov_from_cr(cr, gp, regs);
    2.63          break;
    2.64      case TYPE_CLTS:
    2.65 +        TRACE_VMEXIT(1,TYPE_CLTS);
    2.66          clts();
    2.67          setup_fpu(current);
    2.68  
    2.69 @@ -1301,6 +1318,7 @@ static int vmx_cr_access(unsigned long e
    2.70          __vmwrite(CR0_READ_SHADOW, value);
    2.71          break;
    2.72      case TYPE_LMSW:
    2.73 +        TRACE_VMEXIT(1,TYPE_LMSW);
    2.74          __vmread(CR0_READ_SHADOW, &value);
    2.75  	value = (value & ~0xF) |
    2.76  		(((exit_qualification & LMSW_SOURCE_DATA) >> 16) & 0xF);
    2.77 @@ -1544,6 +1562,7 @@ asmlinkage void vmx_vmexit_handler(struc
    2.78  
    2.79      __vmread(GUEST_RIP, &eip);
    2.80      TRACE_3D(TRC_VMX_VMEXIT, v->domain->domain_id, eip, exit_reason);
    2.81 +    TRACE_VMEXIT(0,exit_reason);
    2.82  
    2.83      switch (exit_reason) {
    2.84      case EXIT_REASON_EXCEPTION_NMI:
    2.85 @@ -1562,6 +1581,7 @@ asmlinkage void vmx_vmexit_handler(struc
    2.86              __vmx_bug(&regs);
    2.87          vector &= 0xff;
    2.88  
    2.89 +	 TRACE_VMEXIT(1,vector);
    2.90          perfc_incra(cause_vector, vector);
    2.91  
    2.92          TRACE_3D(TRC_VMX_VECTOR, v->domain->domain_id, eip, vector);
    2.93 @@ -1606,6 +1626,10 @@ asmlinkage void vmx_vmexit_handler(struc
    2.94          {
    2.95              __vmread(EXIT_QUALIFICATION, &va);
    2.96              __vmread(VM_EXIT_INTR_ERROR_CODE, &regs.error_code);
    2.97 +            
    2.98 +	    TRACE_VMEXIT(3,regs.error_code);
    2.99 +	    TRACE_VMEXIT(4,va);
   2.100 +
   2.101              VMX_DBG_LOG(DBG_LEVEL_VMMU, 
   2.102                          "eax=%lx, ebx=%lx, ecx=%lx, edx=%lx, esi=%lx, edi=%lx",
   2.103                          (unsigned long)regs.eax, (unsigned long)regs.ebx,
   2.104 @@ -1680,6 +1704,8 @@ asmlinkage void vmx_vmexit_handler(struc
   2.105                  eip, inst_len, exit_qualification);
   2.106          if (vmx_cr_access(exit_qualification, &regs))
   2.107  	    __update_guest_eip(inst_len);
   2.108 +	 TRACE_VMEXIT(3,regs.error_code);
   2.109 +        TRACE_VMEXIT(4,exit_qualification);
   2.110          break;
   2.111      }
   2.112      case EXIT_REASON_DR_ACCESS:
   2.113 @@ -1692,6 +1718,7 @@ asmlinkage void vmx_vmexit_handler(struc
   2.114          __vmread(EXIT_QUALIFICATION, &exit_qualification);
   2.115          __get_instruction_length(inst_len);
   2.116          vmx_io_instruction(&regs, exit_qualification, inst_len);
   2.117 +        TRACE_VMEXIT(4,exit_qualification);
   2.118          break;
   2.119      case EXIT_REASON_MSR_READ:
   2.120          __get_instruction_length(inst_len);
   2.121 @@ -1726,6 +1753,25 @@ asmlinkage void load_cr2(void)
   2.122  #endif
   2.123  }
   2.124  
   2.125 +#ifdef TRACE_BUFFER
   2.126 +asmlinkage void trace_vmentry (void)
   2.127 +{
   2.128 +    TRACE_5D(TRC_VMENTRY,trace_values[current->processor][0],
   2.129 +          trace_values[current->processor][1],trace_values[current->processor][2],
   2.130 +          trace_values[current->processor][3],trace_values[current->processor][4]);
   2.131 +    TRACE_VMEXIT(0,9);
   2.132 +    TRACE_VMEXIT(1,9);
   2.133 +    TRACE_VMEXIT(2,9);
   2.134 +    TRACE_VMEXIT(3,9);
   2.135 +    TRACE_VMEXIT(4,9);
   2.136 +    return;
   2.137 +}
   2.138 +asmlinkage void trace_vmexit (void)
   2.139 +{
   2.140 +    TRACE_3D(TRC_VMEXIT,0,0,0);
   2.141 +    return;
   2.142 +}
   2.143 +#endif 
   2.144  #endif /* CONFIG_VMX */
   2.145  
   2.146  /*
     3.1 --- a/xen/arch/x86/x86_32/entry.S	Thu Aug 25 12:24:48 2005 -0700
     3.2 +++ b/xen/arch/x86/x86_32/entry.S	Thu Aug 25 13:27:03 2005 -0700
     3.3 @@ -121,6 +121,9 @@
     3.4  ENTRY(vmx_asm_vmexit_handler)
     3.5          /* selectors are restored/saved by VMX */
     3.6          VMX_SAVE_ALL_NOSEGREGS
     3.7 +#ifdef TRACE_BUFFER
     3.8 +        call trace_vmexit
     3.9 +#endif
    3.10          call vmx_vmexit_handler
    3.11          jmp vmx_asm_do_resume
    3.12  
    3.13 @@ -142,6 +145,9 @@ 1:
    3.14  /* vmx_restore_all_guest */
    3.15          call vmx_intr_assist
    3.16          call load_cr2
    3.17 +#ifdef TRACE_BUFFER
    3.18 +        call trace_vmentry
    3.19 +#endif
    3.20          .endif
    3.21          VMX_RESTORE_ALL_NOSEGREGS
    3.22          /* 
     4.1 --- a/xen/include/public/trace.h	Thu Aug 25 12:24:48 2005 -0700
     4.2 +++ b/xen/include/public/trace.h	Thu Aug 25 13:27:03 2005 -0700
     4.3 @@ -23,7 +23,7 @@
     4.4  #define TRC_VMXTIMER 0x00082000   /* VMX timer trace           */
     4.5  #define TRC_VMXINT   0x00084000   /* VMX interrupt trace       */
     4.6  #define TRC_VMXIO    0x00088000   /* VMX io emulation trace  */
     4.7 -
     4.8 +#define TRC_VMEXIT_HANDLER    0x00090000   /* VMX handler trace  */
     4.9  
    4.10  /* Trace events per class */
    4.11  
    4.12 @@ -49,6 +49,10 @@
    4.13  
    4.14  #define TRC_VMX_INT             (TRC_VMXINT + 1)
    4.15  
    4.16 +#define TRC_VMEXIT              (TRC_VMEXIT_HANDLER + 1)
    4.17 +#define TRC_VMENTRY             (TRC_VMEXIT_HANDLER + 2)
    4.18 +
    4.19 +
    4.20  /* This structure represents a single trace buffer record. */
    4.21  struct t_rec {
    4.22      u64 cycles;               /* cycle counter timestamp */