Commit Graph

72 Commits

Author SHA1 Message Date
David Arcari b2d6cca82d x86/cpu/topology: Rename topology_max_die_per_package()
JIRA: https://issues.redhat.com/browse/RHEL-35363
Conflicts: limited to intel_rapl, also for now I'm provide both
	   topology_max_die_per_package and topology_max_dies_per_package
	   to allow for an easier transition.  We can remove
	   topology_max_die_per_package at a later date.

commit bd745d1c41e7fa56242889eb5dc6df2d7dd5df32
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Tue Feb 13 22:06:13 2024 +0100

    x86/cpu/topology: Rename topology_max_die_per_package()

    The plural of die is dies.

    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Tested-by: Michael Kelley <mhklinux@outlook.com>
    Tested-by: Sohil Mehta <sohil.mehta@intel.com>
    Link: https://lore.kernel.org/r/20240213210253.065874205@linutronix.de

Signed-off-by: David Arcari <darcari@redhat.com>
2024-05-03 06:59:57 -04:00
David Arcari 40221e045e powercap: intel_rapl: Fix locking in TPMI RAPL
JIRA: https://issues.redhat.com/browse/RHEL-35363

commit 1aa09b9379a7a644cd2f75ae0bac82b8783df600
Author: Zhang Rui <rui.zhang@intel.com>
Date:   Wed Jan 31 19:37:09 2024 +0800

    powercap: intel_rapl: Fix locking in TPMI RAPL

    The RAPL framework uses CPU hotplug locking to protect the rapl_packages
    list and rp->lead_cpu to guarantee that

     1. the RAPL package device is not unprobed and freed
     2. the cached rp->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 <rui.zhang@intel.com>
    Cc: 6.5+ <stable@vger.kernel.org> # 6.5+
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2024-05-03 06:54:34 -04:00
David Arcari 210ce978a6 powercap: intel_rapl: Fix a NULL pointer dereference
JIRA: https://issues.redhat.com/browse/RHEL-35363
JIRA: https://issues.redhat.com/browse/RHEL-35104
CVE: CVE-2024-26975

commit 2d1f5006ff95770da502f8cee2a224a1ff83866e
Author: Zhang Rui <rui.zhang@intel.com>
Date:   Wed Jan 31 19:37:08 2024 +0800

    powercap: intel_rapl: Fix a NULL pointer dereference

    A NULL pointer dereference is triggered when probing the MMIO RAPL
    driver on platforms with CPU ID not listed in intel_rapl_common CPU
    model list.

    This is because the intel_rapl_common module still probes on such
    platforms even if 'defaults_msr' is not set after commit 1488ac990ac8
    ("powercap: intel_rapl: Allow probing without CPUID match"). Thus the
    MMIO RAPL rp->priv->defaults is NULL when registering to RAPL framework.

    Fix the problem by adding sanity check to ensure rp->priv->rapl_defaults
    is always valid.

    Fixes: 1488ac990ac8 ("powercap: intel_rapl: Allow probing without CPUID match")
    Signed-off-by: Zhang Rui <rui.zhang@intel.com>
    Cc: 6.5+ <stable@vger.kernel.org> # 6.5+
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2024-05-03 06:54:25 -04:00
David Arcari d8d425368c powercap: intel_rapl: Downgrade BIOS locked limits pr_warn() to pr_debug()
JIRA: https://issues.redhat.com/browse/RHEL-35363

commit a60ec4485f1c72dfece365cf95e6de82bdd74300
Author: Ville Syrjälä <ville.syrjala@linux.intel.com>
Date:   Tue Oct 24 22:17:19 2023 +0300

    powercap: intel_rapl: Downgrade BIOS locked limits pr_warn() to pr_debug()

    Before the refactoring the pr_warn() only triggered when
    someone explicitly tried to write to a BIOS locked limit.
    After the refactoring the warning is also triggering during
    system resume. The user can't do anything about this so
    printing scary warnings doesn't make sense

    Keep the printk but make it pr_debug() instead of pr_warn()
    to make it clear it's not a serious issue.

    Fixes: 9050a9cd5e4c ("powercap: intel_rapl: Cleanup Power Limits support")
    Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
    Cc: 6.5+ <stable@vger.kernel.org> # 6.5+
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2024-05-03 06:54:19 -04:00
Steve Best 0eddb16135 powercap: intel_rapl: Add support for Arrow Lake
JIRA: https://issues.redhat.com/browse/RHEL-20102

commit 4add6e841a3e079c8cb18fab6eaf7385c28c25c7
Author: Sumeet Pawnikar <sumeet.r.pawnikar@intel.com>
Date:   Wed Jan 31 19:37:13 2024 +0800

    powercap: intel_rapl: Add support for Arrow Lake

    Add support for Arrow Lake platform to the RAPL common driver.

    Signed-off-by: Sumeet Pawnikar <sumeet.r.pawnikar@intel.com>
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: Steve Best <sbest@redhat.com>
2024-04-11 15:14:02 -04:00
Steve Best fab5c93186 powercap: intel_rapl: Add support for Lunar Lake-M paltform
JIRA: https://issues.redhat.com/browse/RHEL-20102

