[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH] linux-2.6.18/xenoprof: cleanup



- frame Xen-specific additions with CONFIG_XEN conditionals
- use per-CPU data

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>

--- a/drivers/oprofile/buffer_sync.c
+++ b/drivers/oprofile/buffer_sync.c
@@ -42,7 +42,10 @@ static cpumask_t marked_cpus = CPU_MASK_
 static DEFINE_SPINLOCK(task_mortuary);
 static void process_task_mortuary(void);
 
+#ifdef CONFIG_XEN
-static int cpu_current_domain[NR_CPUS];
+#include <linux/percpu.h>
+static DEFINE_PER_CPU(int, current_domain) = COORDINATOR_DOMAIN;
+#endif
 
 /* 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;
 
-       for (i = 0; i < NR_CPUS; i++) {
-               cpu_current_domain[i] = COORDINATOR_DOMAIN;
-       }
+       for_each_online_cpu(cpu)
+               per_cpu(current_domain, cpu) = COORDINATOR_DOMAIN;
+#endif
 
        start_cpu_work();
 
@@ -303,12 +307,14 @@ static void add_cpu_mode_switch(unsigned
        }
 }
 
+#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
 
 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);
 }
 
+#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 
 
        return size;
 }
+#else
+#define add_ibs_data(cpu, mm, cpu_mode) 0
+#endif
 
 /* 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)
  
        add_cpu_switch(cpu);
 
+#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] != COORDINATOR_DOMAIN) {
-               add_domain_switch(cpu_current_domain[cpu]);
-       }
+       if (per_cpu(current_domain, cpu) != COORDINATOR_DOMAIN)
+               add_domain_switch(per_cpu(current_domain, cpu));
+#endif
        /* Remember, only we can modify tail_pos */
 
        available = get_slots(cpu_buf);
@@ -616,8 +627,10 @@ void sync_buffer(int cpu)
                        } else if (s->event == CPU_TRACE_BEGIN) {
                                state = sb_bt_start;
                                add_trace_begin();
+#ifdef CONFIG_XEN
                        } else if (s->event == CPU_DOMAIN_SWITCH) {
-                                       domain_switch = 1;                      
        
+                               domain_switch = 1;
+#endif
                        } else {
                                struct mm_struct * oldmm = mm;
 
@@ -633,21 +646,23 @@ void sync_buffer(int cpu)
                        is_ibs_sample = add_ibs_data(cpu, mm, cpu_mode);
 
                } else {
+#ifdef CONFIG_XEN
                        if (domain_switch) {
-                               cpu_current_domain[cpu] = s->eip;
+                               per_cpu(current_domain, cpu) = s->eip;
                                add_domain_switch(s->eip);
                                domain_switch = 0;
-                       } else if (!is_ibs_sample) {
-                               if (cpu_current_domain[cpu] !=
-                                   COORDINATOR_DOMAIN) {
-                                       add_sample_entry(s->eip, s->event);
-                               }
-                               else  if (state >= sb_bt_start &&
-                                   !add_sample(mm, s, cpu_mode)) {
-                                       if (state == sb_bt_start) {
-                                               state = sb_bt_ignore;
-                                               
atomic_inc(&oprofile_stats.bt_lost_no_mapping);
-                                       }
+                       } else if (is_ibs_sample)
+                               ;
+                       else if (per_cpu(current_domain, cpu) !=
+                                COORDINATOR_DOMAIN) {
+                               add_sample_entry(s->eip, s->event);
+                       } else
+#endif
+                       if (state >= sb_bt_start &&
+                           !add_sample(mm, s, cpu_mode)) {
+                               if (state == sb_bt_start) {
+                                       state = sb_bt_ignore;
+                                       
atomic_inc(&oprofile_stats.bt_lost_no_mapping);
                                }
                        }
                }
@@ -656,10 +671,11 @@ void sync_buffer(int cpu)
        }
        release_mm(mm);
 
+#ifdef CONFIG_XEN
        /* We reset domain to COORDINATOR at each CPU switch */
-       if (cpu_current_domain[cpu] != COORDINATOR_DOMAIN) {
+       if (per_cpu(current_domain, cpu) != COORDINATOR_DOMAIN)
                add_domain_switch(COORDINATOR_DOMAIN);
-       }
+#endif
 
        mark_done(cpu);
 
--- 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;
 
+#ifndef CONFIG_XEN
+#define current_domain COORDINATOR_DOMAIN
+#else
 static int32_t current_domain = COORDINATOR_DOMAIN;
+#endif
 
 void free_cpu_buffers(void)
 {
@@ -202,8 +206,10 @@ static int log_sample(struct oprofile_cp
                add_code(cpu_buf, (unsigned long)task);
        }
 
+#ifdef CONFIG_XEN
        if (pc == IBS_FETCH_CODE || pc == IBS_OP_CODE)
                add_code(cpu_buf, cpu_mode);
+#endif
 
        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);
 }
 
+#ifdef CONFIG_XEN
 int oprofile_add_domain_switch(int32_t domain_id)
 {
        struct oprofile_cpu_buffer * cpu_buf = &cpu_buffer[smp_processor_id()];
@@ -302,6 +309,7 @@ int oprofile_add_domain_switch(int32_t d
 
        return 1;
 }
+#endif
 
 /*
  * 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 = 0;
 
+#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
 
 int oprofile_setup(void)
 {
--- a/drivers/oprofile/oprofile_files.c
+++ b/drivers/oprofile/oprofile_files.c
@@ -21,7 +21,11 @@
 #include "oprof.h"
 
 unsigned long fs_buffer_size = 131072;
-unsigned long fs_cpu_buffer_size = 131072;
+#ifndef CONFIG_XEN
+unsigned long fs_cpu_buffer_size = 8192;
+#else
+unsigned long fs_cpu_buffer_size = 32768;
+#endif
 unsigned long fs_buffer_watershed = 32768; /* FIXME: tune */
 
 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 
        .write          = dump_write,
 };
 
+#ifdef CONFIG_XEN
+
 #define TMPBUFSIZE 512
 
 struct domain_data {
@@ -228,8 +234,8 @@ static DEFINE_DOMAIN_DATA(active);
 
 static int adomain_open(struct inode *inode, struct file *filp)
 {
-    filp->private_data = &active_domains;
-    return 0;
+       filp->private_data = &active_domains;
+       return 0;
 }
 
 static const struct file_operations active_domain_ops = {
@@ -242,8 +248,8 @@ static const struct file_operations acti
 
 static int pdomain_open(struct inode *inode, struct file *filp)
 {
-    filp->private_data = &passive_domains;
-    return 0;
+       filp->private_data = &passive_domains;
+       return 0;
 }
 
 static const struct file_operations passive_domain_ops = {
@@ -252,12 +258,16 @@ static const struct file_operations pass
        .write          = domain_write,
 };
 
+#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_ops);
        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_watershed);
--- a/include/linux/oprofile.h
+++ b/include/linux/oprofile.h
@@ -16,8 +16,9 @@
 #include <linux/types.h>
 #include <linux/spinlock.h>
 #include <asm/atomic.h>
-
+#ifdef CONFIG_XEN
 #include <xen/interface/xenoprof.h>
+#endif
  
 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);
-       
+       /* 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. */


Attachment: xen-oprofile-cleanup.patch
Description: Text document

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.