Skip to content

Commit da84789

Browse files
committed
[AMD][Turin][Genoa] Measure DRAM power consumption for SP5 socket
1 parent 5dc529e commit da84789

6 files changed

Lines changed: 110 additions & 41 deletions

File tree

x86_64/amd_reg.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,25 @@ enum {
295295
#define IS_HSMP_OOO(_rx) (_rx == HSMP_UNSPECIFIED \
296296
|| (_rx >= HSMP_FAIL_BGN && _rx <= HSMP_FAIL_END))
297297

298+
typedef union
299+
{
300+
unsigned char addr;
301+
struct {
302+
unsigned char
303+
HID : 3-0, /* Host ID : DIMM SPD */
304+
LID : 7-3, /* Local ID */
305+
Mode0 : 8-7; /* Must be **zero** */
306+
};
307+
struct {
308+
unsigned char
309+
UMC_Inst: 4-0, /* UMC/DDR Phy Logical Mapping */
310+
Dimm_Bit: 5-4, /* DIMM#: DIMM0/1 */
311+
Reserved: 6-5,
312+
Sensor : 7-6, /* Temperature Sensor#: TS0/1 */
313+
Mode1 : 8-7; /* Must be **one** */
314+
};
315+
} ZEN_HSMP_DIMM_ADDR;
316+
298317
typedef union
299318
{
300319
unsigned int value;
@@ -306,6 +325,15 @@ typedef union
306325
};
307326
} ZEN_HSMP_DIMM_PWR;
308327

328+
typedef union
329+
{
330+
unsigned int value;
331+
struct {
332+
unsigned short Fmin,
333+
Fmax;
334+
};
335+
} ZEN_HSMP_FMAX_SKT;
336+
309337
/* Sources: BKDG for AMD Families 0Fh, 10h up to 16h */
310338
const struct {
311339
unsigned int MCF,

x86_64/corefreq-api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ typedef struct
388388
struct
389389
{
390390
unsigned long long ACCU;
391-
} Power, RAM;
391+
} Power;
392392

393393
unsigned int SMI;
394394
} Delta __attribute__ ((aligned (8)));

x86_64/corefreq.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ typedef struct
225225
C1;
226226
struct {
227227
unsigned long long ACCU;
228-
} Power, RAM;
228+
} Power;
229229
} Delta __attribute__ ((aligned (8)));
230230

231231
CLOCK Clock;

x86_64/corefreqd.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,7 +1269,6 @@ static void *Core_Cycle(void *arg)
12691269

12701270
/* Per Core, evaluate the Power properties. */
12711271
CFlip->Delta.Power.ACCU = RO(Core)->Delta.Power.ACCU;
1272-
CFlip->Delta.RAM.ACCU = RO(Core)->Delta.RAM.ACCU;
12731272

12741273
ComputePowerFormula[SCOPE_OF_FORMULA(RO(Shm)->Proc.powerFormula)](
12751274
CFlip, RO(Shm), cpu
@@ -8984,7 +8983,6 @@ static void Pkg_ComputePower_AMD_17h( RW(PROC) *RW(Proc),
89848983
struct FLIP_FLOP *CFlop )
89858984
{
89868985
RW(Proc)->Delta.Power.ACCU[PWR_DOMAIN(CORES)] += CFlop->Delta.Power.ACCU;
8987-
RW(Proc)->Delta.Power.ACCU[PWR_DOMAIN(RAM)] += CFlop->Delta.RAM.ACCU;
89888986
}
89898987

89908988
static void Pkg_ResetPower_None(PROC_RW *Proc)
@@ -9001,7 +8999,6 @@ static void Pkg_ResetPower_None(PROC_RW *Proc)
90018999
static void Pkg_ResetPower_AMD_17h(RW(PROC) *RW(Proc))
90029000
{
90039001
RW(Proc)->Delta.Power.ACCU[PWR_DOMAIN(CORES)] = 0;
9004-
RW(Proc)->Delta.Power.ACCU[PWR_DOMAIN(RAM)] = 0;
90059002
}
90069003

90079004
void Pkg_ResetSensorLimits(PROC_STRUCT *Pkg)

x86_64/corefreqk.c

Lines changed: 74 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9290,13 +9290,7 @@ static unsigned int Query_AMD_HSMP_FreqRange(unsigned int cpu)
92909290
rx = AMD_HSMP_Exec(HSMP_RD_FMAX_SKT, arg);
92919291
if ((rx == HSMP_RESULT_OK) && (arg[0].value > 0))
92929292
{
9293-
union {
9294-
struct {
9295-
unsigned short Fmin,
9296-
Fmax;
9297-
};
9298-
unsigned int value;
9299-
} Socket = { .value = arg[0].value };
9293+
ZEN_HSMP_FMAX_SKT Socket = { .value = arg[0].value };
93009294

93019295
PUBLIC(RO(Core, AT(cpu)))->Boost[BOOST(MIN)] = \
93029296
Socket.Fmin / PRECISION ? :
@@ -20823,42 +20817,62 @@ static void Call_MSR_ACCU(CORE_RO *Core)
2082320817
}
2082420818
}
2082520819

