oprofile: Performance counter multiplexing
Get series with b4
b4 am [email protected]Versions newest first
- v1 Latest26 patches 15 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/26 | x86/oprofile: Rework and simplify nmi_cpu_setup()arch/ | +3 | 0 replies | |
| 2/26 | x86/oprofile: Whitespaces changes onlyarch/ arch/ arch/ +1 more | +20 | 0 replies | |
| 3/26 | oprofile: Implement performance counter multiplexingarch/ arch/ arch/ +9 more | +415 | 0 replies | |
| 4/26 | x86/oprofile: Fix usage of NUM_CONTROLS/NUM_COUNTERS macrosarch/ | +2 | 0 replies | |
| 5/26 | x86/oprofile: Use per_cpu() instead of __get_cpu_var()arch/ | +2 | 0 replies | |
| 6/26 | x86/oprofile: Fix initialization of switch_indexarch/ | +9 | 0 replies | |
| 7/26 | oprofile: oprofile_set_timeout(), return with error for invalid argsdrivers/ | +8 | 0 replies | |
| 8/26 | oprofile: Rename variable timeout_jiffies and move to oprofile_files.cdrivers/ drivers/ drivers/ | +9 | 0 replies | |
| 9/26 | oprofile: Remove oprofile_multiplexing_init()drivers/ drivers/ | +2 | 0 replies | |
| 10/26 | oprofile: Grouping multiplexing code in oprof.cdrivers/ | +49 | 0 replies | |
| 11/26 | oprofile: Introduce op_x86_phys_to_virt()arch/ arch/ arch/ | +55 | 0 replies | |
| 12/26 | oprofile: Grouping multiplexing code in op_model_amd.carch/ | +41 | 0 replies | |
| 13/26 | x86/oprofile: Implement multiplexing setup/shutdown functionsarch/ | +40 | 0 replies | |
| 14/26 | x86/oprofile: Moving nmi_setup_cpu_mux() in nmi_int.carch/ | +19 | 0 replies | |
| 15/26 | x86/oprofile: Moving nmi_cpu_save/restore_mpx_registers() in nmi_int.carch/ | +24 | 0 replies | |
| 16/26 | x86/oprofile: Moving nmi_cpu_switch() in nmi_int.carch/ | +70 | 0 replies | |
| 17/26 | x86/oprofile: Remove const qualifier from struct op_x86_model_specarch/ arch/ arch/ +2 more | +10 | 0 replies | |
| 18/26 | x86/oprofile: Remove unused num_virt_controls from struct op_x86_model_specarch/ arch/ arch/ +1 more | +0 | 0 replies | |
| 19/26 | x86/oprofile: Modify initialization of num_virt_countersarch/ arch/ arch/ | +3 | 0 replies | |
| 20/26 | x86/oprofile: Add function has_mux() to check multiplexing supportarch/ | +18 | 0 replies | |
| 21/26 | x86/oprofile: Enable multiplexing only if the model supports itarch/ | +9 | 0 replies | |
| 22/26 | x86/oprofile: Implement mux_clone()arch/ | +23 | 0 replies | |
| 23/26 | oprofile: Adding switch counter to oprofile statistic variablesarch/ drivers/ drivers/ +1 more | +8 | 0 replies | |
| 24/26 | x86/oprofile: Implement op_x86_virt_to_phys()arch/ arch/ arch/ | +8 | 0 replies | |
| 25/26 | x86/oprofile: Add counter reservation check for virtual countersarch/ | +1 | 0 replies | |
| 26/26 | x86/oprofile: Small coding style fixesarch/ | +2 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [PATCH 0/26] oprofile: Performance counter multiplexing
This patch series introduces performance counter multiplexing for oprofile.
The number of hardware counters is limited. The multiplexing feature enables OProfile to gather more events than counters are provided by the hardware. This is realized by switching between events at an user specified time interval.
A new file (/dev/oprofile/time_slice) is added for the user to specify the timer interval in ms. If the number of events to profile is higher than the number of hardware counters available, the patch will schedule a work queue that switches the event counter and re-writes the different sets of values into it. The switching mechanism needs to be implemented for each architecture to support multiplexing. This patch series only implements AMD CPU support, but multiplexing can be easily extended for other models and architectures.
The patch set includes the initial patch from Jason Yeh and many code improvements and reworks on top. It evolved over time and documents its development. Thus, for review also the enclosed overall diff might be useful.
The patches can be pulled from:
git://git.kernel.org/pub/scm/linux/kernel/git/rric/oprofile.git mux
-Robert
The following changes since commit 8045a4c293d36c61656a20d581b11f7f0cd7acd5:
Robert Richter (1):
x86/oprofile: Fix cast of counter value
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/rric/oprofile.git mux
Jason Yeh (1):
oprofile: Implement performance counter multiplexing
Robert Richter (25):
x86/oprofile: Rework and simplify nmi_cpu_setup() x86/oprofile: Whitespaces changes only
x86/oprofile: Fix usage of NUM_CONTROLS/NUM_COUNTERS macros x86/oprofile: Use per_cpu() instead of __get_cpu_var() x86/oprofile: Fix initialization of switch_index
oprofile: oprofile_set_timeout(), return with error for invalid args
oprofile: Rename variable timeout_jiffies and move to oprofile_files.c
oprofile: Remove oprofile_multiplexing_init()
oprofile: Grouping multiplexing code in oprof.c
oprofile: Introduce op_x86_phys_to_virt()
oprofile: Grouping multiplexing code in op_model_amd.c x86/oprofile: Implement multiplexing setup/shutdown functions x86/oprofile: Moving nmi_setup_cpu_mux() in nmi_int.c x86/oprofile: Moving nmi_cpu_save/restore_mpx_registers() in nmi_int.c x86/oprofile: Moving nmi_cpu_switch() in nmi_int.c x86/oprofile: Remove const qualifier from struct op_x86_model_spec x86/oprofile: Remove unused num_virt_controls from struct op_x86_model_spec x86/oprofile: Modify initialization of num_virt_counters x86/oprofile: Add function has_mux() to check multiplexing support x86/oprofile: Enable multiplexing only if the model supports it x86/oprofile: Implement mux_clone()
oprofile: Adding switch counter to oprofile statistic variables x86/oprofile: Implement op_x86_virt_to_phys()
x86/oprofile: Add counter reservation check for virtual counters x86/oprofile: Small coding style fixes
arch/Kconfig | 12 ++ arch/x86/oprofile/nmi_int.c | 307 +++++++++++++++++++++++++++++-------- arch/x86/oprofile/op_counter.h | 2 +- arch/x86/oprofile/op_model_amd.c | 127 ++++++++++++---- arch/x86/oprofile/op_model_p4.c | 12 +- arch/x86/oprofile/op_model_ppro.c | 10 +- arch/x86/oprofile/op_x86_model.h | 16 ++- drivers/oprofile/oprof.c | 71 +++++++++- drivers/oprofile/oprof.h | 3 + drivers/oprofile/oprofile_files.c | 46 ++++++ drivers/oprofile/oprofile_stats.c | 5 + drivers/oprofile/oprofile_stats.h | 1 + include/linux/oprofile.h | 3 + 13 files changed, 501 insertions(+), 114 deletions(-)
arch/Kconfig +12 -0
@@ -30,6 +30,18 @@ config OPROFILE_IBS If unsure, say N. +config OPROFILE_EVENT_MULTIPLEX + bool "OProfile multiplexing support (EXPERIMENTAL)" + default n + depends on OPROFILE && X86 + help + The number of hardware counters is limited. The multiplexing + feature enables OProfile to gather more events than counters + are provided by the hardware. This is realized by switching + between events at an user specified time interval. + + If unsure, say N. + config HAVE_OPROFILE bool
arch/x86/oprofile/nmi_int.c +239 -68
437 lines not on this page · raw message
arch/x86/oprofile/op_counter.h +1 -1
@@ -10,7 +10,7 @@#ifndef OP_COUNTER_H #define OP_COUNTER_H -#define OP_MAX_COUNTER 8 +#define OP_MAX_COUNTER 32/* Per-perfctr configuration as set via * oprofilefs.
arch/x86/oprofile/op_model_amd.c +98 -29
218 lines not on this page · raw message
arch/x86/oprofile/op_model_p4.c +6 -6
@@ -558,7 +558,7 @@ static void p4_setup_ctrs(struct op_x86_model_spec const *model, }/* clear the cccrs we will use */ -for (i =0 ; i < num_counters ; i++) { +for (i =0 ; i < num_counters; i++) {if (unlikely (!msrs->controls[i].addr))continue ;rdmsr (p4_counters[VIRT_CTR (stag, i)].cccr_address, low, high);
@@ -575,7 +575,7 @@ static void p4_setup_ctrs(struct op_x86_model_spec const *model, }/* setup all counters */ -for (i =0 ; i < num_counters ; ++i) { +for (i =0 ; i < num_counters; ++i) {if (counter_config[i].enabled && msrs->controls[i].addr) { reset_value[i] = counter_config[i].count;pmc_setup_one_p4_counter (i);
@@ -678,7 +678,7 @@ static void p4_shutdown(struct op_msrs const * const msrs) {int i; -for (i =0 ; i < num_counters ; ++i) { +for (i =0 ; i < num_counters; ++i) {if (msrs->counters[i].addr)release_perfctr_nmi (msrs->counters[i].addr); }
@@ -687,7 +687,7 @@ static void p4_shutdown(struct op_msrs const * const msrs)* conjunction with the counter registers (hence the starting offset). * This saves a few bits. */ -for (i = num_counters ; i < num_controls ; ++i) { +for (i = num_counters; i < num_controls; ++i) {if (msrs->controls[i].addr)release_evntsel_nmi (msrs->controls[i].addr); }
@@ -695,7 +695,7 @@ static void p4_shutdown(struct op_msrs const * const msrs)#ifdef CONFIG_SMP -struct op_x86_model_spec const op_p4_ht2_spec = { +struct op_x86_model_spec op_p4_ht2_spec = { .num_counters =NUM_COUNTERS_HT2 , .num_controls =NUM_CONTROLS_HT2 , .fill_in_addresses = &p4_fill_in_addresses,
@@ -707,7 +707,7 @@ struct op_x86_model_spec const op_p4_ht2_spec = { };#endif -struct op_x86_model_spec const op_p4_spec = { +struct op_x86_model_spec op_p4_spec = { .num_counters =NUM_COUNTERS_NON_HT , .num_controls =NUM_CONTROLS_NON_HT , .fill_in_addresses = &p4_fill_in_addresses,
arch/x86/oprofile/op_model_ppro.c +5 -5
@@ -81,7 +81,7 @@ static void ppro_setup_ctrs(struct op_x86_model_spec const *model, }/* clear all counters */ -for (i =0 ; i < num_counters; ++i) { +for (i =0 ; i < num_counters; ++i) {if (unlikely (!msrs->controls[i].addr))continue ;rdmsrl (msrs->controls[i].addr, val);
@@ -125,7 +125,7 @@ static int ppro_check_ctrs(struct pt_regs * const regs,if (unlikely (!reset_value)) goto out; -for (i =0 ; i < num_counters; ++i) { +for (i =0 ; i < num_counters; ++i) {if (!reset_value[i])continue ;rdmsrl (msrs->counters[i].addr, val);
@@ -188,11 +188,11 @@ static void ppro_shutdown(struct op_msrs const * const msrs) {int i; -for (i =0 ; i < num_counters ; ++i) { +for (i =0 ; i < num_counters; ++i) {if (msrs->counters[i].addr)release_perfctr_nmi (MSR_P6_PERFCTR0 + i); } -for (i =0 ; i < num_counters ; ++i) { +for (i =0 ; i < num_counters; ++i) {if (msrs->controls[i].addr)release_evntsel_nmi (MSR_P6_EVNTSEL0 + i); }
@@ -203,7 +203,7 @@ static void ppro_shutdown(struct op_msrs const * const msrs) } -struct op_x86_model_spec const op_ppro_spec = { +struct op_x86_model_spec op_ppro_spec = { .num_counters =2 , .num_controls =2 , .reserved =MSR_PPRO_EVENTSEL_RESERVED ,
arch/x86/oprofile/op_x86_model.h +12 -4
@@ -23,6 +23,7 @@ struct op_msr {struct op_msrs {struct op_msr *counters;struct op_msr *controls; +struct op_msr *multiplex; };struct pt_regs ;
@@ -35,6 +36,7 @@ struct oprofile_operations;struct op_x86_model_spec {unsigned int num_counters;unsigned int num_controls; +unsigned int num_virt_counters;u64 reserved;u16 event_mask;int (*init)(struct oprofile_operations *ops);
@@ -47,17 +49,23 @@ struct op_x86_model_spec {void (*start)(struct op_msrs const *const msrs);void (*stop)(struct op_msrs const *const msrs);void (*shutdown)(struct op_msrs const *const msrs); +#ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX +void (*switch_ctrl)(struct op_x86_model_spec const *model, +struct op_msrs const *const msrs); +#endif };struct op_counter_config ;extern u64 op_x86_get_ctrl (struct op_x86_model_spec const *model,struct op_counter_config *counter_config); +extern int op_x86_phys_to_virt (int phys); +extern int op_x86_virt_to_phys (int virt); -extern struct op_x86_model_spec const op_ppro_spec; -extern struct op_x86_model_spec const op_p4_spec; -extern struct op_x86_model_spec const op_p4_ht2_spec; -extern struct op_x86_model_spec const op_amd_spec; +extern struct op_x86_model_spec op_ppro_spec; +extern struct op_x86_model_spec op_p4_spec; +extern struct op_x86_model_spec op_p4_ht2_spec; +extern struct op_x86_model_spec op_amd_spec;extern struct op_x86_model_spec op_arch_perfmon_spec;#endif /* OP_X86_MODEL_H */
drivers/oprofile/oprof.c +70 -1
101 lines not on this page · raw message
drivers/oprofile/oprof.h +3 -0
@@ -24,6 +24,8 @@ struct oprofile_operations;extern unsigned long oprofile_buffer_size;extern unsigned long oprofile_cpu_buffer_size;extern unsigned long oprofile_buffer_watershed; +extern unsigned long oprofile_time_slice; +extern struct oprofile_operations oprofile_ops;extern unsigned long oprofile_started;extern unsigned long oprofile_backtrace_depth;
@@ -35,5 +37,6 @@ void oprofile_create_files(struct super_block *sb, struct dentry *root);void oprofile_timer_init (struct oprofile_operations *ops);int oprofile_set_backtrace (unsigned long depth); +int oprofile_set_timeout (unsigned long time);#endif /* OPROF_H */
drivers/oprofile/oprofile_files.c +46 -0
74 lines not on this page · raw message
drivers/oprofile/oprofile_stats.c +5 -0
@@ -34,6 +34,7 @@ void oprofile_reset_stats(void)atomic_set (&oprofile_stats.sample_lost_no_mapping,0 );atomic_set (&oprofile_stats.event_lost_overflow,0 );atomic_set (&oprofile_stats.bt_lost_no_mapping,0 ); +atomic_set (&oprofile_stats.multiplex_counter,0 ); }
@@ -76,4 +77,8 @@ void oprofile_create_stats_files(struct super_block *sb, struct dentry *root) &oprofile_stats.event_lost_overflow);oprofilefs_create_ro_atomic (sb, dir,"bt_lost_no_mapping" , &oprofile_stats.bt_lost_no_mapping); +#ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX +oprofilefs_create_ro_atomic (sb, dir,"multiplex_counter" , + &oprofile_stats.multiplex_counter); +#endif }
drivers/oprofile/oprofile_stats.h +1 -0
@@ -17,6 +17,7 @@ struct oprofile_stat_struct {atomic_t sample_lost_no_mapping;atomic_t bt_lost_no_mapping;atomic_t event_lost_overflow; +atomic_t multiplex_counter; };extern struct oprofile_stat_struct oprofile_stats;
include/linux/oprofile.h +3 -0
@@ -67,6 +67,9 @@ struct oprofile_operations {/* Initiate a stack backtrace. Optional. */ void (*backtrace)(struct pt_regs *const regs,unsigned int depth); + +/* Multiplex between different events. Optional. */ +int (*switch_events)(void );/* CPU identification string. */ char * cpu_type; };