<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel/linux.git/include/linux/intel_rapl.h, branch v6.19.11</title>
<subtitle>Linux kernel stable tree (mirror)</subtitle>
<id>https://git.radix-linux.su/kernel/linux.git/atom?h=v6.19.11</id>
<link rel='self' href='https://git.radix-linux.su/kernel/linux.git/atom?h=v6.19.11'/>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/'/>
<updated>2026-02-26T23:01:28+00:00</updated>
<entry>
<title>powercap: intel_rapl: Remove incorrect CPU check in PMU context</title>
<updated>2026-02-26T23:01:28+00:00</updated>
<author>
<name>Kuppuswamy Sathyanarayanan</name>
<email>sathyanarayanan.kuppuswamy@linux.intel.com</email>
</author>
<published>2026-02-09T23:43:09+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=26a67cb7e97a5d638cdf76a5c89adca13bb91765'/>
<id>urn:sha1:26a67cb7e97a5d638cdf76a5c89adca13bb91765</id>
<content type='text'>
[ Upstream commit 7537bae8b6eb635583e0e6260f61d13ddbd52087 ]

The RAPL MSR read path incorrectly validates CPU context when called
from the PMU subsystem:

    if (atomic) {
        if (unlikely(smp_processor_id() != cpu))
            return -EIO;
        rdmsrq(ra-&gt;reg.msr, ra-&gt;value);
    }

This check fails for package-scoped MSRs like RAPL energy counters,
which are readable from any CPU within the package.

The perf tool avoids hitting this check by validating against
/sys/bus/event_source/devices/power/cpumask before opening events.
However, turbostat does not perform this validation and may attempt
reads from non-lead CPUs, causing the check to fail and return zero
power values.

Since package-scoped MSRs are architecturally accessible from any CPU
in the package, remove the CPU matching check.

Also rename 'atomic' to 'pmu_ctx' to clarify this indicates PMU context
where rdmsrq() can be used directly instead of rdmsrl_safe_on_cpu().

Fixes: 748d6ba43afd ("powercap: intel_rapl: Enable MSR-based RAPL PMU support")
Signed-off-by: Kuppuswamy Sathyanarayanan &lt;sathyanarayanan.kuppuswamy@linux.intel.com&gt;
Tested-by: Furquim Ulisses &lt;ulisses.furquim@intel.com&gt;
Reviewed-by: Srinivas Pandruvada &lt;srinivas.pandruvada@linux.intel.com&gt;
Link: https://patch.msgid.link/20260209234310.1440722-2-sathyanarayanan.kuppuswamy@linux.intel.com
Signed-off-by: Rafael J. Wysocki &lt;rafael.j.wysocki@intel.com&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>powercap: intel_rapl: Fix possible recursive lock warning</title>
<updated>2025-12-17T16:24:28+00:00</updated>
<author>
<name>Srinivas Pandruvada</name>
<email>srinivas.pandruvada@linux.intel.com</email>
</author>
<published>2025-12-17T15:34:55+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=dcd0b625fe440d68bb4b97c71d18ca48ecd6e594'/>
<id>urn:sha1:dcd0b625fe440d68bb4b97c71d18ca48ecd6e594</id>
<content type='text'>
With the RAPL PMU addition, there is a recursive locking when CPU online
callback function calls rapl_package_add_pmu(). Here cpu_hotplug_lock
is already acquired by cpuhp_thread_fun() and rapl_package_add_pmu()
tries to acquire again.

&lt;4&gt;[ 8.197433] ============================================
&lt;4&gt;[ 8.197437] WARNING: possible recursive locking detected
&lt;4&gt;[ 8.197440] 6.19.0-rc1-lgci-xe-xe-4242-05b7c58b3367dca84+ #1 Not tainted
&lt;4&gt;[ 8.197444] --------------------------------------------
&lt;4&gt;[ 8.197447] cpuhp/0/20 is trying to acquire lock:
&lt;4&gt;[ 8.197450] ffffffff83487870 (cpu_hotplug_lock){++++}-{0:0}, at:
rapl_package_add_pmu+0x37/0x370 [intel_rapl_common]
&lt;4&gt;[ 8.197463]
but task is already holding lock:
&lt;4&gt;[ 8.197466] ffffffff83487870 (cpu_hotplug_lock){++++}-{0:0}, at:
cpuhp_thread_fun+0x6d/0x290
&lt;4&gt;[ 8.197477]
other info that might help us debug this:
&lt;4&gt;[ 8.197480] Possible unsafe locking scenario:

