Skip to content

Commit 6c1bae7

Browse files
committed
Merge branch 'turbostat' of git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux
Pull turbostat updates from Len Brown: "Update to turbostat v20.03.20. These patches unlock the full turbostat features for some new machines, plus a couple other minor tweaks" * 'turbostat' of git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux: tools/power turbostat: update version tools/power turbostat: Print cpuidle information tools/power turbostat: Fix 32-bit capabilities warning tools/power turbostat: Fix missing SYS_LPI counter on some Chromebooks tools/power turbostat: Support Elkhart Lake tools/power turbostat: Support Jasper Lake tools/power turbostat: Support Ice Lake server tools/power turbostat: Support Tiger Lake tools/power turbostat: Fix gcc build warnings tools/power turbostat: Support Cometlake
2 parents c63c50f + b95fffb commit 6c1bae7

File tree

2 files changed

+114
-30
lines changed

2 files changed

+114
-30
lines changed

tools/power/x86/turbostat/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ override CFLAGS += -D_FORTIFY_SOURCE=2
1616

1717
%: %.c
1818
@mkdir -p $(BUILD_OUTPUT)
19-
$(CC) $(CFLAGS) $< -o $(BUILD_OUTPUT)/$@ $(LDFLAGS)
19+
$(CC) $(CFLAGS) $< -o $(BUILD_OUTPUT)/$@ $(LDFLAGS) -lcap
2020

2121
.PHONY : clean
2222
clean :

tools/power/x86/turbostat/turbostat.c

Lines changed: 113 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include <sched.h>
3131
#include <time.h>
3232
#include <cpuid.h>
33-
#include <linux/capability.h>
33+
#include <sys/capability.h>
3434
#include <errno.h>
3535
#include <math.h>
3636

@@ -304,6 +304,10 @@ int *irqs_per_cpu; /* indexed by cpu_num */
304304

305305
void setup_all_buffers(void);
306306

