瀏覽代碼

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>
Robert Richter 16 年之前
父節點
當前提交
bd7dc46f77
共有 2 個文件被更改,包括 24 次插入2 次删除
  1. 4 2
      drivers/oprofile/buffer_sync.c
  2. 20 0
      drivers/oprofile/cpu_buffer.h

+ 4 - 2
drivers/oprofile/buffer_sync.c

@@ -524,6 +524,7 @@ void sync_buffer(int cpu)
 {
 {
 	struct mm_struct *mm = NULL;
 	struct mm_struct *mm = NULL;
 	struct mm_struct *oldmm;
 	struct mm_struct *oldmm;
+	unsigned long val;
 	struct task_struct *new;
 	struct task_struct *new;
 	unsigned long cookie = 0;
 	unsigned long cookie = 0;
 	int in_kernel = 1;
 	int in_kernel = 1;
@@ -559,10 +560,11 @@ void sync_buffer(int cpu)
 					state = sb_sample_start;
 					state = sb_sample_start;
 				add_kernel_ctx_switch(flags & IS_KERNEL);
 				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 */
 				/* userspace context switch */
+				new = (struct task_struct *)val;
 				oldmm = mm;
 				oldmm = mm;
-				new = (struct task_struct *)sample->data[0];
 				release_mm(oldmm);
 				release_mm(oldmm);
 				mm = take_tasks_mm(new);
 				mm = take_tasks_mm(new);
 				if (mm != oldmm)
 				if (mm != oldmm)

+ 20 - 0
drivers/oprofile/cpu_buffer.h

@@ -90,6 +90,26 @@ int op_cpu_buffer_add_data(struct op_entry *entry, unsigned long val)
 	return entry->size;
 	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 */
 /* extra data flags */
 #define KERNEL_CTX_SWITCH	(1UL << 0)
 #define KERNEL_CTX_SWITCH	(1UL << 0)
 #define IS_KERNEL		(1UL << 1)
 #define IS_KERNEL		(1UL << 1)