&lt;4&gt;[ 8.197483] CPU0
&lt;4&gt;[ 8.197485] ----
&lt;4&gt;[ 8.197487] lock(cpu_hotplug_lock);
&lt;4&gt;[ 8.197490] lock(cpu_hotplug_lock);
&lt;4&gt;[ 8.197493]
*** DEADLOCK ***
..
..
&lt;4&gt;[ 8.197542] __lock_acquire+0x146e/0x2790
&lt;4&gt;[ 8.197548] lock_acquire+0xc4/0x2c0
&lt;4&gt;[ 8.197550] ? rapl_package_add_pmu+0x37/0x370 [intel_rapl_common]
&lt;4&gt;[ 8.197556] cpus_read_lock+0x41/0x110
&lt;4&gt;[ 8.197558] ? rapl_package_add_pmu+0x37/0x370 [intel_rapl_common]
&lt;4&gt;[ 8.197561] rapl_package_add_pmu+0x37/0x370 [intel_rapl_common]
&lt;4&gt;[ 8.197565] rapl_cpu_online+0x85/0x87 [intel_rapl_msr]
&lt;4&gt;[ 8.197568] ? __pfx_rapl_cpu_online+0x10/0x10 [intel_rapl_msr]
&lt;4&gt;[ 8.197570] cpuhp_invoke_callback+0x41f/0x6c0
&lt;4&gt;[ 8.197573] ? cpuhp_thread_fun+0x6d/0x290
&lt;4&gt;[ 8.197575] cpuhp_thread_fun+0x1e2/0x290
&lt;4&gt;[ 8.197578] ? smpboot_thread_fn+0x26/0x290
&lt;4&gt;[ 8.197581] smpboot_thread_fn+0x12f/0x290
&lt;4&gt;[ 8.197584] ? __pfx_smpboot_thread_fn+0x10/0x10
&lt;4&gt;[ 8.197586] kthread+0x11f/0x250
&lt;4&gt;[ 8.197589] ? __pfx_kthread+0x10/0x10
&lt;4&gt;[ 8.197592] ret_from_fork+0x344/0x3a0
&lt;4&gt;[ 8.197595] ? __pfx_kthread+0x10/0x10
&lt;4&gt;[ 8.197597] ret_from_fork_asm+0x1a/0x30
&lt;4&gt;[ 8.197604] &lt;/TASK&gt;

Fix this issue in the same way as rapl powercap package domain is added
from the same CPU online callback by introducing another interface which
doesn't call cpus_read_lock(). Add rapl_package_add_pmu_locked() and
rapl_package_remove_pmu_locked() which don't call cpus_read_lock().

Fixes: 748d6ba43afd ("powercap: intel_rapl: Enable MSR-based RAPL PMU support")
Reported-by: Borah, Chaitanya Kumar &lt;chaitanya.kumar.borah@intel.com&gt;
Closes: https://lore.kernel.org/linux-pm/5427ede1-57a0-43d1-99f3-8ca4b0643e82@intel.com/T/#u
Tested-by: Kuppuswamy Sathyanarayanan &lt;sathyanarayanan.kuppuswamy@linux.intel.com&gt;
Tested-by: RavitejaX Veesam &lt;ravitejax.veesam@intel.com&gt;
Signed-off-by: Srinivas Pandruvada &lt;srinivas.pandruvada@linux.intel.com&gt;
Link: https://patch.msgid.link/20251217153455.3560176-1-srinivas.pandruvada@linux.intel.com
Signed-off-by: Rafael J. Wysocki &lt;rafael.j.wysocki@intel.com&gt;
</content>
</entry>
<entry>
<title>powercap: intel_rapl: Prepare read_raw() interface for atomic-context callers</title>
<updated>2025-11-21T20:47:08+00:00</updated>
<author>
<name>Kuppuswamy Sathyanarayanan</name>
<email>sathyanarayanan.kuppuswamy@linux.intel.com</email>
</author>
<published>2025-11-21T00:05:38+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=1d6c915819f5b805c35487b6ce5923e31a28266b'/>
<id>urn:sha1:1d6c915819f5b805c35487b6ce5923e31a28266b</id>
<content type='text'>
The current read_raw() implementation of the TPMI, MMIO and MSR
interfaces does not distinguish between atomic and non-atomic callers.

