Skip to contentSkip to conversation

turbostat update to version 20.03.19

PATCH In review Len Brown 3 participants 15 messages Mar 20, 2020 – Mar 25, 2020 Turbostat utility

lore
Share & tools
lore

Len Brown

author maintainer
#0 lore raw

Please let me know if you see any issues with these patches.

thanks!
-Len

[PATCH 01/10] tools/power turbostat: Support Cometlake [PATCH 02/10] tools/power turbostat: Fix gcc build warnings [PATCH 03/10] tools/power turbostat: Support Tiger Lake [PATCH 04/10] tools/power turbostat: Support Ice Lake server [PATCH 05/10] tools/power turbostat: Support Jasper Lake [PATCH 06/10] tools/power turbostat: Support Elkhart Lake [PATCH 07/10] tools/power turbostat: Fix missing SYS_LPI counter on [PATCH 08/10] tools/power turbostat: Fix 32-bit capabilities warning [PATCH 09/10] tools/power turbostat: Print cpuidle information [PATCH 10/10] turbostat: update version

author maintainer
#1 lore raw

PATCH 1/10 tools/power turbostat: Support Cometlake

From: Chen Yu <[email protected]>

From a turbostat point of view, Cometlake is like Kabylake.

---
 tools/power/x86/turbostat/turbostat.c | 2 ++
 1 file changed, 2 insertions(+)
tools/power/x86/turbostat/turbostat.c +2 -0
index 31c1ca0bb3ee..dd5ac9f52ac5 100644
@@ -4610,6 +4610,8 @@ unsigned int intel_model_duplicates(unsigned int model)
 	case INTEL_FAM6_SKYLAKE:
 	case INTEL_FAM6_KABYLAKE_L:
 	case INTEL_FAM6_KABYLAKE:
+	case INTEL_FAM6_COMETLAKE_L:
+	case INTEL_FAM6_COMETLAKE:
 		return INTEL_FAM6_SKYLAKE_L;
 
 	case INTEL_FAM6_ICELAKE_L:
Signature · 1 line
2.20.1
author maintainer
#2 lore raw

PATCH 2/10 tools/power turbostat: Fix gcc build warnings

From: Len Brown <[email protected]>

Warning: ‘__builtin_strncpy’ specified bound 20 equals destination size
[-Wstringop-truncation]

reduce param to strncpy, to guarantee that a null byte is always copied into destination buffer.

---
 tools/power/x86/turbostat/turbostat.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/power/x86/turbostat/turbostat.c +2 -2
index dd5ac9f52ac5..fa95a8ca5565 100644
@@ -5325,9 +5325,9 @@ int add_counter(unsigned int msr_num, char *path, char *name,
 	}
 
 	msrp->msr_num = msr_num;
-	strncpy(msrp->name, name, NAME_BYTES);
+	strncpy(msrp->name, name, NAME_BYTES - 1);
 	if (path)
-		strncpy(msrp->path, path, PATH_BYTES);
+		strncpy(msrp->path, path, PATH_BYTES - 1);
 	msrp->width = width;
 	msrp->type = type;
 	msrp->format = format;
Signature · 1 line
2.20.1
author maintainer
#3 lore raw

PATCH 3/10 tools/power turbostat: Support Tiger Lake

In reply to Len Brown

From: Chen Yu <[email protected]>

From a turbostat point of view, Tiger Lake looks like Ice Lake.

---
 tools/power/x86/turbostat/turbostat.c | 2 ++
 1 file changed, 2 insertions(+)
tools/power/x86/turbostat/turbostat.c +2 -0
index fa95a8ca5565..d2c3f294da2d 100644
@@ -4616,6 +4616,8 @@ unsigned int intel_model_duplicates(unsigned int model)
 
 	case INTEL_FAM6_ICELAKE_L:
 	case INTEL_FAM6_ICELAKE_NNPI:
+	case INTEL_FAM6_TIGERLAKE_L:
+	case INTEL_FAM6_TIGERLAKE:
 		return INTEL_FAM6_CANNONLAKE_L;
 
 	case INTEL_FAM6_ATOM_TREMONT_D:
Signature · 1 line
2.20.1
author maintainer
#4 lore raw

PATCH 4/10 tools/power turbostat: Support Ice Lake server

