^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) .. SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) Kernel driver amd_energy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) ==========================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) Supported chips:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * AMD Family 17h Processors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) Prefix: 'amd_energy'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) Addresses used: RAPL MSRs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) Datasheets:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) - Processor Programming Reference (PPR) for AMD Family 17h Model 01h, Revision B1 Processors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) https://developer.amd.com/wp-content/resources/55570-B1_PUB.zip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) - Preliminary Processor Programming Reference (PPR) for AMD Family 17h Model 31h, Revision B0 Processors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) https://developer.amd.com/wp-content/resources/56176_ppr_Family_17h_Model_71h_B0_pub_Rev_3.06.zip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) Author: Naveen Krishna Chatradhi <nchatrad@amd.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) Description
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) -----------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) The Energy driver exposes the energy counters that are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) reported via the Running Average Power Limit (RAPL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) Model-specific Registers (MSRs) via the hardware monitor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) (HWMON) sysfs interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 1. Power, Energy and Time Units
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) MSR_RAPL_POWER_UNIT/ C001_0299:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) shared with all cores in the socket
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 2. Energy consumed by each Core
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) MSR_CORE_ENERGY_STATUS/ C001_029A:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 32-bitRO, Accumulator, core-level power reporting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 3. Energy consumed by Socket
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) MSR_PACKAGE_ENERGY_STATUS/ C001_029B:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 32-bitRO, Accumulator, socket-level power reporting,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) shared with all cores in socket
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) These registers are updated every 1ms and cleared on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) reset of the system.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) Note: If SMT is enabled, Linux enumerates all threads as cpus.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) Since, the energy status registers are accessed at core level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) reading those registers from the sibling threads would result
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) in duplicate values. Hence, energy counter entries are not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) populated for the siblings.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) Energy Caluclation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) ------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) Energy information (in Joules) is based on the multiplier,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 1/2^ESU; where ESU is an unsigned integer read from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) MSR_RAPL_POWER_UNIT register. Default value is 10000b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) indicating energy status unit is 15.3 micro-Joules increment.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) Reported values are scaled as per the formula
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) scaled value = ((1/2^ESU) * (Raw value) * 1000000UL) in uJoules
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) Users calculate power for a given domain by calculating
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) dEnergy/dTime for that domain.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) Energy accumulation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) --------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) Current, Socket energy status register is 32bit, assuming a 240W
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) 2P system, the register would wrap around in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) 2^32*15.3 e-6/240 * 2 = 547.60833024 secs to wrap(~9 mins)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) The Core energy register may wrap around after several days.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) To improve the wrap around time, a kernel thread is implemented
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) to accumulate the socket energy counters and one core energy counter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) per run to a respective 64-bit counter. The kernel thread starts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) running during probe, wakes up every 100secs and stops running
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) when driver is removed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) Frequency of the accumulator thread is set during the probe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) based on the chosen energy unit resolution. For example
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) A. fine grain (1.625 micro J)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) B. course grain (0.125 milli J)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) A socket and core energy read would return the current register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) value added to the respective energy accumulator.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) Sysfs attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) ----------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) =============== ======== =====================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) Attribute Label Description
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) =============== ======== =====================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) * For index N between [1] and [nr_cpus]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) =============== ======== ======================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) energy[N]_input EcoreX Core Energy X = [0] to [nr_cpus - 1]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) Measured input core energy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) =============== ======== ======================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * For N between [nr_cpus] and [nr_cpus + nr_socks]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) =============== ======== ======================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) energy[N]_input EsocketX Socket Energy X = [0] to [nr_socks -1]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) Measured input socket energy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) =============== ======== ======================================