rapl_msr_read_raw() uses rdmsrq_safe_on_cpu(), which can sleep and
issue cross CPU calls. When MSR-based RAPL PMU support is enabled, PMU
event handlers can invoke this function from atomic context where
sleeping or rescheduling is not allowed. In atomic context, the caller
is already executing on the target CPU, so a direct rdmsrq() is
sufficient.

To support such usage, introduce an atomic flag to the read_raw()
interface to allow callers pass the context information. Modify the
common RAPL code to propagate this flag, and set the flag to reflect
the calling contexts.

Utilize the atomic flag in rapl_msr_read_raw() to perform direct MSR
read with rdmsrq() when running in atomic context, and a sanity check
to ensure target CPU matches the current CPU for such use cases.

The TPMI and MMIO implementations do not require special atomic
handling, so the flag is ignored in those paths.

This is a preparatory patch for adding MSR-based RAPL PMU support.

Signed-off-by: Kuppuswamy Sathyanarayanan &lt;sathyanarayanan.kuppuswamy@linux.intel.com&gt;
Reviewed-by: Srinivas Pandruvada &lt;srinivas.pandruvada@linux.intel.com&gt;
[ rjw: Subject tweak ]
Link: https://patch.msgid.link/20251121000539.386069-2-sathyanarayanan.kuppuswamy@linux.intel.com
Signed-off-by: Rafael J. Wysocki &lt;rafael.j.wysocki@intel.com&gt;
</content>
</entry>
<entry>
<title>powercap: intel_rapl: Introduce APIs for PMU support</title>
<updated>2024-04-30T19:10:37+00:00</updated>
<author>
<name>Zhang Rui</name>
<email>rui.zhang@intel.com</email>
</author>
<published>2024-04-28T09:24:26+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=575024a8aa7cf1dff49b94092f774ed1c90586be'/>
<id>urn:sha1:575024a8aa7cf1dff49b94092f774ed1c90586be</id>
<content type='text'>
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.

Signed-off-by: Zhang Rui &lt;rui.zhang@intel.com&gt;
Signed-off-by: Rafael J. Wysocki &lt;rafael.j.wysocki@intel.com&gt;
</content>
</entry>
<entry>
<title>powercap: intel_rapl: Fix locking in TPMI RAPL</title>
<updated>2024-02-13T16:31:48+00:00</updated>
<author>
<name>Zhang Rui</name>
<email>rui.zhang@intel.com</email>
</author>
<published>2024-01-31T11:37:09+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=1aa09b9379a7a644cd2f75ae0bac82b8783df600'/>
<id>urn:sha1:1aa09b9379a7a644cd2f75ae0bac82b8783df600</id>
<content type='text'>
The RAPL framework uses CPU hotplug locking to protect the rapl_packages
list and rp-&gt;lead_cpu to guarantee that

 1. the RAPL package device is not unprobed and freed
 2. the cached rp-&gt;lead_cpu is always valid

for operations like powercap sysfs accesses.

Current RAPL APIs assume being called from CPU hotplug callbacks which
hold the CPU hotplug lock, but TPMI RAPL driver invokes the APIs in the
driver's .probe() function without acquiring the CPU hotplug lock.

Fix the problem by providing both locked and lockless versions of RAPL
APIs.

