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