perf/x86/power: Introduce AMD accumlated power reporting mechanism
Subsystems (2)
v7 cover perf/x86/power: Introduce AMD accumlated power reporting mechanism
Hi,
This series of patches introduces the perf implementation of accumulated power reporting algorithm. It will calculate the average power consumption for the processor. The CPU feature flag is CPUID.8000_0007H:EDX[12].
The V7 is rebased on bp/tip-perf. And need two dependent patches at tip because of modular perf driver:
http://git.kernel.org/tip/675965b00d734c985e4285f5bec7e524d15fc4e1
http://git.kernel.org/tip/3712bba1a260ad851f3aa8ddea9cb7326f6aa0b3
Changes from v1 -> v2:
- Add a patch to fix the build issue which is reported by kbuild test robot.
Changes from v2 -> v3:
- Use raw_spinlock_t instead of spinlock_t, because it need meet the -rt mode use case.
- Use topology_sibling_cpumask to make the cpumask operation easier.
Changes from v3 -> v4:
- Remove active_list, because it is not iterated.
- Capitalize sentences consistently and fix some typos.
- Fix some code style issues.
- Initialize structures in a vertically aligned manner.
- Remove unnecessary comment.
- Fix the runtime bug, and do some testing on CPU-hotplug scenario.
Changes from v4 -> v5:
- Remove "struct pmu" and lock from power_pmu, and rename it to power_pmu_masks
- As Peter's suggestion, add a new struct to hw_perf_event, and track these values from per-event.
Changes from v5 -> v6:
- Remove MAX_CUS check
- Remove DEFINE_PER_CPU(struct power_pmu_masks *, amd_power_pmu)
- Remove power_cpu_prepare power_cpu_free and refine power_cpu_init and power_cpu_exit
- Use smp_num_siblings instead of cores_per_cu variable.
- Make this driver as a module.
- Add a patch to export events_sysfs_show.
Changes from v6 -> v7:
- Remove unnecessary cu_num.
- Remove unnecessary initialization for target as nr_cpumask_bits.
- Refine power_cpu_init interface.
- Handle CPU_DOWN_FAILED case.
- Remove unnecessary tmp variable.
- Re-write the initialization of for_each_online_cpu(cpu) loop.
- Move __register_cpu_notifier after perf_pmu_register.
Thanks,
Rui
Huang Rui (2):
perf/x86: Export events_sysfs_show() perf/x86/amd/power: Add AMD accumulated power reporting mechanism
arch/x86/Kconfig | 9 + arch/x86/kernel/cpu/Makefile | 1 + arch/x86/kernel/cpu/perf_event.c | 1 + arch/x86/kernel/cpu/perf_event_amd_power.c | 353 +++++++++++++++++++++++++++++ include/linux/perf_event.h | 4 + 5 files changed, 368 insertions(+) create mode 100644 arch/x86/kernel/cpu/perf_event_amd_power.c
Signature · 1 line
1.9.1
PATCH v7 1/2 perf/x86: Export events_sysfs_show()
This interface will be used in modular perf drivers.
--- arch/x86/kernel/cpu/perf_event.c | 1 + 1 file changed, 1 insertion(+)
arch/x86/kernel/cpu/perf_event.c +1 -0
@@ -1601,6 +1601,7 @@ ssize_t events_sysfs_show(struct device *dev, struct device_attribute *attr,return x86_pmu.events_sysfs_show (page, config); } +EXPORT_SYMBOL_GPL (events_sysfs_show);EVENT_ATTR (cpu-cycles,CPU_CYCLES );EVENT_ATTR (instructions,INSTRUCTIONS );
Signature · 1 line
1.9.1
PATCH v7 2/2 perf/x86/amd/power: Add AMD accumulated power reporting mechanism
In reply to Huang RuiIntroduce an AMD accumlated power reporting mechanism for the Family 15h, Model 60h processor that can be used to calculate the average power consumed by a processor during a measurement interval. The feature support is indicated by CPUID Fn8000_0007_EDX[12].
This feature will be implemented both in hwmon and perf. The current design provides one event to report per package/processor power consumption by counting each compute unit power value.
Here the gory details of how the computation is done:
---------------------------------------------------------------------
* Tsample: compute unit power accumulator sample period
* Tref: the PTSC counter period (PTSC: performance timestamp counter)
* N: the ratio of compute unit power accumulator sample period to the PTSC period
* Jmax: max compute unit accumulated power which is indicated by MSR_C001007b[MaxCpuSwPwrAcc]
* Jx/Jy: compute unit accumulated power which is indicated by MSR_C001007a[CpuSwPwrAcc]
* Tx/Ty: the value of performance timestamp counter which is indicated by CU_PTSC MSR_C0010280[PTSC]
* PwrCPUave: CPU average power
i. Determine the ratio of Tsample to Tref by executing CPUID Fn8000_0007.
N = value of CPUID Fn8000_0007_ECX[CpuPwrSampleTimeRatio[15:0]].
ii. Read the full range of the cumulative energy value from the new
MSR MaxCpuSwPwrAcc.
Jmax = value returned.
iii. At time x, software reads CpuSwPwrAcc and samples the PTSC.
Jx = value read from CpuSwPwrAcc and Tx = value read from PTSC.
iv. At time y, software reads CpuSwPwrAcc and samples the PTSC.
Jy = value read from CpuSwPwrAcc and Ty = value read from PTSC.
v. Calculate the average power consumption for a compute unit over time period (y-x). Unit of result is uWatt:
if (Jy < Jx) // Rollover has occurred
Jdelta = (Jy + Jmax) - Jx
else
Jdelta = Jy - Jx
PwrCPUave = N * Jdelta * 1000 / (Ty - Tx)
----------------------------------------------------------------------
Simple example:
root@hr-zp:/home/ray/tip# ./tools/perf/perf stat -a -e 'power/power-pkg/' make -j4
CHK include/config/kernel.release
CHK include/generated/uapi/linux/version.h
CHK include/generated/utsrelease.h
CHK include/generated/timeconst.h
CHK include/generated/bounds.h
CHK include/generated/asm-offsets.h
CALL scripts/checksyscalls.sh
CHK include/generated/compile.h
SKIPPED include/generated/compile.h
Building modules, stage 2.
Kernel: arch/x86/boot/bzImage is ready (#40)
MODPOST 4225 modulesPerformance counter stats for 'system wide':
183.44 mWatts power/power-pkg/
341.837270111 seconds time elapsedroot@hr-zp:/home/ray/tip# ./tools/perf/perf stat -a -e 'power/power-pkg/' sleep 10
Performance counter stats for 'system wide':
0.18 mWatts power/power-pkg/
10.012551815 seconds time elapsed
--- arch/x86/Kconfig | 9 + arch/x86/kernel/cpu/Makefile | 1 + arch/x86/kernel/cpu/perf_event_amd_power.c | 353 +++++++++++++++++++++++++++++ include/linux/perf_event.h | 4 + 4 files changed, 367 insertions(+) create mode 100644 arch/x86/kernel/cpu/perf_event_amd_power.c
arch/x86/Kconfig +9 -0
@@ -1202,6 +1202,15 @@ config MICROCODE_OLD_INTERFACE def_bool y depends on MICROCODE +config PERF_EVENTS_AMD_POWER + depends on PERF_EVENTS && CPU_SUP_AMD + tristate "AMD Processor Power Reporting Mechanism" + ---help--- + Provide power reporting mechanism support for AMD processors. + Currently, it leverages X86_FEATURE_ACC_POWER + (CPUID Fn8000_0007_EDX[12]) interface to calculate the + average power consumption on Family 15h processors. + config X86_MSR tristate "/dev/cpu/*/msr - Model-specific register support" ---help---
arch/x86/kernel/cpu/Makefile +1 -0
@@ -34,6 +34,7 @@ obj-$(CONFIG_PERF_EVENTS) += perf_event.o ifdef CONFIG_PERF_EVENTS obj-$(CONFIG_CPU_SUP_AMD) += perf_event_amd.o perf_event_amd_uncore.o +obj-$(CONFIG_PERF_EVENTS_AMD_POWER) += perf_event_amd_power.o ifdef CONFIG_AMD_IOMMU obj-$(CONFIG_CPU_SUP_AMD) += perf_event_amd_iommu.o endif
arch/x86/kernel/cpu/perf_event_amd_power.c new file +353 -0
353 lines not on this page · raw message
include/linux/perf_event.h +4 -0
@@ -128,6 +128,10 @@ struct hw_perf_event {struct {/* itrace */ int itrace_started; }; +struct {/* amd_power */ +u64 pwr_acc; +u64 ptsc; + }; #ifdef CONFIG_HAVE_HW_BREAKPOINT struct { /* breakpoint */ /*
Signature · 1 line
1.9.1
Re: [PATCH v7 2/2] perf/x86/amd/power: Add AMD accumulated power reporting mechanism
Quoted 6 lines · Huang Rui
Suggested-by Peter Zijlstra <[email protected]>Suggested-by Ingo Molnar <[email protected]>Suggested-by Borislav Petkov <[email protected]>Signed-off-by Huang Rui <[email protected]>Cc Guenter Roeck <[email protected]>
Borislav Petkov
maintainerRe: [PATCH v7 2/2] perf/x86/amd/power: Add AMD accumulated power reporting mechanism
In reply to Huang RuiQuoted 8 lines · Huang Rui
Introduce an AMD accumlated power reporting mechanism for the Family 15h, Model 60h processor that can be used to calculate the average power consumed by a processor during a measurement interval. The feature support is indicated by CPUID Fn8000_0007_EDX[12].
This feature will be implemented both in hwmon and perf. The current design provides one event to report per package/processor power consumption by counting each compute unit power value.
...
Quoted 9 lines
Suggested-by Peter Zijlstra <[email protected]>Suggested-by Ingo Molnar <[email protected]>Suggested-by Borislav Petkov <[email protected]>Signed-off-by Huang Rui <[email protected]>Cc Guenter Roeck <[email protected]>--- arch/x86/Kconfig | 9 + arch/x86/kernel/cpu/Makefile | 1 + arch/x86/kernel/cpu/perf_event_amd_power.c | 353 +++++++++++++++++++++++++++++
Please redo this patch against latest tip/master and add Thomas' Reviewed-by.
Thanks.
Signature · 4 lines
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.