commit 876ed77fbed4450a0006ce9a953433a599848c9c
Author: Zhang Rui <rui.zhang@intel.com>
Date:   Wed Jan 31 19:37:12 2024 +0800

    powercap: intel_rapl: Add support for Lunar Lake-M paltform

    Add support for Lunar Lake-M platform to the RAPL common driver.

    Signed-off-by: Zhang Rui <rui.zhang@intel.com>
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: Steve Best <sbest@redhat.com>
2024-04-11 15:13:56 -04:00
Michael Petlan 983308506a x86/cpu: Fix Gracemont uarch
Bugzilla: https://bugzilla.redhat.com/2177050

upstream
========
commit 882cdb06b668488a42ef717a260c05ba7dc43a49
Author: Peter Zijlstra <peterz@infradead.org>
Date:   Mon Aug 7 14:38:07 2023 +0200

description
===========
Alderlake N is an E-core only product using Gracemont
micro-architecture. It fits the pre-existing naming scheme perfectly
fine, adhere to it.

    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
    Acked-by: Hans de Goede <hdegoede@redhat.com>
    Link: https://lore.kernel.org/r/20230807150405.686834933@infradead.org

Conflicts:
==========
Some hunks touch code that we haven't backported yet. I don't take it,
since it is unrelated to my area. Namely, I mean these patches:
  - 7420ae3bb977 ("x86/intel_epb: Set Alder Lake N and Raptor Lake P normal EPB")
  - a414a08aefe6 ("drivers/thermal/intel: Add TCC cooling support for AlderLake platform")
  - 312c1a44da37 ("thermal: intel: Add TCC cooling support for Alder Lake-N and Raptor Lake-P")
  - 62f46fc7b8c6 ("thermal: intel_tcc_cooling: Add TCC cooling support for RaptorLake")

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2023-09-29 10:08:27 +02:00
David Arcari d2398d44e5 powercap: intel_rapl: Fix invalid setting of Power Limit 4
Bugzilla: https://bugzilla.redhat.com/2177009

commit 081690e941188acfad41b8dbde2112029a2aa206
Author: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Date:   Wed Sep 6 12:08:16 2023 -0700

    powercap: intel_rapl: Fix invalid setting of Power Limit 4

    System runs at minimum performance, once powercap RAPL package domain
    enabled flag is changed from 1 to 0 to 1.

    Setting RAPL package domain enabled flag to 0, results in setting of
    power limit 4 (PL4) MSR 0x601 to 0. This implies disabling PL4 limit.
    The PL4 limit controls the peak power. So setting 0, results in some
    undesirable performance, which depends on hardware implementation.

    Even worse, when the enabled flag is set to 1 again. This will set PL4
    MSR value to 0x01, which means reduce peak power to 0.125W. This will
    force system to run at the lowest possible performance on every PL4
    supported system.

    Setting enabled flag should only affect the "enable" bit, not other
    bits. Here it is changing power limit.

    This is caused by a change which assumes that there is an enable bit in
    the PL4 MSR like other power limits. Although PL4 enable/disable bit is
    present with TPMI RAPL interface, it is not present with the MSR
    interface.

    There is a rapl_primitive_info defined for non existent PL4 enable bit
    and then it is used with the commit 9050a9cd5e4c ("powercap: intel_rapl:
    Cleanup Power Limits support") to enable PL4. This is wrong, hence remove
    this rapl primitive for PL4. Also in the function
    rapl_detect_powerlimit(), PL_ENABLE is used to check for the presence of
    power limits. Replace PL_ENABLE with PL_LIMIT, as PL_LIMIT must be
    present. Without this change, PL4 controls will not be available in the
    sysfs once rapl primitive for PL4 is removed.

    Fixes: 9050a9cd5e4c ("powercap: intel_rapl: Cleanup Power Limits support")
    Suggested-by: Zhang Rui <rui.zhang@intel.com>
    Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
    Tested-by: Sumeet Pawnikar <sumeet.r.pawnikar@intel.com>
    Cc: 6.5+ <stable@vger.kernel.org> # 6.5+
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2023-09-14 07:10:20 -04:00
David Arcari a866485b40 powercap: intel_rapl: Optimize rp->domains memory allocation
Bugzilla: https://bugzilla.redhat.com/2177009

commit 2fa00769b1e4bcf20cf0c967cb45f0cd1cea2b5c
Author: xiongxin <xiongxin@kylinos.cn>
Date:   Fri Apr 7 10:47:59 2023 +0800

    powercap: intel_rapl: Optimize rp->domains memory allocation

    In the memory allocation of rp->domains in rapl_detect_domains(), there
    is an additional memory of struct rapl_domain allocated, optimize the
    code here to save sizeof(struct rapl_domain) bytes of memory.

    Test in Intel NUC (i5-1135G7).

    Signed-off-by: xiongxin <xiongxin@kylinos.cn>
    Tested-by: xiongxin <xiongxin@kylinos.cn>
    Reviewed-by: Srinivas Pandruvada<srinivas.pandruvada@linux.intel.com>
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2023-09-14 07:10:19 -04:00
David Arcari eb45b5dd33 powercap: intel_rapl: Fix a sparse warning in TPMI interface
Bugzilla: https://bugzilla.redhat.com/2177009

commit 16e95a62eed18864aecac404f1e4eed764c363f2
Author: Zhang Rui <rui.zhang@intel.com>
Date:   Tue Jul 25 13:39:12 2023 +0800

    powercap: intel_rapl: Fix a sparse warning in TPMI interface

    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 >>)
    >> 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 <David.Laight@ACULAB.COM>
    Reported-by: kernel test robot <lkp@intel.com>
    Closes: https://lore.kernel.org/oe-kbuild-all/202307031405.dy3druuy-lkp@intel.com/
    Tested-by: Wang Wendy <wendy.wang@intel.com>
    Signed-off-by: Zhang Rui <rui.zhang@intel.com>
    [ rjw: Subject and changelog edits ]
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2023-09-14 07:10:19 -04:00
David Arcari 791784ea71 powercap: intel_rapl: Introduce core support for TPMI interface
Bugzilla: https://bugzilla.redhat.com/2177009

