Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

oprofile: change cpu_buffer from array to per_cpu variable

Change cpu_buffer from array to per_cpu variable in oprofile functions.

[akpm@linux-foundation.org: coding-style fixes]
Cc: Philippe Elie <phil.el@wanadoo.fr>
Signed-off-by: Mike Travis <travis@sgi.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Mike Travis and committed by
Linus Torvalds
608dfddd 7ae9392c

+13 -12
+1 -1
drivers/oprofile/buffer_sync.c
··· 491 491 */ 492 492 void sync_buffer(int cpu) 493 493 { 494 - struct oprofile_cpu_buffer * cpu_buf = &cpu_buffer[cpu]; 494 + struct oprofile_cpu_buffer *cpu_buf = &per_cpu(cpu_buffer, cpu); 495 495 struct mm_struct *mm = NULL; 496 496 struct task_struct * new; 497 497 unsigned long cookie = 0;
+8 -8
drivers/oprofile/cpu_buffer.c
··· 27 27 #include "buffer_sync.h" 28 28 #include "oprof.h" 29 29 30 - struct oprofile_cpu_buffer cpu_buffer[NR_CPUS] __cacheline_aligned; 30 + DEFINE_PER_CPU_SHARED_ALIGNED(struct oprofile_cpu_buffer, cpu_buffer); 31 31 32 32 static void wq_sync_buffer(struct work_struct *work); 33 33 ··· 39 39 int i; 40 40 41 41 for_each_online_cpu(i) 42 - vfree(cpu_buffer[i].buffer); 42 + vfree(per_cpu(cpu_buffer, i).buffer); 43 43 } 44 44 45 45 int alloc_cpu_buffers(void) ··· 49 49 unsigned long buffer_size = fs_cpu_buffer_size; 50 50 51 51 for_each_online_cpu(i) { 52 - struct oprofile_cpu_buffer * b = &cpu_buffer[i]; 52 + struct oprofile_cpu_buffer *b = &per_cpu(cpu_buffer, i); 53 53 54 54 b->buffer = vmalloc_node(sizeof(struct op_sample) * buffer_size, 55 55 cpu_to_node(i)); ··· 83 83 work_enabled = 1; 84 84 85 85 for_each_online_cpu(i) { 86 - struct oprofile_cpu_buffer * b = &cpu_buffer[i]; 86 + struct oprofile_cpu_buffer *b = &per_cpu(cpu_buffer, i); 87 87 88 88 /* 89 89 * Spread the work by 1 jiffy per cpu so they dont all ··· 100 100 work_enabled = 0; 101 101 102 102 for_each_online_cpu(i) { 103 - struct oprofile_cpu_buffer * b = &cpu_buffer[i]; 103 + struct oprofile_cpu_buffer *b = &per_cpu(cpu_buffer, i); 104 104 105 105 cancel_delayed_work(&b->work); 106 106 } ··· 227 227 void oprofile_add_ext_sample(unsigned long pc, struct pt_regs * const regs, 228 228 unsigned long event, int is_kernel) 229 229 { 230 - struct oprofile_cpu_buffer * cpu_buf = &cpu_buffer[smp_processor_id()]; 230 + struct oprofile_cpu_buffer *cpu_buf = &__get_cpu_var(cpu_buffer); 231 231 232 232 if (!backtrace_depth) { 233 233 log_sample(cpu_buf, pc, is_kernel, event); ··· 254 254 255 255 void oprofile_add_pc(unsigned long pc, int is_kernel, unsigned long event) 256 256 { 257 - struct oprofile_cpu_buffer * cpu_buf = &cpu_buffer[smp_processor_id()]; 257 + struct oprofile_cpu_buffer *cpu_buf = &__get_cpu_var(cpu_buffer); 258 258 log_sample(cpu_buf, pc, is_kernel, event); 259 259 } 260 260 261 261 void oprofile_add_trace(unsigned long pc) 262 262 { 263 - struct oprofile_cpu_buffer * cpu_buf = &cpu_buffer[smp_processor_id()]; 263 + struct oprofile_cpu_buffer *cpu_buf = &__get_cpu_var(cpu_buffer); 264 264 265 265 if (!cpu_buf->tracing) 266 266 return;
+2 -1
drivers/oprofile/cpu_buffer.h
··· 14 14 #include <linux/spinlock.h> 15 15 #include <linux/workqueue.h> 16 16 #include <linux/cache.h> 17 + #include <linux/sched.h> 17 18 18 19 struct task_struct; 19 20 ··· 48 47 struct delayed_work work; 49 48 } ____cacheline_aligned; 50 49 51 - extern struct oprofile_cpu_buffer cpu_buffer[]; 50 + DECLARE_PER_CPU(struct oprofile_cpu_buffer, cpu_buffer); 52 51 53 52 void cpu_buffer_reset(struct oprofile_cpu_buffer * cpu_buf); 54 53
+2 -2
drivers/oprofile/oprofile_stats.c
··· 23 23 int i; 24 24 25 25 for_each_possible_cpu(i) { 26 - cpu_buf = &cpu_buffer[i]; 26 + cpu_buf = &per_cpu(cpu_buffer, i); 27 27 cpu_buf->sample_received = 0; 28 28 cpu_buf->sample_lost_overflow = 0; 29 29 cpu_buf->backtrace_aborted = 0; ··· 49 49 return; 50 50 51 51 for_each_possible_cpu(i) { 52 - cpu_buf = &cpu_buffer[i]; 52 + cpu_buf = &per_cpu(cpu_buffer, i); 53 53 snprintf(buf, 10, "cpu%d", i); 54 54 cpudir = oprofilefs_mkdir(sb, dir, buf); 55 55