In reply to Len Brown

From: Chen Yu <[email protected]>

From a turbostat point of view, Ice Lake server looks like Sky Lake server.

---
 tools/power/x86/turbostat/turbostat.c | 3 +++
 1 file changed, 3 insertions(+)
tools/power/x86/turbostat/turbostat.c +3 -0
index d2c3f294da2d..26088b2a27cc 100644
@@ -4622,6 +4622,9 @@ unsigned int intel_model_duplicates(unsigned int model)
 
 	case INTEL_FAM6_ATOM_TREMONT_D:
 		return INTEL_FAM6_ATOM_GOLDMONT_D;
+
+	case INTEL_FAM6_ICELAKE_X:
+		return INTEL_FAM6_SKYLAKE_X;
 	}
 	return model;
 }
Signature · 1 line
2.20.1
author maintainer
#5 lore raw

PATCH 5/10 tools/power turbostat: Support Jasper Lake

In reply to Len Brown

From: Chen Yu <[email protected]>

Jasper Lake, like Elkhart Lake, uses a Tremont CPU. So reuse the code.

---
 tools/power/x86/turbostat/turbostat.c | 3 +++
 1 file changed, 3 insertions(+)
tools/power/x86/turbostat/turbostat.c +3 -0
index 26088b2a27cc..e953afb2e7a1 100644
@@ -4623,6 +4623,9 @@ unsigned int intel_model_duplicates(unsigned int model)
 	case INTEL_FAM6_ATOM_TREMONT_D:
 		return INTEL_FAM6_ATOM_GOLDMONT_D;
 
+	case INTEL_FAM6_ATOM_TREMONT_L:
+		return INTEL_FAM6_ATOM_TREMONT;
+
 	case INTEL_FAM6_ICELAKE_X:
 		return INTEL_FAM6_SKYLAKE_X;
 	}
Signature · 1 line
2.20.1
author maintainer
#6 lore raw

PATCH 6/10 tools/power turbostat: Support Elkhart Lake

In reply to Len Brown

From: Chen Yu <[email protected]>

From a turbostat point of view the Tremont-based Elkhart Lake is very similar to Goldmont, reuse the code of Goldmont.

Elkhart Lake does not support 'group turbo limit counter' nor C3, adjust the code accordingly.

---
 tools/power/x86/turbostat/turbostat.c | 31 ++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
tools/power/x86/turbostat/turbostat.c +30 -1
index e953afb2e7a1..761146c4f9bc 100644
@@ -3265,6 +3265,7 @@ int probe_nhm_msrs(unsigned int family, unsigned int model)
 	case INTEL_FAM6_ATOM_GOLDMONT:	/* BXT */
 	case INTEL_FAM6_ATOM_GOLDMONT_PLUS:
 	case INTEL_FAM6_ATOM_GOLDMONT_D:	/* DNV */
+	case INTEL_FAM6_ATOM_TREMONT:	/* EHL */
 		pkg_cstate_limits = glm_pkg_cstate_limits;
 		break;
 	default:
@@ -3336,6 +3337,17 @@ int is_skx(unsigned int family, unsigned int model)
 	}
 	return 0;
 }
+int is_ehl(unsigned int family, unsigned int model)
+{
+	if (!genuine_intel)
+		return 0;
+
+	switch (model) {
+	case INTEL_FAM6_ATOM_TREMONT:
+		return 1;
+	}
+	return 0;
+}
 
 int has_turbo_ratio_limit(unsigned int family, unsigned int model)
 {
@@ -3894,6 +3906,20 @@ void rapl_probe_intel(unsigned int family, unsigned int model)
 		else
 			BIC_PRESENT(BIC_PkgWatt);
 		break;
+	case INTEL_FAM6_ATOM_TREMONT:	/* EHL */
+		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;
+		if (rapl_joules) {
+			BIC_PRESENT(BIC_Pkg_J);
+			BIC_PRESENT(BIC_Cor_J);
+			BIC_PRESENT(BIC_RAM_J);
+			BIC_PRESENT(BIC_GFX_J);
+		} else {
+			BIC_PRESENT(BIC_PkgWatt);
+			BIC_PRESENT(BIC_CorWatt);
+			BIC_PRESENT(BIC_RAMWatt);
+			BIC_PRESENT(BIC_GFXWatt);
+		}
+		break;
 	case INTEL_FAM6_SKYLAKE_L:	/* SKL */
 	case INTEL_FAM6_CANNONLAKE_L:	/* CNL */
 		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 +4321,7 @@ int has_snb_msrs(unsigned int family, unsigned int model)
 	case INTEL_FAM6_ATOM_GOLDMONT:		/* BXT */
 	case INTEL_FAM6_ATOM_GOLDMONT_PLUS:
 	case INTEL_FAM6_ATOM_GOLDMONT_D:	/* DNV */
+	case INTEL_FAM6_ATOM_TREMONT:		/* EHL */
 		return 1;
 	}
 	return 0;