commit e12dee18b89f1b0d4fc070eda4843f9d806645ca
Author: Zhang Rui <rui.zhang@intel.com>
Date:   Wed Apr 19 10:44:18 2023 +0800

    powercap: intel_rapl: Introduce core support for TPMI interface

    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 <rui.zhang@intel.com>
    Tested-by: Wang Wendy <wendy.wang@intel.com>
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2023-09-12 17:23:07 -04:00
David Arcari b2ee67a117 powercap: intel_rapl: Introduce RAPL I/F type
Bugzilla: https://bugzilla.redhat.com/2177009

commit b4288ce788aaf160f2a706672af2eaef417bb057
Author: Zhang Rui <rui.zhang@intel.com>
Date:   Wed Apr 19 10:44:17 2023 +0800

    powercap: intel_rapl: Introduce RAPL I/F type

    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 <rui.zhang@intel.com>
    Tested-by: Wang Wendy <wendy.wang@intel.com>
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2023-09-12 17:23:07 -04:00
David Arcari 9110d20517 powercap: intel_rapl: Make cpu optional for rapl_package
Bugzilla: https://bugzilla.redhat.com/2177009

commit bf44b9011df3d6e34a23be77d86540553ba2bbe2
Author: Zhang Rui <rui.zhang@intel.com>
Date:   Wed Apr 19 10:44:16 2023 +0800

    powercap: intel_rapl: Make cpu optional for rapl_package

    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 <rui.zhang@intel.com>
    Tested-by: Wang Wendy <wendy.wang@intel.com>
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2023-09-12 17:23:07 -04:00
David Arcari 3fb4a12c4e powercap: intel_rapl: Remove redundant cpu parameter
Bugzilla: https://bugzilla.redhat.com/2177009

commit 693c1d7868cf710382c39c2d64cbb55e72b36d66
Author: Zhang Rui <rui.zhang@intel.com>
Date:   Wed Apr 19 10:44:15 2023 +0800

    powercap: intel_rapl: Remove redundant cpu parameter

    For rapl_packages that rely on online CPUs to work, rp->lead_cpu always
    has a valid CPU id.

    Remove the redundant cpu parameter in rapl_check_domain(),
    rapl_detect_domains() and .check_unit() callbacks.

    No functional change.

    Signed-off-by: Zhang Rui <rui.zhang@intel.com>
    Tested-by: Wang Wendy <wendy.wang@intel.com>
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2023-09-12 17:23:07 -04:00
David Arcari da07c86d11 powercap: intel_rapl: Add support for lock bit per Power Limit
Bugzilla: https://bugzilla.redhat.com/2177009

commit f442bd2742174eed6993315ec621275df13f311d
Author: Zhang Rui <rui.zhang@intel.com>
Date:   Wed Apr 19 10:44:14 2023 +0800

    powercap: intel_rapl: Add support for lock bit per Power Limit

    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 <rui.zhang@intel.com>
    Tested-by: Wang Wendy <wendy.wang@intel.com>
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2023-09-12 17:23:07 -04:00
David Arcari d6423f2815 powercap: intel_rapl: Cleanup Power Limits support
Bugzilla: https://bugzilla.redhat.com/2177009

