[Deepin-Kernel-SIG] [linux 6.6-y] [Upstream] [Intel] Intel: Backport TPMI based RAPL PMU support for next Intel Xeon Granite Rapids (GNR)#836
Conversation
ANBZ: #9256 commit 72b8b94 upstream. Sort header files alphabetically. Intel-SIG: commit 72b8b94 powercap: intel_rapl: Sort header files Backport TPMI based RAPL PMU support for GNR and future Xeons. Signed-off-by: Zhang Rui <rui.zhang@intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> [ Yunying Sun: amend commit log ] Signed-off-by: Yunying Sun <yunying.sun@intel.com>
ANBZ: #9256 commit 575024a upstream. Introduce two new APIs rapl_package_add_pmu()/rapl_package_remove_pmu(). RAPL driver can invoke these APIs to expose its supported energy counters via perf PMU. The new RAPL PMU is fully compatible with current MSR RAPL PMU, including using the same PMU name and events name/id/unit/scale, etc. For example, use below command perf stat -e power/energy-pkg/ -e power/energy-ram/ FOO to get the energy consumption if power/energy-pkg/ and power/energy-ram/ events are available in the "perf list" output. This does not introduce any conflict because TPMI RAPL is the only user of these APIs currently, and it never co-exists with MSR RAPL. Note that RAPL Packages can be probed/removed dynamically, and the events supported by each TPMI RAPL device can be different. Thus the RAPL PMU support is done on demand, which means 1. PMU is registered only if it is needed by a RAPL Package. PMU events for unsupported counters are not exposed. 2. PMU is unregistered and registered when a new RAPL Package is probed and supports new counters that are not supported by current PMU. For example, on a dual-package system using TPMI RAPL, it is possible that Package 1 behaves as TPMI domain root and supports Psys domain. In this case, register PMU without Psys event when probing Package 0, and re-register the PMU with Psys event when probing Package 1. 3. PMU is unregistered when all registered RAPL Packages don't need PMU. Intel-SIG: commit 575024a powercap: intel_rapl: Introduce APIs for PMU support Backport TPMI based RAPL PMU support for GNR and future Xeons. Signed-off-by: Zhang Rui <rui.zhang@intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> [ Yunying Sun: amend commit log ] Signed-off-by: Yunying Sun <yunying.sun@intel.com>
ANBZ: #9256 commit 963a9ad upstream. Enable RAPL PMU support for TPMI RAPL driver. Intel-SIG: commit 963a9ad powercap: intel_rapl_tpmi: Enable PMU support Backport TPMI based RAPL PMU support for GNR and future Xeons. Signed-off-by: Zhang Rui <rui.zhang@intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> [ Yunying Sun: amend commit log ] Signed-off-by: Yunying Sun <yunying.sun@intel.com>
Reviewer's GuideBackports upstream v6.10 TPMI-based RAPL perf PMU support by extending the Intel RAPL framework with new PMU APIs in the common driver, updating headers, and integrating PMU hooks in the TPMI RAPL driver. Sequence Diagram: Adding PMU Support for a RAPL PackagesequenceDiagram
participant TPMI_Driver as intel_rapl_tpmi_probe
participant RAPL_Common as intel_rapl_common.c
participant Perf_Core as Linux Perf Core
TPMI_Driver->>+RAPL_Common: rapl_package_add_pmu(rp)
RAPL_Common->>RAPL_Common: Initialize rp->pmu_data (scale, timer, etc.)
RAPL_Common->>RAPL_Common: rapl_pmu_update(rp)
alt PMU needs registration/update
RAPL_Common->>RAPL_Common: Potentially unregister existing rapl_pmu if different config needed
RAPL_Common->>Perf_Core: perf_pmu_register(&rapl_pmu.pmu, "power", ...)
Perf_Core-->>RAPL_Common: Registration status
RAPL_Common->>RAPL_Common: Update rapl_pmu.registered, rp->has_pmu = true
end
RAPL_Common-->>-TPMI_Driver: Status
Class Diagram: Data Structures for RAPL PMU SupportclassDiagram
class rapl_package {
<<struct>>
+bool has_pmu (added)
+rapl_package_pmu_data pmu_data (added)
# ... other existing fields (not shown for brevity)
}
class rapl_package_pmu_data {
<<new struct>>
+u64 scale[RAPL_DOMAIN_MAX]
+raw_spinlock_t lock
+int n_active
+list_head active_list
+ktime_t timer_interval
+hrtimer hrtimer
}
class rapl_pmu {
<<new struct / global static>>
+pmu pmu
+u64 timer_ms
+unsigned long domain_map
+bool registered
}
rapl_package "1" -- "1" rapl_package_pmu_data : contains
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Pull Request Overview
This PR backports the TPMI-based RAPL PMU support to the Linux 6.6-y kernel, enabling power/energy events on Intel Xeon Granite Rapids systems. Key changes include:
- Adding new PMU support APIs in the RAPL framework (in include/linux/intel_rapl.h).
- Integrating PMU support calls into the TPMI RAPL driver (in drivers/powercap/intel_rapl_tpmi.c).
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| include/linux/intel_rapl.h | Introduces new data structures and inline functions for PMU support. |
| drivers/powercap/intel_rapl_tpmi.c | Adds PMU initialization and removal calls in the TPMI RAPL driver. |
| goto err; | ||
| } | ||
|
|
||
| rapl_package_add_pmu(trp->rp); |
There was a problem hiding this comment.
The return value of rapl_package_add_pmu is not checked. It is recommended to handle errors appropriately and perform cleanup if PMU initialization fails.
| rapl_package_add_pmu(trp->rp); | |
| ret = rapl_package_add_pmu(trp->rp); | |
| if (ret) { | |
| dev_err(&auxdev->dev, "Failed to add PMU for Package%d, %d\n", info->package_id, ret); | |
| goto err; | |
| } |
| { | ||
| struct tpmi_rapl_package *trp = auxiliary_get_drvdata(auxdev); | ||
|
|
||
| rapl_package_remove_pmu(trp->rp); |
There was a problem hiding this comment.
Ensure that rapl_package_remove_pmu is only called if the PMU was successfully added. Consider setting and checking a flag to indicate whether PMU initialization succeeded.
| char name[PACKAGE_DOMAIN_NAME_LENGTH]; | ||
| struct rapl_if_priv *priv; | ||
| #ifdef CONFIG_PERF_EVENTS | ||
| bool has_pmu; |
There was a problem hiding this comment.
The 'has_pmu' flag is declared but never updated. Consider setting this flag after a successful PMU initialization to accurately reflect the package's state.
There was a problem hiding this comment.
Hey @Avenger-285714 - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
bugzilla: https://bugzilla.openanolis.cn/show_bug.cgi?id=9256
RAPL energy counter MSRs are exposed via perf PMU. But this is done by separate code which is not part of RAPL framework, and it cannot be reused by other RAPL Interface drivers like TPMI RAPL.
Introduce two new APIs for PMU support in RAPL framework. This allows TPMI RAPL PMU support and also makes it possible for future cleanups of MSR RAPL PMU code.
Commits from mainline kernel v6.10-rc1:
963a9ad powercap: intel_rapl_tpmi: Enable PMU support
575024a powercap: intel_rapl: Introduce APIs for PMU support
72b8b94 powercap: intel_rapl: Sort header files
Test:
Before backport, there's no "power/energy-{pkg,psys,ram}" events available on GNR:
$ perf list | grep -i energy
$
After backport on GNR:
$ perf list | grep -i energy
power/energy-pkg/ [Kernel PMU event]
power/energy-psys/ [Kernel PMU event]
power/energy-ram/ [Kernel PMU event]
$
$ perf stat -a -e power/energy-pkg/ -e power/energy-ram/ -e power/energy-psys/ sleep 2
Performance counter stats for 'system wide':
$
The backported patches are identical as mainline version, and have been verified on Intel GNR platform.
Known issue:
N/A
Configs:
Note that to make RAPL PMU work, TPMI must be enabled in kernel with configs:
CONFIG_INTEL_TPMI=m
CONFIG_INTEL_RAPL_TPMI=m
Link: https://gitee.com/anolis/cloud-kernel/pulls/3293
Summary by Sourcery
Backport upstream RAPL PMU support into the Linux 6.6 kernel, adding unified perf event exposure for TPMI-based Intel RAPL on next-gen Granite Rapids processors
New Features:
Enhancements:
Tests: