Skip to content

Commit b69880f

Browse files
Dirk Brandewierafaeljw
authored andcommitted
intel_pstate: Add trace point to report internal state.
Add perf trace event "power:pstate_sample" to report driver state to aid in diagnosing issues reported against intel_pstate. Signed-off-by: Dirk Brandewie <dirk.j.brandewie@intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 652ed95 commit b69880f

2 files changed

Lines changed: 77 additions & 0 deletions

File tree

‎drivers/cpufreq/intel_pstate.c‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ static inline int32_t div_fp(int32_t x, int32_t y)
5151
return div_s64((int64_t)x << FRAC_BITS, (int64_t)y);
5252
}
5353

54+
static u64 energy_divisor;
55+
5456
struct sample {
5557
int32_t core_pct_busy;
5658
u64 aperf;
@@ -559,6 +561,7 @@ static inline void intel_pstate_sample(struct cpudata *cpu)
559561

560562
rdmsrl(MSR_IA32_APERF, aperf);
561563
rdmsrl(MSR_IA32_MPERF, mperf);
564+
562565
cpu->sample_ptr = (cpu->sample_ptr + 1) % SAMPLE_COUNT;
563566
cpu->samples[cpu->sample_ptr].aperf = aperf;
564567
cpu->samples[cpu->sample_ptr].mperf = mperf;
@@ -603,6 +606,7 @@ static inline void intel_pstate_adjust_busy_pstate(struct cpudata *cpu)
603606
ctl = pid_calc(pid, busy_scaled);
604607

605608
steps = abs(ctl);
609+
606610
if (ctl < 0)
607611
intel_pstate_pstate_increase(cpu, steps);
608612
else
@@ -612,9 +616,24 @@ static inline void intel_pstate_adjust_busy_pstate(struct cpudata *cpu)
612616
static void intel_pstate_timer_func(unsigned long __data)
613617
{
614618
struct cpudata *cpu = (struct cpudata *) __data;
619+
struct sample *sample;
620+
u64 energy;
615621

616622
intel_pstate_sample(cpu);
623+
624+
sample = &cpu->samples[cpu->sample_ptr];
625+
rdmsrl(MSR_PKG_ENERGY_STATUS, energy);
626+
617627
intel_pstate_adjust_busy_pstate(cpu);
628+
629+
trace_pstate_sample(fp_toint(sample->core_pct_busy),
630+
fp_toint(intel_pstate_get_scaled_busy(cpu)),
631+
cpu->pstate.current_pstate,
632+
sample->mperf,
633+
sample->aperf,
634+
div64_u64(energy, energy_divisor),
635+
sample->freq);
636+
618637
intel_pstate_set_sample_time(cpu);
619638
}
620639

@@ -894,6 +913,7 @@ static int __init intel_pstate_init(void)
894913
int cpu, rc = 0;
895914
const struct x86_cpu_id *id;
896915
struct cpu_defaults *cpu_info;
916+
u64 units;
897917

898918
if (no_load)
899919
return -ENODEV;
@@ -927,8 +947,12 @@ static int __init intel_pstate_init(void)
927947
if (rc)
928948
goto out;
929949

950+
rdmsrl(MSR_RAPL_POWER_UNIT, units);
951+
energy_divisor = 1 << ((units >> 8) & 0x1f); /* bits{12:8} */
952+
930953
intel_pstate_debug_expose_params();
931954
intel_pstate_sysfs_expose_params();
955+
932956
return rc;
933957
out:
934958
get_online_cpus();

‎include/trace/events/power.h‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,59 @@ DEFINE_EVENT(cpu, cpu_idle,
3535
TP_ARGS(state, cpu_id)
3636
);
3737

38+
TRACE_EVENT(pstate_sample,
39+
40+
TP_PROTO(u32 core_busy,
41+
u32 scaled_busy,
42+
u32 state,
43+
u64 mperf,
44+
u64 aperf,
45+
u32 energy,
46+
u32 freq
47+
),
48+
49+
TP_ARGS(core_busy,
50+
scaled_busy,
51+
state,
52+
mperf,
53+
aperf,
54+
energy,
55+
freq
56+
),
57+
58+
TP_STRUCT__entry(
59+
__field(u32, core_busy)
60+
__field(u32, scaled_busy)
61+
__field(u32, state)
62+
__field(u64, mperf)
63+
__field(u64, aperf)
64+
__field(u32, energy)
65+
__field(u32, freq)
66+
67+
),
68+
69+
TP_fast_assign(
70+
__entry->core_busy = core_busy;
71+
__entry->scaled_busy = scaled_busy;
72+
__entry->state = state;
73+
__entry->mperf = mperf;
74+
__entry->aperf = aperf;
75+
__entry->energy = energy;
76+
__entry->freq = freq;
77+
),
78+
79+
TP_printk("core_busy=%lu scaled=%lu state=%lu mperf=%llu aperf=%llu energy=%lu freq=%lu ",
80+
(unsigned long)__entry->core_busy,
81+
(unsigned long)__entry->scaled_busy,
82+
(unsigned long)__entry->state,
83+
(unsigned long long)__entry->mperf,
84+
(unsigned long long)__entry->aperf,
85+
(unsigned long)__entry->energy,
86+
(unsigned long)__entry->freq
87+
)
88+
89+
);
90+
3891
/* This file can get included multiple times, TRACE_HEADER_MULTI_READ at top */
3992
#ifndef _PWR_EVENT_AVOID_DOUBLE_DEFINING
4093
#define _PWR_EVENT_AVOID_DOUBLE_DEFINING

0 commit comments

Comments
 (0)