commit 9050a9cd5e4c848e265915d6e7b1f731e6e1e0e6
Author: Zhang Rui <rui.zhang@intel.com>
Date:   Wed Apr 19 10:44:13 2023 +0800

    powercap: intel_rapl: Cleanup Power Limits support

    The same set of operations are shared by different Powert Limits,
    including Power Limit get/set, Power Limit enable/disable, clamping
    enable/disable, time window get/set, and max power get/set, etc.

    But the same operation for different Power Limit has different
    primitives because they use different registers/register bits.

    A lot of dirty/duplicate code was introduced to handle this difference.

    Introduce a universal way to issue Power Limit operations.
    Instead of using hardcoded primitive name directly, use Power Limit id
    + operation type, and hide all the Power Limit difference details in a
    central place, get_pl_prim(). Two helpers, rapl_read_pl_data() and
    rapl_write_pl_data(), are introduced at the same time to simplify the
    code for issuing Power Limit operations.

    Signed-off-by: Zhang Rui <rui.zhang@intel.com>
    Tested-by: Wang Wendy <wendy.wang@intel.com>
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2023-09-12 17:23:07 -04:00
David Arcari 9daa202a43 powercap: intel_rapl: Use bitmap for Power Limits
Bugzilla: https://bugzilla.redhat.com/2177009

commit a38f300bb23c896d2d132a4502086d4bfec2a25e
Author: Zhang Rui <rui.zhang@intel.com>
Date:   Wed Apr 19 10:44:12 2023 +0800

    powercap: intel_rapl: Use bitmap for Power Limits

    Currently, a RAPL package is registered with the number of Power Limits
    supported in each RAPL domain. But this doesn't tell which Power Limits
    are available. Using the number of Power Limits supported to guess the
    availability of each Power Limit is fragile.

    Use bitmap to represent the availability of each Power Limit.

    Note that PL1 is mandatory thus it does not need to be set explicitly by
    the RAPL Interface drivers.

    No functional change intended.

    Signed-off-by: Zhang Rui <rui.zhang@intel.com>
    Tested-by: Wang Wendy <wendy.wang@intel.com>
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2023-09-12 17:23:07 -04:00
David Arcari 1be56b18f8 powercap: intel_rapl: Change primitive order
Bugzilla: https://bugzilla.redhat.com/2177009

commit 045610c383bd6b740bb7e7c780d6f7729249e60d
Author: Zhang Rui <rui.zhang@intel.com>
Date:   Wed Apr 19 10:44:11 2023 +0800

    powercap: intel_rapl: Change primitive order

    The same set of operations are shared by different Powert Limits,
    including Power Limit get/set, Power Limit enable/disable, clamping
    enable/disable, time window get/set, and max power get/set, etc.

    But the same operation for different Power Limit has different
    primitives because they use different registers/register bits.

    A lot of dirty/duplicate code was introduced to handle this difference.

    Instead of using hardcoded primitive name directly, using Power Limit id
    + operation type is much cleaner.

    For this sense, move POWER_LIMIT1/POWER_LIMIT2/POWER_LIMIT4 to the
    beginning of enum rapl_primitives so that they can be reused as
    Power Limit ids.

    No functional change.

    Signed-off-by: Zhang Rui <rui.zhang@intel.com>
    Tested-by: Wang Wendy <wendy.wang@intel.com>
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2023-09-12 17:23:06 -04:00
David Arcari 73ea5602ff powercap: intel_rapl: Use index to initialize primitive information
Bugzilla: https://bugzilla.redhat.com/2177009

commit 11edbe5c66d624e2e1eec8929d3668d76a574c3b
Author: Zhang Rui <rui.zhang@intel.com>
Date:   Wed Apr 19 10:44:10 2023 +0800

    powercap: intel_rapl: Use index to initialize primitive information

    Currently, the RAPL primitive information array is required to be
    initialized in the order of enum rapl_primitives.
    This can break easily, especially when different RAPL Interfaces may
    support different sets of primitives.

    Convert the code to initialize the primitive information using array
    index explicitly.

    No functional change.

    Signed-off-by: Zhang Rui <rui.zhang@intel.com>
    Tested-by: Wang Wendy <wendy.wang@intel.com>
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2023-09-12 17:23:06 -04:00
David Arcari 4bbab25cd3 powercap: intel_rapl: Support per domain energy/power/time unit
Bugzilla: https://bugzilla.redhat.com/2177009

