Skip to content

Commit 5f567af

Browse files
superm1shuahkh
authored andcommitted
cpupower: Add support for showing energy performance preference
The EPP value is useful for characterization of performance. Show it in cpupower frequency-info output. Link: https://lore.kernel.org/r/20241218191144.3440854-6-superm1@kernel.org Signed-off-by: Mario Limonciello <mario.limonciello@amd.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent 26e1617 commit 5f567af

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

tools/power/cpupower/lib/cpufreq.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,14 @@ static unsigned long sysfs_cpufreq_get_one_value(unsigned int cpu,
127127
enum cpufreq_string {
128128
SCALING_DRIVER,
129129
SCALING_GOVERNOR,
130+
ENERGY_PERFORMANCE_PREFERENCE,
130131
MAX_CPUFREQ_STRING_FILES
131132
};
132133

133134
static const char *cpufreq_string_files[MAX_CPUFREQ_STRING_FILES] = {
134135
[SCALING_DRIVER] = "scaling_driver",
135136
[SCALING_GOVERNOR] = "scaling_governor",
137+
[ENERGY_PERFORMANCE_PREFERENCE] = "energy_performance_preference",
136138
};
137139

138140

@@ -207,6 +209,18 @@ unsigned long cpufreq_get_transition_latency(unsigned int cpu)
207209
return sysfs_cpufreq_get_one_value(cpu, CPUINFO_LATENCY);
208210
}
209211

212+
char *cpufreq_get_energy_performance_preference(unsigned int cpu)
213+
{
214+
return sysfs_cpufreq_get_one_string(cpu, ENERGY_PERFORMANCE_PREFERENCE);
215+
}
216+
217+
void cpufreq_put_energy_performance_preference(char *ptr)
218+
{
219+
if (!ptr)
220+
return;
221+
free(ptr);
222+
}
223+
210224
int cpufreq_get_hardware_limits(unsigned int cpu,
211225
unsigned long *min,
212226
unsigned long *max)

tools/power/cpupower/lib/cpufreq.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ unsigned long cpufreq_get_freq_hardware(unsigned int cpu);
6868
unsigned long cpufreq_get_transition_latency(unsigned int cpu);
6969

7070

71+
/* determine energy performance preference
72+
*
73+
* returns NULL on failure, else the string that represents the energy performance
74+
* preference requested.
75+
*/
76+
char *cpufreq_get_energy_performance_preference(unsigned int cpu);
77+
void cpufreq_put_energy_performance_preference(char *ptr);
78+
7179
/* determine hardware CPU frequency limits
7280
*
7381
* These may be limited further by thermal, energy or other

tools/power/cpupower/utils/cpufreq-info.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,23 @@ static int get_freq_stats(unsigned int cpu, unsigned int human)
422422
return 0;
423423
}
424424

425+
/* --epp / -z */
426+
427+
static int get_epp(unsigned int cpu, bool interactive)
428+
{
429+
char *epp;
430+
431+
epp = cpufreq_get_energy_performance_preference(cpu);
432+
if (!epp)
433+
return -EINVAL;
434+
if (interactive)
435+
printf(_(" energy performance preference: %s\n"), epp);
436+
437+
cpufreq_put_energy_performance_preference(epp);
438+
439+
return 0;
440+
}
441+
425442
/* --latency / -y */
426443

427444
static int get_latency(unsigned int cpu, unsigned int human)
@@ -461,6 +478,7 @@ static void debug_output_one(unsigned int cpu)
461478
get_related_cpus(cpu);
462479
get_affected_cpus(cpu);
463480
get_latency(cpu, 1);
481+
get_epp(cpu, true);
464482
get_hardware_limits(cpu, 1);
465483

466484
freqs = cpufreq_get_available_frequencies(cpu);
@@ -501,6 +519,7 @@ static struct option info_opts[] = {
501519
{"human", no_argument, NULL, 'm'},
502520
{"no-rounding", no_argument, NULL, 'n'},
503521
{"performance", no_argument, NULL, 'c'},
522+
{"epp", no_argument, NULL, 'z'},
504523
{ },
505524
};
506525

@@ -514,7 +533,7 @@ int cmd_freq_info(int argc, char **argv)
514533
int output_param = 0;
515534

516535
do {
517-
ret = getopt_long(argc, argv, "oefwldpgrasmybnc", info_opts,
536+
ret = getopt_long(argc, argv, "oefwldpgrasmybncz", info_opts,
518537
NULL);
519538
switch (ret) {
520539
case '?':
@@ -538,6 +557,7 @@ int cmd_freq_info(int argc, char **argv)
538557
case 's':
539558
case 'y':
540559
case 'c':
560+
case 'z':
541561
if (output_param) {
542562
output_param = -1;
543563
cont = 0;
@@ -647,6 +667,9 @@ int cmd_freq_info(int argc, char **argv)
647667
case 'c':
648668
ret = get_perf_cap(cpu);
649669
break;
670+
case 'z':
671+
ret = get_epp(cpu, true);
672+
break;
650673
}
651674
if (ret)
652675
return ret;

0 commit comments

Comments
 (0)