Skip to content

Commit 6161352

Browse files
fenrus75Ingo Molnar
authored andcommitted
tracing, perf: Convert the power tracer into an event tracer
This patch converts the existing power tracer into an event tracer, so that power events (C states and frequency changes) can be tracked via "perf". This also removes the perl script that was used to demo the tracer; its functionality is being replaced entirely with timechart. Signed-off-by: Arjan van de Ven <arjan@linux.intel.com> Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Paul Mackerras <paulus@samba.org> Cc: Frederic Weisbecker <fweisbec@gmail.com> LKML-Reference: <20090912130542.6d314860@infradead.org> Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent fd39e05 commit 6161352

10 files changed

Lines changed: 113 additions & 388 deletions

File tree

‎Documentation/trace/power.txt‎

Lines changed: 0 additions & 17 deletions
This file was deleted.

‎arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include <linux/cpufreq.h>
3434
#include <linux/compiler.h>
3535
#include <linux/dmi.h>
36-
#include <trace/power.h>
36+
#include <trace/events/power.h>
3737

3838
#include <linux/acpi.h>
3939
#include <linux/io.h>
@@ -72,8 +72,6 @@ static DEFINE_PER_CPU(struct acpi_cpufreq_data *, drv_data);
7272

7373
static DEFINE_PER_CPU(struct aperfmperf, old_perf);
7474

75-
DEFINE_TRACE(power_mark);
76-
7775
/* acpi_perf_data is a pointer to percpu data. */
7876
static struct acpi_processor_performance *acpi_perf_data;
7977

@@ -332,7 +330,6 @@ static int acpi_cpufreq_target(struct cpufreq_policy *policy,
332330
unsigned int next_perf_state = 0; /* Index into perf table */
333331
unsigned int i;
334332
int result = 0;
335-
struct power_trace it;
336333

337334
dprintk("acpi_cpufreq_target %d (%d)\n", target_freq, policy->cpu);
338335

@@ -364,7 +361,7 @@ static int acpi_cpufreq_target(struct cpufreq_policy *policy,
364361
}
365362
}
366363

367-
trace_power_mark(&it, POWER_PSTATE, next_perf_state);
364+
trace_power_frequency(POWER_PSTATE, data->freq_table[next_state].frequency);
368365