commit cb532e728ee2880be53264752e74945fd2d917ac
Author: Zhang Rui <rui.zhang@intel.com>
Date:   Wed Apr 19 10:44:09 2023 +0800

    powercap: intel_rapl: Support per domain energy/power/time unit

    RAPL MSR/MMIO Interface has package scope unit register but some RAPL
    domains like Dram/Psys may use a fixed energy unit value instead of the
    default unit value on certain platforms.
    RAPL TPMI Interface supports per domain unit register.

    For the above reasons, add support for per domain unit register and per
    domain energy/power/time unit.

    When per domain unit register is not available, use the package scope
    unit register as the per domain unit register for each RAPL domain so
    that this change is transparent to MSR/MMIO Interface.

    No functional change intended.

    Signed-off-by: Zhang Rui <rui.zhang@intel.com>
    Tested-by: Wang Wendy <wendy.wang@intel.com>
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2023-09-12 17:23:06 -04:00
David Arcari dd6429409d powercap: intel_rapl: Support per Interface primitive information
Bugzilla: https://bugzilla.redhat.com/2177009

commit 98ff639a7289067247b3ef9dd5d1e922361e7365
Author: Zhang Rui <rui.zhang@intel.com>
Date:   Wed Apr 19 10:44:08 2023 +0800

    powercap: intel_rapl: Support per Interface primitive information

    RAPL primitive information is Interface specific.

    Although current MSR and MMIO Interface share the same RAPL primitives,
    new Interface like TPMI has its own RAPL primitive information.

    Save the primitive information in the Interface private structure.

    Plus, using variant name "rp" for struct rapl_primitive_info is
    confusing because "rp" is also used for struct rapl_package.
    Use "rpi" as the variant name for struct rapl_primitive_info, and rename
    the previous rpi[] array to avoid conflict.

    No functional change.

    Signed-off-by: Zhang Rui <rui.zhang@intel.com>
    Tested-by: Wang Wendy <wendy.wang@intel.com>
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2023-09-12 17:23:06 -04:00
David Arcari 4c56054085 powercap: intel_rapl: Support per Interface rapl_defaults
Bugzilla: https://bugzilla.redhat.com/2177009

commit e8e28c2af16b279b6c37d533e1e73effb197cf2e
Author: Zhang Rui <rui.zhang@intel.com>
Date:   Wed Apr 19 10:44:07 2023 +0800

    powercap: intel_rapl: Support per Interface rapl_defaults

    rapl_defaults is Interface specific.

    Although current MSR and MMIO Interface share the same rapl_defaults,
    new Interface like TPMI need its own rapl_defaults callbacks.

    Save the rapl_defaults information in the Interface private structure.

    No functional change.

    Signed-off-by: Zhang Rui <rui.zhang@intel.com>
    Tested-by: Wang Wendy <wendy.wang@intel.com>
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2023-09-12 17:23:06 -04:00
David Arcari bbc9a92f11 powercap: intel_rapl: Allow probing without CPUID match
Bugzilla: https://bugzilla.redhat.com/2177009

commit 1488ac990ac886b1209aa9f94c0c66022bcc8827
Author: Zhang Rui <rui.zhang@intel.com>
Date:   Wed Apr 19 10:44:06 2023 +0800

    powercap: intel_rapl: Allow probing without CPUID match

    Currently, CPU model checks is used to
    1. get proper rapl_defaults callbacks for RAPL MSR/MMIO Interface.
    2. create a platform device node for the intel_rapl_msr driver to probe.

    Both of these are only mandatory for the RAPL MSR/MMIO Interface.

    Make the CPUID match optional.

    Signed-off-by: Zhang Rui <rui.zhang@intel.com>
    Tested-by: Wang Wendy <wendy.wang@intel.com>
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2023-09-12 17:23:06 -04:00
David Arcari 972b5a8f71 powercap: intel_rapl: Fix handling for large time window
Bugzilla: https://bugzilla.redhat.com/2177009

commit cf835b005b2857c2fd763a006c1957f332e5254b
Author: Zhang Rui <rui.zhang@intel.com>
Date:   Sat Feb 11 11:17:10 2023 +0800

    powercap: intel_rapl: Fix handling for large time window

    When setting the power limit time window, software updates the 'y' bits
    and 'f' bits in the power limit register, and the value hardware takes
    follows the formula below

            Time window = 2 ^ y * (1 + f / 4) * Time_Unit

    When handling large time window input from userspace, using left
    shifting breaks in two cases:

     1. when ilog2(value) is bigger than 31, in expression "1 << y", left
        shifting by more than 31 bits has undefined behavior. This breaks
        'y'. For example, on an Alderlake platform, "1 << 32" returns 1.

     2. when ilog2(value) equals 31, "1 << 31" returns negative value
        because '1' is recognized as signed int. And this breaks 'f'.

    Given that 'y' has 5 bits and hardware can never take a value larger
    than 31, fix the first problem by clamp the time window to the maximum
    possible value that the hardware can take.

    Fix the second problem by using unsigned bit left shift.

    Note that hardware has its own maximum time window limitation, which
    may be lower than the time window value retrieved from the power limit
    register. When this happens, hardware clamps the input to its maximum
    time window limitation. That is why a software clamp is preferred to
    handle the problem on hand.

    Signed-off-by: Zhang Rui <rui.zhang@intel.com>
    [ rjw: Adjusted the comment added by this change ]
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2023-09-12 17:23:06 -04:00
David Arcari 0a1219120a powercap: intel_rapl: Use standard Energy Unit for SPR Dram RAPL domain
Bugzilla: https://bugzilla.redhat.com/2180653