307+
char *sys_lpi_file;
308+
char *sys_lpi_file_sysfs = "/sys/devices/system/cpu/cpuidle/low_power_idle_system_residency_us";
309+
char *sys_lpi_file_debugfs = "/sys/kernel/debug/pmc_core/slp_s0_residency_usec";
310+
307311
int cpu_is_not_present(int cpu)
308312
{
309313
return !CPU_ISSET_S(cpu, cpu_present_setsize, cpu_present_set);
@@ -2916,8 +2920,6 @@ int snapshot_gfx_mhz(void)
29162920
*
29172921
* record snapshot of
29182922
* /sys/devices/system/cpu/cpuidle/low_power_idle_cpu_residency_us
2919-
*
2920-
* return 1 if config change requires a restart, else return 0
29212923
*/
29222924
int snapshot_cpu_lpi_us(void)
29232925
{
@@ -2941,17 +2943,14 @@ int snapshot_cpu_lpi_us(void)
29412943
/*
29422944
* snapshot_sys_lpi()
29432945
*
2944-
* record snapshot of
2945-
* /sys/devices/system/cpu/cpuidle/low_power_idle_system_residency_us
2946-
*
2947-
* return 1 if config change requires a restart, else return 0
2946+
* record snapshot of sys_lpi_file
29482947
*/
29492948
int snapshot_sys_lpi_us(void)
29502949
{
29512950
FILE *fp;
29522951
int retval;
29532952

2954-
fp = fopen_or_die("/sys/devices/system/cpu/cpuidle/low_power_idle_system_residency_us", "r");
2953+
fp = fopen_or_die(sys_lpi_file, "r");
29552954

29562955
retval = fscanf(fp, "%lld", &cpuidle_cur_sys_lpi_us);
29572956
if (retval != 1) {
@@ -3151,28 +3150,42 @@ void check_dev_msr()
31513150
err(-5, "no /dev/cpu/0/msr, Try \"# modprobe msr\" ");
31523151
}
31533152

3154-
void check_permissions()
3153+
/*
3154+
* check for CAP_SYS_RAWIO
3155+
* return 0 on success
3156+
* return 1 on fail
3157+
*/
3158+
int check_for_cap_sys_rawio(void)
31553159
{
3156-
struct __user_cap_header_struct cap_header_data;
3157-
cap_user_header_t cap_header = &cap_header_data;
3158-
struct __user_cap_data_struct cap_data_data;
3159-
cap_user_data_t cap_data = &cap_data_data;
3160-
extern int capget(cap_user_header_t hdrp, cap_user_data_t datap);
3161-
int do_exit = 0;
3162-
char pathname[32];
3160+
cap_t caps;
3161+
cap_flag_value_t cap_flag_value;
31633162

3164-
/* check for CAP_SYS_RAWIO */
3165-
cap_header->pid = getpid();
3166-
cap_header->version = _LINUX_CAPABILITY_VERSION;
3167-
if (capget(cap_header, cap_data) < 0)
3168-
err(-6, "capget(2) failed");
3163+
caps = cap_get_proc();
3164+
if (caps == NULL)
3165+
err(-6, "cap_get_proc\n");
31693166

3170-
if ((cap_data->effective & (1 << CAP_SYS_RAWIO)) == 0) {
3171-
do_exit++;
3167+
if (cap_get_flag(caps, CAP_SYS_RAWIO, CAP_EFFECTIVE, &cap_flag_value))
3168+
err(-6, "cap_get\n");
3169+
3170+
if (cap_flag_value != CAP_SET) {
31723171
warnx("capget(CAP_SYS_RAWIO) failed,"
31733172
" try \"# setcap cap_sys_rawio=ep %s\"", progname);
3173+
return 1;
31743174
}
31753175

3176+
if (cap_free(caps) == -1)
3177+
err(-6, "cap_free\n");
3178+
3179+
return 0;
3180+
}
3181+
void check_permissions(void)
3182+
{
3183+
int do_exit = 0;
3184+
char pathname[32];
3185+
3186+
/* check for CAP_SYS_RAWIO */
3187+
do_exit += check_for_cap_sys_rawio();
3188+
31763189
/* test file permissions */
31773190
sprintf(pathname, "/dev/cpu/%d/msr", base_cpu);
31783191
if (euidaccess(pathname, R_OK)) {
@@ -3265,6 +3278,7 @@ int probe_nhm_msrs(unsigned int family, unsigned int model)
32653278
case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */
32663279
case INTEL_FAM6_ATOM_GOLDMONT_PLUS:
32673280
case INTEL_FAM6_ATOM_GOLDMONT_D: /* DNV */
3281+
case INTEL_FAM6_ATOM_TREMONT: /* EHL */
32683282
pkg_cstate_limits = glm_pkg_cstate_limits;
32693283
break;
32703284
default:
@@ -3336,6 +3350,17 @@ int is_skx(unsigned int family, unsigned int model)
33363350
}
33373351
return 0;
33383352
}
3353+
int is_ehl(unsigned int family, unsigned int model)
3354+
{
3355+
if (!genuine_intel)
3356+
return 0;
3357+
3358+
switch (model) {
3359+
case INTEL_FAM6_ATOM_TREMONT:
3360+
return 1;
3361+
}
3362+
return 0;
3363+
}
33393364

33403365
int has_turbo_ratio_limit(unsigned int family, unsigned int model)
33413366
{
@@ -3478,6 +3503,23 @@ dump_cstate_pstate_config_info(unsigned int family, unsigned int model)
34783503
dump_nhm_cst_cfg();
34793504
}
34803505

3506+
static void dump_sysfs_file(char *path)
3507+
{
3508+
FILE *input;
3509+
char cpuidle_buf[64];
3510+
3511+
input = fopen(path, "r");
3512+
if (input == NULL) {
3513+
if (debug)
3514+
fprintf(outf, "NSFOD %s\n", path);
3515+
return;
3516+
}
3517+
if (!fgets(cpuidle_buf, sizeof(cpuidle_buf), input))
3518+
err(1, "%s: failed to read file", path);
3519+
fclose(input);
3520+
3521+
fprintf(outf, "%s: %s", strrchr(path, '/') + 1, cpuidle_buf);
3522+
}
34813523
static void
34823524
dump_sysfs_cstate_config(void)
34833525
{
@@ -3491,6 +3533,15 @@ dump_sysfs_cstate_config(void)
34913533
if (!DO_BIC(BIC_sysfs))
34923534
return;
34933535

3536+
if (access("/sys/devices/system/cpu/cpuidle", R_OK)) {
3537+
fprintf(outf, "cpuidle not loaded\n");
3538+
return;
3539+
}
3540+
3541+
dump_sysfs_file("/sys/devices/system/cpu/cpuidle/current_driver");
3542+
dump_sysfs_file("/sys/devices/system/cpu/cpuidle/current_governor");
3543+
dump_sysfs_file("/sys/devices/system/cpu/cpuidle/current_governor_ro");
3544+
34943545
for (state = 0; state < 10; ++state) {
34953546

34963547
sprintf(path, "/sys/devices/system/cpu/cpu%d/cpuidle/state%d/name",
@@ -3894,6 +3945,20 @@ void rapl_probe_intel(unsigned int family, unsigned int model)
38943945
else
38953946
BIC_PRESENT(BIC_PkgWatt);
38963947
break;
3948+
case INTEL_FAM6_ATOM_TREMONT: /* EHL */
3949+
do_rapl = RAPL_PKG | RAPL_CORES | RAPL_CORE_POLICY | RAPL_DRAM | RAPL_DRAM_PERF_STATUS | RAPL_PKG_PERF_STATUS | RAPL_GFX | RAPL_PKG_POWER_INFO;
3950+
if (rapl_joules) {
3951+
BIC_PRESENT(BIC_Pkg_J);
3952+
BIC_PRESENT(BIC_Cor_J);
3953+
BIC_PRESENT(BIC_RAM_J);
3954+
BIC_PRESENT(BIC_GFX_J);
3955+
} else {
3956+
BIC_PRESENT(BIC_PkgWatt);
3957+
BIC_PRESENT(BIC_CorWatt);
3958+
BIC_PRESENT(BIC_RAMWatt);
3959+
BIC_PRESENT(BIC_GFXWatt);
3960+
}
3961+
break;
38973962
case INTEL_FAM6_SKYLAKE_L: /* SKL */
38983963
case INTEL_FAM6_CANNONLAKE_L: /* CNL */
38993964
do_rapl = RAPL_PKG | RAPL_CORES | RAPL_CORE_POLICY | RAPL_DRAM | RAPL_DRAM_PERF_STATUS | RAPL_PKG_PERF_STATUS | RAPL_GFX | RAPL_PKG_POWER_INFO;
@@ -4295,6 +4360,7 @@ int has_snb_msrs(unsigned int family, unsigned int model)
42954360
case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */
42964361
case INTEL_FAM6_ATOM_GOLDMONT_PLUS:
42974362
case INTEL_FAM6_ATOM_GOLDMONT_D: /* DNV */
4363+
case INTEL_FAM6_ATOM_TREMONT: /* EHL */
42984364
return 1;
42994365
}
43004366
return 0;
@@ -4324,6 +4390,7 @@ int has_c8910_msrs(unsigned int family, unsigned int model)
43244390
case INTEL_FAM6_CANNONLAKE_L: /* CNL */
43254391
case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */
43264392
case INTEL_FAM6_ATOM_GOLDMONT_PLUS:
4393+
case INTEL_FAM6_ATOM_TREMONT: /* EHL */
43274394
return 1;
43284395
}
43294396
return 0;
@@ -4610,14 +4677,24 @@ unsigned int intel_model_duplicates(unsigned int model)
46104677
case INTEL_FAM6_SKYLAKE:
46114678
case INTEL_FAM6_KABYLAKE_L:
46124679
case INTEL_FAM6_KABYLAKE:
4680+
case INTEL_FAM6_COMETLAKE_L:
4681+
case INTEL_FAM6_COMETLAKE:
46134682
return INTEL_FAM6_SKYLAKE_L;
46144683

46154684
case INTEL_FAM6_ICELAKE_L:
46164685
case INTEL_FAM6_ICELAKE_NNPI:
4686+
case INTEL_FAM6_TIGERLAKE_L:
4687+
case INTEL_FAM6_TIGERLAKE:
46174688
return INTEL_FAM6_CANNONLAKE_L;
46184689

46194690
case INTEL_FAM6_ATOM_TREMONT_D:
46204691
return INTEL_FAM6_ATOM_GOLDMONT_D;
4692+
4693+
case INTEL_FAM6_ATOM_TREMONT_L:
4694+
return INTEL_FAM6_ATOM_TREMONT;
4695+
4696+
case INTEL_FAM6_ICELAKE_X:
4697+
return INTEL_FAM6_SKYLAKE_X;
46214698
}
46224699
return model;
46234700
}
@@ -4872,7 +4949,8 @@ void process_cpuid()
48724949
do_slm_cstates = is_slm(family, model);
48734950
do_knl_cstates = is_knl(family, model);
48744951

4875-
if (do_slm_cstates || do_knl_cstates || is_cnl(family, model))
4952+
if (do_slm_cstates || do_knl_cstates || is_cnl(family, model) ||
4953+
is_ehl(family, model))
48764954
BIC_NOT_PRESENT(BIC_CPU_c3);
48774955

48784956
if (!quiet)
@@ -4907,10 +4985,16 @@ void process_cpuid()
49074985
else
49084986
BIC_NOT_PRESENT(BIC_CPU_LPI);
49094987

4910-
if (!access("/sys/devices/system/cpu/cpuidle/low_power_idle_system_residency_us", R_OK))
4988+
if (!access(sys_lpi_file_sysfs, R_OK)) {
4989+
sys_lpi_file = sys_lpi_file_sysfs;
49114990
BIC_PRESENT(BIC_SYS_LPI);
4912-
else
4991+
} else if (!access(sys_lpi_file_debugfs, R_OK)) {
4992+
sys_lpi_file = sys_lpi_file_debugfs;
4993+
BIC_PRESENT(BIC_SYS_LPI);
4994+
} else {
4995+
sys_lpi_file_sysfs = NULL;
49134996
BIC_NOT_PRESENT(BIC_SYS_LPI);
4997+
}
49144998

49154999
if (!quiet)
49165000
decode_misc_feature_control();
@@ -5306,7 +5390,7 @@ int get_and_dump_counters(void)
53065390
}
53075391

53085392
void print_version() {
5309-
fprintf(outf, "turbostat version 19.08.31"
5393+
fprintf(outf, "turbostat version 20.03.20"
53105394
" - Len Brown <[email protected]>\n");
53115395
}
53125396

@@ -5323,9 +5407,9 @@ int add_counter(unsigned int msr_num, char *path, char *name,
53235407
}
53245408

53255409
msrp->msr_num = msr_num;
5326-
strncpy(msrp->name, name, NAME_BYTES);
5410+
strncpy(msrp->name, name, NAME_BYTES - 1);
53275411
if (path)
5328-
strncpy(msrp->path, path, PATH_BYTES);
5412+
strncpy(msrp->path, path, PATH_BYTES - 1);
53295413
msrp->width = width;
53305414
msrp->type = type;
53315415
msrp->format = format;

0 commit comments

Comments
 (0)