Fixes: 9eef7f9da928 ("powercap: intel_rapl: Introduce RAPL TPMI interface driver")
Signed-off-by: Zhang Rui &lt;rui.zhang@intel.com&gt;
Cc: 6.5+ &lt;stable@vger.kernel.org&gt; # 6.5+
Signed-off-by: Rafael J. Wysocki &lt;rafael.j.wysocki@intel.com&gt;
</content>
</entry>
<entry>
<title>powercap: intel_rapl: Fix a sparse warning in TPMI interface</title>
<updated>2023-08-01T11:45:08+00:00</updated>
<author>
<name>Zhang Rui</name>
<email>rui.zhang@intel.com</email>
</author>
<published>2023-07-25T05:39:12+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=16e95a62eed18864aecac404f1e4eed764c363f2'/>
<id>urn:sha1:16e95a62eed18864aecac404f1e4eed764c363f2</id>
<content type='text'>
Depends on the interface used, the RAPL registers can be either MSR
indexes or memory mapped IO addresses. Current RAPL common code uses u64
to save both MSR and memory mapped IO registers. With this, when
handling register address with an __iomem annotation, it triggers a
sparse warning like below:

sparse warnings: (new ones prefixed by &gt;&gt;)
&gt;&gt; drivers/powercap/intel_rapl_tpmi.c:141:41: sparse: sparse: incorrect type in initializer (different address spaces) @@     expected unsigned long long [usertype] *tpmi_rapl_regs @@     got void [noderef] __iomem * @@
   drivers/powercap/intel_rapl_tpmi.c:141:41: sparse:     expected unsigned long long [usertype] *tpmi_rapl_regs
   drivers/powercap/intel_rapl_tpmi.c:141:41: sparse:     got void [noderef] __iomem *

Fix the problem by using a union to save the registers instead.

Suggested-by: David Laight &lt;David.Laight@ACULAB.COM&gt;
Reported-by: kernel test robot &lt;lkp@intel.com&gt;
Closes: https://lore.kernel.org/oe-kbuild-all/202307031405.dy3druuy-lkp@intel.com/
Tested-by: Wang Wendy &lt;wendy.wang@intel.com&gt;
Signed-off-by: Zhang Rui &lt;rui.zhang@intel.com&gt;
[ rjw: Subject and changelog edits ]
Signed-off-by: Rafael J. Wysocki &lt;rafael.j.wysocki@intel.com&gt;
</content>
</entry>
<entry>
<title>powercap: intel_rapl: Introduce core support for TPMI interface</title>
<updated>2023-05-24T16:46:20+00:00</updated>
<author>
<name>Zhang Rui</name>
<email>rui.zhang@intel.com</email>
</author>
<published>2023-04-19T02:44:18+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=e12dee18b89f1b0d4fc070eda4843f9d806645ca'/>
<id>urn:sha1:e12dee18b89f1b0d4fc070eda4843f9d806645ca</id>
<content type='text'>
Compared with existing RAPL MSR/MMIO Interface, the RAPL TPMI Interface
1. has per Power Limit register, thus has per Power Limit Lock and
   Enable bit.
2. doesn't have Power Limit Clamp bit.
3. the Power Limit Lock and Enable bits have different bit offsets.
These mean RAPL TPMI Interface needs its own primitive information.

RAPL TPMI Interface also has per domain unit register but with a
different register layout. This requires a TPMI specific rapl_defaults
call to decode the unit register.

Introduce the RAPL core support for TPMI Interface.

Signed-off-by: Zhang Rui &lt;rui.zhang@intel.com&gt;
Tested-by: Wang Wendy &lt;wendy.wang@intel.com&gt;
Signed-off-by: Rafael J. Wysocki &lt;rafael.j.wysocki@intel.com&gt;
</content>
</entry>
<entry>
<title>powercap: intel_rapl: Introduce RAPL I/F type</title>
<updated>2023-05-24T16:46:20+00:00</updated>
<author>
<name>Zhang Rui</name>
<email>rui.zhang@intel.com</email>
</author>
<published>2023-04-19T02:44:17+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=b4288ce788aaf160f2a706672af2eaef417bb057'/>
<id>urn:sha1:b4288ce788aaf160f2a706672af2eaef417bb057</id>
<content type='text'>
Different RAPL Interfaces may have different primitive information and
rapl_defaults calls.