@@ -4324,6 +4351,7 @@ int has_c8910_msrs(unsigned int family, unsigned int model)
 	case INTEL_FAM6_CANNONLAKE_L:	/* CNL */
 	case INTEL_FAM6_ATOM_GOLDMONT:	/* BXT */
 	case INTEL_FAM6_ATOM_GOLDMONT_PLUS:
+	case INTEL_FAM6_ATOM_TREMONT:	/* EHL */
 		return 1;
 	}
 	return 0;
@@ -4882,7 +4910,8 @@ void process_cpuid()
 	do_slm_cstates = is_slm(family, model);
 	do_knl_cstates  = is_knl(family, model);
 
-	if (do_slm_cstates || do_knl_cstates || is_cnl(family, model))
+	if (do_slm_cstates || do_knl_cstates || is_cnl(family, model) ||
+	    is_ehl(family, model))
 		BIC_NOT_PRESENT(BIC_CPU_c3);
 
 	if (!quiet)
Signature · 1 line
2.20.1
author maintainer
#7 lore raw

PATCH 7/10 tools/power turbostat: Fix missing SYS_LPI counter on some Chromebooks

In reply to Len Brown

From: Len Brown <[email protected]>

Some Chromebook BIOS' do not export an ACPI LPIT, which is how Linux finds the residency counter for CPU and SYSTEM low power states, that is exports in /sys/devices/system/cpu/cpuidle/*residency_us

When these sysfs attributes are missing, check the debugfs attrubte from the pmc_core driver, which accesses the same counter value.

---
 tools/power/x86/turbostat/turbostat.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)
tools/power/x86/turbostat/turbostat.c +14 -9
index 761146c4f9bc..3ecbf709a48c 100644
@@ -304,6 +304,10 @@ int *irqs_per_cpu;		/* indexed by cpu_num */
 
 void setup_all_buffers(void);
 
