]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
oprofile: add op_cpu_buffer_get_data()
authorRobert Richter <robert.richter@amd.com>
Tue, 6 Jan 2009 02:56:50 +0000 (03:56 +0100)
committerRobert Richter <robert.richter@amd.com>
Wed, 7 Jan 2009 21:45:46 +0000 (22:45 +0100)
This function provides access to attached data of a sample. It returns
the size of data including the current value. Also,
op_cpu_buffer_get_size() is available to check if there is data
attached.

Signed-off-by: Robert Richter <robert.richter@amd.com>
drivers/oprofile/buffer_sync.c
drivers/oprofile/cpu_buffer.h

index d969bb13a25281b875e9c4726d7a3fb51ff663ac..f9031d31eeb7eceab4872b2496c8f13d986e1e04 100644 (file)
@@ -524,6 +524,7 @@ void sync_buffer(int cpu)
 {
        struct mm_struct *mm = NULL;
        struct mm_struct *oldmm;
+       unsigned long val;
        struct task_struct *new;
        unsigned long cookie = 0;
        int in_kernel = 1;
@@ -559,10 +560,11 @@ void sync_buffer(int cpu)
                                        state = sb_sample_start;
                                add_kernel_ctx_switch(flags & IS_KERNEL);
                        }
-                       if (flags & USER_CTX_SWITCH) {
+                       if (flags & USER_CTX_SWITCH
+                           && op_cpu_buffer_get_data(&entry, &val)) {
                                /* userspace context switch */
+                               new = (struct task_struct *)val;
                                oldmm = mm;
-                               new = (struct task_struct *)sample->data[0];
                                release_mm(oldmm);
                                mm = take_tasks_mm(new);
                                if (mm != oldmm)
index e178dd2799c4f387f9fbff31805cbc34301792c6..f343760465737d7a99a3db25dbf2cd16656e4a41 100644 (file)
@@ -90,6 +90,26 @@ int op_cpu_buffer_add_data(struct op_entry *entry, unsigned long val)
        return entry->size;
 }
 
+/* returns the size of data in the entry */
+static inline
+int op_cpu_buffer_get_size(struct op_entry *entry)
+{
+       return entry->size;
+}
+
+/* returns 0 if empty or the size of data including the current value */
+static inline
+int op_cpu_buffer_get_data(struct op_entry *entry, unsigned long *val)
+{
+       int size = entry->size;
+       if (!size)
+               return 0;
+       *val = *entry->data;
+       entry->size--;
+       entry->data++;
+       return size;
+}
+
 /* extra data flags */
 #define KERNEL_CTX_SWITCH      (1UL << 0)
 #define IS_KERNEL              (1UL << 1)