369366
switch (data->cpu_feature) {
370367
case SYSTEM_INTEL_MSR_CAPABLE:

‎arch/x86/kernel/process.c‎

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <linux/pm.h>
1010
#include <linux/clockchips.h>
1111
#include <linux/random.h>
12-
#include <trace/power.h>
12+
#include <trace/events/power.h>
1313
#include <asm/system.h>
1414
#include <asm/apic.h>
1515
#include <asm/syscalls.h>
@@ -25,9 +25,6 @@ EXPORT_SYMBOL(idle_nomwait);
2525

2626
struct kmem_cache *task_xstate_cachep;
2727

28-
DEFINE_TRACE(power_start);
29-
DEFINE_TRACE(power_end);
30-
3128
int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
3229
{
3330
*dst = *src;
@@ -299,9 +296,7 @@ static inline int hlt_use_halt(void)
299296
void default_idle(void)
300297
{
301298
if (hlt_use_halt()) {
302-
struct power_trace it;
303-
304-
trace_power_start(&it, POWER_CSTATE, 1);
299+
trace_power_start(POWER_CSTATE, 1);
305300
current_thread_info()->status &= ~TS_POLLING;
306301
/*
307302
* TS_POLLING-cleared state must be visible before we
@@ -314,7 +309,7 @@ void default_idle(void)
314309
else
315310
local_irq_enable();
316311
current_thread_info()->status |= TS_POLLING;
317-
trace_power_end(&it);
312+
trace_power_end(0);
318313
} else {
319314
local_irq_enable();
320315
/* loop is done by the caller */
@@ -372,9 +367,7 @@ EXPORT_SYMBOL_GPL(cpu_idle_wait);
372367
*/
373368
void mwait_idle_with_hints(unsigned long ax, unsigned long cx)
374369
{
375-
struct power_trace it;
376-
377-
trace_power_start(&it, POWER_CSTATE, (ax>>4)+1);
370+
trace_power_start(POWER_CSTATE, (ax>>4)+1);
378371
if (!need_resched()) {
379372
if (cpu_has(&current_cpu_data, X86_FEATURE_CLFLUSH_MONITOR))
380373
clflush((void *)&current_thread_info()->flags);
@@ -384,15 +377,14 @@ void mwait_idle_with_hints(unsigned long ax, unsigned long cx)
384377
if (!need_resched())
385378
__mwait(ax, cx);
386379
}
387-
trace_power_end(&it);
380+
trace_power_end(0);
388381
}
389382

390383
/* Default MONITOR/MWAIT with no hints, used for default C1 state */
391384
static void mwait_idle(void)
392385
{
393-
struct power_trace it;
394386
if (!need_resched()) {
395-
trace_power_start(&it, POWER_CSTATE, 1);
387+
trace_power_start(POWER_CSTATE, 1);
396388
if (cpu_has(&current_cpu_data, X86_FEATURE_CLFLUSH_MONITOR))
397389
clflush((void *)&current_thread_info()->flags);
398390

@@ -402,7 +394,7 @@ static void mwait_idle(void)
402394
__sti_mwait(0, 0);
403395
else
404396
local_irq_enable();
405-
trace_power_end(&it);
397+
trace_power_end(0);
406398
} else
407399
local_irq_enable();
408400
}
@@ -414,13 +406,11 @@ static void mwait_idle(void)
414406
*/
415407
static void poll_idle(void)
416408
{
417-
struct power_trace it;
418-
419-
trace_power_start(&it, POWER_CSTATE, 0);
409+
trace_power_start(POWER_CSTATE, 0);
420410
local_irq_enable();
421411
while (!need_resched())
422412
cpu_relax();
423-
trace_power_end(&it);
413+
trace_power_end(0);
424414
}
425415

426416
/*

‎include/trace/events/power.h‎

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#undef TRACE_SYSTEM
2+
#define TRACE_SYSTEM power
3+
4+
#if !defined(_TRACE_POWER_H) || defined(TRACE_HEADER_MULTI_READ)
5+
#define _TRACE_POWER_H
6+
7+
#include <linux/ktime.h>
8+
#include <linux/tracepoint.h>
9+
10+
#ifndef _TRACE_POWER_ENUM_
11+
#define _TRACE_POWER_ENUM_
12+
enum {
13+
POWER_NONE = 0,
14+
POWER_CSTATE = 1,
15+
POWER_PSTATE = 2,
16+
};
17+
#endif
18+
19+
20+
21+
TRACE_EVENT(power_start,
22+
23+
TP_PROTO(unsigned int type, unsigned int state),
24+
25+
TP_ARGS(type, state),
26+
27+
TP_STRUCT__entry(
28+
__field( u64, type )
29+
__field( u64, state )
30+
),
31+
32+
TP_fast_assign(
33+
__entry->type = type;
34+
__entry->state = state;
35+
),
36+
37+
TP_printk("type=%lu state=%lu", (unsigned long)__entry->type, (unsigned long)__entry->state)
38+
);
39+
40+
TRACE_EVENT(power_end,
41+
42+
TP_PROTO(int dummy),
43+
44+
TP_ARGS(dummy),
45+
46+
TP_STRUCT__entry(
47+
__field( u64, dummy )
48+
),
49+
50+
TP_fast_assign(
51+
__entry->dummy = 0xffff;
52+
),
53+
54+
TP_printk("dummy=%lu", (unsigned long)__entry->dummy)
55+
56+
);
57+
58+
59+
TRACE_EVENT(power_frequency,
60+
61+
TP_PROTO(unsigned int type, unsigned int state),
62+
63+
TP_ARGS(type, state),
64+
65+
TP_STRUCT__entry(
66+
__field( u64, type )
67+
__field( u64, state )
68+
),
69+
70+
TP_fast_assign(
71+
__entry->type = type;
72+
__entry->state = state;
73+
),
74+
75+
TP_printk("type=%lu state=%lu", (unsigned long)__entry->type, (unsigned long) __entry->state)
76+
);
77+
78+
#endif /* _TRACE_POWER_H */
79+
80+
/* This part must be outside protection */
81+
#include <trace/define_trace.h>

‎kernel/trace/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ obj-$(CONFIG_BOOT_TRACER) += trace_boot.o
4242
obj-$(CONFIG_FUNCTION_GRAPH_TRACER) += trace_functions_graph.o
4343
obj-$(CONFIG_TRACE_BRANCH_PROFILING) += trace_branch.o
4444
obj-$(CONFIG_HW_BRANCH_TRACER) += trace_hw_branches.o
45-
obj-$(CONFIG_POWER_TRACER) += trace_power.o
4645
obj-$(CONFIG_KMEMTRACE) += kmemtrace.o
4746
obj-$(CONFIG_WORKQUEUE_TRACER) += trace_workqueue.o
4847
obj-$(CONFIG_BLK_DEV_IO_TRACE) += blktrace.o
@@ -54,5 +53,6 @@ obj-$(CONFIG_EVENT_TRACING) += trace_export.o
5453
obj-$(CONFIG_FTRACE_SYSCALLS) += trace_syscalls.o
5554
obj-$(CONFIG_EVENT_PROFILE) += trace_event_profile.o
5655
obj-$(CONFIG_EVENT_TRACING) += trace_events_filter.o
56+
obj-$(CONFIG_EVENT_TRACING) += power-traces.o
5757

5858
libftrace-y := ftrace.o

‎kernel/trace/power-traces.c‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Power trace points
3+
*
4+
* Copyright (C) 2009 Arjan van de Ven <arjan@linux.intel.com>
5+
*/
6+
7+
#include <linux/string.h>
8+
#include <linux/types.h>
9+
#include <linux/workqueue.h>
10+
#include <linux/sched.h>
11+
#include <linux/module.h>
12+
#include <linux/slab.h>
13+
14+
#define CREATE_TRACE_POINTS
15+
#include <trace/events/power.h>
16+
17+
EXPORT_TRACEPOINT_SYMBOL_GPL(power_start);
18+
EXPORT_TRACEPOINT_SYMBOL_GPL(power_end);
19+
EXPORT_TRACEPOINT_SYMBOL_GPL(power_frequency);
20+

‎kernel/trace/trace.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <linux/ftrace.h>
1212
#include <trace/boot.h>
1313
#include <linux/kmemtrace.h>
14-
#include <trace/power.h>
1514

1615
#include <linux/trace_seq.h>
1716
#include <linux/ftrace_event.h>
@@ -37,7 +36,6 @@ enum trace_type {
3736
TRACE_HW_BRANCHES,
3837
TRACE_KMEM_ALLOC,
3938
TRACE_KMEM_FREE,
40-
TRACE_POWER,
4139
TRACE_BLK,
4240

4341
__TRACE_LAST_TYPE,
@@ -207,7 +205,6 @@ extern void __ftrace_bad_type(void);
207205
IF_ASSIGN(var, ent, struct ftrace_graph_ret_entry, \
208206
TRACE_GRAPH_RET); \
209207
IF_ASSIGN(var, ent, struct hw_branch_entry, TRACE_HW_BRANCHES);\
210-
IF_ASSIGN(var, ent, struct trace_power, TRACE_POWER); \
211208
IF_ASSIGN(var, ent, struct kmemtrace_alloc_entry, \
212209
TRACE_KMEM_ALLOC); \
213210
IF_ASSIGN(var, ent, struct kmemtrace_free_entry, \

‎kernel/trace/trace_entries.h‎

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -330,23 +330,6 @@ FTRACE_ENTRY(hw_branch, hw_branch_entry,
330330
F_printk("from: %llx to: %llx", __entry->from, __entry->to)
331331
);
332332

333-
FTRACE_ENTRY(power, trace_power,
334-
335-
TRACE_POWER,
336-
337-
F_STRUCT(
338-
__field_struct( struct power_trace, state_data )
339-
__field_desc( s64, state_data, stamp )
340-
__field_desc( s64, state_data, end )
341-
__field_desc( int, state_data, type )
342-
__field_desc( int, state_data, state )
343-
),
344-
345-
F_printk("%llx->%llx type:%u state:%u",
346-
__entry->stamp, __entry->end,
347-
__entry->type, __entry->state)
348-
);
349-
350333
FTRACE_ENTRY(kmem_alloc, kmemtrace_alloc_entry,
351334

352335
TRACE_KMEM_ALLOC,

0 commit comments

Comments
 (0)