From: "Jan Beulich" Subject: [PATCH] linux-2.6.18/xenoprof: cleanup Date: Wed, 15 Feb 2012 16:01:31 +0000 Message-ID: <4F3BE4EB020000780007333A@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part012F78CB.0__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: "xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part012F78CB.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline - frame Xen-specific additions with CONFIG_XEN conditionals - use per-CPU data Signed-off-by: Jan Beulich --- a/drivers/oprofile/buffer_sync.c +++ b/drivers/oprofile/buffer_sync.c @@ -42,7 +42,10 @@ static cpumask_t marked_cpus =3D CPU_MASK_ static DEFINE_SPINLOCK(task_mortuary); static void process_task_mortuary(void); =20 +#ifdef CONFIG_XEN -static int cpu_current_domain[NR_CPUS]; +#include +static DEFINE_PER_CPU(int, current_domain) =3D COORDINATOR_DOMAIN; +#endif =20 /* Take ownership of the task struct and place it on the * list for processing. Only after two full buffer syncs @@ -151,11 +154,12 @@ static void end_sync(void) int sync_start(void) { int err; - int i; +#ifdef CONFIG_XEN + unsigned int cpu; =20 - for (i =3D 0; i < NR_CPUS; i++) { - cpu_current_domain[i] =3D COORDINATOR_DOMAIN; - } + for_each_online_cpu(cpu) + per_cpu(current_domain, cpu) =3D COORDINATOR_DOMAIN; +#endif =20 start_cpu_work(); =20 @@ -303,12 +307,14 @@ static void add_cpu_mode_switch(unsigned } } =20 +#ifdef CONFIG_XEN static void add_domain_switch(unsigned long domain_id) { add_event_entry(ESCAPE_CODE); add_event_entry(DOMAIN_SWITCH_CODE); add_event_entry(domain_id); } +#endif =20 static void add_user_ctx_switch(struct task_struct const * task, unsigned long = cookie) @@ -498,6 +504,7 @@ static void mark_done(int cpu) cpus_clear(marked_cpus); } =20 +#ifdef CONFIG_XEN /* Add IBS samples into event buffer */ #define IBS_FETCH_SIZE 8 #define IBS_OP_SIZE 14 @@ -559,6 +566,9 @@ static int add_ibs_data(int cpu, struct=20 =20 return size; } +#else +#define add_ibs_data(cpu, mm, cpu_mode) 0 +#endif =20 /* FIXME: this is not sufficient if we implement syscall barrier = backtrace * traversal, the code switch to sb_sample_start at first kernel = enter/exit @@ -594,11 +604,12 @@ void sync_buffer(int cpu) =20 add_cpu_switch(cpu); =20 +#ifdef CONFIG_XEN /* We need to assign the first samples in this CPU buffer to the same domain that we were processing at the last sync_buffer */ - if (cpu_current_domain[cpu] !=3D COORDINATOR_DOMAIN) { - add_domain_switch(cpu_current_domain[cpu]); - } + if (per_cpu(current_domain, cpu) !=3D COORDINATOR_DOMAIN) + add_domain_switch(per_cpu(current_domain, cpu)); +#endif /* Remember, only we can modify tail_pos */ =20 available =3D get_slots(cpu_buf); @@ -616,8 +627,10 @@ void sync_buffer(int cpu) } else if (s->event =3D=3D CPU_TRACE_BEGIN) { state =3D sb_bt_start; add_trace_begin(); +#ifdef CONFIG_XEN } else if (s->event =3D=3D CPU_DOMAIN_SWITCH) { - domain_switch =3D 1; = =09 + domain_switch =3D 1; +#endif } else { struct mm_struct * oldmm =3D mm; =20 @@ -633,21 +646,23 @@ void sync_buffer(int cpu) is_ibs_sample =3D add_ibs_data(cpu, mm, cpu_mode); =20 } else { +#ifdef CONFIG_XEN if (domain_switch) { - cpu_current_domain[cpu] =3D s->eip; + per_cpu(current_domain, cpu) =3D s->eip; add_domain_switch(s->eip); domain_switch =3D 0; - } else if (!is_ibs_sample) { - if (cpu_current_domain[cpu] !=3D - COORDINATOR_DOMAIN) { - add_sample_entry(s->eip, s->event);= - } - else if (state >=3D sb_bt_start && - !add_sample(mm, s, cpu_mode)) { - if (state =3D=3D sb_bt_start) { - state =3D sb_bt_ignore; - atomic_inc(&oprofile_stats.= bt_lost_no_mapping); - } + } else if (is_ibs_sample) + ; + else if (per_cpu(current_domain, cpu) !=3D + COORDINATOR_DOMAIN) { + add_sample_entry(s->eip, s->event); + } else +#endif + if (state >=3D sb_bt_start && + !add_sample(mm, s, cpu_mode)) { + if (state =3D=3D sb_bt_start) { + state =3D sb_bt_ignore; + atomic_inc(&oprofile_stats.bt_lost_= no_mapping); } } } @@ -656,10 +671,11 @@ void sync_buffer(int cpu) } release_mm(mm); =20 +#ifdef CONFIG_XEN /* We reset domain to COORDINATOR at each CPU switch */ - if (cpu_current_domain[cpu] !=3D COORDINATOR_DOMAIN) { + if (per_cpu(current_domain, cpu) !=3D COORDINATOR_DOMAIN) add_domain_switch(COORDINATOR_DOMAIN); - } +#endif =20 mark_done(cpu); =20 --- a/drivers/oprofile/cpu_buffer.c +++ b/drivers/oprofile/cpu_buffer.c @@ -38,7 +38,11 @@ static void wq_sync_buffer(void *); #define DEFAULT_TIMER_EXPIRE (HZ / 10) static int work_enabled; =20 +#ifndef CONFIG_XEN +#define current_domain COORDINATOR_DOMAIN +#else static int32_t current_domain =3D COORDINATOR_DOMAIN; +#endif =20 void free_cpu_buffers(void) { @@ -202,8 +206,10 @@ static int log_sample(struct oprofile_cp add_code(cpu_buf, (unsigned long)task); } =20 +#ifdef CONFIG_XEN if (pc =3D=3D IBS_FETCH_CODE || pc =3D=3D IBS_OP_CODE) add_code(cpu_buf, cpu_mode); +#endif =20 add_sample(cpu_buf, pc, event); return 1; @@ -284,6 +290,7 @@ void oprofile_add_trace(unsigned long pc add_sample(cpu_buf, pc, 0); } =20 +#ifdef CONFIG_XEN int oprofile_add_domain_switch(int32_t domain_id) { struct oprofile_cpu_buffer * cpu_buf =3D &cpu_buffer[smp_processor_= id()]; @@ -302,6 +309,7 @@ int oprofile_add_domain_switch(int32_t d =20 return 1; } +#endif =20 /* * This serves to avoid cpu buffer overflow, and makes sure --- a/drivers/oprofile/oprof.c +++ b/drivers/oprofile/oprof.c @@ -37,6 +37,7 @@ static DECLARE_MUTEX(start_sem); */ static int timer =3D 0; =20 +#ifdef CONFIG_XEN int oprofile_set_active(int active_domains[], unsigned int adomains) { int err; @@ -62,6 +63,7 @@ int oprofile_set_passive(int passive_dom mutex_unlock(&start_mutex); return err; } +#endif =20 int oprofile_setup(void) { --- a/drivers/oprofile/oprofile_files.c +++ b/drivers/oprofile/oprofile_files.c @@ -21,7 +21,11 @@ #include "oprof.h" =20 unsigned long fs_buffer_size =3D 131072; -unsigned long fs_cpu_buffer_size =3D 131072; +#ifndef CONFIG_XEN +unsigned long fs_cpu_buffer_size =3D 8192; +#else +unsigned long fs_cpu_buffer_size =3D 32768; +#endif unsigned long fs_buffer_watershed =3D 32768; /* FIXME: tune */ =20 static ssize_t depth_read(struct file * file, char __user * buf, size_t = count, loff_t * offset) @@ -124,6 +128,8 @@ static struct file_operations dump_fops=20 .write =3D dump_write, }; =20 +#ifdef CONFIG_XEN + #define TMPBUFSIZE 512 =20 struct domain_data { @@ -228,8 +234,8 @@ static DEFINE_DOMAIN_DATA(active); =20 static int adomain_open(struct inode *inode, struct file *filp) { - filp->private_data =3D &active_domains; - return 0; + filp->private_data =3D &active_domains; + return 0; } =20 static const struct file_operations active_domain_ops =3D { @@ -242,8 +248,8 @@ static const struct file_operations acti =20 static int pdomain_open(struct inode *inode, struct file *filp) { - filp->private_data =3D &passive_domains; - return 0; + filp->private_data =3D &passive_domains; + return 0; } =20 static const struct file_operations passive_domain_ops =3D { @@ -252,12 +258,16 @@ static const struct file_operations pass .write =3D domain_write, }; =20 +#endif /* CONFIG_XEN */ + void oprofile_create_files(struct super_block * sb, struct dentry * root) { oprofilefs_create_file(sb, root, "enable", &enable_fops); oprofilefs_create_file_perm(sb, root, "dump", &dump_fops, 0666); +#ifdef CONFIG_XEN oprofilefs_create_file(sb, root, "active_domains", &active_domain_o= ps); oprofilefs_create_file(sb, root, "passive_domains", &passive_domain= _ops); +#endif oprofilefs_create_file(sb, root, "buffer", &event_buffer_fops); oprofilefs_create_ulong(sb, root, "buffer_size", &fs_buffer_size); oprofilefs_create_ulong(sb, root, "buffer_watershed", &fs_buffer_wa= tershed); --- a/include/linux/oprofile.h +++ b/include/linux/oprofile.h @@ -16,8 +16,9 @@ #include #include #include - +#ifdef CONFIG_XEN #include +#endif =20 struct super_block; struct dentry; @@ -29,11 +30,12 @@ struct oprofile_operations { /* create any necessary configuration files in the oprofile fs. * Optional. */ int (*create_files)(struct super_block * sb, struct dentry * = root); +#ifdef CONFIG_XEN /* setup active domains with Xen */ int (*set_active)(int *active_domains, unsigned int adomains); - /* setup passive domains with Xen */ - int (*set_passive)(int *passive_domains, unsigned int pdomains); -=09 + /* setup passive domains with Xen */ + int (*set_passive)(int *passive_domains, unsigned int pdomains); +#endif /* Do any necessary interrupt setup. Optional. */ int (*setup)(void); /* Do any necessary interrupt shutdown. Optional. */ --=__Part012F78CB.0__= Content-Type: text/plain; name="xen-oprofile-cleanup.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="xen-oprofile-cleanup.patch" xenoprof: cleanup=0A=0A- frame Xen-specific additions with CONFIG_XEN = conditionals=0A- use per-CPU data=0A=0ASigned-off-by: Jan Beulich = =0A=0A--- a/drivers/oprofile/buffer_sync.c=0A+++ = b/drivers/oprofile/buffer_sync.c=0A@@ -42,7 +42,10 @@ static cpumask_t = marked_cpus =3D CPU_MASK_=0A static DEFINE_SPINLOCK(task_mortuary);=0A = static void process_task_mortuary(void);=0A =0A+#ifdef CONFIG_XEN=0A-static= int cpu_current_domain[NR_CPUS];=0A+#include =0A+static = DEFINE_PER_CPU(int, current_domain) =3D COORDINATOR_DOMAIN;=0A+#endif=0A = =0A /* Take ownership of the task struct and place it on the=0A * list = for processing. Only after two full buffer syncs=0A@@ -151,11 +154,12 @@ = static void end_sync(void)=0A int sync_start(void)=0A {=0A int = err;=0A- int i;=0A+#ifdef CONFIG_XEN=0A+ unsigned int cpu;=0A =0A- = for (i =3D 0; i < NR_CPUS; i++) {=0A- cpu_current_domain[i] =3D = COORDINATOR_DOMAIN;=0A- }=0A+ for_each_online_cpu(cpu)=0A+ = per_cpu(current_domain, cpu) =3D COORDINATOR_DOMAIN;=0A+#endif=0A =0A = start_cpu_work();=0A =0A@@ -303,12 +307,14 @@ static void add_cpu_mode_swit= ch(unsigned=0A }=0A }=0A =0A+#ifdef CONFIG_XEN=0A static void add_domain_s= witch(unsigned long domain_id)=0A {=0A add_event_entry(ESCAPE_CODE);=0A = add_event_entry(DOMAIN_SWITCH_CODE);=0A add_event_entry(domain_id);= =0A }=0A+#endif=0A =0A static void=0A add_user_ctx_switch(struct task_struc= t const * task, unsigned long cookie)=0A@@ -498,6 +504,7 @@ static void = mark_done(int cpu)=0A cpus_clear(marked_cpus);=0A }=0A =0A+#ifdef = CONFIG_XEN=0A /* Add IBS samples into event buffer */=0A #define IBS_FETCH_= SIZE 8=0A #define IBS_OP_SIZE 14=0A@@ -559,6 +566,9 @@ = static int add_ibs_data(int cpu, struct =0A =0A return size;=0A = }=0A+#else=0A+#define add_ibs_data(cpu, mm, cpu_mode) 0=0A+#endif=0A =0A = /* FIXME: this is not sufficient if we implement syscall barrier = backtrace=0A * traversal, the code switch to sb_sample_start at first = kernel enter/exit=0A@@ -594,11 +604,12 @@ void sync_buffer(int cpu)=0A = =0A add_cpu_switch(cpu);=0A =0A+#ifdef CONFIG_XEN=0A /* We need = to assign the first samples in this CPU buffer to the=0A same = domain that we were processing at the last sync_buffer */=0A- if = (cpu_current_domain[cpu] !=3D COORDINATOR_DOMAIN) {=0A- add_domain_= switch(cpu_current_domain[cpu]);=0A- }=0A+ if (per_cpu(current_domain,= cpu) !=3D COORDINATOR_DOMAIN)=0A+ add_domain_switch(per_cpu(c= urrent_domain, cpu));=0A+#endif=0A /* Remember, only we can modify = tail_pos */=0A =0A available =3D get_slots(cpu_buf);=0A@@ -616,8 = +627,10 @@ void sync_buffer(int cpu)=0A } else if = (s->event =3D=3D CPU_TRACE_BEGIN) {=0A state =3D = sb_bt_start;=0A add_trace_begin();=0A+#ifde= f CONFIG_XEN=0A } else if (s->event =3D=3D = CPU_DOMAIN_SWITCH) {=0A- domain_swit= ch =3D 1; =0A+ = domain_switch =3D 1;=0A+#endif=0A } else {=0A = struct mm_struct * oldmm =3D mm;=0A =0A@@ -633,21 +646,23 = @@ void sync_buffer(int cpu)=0A is_ibs_sample =3D = add_ibs_data(cpu, mm, cpu_mode);=0A =0A } else {=0A+#ifdef = CONFIG_XEN=0A if (domain_switch) {=0A- = cpu_current_domain[cpu] =3D s->eip;=0A+ = per_cpu(current_domain, cpu) =3D s->eip;=0A = add_domain_switch(s->eip);=0A domain_switch =3D = 0;=0A- } else if (!is_ibs_sample) {=0A- = if (cpu_current_domain[cpu] !=3D=0A- = COORDINATOR_DOMAIN) {=0A- add_sample_= entry(s->eip, s->event);=0A- }=0A- = else if (state >=3D sb_bt_start &&=0A- = !add_sample(mm, s, cpu_mode)) {=0A- if = (state =3D=3D sb_bt_start) {=0A- = state =3D sb_bt_ignore;=0A- = atomic_inc(&oprofile_stats.bt_lost_no_mapping);=0A- = }=0A+ } else if (is_ibs_sample)=0A+ = ;=0A+ else if (per_cpu(current_domain, cpu) = !=3D=0A+ COORDINATOR_DOMAIN) {=0A+ = add_sample_entry(s->eip, s->event);=0A+ } = else=0A+#endif=0A+ if (state >=3D sb_bt_start &&=0A+ = !add_sample(mm, s, cpu_mode)) {=0A+ = if (state =3D=3D sb_bt_start) {=0A+ = state =3D sb_bt_ignore;=0A+ atomic_inc(= &oprofile_stats.bt_lost_no_mapping);=0A = }=0A }=0A }=0A@@ -656,10 +671,11 @@ void = sync_buffer(int cpu)=0A }=0A release_mm(mm);=0A =0A+#ifdef = CONFIG_XEN=0A /* We reset domain to COORDINATOR at each CPU switch = */=0A- if (cpu_current_domain[cpu] !=3D COORDINATOR_DOMAIN) {=0A+ if = (per_cpu(current_domain, cpu) !=3D COORDINATOR_DOMAIN)=0A = add_domain_switch(COORDINATOR_DOMAIN);=0A- }=0A+#endif=0A =0A = mark_done(cpu);=0A =0A--- a/drivers/oprofile/cpu_buffer.c=0A+++ b/drivers/o= profile/cpu_buffer.c=0A@@ -38,7 +38,11 @@ static void wq_sync_buffer(void = *);=0A #define DEFAULT_TIMER_EXPIRE (HZ / 10)=0A static int work_enabled;= =0A =0A+#ifndef CONFIG_XEN=0A+#define current_domain COORDINATOR_DOMAIN=0A+= #else=0A static int32_t current_domain =3D COORDINATOR_DOMAIN;=0A+#endif=0A= =0A void free_cpu_buffers(void)=0A {=0A@@ -202,8 +206,10 @@ static int = log_sample(struct oprofile_cp=0A add_code(cpu_buf, = (unsigned long)task);=0A }=0A =0A+#ifdef CONFIG_XEN=0A if (pc = =3D=3D IBS_FETCH_CODE || pc =3D=3D IBS_OP_CODE)=0A add_code(cp= u_buf, cpu_mode);=0A+#endif=0A =0A add_sample(cpu_buf, pc, event);=0A = return 1;=0A@@ -284,6 +290,7 @@ void oprofile_add_trace(unsigned = long pc=0A add_sample(cpu_buf, pc, 0);=0A }=0A =0A+#ifdef CONFIG_XEN= =0A int oprofile_add_domain_switch(int32_t domain_id)=0A {=0A struct = oprofile_cpu_buffer * cpu_buf =3D &cpu_buffer[smp_processor_id()];=0A@@ = -302,6 +309,7 @@ int oprofile_add_domain_switch(int32_t d=0A =0A = return 1;=0A }=0A+#endif=0A =0A /*=0A * This serves to avoid cpu buffer = overflow, and makes sure=0A--- a/drivers/oprofile/oprof.c=0A+++ b/drivers/o= profile/oprof.c=0A@@ -37,6 +37,7 @@ static DECLARE_MUTEX(start_sem);=0A = */=0A static int timer =3D 0;=0A =0A+#ifdef CONFIG_XEN=0A int oprofile_set_= active(int active_domains[], unsigned int adomains)=0A {=0A int = err;=0A@@ -62,6 +63,7 @@ int oprofile_set_passive(int passive_dom=0A = mutex_unlock(&start_mutex);=0A return err;=0A }=0A+#endif=0A =0A int = oprofile_setup(void)=0A {=0A--- a/drivers/oprofile/oprofile_files.c=0A+++ = b/drivers/oprofile/oprofile_files.c=0A@@ -21,7 +21,11 @@=0A #include = "oprof.h"=0A =0A unsigned long fs_buffer_size =3D 131072;=0A-unsigned long = fs_cpu_buffer_size =3D 131072;=0A+#ifndef CONFIG_XEN=0A+unsigned long = fs_cpu_buffer_size =3D 8192;=0A+#else=0A+unsigned long fs_cpu_buffer_size = =3D 32768;=0A+#endif=0A unsigned long fs_buffer_watershed =3D 32768; /* = FIXME: tune */=0A =0A static ssize_t depth_read(struct file * file, char = __user * buf, size_t count, loff_t * offset)=0A@@ -124,6 +128,8 @@ static = struct file_operations dump_fops =0A .write =3D dump_write,=0A = };=0A =0A+#ifdef CONFIG_XEN=0A+=0A #define TMPBUFSIZE 512=0A =0A struct = domain_data {=0A@@ -228,8 +234,8 @@ static DEFINE_DOMAIN_DATA(active);=0A = =0A static int adomain_open(struct inode *inode, struct file *filp)=0A = {=0A- filp->private_data =3D &active_domains;=0A- return 0;=0A+ = filp->private_data =3D &active_domains;=0A+ return 0;=0A }=0A =0A = static const struct file_operations active_domain_ops =3D {=0A@@ -242,8 = +248,8 @@ static const struct file_operations acti=0A =0A static int = pdomain_open(struct inode *inode, struct file *filp)=0A {=0A- filp->priv= ate_data =3D &passive_domains;=0A- return 0;=0A+ filp->private_data = =3D &passive_domains;=0A+ return 0;=0A }=0A =0A static const struct = file_operations passive_domain_ops =3D {=0A@@ -252,12 +258,16 @@ static = const struct file_operations pass=0A .write =3D domain_write,= =0A };=0A =0A+#endif /* CONFIG_XEN */=0A+=0A void oprofile_create_files(str= uct super_block * sb, struct dentry * root)=0A {=0A oprofilefs_create_f= ile(sb, root, "enable", &enable_fops);=0A oprofilefs_create_file_perm= (sb, root, "dump", &dump_fops, 0666);=0A+#ifdef CONFIG_XEN=0A oprofilefs_= create_file(sb, root, "active_domains", &active_domain_ops);=0A = oprofilefs_create_file(sb, root, "passive_domains", &passive_domain_ops);= =0A+#endif=0A oprofilefs_create_file(sb, root, "buffer", &event_buffer_fo= ps);=0A oprofilefs_create_ulong(sb, root, "buffer_size", &fs_buffer= _size);=0A oprofilefs_create_ulong(sb, root, "buffer_watershed", = &fs_buffer_watershed);=0A--- a/include/linux/oprofile.h=0A+++ b/include/lin= ux/oprofile.h=0A@@ -16,8 +16,9 @@=0A #include =0A #include = =0A #include =0A-=0A+#ifdef CONFIG_XEN=0A = #include =0A+#endif=0A =0A struct super_block;= =0A struct dentry;=0A@@ -29,11 +30,12 @@ struct oprofile_operations {=0A = /* create any necessary configuration files in the oprofile fs.=0A * = Optional. */=0A int (*create_files)(struct super_block * sb, = struct dentry * root);=0A+#ifdef CONFIG_XEN=0A /* setup active domains = with Xen */=0A int (*set_active)(int *active_domains, unsigned int = adomains);=0A- /* setup passive domains with Xen */=0A- int = (*set_passive)(int *passive_domains, unsigned int pdomains);=0A- = =0A+ /* setup passive domains with Xen */=0A+ int (*set_passive)(= int *passive_domains, unsigned int pdomains);=0A+#endif=0A /* Do any = necessary interrupt setup. Optional. */=0A int (*setup)(void);=0A /* = Do any necessary interrupt shutdown. Optional. */=0A --=__Part012F78CB.0__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=__Part012F78CB.0__=--