commit 4c081324df5608b73428662ca54d5221ea03a6bd
Author: Zhang Rui <rui.zhang@intel.com>
Date:   Sat Sep 24 13:47:36 2022 +0800

    powercap: intel_rapl: Use standard Energy Unit for SPR Dram RAPL domain

    Intel Xeon servers used to use a fixed energy resolution (15.3uj) for
    Dram RAPL domain. But on SPR, Dram RAPL domain follows the standard
    energy resolution as described in MSR_RAPL_POWER_UNIT.

    Remove the SPR dram_domain_energy_unit quirk.

    Fixes: 2d798d9f59 ("powercap: intel_rapl: add support for Sapphire Rapids")
    Signed-off-by: Zhang Rui <rui.zhang@intel.com>
    Tested-by: Wang Wendy <wendy.wang@intel.com>
    Cc: 5.9+ <stable@vger.kernel.org> # 5.9+
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2023-03-28 11:04:25 -04:00
David Arcari 013592c46f powercap: intel_rapl: fix UBSAN shift-out-of-bounds issue
Bugzilla: https://bugzilla.redhat.com/2180653

commit 2d93540014387d1c73b9ccc4d7895320df66d01b
Author: Chao Qin <chao.qin@intel.com>
Date:   Tue Sep 20 14:08:26 2022 +0800

    powercap: intel_rapl: fix UBSAN shift-out-of-bounds issue

    When value < time_unit, the parameter of ilog2() will be zero and
    the return value is -1. u64(-1) is too large for shift exponent
    and then will trigger shift-out-of-bounds:

    shift exponent 18446744073709551615 is too large for 32-bit type 'int'
    Call Trace:
     rapl_compute_time_window_core
     rapl_write_data_raw
     set_time_window
     store_constraint_time_window_us

    Signed-off-by: Chao Qin <chao.qin@intel.com>
    Acked-by: Zhang Rui <rui.zhang@intel.com>
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2023-03-28 11:04:24 -04:00
David Arcari cd00bf3627 powercap: intel_rapl: add support for Emerald Rapids
Bugzilla: https://bugzilla.redhat.com/2156805

commit 7adc6885259edd4ef5c9a7a62fd4270cf38fdbfb
Author: Zhang Rui <rui.zhang@intel.com>
Date:   Wed Jan 4 22:36:02 2023 +0800

    powercap: intel_rapl: add support for Emerald Rapids

    Add Emerald Rapids to the list of supported processor models in the
    Intel RAPL power capping driver.

    Signed-off-by: Zhang Rui <rui.zhang@intel.com>
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2023-03-20 10:42:15 -04:00
David Arcari d6dc1ed91a powercap: intel_rapl: add support for Meteor Lake
Bugzilla: https://bugzilla.redhat.com/2153965

commit bdaad038cc3c620a769f2156e7c9aab8605411c2
Author: Zhang Rui <rui.zhang@intel.com>
Date:   Wed Jan 4 22:36:01 2023 +0800

    powercap: intel_rapl: add support for Meteor Lake

    Add Meteor Lake to the list of supported processor models in the
    Intel RAPL power capping driver.

    Signed-off-by: Zhang Rui <rui.zhang@intel.com>
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2023-03-13 07:50:07 -04:00
David Arcari ae024016af powercap: intel_rapl: Add support for RAPTORLAKE_S
Bugzilla: https://bugzilla.redhat.com/2159756

commit 0d7a23b5f8e162bf2c5caab06f5df4aee2619073
Author: Zhang Rui <rui.zhang@intel.com>
Date:   Tue Aug 30 11:01:34 2022 +0800

    powercap: intel_rapl: Add support for RAPTORLAKE_S

    Add intel_rapl support for RAPTORLAKE_S platform, which behaves the same
    as RAPTORLAKE and RAPTORLAKE_P platforms.

    Signed-off-by: Zhang Rui <rui.zhang@intel.com>
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2023-01-10 14:08:03 -05:00
David Arcari af1400a18c powercap: intel_rapl: remove redundant store to value after multiply
Bugzilla: https://bugzilla.redhat.com/2106144

