platform/x86: intel_pmc_core: transform Pkg C-state residency from TSC ticks into microseconds
PATCH 1/1 platform/x86: intel_pmc_core: transform Pkg C-state residency from TSC ticks into microseconds
Refer to the Intel SDM Vol.4, the package C-state residency counters of modern IA micro-architecture are all ticking in TSC frequency, hence we can apply simple math to transform the ticks into microseconds. i.e.,
residency (ms) = count / tsc_khz
residency (us) = count / tsc_khz * 1000
This also aligns to other sysfs debug entries of residency counter in the same metric in microseconds, benefits reading and scripting.
---
drivers/platform/x86/intel_pmc_core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/platform/x86/intel_pmc_core.c +3 -3
@@ -24,6 +24,7 @@#include <asm/cpu_device_id.h> #include <asm/intel-family.h> #include <asm/msr.h> +#include <asm/tsc.h> #include "intel_pmc_core.h"
@@ -726,7 +727,6 @@ static int pmc_core_ltr_show(struct seq_file *s, void *unused)return 0 ; }DEFINE_SHOW_ATTRIBUTE (pmc_core_ltr); -static int pmc_core_pkgc_show (struct seq_file *s,void *unused) {struct pmc_dev *pmcdev = s->private;
@@ -738,8 +738,8 @@ static int pmc_core_pkgc_show(struct seq_file *s, void *unused)if (rdmsrl_safe (map[index].bit_mask, &pcstate_count))continue ; -seq_printf (s,"%-8s : 0x%llx\n" , map[index].name, - pcstate_count); +seq_printf (s,"%-8s : %llu\n" , map[index].name, + pcstate_count *1000 / tsc_khz); }return 0 ;
Signature · 1 line
2.20.1
PATCH 1/1 platform/x86: intel_pmc_core: transform Pkg C-state residency from TSC ticks into microseconds
Refer to the Intel SDM Vol.4, the package C-state residency counters of modern IA micro-architecture are all ticking in TSC frequency, hence we can apply simple math to transform the ticks into microseconds. i.e.,
residency (ms) = count / tsc_khz
residency (us) = count / tsc_khz * 1000
This also aligns to other sysfs debug entries of residency counter in the same metric in microseconds, benefits reading and scripting.
v2: restore the accidentally deleted newline, no function change.
---
drivers/platform/x86/intel_pmc_core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/platform/x86/intel_pmc_core.c +3 -2
@@ -24,6 +24,7 @@#include <asm/cpu_device_id.h> #include <asm/intel-family.h> #include <asm/msr.h> +#include <asm/tsc.h> #include "intel_pmc_core.h"
@@ -738,8 +739,8 @@ static int pmc_core_pkgc_show(struct seq_file *s, void *unused)if (rdmsrl_safe (map[index].bit_mask, &pcstate_count))continue ; -seq_printf (s,"%-8s : 0x%llx\n" , map[index].name, - pcstate_count); +seq_printf (s,"%-8s : %llu\n" , map[index].name, + pcstate_count *1000 / tsc_khz); }return 0 ;
Signature · 1 line
2.20.1
PATCH v2 1/1 platform/x86: intel_pmc_core: transform Pkg C-state residency from TSC ticks into microseconds
In reply to Harry PanRefer to the Intel SDM Vol.4, the package C-state residency counters of modern IA micro-architecture are all ticking in TSC frequency, hence we can apply simple math to transform the ticks into microseconds. i.e.,
residency (ms) = count / tsc_khz
residency (us) = count / tsc_khz * 1000
This also aligns to other sysfs debug entries of residency counter in the same metric in microseconds, benefits reading and scripting.
v2: restore the accidentally deleted newline, no function change.
---
drivers/platform/x86/intel_pmc_core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/platform/x86/intel_pmc_core.c +3 -2
@@ -24,6 +24,7 @@#include <asm/cpu_device_id.h> #include <asm/intel-family.h> #include <asm/msr.h> +#include <asm/tsc.h> #include "intel_pmc_core.h"
@@ -738,8 +739,8 @@ static int pmc_core_pkgc_show(struct seq_file *s, void *unused)if (rdmsrl_safe (map[index].bit_mask, &pcstate_count))continue ; -seq_printf (s,"%-8s : 0x%llx\n" , map[index].name, - pcstate_count); +seq_printf (s,"%-8s : %llu\n" , map[index].name, + pcstate_count *1000 / tsc_khz); }return 0 ;
Signature · 1 line
2.20.1
PATCH v3 1/1 platform/x86: intel_pmc_core: transform Pkg C-state residency from TSC ticks into microseconds
Refer to the Intel SDM Vol.4, the package C-state residency counters of modern IA micro-architecture are all ticking in TSC frequency, hence we can apply simple math to transform the ticks into microseconds. i.e.,
residency (ms) = count / tsc_khz
residency (us) = count / tsc_khz * 1000
This also aligns to other sysfs debug entries of residency counter in the same metric in microseconds, benefits reading and scripting.
v2: restore the accidentally deleted newline, no function change.
v3: apply kernel do_div() macro to calculate division
---
drivers/platform/x86/intel_pmc_core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/platform/x86/intel_pmc_core.c +4 -1
@@ -24,6 +24,7 @@#include <asm/cpu_device_id.h> #include <asm/intel-family.h> #include <asm/msr.h> +#include <asm/tsc.h> #include "intel_pmc_core.h"
@@ -738,7 +739,9 @@ static int pmc_core_pkgc_show(struct seq_file *s, void *unused)if (rdmsrl_safe (map[index].bit_mask, &pcstate_count))continue ; -seq_printf (s,"%-8s : 0x%llx\n" , map[index].name, + pcstate_count *=1000 ; +do_div (pcstate_count, tsc_khz); +seq_printf (s,"%-8s : %llu\n" , map[index].name, pcstate_count); }
Signature · 1 line
2.20.1
Quoted 8 lines · Harry Pan
Refer to the Intel SDM Vol.4, the package C-state residency counters of modern IA micro-architecture are all ticking in TSC frequency, hence we can apply simple math to transform the ticks into microseconds. i.e.,
residency (ms) = count /tsc_khz
residency (us) = count /tsc_khz* 1000
Quoted 8 lines
This also aligns to other sysfs debug entries of residency counter in the same metric in microseconds, benefits reading and scripting.
v2: restore the accidentally deleted newline, no function change.
v3: apply kerneldo_div()macro to calculate divisionSigned-off-by Harry Pan <[email protected]>
Pushed to my review and testing queue, thanks!
Quoted 31 lines
---
drivers/platform/x86/intel_pmc_core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/platform/x86/intel_pmc_core.c +4
-2@@ -24,6 +24,7 @@#include <asm/cpu_device_id.h> #include <asm/intel-family.h> #include <asm/msr.h> +#include <asm/tsc.h> #include "intel_pmc_core.h" @@ -738,7 +739,9 @@ static int pmc_core_pkgc_show(struct seq_file *s, void *unused)if (rdmsrl_safe (map[index].bit_mask, &pcstate_count))continue ; -seq_printf (s,"%-8s : 0x%llx\n" , map[index].name, + pcstate_count *=1000 ; +do_div (pcstate_count, tsc_khz); +seq_printf (s,"%-8s : %llu\n" , map[index].name, pcstate_count); } --2.20.1
Signature · 2 lines
With Best Regards, Andy Shevchenko