1*4882a593SmuzhiyunKernel driver fam15h_power 2*4882a593Smuzhiyun========================== 3*4882a593Smuzhiyun 4*4882a593SmuzhiyunSupported chips: 5*4882a593Smuzhiyun 6*4882a593Smuzhiyun* AMD Family 15h Processors 7*4882a593Smuzhiyun 8*4882a593Smuzhiyun* AMD Family 16h Processors 9*4882a593Smuzhiyun 10*4882a593Smuzhiyun Prefix: 'fam15h_power' 11*4882a593Smuzhiyun 12*4882a593Smuzhiyun Addresses scanned: PCI space 13*4882a593Smuzhiyun 14*4882a593Smuzhiyun Datasheets: 15*4882a593Smuzhiyun 16*4882a593Smuzhiyun - BIOS and Kernel Developer's Guide (BKDG) For AMD Family 15h Processors 17*4882a593Smuzhiyun - BIOS and Kernel Developer's Guide (BKDG) For AMD Family 16h Processors 18*4882a593Smuzhiyun - AMD64 Architecture Programmer's Manual Volume 2: System Programming 19*4882a593Smuzhiyun 20*4882a593SmuzhiyunAuthor: Andreas Herrmann <herrmann.der.user@googlemail.com> 21*4882a593Smuzhiyun 22*4882a593SmuzhiyunDescription 23*4882a593Smuzhiyun----------- 24*4882a593Smuzhiyun 25*4882a593Smuzhiyun1) Processor TDP (Thermal design power) 26*4882a593Smuzhiyun 27*4882a593SmuzhiyunGiven a fixed frequency and voltage, the power consumption of a 28*4882a593Smuzhiyunprocessor varies based on the workload being executed. Derated power 29*4882a593Smuzhiyunis the power consumed when running a specific application. Thermal 30*4882a593Smuzhiyundesign power (TDP) is an example of derated power. 31*4882a593Smuzhiyun 32*4882a593SmuzhiyunThis driver permits reading of registers providing power information 33*4882a593Smuzhiyunof AMD Family 15h and 16h processors via TDP algorithm. 34*4882a593Smuzhiyun 35*4882a593SmuzhiyunFor AMD Family 15h and 16h processors the following power values can 36*4882a593Smuzhiyunbe calculated using different processor northbridge function 37*4882a593Smuzhiyunregisters: 38*4882a593Smuzhiyun 39*4882a593Smuzhiyun* BasePwrWatts: 40*4882a593Smuzhiyun Specifies in watts the maximum amount of power 41*4882a593Smuzhiyun consumed by the processor for NB and logic external to the core. 42*4882a593Smuzhiyun 43*4882a593Smuzhiyun* ProcessorPwrWatts: 44*4882a593Smuzhiyun Specifies in watts the maximum amount of power 45*4882a593Smuzhiyun the processor can support. 46*4882a593Smuzhiyun* CurrPwrWatts: 47*4882a593Smuzhiyun Specifies in watts the current amount of power being 48*4882a593Smuzhiyun consumed by the processor. 49*4882a593Smuzhiyun 50*4882a593SmuzhiyunThis driver provides ProcessorPwrWatts and CurrPwrWatts: 51*4882a593Smuzhiyun 52*4882a593Smuzhiyun* power1_crit (ProcessorPwrWatts) 53*4882a593Smuzhiyun* power1_input (CurrPwrWatts) 54*4882a593Smuzhiyun 55*4882a593SmuzhiyunOn multi-node processors the calculated value is for the entire 56*4882a593Smuzhiyunpackage and not for a single node. Thus the driver creates sysfs 57*4882a593Smuzhiyunattributes only for internal node0 of a multi-node processor. 58*4882a593Smuzhiyun 59*4882a593Smuzhiyun2) Accumulated Power Mechanism 60*4882a593Smuzhiyun 61*4882a593SmuzhiyunThis driver also introduces an algorithm that should be used to 62*4882a593Smuzhiyuncalculate the average power consumed by a processor during a 63*4882a593Smuzhiyunmeasurement interval Tm. The feature of accumulated power mechanism is 64*4882a593Smuzhiyunindicated by CPUID Fn8000_0007_EDX[12]. 65*4882a593Smuzhiyun 66*4882a593Smuzhiyun* Tsample: 67*4882a593Smuzhiyun compute unit power accumulator sample period 68*4882a593Smuzhiyun 69*4882a593Smuzhiyun* Tref: 70*4882a593Smuzhiyun the PTSC counter period 71*4882a593Smuzhiyun 72*4882a593Smuzhiyun* PTSC: 73*4882a593Smuzhiyun performance timestamp counter 74*4882a593Smuzhiyun 75*4882a593Smuzhiyun* N: 76*4882a593Smuzhiyun the ratio of compute unit power accumulator sample period to the 77*4882a593Smuzhiyun PTSC period 78*4882a593Smuzhiyun 79*4882a593Smuzhiyun* Jmax: 80*4882a593Smuzhiyun max compute unit accumulated power which is indicated by 81*4882a593Smuzhiyun MaxCpuSwPwrAcc MSR C001007b 82*4882a593Smuzhiyun 83*4882a593Smuzhiyun* Jx/Jy: 84*4882a593Smuzhiyun compute unit accumulated power which is indicated by 85*4882a593Smuzhiyun CpuSwPwrAcc MSR C001007a 86*4882a593Smuzhiyun* Tx/Ty: 87*4882a593Smuzhiyun the value of performance timestamp counter which is indicated 88*4882a593Smuzhiyun by CU_PTSC MSR C0010280 89*4882a593Smuzhiyun 90*4882a593Smuzhiyun* PwrCPUave: 91*4882a593Smuzhiyun CPU average power 92*4882a593Smuzhiyun 93*4882a593Smuzhiyuni. Determine the ratio of Tsample to Tref by executing CPUID Fn8000_0007. 94*4882a593Smuzhiyun 95*4882a593Smuzhiyun N = value of CPUID Fn8000_0007_ECX[CpuPwrSampleTimeRatio[15:0]]. 96*4882a593Smuzhiyun 97*4882a593Smuzhiyunii. Read the full range of the cumulative energy value from the new 98*4882a593Smuzhiyun MSR MaxCpuSwPwrAcc. 99*4882a593Smuzhiyun 100*4882a593Smuzhiyun Jmax = value returned. 101*4882a593Smuzhiyun 102*4882a593Smuzhiyuniii. At time x, SW reads CpuSwPwrAcc MSR and samples the PTSC. 103*4882a593Smuzhiyun 104*4882a593Smuzhiyun Jx = value read from CpuSwPwrAcc and Tx = value read from PTSC. 105*4882a593Smuzhiyun 106*4882a593Smuzhiyuniv. At time y, SW reads CpuSwPwrAcc MSR and samples the PTSC. 107*4882a593Smuzhiyun 108*4882a593Smuzhiyun Jy = value read from CpuSwPwrAcc and Ty = value read from PTSC. 109*4882a593Smuzhiyun 110*4882a593Smuzhiyunv. Calculate the average power consumption for a compute unit over 111*4882a593Smuzhiyun time period (y-x). Unit of result is uWatt:: 112*4882a593Smuzhiyun 113*4882a593Smuzhiyun if (Jy < Jx) // Rollover has occurred 114*4882a593Smuzhiyun Jdelta = (Jy + Jmax) - Jx 115*4882a593Smuzhiyun else 116*4882a593Smuzhiyun Jdelta = Jy - Jx 117*4882a593Smuzhiyun PwrCPUave = N * Jdelta * 1000 / (Ty - Tx) 118*4882a593Smuzhiyun 119*4882a593SmuzhiyunThis driver provides PwrCPUave and interval(default is 10 millisecond 120*4882a593Smuzhiyunand maximum is 1 second): 121*4882a593Smuzhiyun 122*4882a593Smuzhiyun* power1_average (PwrCPUave) 123*4882a593Smuzhiyun* power1_average_interval (Interval) 124*4882a593Smuzhiyun 125*4882a593SmuzhiyunThe power1_average_interval can be updated at /etc/sensors3.conf file 126*4882a593Smuzhiyunas below: 127*4882a593Smuzhiyun 128*4882a593Smuzhiyunchip `fam15h_power-*` 129*4882a593Smuzhiyun set power1_average_interval 0.01 130*4882a593Smuzhiyun 131*4882a593SmuzhiyunThen save it with "sensors -s". 132