oprofile and ftrace: some trivial patches
Subsystems (3)
cover oprofile and ftrace: some trivial patches
The following patch set contains some cleanups, code reworks and fixes for oprofile. Additional there are 2 trivial patches for ftrace too. This patch set is in preparation of a follow on patch set that ports to the new ring buffer.
Patches are also here:
git://git.kernel.org/pub/scm/linux/kernel/git/rric/oprofile.git next
-Robert
PATCH 1/10 oprofile: comment cleanup
This fixes the coding style of some comments.
--- arch/x86/oprofile/op_model_amd.c | 31 ++++++++++++++++--------------- drivers/oprofile/cpu_buffer.c | 25 ++++++++++++++++--------- 2 files changed, 32 insertions(+), 24 deletions(-)
arch/x86/oprofile/op_model_amd.c +16 -15
@@ -65,8 +65,10 @@ static unsigned long reset_value[NUM_COUNTERS];#define IBS_FETCH_BEGIN 3#define IBS_OP_BEGIN 4 -/* The function interface needs to be fixed, something like add -data. Should then be added to linux/oprofile.h. */ +/* +* The function interface needs to be fixed, something like add +* data. Should then be added to linux/oprofile.h. +*/ extern void oprofile_add_ibs_sample (struct pt_regs *const regs,unsigned int *const ibs_sample,int ibs_code);
@@ -106,7 +108,7 @@ struct ibs_op_sample {/* * unitialize the APIC for the IBS interrupts if needed on AMD Family10h+ -*/ +*/ static void clear_ibs_nmi (void );static int ibs_allowed;/* AMD Family10h and later */
@@ -223,7 +225,7 @@ op_amd_handle_ibs(struct pt_regs * const regs, (unsigned int *)&ibs_fetch, IBS_FETCH_BEGIN); -/*reenable the IRQ */ +/* reenable the IRQ */ rdmsr (MSR_AMD64_IBSFETCHCTL , low, high); high &= ~IBS_FETCH_HIGH_VALID_BIT ; high |=IBS_FETCH_HIGH_ENABLE ;
@@ -331,8 +333,10 @@ static void op_amd_stop(struct op_msrs const * const msrs)unsigned int low, high;int i; -/* Subtle: stop on all counters to avoid race with -* setting our pm callback */ +/* +* Subtle: stop on all counters to avoid race with setting our +* pm callback +*/ for (i =0 ; i <NUM_COUNTERS ; ++i) {if (!reset_value[i])continue ;
@@ -343,13 +347,15 @@ static void op_amd_stop(struct op_msrs const * const msrs)#ifdef CONFIG_OPROFILE_IBS if (ibs_allowed && ibs_config.fetch_enabled) { - low =0 ;/* clear max count and enable */ +/* clear max count and enable */ + low =0 ; high =0 ;wrmsr (MSR_AMD64_IBSFETCHCTL , low, high); }if (ibs_allowed && ibs_config.op_enabled) { - low =0 ;/* clear max count and enable */ +/* clear max count and enable */ + low =0 ; high =0 ;wrmsr (MSR_AMD64_IBSOPCTL , low, high); }
@@ -443,10 +449,7 @@ static int pfm_amd64_setup_eilvt(void)return 0 ; } -/* -* initialize the APIC for the IBS interrupts -* if available (AMD Family10h rev B0 and later) -*/ +/* initialize the APIC for the IBS interrupts if available */ static void setup_ibs (void ) { ibs_allowed =boot_cpu_has (X86_FEATURE_IBS );
@@ -463,9 +466,7 @@ static void setup_ibs(void) } -/* -* unitialize the APIC for the IBS interrupts if needed on AMD Family10h -* rev B0 and later */ +/* uninitialize the APIC for the IBS interrupts if needed */ static void clear_ibs_nmi (void ) {if (ibs_allowed)
drivers/oprofile/cpu_buffer.c +16 -9
@@ -127,9 +127,10 @@ void end_cpu_work(void)/* Resets the cpu buffer to a sane state. */ void cpu_buffer_reset (struct oprofile_cpu_buffer *cpu_buf) { -/* reset these to invalid values; the next sample -* collected will populate the buffer with proper -* values to initialize the buffer +/* +* reset these to invalid values; the next sample collected +* will populate the buffer with proper values to initialize +* the buffer */ cpu_buf->last_is_kernel =-1 ; cpu_buf->last_task =NULL ;
@@ -151,8 +152,10 @@ static void increment_head(struct oprofile_cpu_buffer *b) {unsigned long new_head = b->head_pos +1 ; -/* Ensure anything written to the slot before we -* increment is visible */ +/* +* Ensure anything written to the slot before we increment is +* visible +*/ wmb ();if (new_head < b->buffer_size)
@@ -253,8 +256,10 @@ void oprofile_add_ext_sample(unsigned long pc, struct pt_regs * const regs,if (!oprofile_begin_trace (cpu_buf))return ; -/* if log_sample() fail we can't backtrace since we lost the source -* of this event */ +/* +* if log_sample() fail we can't backtrace since we lost the +* source of this event +*/ if (log_sample (cpu_buf, pc, is_kernel, event)) oprofile_ops.backtrace (regs, backtrace_depth);oprofile_end_trace (cpu_buf);
@@ -338,8 +343,10 @@ void oprofile_add_trace(unsigned long pc)return ; } -/* broken frame can give an eip with the same value as an escape code, -* abort the trace if we get it */ +/* +* broken frame can give an eip with the same value as an +* escape code, abort the trace if we get it +*/ if (pc ==ESCAPE_CODE ) { cpu_buf->tracing =0 ; cpu_buf->backtrace_aborted++;
Signature · 1 line
1.6.0.1
PATCH 2/10 oprofile: update comment for oprofile_add_sample()
In reply to Robert RichterThe cpu argument is no longer part of the parameter list.
--- include/linux/oprofile.h | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
include/linux/oprofile.h +1 -2
@@ -86,8 +86,7 @@ int oprofile_arch_init(struct oprofile_operations * ops);void oprofile_arch_exit (void );/** -* Add a sample. This may be called from any context. Pass -* smp_processor_id() as cpu. +* Add a sample. This may be called from any context. */ void oprofile_add_sample (struct pt_regs *const regs,unsigned long event);
Signature · 1 line
1.6.0.1
PATCH 3/10 oprofile: whitspace changes only
In reply to Robert Richter--- arch/x86/oprofile/op_model_amd.c | 4 ++-- drivers/oprofile/cpu_buffer.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
arch/x86/oprofile/op_model_amd.c +2 -2
@@ -70,8 +70,8 @@ static unsigned long reset_value[NUM_COUNTERS];* data. Should then be added to linux/oprofile.h. */ extern void -oprofile_add_ibs_sample (struct pt_regs *const regs, -unsigned int *const ibs_sample,int ibs_code); +oprofile_add_ibs_sample (struct pt_regs *const regs, +unsigned int *const ibs_sample,int ibs_code);struct ibs_fetch_sample {/* MSRC001_1031 IBS Fetch Linear Address Register */
drivers/oprofile/cpu_buffer.c +2 -2
@@ -277,8 +277,8 @@ void oprofile_add_sample(struct pt_regs * const regs, unsigned long event)#define MAX_IBS_SAMPLE_SIZE 14 -void oprofile_add_ibs_sample (struct pt_regs *const regs, -unsigned int *const ibs_sample,int ibs_code) +void oprofile_add_ibs_sample (struct pt_regs *const regs, +unsigned int *const ibs_sample,int ibs_code) {int is_kernel = !user_mode (regs);struct oprofile_cpu_buffer *cpu_buf = &__get_cpu_var (cpu_buffer);
Signature · 1 line
1.6.0.1
PATCH 4/10 oprofile: fix typo
In reply to Robert Richter--- drivers/oprofile/buffer_sync.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/oprofile/buffer_sync.c +1 -1
@@ -272,7 +272,7 @@ static void increment_tail(struct oprofile_cpu_buffer *b) {unsigned long new_tail = b->tail_pos +1 ; -rmb ();/* be sure fifo pointers are synchromized */ +rmb ();/* be sure fifo pointers are synchronized */ if (new_tail < b->buffer_size) b->tail_pos = new_tail;
Signature · 1 line
1.6.0.1
PATCH 5/10 x86/oprofile: reordering IBS code in op_model_amd.c
In reply to Robert RichterThis is part of the cpu buffer rework.
--- arch/x86/oprofile/op_model_amd.c | 26 +++++++++++++------------- 1 files changed, 13 insertions(+), 13 deletions(-)
arch/x86/oprofile/op_model_amd.c +13 -13
@@ -376,18 +376,7 @@ static void op_amd_shutdown(struct op_msrs const * const msrs) } } -#ifndef CONFIG_OPROFILE_IBS - -/* no IBS support */ - -static int op_amd_init (struct oprofile_operations *ops) -{ -return 0 ; -} - -static void op_amd_exit (void ) {} - -#else +#ifdef CONFIG_OPROFILE_IBS static u8 ibs_eilvt_off;
@@ -531,7 +520,18 @@ static void op_amd_exit(void)clear_ibs_nmi (); } -#endif +#else + +/* no IBS support */ + +static int op_amd_init (struct oprofile_operations *ops) +{ +return 0 ; +} + +static void op_amd_exit (void ) {} + +#endif /* CONFIG_OPROFILE_IBS */ struct op_x86_model_spec const op_amd_spec = { .init = op_amd_init,
Signature · 1 line
1.6.0.1
PATCH 6/10 x86/oprofile: cleanup IBS init/exit functions in op_model_amd.c
In reply to Robert RichterImplementation of pairwise init/exit funcions for IBS and IBS NMI setup. There are also some function renames and the removal of forward function declarations.
--- arch/x86/oprofile/op_model_amd.c | 32 +++++++++++++++++--------------- 1 files changed, 17 insertions(+), 15 deletions(-)
arch/x86/oprofile/op_model_amd.c +17 -15
@@ -106,11 +106,6 @@ struct ibs_op_sample {unsigned int ibs_dc_phys_high; }; -/* -* unitialize the APIC for the IBS interrupts if needed on AMD Family10h+ -*/ -static void clear_ibs_nmi (void ); -static int ibs_allowed;/* AMD Family10h and later */ struct op_ibs_config {
@@ -390,7 +385,7 @@ static inline void apic_clear_ibs_nmi_per_cpu(void *arg)setup_APIC_eilvt_ibs (0 ,APIC_EILVT_MSG_FIX ,1 ); } -static int pfm_amd64_setup_eilvt (void ) +static int init_ibs_nmi (void ) {#define IBSCTL_LVTOFFSETVAL (1 << 8)#define IBSCTL 0x1cc
@@ -438,15 +433,22 @@ static int pfm_amd64_setup_eilvt(void)return 0 ; } +/* uninitialize the APIC for the IBS interrupts if needed */ +static void clear_ibs_nmi (void ) +{ +if (ibs_allowed) +on_each_cpu (apic_clear_ibs_nmi_per_cpu,NULL ,1 ); +} +/* initialize the APIC for the IBS interrupts if available */ -static void setup_ibs (void ) +static void ibs_init (void ) { ibs_allowed =boot_cpu_has (X86_FEATURE_IBS );if (!ibs_allowed)return ; -if (pfm_amd64_setup_eilvt ()) { +if (init_ibs_nmi ()) { ibs_allowed =0 ;return ; }
@@ -454,12 +456,12 @@ static void setup_ibs(void)printk (KERN_INFO "oprofile: AMD IBS detected\n" ); } - -/* uninitialize the APIC for the IBS interrupts if needed */ -static void clear_ibs_nmi (void ) +static void ibs_exit (void ) { -if (ibs_allowed) -on_each_cpu (apic_clear_ibs_nmi_per_cpu,NULL ,1 ); +if (!ibs_allowed) +return ; + +clear_ibs_nmi (); }static int (*create_arch_files)(struct super_block *sb,struct dentry *root);
@@ -509,7 +511,7 @@ static int setup_ibs_files(struct super_block *sb, struct dentry *root)static int op_amd_init (struct oprofile_operations *ops) { -setup_ibs (); +ibs_init (); create_arch_files = ops->create_files; ops->create_files = setup_ibs_files;return 0 ;
@@ -517,7 +519,7 @@ static int op_amd_init(struct oprofile_operations *ops)static void op_amd_exit (void ) { -clear_ibs_nmi (); +ibs_exit (); }#else
Signature · 1 line
1.6.0.1
PATCH 7/10 oprofile: implement switch/case in buffer_sync.c
In reply to Robert Richter--- drivers/oprofile/buffer_sync.c | 22 ++++++++++++++-------- 1 files changed, 14 insertions(+), 8 deletions(-)
drivers/oprofile/buffer_sync.c +14 -8
@@ -561,6 +561,7 @@ void sync_buffer(int cpu) {struct oprofile_cpu_buffer *cpu_buf = &per_cpu (cpu_buffer, cpu);struct mm_struct *mm =NULL ; +struct mm_struct *oldmm;struct task_struct *new;unsigned long cookie =0 ;int in_kernel =1 ;
@@ -586,34 +587,39 @@ void sync_buffer(int cpu)struct op_sample *s = &cpu_buf->buffer[cpu_buf->tail_pos];if (is_code (s->eip)) { -if (s->event <=CPU_IS_KERNEL ) { +switch (s->event) { +case 0 : +case CPU_IS_KERNEL :/* kernel/userspace switch */ in_kernel = s->event;if (state == sb_buffer_start) state = sb_sample_start;add_kernel_ctx_switch (s->event); - }else if (s->event ==CPU_TRACE_BEGIN ) { +break ; +case CPU_TRACE_BEGIN : state = sb_bt_start;add_trace_begin (); +break ;#ifdef CONFIG_OPROFILE_IBS - }else if (s->event ==IBS_FETCH_BEGIN ) { +case IBS_FETCH_BEGIN : state = sb_bt_start;add_ibs_begin (cpu_buf,IBS_FETCH_CODE , mm); - }else if (s->event ==IBS_OP_BEGIN ) { +break ; +case IBS_OP_BEGIN : state = sb_bt_start;add_ibs_begin (cpu_buf,IBS_OP_CODE , mm); +break ;#endif - }else { -struct mm_struct *oldmm = mm; - +default :/* userspace context switch */ + oldmm = mm; new = (struct task_struct *)s->event; -release_mm (oldmm); mm =take_tasks_mm (new);if (mm != oldmm) cookie =get_exec_dcookie (mm);add_user_ctx_switch (new, cookie); +break ; } }else if (state >= sb_bt_start && !add_sample (mm, s, in_kernel)) {
Signature · 1 line
1.6.0.1
PATCH 8/10 oprofile: set values to default when creating oprofilefs
In reply to Robert RichterThis patch restores default values for:
/dev/oprofile/cpu_buffer_size/dev/oprofile/buffer_watershed/dev/oprofile/buffer_size
when creating the oprofilefs:
# opcontrol --deinit # opcontrol --init # cat /dev/oprofile/cpu_buffer_size 8192 # echo 5123 > /dev/oprofile/cpu_buffer_size # cat /dev/oprofile/cpu_buffer_size 5123 # opcontrol --deinit # opcontrol --init # cat /dev/oprofile/cpu_buffer_size 8192 # opcontrol --deinit
This sets the values in a defined state. Before, there was no way to restore the defaults without rebooting the system or reloading the module.
--- drivers/oprofile/oprofile_files.c | 15 ++++++++++++--- 1 files changed, 12 insertions(+), 3 deletions(-)
drivers/oprofile/oprofile_files.c +12 -3
@@ -14,9 +14,13 @@#include "oprofile_stats.h" #include "oprof.h" -unsigned long fs_buffer_size =131072 ; -unsigned long fs_cpu_buffer_size =8192 ; -unsigned long fs_buffer_watershed =32768 ;/* FIXME: tune */ +#define FS_BUFFER_SIZE_DEFAULT 131072 +#define FS_CPU_BUFFER_SIZE_DEFAULT 8192 +#define FS_BUFFER_WATERSHED_DEFAULT 32768/* FIXME: tune */ + +unsigned long fs_buffer_size; +unsigned long fs_cpu_buffer_size; +unsigned long fs_buffer_watershed;static ssize_t depth_read (struct file *file,char __user *buf,size_t count,loff_t *offset) {
@@ -120,6 +124,11 @@ static const struct file_operations dump_fops = {void oprofile_create_files (struct super_block *sb,struct dentry *root) { +/* reinitialize default values */ + fs_buffer_size =FS_BUFFER_SIZE_DEFAULT ; + fs_cpu_buffer_size =FS_CPU_BUFFER_SIZE_DEFAULT ; + fs_buffer_watershed =FS_BUFFER_WATERSHED_DEFAULT ; +oprofilefs_create_file (sb, root,"enable" , &enable_fops);oprofilefs_create_file_perm (sb, root,"dump" , &dump_fops,0666 );oprofilefs_create_file (sb, root,"buffer" , &event_buffer_fops);
Signature · 1 line
1.6.0.1
Re: [PATCH 08/10] oprofile: set values to default when creating oprofilefs
Quoted 38 lines · On Thu, 11 Dec 2008 16:04:44 +0100 Robert Richter <[email protected]>…
This patch restores default values for:
/dev/oprofile/cpu_buffer_size/dev/oprofile/buffer_watershed/dev/oprofile/buffer_sizewhen creating the oprofilefs:
# opcontrol --deinit # opcontrol --init # cat /dev/oprofile/cpu_buffer_size 8192 # echo 5123 > /dev/oprofile/cpu_buffer_size # cat /dev/oprofile/cpu_buffer_size 5123 # opcontrol --deinit # opcontrol --init # cat /dev/oprofile/cpu_buffer_size 8192 # opcontrol --deinitThis sets the values in a defined state. Before, there was no way to restore the defaults without rebooting the system or reloading the module.
Signed-off-by Robert Richter <[email protected]>--- drivers/oprofile/oprofile_files.c | 15 ++++++++++++--- 1 files changed, 12 insertions(+), 3 deletions(-)drivers/oprofile/oprofile_files.c +0
-0@@ -14,9 +14,13 @@#include "oprofile_stats.h" #include "oprof.h"
drivers/oprofile/oprofile_files.c line 23
Quoted 10 lines
drivers/oprofile/oprofile_files.c +7
-3-unsigned long fs_buffer_size =131072 ; -unsigned long fs_cpu_buffer_size =8192 ; -unsigned long fs_buffer_watershed =32768 ;/* FIXME: tune */ +#define FS_BUFFER_SIZE_DEFAULT 131072 +#define FS_CPU_BUFFER_SIZE_DEFAULT 8192 +#define FS_BUFFER_WATERSHED_DEFAULT 32768/* FIXME: tune */ + +unsigned long fs_buffer_size; +unsigned long fs_cpu_buffer_size; +unsigned long fs_buffer_watershed;
These were poorly chosen kernel-wide identifiers.
Quoted 4 lines
drivers/oprofile/oprofile_files.c +0
-0static ssize_t depth_read (struct file *file,char __user *buf,size_t count,loff_t *offset) {@@ -120,6 +124,11 @@ static const struct file_operations dump_fops = {
drivers/oprofile/oprofile_files.c static const struct file_operations dump_fops = { · line 134
Quoted 10 lines
drivers/oprofile/oprofile_files.c +5
-0void oprofile_create_files (struct super_block *sb,struct dentry *root) { +/* reinitialize default values */ + fs_buffer_size =FS_BUFFER_SIZE_DEFAULT ; + fs_cpu_buffer_size =FS_CPU_BUFFER_SIZE_DEFAULT ; + fs_buffer_watershed =FS_BUFFER_WATERSHED_DEFAULT ; +oprofilefs_create_file (sb, root,"enable" , &enable_fops);oprofilefs_create_file_perm (sb, root,"dump" , &dump_fops,0666 );oprofilefs_create_file (sb, root,"buffer" , &event_buffer_fops);
afacit oprofile_create_files() only gets run when the module is loaded, so this patch is a no-op?
Re: [PATCH 08/10] oprofile: set values to default when creating oprofilefs
Quoted 5 lines · Andrew Morton
drivers/oprofile/oprofile_files.c line 23
Quoted 3 lines
drivers/oprofile/oprofile_files.c +3
-0+unsigned long fs_buffer_size; +unsigned long fs_cpu_buffer_size; +unsigned long fs_buffer_watershed;These were poorly chosen kernel-wide identifiers.
Right, didn't notice that. Will change this.
Quoted 4 lines
Quoted 4 lines
static
ssize_tdepth_read(struct file *file, char __user *buf, size_t count, loff_t *offset){(quoted diff) +0
-0@@ -120,6 +124,11 @@ static const struct file_operations dump_fops = {
Quoted 13 lines
drivers/oprofile/oprofile_files.c static const struct file_operations dump_fops = { · line 134
Quoted 10 lines
drivers/oprofile/oprofile_files.c +5
-0void oprofile_create_files (struct super_block *sb,struct dentry *root) { +/* reinitialize default values */ + fs_buffer_size =FS_BUFFER_SIZE_DEFAULT ; + fs_cpu_buffer_size =FS_CPU_BUFFER_SIZE_DEFAULT ; + fs_buffer_watershed =FS_BUFFER_WATERSHED_DEFAULT ; +oprofilefs_create_file (sb, root,"enable" , &enable_fops);oprofilefs_create_file_perm (sb, root,"dump" , &dump_fops,0666 );oprofilefs_create_file (sb, root,"buffer" , &event_buffer_fops);afacit
oprofile_create_files()only gets run when the module is loaded, so this patch is a no-op?
This code runs when oprofilefs is mounted. This happens typically in an opcontrol --init/--deinit sequence. Before, the previous values would have been used after mounting again. Now, default values are restored.
-Robert
Signature · 3 lines
Advanced Micro Devices, Inc. Operating System Research Center email: [email protected]
PATCH 9/10 ring_buffer: update description for ring_buffer_alloc()
In reply to Robert RichterTrivial patch.
--- kernel/trace/ring_buffer.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/trace/ring_buffer.c +1 -1
@@ -381,7 +381,7 @@ extern int ring_buffer_page_too_big(void);/** * ring_buffer_alloc - allocate a new ring_buffer -* @size: the size in bytes that is needed. +* @size: the size in bytes per cpu that is needed. * @flags: attributes to set for the ring buffer. * * Currently the only flag that is available is the RB_FL_OVERWRITE
Signature · 1 line
1.6.0.1
PATCH 10/10 ftrace: remove unused function arg in trace_iterator_increment()
In reply to Robert RichterThis removes the unused cpu function parameter.
--- kernel/trace/trace.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
kernel/trace/trace.c +2 -2
@@ -914,7 +914,7 @@ enum trace_file_type { TRACE_FILE_LAT_FMT = 1, }; -static void trace_iterator_increment (struct trace_iterator *iter,int cpu) +static void trace_iterator_increment (struct trace_iterator *iter) {/* Don't allow ftrace to trace into the ring buffers */ ftrace_disable_cpu ();
@@ -993,7 +993,7 @@ static void *find_next_entry_inc(struct trace_iterator *iter) iter->ent =__find_next_entry (iter, &iter->cpu, &iter->ts);if (iter->ent) -trace_iterator_increment (iter, iter->cpu); +trace_iterator_increment (iter);return iter->ent ? iter :NULL ; }
Signature · 1 line
1.6.0.1