-
-
Notifications
You must be signed in to change notification settings - Fork 442
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
linux: assign CPU temperatures by package/core or CCD #1352
base: main
Are you sure you want to change the base?
Changes from all commits
9875459
6ba9905
edc4417
a0f8646
8219851
7460082
fff938b
18ab414
7581c9e
195abc3
333bc6d
8fdd40c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -616,6 +616,100 @@ static void scanCPUFrequencyFromCPUinfo(LinuxMachine* this) { | |
} | ||
} | ||
|
||
#ifdef HAVE_SENSORS_SENSORS_H | ||
static void LinuxMachine_fetchCPUTopologyFromCPUinfo(LinuxMachine* this) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function does similar to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then we need to move the |
||
const Machine* super = &this->super; | ||
|
||
FILE* file = fopen(PROCCPUINFOFILE, "r"); | ||
if (file == NULL) | ||
return; | ||
|
||
int cpuid = -1; | ||
int coreid = -1; | ||
int physicalid = -1; | ||
|
||
int max_physicalid = -1; | ||
int max_coreid = -1; | ||
|
||
while (!feof(file)) { | ||
char *buffer = String_readLine(file); | ||
if (!buffer) | ||
break; | ||
|
||
if (buffer[0] == '\0') { /* empty line after each cpu */ | ||
if (cpuid >= 0 && (unsigned int)cpuid < super->existingCPUs) { | ||
CPUData* cpuData = &(this->cpuData[cpuid + 1]); | ||
cpuData->coreID = coreid; | ||
cpuData->physicalID = physicalid; | ||
|
||
if (coreid > max_coreid) | ||
max_coreid = coreid; | ||
if (physicalid > max_physicalid) | ||
max_physicalid = physicalid; | ||
|
||
cpuid = -1; | ||
coreid = -1; | ||
physicalid = -1; | ||
} | ||
} else if (String_startsWith(buffer, "processor")) { | ||
sscanf(buffer, "processor : %d", &cpuid); | ||
} else if (String_startsWith(buffer, "physical id")) { | ||
sscanf(buffer, "physical id : %d", &physicalid); | ||
} else if (String_startsWith(buffer, "core id")) { | ||
sscanf(buffer, "core id : %d", &coreid); | ||
} | ||
|
||
free(buffer); | ||
} | ||
|
||
this->maxPhysicalID = max_physicalid; | ||
this->maxCoreID = max_coreid; | ||
|
||
fclose(file); | ||
} | ||
|
||
static void LinuxMachine_assignCCDs(LinuxMachine* this, int ccds) { | ||
/* For AMD k10temp/zenpower, temperatures are provided for CCDs only, | ||
which is an aggregate of multiple cores. | ||
There's no obvious mapping between hwmon sensors and sockets and CCDs. | ||
Assume both are iterated in order. | ||
Hypothesis: Each CCD has same size N = #Cores/#CCD | ||
and is assigned N coreID in sequence. | ||
Also assume all CPUs have same number of CCDs. */ | ||
|
||
const Machine* super = &this->super; | ||
CPUData *cpus = this->cpuData; | ||
|
||
if (ccds == 0) { | ||
for (size_t i = 0; i < super->existingCPUs + 1; i++) { | ||
cpus[i].ccdID = -1; | ||
} | ||
return; | ||
} | ||
|
||
int coresPerCCD = super->existingCPUs / ccds; | ||
cgzones marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
int ccd = 0; | ||
int nc = coresPerCCD; | ||
for (int p = 0; p <= (int)this->maxPhysicalID; p++) { | ||
for (int c = 0; c <= (int)this->maxCoreID; c++) { | ||
for (size_t i = 1; i <= super->existingCPUs; i++) { | ||
if (cpus[i].physicalID != p || cpus[i].coreID != c) | ||
continue; | ||
|
||
cpus[i].ccdID = ccd; | ||
|
||
if (--nc == 0) { | ||
nc = coresPerCCD; | ||
ccd++; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
#endif | ||
|
||
static void LinuxMachine_scanCPUFrequency(LinuxMachine* this) { | ||
const Machine* super = &this->super; | ||
|
||
|
@@ -638,7 +732,11 @@ void Machine_scan(Machine* super) { | |
LinuxMachine_scanCPUTime(this); | ||
|
||
const Settings* settings = super->settings; | ||
if (settings->showCPUFrequency) | ||
if (settings->showCPUFrequency | ||
#ifdef HAVE_SENSORS_SENSORS_H | ||
|| settings->showCPUTemperature | ||
#endif | ||
) | ||
LinuxMachine_scanCPUFrequency(this); | ||
|
||
#ifdef HAVE_SENSORS_SENSORS_H | ||
|
@@ -687,6 +785,13 @@ Machine* Machine_new(UsersTable* usersTable, uid_t userId) { | |
// Initialize CPU count | ||
LinuxMachine_updateCPUcount(this); | ||
|
||
#ifdef HAVE_SENSORS_SENSORS_H | ||
// Fetch CPU topology | ||
LinuxMachine_fetchCPUTopologyFromCPUinfo(this); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know what this means, this code runs only once already? |
||
int ccds = LibSensors_countCCDs(); | ||
LinuxMachine_assignCCDs(this, ccds); | ||
#endif | ||
|
||
return super; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use the number from the label here, e.g.
Tccd5
? The features might not be sorted or even monotonically increasing by 1.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need a total count of CCD however, too...