ia64/xen-unstable

changeset 11917:e256d8ccd6ac

[HVM] Fix oprofile for HVM guests.

Signed-off-by: Tom Woller <thomas.woller@amd.com>
Signed-off-by: Mats Petersson <mats.petersson@amd.com>
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Fri Oct 20 10:34:24 2006 +0100 (2006-10-20)
parents 899836e04387
children 6677b97612a2
files xen/arch/x86/hvm/svm/x86_32/exits.S xen/arch/x86/hvm/svm/x86_64/exits.S xen/arch/x86/oprofile/op_model_athlon.c xen/arch/x86/oprofile/op_model_p4.c xen/arch/x86/oprofile/op_model_ppro.c xen/arch/x86/oprofile/xenoprof.c
line diff
     1.1 --- a/xen/arch/x86/hvm/svm/x86_32/exits.S	Fri Oct 20 10:11:45 2006 +0100
     1.2 +++ b/xen/arch/x86/hvm/svm/x86_32/exits.S	Fri Oct 20 10:34:24 2006 +0100
     1.3 @@ -126,6 +126,8 @@ ENTRY(svm_asm_do_launch)
     1.4  
     1.5          HVM_SAVE_ALL_NOSEGREGS
     1.6          STGI
     1.7 +.globl svm_stgi_label;
     1.8 +svm_stgi_label:
     1.9          movl %esp,%eax
    1.10          push %eax
    1.11          call svm_vmexit_handler
     2.1 --- a/xen/arch/x86/hvm/svm/x86_64/exits.S	Fri Oct 20 10:11:45 2006 +0100
     2.2 +++ b/xen/arch/x86/hvm/svm/x86_64/exits.S	Fri Oct 20 10:34:24 2006 +0100
     2.3 @@ -144,6 +144,8 @@ ENTRY(svm_asm_do_launch)
     2.4          VMLOAD
     2.5  
     2.6          STGI
     2.7 +.globl svm_stgi_label;
     2.8 +svm_stgi_label:
     2.9          movq %rsp,%rdi
    2.10          call svm_vmexit_handler
    2.11          jmp  svm_asm_do_resume
     3.1 --- a/xen/arch/x86/oprofile/op_model_athlon.c	Fri Oct 20 10:11:45 2006 +0100
     3.2 +++ b/xen/arch/x86/oprofile/op_model_athlon.c	Fri Oct 20 10:34:24 2006 +0100
     3.3 @@ -18,6 +18,7 @@
     3.4  #include <xen/sched.h>
     3.5  #include <asm/regs.h>
     3.6  #include <asm/current.h>
     3.7 +#include <asm/hvm/support.h>
     3.8   
     3.9  #include "op_x86_model.h"
    3.10  #include "op_counter.h"
    3.11 @@ -44,7 +45,11 @@ static unsigned long reset_value[NUM_COU
    3.12  
    3.13  extern void xenoprof_log_event(struct vcpu *v, unsigned long eip,
    3.14  			       int mode, int event);
    3.15 - 
    3.16 +extern int xenoprofile_get_mode(struct vcpu *v,
    3.17 +				struct cpu_user_regs * const regs);
    3.18 +
    3.19 +extern char svm_stgi_label[];
    3.20 +
    3.21  static void athlon_fill_in_addresses(struct op_msrs * const msrs)
    3.22  {
    3.23  	msrs->counters[0].addr = MSR_K7_PERFCTR0;
    3.24 @@ -97,10 +102,9 @@ static void athlon_setup_ctrs(struct op_
    3.25  	}
    3.26  }
    3.27  
    3.28 - 
    3.29  static int athlon_check_ctrs(unsigned int const cpu,
    3.30 -                             struct op_msrs const * const msrs,
    3.31 -                             struct cpu_user_regs * const regs)
    3.32 +			     struct op_msrs const * const msrs,
    3.33 +			     struct cpu_user_regs * const regs)
    3.34  
    3.35  {
    3.36  	unsigned int low, high;
    3.37 @@ -108,11 +112,19 @@ static int athlon_check_ctrs(unsigned in
    3.38  	int ovf = 0;
    3.39  	unsigned long eip = regs->eip;
    3.40  	int mode = 0;
    3.41 +	struct vcpu *v = current;
    3.42 +	struct cpu_user_regs tmp_regs;
    3.43  
    3.44 -	if (guest_kernel_mode(current, regs))
    3.45 -		mode = 1;
    3.46 -	else if (ring_0(regs))
    3.47 -		mode = 2;
    3.48 +	if (!guest_mode(regs) &&
    3.49 +	    (regs->eip == (unsigned long)svm_stgi_label)) {
    3.50 +		/* SVM guest was running when NMI occurred */
    3.51 +		hvm_store_cpu_guest_regs(v, &tmp_regs, NULL);
    3.52 +		eip = tmp_regs.eip;
    3.53 +		mode = xenoprofile_get_mode(v, &tmp_regs);
    3.54 +	} else {
    3.55 +		eip = regs->eip;
    3.56 +		mode = xenoprofile_get_mode(v, regs);
    3.57 +	}
    3.58  
    3.59  	for (i = 0 ; i < NUM_COUNTERS; ++i) {
    3.60  		CTR_READ(low, high, msrs, i);
     4.1 --- a/xen/arch/x86/oprofile/op_model_p4.c	Fri Oct 20 10:11:45 2006 +0100
     4.2 +++ b/xen/arch/x86/oprofile/op_model_p4.c	Fri Oct 20 10:34:24 2006 +0100
     4.3 @@ -620,9 +620,10 @@ static void p4_setup_ctrs(struct op_msrs
     4.4  	}
     4.5  }
     4.6  
     4.7 -
     4.8  extern void xenoprof_log_event(struct vcpu *v, unsigned long eip,
     4.9  			       int mode, int event);
    4.10 +extern int xenoprofile_get_mode(struct vcpu *v,
    4.11 +				struct cpu_user_regs * const regs);
    4.12  
    4.13  static int p4_check_ctrs(unsigned int const cpu,
    4.14                           struct op_msrs const * const msrs,
    4.15 @@ -632,12 +633,7 @@ static int p4_check_ctrs(unsigned int co
    4.16  	int i;
    4.17  	int ovf = 0;
    4.18  	unsigned long eip = regs->eip;
    4.19 -	int mode = 0;
    4.20 -
    4.21 -	if (guest_kernel_mode(current, regs))
    4.22 -		mode = 1;
    4.23 -	else if (ring_0(regs))
    4.24 -		mode = 2;
    4.25 +	int mode = xenoprofile_get_mode(current, regs);
    4.26  
    4.27  	stag = get_stagger();
    4.28  
     5.1 --- a/xen/arch/x86/oprofile/op_model_ppro.c	Fri Oct 20 10:11:45 2006 +0100
     5.2 +++ b/xen/arch/x86/oprofile/op_model_ppro.c	Fri Oct 20 10:34:24 2006 +0100
     5.3 @@ -88,9 +88,10 @@ static void ppro_setup_ctrs(struct op_ms
     5.4  	}
     5.5  }
     5.6  
     5.7 -
     5.8  extern void xenoprof_log_event(struct vcpu *v, unsigned long eip,
     5.9  			       int mode, int event);
    5.10 +extern int xenoprofile_get_mode(struct vcpu *v,
    5.11 +				struct cpu_user_regs * const regs);
    5.12   
    5.13  static int ppro_check_ctrs(unsigned int const cpu,
    5.14                             struct op_msrs const * const msrs,
    5.15 @@ -100,13 +101,8 @@ static int ppro_check_ctrs(unsigned int 
    5.16  	int i;
    5.17  	int ovf = 0;
    5.18  	unsigned long eip = regs->eip;
    5.19 -	int mode = 0;
    5.20 +	int mode = xenoprofile_get_mode(current, regs);
    5.21  
    5.22 -	if ( guest_kernel_mode(current, regs) ) 
    5.23 -		mode = 1;
    5.24 -	else if ( ring_0(regs) )
    5.25 -		mode = 2;
    5.26 - 
    5.27  	for (i = 0 ; i < NUM_COUNTERS; ++i) {
    5.28  		CTR_READ(low, high, msrs, i);
    5.29  		if (CTR_OVERFLOWED(low)) {
     6.1 --- a/xen/arch/x86/oprofile/xenoprof.c	Fri Oct 20 10:11:45 2006 +0100
     6.2 +++ b/xen/arch/x86/oprofile/xenoprof.c	Fri Oct 20 10:34:24 2006 +0100
     6.3 @@ -7,6 +7,7 @@
     6.4  #include <xen/guest_access.h>
     6.5  #include <xen/sched.h>
     6.6  #include <public/xenoprof.h>
     6.7 +#include <asm/hvm/support.h>
     6.8  
     6.9  #include "op_counter.h"
    6.10  
    6.11 @@ -98,7 +99,7 @@ static void xenoprof_reset_buf(struct do
    6.12      }
    6.13  }
    6.14  
    6.15 -char *alloc_xenoprof_buf(struct domain *d, int npages)
    6.16 +static char *alloc_xenoprof_buf(struct domain *d, int npages)
    6.17  {
    6.18      char *rawbuf;
    6.19      int i, order;
    6.20 @@ -121,7 +122,8 @@ char *alloc_xenoprof_buf(struct domain *
    6.21      return rawbuf;
    6.22  }
    6.23  
    6.24 -int alloc_xenoprof_struct(struct domain *d, int max_samples, int is_passive)
    6.25 +static int alloc_xenoprof_struct(
    6.26 +    struct domain *d, int max_samples, int is_passive)
    6.27  {
    6.28      struct vcpu *v;
    6.29      int nvcpu, npages, bufsize, max_bufsize;
    6.30 @@ -207,7 +209,7 @@ void free_xenoprof_pages(struct domain *
    6.31      d->xenoprof = NULL;
    6.32  }
    6.33  
    6.34 -int active_index(struct domain *d)
    6.35 +static int active_index(struct domain *d)
    6.36  {
    6.37      int i;
    6.38  
    6.39 @@ -218,7 +220,7 @@ int active_index(struct domain *d)
    6.40      return -1;
    6.41  }
    6.42  
    6.43 -int set_active(struct domain *d)
    6.44 +static int set_active(struct domain *d)
    6.45  {
    6.46      int ind;
    6.47      struct xenoprof *x;
    6.48 @@ -239,7 +241,7 @@ int set_active(struct domain *d)
    6.49      return 0;
    6.50  }
    6.51  
    6.52 -int reset_active(struct domain *d)
    6.53 +static int reset_active(struct domain *d)
    6.54  {
    6.55      int ind;
    6.56      struct xenoprof *x;
    6.57 @@ -265,7 +267,7 @@ int reset_active(struct domain *d)
    6.58      return 0;
    6.59  }
    6.60  
    6.61 -void reset_passive(struct domain *d)
    6.62 +static void reset_passive(struct domain *d)
    6.63  {
    6.64      struct xenoprof *x;
    6.65  
    6.66 @@ -281,7 +283,7 @@ void reset_passive(struct domain *d)
    6.67      return;
    6.68  }
    6.69  
    6.70 -void reset_active_list(void)
    6.71 +static void reset_active_list(void)
    6.72  {
    6.73      int i;
    6.74  
    6.75 @@ -297,7 +299,7 @@ void reset_active_list(void)
    6.76      activated = 0;
    6.77  }
    6.78  
    6.79 -void reset_passive_list(void)
    6.80 +static void reset_passive_list(void)
    6.81  {
    6.82      int i;
    6.83  
    6.84 @@ -311,7 +313,7 @@ void reset_passive_list(void)
    6.85      pdomains = 0;
    6.86  }
    6.87  
    6.88 -int add_active_list (domid_t domid)
    6.89 +static int add_active_list(domid_t domid)
    6.90  {
    6.91      struct domain *d;
    6.92  
    6.93 @@ -329,7 +331,7 @@ int add_active_list (domid_t domid)
    6.94      return 0;
    6.95  }
    6.96  
    6.97 -int add_passive_list(XEN_GUEST_HANDLE(void) arg)
    6.98 +static int add_passive_list(XEN_GUEST_HANDLE(void) arg)
    6.99  {
   6.100      struct xenoprof_passive passive;
   6.101      struct domain *d;
   6.102 @@ -436,7 +438,7 @@ void xenoprof_log_event(
   6.103      }
   6.104  }
   6.105  
   6.106 -int xenoprof_op_init(XEN_GUEST_HANDLE(void) arg)
   6.107 +static int xenoprof_op_init(XEN_GUEST_HANDLE(void) arg)
   6.108  {
   6.109      struct xenoprof_init xenoprof_init;
   6.110      int ret;
   6.111 @@ -458,7 +460,7 @@ int xenoprof_op_init(XEN_GUEST_HANDLE(vo
   6.112      return 0;
   6.113  }
   6.114  
   6.115 -int xenoprof_op_get_buffer(XEN_GUEST_HANDLE(void) arg)
   6.116 +static int xenoprof_op_get_buffer(XEN_GUEST_HANDLE(void) arg)
   6.117  {
   6.118      struct xenoprof_get_buffer xenoprof_get_buffer;
   6.119      struct domain *d = current->domain;
   6.120 @@ -694,6 +696,17 @@ int do_xenoprof_op(int op, XEN_GUEST_HAN
   6.121      return ret;
   6.122  }
   6.123  
   6.124 +int xenoprofile_get_mode(struct vcpu *v, struct cpu_user_regs * const regs)
   6.125 +{
   6.126 +    if ( !guest_mode(regs) )
   6.127 +        return 2;
   6.128 +
   6.129 +    if ( hvm_guest(v) )
   6.130 +        return ((regs->cs & 3) != 3);
   6.131 +
   6.132 +    return guest_kernel_mode(v, regs);  
   6.133 +}
   6.134 +
   6.135  /*
   6.136   * Local variables:
   6.137   * mode: C