Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions linux/LinuxMachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,26 @@ static void LinuxMachine_computeThreadIndices(LinuxMachine* this) {
}
cpus[i].threadIndex = threadIndex;
}

/* Now compute a normalized physical core index for each CPU.
On many systems, this index will match the following:
physicalID*(maxPhysicalID+1)+coreID
But there are some systems where this is not true, either
because CoreIDs are not contiguous or because cpus are
enumerated in an alternative order, or both. */
for (size_t i = 1; i <= super->existingCPUs; i++) {
Comment thread
tjk213 marked this conversation as resolved.
cpus[i].coreIndex = 0;
for (size_t j = i - 1; j >= 1; j--) {
Comment thread
tjk213 marked this conversation as resolved.
if (cpus[i].threadIndex == cpus[j].threadIndex) {
cpus[i].coreIndex = cpus[j].coreIndex + 1;
break;
}
}
}

/* Set core & thread indices to zero for cpu0 (average) */
cpus[0].coreIndex = 0;
cpus[0].threadIndex = 0;
}

static void LinuxMachine_scanCPUFrequency(LinuxMachine* this) {
Expand Down Expand Up @@ -850,9 +870,7 @@ int Machine_getCPUPhysicalCoreID(const Machine* super, unsigned int id) {
const LinuxMachine* this = (const LinuxMachine*) super;

assert(id < super->existingCPUs);

const CPUData* cpu = &this->cpuData[id + 1];
return cpu->physicalID * (this->maxCoreID + 1) + cpu->coreID;
return this->cpuData[id + 1].coreIndex;
}

int Machine_getCPUThreadIndex(const Machine* super, unsigned int id) {
Expand Down
1 change: 1 addition & 0 deletions linux/LinuxMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ typedef struct CPUData_ {
int physicalID; /* different for each CPU socket */
int coreID; /* same for hyperthreading */
int ccdID; /* same for each AMD chiplet */
int coreIndex; /* Normalized physical core ID */
int threadIndex; /* SMT thread index: 0 for first thread, 1 for second, etc. */

bool online;
Expand Down
Loading