20826-
static void Call_HSMP_ACCU(CORE_RO *Core)
20827-
{ /* Convert DIMM Power from HSMP to RAPL. */
20828-
if (PUBLIC(RO(Proc))->Features.HSMP_Enable)
20829-
{
20820+
static unsigned long long Query_AMD_HSMP_DIMM_Power(const unsigned short umc,
20821+
const unsigned short dimm)
20822+
{
20823+
ZEN_HSMP_DIMM_ADDR DIMM = {
20824+
.UMC_Inst = umc,
20825+
.Dimm_Bit = dimm,
20826+
.Reserved = 0,
20827+
.Sensor = 0,
20828+
.Mode1 = 1
20829+
};
2083020830
ZEN_HSMP_DIMM_PWR DIMM_PWR = {
20831-
.mWatt = 0, .ms = 0, .addr = Core->T.ApicID
20831+
.mWatt = 0, .ms = 0, .addr = DIMM.addr
2083220832
};
2083320833
HSMP_ARG arg[8] = {
2083420834
[7] = {0x0}, [6] = {0x0}, [5] = {0x0}, [4] = {0x0},
20835-
[3] = {0x0}, [2] = {0x0}, [1] = {0x0}, [0] = {DIMM_PWR.value}
20835+
[3] = {0x0}, [2] = {0x0}, [1] = {0x0}, [0] = { DIMM_PWR.value }
2083620836
};
2083720837
unsigned int rx;
20838-
if ((rx = AMD_HSMP_Exec(HSMP_RD_DIMM_PWR, arg)) == HSMP_RESULT_OK)
20839-
{
20840-
DIMM_PWR.value = arg[0].value;
20841-
if ((DIMM_PWR.mWatt > 0) && (DIMM_PWR.mWatt != 0b111111111111111))
20842-
{
20843-
Core->Delta.RAM.ACCU = (unsigned long long) DIMM_PWR.mWatt;
20844-
Core->Delta.RAM.ACCU <<= PUBLIC(RO(Proc))->PowerThermal.Unit.ESU;
20845-
Core->Delta.RAM.ACCU *= PUBLIC(RO(Proc))->SleepInterval;
20846-
Core->Delta.RAM.ACCU = Core->Delta.RAM.ACCU / (1000LLU * 1000LLU);
20847-
}
20848-
}
20849-
else if (IS_HSMP_OOO(rx))
20850-
{
20851-
PUBLIC(RO(Proc))->Features.HSMP_Enable = 0;
20852-
}
20853-
}
20838+
if ((rx = AMD_HSMP_Exec(HSMP_RD_DIMM_PWR, arg)) == HSMP_RESULT_OK)
20839+
{
20840+
DIMM_PWR.value = arg[0].value;
20841+
if ((DIMM_PWR.mWatt > 0) && (DIMM_PWR.mWatt != 0b111111111111111))
20842+
{
20843+
return (unsigned long long) DIMM_PWR.mWatt;
20844+
}
20845+
}
20846+
else if (IS_HSMP_OOO(rx))
20847+
{
20848+
PUBLIC(RO(Proc))->Features.HSMP_Enable = 0;
20849+
}
20850+
return 0LLU;
20851+
}
20852+
20853+
static void Call_HSMP_ACCU(const unsigned short ids, const unsigned short UMC[])
20854+
{
20855+
unsigned long long DIMM_PWR_mWatt = 0;
20856+
20857+
unsigned short id = 0;
20858+
for (id = 0; id < ids && PUBLIC(RO(Proc))->Features.HSMP_Enable; id++)
20859+
{
20860+
DIMM_PWR_mWatt += Query_AMD_HSMP_DIMM_Power(UMC[id], 0);
20861+
}
20862+
/* Convert DIMM Power from HSMP to RAPL. */
20863+
DIMM_PWR_mWatt <<= PUBLIC(RO(Proc))->PowerThermal.Unit.ESU;
20864+
DIMM_PWR_mWatt *= PUBLIC(RO(Proc))->SleepInterval;
20865+
DIMM_PWR_mWatt /= (1000LLU * 1000LLU);
20866+
PUBLIC(RW(Proc))->Delta.Power.ACCU[PWR_DOMAIN(RAM)] = DIMM_PWR_mWatt;
2085420867
}
2085520868

2085620869
static void Call_Genoa_ACCU(CORE_RO *Core)
2085720870
{
2085820871
Call_MSR_ACCU(Core);
20859-
Call_HSMP_ACCU(Core);
2086020872
}
2086120873

20874+
#define Call_Turin_ACCU Call_Genoa_ACCU
20875+
2086220876
static void SoC_RAPL(AMD_F17H_SVI SVI, const unsigned long long factor)
2086320877
{
2086420878
unsigned long long VCC, ICC, ACCU;
@@ -20963,6 +20977,26 @@ static void Call_Genoa( const unsigned int plane0, const unsigned int plane1,
2096320977
}
2096420978
}
2096520979

20980+
#define Call_Turin Call_Genoa
20981+
20982+
static void Call_Genoa_SP5(const unsigned int plane0, const unsigned int plane1,
20983+
const unsigned long long factor)
20984+
{
20985+
Call_Genoa(plane0, plane1, factor);
20986+
20987+
Call_HSMP_ACCU( 12, (const unsigned short[12])
20988+
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 } );
20989+
}
20990+
20991+
static void Call_Turin_SP5(const unsigned int plane0, const unsigned int plane1,
20992+
const unsigned long long factor)
20993+
{
20994+
Call_Turin(plane0, plane1, factor);
20995+
20996+
Call_HSMP_ACCU( 12, (const unsigned short[12])
20997+
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 } );
20998+
}
20999+
2096621000
static enum hrtimer_restart Entry_AMD_F17h(struct hrtimer *pTimer,
2096721001
void (*Call_PWR)(CORE_RO *Core),
2096821002
void (*Call_SMU)(const unsigned int, const unsigned int,
@@ -21015,7 +21049,11 @@ static enum hrtimer_restart Cycle_AMD_Zen4_RPL(struct hrtimer *pTimer)
2101521049
}
2101621050
static enum hrtimer_restart Cycle_AMD_Zen4_Genoa(struct hrtimer *pTimer)
2101721051
{
21018-
return Entry_AMD_F17h(pTimer, Call_Genoa_ACCU, Call_Genoa, 1, 2, 0LLU);
21052+
return Entry_AMD_F17h(pTimer, Call_Genoa_ACCU, Call_Genoa_SP5,1,2,0LLU);
21053+
}
21054+
static enum hrtimer_restart Cycle_AMD_Zen5_Turin(struct hrtimer *pTimer)
21055+
{
21056+
return Entry_AMD_F17h(pTimer, Call_Turin_ACCU, Call_Turin_SP5,1,2,0LLU);
2101921057
}
2102021058
static enum hrtimer_restart Cycle_AMD_F17h(struct hrtimer *pTimer)
2102121059
{
@@ -21062,6 +21100,11 @@ static void InitTimer_AMD_Zen4_Genoa(unsigned int cpu)
2106221100
smp_call_function_single(cpu, InitTimer, Cycle_AMD_Zen4_Genoa, 1);
2106321101
}
2106421102

21103+
static void InitTimer_AMD_Zen5_Turin(unsigned int cpu)
21104+
{
21105+
smp_call_function_single(cpu, InitTimer, Cycle_AMD_Zen5_Turin, 1);
21106+
}
21107+
2106521108
static void InitTimer_AMD_Zen5_STX(unsigned int cpu)
2106621109
{
2106721110
smp_call_function_single(cpu, InitTimer, Cycle_AMD_F17h, 1);

x86_64/corefreqk.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,6 +1626,7 @@ static void PerCore_AMD_Family_1Ah_Query(void *arg) ;
16261626

16271627
static void Query_AMD_F1Ah_24h_60h_70h_PerSocket(unsigned int cpu) ;
16281628
static void InitTimer_AMD_Zen5_STX(unsigned int cpu) ;
1629+
static void InitTimer_AMD_Zen5_Turin(unsigned int cpu) ;
16291630

16301631
/* [Void] */
16311632
#define _Void_Signature {.ExtFamily=0x0, .Family=0x0, .ExtModel=0x0, .Model=0x0}
@@ -14400,7 +14401,7 @@ static ARCH Arch[ARCHITECTURES] = {
1440014401
.Start = Start_AMD_Family_1Ah,
1440114402
.Stop = Stop_AMD_Family_1Ah,
1440214403
.Exit = Exit_AMD_F1Ah,
14403-
.Timer = InitTimer_AMD_Family_1Ah,
14404+
.Timer = InitTimer_AMD_Zen5_Turin,
1440414405
.BaseClock = BaseClock_AMD_Family_1Ah,
1440514406
.ClockMod = ClockMod_AMD_Zen,
1440614407
.TurboClock = TurboClock_AMD_Zen,
@@ -14424,7 +14425,7 @@ static ARCH Arch[ARCHITECTURES] = {
1442414425
.Start = Start_AMD_Family_1Ah,
1442514426
.Stop = Stop_AMD_Family_1Ah,
1442614427
.Exit = Exit_AMD_F1Ah,
14427-
.Timer = InitTimer_AMD_Family_1Ah,
14428+
.Timer = InitTimer_AMD_Zen5_Turin,
1442814429
.BaseClock = BaseClock_AMD_Family_1Ah,
1442914430
.ClockMod = ClockMod_AMD_Zen,
1443014431
.TurboClock = TurboClock_AMD_Zen,
@@ -14448,7 +14449,7 @@ static ARCH Arch[ARCHITECTURES] = {
1444814449
.Start = Start_AMD_Family_1Ah,
1444914450
.Stop = Stop_AMD_Family_1Ah,
1445014451
.Exit = Exit_AMD_F1Ah,
14451-
.Timer = InitTimer_AMD_Family_1Ah,
14452+
.Timer = InitTimer_AMD_Zen5_Turin,
1445214453
.BaseClock = BaseClock_AMD_Family_1Ah,
1445314454
.ClockMod = ClockMod_AMD_Zen,
1445414455
.TurboClock = TurboClock_AMD_Zen,
@@ -14463,7 +14464,7 @@ static ARCH Arch[ARCHITECTURES] = {
1446314464
},
1446414465
.Specific = AMD_Zen5_F1Ah_Specific,
1446514466
.SystemDriver = VOID_Driver,
14466-
.Architecture = Arch_AMD_Family_1Ah
14467+
.Architecture = Arch_AMD_Zen5_Turin
1446714468
},
1446814469
[AMD_Zen5_KRK] = { /*133*/
1446914470
.Signature = _AMD_Zen5_KRK,
@@ -14520,7 +14521,7 @@ static ARCH Arch[ARCHITECTURES] = {
1452014521
.Start = Start_AMD_Family_1Ah,
1452114522
.Stop = Stop_AMD_Family_1Ah,
1452214523
.Exit = Exit_AMD_F1Ah,
14523-
.Timer = InitTimer_AMD_Family_1Ah,
14524+
.Timer = InitTimer_AMD_Zen5_Turin,
1452414525
.BaseClock = BaseClock_AMD_Family_1Ah,
1452514526
.ClockMod = ClockMod_AMD_Zen,
1452614527
.TurboClock = TurboClock_AMD_Zen,

0 commit comments

Comments
 (0)