Cleanup and enhance power trace events
Subsystems (6)
Tested with:acpi_idle and intel_idle as cpuidle drivers.
also tested perf timechart userspace tool without the new interface and it still works fine with the new kernel changes.
There are quite some issues with the balance of cpu_idle enter/leave a sleep state, but this was the case already. perf timechart handles double "leave idle" events gracefully (should still get fixed up at some time).
The first patch makes intel_idle cpuidle driver tracable, even if compiled as a module.
Ingo: Can you please push these into an approprate git tree/branch.
Thanks,
Thomas
PATCH 1/3 PERF: Do not export power_frequency, but power_start event
power_frequency moved to drivers/cpufreq/cpufreq.c which has to be compiled in, no need to export it.
intel_idle can a be module though...
--- drivers/idle/intel_idle.c | 2 -- kernel/trace/power-traces.c | 2 +- 2 files changed, 1 insertions(+), 3 deletions(-)
drivers/idle/intel_idle.c +0 -2
@@ -201,9 +201,7 @@ static int intel_idle(struct cpuidle_device *dev, struct cpuidle_state *state) kt_before =ktime_get_real ();stop_critical_timings (); -#ifndef MODULE trace_power_start (POWER_CSTATE , (eax >>4 ) +1 , cpu); -#endif if (!need_resched ()) {__monitor ((void *)¤t_thread_info ()->flags,0 ,0 );
kernel/trace/power-traces.c +1 -1
@@ -13,5 +13,5 @@#define CREATE_TRACE_POINTS #include <trace/events/power.h> -EXPORT_TRACEPOINT_SYMBOL_GPL (power_frequency); +EXPORT_TRACEPOINT_SYMBOL_GPL (power_start);
Signature · 1 line
1.6.3
PATCH 1/3 PERF: Do not export power_frequency, but power_start event
In reply to Thomas Renningerpower_frequency moved to drivers/cpufreq/cpufreq.c which has to be compiled in, no need to export it.
intel_idle can a be module though...
--- drivers/idle/intel_idle.c | 2 -- kernel/trace/power-traces.c | 2 +- 2 files changed, 1 insertions(+), 3 deletions(-)
drivers/idle/intel_idle.c +0 -2
@@ -201,9 +201,7 @@ static int intel_idle(struct cpuidle_device *dev, struct cpuidle_state *state) kt_before =ktime_get_real ();stop_critical_timings (); -#ifndef MODULE trace_power_start (POWER_CSTATE , (eax >>4 ) +1 , cpu); -#endif if (!need_resched ()) {__monitor ((void *)¤t_thread_info ()->flags,0 ,0 );
kernel/trace/power-traces.c +1 -1
@@ -13,5 +13,5 @@#define CREATE_TRACE_POINTS #include <trace/events/power.h> -EXPORT_TRACEPOINT_SYMBOL_GPL (power_frequency); +EXPORT_TRACEPOINT_SYMBOL_GPL (power_start);
Signature · 1 line
1.6.3
PATCH 2/3 PERF(kernel): Cleanup power events
In reply to Thomas RenningerRecent changes:
- Enable EVENT_POWER_TRACING_DEPRECATED by default
New power trace events:
power:cpu_idle
power:cpu_frequency
power:machine_suspend
C-state/idle accounting events:
power:power_start
power:power_end
are replaced with:
power:cpu_idle
and
power:power_frequency
is replaced with:
power:cpu_frequency
power:machine_suspend
is newly introduced, a first implementation
comes from the ARM side, but it's easy to add these events in X86 as well if needed.
the type= field got removed from both, it was never used and the type is differed by the event type itself.
perf timechart
userspace tool gets adjusted in a separate patch.
--- arch/x86/kernel/process.c | 7 +++- arch/x86/kernel/process_32.c | 2 +- arch/x86/kernel/process_64.c | 2 + drivers/cpufreq/cpufreq.c | 1 + drivers/cpuidle/cpuidle.c | 1 + drivers/idle/intel_idle.c | 1 + include/trace/events/power.h | 87 +++++++++++++++++++++++++++++++++++++++++- kernel/trace/Kconfig | 15 +++++++ kernel/trace/power-traces.c | 3 + 9 files changed, 116 insertions(+), 3 deletions(-)
arch/x86/kernel/process.c +6 -1
@@ -374,6 +374,7 @@ void default_idle(void) {if (hlt_use_halt ()) {trace_power_start (POWER_CSTATE ,1 ,smp_processor_id ()); +trace_cpu_idle (1 ,smp_processor_id ());current_thread_info ()->status &= ~TS_POLLING ;/* * TS_POLLING-cleared state must be visible before we
@@ -444,6 +445,7 @@ EXPORT_SYMBOL_GPL(cpu_idle_wait);void mwait_idle_with_hints (unsigned long ax,unsigned long cx) {trace_power_start (POWER_CSTATE , (ax>>4 )+1 ,smp_processor_id ()); +trace_cpu_idle ((ax>>4 )+1 ,smp_processor_id ());if (!need_resched ()) {if (cpu_has (¤t_cpu_data,X86_FEATURE_CLFLUSH_MONITOR ))clflush ((void *)¤t_thread_info ()->flags);
@@ -460,6 +462,7 @@ static void mwait_idle(void) {if (!need_resched ()) {trace_power_start (POWER_CSTATE ,1 ,smp_processor_id ()); +trace_cpu_idle (1 ,smp_processor_id ());if (cpu_has (¤t_cpu_data,X86_FEATURE_CLFLUSH_MONITOR ))clflush ((void *)¤t_thread_info ()->flags);
@@ -481,10 +484,12 @@ static void mwait_idle(void)static void poll_idle (void ) {trace_power_start (POWER_CSTATE ,0 ,smp_processor_id ()); +trace_cpu_idle (0 ,smp_processor_id ());local_irq_enable ();while (!need_resched ())cpu_relax (); -trace_power_end (0 ); +trace_power_end (smp_processor_id ()); +trace_cpu_idle (PWR_EVENT_EXIT ,smp_processor_id ()); }/*
arch/x86/kernel/process_32.c +1 -1
@@ -113,8 +113,8 @@ void cpu_idle(void)stop_critical_timings ();pm_idle ();start_critical_timings (); -trace_power_end (smp_processor_id ()); +trace_cpu_idle (PWR_EVENT_EXIT ,smp_processor_id ()); }tick_nohz_restart_sched_tick ();preempt_enable_no_resched ();
arch/x86/kernel/process_64.c +2 -0
@@ -142,6 +142,8 @@ void cpu_idle(void)start_critical_timings ();trace_power_end (smp_processor_id ()); +trace_cpu_idle (PWR_EVENT_EXIT , +smp_processor_id ());/* In many cases the interrupt that ended idle has already called exit_idle. But some idle
drivers/cpufreq/cpufreq.c +1 -0
@@ -355,6 +355,7 @@ void cpufreq_notify_transition(struct cpufreq_freqs *freqs, unsigned int state)dprintk ("FREQ: %lu - CPU: %lu" , (unsigned long )freqs->new, (unsigned long )freqs->cpu);trace_power_frequency (POWER_PSTATE , freqs->new, freqs->cpu); +trace_cpu_frequency (freqs->new, freqs->cpu);srcu_notifier_call_chain (&cpufreq_transition_notifier_list,CPUFREQ_POSTCHANGE , freqs);if (likely (policy) &&likely (policy->cpu == freqs->cpu))
drivers/cpuidle/cpuidle.c +1 -0
@@ -107,6 +107,7 @@ static void cpuidle_idle_call(void)if (cpuidle_curr_governor->reflect) cpuidle_curr_governor->reflect (dev);trace_power_end (smp_processor_id ()); +trace_cpu_idle (PWR_EVENT_EXIT ,smp_processor_id ()); }/**
drivers/idle/intel_idle.c +1 -0
@@ -202,6 +202,7 @@ static int intel_idle(struct cpuidle_device *dev, struct cpuidle_state *state)stop_critical_timings ();trace_power_start (POWER_CSTATE , (eax >>4 ) +1 , cpu); +trace_cpu_idle ((eax >>4 ) +1 , cpu);if (!need_resched ()) {__monitor ((void *)¤t_thread_info ()->flags,0 ,0 );
include/trace/events/power.h +86 -1
100 lines not on this page · raw message
kernel/trace/Kconfig +15 -0
@@ -64,6 +64,21 @@ config EVENT_TRACING select CONTEXT_SWITCH_TRACER bool +config EVENT_POWER_TRACING_DEPRECATED + depends on EVENT_TRACING + bool + default y + help + Provides old power event types: + C-state/idle accounting events: + power:power_start + power:power_end + and old cpufreq accounting event: + power:power_frequency + This is for userspace compatibility + and will vanish after 5 kernel iterations, + namely 2.6.41. + config CONTEXT_SWITCH_TRACER bool
kernel/trace/power-traces.c +3 -0
@@ -13,5 +13,8 @@#define CREATE_TRACE_POINTS #include <trace/events/power.h> +#ifdef EVENT_POWER_TRACING_DEPRECATED EXPORT_TRACEPOINT_SYMBOL_GPL (power_start); +#endif +EXPORT_TRACEPOINT_SYMBOL_GPL (cpu_idle);
Signature · 1 line
1.6.3
PATCH 2/3 PERF(kernel): Cleanup power events
In reply to Thomas RenningerRecent changes:
- Enable EVENT_POWER_TRACING_DEPRECATED by default
New power trace events:
power:cpu_idle
power:cpu_frequency
power:machine_suspend
C-state/idle accounting events:
power:power_start
power:power_end
are replaced with:
power:cpu_idle
and
power:power_frequency
is replaced with:
power:cpu_frequency
power:machine_suspend
is newly introduced, a first implementation
comes from the ARM side, but it's easy to add these events in X86 as well if needed.
the type= field got removed from both, it was never used and the type is differed by the event type itself.
perf timechart
userspace tool gets adjusted in a separate patch.
--- arch/x86/kernel/process.c | 7 +++- arch/x86/kernel/process_32.c | 2 +- arch/x86/kernel/process_64.c | 2 + drivers/cpufreq/cpufreq.c | 1 + drivers/cpuidle/cpuidle.c | 1 + drivers/idle/intel_idle.c | 1 + include/trace/events/power.h | 87 +++++++++++++++++++++++++++++++++++++++++- kernel/trace/Kconfig | 15 +++++++ kernel/trace/power-traces.c | 3 + 9 files changed, 116 insertions(+), 3 deletions(-)
arch/x86/kernel/process.c +6 -1
@@ -374,6 +374,7 @@ void default_idle(void) {if (hlt_use_halt ()) {trace_power_start (POWER_CSTATE ,1 ,smp_processor_id ()); +trace_cpu_idle (1 ,smp_processor_id ());current_thread_info ()->status &= ~TS_POLLING ;/* * TS_POLLING-cleared state must be visible before we
@@ -444,6 +445,7 @@ EXPORT_SYMBOL_GPL(cpu_idle_wait);void mwait_idle_with_hints (unsigned long ax,unsigned long cx) {trace_power_start (POWER_CSTATE , (ax>>4 )+1 ,smp_processor_id ()); +trace_cpu_idle ((ax>>4 )+1 ,smp_processor_id ());if (!need_resched ()) {if (cpu_has (¤t_cpu_data,X86_FEATURE_CLFLUSH_MONITOR ))clflush ((void *)¤t_thread_info ()->flags);
@@ -460,6 +462,7 @@ static void mwait_idle(void) {if (!need_resched ()) {trace_power_start (POWER_CSTATE ,1 ,smp_processor_id ()); +trace_cpu_idle (1 ,smp_processor_id ());if (cpu_has (¤t_cpu_data,X86_FEATURE_CLFLUSH_MONITOR ))clflush ((void *)¤t_thread_info ()->flags);
@@ -481,10 +484,12 @@ static void mwait_idle(void)static void poll_idle (void ) {trace_power_start (POWER_CSTATE ,0 ,smp_processor_id ()); +trace_cpu_idle (0 ,smp_processor_id ());local_irq_enable ();while (!need_resched ())cpu_relax (); -trace_power_end (0 ); +trace_power_end (smp_processor_id ()); +trace_cpu_idle (PWR_EVENT_EXIT ,smp_processor_id ()); }/*
arch/x86/kernel/process_32.c +1 -1
@@ -113,8 +113,8 @@ void cpu_idle(void)stop_critical_timings ();pm_idle ();start_critical_timings (); -trace_power_end (smp_processor_id ()); +trace_cpu_idle (PWR_EVENT_EXIT ,smp_processor_id ()); }tick_nohz_restart_sched_tick ();preempt_enable_no_resched ();
arch/x86/kernel/process_64.c +2 -0
@@ -142,6 +142,8 @@ void cpu_idle(void)start_critical_timings ();trace_power_end (smp_processor_id ()); +trace_cpu_idle (PWR_EVENT_EXIT , +smp_processor_id ());/* In many cases the interrupt that ended idle has already called exit_idle. But some idle
drivers/cpufreq/cpufreq.c +1 -0
@@ -355,6 +355,7 @@ void cpufreq_notify_transition(struct cpufreq_freqs *freqs, unsigned int state)dprintk ("FREQ: %lu - CPU: %lu" , (unsigned long )freqs->new, (unsigned long )freqs->cpu);trace_power_frequency (POWER_PSTATE , freqs->new, freqs->cpu); +trace_cpu_frequency (freqs->new, freqs->cpu);srcu_notifier_call_chain (&cpufreq_transition_notifier_list,CPUFREQ_POSTCHANGE , freqs);if (likely (policy) &&likely (policy->cpu == freqs->cpu))
drivers/cpuidle/cpuidle.c +1 -0
@@ -107,6 +107,7 @@ static void cpuidle_idle_call(void)if (cpuidle_curr_governor->reflect) cpuidle_curr_governor->reflect (dev);trace_power_end (smp_processor_id ()); +trace_cpu_idle (PWR_EVENT_EXIT ,smp_processor_id ()); }/**
drivers/idle/intel_idle.c +1 -0
@@ -202,6 +202,7 @@ static int intel_idle(struct cpuidle_device *dev, struct cpuidle_state *state)stop_critical_timings ();trace_power_start (POWER_CSTATE , (eax >>4 ) +1 , cpu); +trace_cpu_idle ((eax >>4 ) +1 , cpu);if (!need_resched ()) {__monitor ((void *)¤t_thread_info ()->flags,0 ,0 );
include/trace/events/power.h +86 -1
100 lines not on this page · raw message
kernel/trace/Kconfig +15 -0
@@ -64,6 +64,21 @@ config EVENT_TRACING select CONTEXT_SWITCH_TRACER bool +config EVENT_POWER_TRACING_DEPRECATED + depends on EVENT_TRACING + bool + default y + help + Provides old power event types: + C-state/idle accounting events: + power:power_start + power:power_end + and old cpufreq accounting event: + power:power_frequency + This is for userspace compatibility + and will vanish after 5 kernel iterations, + namely 2.6.41. + config CONTEXT_SWITCH_TRACER bool
kernel/trace/power-traces.c +3 -0
@@ -13,5 +13,8 @@#define CREATE_TRACE_POINTS #include <trace/events/power.h> +#ifdef EVENT_POWER_TRACING_DEPRECATED EXPORT_TRACEPOINT_SYMBOL_GPL (power_start); +#endif +EXPORT_TRACEPOINT_SYMBOL_GPL (cpu_idle);
Signature · 1 line
1.6.3
Re: [PATCH 2/3] PERF(kernel): Cleanup power events
Quoted 20 lines · Thomas Renninger
Recent changes:
- EnableEVENT_POWER_TRACING_DEPRECATEDby defaultNew power trace events:
power:cpu_idle
power:cpu_frequency
power:machine_suspendC-state/idle accounting events:
power:power_start
power:power_end
are replaced with:
power:cpu_idleand
power:power_frequency
is replaced with:
power:cpu_frequency
Quoted 4 lines
power:machine_suspend
is newly introduced, a first implementation
comes from the ARM side, but it's easy to add these events in X86 as well if needed.
Can you please check that changelog, please?
I've asked you for that already once.
Thanks,
Rafael
Re: [linux-pm] [PATCH 2/3] PERF(kernel): Cleanup power events
Quoted 21 lines · Rafael J. Wysocki
Quoted 20 lines · Thomas Renninger
Recent changes:
- EnableEVENT_POWER_TRACING_DEPRECATEDby defaultNew power trace events:
power:cpu_idle
power:cpu_frequency
power:machine_suspendC-state/idle accounting events:
power:power_start
power:power_end
are replaced with:
power:cpu_idleand
power:power_frequency
is replaced with:
power:cpu_frequency
Quoted 6 lines
Quoted 4 lines
power:machine_suspend
is newly introduced, a first implementation
comes from the ARM side, but it's easy to add these events in X86 as well if needed.Can you please check that changelog, please?
Sorry s/check/modify/
In fact, there won't be any ARM implementation, because it's going to be added at the core level.
Quoted 1 line
I've asked you for that already once.
Thanks,
Rafael
PATCH 2/3 PERF(kernel): Cleanup power events
Recent changes:
- Enable EVENT_POWER_TRACING_DEPRECATED by default
New power trace events:
power:cpu_idle
power:cpu_frequency
power:machine_suspend
C-state/idle accounting events:
power:power_start
power:power_end
are replaced with:
power:cpu_idle
and
power:power_frequency
is replaced with:
power:cpu_frequency
power:machine_suspend
is newly introduced.
Jean Pihet has a patch integrated into the generic layer (kernel/power/suspend.c) which will make use of it.
the type= field got removed from both, it was never used and the type is differed by the event type itself.
perf timechart
userspace tool gets adjusted in a separate patch.
arch/x86/kernel/process.c +6 -1
@@ -374,6 +374,7 @@ void default_idle(void) {if (hlt_use_halt ()) {trace_power_start (POWER_CSTATE ,1 ,smp_processor_id ()); +trace_cpu_idle (1 ,smp_processor_id ());current_thread_info ()->status &= ~TS_POLLING ;/* * TS_POLLING-cleared state must be visible before we
@@ -444,6 +445,7 @@ EXPORT_SYMBOL_GPL(cpu_idle_wait);void mwait_idle_with_hints (unsigned long ax,unsigned long cx) {trace_power_start (POWER_CSTATE , (ax>>4 )+1 ,smp_processor_id ()); +trace_cpu_idle ((ax>>4 )+1 ,smp_processor_id ());if (!need_resched ()) {if (cpu_has (¤t_cpu_data,X86_FEATURE_CLFLUSH_MONITOR ))clflush ((void *)¤t_thread_info ()->flags);
@@ -460,6 +462,7 @@ static void mwait_idle(void) {if (!need_resched ()) {trace_power_start (POWER_CSTATE ,1 ,smp_processor_id ()); +trace_cpu_idle (1 ,smp_processor_id ());if (cpu_has (¤t_cpu_data,X86_FEATURE_CLFLUSH_MONITOR ))clflush ((void *)¤t_thread_info ()->flags);
@@ -481,10 +484,12 @@ static void mwait_idle(void)static void poll_idle (void ) {trace_power_start (POWER_CSTATE ,0 ,smp_processor_id ()); +trace_cpu_idle (0 ,smp_processor_id ());local_irq_enable ();while (!need_resched ())cpu_relax (); -trace_power_end (0 ); +trace_power_end (smp_processor_id ()); +trace_cpu_idle (PWR_EVENT_EXIT ,smp_processor_id ()); }/*
arch/x86/kernel/process_32.c +1 -1
@@ -113,8 +113,8 @@ void cpu_idle(void)stop_critical_timings ();pm_idle ();start_critical_timings (); -trace_power_end (smp_processor_id ()); +trace_cpu_idle (PWR_EVENT_EXIT ,smp_processor_id ()); }tick_nohz_restart_sched_tick ();preempt_enable_no_resched ();
arch/x86/kernel/process_64.c +2 -0
@@ -142,6 +142,8 @@ void cpu_idle(void)start_critical_timings ();trace_power_end (smp_processor_id ()); +trace_cpu_idle (PWR_EVENT_EXIT , +smp_processor_id ());/* In many cases the interrupt that ended idle has already called exit_idle. But some idle
drivers/cpufreq/cpufreq.c +0 -0
@@ -355,6 +355,7 @@ void cpufreq_notify_transition(struct cpufreq_freqs
*freqs, unsigned int state)
dprintk("FREQ: %lu - CPU: %lu", (unsigned long)freqs->new,
(unsigned long)freqs->cpu);
trace_power_frequency(POWER_PSTATE, freqs->new, freqs->cpu);
+ trace_cpu_frequency(freqs->new, freqs->cpu);
srcu_notifier_call_chain(&cpufreq_transition_notifier_list,
CPUFREQ_POSTCHANGE, freqs);
if (likely(policy) && likely(policy->cpu == freqs->cpu))
drivers/cpuidle/cpuidle.c +1 -0
@@ -107,6 +107,7 @@ static void cpuidle_idle_call(void)if (cpuidle_curr_governor->reflect) cpuidle_curr_governor->reflect (dev);trace_power_end (smp_processor_id ()); +trace_cpu_idle (PWR_EVENT_EXIT ,smp_processor_id ()); }/**
drivers/idle/intel_idle.c +0 -0
@@ -202,6 +202,7 @@ static int intel_idle(struct cpuidle_device *dev,
struct cpuidle_state *state)
stop_critical_timings(); trace_power_start(POWER_CSTATE, (eax >> 4) + 1, cpu);
+ trace_cpu_idle((eax >> 4) + 1, cpu);
if (!need_resched()) {
__monitor((void *)¤t_thread_info()->flags, 0, 0);
include/trace/events/power.h +28 -0
@@ -7,6 +7,67 @@#include <linux/ktime.h> #include <linux/tracepoint.h> +DECLARE_EVENT_CLASS (cpu, + + TP_PROTO(unsigned int state, unsigned int cpu_id), + +TP_ARGS (state, cpu_id), + +TP_STRUCT__entry ( + __field( u32, state ) +__field ( u32, cpu_id ) + ), + +TP_fast_assign ( + __entry->state = state; + __entry->cpu_id = cpu_id; + ), + +TP_printk ("state=%lu cpu_id=%lu" , (unsigned long )__entry->state, + (unsigned long )__entry->cpu_id) +); + +DEFINE_EVENT (cpu, cpu_idle, + + TP_PROTO(unsigned int state, unsigned int cpu_id), + +TP_ARGS (state, cpu_id) +); + +/* This file can get included multiple times, TRACE_HEADER_MULTI_READ
at top */
+#ifndef _PWR_EVENT_AVOID_DOUBLE_DEFINING
+#define _PWR_EVENT_AVOID_DOUBLE_DEFINING
+
+#define PWR_EVENT_EXIT -1
+
+#endif
+
+DEFINE_EVENT(cpu, cpu_frequency,
+
+ TP_PROTO(unsigned int frequency, unsigned int cpu_id),
+
+ TP_ARGS(frequency, cpu_id)
+);
+
+TRACE_EVENT(machine_suspend,
+
+ TP_PROTO(unsigned int state),
+
+ TP_ARGS(state),
+
+ TP_STRUCT__entry(
+ __field( u32, state )
+ ),
+
+ TP_fast_assign(
+ __entry->state = state;
+ ),
+
+ TP_printk("state=%lu", (unsigned long)__entry->state)
+);
+
+#ifdef CONFIG_EVENT_POWER_TRACING_DEPRECATED
+
#ifndef _TRACE_POWER_ENUM_
#define _TRACE_POWER_ENUM_
enum {
@@ -69,8 +130,32 @@ TRACE_EVENT(power_end,
TP_printk("cpu_id=%lu", (unsigned long)__entry->cpu_id)
);
-
+#endif /* CONFIG_EVENT_POWER_TRACING_DEPRECATED */
#endif /* _TRACE_POWER_H */
+/* Deprecated dummy functions must be protected against multi- declartion */
+#ifndef EVENT_POWER_TRACING_DEPRECATED_PART_H
+#define EVENT_POWER_TRACING_DEPRECATED_PART_H
+
+#ifndef CONFIG_EVENT_POWER_TRACING_DEPRECATED
+
+#ifndef _TRACE_POWER_ENUM_
+#define _TRACE_POWER_ENUM_
+enum {
+ POWER_NONE = 0,
+ POWER_CSTATE = 1,
+ POWER_PSTATE = 2,
+};
+#endif
+
+static inline void trace_power_start(u64 type, u64 state, u64 cpuid) {};
+static inline void trace_power_end(u64 cpuid) {};
+static inline void trace_power_frequency(u64 type, u64 state, u64 cpuid) {};
+#endif /* CONFIG_EVENT_POWER_TRACING_DEPRECATED */
+
+#endif /* EVENT_POWER_TRACING_DEPRECATED_PART_H */
+
+
+
/* This part must be outside protection */
#include <trace/define_trace.h>
kernel/trace/Kconfig +15 -0
@@ -64,6 +64,21 @@ config EVENT_TRACING select CONTEXT_SWITCH_TRACER bool +config EVENT_POWER_TRACING_DEPRECATED + depends on EVENT_TRACING + bool + default y + help + Provides old power event types: + C-state/idle accounting events: + power:power_start + power:power_end + and old cpufreq accounting event: + power:power_frequency + This is for userspace compatibility + and will vanish after 5 kernel iterations, + namely 2.6.41. + config CONTEXT_SWITCH_TRACER bool
kernel/trace/power-traces.c +3 -0
@@ -13,5 +13,8 @@#define CREATE_TRACE_POINTS #include <trace/events/power.h> +#ifdef EVENT_POWER_TRACING_DEPRECATED EXPORT_TRACEPOINT_SYMBOL_GPL (power_start); +#endif +EXPORT_TRACEPOINT_SYMBOL_GPL (cpu_idle);
PATCH 2/3 PERF(kernel): Cleanup power events
In reply to Rafael J. WysockiRecent changes:
- Enable EVENT_POWER_TRACING_DEPRECATED by default
New power trace events:
power:cpu_idle
power:cpu_frequency
power:machine_suspend
C-state/idle accounting events:
power:power_start
power:power_end
are replaced with:
power:cpu_idle
and
power:power_frequency
is replaced with:
power:cpu_frequency
power:machine_suspend
is newly introduced.
Jean Pihet has a patch integrated into the generic layer (kernel/power/suspend.c) which will make use of it.
the type= field got removed from both, it was never used and the type is differed by the event type itself.
perf timechart
userspace tool gets adjusted in a separate patch.
arch/x86/kernel/process.c +6 -1
@@ -374,6 +374,7 @@ void default_idle(void) {if (hlt_use_halt ()) {trace_power_start (POWER_CSTATE ,1 ,smp_processor_id ()); +trace_cpu_idle (1 ,smp_processor_id ());current_thread_info ()->status &= ~TS_POLLING ;/* * TS_POLLING-cleared state must be visible before we
@@ -444,6 +445,7 @@ EXPORT_SYMBOL_GPL(cpu_idle_wait);void mwait_idle_with_hints (unsigned long ax,unsigned long cx) {trace_power_start (POWER_CSTATE , (ax>>4 )+1 ,smp_processor_id ()); +trace_cpu_idle ((ax>>4 )+1 ,smp_processor_id ());if (!need_resched ()) {if (cpu_has (¤t_cpu_data,X86_FEATURE_CLFLUSH_MONITOR ))clflush ((void *)¤t_thread_info ()->flags);
@@ -460,6 +462,7 @@ static void mwait_idle(void) {if (!need_resched ()) {trace_power_start (POWER_CSTATE ,1 ,smp_processor_id ()); +trace_cpu_idle (1 ,smp_processor_id ());if (cpu_has (¤t_cpu_data,X86_FEATURE_CLFLUSH_MONITOR ))clflush ((void *)¤t_thread_info ()->flags);
@@ -481,10 +484,12 @@ static void mwait_idle(void)static void poll_idle (void ) {trace_power_start (POWER_CSTATE ,0 ,smp_processor_id ()); +trace_cpu_idle (0 ,smp_processor_id ());local_irq_enable ();while (!need_resched ())cpu_relax (); -trace_power_end (0 ); +trace_power_end (smp_processor_id ()); +trace_cpu_idle (PWR_EVENT_EXIT ,smp_processor_id ()); }/*
arch/x86/kernel/process_32.c +1 -1
@@ -113,8 +113,8 @@ void cpu_idle(void)stop_critical_timings ();pm_idle ();start_critical_timings (); -trace_power_end (smp_processor_id ()); +trace_cpu_idle (PWR_EVENT_EXIT ,smp_processor_id ()); }tick_nohz_restart_sched_tick ();preempt_enable_no_resched ();
arch/x86/kernel/process_64.c +2 -0
@@ -142,6 +142,8 @@ void cpu_idle(void)start_critical_timings ();trace_power_end (smp_processor_id ()); +trace_cpu_idle (PWR_EVENT_EXIT , +smp_processor_id ());/* In many cases the interrupt that ended idle has already called exit_idle. But some idle
drivers/cpufreq/cpufreq.c +0 -0
@@ -355,6 +355,7 @@ void cpufreq_notify_transition(struct cpufreq_freqs
*freqs, unsigned int state)
dprintk("FREQ: %lu - CPU: %lu", (unsigned long)freqs->new,
(unsigned long)freqs->cpu);
trace_power_frequency(POWER_PSTATE, freqs->new, freqs->cpu);
+ trace_cpu_frequency(freqs->new, freqs->cpu);
srcu_notifier_call_chain(&cpufreq_transition_notifier_list,
CPUFREQ_POSTCHANGE, freqs);
if (likely(policy) && likely(policy->cpu == freqs->cpu))
drivers/cpuidle/cpuidle.c +1 -0
@@ -107,6 +107,7 @@ static void cpuidle_idle_call(void)if (cpuidle_curr_governor->reflect) cpuidle_curr_governor->reflect (dev);trace_power_end (smp_processor_id ()); +trace_cpu_idle (PWR_EVENT_EXIT ,smp_processor_id ()); }/**
drivers/idle/intel_idle.c +0 -0
@@ -202,6 +202,7 @@ static int intel_idle(struct cpuidle_device *dev,
struct cpuidle_state *state)
stop_critical_timings(); trace_power_start(POWER_CSTATE, (eax >> 4) + 1, cpu);
+ trace_cpu_idle((eax >> 4) + 1, cpu);
if (!need_resched()) {
__monitor((void *)¤t_thread_info()->flags, 0, 0);
include/trace/events/power.h +28 -0
@@ -7,6 +7,67 @@#include <linux/ktime.h> #include <linux/tracepoint.h> +DECLARE_EVENT_CLASS (cpu, + + TP_PROTO(unsigned int state, unsigned int cpu_id), + +TP_ARGS (state, cpu_id), + +TP_STRUCT__entry ( + __field( u32, state ) +__field ( u32, cpu_id ) + ), + +TP_fast_assign ( + __entry->state = state; + __entry->cpu_id = cpu_id; + ), + +TP_printk ("state=%lu cpu_id=%lu" , (unsigned long )__entry->state, + (unsigned long )__entry->cpu_id) +); + +DEFINE_EVENT (cpu, cpu_idle, + + TP_PROTO(unsigned int state, unsigned int cpu_id), + +TP_ARGS (state, cpu_id) +); + +/* This file can get included multiple times, TRACE_HEADER_MULTI_READ
at top */
+#ifndef _PWR_EVENT_AVOID_DOUBLE_DEFINING
+#define _PWR_EVENT_AVOID_DOUBLE_DEFINING
+
+#define PWR_EVENT_EXIT -1
+
+#endif
+
+DEFINE_EVENT(cpu, cpu_frequency,
+
+ TP_PROTO(unsigned int frequency, unsigned int cpu_id),
+
+ TP_ARGS(frequency, cpu_id)
+);
+
+TRACE_EVENT(machine_suspend,
+
+ TP_PROTO(unsigned int state),
+
+ TP_ARGS(state),
+
+ TP_STRUCT__entry(
+ __field( u32, state )
+ ),
+
+ TP_fast_assign(
+ __entry->state = state;
+ ),
+
+ TP_printk("state=%lu", (unsigned long)__entry->state)
+);
+
+#ifdef CONFIG_EVENT_POWER_TRACING_DEPRECATED
+
#ifndef _TRACE_POWER_ENUM_
#define _TRACE_POWER_ENUM_
enum {
@@ -69,8 +130,32 @@ TRACE_EVENT(power_end,
TP_printk("cpu_id=%lu", (unsigned long)__entry->cpu_id)
);
-
+#endif /* CONFIG_EVENT_POWER_TRACING_DEPRECATED */
#endif /* _TRACE_POWER_H */
+/* Deprecated dummy functions must be protected against multi- declartion */
+#ifndef EVENT_POWER_TRACING_DEPRECATED_PART_H
+#define EVENT_POWER_TRACING_DEPRECATED_PART_H
+
+#ifndef CONFIG_EVENT_POWER_TRACING_DEPRECATED
+
+#ifndef _TRACE_POWER_ENUM_
+#define _TRACE_POWER_ENUM_
+enum {
+ POWER_NONE = 0,
+ POWER_CSTATE = 1,
+ POWER_PSTATE = 2,
+};
+#endif
+
+static inline void trace_power_start(u64 type, u64 state, u64 cpuid) {};
+static inline void trace_power_end(u64 cpuid) {};
+static inline void trace_power_frequency(u64 type, u64 state, u64 cpuid) {};
+#endif /* CONFIG_EVENT_POWER_TRACING_DEPRECATED */
+
+#endif /* EVENT_POWER_TRACING_DEPRECATED_PART_H */
+
+
+
/* This part must be outside protection */
#include <trace/define_trace.h>
kernel/trace/Kconfig +15 -0
@@ -64,6 +64,21 @@ config EVENT_TRACING select CONTEXT_SWITCH_TRACER bool +config EVENT_POWER_TRACING_DEPRECATED + depends on EVENT_TRACING + bool + default y + help + Provides old power event types: + C-state/idle accounting events: + power:power_start + power:power_end + and old cpufreq accounting event: + power:power_frequency + This is for userspace compatibility + and will vanish after 5 kernel iterations, + namely 2.6.41. + config CONTEXT_SWITCH_TRACER bool
kernel/trace/power-traces.c +3 -0
@@ -13,5 +13,8 @@#define CREATE_TRACE_POINTS #include <trace/events/power.h> +#ifdef EVENT_POWER_TRACING_DEPRECATED EXPORT_TRACEPOINT_SYMBOL_GPL (power_start); +#endif +EXPORT_TRACEPOINT_SYMBOL_GPL (cpu_idle);
Re: [PATCH 2/3] PERF(kernel): Cleanup power events
In reply to Rafael J. WysockiQuoted 21 lines · Rafael J. Wysocki
Quoted 20 lines · Thomas Renninger
Recent changes:
- EnableEVENT_POWER_TRACING_DEPRECATEDby defaultNew power trace events:
power:cpu_idle
power:cpu_frequency
power:machine_suspendC-state/idle accounting events:
power:power_start
power:power_end
are replaced with:
power:cpu_idleand
power:power_frequency
is replaced with:
power:cpu_frequency
Quoted 6 lines
Quoted 4 lines
power:machine_suspend
is newly introduced, a first implementation
comes from the ARM side, but it's easy to add these events in X86 as well if needed.Can you please check that changelog, please?
Sorry s/check/modify/
In fact, there won't be any ARM implementation, because it's going to be added at the core level.
Quoted 1 line
I've asked you for that already once.
Thanks,
Rafael
Re: [PATCH 2/3] PERF(kernel): Cleanup power events
In reply to Thomas RenningerQuoted 20 lines · Thomas Renninger
Recent changes:
- EnableEVENT_POWER_TRACING_DEPRECATEDby defaultNew power trace events:
power:cpu_idle
power:cpu_frequency
power:machine_suspendC-state/idle accounting events:
power:power_start
power:power_end
are replaced with:
power:cpu_idleand
power:power_frequency
is replaced with:
power:cpu_frequency
Quoted 4 lines
power:machine_suspend
is newly introduced, a first implementation
comes from the ARM side, but it's easy to add these events in X86 as well if needed.
Can you please check that changelog, please?
I've asked you for that already once.
Thanks,
Rafael
PATCH 3/3 PERF(userspace): Adjust perf timechart to the new power events
In reply to Thomas RenningerRecent changes:
- Adjust state/cpuid to u32 as done in the kernel
The transition was rather smooth, only part I had to fiddle some time was the check whether a tracepoint/event is supported by the running kernel.
builtin-timechart must only pass -e power:xy events which are supported by the running kernel.
For this I added the tiny helper function:
int is_valid_tracepoint(const char *event_string)
to parse-events.[hc]
which could be more generic as an interface and support hardware/software/... events, not only tracepoints, but someone else could extend that if needed...
--- tools/perf/builtin-timechart.c | 91 ++++++++++++++++++++++++++++++++------- tools/perf/util/parse-events.c | 41 ++++++++++++++++++ tools/perf/util/parse-events.h | 1 + 3 files changed, 116 insertions(+), 17 deletions(-)
tools/perf/builtin-timechart.c +74 -17
@@ -32,6 +32,10 @@#include "util/session.h" #include "util/svghelper.h" +#define SUPPORT_OLD_POWER_EVENTS 1 +#define PWR_EVENT_EXIT -1 + +static char const *input_name ="perf.data" ;static char const *output_name ="output.svg" ;
@@ -298,12 +302,21 @@ struct trace_entry {int lock_depth; }; -struct power_entry { +#if defined(SUPPORT_OLD_POWER_EVENTS ) +static int use_old_power_events; +struct power_entry_old {struct trace_entry te;u64 type;u64 value;u64 cpu_id; }; +#endif + +struct power_processor_entry { +struct trace_entry te; +u32 state; +u32 cpu_id; +};#define TASK_COMM_LEN 16struct wakeup_entry {
@@ -489,29 +502,48 @@ static int process_sample_event(event_t *event, struct perf_session *session) te = (void *)data.raw_data;if (session->sample_type &PERF_SAMPLE_RAW && data.raw_size >0 ) {char *event_str; -struct power_entry *pe; - - pe = (void *)te; +#if defined(SUPPORT_OLD_POWER_EVENTS ) +struct power_entry_old *peo; + peo = (void *)te; +#endif event_str =perf_header__find_event (te->type);if (!event_str)return 0 ; -if (strcmp (event_str,"power:power_start" ) ==0 ) -c_state_start (pe->cpu_id, data.time, pe->value); - -if (strcmp (event_str,"power:power_end" ) ==0 ) -c_state_end (pe->cpu_id, data.time); +if (strcmp (event_str,"power:cpu_idle" ) ==0 ) { +struct power_processor_entry *ppe = (void *)te; +if (ppe->state == (u32 )PWR_EVENT_EXIT ) +c_state_end (ppe->cpu_id, data.time); +else +c_state_start (ppe->cpu_id, data.time, + ppe->state); + } -if (strcmp (event_str,"power:power_frequency" ) ==0 ) -p_state_change (pe->cpu_id, data.time, pe->value); +else if (strcmp (event_str,"power:cpu_frequency" ) ==0 ) { +struct power_processor_entry *ppe = (void *)te; +p_state_change (ppe->cpu_id, data.time, ppe->state); + } -if (strcmp (event_str,"sched:sched_wakeup" ) ==0 ) +else if (strcmp (event_str,"sched:sched_wakeup" ) ==0 )sched_wakeup (data.cpu, data.time, data.pid, te); -if (strcmp (event_str,"sched:sched_switch" ) ==0 ) +else if (strcmp (event_str,"sched:sched_switch" ) ==0 )sched_switch (data.cpu, data.time, te); + +#if defined(SUPPORT_OLD_POWER_EVENTS ) +if (use_old_power_events) { +if (strcmp (event_str,"power:power_start" ) ==0 ) +c_state_start (peo->cpu_id, data.time, peo->value); + +else if (strcmp (event_str,"power:power_end" ) ==0 ) +c_state_end (peo->cpu_id, data.time); + +else if (strcmp (event_str,"power:power_frequency" ) ==0 ) +p_state_change (peo->cpu_id, data.time, peo->value); + } +#endif }return 0 ; }
@@ -968,7 +1000,8 @@ static const char * const timechart_usage[] = {NULL }; -static const char *record_args[] = { +#if defined(SUPPORT_OLD_POWER_EVENTS ) +static const char *record_old_args[] = {"record" ,"-a" , "-R",
@@ -980,16 +1013,40 @@ static const char *record_args[] = {"-e" ,"sched:sched_wakeup" , "-e", "sched:sched_switch", }; +#endif + +static const char *record_new_args[] = { +"record" , +"-a" , +"-R" , +"-f" , +"-c" ,"1" , +"-e" ,"power:cpu_frequency" , +"-e" ,"power:cpu_idle" , +"-e" ,"sched:sched_wakeup" , +"-e" ,"sched:sched_switch" , +};static int __cmd_record (int argc,const char **argv) {unsigned int rec_argc, i, j;const char **rec_argv; - - rec_argc =ARRAY_SIZE (record_args) + argc -1 ; +const char **record_args = record_new_args; +unsigned int record_elems =ARRAY_SIZE (record_new_args); + +#if defined(SUPPORT_OLD_POWER_EVENTS ) +if (!is_valid_tracepoint ("power:cpu_idle" ) && +is_valid_tracepoint ("power:power_start" )) { + use_old_power_events =1 ; + record_args = record_old_args; + record_elems =ARRAY_SIZE (record_old_args); + } +#endif + + rec_argc = record_elems + argc -1 ; rec_argv =calloc (rec_argc +1 ,sizeof (char *)); -for (i =0 ; i <ARRAY_SIZE (record_args); i++) +for (i =0 ; i < record_elems; i++) rec_argv[i] =strdup (record_args[i]);for (j =1 ; j < (unsigned int )argc; j++, i++)
tools/perf/util/parse-events.c +41 -0
47 lines not on this page · raw message
tools/perf/util/parse-events.h +1 -0
@@ -29,6 +29,7 @@ extern int parse_filter(const struct option *opt, const char *str, int unset);#define EVENTS_HELP_MAX (128*1024)extern void print_events (void ); +extern int is_valid_tracepoint (const char *event_string);extern char debugfs_path[];extern int valid_debugfs_mount (const char *debugfs);
Signature · 1 line
1.6.3
PATCH 3/3 PERF(userspace): Adjust perf timechart to the new power events
In reply to Thomas RenningerRecent changes:
- Adjust state/cpuid to u32 as done in the kernel
The transition was rather smooth, only part I had to fiddle some time was the check whether a tracepoint/event is supported by the running kernel.
builtin-timechart must only pass -e power:xy events which are supported by the running kernel.
For this I added the tiny helper function:
int is_valid_tracepoint(const char *event_string)
to parse-events.[hc]
which could be more generic as an interface and support hardware/software/... events, not only tracepoints, but someone else could extend that if needed...
--- tools/perf/builtin-timechart.c | 91 ++++++++++++++++++++++++++++++++------- tools/perf/util/parse-events.c | 41 ++++++++++++++++++ tools/perf/util/parse-events.h | 1 + 3 files changed, 116 insertions(+), 17 deletions(-)
tools/perf/builtin-timechart.c +74 -17
@@ -32,6 +32,10 @@#include "util/session.h" #include "util/svghelper.h" +#define SUPPORT_OLD_POWER_EVENTS 1 +#define PWR_EVENT_EXIT -1 + +static char const *input_name ="perf.data" ;static char const *output_name ="output.svg" ;
@@ -298,12 +302,21 @@ struct trace_entry {int lock_depth; }; -struct power_entry { +#if defined(SUPPORT_OLD_POWER_EVENTS ) +static int use_old_power_events; +struct power_entry_old {struct trace_entry te;u64 type;u64 value;u64 cpu_id; }; +#endif + +struct power_processor_entry { +struct trace_entry te; +u32 state; +u32 cpu_id; +};#define TASK_COMM_LEN 16struct wakeup_entry {
@@ -489,29 +502,48 @@ static int process_sample_event(event_t *event, struct perf_session *session) te = (void *)data.raw_data;if (session->sample_type &PERF_SAMPLE_RAW && data.raw_size >0 ) {char *event_str; -struct power_entry *pe; - - pe = (void *)te; +#if defined(SUPPORT_OLD_POWER_EVENTS ) +struct power_entry_old *peo; + peo = (void *)te; +#endif event_str =perf_header__find_event (te->type);if (!event_str)return 0 ; -if (strcmp (event_str,"power:power_start" ) ==0 ) -c_state_start (pe->cpu_id, data.time, pe->value); - -if (strcmp (event_str,"power:power_end" ) ==0 ) -c_state_end (pe->cpu_id, data.time); +if (strcmp (event_str,"power:cpu_idle" ) ==0 ) { +struct power_processor_entry *ppe = (void *)te; +if (ppe->state == (u32 )PWR_EVENT_EXIT ) +c_state_end (ppe->cpu_id, data.time); +else +c_state_start (ppe->cpu_id, data.time, + ppe->state); + } -if (strcmp (event_str,"power:power_frequency" ) ==0 ) -p_state_change (pe->cpu_id, data.time, pe->value); +else if (strcmp (event_str,"power:cpu_frequency" ) ==0 ) { +struct power_processor_entry *ppe = (void *)te; +p_state_change (ppe->cpu_id, data.time, ppe->state); + } -if (strcmp (event_str,"sched:sched_wakeup" ) ==0 ) +else if (strcmp (event_str,"sched:sched_wakeup" ) ==0 )sched_wakeup (data.cpu, data.time, data.pid, te); -if (strcmp (event_str,"sched:sched_switch" ) ==0 ) +else if (strcmp (event_str,"sched:sched_switch" ) ==0 )sched_switch (data.cpu, data.time, te); + +#if defined(SUPPORT_OLD_POWER_EVENTS ) +if (use_old_power_events) { +if (strcmp (event_str,"power:power_start" ) ==0 ) +c_state_start (peo->cpu_id, data.time, peo->value); + +else if (strcmp (event_str,"power:power_end" ) ==0 ) +c_state_end (peo->cpu_id, data.time); + +else if (strcmp (event_str,"power:power_frequency" ) ==0 ) +p_state_change (peo->cpu_id, data.time, peo->value); + } +#endif }return 0 ; }
@@ -968,7 +1000,8 @@ static const char * const timechart_usage[] = {NULL }; -static const char *record_args[] = { +#if defined(SUPPORT_OLD_POWER_EVENTS ) +static const char *record_old_args[] = {"record" ,"-a" , "-R",
@@ -980,16 +1013,40 @@ static const char *record_args[] = {"-e" ,"sched:sched_wakeup" , "-e", "sched:sched_switch", }; +#endif + +static const char *record_new_args[] = { +"record" , +"-a" , +"-R" , +"-f" , +"-c" ,"1" , +"-e" ,"power:cpu_frequency" , +"-e" ,"power:cpu_idle" , +"-e" ,"sched:sched_wakeup" , +"-e" ,"sched:sched_switch" , +};static int __cmd_record (int argc,const char **argv) {unsigned int rec_argc, i, j;const char **rec_argv; - - rec_argc =ARRAY_SIZE (record_args) + argc -1 ; +const char **record_args = record_new_args; +unsigned int record_elems =ARRAY_SIZE (record_new_args); + +#if defined(SUPPORT_OLD_POWER_EVENTS ) +if (!is_valid_tracepoint ("power:cpu_idle" ) && +is_valid_tracepoint ("power:power_start" )) { + use_old_power_events =1 ; + record_args = record_old_args; + record_elems =ARRAY_SIZE (record_old_args); + } +#endif + + rec_argc = record_elems + argc -1 ; rec_argv =calloc (rec_argc +1 ,sizeof (char *)); -for (i =0 ; i <ARRAY_SIZE (record_args); i++) +for (i =0 ; i < record_elems; i++) rec_argv[i] =strdup (record_args[i]);for (j =1 ; j < (unsigned int )argc; j++, i++)
tools/perf/util/parse-events.c +41 -0
47 lines not on this page · raw message
tools/perf/util/parse-events.h +1 -0
@@ -29,6 +29,7 @@ extern int parse_filter(const struct option *opt, const char *str, int unset);#define EVENTS_HELP_MAX (128*1024)extern void print_events (void ); +extern int is_valid_tracepoint (const char *event_string);extern char debugfs_path[];extern int valid_debugfs_mount (const char *debugfs);
Signature · 1 line
1.6.3
Re: [PATCH 3/3] PERF(userspace): Adjust perf timechart to the new power events
Quoted 3 lines · On Thursday 28 October 2010 11:02:59 Thomas Renninger wrote:
Recent changes:
- Adjust state/cpuid to u32 as done in the kernel
Argh, I forgot a guilt refresh...
Below final :) patch also fixes a bug that got introduced in 2.6.36 already. Will also send a version for stable inclusion.
Thomas
----
PERF(userspace): Adjust perf timechart to the new power events
Recent changes:
- Adjust state/cpuid to u32 as done in the kernel
The transition was rather smooth, only part I had to fiddle some time was the check whether a tracepoint/event is supported by the running kernel.
builtin-timechart must only pass -e power:xy events which are supported by the running kernel.
For this I added the tiny helper function:
int is_valid_tracepoint(const char *event_string)
to parse-events.[hc]
which could be more generic as an interface and support hardware/software/... events, not only tracepoints, but someone else could extend that if needed...
tools/perf/builtin-timechart.c +74 -17
@@ -32,6 +32,10 @@#include "util/session.h" #include "util/svghelper.h" +#define SUPPORT_OLD_POWER_EVENTS 1 +#define PWR_EVENT_EXIT -1 + +static char const *input_name ="perf.data" ;static char const *output_name ="output.svg" ;
@@ -298,12 +302,21 @@ struct trace_entry {int lock_depth; }; -struct power_entry { +#if defined(SUPPORT_OLD_POWER_EVENTS ) +static int use_old_power_events; +struct power_entry_old {struct trace_entry te;u64 type;u64 value;u64 cpu_id; }; +#endif + +struct power_processor_entry { +struct trace_entry te; +u32 state; +u32 cpu_id; +};#define TASK_COMM_LEN 16struct wakeup_entry {
@@ -489,29 +502,48 @@ static int process_sample_event(event_t *event, struct perf_session *session) te = (void *)data.raw_data;if (session->sample_type &PERF_SAMPLE_RAW && data.raw_size >0 ) {char *event_str; -struct power_entry *pe; - - pe = (void *)te; +#if defined(SUPPORT_OLD_POWER_EVENTS ) +struct power_entry_old *peo; + peo = (void *)te; +#endif event_str =perf_header__find_event (te->type);if (!event_str)return 0 ; -if (strcmp (event_str,"power:power_start" ) ==0 ) -c_state_start (pe->cpu_id, data.time, pe->value); - -if (strcmp (event_str,"power:power_end" ) ==0 ) -c_state_end (pe->cpu_id, data.time); +if (strcmp (event_str,"power:cpu_idle" ) ==0 ) { +struct power_processor_entry *ppe = (void *)te; +if (ppe->state == (u32 )PWR_EVENT_EXIT ) +c_state_end (ppe->cpu_id, data.time); +else +c_state_start (ppe->cpu_id, data.time, + ppe->state); + } -if (strcmp (event_str,"power:power_frequency" ) ==0 ) -p_state_change (pe->cpu_id, data.time, pe->value); +else if (strcmp (event_str,"power:cpu_frequency" ) ==0 ) { +struct power_processor_entry *ppe = (void *)te; +p_state_change (ppe->cpu_id, data.time, ppe->state); + } -if (strcmp (event_str,"sched:sched_wakeup" ) ==0 ) +else if (strcmp (event_str,"sched:sched_wakeup" ) ==0 )sched_wakeup (data.cpu, data.time, data.pid, te); -if (strcmp (event_str,"sched:sched_switch" ) ==0 ) +else if (strcmp (event_str,"sched:sched_switch" ) ==0 )sched_switch (data.cpu, data.time, te); + +#if defined(SUPPORT_OLD_POWER_EVENTS ) +if (use_old_power_events) { +if (strcmp (event_str,"power:power_start" ) ==0 ) +c_state_start (peo->cpu_id, data.time, peo->value); + +else if (strcmp (event_str,"power:power_end" ) ==0 ) +c_state_end (data.cpu, data.time); + +else if (strcmp (event_str,"power:power_frequency" ) ==0 ) +p_state_change (peo->cpu_id, data.time, peo->value); + } +#endif }return 0 ; }
@@ -968,7 +1000,8 @@ static const char * const timechart_usage[] = {NULL }; -static const char *record_args[] = { +#if defined(SUPPORT_OLD_POWER_EVENTS ) +static const char *record_old_args[] = {"record" ,"-a" , "-R",
@@ -980,16 +1013,40 @@ static const char *record_args[] = {"-e" ,"sched:sched_wakeup" , "-e", "sched:sched_switch", }; +#endif + +static const char *record_new_args[] = { +"record" , +"-a" , +"-R" , +"-f" , +"-c" ,"1" , +"-e" ,"power:cpu_frequency" , +"-e" ,"power:cpu_idle" , +"-e" ,"sched:sched_wakeup" , +"-e" ,"sched:sched_switch" , +};static int __cmd_record (int argc,const char **argv) {unsigned int rec_argc, i, j;const char **rec_argv; - - rec_argc =ARRAY_SIZE (record_args) + argc -1 ; +const char **record_args = record_new_args; +unsigned int record_elems =ARRAY_SIZE (record_new_args); + +#if defined(SUPPORT_OLD_POWER_EVENTS ) +if (!is_valid_tracepoint ("power:cpu_idle" ) && +is_valid_tracepoint ("power:power_start" )) { + use_old_power_events =1 ; + record_args = record_old_args; + record_elems =ARRAY_SIZE (record_old_args); + } +#endif + + rec_argc = record_elems + argc -1 ; rec_argv =calloc (rec_argc +1 ,sizeof (char *)); -for (i =0 ; i <ARRAY_SIZE (record_args); i++) +for (i =0 ; i < record_elems; i++) rec_argv[i] =strdup (record_args[i]);for (j =1 ; j < (unsigned int )argc; j++, i++)
tools/perf/util/parse-events.c +41 -0
47 lines not on this page · raw message
tools/perf/util/parse-events.h +1 -0
@@ -29,6 +29,7 @@ extern int parse_filter(const struct option *opt, const char *str, int unset);#define EVENTS_HELP_MAX (128*1024)extern void print_events (void ); +extern int is_valid_tracepoint (const char *event_string);extern char debugfs_path[];extern int valid_debugfs_mount (const char *debugfs);
Re: [PATCH 3/3] PERF(userspace): Adjust perf timechart to the new power events
In reply to Thomas RenningerQuoted 3 lines · On Thursday 28 October 2010 11:02:59 Thomas Renninger wrote:
Recent changes:
- Adjust state/cpuid to u32 as done in the kernel
Argh, I forgot a guilt refresh...
Below final :) patch also fixes a bug that got introduced in 2.6.36 already. Will also send a version for stable inclusion.
Thomas
----
PERF(userspace): Adjust perf timechart to the new power events
Recent changes:
- Adjust state/cpuid to u32 as done in the kernel
The transition was rather smooth, only part I had to fiddle some time was the check whether a tracepoint/event is supported by the running kernel.
builtin-timechart must only pass -e power:xy events which are supported by the running kernel.
For this I added the tiny helper function:
int is_valid_tracepoint(const char *event_string)
to parse-events.[hc]
which could be more generic as an interface and support hardware/software/... events, not only tracepoints, but someone else could extend that if needed...
tools/perf/builtin-timechart.c +74 -17
@@ -32,6 +32,10 @@#include "util/session.h" #include "util/svghelper.h" +#define SUPPORT_OLD_POWER_EVENTS 1 +#define PWR_EVENT_EXIT -1 + +static char const *input_name ="perf.data" ;static char const *output_name ="output.svg" ;
@@ -298,12 +302,21 @@ struct trace_entry {int lock_depth; }; -struct power_entry { +#if defined(SUPPORT_OLD_POWER_EVENTS ) +static int use_old_power_events; +struct power_entry_old {struct trace_entry te;u64 type;u64 value;u64 cpu_id; }; +#endif + +struct power_processor_entry { +struct trace_entry te; +u32 state; +u32 cpu_id; +};#define TASK_COMM_LEN 16struct wakeup_entry {
@@ -489,29 +502,48 @@ static int process_sample_event(event_t *event, struct perf_session *session) te = (void *)data.raw_data;if (session->sample_type &PERF_SAMPLE_RAW && data.raw_size >0 ) {char *event_str; -struct power_entry *pe; - - pe = (void *)te; +#if defined(SUPPORT_OLD_POWER_EVENTS ) +struct power_entry_old *peo; + peo = (void *)te; +#endif event_str =perf_header__find_event (te->type);if (!event_str)return 0 ; -if (strcmp (event_str,"power:power_start" ) ==0 ) -c_state_start (pe->cpu_id, data.time, pe->value); - -if (strcmp (event_str,"power:power_end" ) ==0 ) -c_state_end (pe->cpu_id, data.time); +if (strcmp (event_str,"power:cpu_idle" ) ==0 ) { +struct power_processor_entry *ppe = (void *)te; +if (ppe->state == (u32 )PWR_EVENT_EXIT ) +c_state_end (ppe->cpu_id, data.time); +else +c_state_start (ppe->cpu_id, data.time, + ppe->state); + } -if (strcmp (event_str,"power:power_frequency" ) ==0 ) -p_state_change (pe->cpu_id, data.time, pe->value); +else if (strcmp (event_str,"power:cpu_frequency" ) ==0 ) { +struct power_processor_entry *ppe = (void *)te; +p_state_change (ppe->cpu_id, data.time, ppe->state); + } -if (strcmp (event_str,"sched:sched_wakeup" ) ==0 ) +else if (strcmp (event_str,"sched:sched_wakeup" ) ==0 )sched_wakeup (data.cpu, data.time, data.pid, te); -if (strcmp (event_str,"sched:sched_switch" ) ==0 ) +else if (strcmp (event_str,"sched:sched_switch" ) ==0 )sched_switch (data.cpu, data.time, te); + +#if defined(SUPPORT_OLD_POWER_EVENTS ) +if (use_old_power_events) { +if (strcmp (event_str,"power:power_start" ) ==0 ) +c_state_start (peo->cpu_id, data.time, peo->value); + +else if (strcmp (event_str,"power:power_end" ) ==0 ) +c_state_end (data.cpu, data.time); + +else if (strcmp (event_str,"power:power_frequency" ) ==0 ) +p_state_change (peo->cpu_id, data.time, peo->value); + } +#endif }return 0 ; }
@@ -968,7 +1000,8 @@ static const char * const timechart_usage[] = {NULL }; -static const char *record_args[] = { +#if defined(SUPPORT_OLD_POWER_EVENTS ) +static const char *record_old_args[] = {"record" ,"-a" , "-R",
@@ -980,16 +1013,40 @@ static const char *record_args[] = {"-e" ,"sched:sched_wakeup" , "-e", "sched:sched_switch", }; +#endif + +static const char *record_new_args[] = { +"record" , +"-a" , +"-R" , +"-f" , +"-c" ,"1" , +"-e" ,"power:cpu_frequency" , +"-e" ,"power:cpu_idle" , +"-e" ,"sched:sched_wakeup" , +"-e" ,"sched:sched_switch" , +};static int __cmd_record (int argc,const char **argv) {unsigned int rec_argc, i, j;const char **rec_argv; - - rec_argc =ARRAY_SIZE (record_args) + argc -1 ; +const char **record_args = record_new_args; +unsigned int record_elems =ARRAY_SIZE (record_new_args); + +#if defined(SUPPORT_OLD_POWER_EVENTS ) +if (!is_valid_tracepoint ("power:cpu_idle" ) && +is_valid_tracepoint ("power:power_start" )) { + use_old_power_events =1 ; + record_args = record_old_args; + record_elems =ARRAY_SIZE (record_old_args); + } +#endif + + rec_argc = record_elems + argc -1 ; rec_argv =calloc (rec_argc +1 ,sizeof (char *)); -for (i =0 ; i <ARRAY_SIZE (record_args); i++) +for (i =0 ; i < record_elems; i++) rec_argv[i] =strdup (record_args[i]);for (j =1 ; j < (unsigned int )argc; j++, i++)
tools/perf/util/parse-events.c +41 -0
47 lines not on this page · raw message
tools/perf/util/parse-events.h +1 -0
@@ -29,6 +29,7 @@ extern int parse_filter(const struct option *opt, const char *str, int unset);#define EVENTS_HELP_MAX (128*1024)extern void print_events (void ); +extern int is_valid_tracepoint (const char *event_string);extern char debugfs_path[];extern int valid_debugfs_mount (const char *debugfs);