+char *sys_lpi_file;
+char *sys_lpi_file_sysfs = "/sys/devices/system/cpu/cpuidle/low_power_idle_system_residency_us";
+char *sys_lpi_file_debugfs = "/sys/kernel/debug/pmc_core/slp_s0_residency_usec";
+
 int cpu_is_not_present(int cpu)
 {
 	return !CPU_ISSET_S(cpu, cpu_present_setsize, cpu_present_set);
@@ -2916,8 +2920,6 @@ int snapshot_gfx_mhz(void)
  *
  * record snapshot of
  * /sys/devices/system/cpu/cpuidle/low_power_idle_cpu_residency_us
- *
- * return 1 if config change requires a restart, else return 0
  */
 int snapshot_cpu_lpi_us(void)
 {
@@ -2941,17 +2943,14 @@ int snapshot_cpu_lpi_us(void)
 /*
  * snapshot_sys_lpi()
  *
- * record snapshot of
- * /sys/devices/system/cpu/cpuidle/low_power_idle_system_residency_us
- *
- * return 1 if config change requires a restart, else return 0
+ * record snapshot of sys_lpi_file
  */
 int snapshot_sys_lpi_us(void)
 {
 	FILE *fp;
 	int retval;
 
-	fp = fopen_or_die("/sys/devices/system/cpu/cpuidle/low_power_idle_system_residency_us", "r");
+	fp = fopen_or_die(sys_lpi_file, "r");
 
 	retval = fscanf(fp, "%lld", &cpuidle_cur_sys_lpi_us);
 	if (retval != 1) {
@@ -4946,10 +4945,16 @@ void process_cpuid()
 	else
 		BIC_NOT_PRESENT(BIC_CPU_LPI);
 
-	if (!access("/sys/devices/system/cpu/cpuidle/low_power_idle_system_residency_us", R_OK))
+	if (!access(sys_lpi_file_sysfs, R_OK)) {
+		sys_lpi_file = sys_lpi_file_sysfs;
 		BIC_PRESENT(BIC_SYS_LPI);
-	else
+	} else if (!access(sys_lpi_file_debugfs, R_OK)) {
+		sys_lpi_file = sys_lpi_file_debugfs;
+		BIC_PRESENT(BIC_SYS_LPI);
+	} else {
+		sys_lpi_file_sysfs = NULL;
 		BIC_NOT_PRESENT(BIC_SYS_LPI);
+	}
 
 	if (!quiet)
 		decode_misc_feature_control();
Signature · 1 line
2.20.1
author maintainer
#8 lore raw

PATCH 8/10 tools/power turbostat: Fix 32-bit capabilities warning

In reply to Len Brown

From: Len Brown <[email protected]>

warning: `turbostat' uses 32-bit capabilities (legacy support in use)

---
 tools/power/x86/turbostat/Makefile    |  2 +-
 tools/power/x86/turbostat/turbostat.c | 46 +++++++++++++++++----------
 2 files changed, 31 insertions(+), 17 deletions(-)
tools/power/x86/turbostat/Makefile +1 -1
index 13f1e8b9ac52..2b6551269e43 100644
@@ -16,7 +16,7 @@ override CFLAGS +=	-D_FORTIFY_SOURCE=2
 
 %: %.c
 	@mkdir -p $(BUILD_OUTPUT)
-	$(CC) $(CFLAGS) $< -o $(BUILD_OUTPUT)/$@ $(LDFLAGS)
+	$(CC) $(CFLAGS) $< -o $(BUILD_OUTPUT)/$@ $(LDFLAGS) -lcap
 
 .PHONY : clean
 clean :
tools/power/x86/turbostat/turbostat.c +30 -16

65 lines not on this page · raw message

Signature · 1 line
2.20.1
#9 lore raw

RE: [PATCH 08/10] tools/power turbostat: Fix 32-bit capabilities warning

Hi Len,

Quoted 9 lines · On 2020.03.24 22:23 Len Brown wrote:

From: Len Brown <[email protected]>

warning: `turbostat' uses 32-bit capabilities (legacy support in use)

---
 tools/power/x86/turbostat/Makefile    |  2 +-
 tools/power/x86/turbostat/turbostat.c | 46 +++++++++++++++++----------
 2 files changed, 31 insertions(+), 17 deletions(-)

...

Quoted 1 line

+#include <sys/capability.h>

This seems to require a package, libcap-dev, to be installed. I never needed it before.
Just F.Y.I.

... Doug

#10 lore raw

RE: [PATCH 08/10] tools/power turbostat: Fix 32-bit capabilities warning

Quoted 3 lines

+#include <sys/capability.h>

This seems to require a package, libcap-dev, to be installed.

Yeah, sort of annoying that libcap-dev isn't installed by default.
I've added it to the list of stuff that I install on new machines before they are usable...

author maintainer
#11 lore raw

PATCH 9/10 tools/power turbostat: Print cpuidle information

In reply to Len Brown

From: Antti Laakso <[email protected]>

Print cpuidle driver and governor.

---
 tools/power/x86/turbostat/turbostat.c | 30 +++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
tools/power/x86/turbostat/turbostat.c +30 -0
index 77f89371ec5f..c9e299e99c2f 100644
@@ -3509,6 +3509,7 @@ dump_sysfs_cstate_config(void)
 	char path[64];
 	char name_buf[16];
 	char desc[64];
+	char cpuidle_buf[64];
 	FILE *input;
 	int state;
 	char *sp;
@@ -3516,6 +3517,35 @@ dump_sysfs_cstate_config(void)
 	if (!DO_BIC(BIC_sysfs))
 		return;
 
+	if (access("/sys/devices/system/cpu/cpuidle", R_OK)) {
+		fprintf(outf, "cpuidle not loaded\n");
+		return;
+	}
+
+	sprintf(path, "/sys/devices/system/cpu/cpuidle/current_driver");
+	input = fopen(path, "r");
+	if (input == NULL) {
+		fprintf(outf, "NSFOD %s\n", path);
+		return;
+	}
+	if (!fgets(cpuidle_buf, sizeof(cpuidle_buf), input))
+		err(1, "%s: failed to read file", path);
+	fclose(input);
+
+	fprintf(outf, "cpuidle driver: %s", cpuidle_buf);
+
+	sprintf(path, "/sys/devices/system/cpu/cpuidle/current_governor_ro");
+	input = fopen(path, "r");
+	if (input == NULL) {
+		fprintf(outf, "NSFOD %s\n", path);
+		return;
+	}
+	if (!fgets(cpuidle_buf, sizeof(cpuidle_buf), input))
+		err(1, "%s: failed to read file", path);
+	fclose(input);
+
+	fprintf(outf, "cpuidle governor: %s", cpuidle_buf);
+
 	for (state = 0; state < 10; ++state) {
 
 		sprintf(path, "/sys/devices/system/cpu/cpu%d/cpuidle/state%d/name",
Signature · 1 line
2.20.1
#12 lore raw

RE: [PATCH 09/10] tools/power turbostat: Print cpuidle information

Hi Len, Antti,

I didn't actually try it yet.
This reply is just from reading the patches.

Quoted 6 lines · On 2020.03.19 22:23 Len Brown wrote:

From: Antti Laakso <[email protected]>

Print cpuidle driver and governor.

...

tools/power/x86/turbostat/turbostat.c dump_sysfs_cstate_config(void) · line 3548

Quoted 12 lines
tools/power/x86/turbostat/turbostat.c +12 -0
+	sprintf(path, "/sys/devices/system/cpu/cpuidle/current_governor_ro");
+	input = fopen(path, "r");
+	if (input == NULL) {
+		fprintf(outf, "NSFOD %s\n", path);
+		return;
+	}
+	if (!fgets(cpuidle_buf, sizeof(cpuidle_buf), input))
+		err(1, "%s: failed to read file", path);
+	fclose(input);
+
+	fprintf(outf, "cpuidle governor: %s", cpuidle_buf);
+

There is a problem here if one has the 'cpuidle_sysfs_switch' in the kernel command line (which I do always), because that (not) variable name changes as a function of the switch [2].

I have:

$ grep . /sys/devices/system/cpu/cpuidle/*
/sys/devices/system/cpu/cpuidle/available_governors:ladder menu teo
/sys/devices/system/cpu/cpuidle/current_driver:intel_idle
/sys/devices/system/cpu/cpuidle/current_governor:teo

And in grub:

GRUB_CMDLINE_LINUX_DEFAULT="ipv6.disable=1 consoleblank=300 intel_pstate=passive cpuidle_sysfs_switch cpuidle.governor=teo"

Note that there was talk of getting rid of the command line switch [1 at the end], which would be great. Copied below:

Quoted 4 lines · On 2019.09.02 14:59 Rafael wrote:

FWIW, I've been thinking about getting rid of the cpuidle_sysfs_switch command line option and always allowing user space to switch cpuidle governors at run time. At least I see no reason why that would not work ATM.

[1] https://marc.info/?l=linux-pm&m=156746153919195&w=2
[2] Documentation/admin-guide/pm/cpuidle.rst (search for 'current_governor_ro')

... Doug

author maintainer
#13 lore raw

Re: [PATCH 09/10] tools/power turbostat: Print cpuidle information

Thanks, Doug, for reviewing the patch!

I'll send a replacement that is more flexible.

cheers,
-Len

author maintainer
#14 lore raw

PATCH 10/10 turbostat: update version

In reply to Len Brown

From: Len Brown <[email protected]>

A stitch in time saves nine.

---
 tools/power/x86/turbostat/turbostat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/power/x86/turbostat/turbostat.c +1 -1
index c9e299e99c2f..399b2c3b095c 100644
@@ -5394,7 +5394,7 @@ int get_and_dump_counters(void)
 }
 
 void print_version() {
-	fprintf(outf, "turbostat version 19.08.31"
+	fprintf(outf, "turbostat version 20.03.19"
 		" - Len Brown <[email protected]>\n");
 }
 
Signature · 1 line
2.20.1