ia64/xen-unstable
changeset 15570:26eef8426110
xenoprof: Fix initialisation. Much can be done at boot-time, as
indicated by the fact that the low-level functiosn are marked
'__init'.
Signed-off-by: Keir Fraser <keir@xensource.com>
indicated by the fact that the low-level functiosn are marked
'__init'.
Signed-off-by: Keir Fraser <keir@xensource.com>
author | kfraser@localhost.localdomain |
---|---|
date | Tue Jul 10 15:41:26 2007 +0100 (2007-07-10) |
parents | f01cb504cf28 |
children | 1315b0901dea |
files | xen/arch/ia64/linux-xen/perfmon.c xen/arch/ia64/xen/oprofile/perfmon.c xen/arch/x86/oprofile/nmi_int.c xen/common/xenoprof.c xen/include/asm-ia64/xenoprof.h xen/include/asm-x86/xenoprof.h xen/include/xen/xenoprof.h |
line diff
1.1 --- a/xen/arch/ia64/linux-xen/perfmon.c Tue Jul 10 14:57:04 2007 +0100 1.2 +++ b/xen/arch/ia64/linux-xen/perfmon.c Tue Jul 10 15:41:26 2007 +0100 1.3 @@ -7729,7 +7729,7 @@ do_perfmon_op(unsigned long cmd, 1.4 { 1.5 unsigned long error = 0; 1.6 1.7 - if (!NONPRIV_OP(cmd) && current->domain != xenoprof_primary_profiler) { 1.8 + if (!NONPRIV_OP(cmd) && current->domain->domain_id !=0) { 1.9 gdprintk(XENLOG_INFO, "xen perfmon: " 1.10 "dom %d denied privileged operation %ld\n", 1.11 current->domain->domain_id, cmd);
2.1 --- a/xen/arch/ia64/xen/oprofile/perfmon.c Tue Jul 10 14:57:04 2007 +0100 2.2 +++ b/xen/arch/ia64/xen/oprofile/perfmon.c Tue Jul 10 15:41:26 2007 +0100 2.3 @@ -119,19 +119,10 @@ void xenoprof_perfmon_exit(void) 2.4 /////////////////////////////////////////////////////////////////////////// 2.5 // glue methods for xenoprof and perfmon. 2.6 int 2.7 -xenoprof_arch_init(int *num_events, int *is_primary, char *cpu_type) 2.8 +xenoprof_arch_init(int *num_events, char *cpu_type) 2.9 { 2.10 *num_events = 0; 2.11 strlcpy(cpu_type, get_cpu_type(), XENOPROF_CPU_TYPE_SIZE); 2.12 - 2.13 - *is_primary = 0; 2.14 - if (xenoprof_primary_profiler == NULL) { 2.15 - /* For now, only dom0 can be the primary profiler */ 2.16 - if (current->domain->domain_id == 0) { 2.17 - *is_primary = 1; 2.18 - } 2.19 - } else if (xenoprof_primary_profiler == current->domain) 2.20 - *is_primary = 1; 2.21 return 0; 2.22 } 2.23
3.1 --- a/xen/arch/x86/oprofile/nmi_int.c Tue Jul 10 14:57:04 2007 +0100 3.2 +++ b/xen/arch/x86/oprofile/nmi_int.c Tue Jul 10 15:41:26 2007 +0100 3.3 @@ -27,20 +27,15 @@ 3.4 #include "op_counter.h" 3.5 #include "op_x86_model.h" 3.6 3.7 +struct op_counter_config counter_config[OP_MAX_COUNTER]; 3.8 + 3.9 static struct op_x86_model_spec const * model; 3.10 static struct op_msrs cpu_msrs[NR_CPUS]; 3.11 static unsigned long saved_lvtpc[NR_CPUS]; 3.12 3.13 -#define VIRQ_BITMASK_SIZE (MAX_OPROF_DOMAINS/32 + 1) 3.14 -extern int active_domains[MAX_OPROF_DOMAINS]; 3.15 -extern unsigned int adomains; 3.16 -extern struct domain *adomain_ptrs[MAX_OPROF_DOMAINS]; 3.17 -extern unsigned long virq_ovf_pending[VIRQ_BITMASK_SIZE]; 3.18 +static char *cpu_type; 3.19 + 3.20 extern int is_active(struct domain *d); 3.21 -extern int active_id(struct domain *d); 3.22 -extern int is_profiled(struct domain *d); 3.23 - 3.24 - 3.25 3.26 static int nmi_callback(struct cpu_user_regs *regs, int cpu) 3.27 { 3.28 @@ -262,9 +257,7 @@ void nmi_stop(void) 3.29 } 3.30 3.31 3.32 -struct op_counter_config counter_config[OP_MAX_COUNTER]; 3.33 - 3.34 -static int __init p4_init(char * cpu_type) 3.35 +static int __init p4_init(char ** cpu_type) 3.36 { 3.37 __u8 cpu_model = current_cpu_data.x86_model; 3.38 3.39 @@ -276,20 +269,18 @@ static int __init p4_init(char * cpu_typ 3.40 } 3.41 3.42 #ifndef CONFIG_SMP 3.43 - strlcpy (cpu_type, "i386/p4", XENOPROF_CPU_TYPE_SIZE); 3.44 + *cpu_type = "i386/p4", XENOPROF_CPU_TYPE_SIZE); 3.45 model = &op_p4_spec; 3.46 return 1; 3.47 #else 3.48 switch (smp_num_siblings) { 3.49 case 1: 3.50 - strlcpy (cpu_type, "i386/p4", 3.51 - XENOPROF_CPU_TYPE_SIZE); 3.52 + *cpu_type = "i386/p4"; 3.53 model = &op_p4_spec; 3.54 return 1; 3.55 3.56 case 2: 3.57 - strlcpy (cpu_type, "i386/p4-ht", 3.58 - XENOPROF_CPU_TYPE_SIZE); 3.59 + *cpu_type = "i386/p4-ht"; 3.60 model = &op_p4_ht2_spec; 3.61 return 1; 3.62 } 3.63 @@ -300,7 +291,7 @@ static int __init p4_init(char * cpu_typ 3.64 } 3.65 3.66 3.67 -static int __init ppro_init(char *cpu_type) 3.68 +static int __init ppro_init(char ** cpu_type) 3.69 { 3.70 __u8 cpu_model = current_cpu_data.x86_model; 3.71 3.72 @@ -311,41 +302,32 @@ static int __init ppro_init(char *cpu_ty 3.73 return 0; 3.74 } 3.75 else if (cpu_model == 15) 3.76 - strlcpy (cpu_type, "i386/core_2", XENOPROF_CPU_TYPE_SIZE); 3.77 + *cpu_type = "i386/core_2"; 3.78 else if (cpu_model == 14) 3.79 - strlcpy (cpu_type, "i386/core", XENOPROF_CPU_TYPE_SIZE); 3.80 + *cpu_type = "i386/core"; 3.81 else if (cpu_model == 9) 3.82 - strlcpy (cpu_type, "i386/p6_mobile", XENOPROF_CPU_TYPE_SIZE); 3.83 + *cpu_type = "i386/p6_mobile"; 3.84 else if (cpu_model > 5) 3.85 - strlcpy (cpu_type, "i386/piii", XENOPROF_CPU_TYPE_SIZE); 3.86 + *cpu_type = "i386/piii"; 3.87 else if (cpu_model > 2) 3.88 - strlcpy (cpu_type, "i386/pii", XENOPROF_CPU_TYPE_SIZE); 3.89 + *cpu_type = "i386/pii"; 3.90 else 3.91 - strlcpy (cpu_type, "i386/ppro", XENOPROF_CPU_TYPE_SIZE); 3.92 + *cpu_type = "i386/ppro"; 3.93 3.94 model = &op_ppro_spec; 3.95 return 1; 3.96 } 3.97 3.98 -int nmi_init(int *num_events, int *is_primary, char *cpu_type) 3.99 +static int __init nmi_init(void) 3.100 { 3.101 __u8 vendor = current_cpu_data.x86_vendor; 3.102 __u8 family = current_cpu_data.x86; 3.103 - int prim = 0; 3.104 3.105 if (!cpu_has_apic) { 3.106 - printk("xenoprof: Initialization failed. No apic.\n"); 3.107 + printk("xenoprof: Initialization failed. No APIC\n"); 3.108 return -ENODEV; 3.109 } 3.110 3.111 - if (xenoprof_primary_profiler == NULL) { 3.112 - /* For now, only dom0 can be the primary profiler */ 3.113 - if (current->domain->domain_id == 0) { 3.114 - xenoprof_primary_profiler = current->domain; 3.115 - prim = 1; 3.116 - } 3.117 - } 3.118 - 3.119 switch (vendor) { 3.120 case X86_VENDOR_AMD: 3.121 /* Needs to be at least an Athlon (or hammer in 32bit mode) */ 3.122 @@ -358,15 +340,13 @@ int nmi_init(int *num_events, int *is_pr 3.123 return -ENODEV; 3.124 case 6: 3.125 model = &op_athlon_spec; 3.126 - strlcpy (cpu_type, "i386/athlon", 3.127 - XENOPROF_CPU_TYPE_SIZE); 3.128 + cpu_type = "i386/athlon"; 3.129 break; 3.130 case 0xf: 3.131 model = &op_athlon_spec; 3.132 - /* Actually it could be i386/hammer too, but give 3.133 - user space an consistent name. */ 3.134 - strlcpy (cpu_type, "x86-64/hammer", 3.135 - XENOPROF_CPU_TYPE_SIZE); 3.136 + /* Actually it could be i386/hammer too, but 3.137 + give user space an consistent name. */ 3.138 + cpu_type = "x86-64/hammer"; 3.139 break; 3.140 } 3.141 break; 3.142 @@ -375,13 +355,13 @@ int nmi_init(int *num_events, int *is_pr 3.143 switch (family) { 3.144 /* Pentium IV */ 3.145 case 0xf: 3.146 - if (!p4_init(cpu_type)) 3.147 + if (!p4_init(&cpu_type)) 3.148 return -ENODEV; 3.149 break; 3.150 3.151 /* A P6-class processor */ 3.152 case 6: 3.153 - if (!ppro_init(cpu_type)) 3.154 + if (!ppro_init(&cpu_type)) 3.155 return -ENODEV; 3.156 break; 3.157 3.158 @@ -400,9 +380,16 @@ int nmi_init(int *num_events, int *is_pr 3.159 return -ENODEV; 3.160 } 3.161 3.162 - *num_events = model->num_counters; 3.163 - *is_primary = prim; 3.164 - 3.165 return 0; 3.166 } 3.167 3.168 +__initcall(nmi_init); 3.169 + 3.170 +int xenoprof_arch_init(int *num_events, char *_cpu_type) 3.171 +{ 3.172 + if (cpu_type == NULL) 3.173 + return -ENODEV; 3.174 + *num_events = model->num_counters; 3.175 + strlcpy(_cpu_type, cpu_type, XENOPROF_CPU_TYPE_SIZE); 3.176 + return 0; 3.177 +}
4.1 --- a/xen/common/xenoprof.c Tue Jul 10 14:57:04 2007 +0100 4.2 +++ b/xen/common/xenoprof.c Tue Jul 10 15:41:26 2007 +0100 4.3 @@ -21,26 +21,26 @@ 4.4 /* Lock protecting the following global state */ 4.5 static DEFINE_SPINLOCK(xenoprof_lock); 4.6 4.7 -struct domain *active_domains[MAX_OPROF_DOMAINS]; 4.8 -int active_ready[MAX_OPROF_DOMAINS]; 4.9 -unsigned int adomains; 4.10 +static struct domain *active_domains[MAX_OPROF_DOMAINS]; 4.11 +static int active_ready[MAX_OPROF_DOMAINS]; 4.12 +static unsigned int adomains; 4.13 4.14 -struct domain *passive_domains[MAX_OPROF_DOMAINS]; 4.15 -unsigned int pdomains; 4.16 +static struct domain *passive_domains[MAX_OPROF_DOMAINS]; 4.17 +static unsigned int pdomains; 4.18 4.19 -unsigned int activated; 4.20 -struct domain *xenoprof_primary_profiler; 4.21 -int xenoprof_state = XENOPROF_IDLE; 4.22 +static unsigned int activated; 4.23 +static struct domain *xenoprof_primary_profiler; 4.24 +static int xenoprof_state = XENOPROF_IDLE; 4.25 static unsigned long backtrace_depth; 4.26 4.27 -u64 total_samples; 4.28 -u64 invalid_buffer_samples; 4.29 -u64 corrupted_buffer_samples; 4.30 -u64 lost_samples; 4.31 -u64 active_samples; 4.32 -u64 passive_samples; 4.33 -u64 idle_samples; 4.34 -u64 others_samples; 4.35 +static u64 total_samples; 4.36 +static u64 invalid_buffer_samples; 4.37 +static u64 corrupted_buffer_samples; 4.38 +static u64 lost_samples; 4.39 +static u64 active_samples; 4.40 +static u64 passive_samples; 4.41 +static u64 idle_samples; 4.42 +static u64 others_samples; 4.43 4.44 int is_active(struct domain *d) 4.45 { 4.46 @@ -48,13 +48,13 @@ int is_active(struct domain *d) 4.47 return ((x != NULL) && (x->domain_type == XENOPROF_DOMAIN_ACTIVE)); 4.48 } 4.49 4.50 -int is_passive(struct domain *d) 4.51 +static int is_passive(struct domain *d) 4.52 { 4.53 struct xenoprof *x = d->xenoprof; 4.54 return ((x != NULL) && (x->domain_type == XENOPROF_DOMAIN_PASSIVE)); 4.55 } 4.56 4.57 -int is_profiled(struct domain *d) 4.58 +static int is_profiled(struct domain *d) 4.59 { 4.60 return (is_active(d) || is_passive(d)); 4.61 } 4.62 @@ -543,24 +543,24 @@ void xenoprof_log_event(struct vcpu *vcp 4.63 4.64 static int xenoprof_op_init(XEN_GUEST_HANDLE(void) arg) 4.65 { 4.66 + struct domain *d = current->domain; 4.67 struct xenoprof_init xenoprof_init; 4.68 int ret; 4.69 4.70 if ( copy_from_guest(&xenoprof_init, arg, 1) ) 4.71 return -EFAULT; 4.72 4.73 - if ( (ret = xenoprof_arch_init(&xenoprof_init.num_events, 4.74 - &xenoprof_init.is_primary, 4.75 + if ( (ret = xenoprof_arch_init(&xenoprof_init.num_events, 4.76 xenoprof_init.cpu_type)) ) 4.77 return ret; 4.78 4.79 - if ( copy_to_guest(arg, &xenoprof_init, 1) ) 4.80 - return -EFAULT; 4.81 - 4.82 + xenoprof_init.is_primary = 4.83 + ((xenoprof_primary_profiler == d) || 4.84 + ((xenoprof_primary_profiler == NULL) && (d->domain_id == 0))); 4.85 if ( xenoprof_init.is_primary ) 4.86 xenoprof_primary_profiler = current->domain; 4.87 4.88 - return 0; 4.89 + return (copy_to_guest(arg, &xenoprof_init, 1) ? -EFAULT : 0); 4.90 } 4.91 4.92 #endif /* !COMPAT */
5.1 --- a/xen/include/asm-ia64/xenoprof.h Tue Jul 10 14:57:04 2007 +0100 5.2 +++ b/xen/include/asm-ia64/xenoprof.h Tue Jul 10 15:41:26 2007 +0100 5.3 @@ -24,7 +24,7 @@ 5.4 #ifndef __ASM_XENOPROF_H__ 5.5 #define __ASM_XENOPROF_H__ 5.6 5.7 -int xenoprof_arch_init(int *num_events, int *is_primary, char *cpu_type); 5.8 +int xenoprof_arch_init(int *num_events, char *cpu_type); 5.9 int xenoprof_arch_reserve_counters(void); 5.10 int xenoprof_arch_counter(XEN_GUEST_HANDLE(void) arg); 5.11 int xenoprof_arch_setup_events(void);
6.1 --- a/xen/include/asm-x86/xenoprof.h Tue Jul 10 14:57:04 2007 +0100 6.2 +++ b/xen/include/asm-x86/xenoprof.h Tue Jul 10 15:41:26 2007 +0100 6.3 @@ -23,7 +23,6 @@ 6.4 #ifndef __ASM_X86_XENOPROF_H__ 6.5 #define __ASM_X86_XENOPROF_H__ 6.6 6.7 -int nmi_init(int *num_events, int *is_primary, char *cpu_type); 6.8 int nmi_reserve_counters(void); 6.9 int nmi_setup_events(void); 6.10 int nmi_enable_virq(void); 6.11 @@ -32,8 +31,7 @@ void nmi_stop(void); 6.12 void nmi_disable_virq(void); 6.13 void nmi_release_counters(void); 6.14 6.15 -#define xenoprof_arch_init(num_events, is_primary, cpu_type) \ 6.16 - nmi_init(num_events, is_primary, cpu_type) 6.17 +int xenoprof_arch_init(int *num_events, char *cpu_type); 6.18 #define xenoprof_arch_reserve_counters() nmi_reserve_counters() 6.19 #define xenoprof_arch_setup_events() nmi_setup_events() 6.20 #define xenoprof_arch_enable_virq() nmi_enable_virq()
7.1 --- a/xen/include/xen/xenoprof.h Tue Jul 10 14:57:04 2007 +0100 7.2 +++ b/xen/include/xen/xenoprof.h Tue Jul 10 15:41:26 2007 +0100 7.3 @@ -69,6 +69,4 @@ int do_xenoprof_op(int op, XEN_GUEST_HAN 7.4 int xenoprof_add_trace(struct domain *d, struct vcpu *v, 7.5 unsigned long eip, int mode); 7.6 7.7 -extern struct domain *xenoprof_primary_profiler; 7.8 - 7.9 #endif /* __XEN__XENOPROF_H__ */