To better distinguish this difference in the RAPL framework code,
introduce a new enum to represent different types of RAPL Interfaces.

No functional change.

Signed-off-by: Zhang Rui &lt;rui.zhang@intel.com&gt;
Tested-by: Wang Wendy &lt;wendy.wang@intel.com&gt;
Signed-off-by: Rafael J. Wysocki &lt;rafael.j.wysocki@intel.com&gt;
</content>
</entry>
<entry>
<title>powercap: intel_rapl: Make cpu optional for rapl_package</title>
<updated>2023-05-24T16:46:20+00:00</updated>
<author>
<name>Zhang Rui</name>
<email>rui.zhang@intel.com</email>
</author>
<published>2023-04-19T02:44:16+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=bf44b9011df3d6e34a23be77d86540553ba2bbe2'/>
<id>urn:sha1:bf44b9011df3d6e34a23be77d86540553ba2bbe2</id>
<content type='text'>
MSR RAPL Interface always removes a rapl_package when all the CPUs in
that rapl_package are offlined. This is because it relies on an online
CPU to access the MSR.

But for RAPL Interface using MMIO registers, when all the cpus within
the rapl_package are offlined,
1. the register can still be accessed
2. monitoring and setting the Power Pimits for the rapl_package is still
   meaningful because of uncore power.

This means that, a valid rapl_package doesn't rely on one or more cpus
being onlined.

For this sense, make cpu optional for rapl_package. A rapl_package can
be registered either using a CPU id to represent the physical
package/die, or using the physical package id directly.

Note that, the thermal throttling interrupt is not disabled via
MSR_IA32_PACKAGE_THERM_INTERRUPT for such rapl_package at the moment.
If it is still needed in the future, this can be achieved by selecting
an onlined CPU using the physical package id.

Note that, processor_thermal_rapl, the current MMIO RAPL Interface
driver, can also be converted to register using a package id instead.
But this is not done right now because processor_thermal_rapl driver
works on single-package systems only, and offlining the only package
will not happen. So keep the previous logic.

Signed-off-by: Zhang Rui &lt;rui.zhang@intel.com&gt;
Tested-by: Wang Wendy &lt;wendy.wang@intel.com&gt;
Signed-off-by: Rafael J. Wysocki &lt;rafael.j.wysocki@intel.com&gt;
</content>
</entry>
<entry>
<title>powercap: intel_rapl: Add support for lock bit per Power Limit</title>
<updated>2023-05-24T16:46:20+00:00</updated>
<author>
<name>Zhang Rui</name>
<email>rui.zhang@intel.com</email>
</author>
<published>2023-04-19T02:44:14+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=f442bd2742174eed6993315ec621275df13f311d'/>
<id>urn:sha1:f442bd2742174eed6993315ec621275df13f311d</id>
<content type='text'>
With RAPL MSR/MMIO Interface, each RAPL domain has one Power Limit
register. Each Power Limit register has one lock bit which tells the OS
if the power limit register can be used or not.
Depending on the number of power limits supported by the power limit
register, the lock bit may apply to one or more power limits.

With RAPL TPMI Interface, each RAPL domain has multiple Power Limits,
and each Power Limit has its own register, with a lock bit.

To handle this, introduce support for lock bit per Power Limit.

For existing RAPL MSR/MMIO Interfaces, the lock bit in the Power Limit
register applies to all the Power Limits controlled by this register.

Remove the per domain DOMAIN_STATE_BIOS_LOCKED flag at the same time
because it can be replaced by the per Power Limit lock.

No functional change intended.

Signed-off-by: Zhang Rui &lt;rui.zhang@intel.com&gt;
Tested-by: Wang Wendy &lt;wendy.wang@intel.com&gt;
Signed-off-by: Rafael J. Wysocki &lt;rafael.j.wysocki@intel.com&gt;
</content>
</entry>
</feed>
