Skip to content

Commit

Permalink
Merge branch 'master' of github.com:RRZE-HPC/likwid
Browse files Browse the repository at this point in the history
  • Loading branch information
TomTheBear committed Dec 3, 2024
2 parents da5f917 + 08f7095 commit 61e6ef0
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/includes/sysFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,4 @@
#define HWFEATURES_MAX_STR_LENGTH 100
#define HWFEATURES_MIN_STRLEN(a, b) ((a) > (b) ? (b) : (a))


#endif
8 changes: 8 additions & 0 deletions src/includes/sysFeatures_intel_thermal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef SYSFEATURES_INTEL_THERMAL_H
#define SYSFEATURES_INTEL_THERMAL_H

#include <sysFeatures_types.h>

extern const _SysFeatureList likwid_sysft_intel_cpu_thermal_feature_list;

#endif //SYSFEATURES_INTEL_THERMAL_H
39 changes: 36 additions & 3 deletions src/sysFeatures_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,16 +362,46 @@ static int readmsr_socket(const LikwidDevice_t device, uint64_t reg, uint64_t *m
if ((int)t->packageId == device->id.simple.id && t->inCpuSet)
{
err = HPMaddThread(t->apicId);
if (err < 0) continue;
if (err < 0)
continue;
err = HPMread(t->apicId, MSR_DEV, reg, msrData);
if (err < 0) continue;
if (err < 0)
continue;
return 0;
}
}

if (err < 0)
return err;
return -ENODEV;
}

static int readmsr_core(const LikwidDevice_t device, uint64_t reg, uint64_t *msrData)
{
assert(device->type == DEVICE_TYPE_CORE);

int err = topology_init();
if (err < 0)
{
return err;

CpuTopology_t topo = get_cpuTopology();
for (unsigned i = 0; i < topo->numHWThreads; i++)
{
HWThread* t = &topo->threadPool[i];
if ((int)t->coreId == device->id.simple.id && t->inCpuSet)
{
err = HPMaddThread(t->apicId);
if (err < 0)
continue;
err = HPMread(t->apicId, MSR_DEV, reg, msrData);
if (err < 0)
continue;
return 0;
}
}

if (err < 0)
return err;
return -ENODEV;
}

Expand All @@ -398,6 +428,9 @@ int likwid_sysft_readmsr(const LikwidDevice_t device, uint64_t reg, uint64_t *ms
case DEVICE_TYPE_SOCKET:
err = readmsr_socket(device, reg, msrData);
break;
case DEVICE_TYPE_CORE:
err = readmsr_core(device, reg, msrData);
break;
case DEVICE_TYPE_HWTHREAD:
err = readmsr_hwthread(device, reg, msrData);
break;
Expand Down
2 changes: 2 additions & 0 deletions src/sysFeatures_intel.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include <sysFeatures_intel_turbo.h>
#include <sysFeatures_intel_uncorefreq.h>
#include <sysFeatures_intel_spec_ctrl.h>
#include <sysFeatures_intel_thermal.h>

static const _HWArchFeatures intel_arch_features[];

Expand Down Expand Up @@ -81,6 +82,7 @@ static const _SysFeatureList* intel_arch_feature_inputs[] = {
&likwid_sysft_intel_cpu_turbo_feature_list,
&likwid_sysft_intel_uncorefreq_feature_list,
&likwid_sysft_intel_cpu_spec_ctrl_feature_list,
&likwid_sysft_intel_cpu_thermal_feature_list,
NULL,
};

Expand Down
91 changes: 91 additions & 0 deletions src/sysFeatures_intel_thermal.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#include <sysFeatures_intel_thermal.h>

#include <string.h>
#include <stdbool.h>

#include <sysFeatures_common.h>
#include <topology.h>
#include <registers.h>

static int intel_thermal_temperature_getter(const LikwidDevice_t device, bool core, char **value)
{
if (!device || !value)
return -EINVAL;

int err;
_LikwidDevice socketDev;
if (core)
{
/* If we read temperature from the core, we need to determine its socket.
* That is because the TEMPERATURE_TARGET is per socket only. */
err = topology_init();
if (err < 0)
return err;

bool found = false;
CpuTopology_t topo = get_cpuTopology();
for (unsigned i = 0; i < topo->numHWThreads; i++)
{
const HWThread *t = &topo->threadPool[i];
if (t->packageId != i)
continue;

memset(&socketDev, 0, sizeof(socketDev));
socketDev.type = DEVICE_TYPE_SOCKET;
socketDev.id.simple.id = t->packageId;
socketDev.internal_id = t->packageId;
found = true;
break;
}

if (!found)
return -EINVAL;
} else {
socketDev = *device;
}

uint64_t therm_status_raw;
err = likwid_sysft_readmsr(device, core ? IA32_THERM_STATUS : IA32_PACKAGE_THERM_STATUS, &therm_status_raw);
if (err < 0)
return err;

const int readout = (int)field64(therm_status_raw, 16, 7);

uint64_t temp_target_raw;
err = likwid_sysft_readmsr(&socketDev, MSR_TEMPERATURE_TARGET, &temp_target_raw);
if (err < 0)
return err;

const int temp_target = (int)field64(temp_target_raw, 16, 8);
const int temp_offset = (int)field64(temp_target_raw, 24, 6);

const int final_temp = temp_target - temp_offset - readout;

return likwid_sysft_uint64_to_string(final_temp, value);
}

static int intel_thermal_temperature_core_getter(LikwidDevice_t dev, char **value)
{
return intel_thermal_temperature_getter(dev, DEVICE_TYPE_CORE, value);
}

static int intel_thermal_temperature_socket_getter(LikwidDevice_t dev, char **value)
{
return intel_thermal_temperature_getter(dev, DEVICE_TYPE_SOCKET, value);
}

static int intel_thermal_tester(void)
{
return cpuid_hasFeature(TM2);
}

static _SysFeature intel_thermal_features[] = {
{"core_temp", "thermal", "Current CPU temperature (core)", intel_thermal_temperature_core_getter, NULL, DEVICE_TYPE_CORE, NULL, "degrees C"},
{"pkg_temp", "thermal", "Current CPU temperature (package)", intel_thermal_temperature_socket_getter, NULL, DEVICE_TYPE_SOCKET, NULL, "degrees C"},
};

const _SysFeatureList likwid_sysft_intel_cpu_thermal_feature_list = {
.num_features = ARRAY_COUNT(intel_thermal_features),
.tester = intel_thermal_tester,
.features = intel_thermal_features,
};

0 comments on commit 61e6ef0

Please sign in to comment.