Skip to content

Commit 60e10f8

Browse files
huangruirafaeljw
authored andcommitted
cpufreq: amd-pstate: Add trace for AMD P-State module
Add trace event to monitor the performance value changes which is controlled by cpu governors. Signed-off-by: Huang Rui <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent e059c18 commit 60e10f8

File tree

4 files changed

+88
-1
lines changed

4 files changed

+88
-1
lines changed

drivers/cpufreq/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ obj-$(CONFIG_CPU_FREQ_GOV_ATTR_SET) += cpufreq_governor_attr_set.o
1717
obj-$(CONFIG_CPUFREQ_DT) += cpufreq-dt.o
1818
obj-$(CONFIG_CPUFREQ_DT_PLATDEV) += cpufreq-dt-platdev.o
1919

20+
# Traces
21+
CFLAGS_amd-pstate-trace.o := -I$(src)
22+
amd_pstate-y := amd-pstate.o amd-pstate-trace.o
23+
2024
##################################################################################
2125
# x86 drivers.
2226
# Link order matters. K8 is preferred to ACPI because of firmware bugs in early
@@ -25,7 +29,7 @@ obj-$(CONFIG_CPUFREQ_DT_PLATDEV) += cpufreq-dt-platdev.o
2529
# speedstep-* is preferred over p4-clockmod.
2630

2731
obj-$(CONFIG_X86_ACPI_CPUFREQ) += acpi-cpufreq.o
28-
obj-$(CONFIG_X86_AMD_PSTATE) += amd-pstate.o
32+
obj-$(CONFIG_X86_AMD_PSTATE) += amd_pstate.o
2933
obj-$(CONFIG_X86_POWERNOW_K8) += powernow-k8.o
3034
obj-$(CONFIG_X86_PCC_CPUFREQ) += pcc-cpufreq.o
3135
obj-$(CONFIG_X86_POWERNOW_K6) += powernow-k6.o

drivers/cpufreq/amd-pstate-trace.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#define CREATE_TRACE_POINTS
2+
#include "amd-pstate-trace.h"

drivers/cpufreq/amd-pstate-trace.h

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* amd-pstate-trace.h - AMD Processor P-state Frequency Driver Tracer
4+
*
5+
* Copyright (C) 2021 Advanced Micro Devices, Inc. All Rights Reserved.
6+
*
7+
* Author: Huang Rui <[email protected]>
8+
*/
9+
10+
#if !defined(_AMD_PSTATE_TRACE_H) || defined(TRACE_HEADER_MULTI_READ)
11+
#define _AMD_PSTATE_TRACE_H
12+
13+
#include <linux/cpufreq.h>
14+
#include <linux/tracepoint.h>
15+
#include <linux/trace_events.h>
16+
17+
#undef TRACE_SYSTEM
18+
#define TRACE_SYSTEM amd_cpu
19+
20+
#undef TRACE_INCLUDE_FILE
21+
#define TRACE_INCLUDE_FILE amd-pstate-trace
22+
23+
#define TPS(x) tracepoint_string(x)
24+
25+
TRACE_EVENT(amd_pstate_perf,
26+
27+
TP_PROTO(unsigned long min_perf,
28+
unsigned long target_perf,
29+
unsigned long capacity,
30+
unsigned int cpu_id,
31+
bool changed,
32+
bool fast_switch
33+
),
34+
35+
TP_ARGS(min_perf,
36+
target_perf,
37+
capacity,
38+
cpu_id,
39+
changed,
40+
fast_switch
41+
),
42+
43+
TP_STRUCT__entry(
44+
__field(unsigned long, min_perf)
45+
__field(unsigned long, target_perf)
46+
__field(unsigned long, capacity)
47+
__field(unsigned int, cpu_id)
48+
__field(bool, changed)
49+
__field(bool, fast_switch)
50+
),
51+
52+
TP_fast_assign(
53+
__entry->min_perf = min_perf;
54+
__entry->target_perf = target_perf;
55+
__entry->capacity = capacity;
56+
__entry->cpu_id = cpu_id;
57+
__entry->changed = changed;
58+
__entry->fast_switch = fast_switch;
59+
),
60+
61+
TP_printk("amd_min_perf=%lu amd_des_perf=%lu amd_max_perf=%lu cpu_id=%u changed=%s fast_switch=%s",
62+
(unsigned long)__entry->min_perf,
63+
(unsigned long)__entry->target_perf,
64+
(unsigned long)__entry->capacity,
65+
(unsigned int)__entry->cpu_id,
66+
(__entry->changed) ? "true" : "false",
67+
(__entry->fast_switch) ? "true" : "false"
68+
)
69+
);
70+
71+
#endif /* _AMD_PSTATE_TRACE_H */
72+
73+
/* This part must be outside protection */
74+
#undef TRACE_INCLUDE_PATH
75+
#define TRACE_INCLUDE_PATH .
76+
77+
#include <trace/define_trace.h>

drivers/cpufreq/amd-pstate.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include <asm/processor.h>
4545
#include <asm/cpufeature.h>
4646
#include <asm/cpu_device_id.h>
47+
#include "amd-pstate-trace.h"
4748

4849
#define AMD_PSTATE_TRANSITION_LATENCY 0x20000
4950
#define AMD_PSTATE_TRANSITION_DELAY 500
@@ -220,6 +221,9 @@ static void amd_pstate_update(struct amd_cpudata *cpudata, u32 min_perf,
220221
value &= ~AMD_CPPC_MAX_PERF(~0L);
221222
value |= AMD_CPPC_MAX_PERF(max_perf);
222223

224+
trace_amd_pstate_perf(min_perf, des_perf, max_perf,
225+
cpudata->cpu, (value != prev), fast_switch);
226+
223227
if (value == prev)
224228
return;
225229

0 commit comments

Comments
 (0)