Skip to content

Commit 64f2382

Browse files
committed
CPU nominal TDP
1 parent 6a8de8d commit 64f2382

File tree

5 files changed

+46
-0
lines changed

5 files changed

+46
-0
lines changed

libnw/cpu/amd_cpu.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,25 @@ static int get_microcode_ver(struct msr_info_t* info)
614614
return 0;
615615
}
616616

617+
#define F17H_ZEN2_MCM_TDP 0x0005D2B8 // [11:3]
618+
619+
static int get_tdp_nominal(struct msr_info_t* info)
620+
{
621+
#if 0
622+
int ret = CPU_INVALID_VALUE;
623+
WR0_WaitPciBus(10);
624+
if (info->id->x86.ext_family < 0x17)
625+
goto fail;
626+
DWORD raw_tdp = WR0_RdAmdSmn(info->handle, WR0_SMN_AMD17H, F17H_ZEN2_MCM_TDP);
627+
ret = (int)((raw_tdp >> 3) & 0x1FF);
628+
fail:
629+
WR0_ReleasePciBus();
630+
return ret;
631+
#else
632+
return CPU_INVALID_VALUE;
633+
#endif
634+
}
635+
617636
struct msr_fn_t msr_fn_amd =
618637
{
619638
.get_min_multiplier = get_min_multiplier,
@@ -629,4 +648,5 @@ struct msr_fn_t msr_fn_amd =
629648
.get_igpu_temperature = get_igpu_temperature,
630649
.get_igpu_energy = get_igpu_energy,
631650
.get_microcode_ver = get_microcode_ver,
651+
.get_tdp_nominal = get_tdp_nominal,
632652
};

libnw/cpu/centaur_cpu.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ static int get_microcode_ver(struct msr_info_t* info)
160160
return 0;
161161
}
162162

163+
static int get_tdp_nominal(struct msr_info_t* info)
164+
{
165+
return CPU_INVALID_VALUE;
166+
}
167+
163168
struct msr_fn_t msr_fn_centaur =
164169
{
165170
.get_min_multiplier = get_min_multiplier,
@@ -175,4 +180,5 @@ struct msr_fn_t msr_fn_centaur =
175180
.get_igpu_temperature = get_igpu_temperature,
176181
.get_igpu_energy = get_igpu_energy,
177182
.get_microcode_ver = get_microcode_ver,
183+
.get_tdp_nominal = get_tdp_nominal,
178184
};

libnw/cpu/intel_cpu.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#define MSR_IA32_BIOS_SIGN_ID 0x8B
2424
#define MSR_FSB_FREQ 0xCD
2525

26+
#define MSR_PKG_POWER_INFO 0x614
27+
2628
static inline int
2729
read_intel_msr(struct wr0_drv_t* handle, uint32_t msr_index, uint8_t highbit, uint8_t lowbit, uint64_t* result)
2830
{
@@ -271,6 +273,18 @@ static int get_microcode_ver(struct msr_info_t* info)
271273
return 0;
272274
}
273275

276+
static int get_tdp_nominal(struct msr_info_t* info)
277+
{
278+
uint64_t raw_tdp, pu;
279+
if (read_intel_msr(info->handle, MSR_PKG_POWER_INFO, 14, 0, &raw_tdp))
280+
goto fail;
281+
if (read_intel_msr(info->handle, MSR_RAPL_POWER_UNIT, 3, 0, &pu))
282+
goto fail;
283+
return (int)raw_tdp / (1ULL << pu);
284+
fail:
285+
return CPU_INVALID_VALUE;
286+
}
287+
274288
struct msr_fn_t msr_fn_intel =
275289
{
276290
.get_min_multiplier = get_min_multiplier,
@@ -286,4 +300,5 @@ struct msr_fn_t msr_fn_intel =
286300
.get_igpu_temperature = get_igpu_temperature,
287301
.get_igpu_energy = get_igpu_energy,
288302
.get_microcode_ver = get_microcode_ver,
303+
.get_tdp_nominal = get_tdp_nominal,
289304
};

libnw/cpu/rdmsr.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ int cpu_msrinfo(struct wr0_drv_t* handle, logical_cpu_t cpu, cpu_msrinfo_request
139139
case INFO_MICROCODE_VER:
140140
ret = (int) (fn->get_microcode_ver(&info));
141141
break;
142+
case INFO_TDP_NOMINAL:
143+
ret = (int) fn->get_tdp_nominal(&info);
144+
break;
142145
}
143146
// Restore AffinityMask
144147
SetThreadGroupAffinity(thread, &saved_aff, NULL);

libnw/cpu/rdmsr.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ typedef enum
4040
INFO_IGPU_ENERGY, /*!< The current integrated GPU energy consumption in Joules,
4141
multiplied by 100. */
4242
INFO_MICROCODE_VER, /*!< The microcode revision number */
43+
INFO_TDP_NOMINAL, /*!< The TDP in Watts. */
4344
} cpu_msrinfo_request_t;
4445

4546
/**
@@ -74,6 +75,7 @@ struct msr_fn_t
7475
int (*get_igpu_temperature)(struct msr_info_t* info);
7576
double (*get_igpu_energy)(struct msr_info_t* info);
7677
int (*get_microcode_ver)(struct msr_info_t* info);
78+
int (*get_tdp_nominal)(struct msr_info_t* info);
7779
};
7880

7981
struct msr_info_t

0 commit comments

Comments
 (0)