commit 59cafa728c373551423d67a1369289a717006a4b
Author: Colin Ian King <colin.king@intel.com>
Date:   Wed May 18 09:45:36 2022 +0100

    powercap: intel_rapl: remove redundant store to value after multiply

    There is no need to store the result of the multiply back to variable value
    after the multiplication. The store is redundant, replace *= with just *.

    Cleans up clang scan build warning:
    warning: Although the value stored to 'value' is used in the enclosing
    expression, the value is never actually read from 'value'
    [deadcode.DeadStores]

    Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2022-12-12 07:16:18 -05:00
David Arcari 0d53be3e8c powercap: intel_rapl: support new layout of Psys PowerLimit Register on SPR
Bugzilla: https://bugzilla.redhat.com/2106144

commit 931da6a0de5d620425af4425344259e6ff46b654
Author: Zhang Rui <rui.zhang@intel.com>
Date:   Tue Dec 7 21:17:34 2021 +0800

    powercap: intel_rapl: support new layout of Psys PowerLimit Register on SPR

    On Sapphire Rapids, the layout of the Psys domain Power Limit Register
    is different from from what it was before.

    Enhance the code to support the new Psys PL register layout.

    Signed-off-by: Zhang Rui <rui.zhang@intel.com>
    Reported-and-tested-by: Alkattan Dana <dana.alkattan@intel.com>
    [ rjw: Subject and changelog edits ]
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2022-12-12 07:16:17 -05:00
David Arcari 77255201df powercap: intel_rapl: Add support for RAPTORLAKE_P
Bugzilla: https://bugzilla.redhat.com/2076727

commit 2755714656d0f2f41adfe231f3865e72da2cbe39
Author: George D Sworo <george.d.sworo@intel.com>
Date:   Wed Jun 1 12:22:16 2022 -0700

    powercap: intel_rapl: Add support for RAPTORLAKE_P

    Add RAPTORLAKE_P to the list of supported processor models in the Intel
    RAPL power capping driver.

    Signed-off-by: George D Sworo <george.d.sworo@intel.com>
    Acked-by: Zhang Rui <rui.zhang@intel.com>
    Tested-by: Sumeet Pawnikar <sumeet.r.pawnikar@intel.com>
    [ rjw: Minor changelog edits ]
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2022-10-26 08:40:27 -04:00
David Arcari c921ad061e powercap: intel_rapl: add support for ALDERLAKE_N
Bugzilla: https://bugzilla.redhat.com/2096965

commit f125bdbdd6bd4a88f3697e5850359d3ffe43a3f2
Author: Zhang Rui <rui.zhang@intel.com>
Date:   Fri May 13 13:00:40 2022 +0800

    powercap: intel_rapl: add support for ALDERLAKE_N

    Add ALDERLAKE_N to the list of supported processor models in the Intel
    RAPL power capping driver.

    Signed-off-by: Zhang Rui <rui.zhang@intel.com>
    [ rjw: Changelog ]
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2022-07-18 13:04:27 -04:00
David Arcari 9f15938d64 powercap: intel_rapl: add support for RaptorLake
Bugzilla: https://bugzilla.redhat.com/2076725

commit ae0dc7ed1a7c713ee9ba563a328d3b4d59223d7c
Author: Zhang Rui <rui.zhang@intel.com>
Date:   Thu Apr 21 23:07:36 2022 +0800

    powercap: intel_rapl: add support for RaptorLake

    Add intel_rapl support for the RaptorLake platform.

    Signed-off-by: Zhang Rui <rui.zhang@intel.com>
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: David Arcari <darcari@redhat.com>
2022-06-14 15:16:07 -04:00
Prarit Bhargava 626441dd2c powercap: intel_rapl: Replace deprecated CPU-hotplug functions
Bugzilla: http://bugzilla.redhat.com/2023079

commit 5d4c779cb62e676aedc278de910b4bb8ef65a5cc
Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Date:   Tue Aug 3 16:16:01 2021 +0200

    powercap: intel_rapl: Replace deprecated CPU-hotplug functions

    The functions get_online_cpus() and put_online_cpus() have been
    deprecated during the CPU hotplug rework. They map directly to
    cpus_read_lock() and cpus_read_unlock().

    Replace deprecated CPU-hotplug functions with the official version.
    The behavior remains unchanged.

    Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2021-12-09 09:04:07 -05:00
Pu Wen a740561201 powercap: Add Hygon Fam18h RAPL support
Enable Hygon Fam18h RAPL support for the power capping framework.

Signed-off-by: Pu Wen <puwen@hygon.cn>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2021-03-18 19:42:23 +01:00
Yunfeng Ye 65348ba259 powercap: intel_rapl: Use topology interface in rapl_init_domains()
It's not a good idea to access the phys_proc_id of cpuinfo directly.

