Skip to content

Commit bd7dc46

Browse files
author
Robert Richter
committed
oprofile: add op_cpu_buffer_get_data()
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>
1 parent d9928c2 commit bd7dc46

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

‎drivers/oprofile/buffer_sync.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ void sync_buffer(int cpu)
524524
{
525525
struct mm_struct *mm = NULL;
526526
struct mm_struct *oldmm;
527+
unsigned long val;
527528
struct task_struct *new;
528529
unsigned long cookie = 0;
529530
int in_kernel = 1;
@@ -559,10 +560,11 @@ void sync_buffer(int cpu)
559560
state = sb_sample_start;
560561
add_kernel_ctx_switch(flags & IS_KERNEL);
561562
}
562-
if (flags & USER_CTX_SWITCH) {
563+
if (flags & USER_CTX_SWITCH
564+
&& op_cpu_buffer_get_data(&entry, &val)) {
563565
/* userspace context switch */
566+
new = (struct task_struct *)val;
564567
oldmm = mm;
565-
new = (struct task_struct *)sample->data[0];
566568
release_mm(oldmm);
567569
mm = take_tasks_mm(new);
568570
if (mm != oldmm)

‎drivers/oprofile/cpu_buffer.h‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,26 @@ int op_cpu_buffer_add_data(struct op_entry *entry, unsigned long val)
9090
return entry->size;
9191
}
9292

93+
/* returns the size of data in the entry */
94+
static inline
95+
int op_cpu_buffer_get_size(struct op_entry *entry)
96+
{
97+
return entry->size;
98+
}
99+
100+
/* returns 0 if empty or the size of data including the current value */
101+
static inline
102+
int op_cpu_buffer_get_data(struct op_entry *entry, unsigned long *val)
103+
{
104+
int size = entry->size;
105+
if (!size)
106+
return 0;
107+
*val = *entry->data;
108+
entry->size--;
109+
entry->data++;
110+
return size;
111+
}
112+
93113
/* extra data flags */
94114
#define KERNEL_CTX_SWITCH (1UL << 0)
95115
#define IS_KERNEL (1UL << 1)

0 commit comments

Comments
 (0)