Skip to content

oprofile: Performance counter multiplexing

Robert Richter lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest26 patches 15 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/26x86/oprofile: Rework and simplify nmi_cpu_setup()arch/x86/oprofile/nmi_int.c+3 -100 replies
2/26x86/oprofile: Whitespaces changes onlyarch/x86/oprofile/nmi_int.c arch/x86/oprofile/op_model_amd.c arch/x86/oprofile/op_model_p4.c +1 more+20 -200 replies
3/26oprofile: Implement performance counter multiplexingarch/Kconfig arch/x86/oprofile/nmi_int.c arch/x86/oprofile/op_counter.h +9 more+415 -200 replies
4/26x86/oprofile: Fix usage of NUM_CONTROLS/NUM_COUNTERS macrosarch/x86/oprofile/op_model_amd.c+2 -20 replies
5/26x86/oprofile: Use per_cpu() instead of __get_cpu_var()arch/x86/oprofile/nmi_int.c+2 -20 replies
6/26x86/oprofile: Fix initialization of switch_indexarch/x86/oprofile/nmi_int.c+9 -70 replies
7/26oprofile: oprofile_set_timeout(), return with error for invalid argsdrivers/oprofile/oprof.c+8 -30 replies
8/26oprofile: Rename variable timeout_jiffies and move to oprofile_files.cdrivers/oprofile/oprof.c drivers/oprofile/oprof.h drivers/oprofile/oprofile_files.c+9 -80 replies
9/26oprofile: Remove oprofile_multiplexing_init()drivers/oprofile/oprof.c drivers/oprofile/oprofile_files.c+2 -140 replies
10/26oprofile: Grouping multiplexing code in oprof.cdrivers/oprofile/oprof.c+49 -510 replies
11/26oprofile: Introduce op_x86_phys_to_virt()arch/x86/oprofile/nmi_int.c arch/x86/oprofile/op_model_amd.c arch/x86/oprofile/op_x86_model.h+55 -690 replies
12/26oprofile: Grouping multiplexing code in op_model_amd.carch/x86/oprofile/op_model_amd.c+41 -340 replies
13/26x86/oprofile: Implement multiplexing setup/shutdown functionsarch/x86/oprofile/nmi_int.c+40 -360 replies
14/26x86/oprofile: Moving nmi_setup_cpu_mux() in nmi_int.carch/x86/oprofile/nmi_int.c+19 -260 replies
15/26x86/oprofile: Moving nmi_cpu_save/restore_mpx_registers() in nmi_int.carch/x86/oprofile/nmi_int.c+24 -280 replies
16/26x86/oprofile: Moving nmi_cpu_switch() in nmi_int.carch/x86/oprofile/nmi_int.c+70 -740 replies
17/26x86/oprofile: Remove const qualifier from struct op_x86_model_specarch/x86/oprofile/nmi_int.c arch/x86/oprofile/op_model_amd.c arch/x86/oprofile/op_model_p4.c +2 more+10 -100 replies
18/26x86/oprofile: Remove unused num_virt_controls from struct op_x86_model_specarch/x86/oprofile/op_model_amd.c arch/x86/oprofile/op_model_p4.c arch/x86/oprofile/op_model_ppro.c +1 more+0 -50 replies
19/26x86/oprofile: Modify initialization of num_virt_countersarch/x86/oprofile/nmi_int.c arch/x86/oprofile/op_model_p4.c arch/x86/oprofile/op_model_ppro.c+3 -30 replies
20/26x86/oprofile: Add function has_mux() to check multiplexing supportarch/x86/oprofile/nmi_int.c+18 -10 replies
21/26x86/oprofile: Enable multiplexing only if the model supports itarch/x86/oprofile/nmi_int.c+9 -30 replies
22/26x86/oprofile: Implement mux_clone()arch/x86/oprofile/nmi_int.c+23 -140 replies
23/26oprofile: Adding switch counter to oprofile statistic variablesarch/x86/oprofile/nmi_int.c drivers/oprofile/oprof.c drivers/oprofile/oprofile_stats.c +1 more+8 -160 replies
24/26x86/oprofile: Implement op_x86_virt_to_phys()arch/x86/oprofile/nmi_int.c arch/x86/oprofile/op_model_amd.c arch/x86/oprofile/op_x86_model.h+8 -10 replies
25/26x86/oprofile: Add counter reservation check for virtual countersarch/x86/oprofile/nmi_int.c+1 -30 replies
26/26x86/oprofile: Small coding style fixesarch/x86/oprofile/op_model_amd.c+2 -30 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

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
index 99193b1..beea3cc 100644
@@ -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
index 91b6a11..e28398d 100644
@@ -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
index 9db9e36..ac6b354 100644
@@ -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
index cd72d5c..4899215 100644
@@ -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
index 5054898..b837761 100644
@@ -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
index c288d3c..cb92f5c 100644
@@ -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
index 3c2270a..61689e8 100644
@@ -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
index 3da0d08..0b54e46 100644
@@ -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
index d68d2ed..5171639 100644
@@ -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;
 };