Use topology_physical_package_id(cpu) instead.

Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
[ rjw: Changelog edits ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2021-02-12 16:53:01 +01:00
Yunfeng Ye 88ffce9576 powercap: intel_rapl: Use topology interface in rapl_add_package()
It's not a good idea to access phys_proc_id and cpu_die_id directly.

Use topology_physical_package_id(cpu) and topology_die_id(cpu)
instead.

Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
[ rjw: Changelog edits ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2021-02-12 16:53:01 +01:00
Zhang Rui cca26b66ef powercap/intel_rapl: add support for AlderLake Mobile
Add intel_rapl support for the AlderLake Mobile platform.

Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2021-01-27 19:26:47 +01:00
Kim Phillips 8a9d881f22 powercap: RAPL: Add AMD Fam19h RAPL support
AMD Family 19h's RAPL MSRs are identical to Family 17h's.  Extend
Family 17h's support to Family 19h.

Signed-off-by: Kim Phillips <kim.phillips@amd.com>
Signed-off-by: Victor Ding <victording@google.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2020-11-10 19:59:07 +01:00
Victor Ding 43756a2989 powercap: Add AMD Fam17h RAPL support
Enable AMD Fam17h RAPL support for the power capping framework.

The support is as per AMD Fam17h Model31h (Zen2) and model 00-ffh
(Zen1) PPR.

Tested by comparing the results of following two sysfs entries and the
values directly read from corresponding MSRs via /dev/cpu/[x]/msr:
  /sys/class/powercap/intel-rapl/intel-rapl:0/energy_uj
  /sys/class/powercap/intel-rapl/intel-rapl:0/intel-rapl:0:0/energy_uj

Signed-off-by: Victor Ding <victording@google.com>
Acked-by: Kim Phillips <kim.phillips@amd.com>
[ rjw: Changelog edits ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2020-11-10 19:59:07 +01:00
Tom Rix a8193af7ec powercap/intel_rapl: remove unneeded semicolon
A semicolon is not needed after a switch statement.

Signed-off-by: Tom Rix <trix@redhat.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2020-11-02 18:04:34 +01:00
Zhang Rui f1e8d7560d powercap/intel_rapl: enumerate Psys RAPL domain together with package RAPL domain
On multi-package systems, the Psys MSR is only valid for CPUs on
specific package (master package). The current code makes the
assumption that package 0 is the master package, but this is not
true on new platforms like SPR.

Fix the problem by emuerating the Psys RAPL domain for every
package, so CPUs in slave packages will read 0 for the Psys energy
counter and only CPUs in master packages can get a valid reading
and register the Psys RAPL domain.

The sysfs I/F for the Psys RAPL domain is not changed.

Signed-off-by: Zhang Rui <rui.zhang@intel.com>
[ rjw: Subject and changelog edits ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2020-10-16 17:35:36 +02:00
Zhang Rui 7a57e9f112 powercap/intel_rapl: Fix domain detection
As only the low 32 bits of the RAPL_DOMAIN_REG_STATUS register
represents the energy counter, and the high 32 bits are reserved,
detect the existence of a RAPL domain by checking the low 32 bits only.

Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2020-10-16 17:35:36 +02:00
Ricardo Neri e1c2d96cd0 powercap: RAPL: Add support for Lakefield
Simply add Lakefield model ID. No additional changes are needed.

Signed-off-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
[ rjw: Minor subject edit ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2020-09-16 14:16:04 +02:00
Zhang Rui ba92a42011 powercap/intel_rapl: add support for AlderLake
Add intel_rapl support for the AlderLake platform.

Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2020-09-10 19:17:29 +02:00
Zhang Rui 64e5f36715 powercap/intel_rapl: add support for RocketLake
Add intel_rapl support for the RocketLake platform.

Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2020-09-10 19:17:29 +02:00
Zhang Rui 57a2fb068a powercap/intel_rapl: add support for TigerLake Desktop
Add intel_rapl support for the TigerLake desktop platform.

Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2020-09-10 19:17:29 +02:00
Sumeet Pawnikar 8365a898fe powercap: Add Power Limit4 support
Modern Intel Mobile platforms support power limit4 (PL4), which is
the SoC package level maximum power limit (in Watts). It can be used
to preemptively limits potential SoC power to prevent power spikes
from tripping the power adapter and battery over-current protection.
This patch enables this feature by exposing package level peak power
capping control to userspace via RAPL sysfs interface. With this,
application like DTPF can modify PL4 power limit, the similar way
of other package power limit (PL1).
As this feature is not tested on previous generations, here it is
enabled only for the platform that has been verified to work,
for safety concerns.

Signed-off-by: Sumeet Pawnikar <sumeet.r.pawnikar@intel.com>
Co-developed-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Reviewed-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Tested-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2020-07-27 14:17:36 +02:00
Zhang Rui 2d798d9f59 powercap: intel_rapl: add support for Sapphire Rapids
RAPL on SPR behaves similar to Haswell server, except that SPR uses
a fixed energy unit (1 Joule) for the PSYS RAPL domain.

Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2020-06-30 20:42:07 +02:00