Skip to content

Commit d515e2e

Browse files
tjk213Explorer09
andcommitted
optimize coreIndex enumeration
Co-authored-by: Kang-Che Sung (宋岡哲) <Explorer09@gmail.com>
1 parent 0724863 commit d515e2e

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

linux/LinuxMachine.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -739,13 +739,12 @@ static void LinuxMachine_computeThreadIndices(LinuxMachine* this) {
739739
because CoreIDs are not contiguous or because cpus are
740740
enumerated in an alternative order, or both. */
741741
for (size_t i = 1; i <= super->existingCPUs; i++) {
742-
int coreIndex = 0;
743-
for (size_t j = 1; j < i; j++) {
742+
for (size_t j = i - 1; j >= 1; j--) {
744743
if (cpus[i].threadIndex == cpus[j].threadIndex) {
745-
coreIndex++;
744+
cpus[i].coreIndex = cpus[j].coreIndex + 1;
745+
break;
746746
}
747747
}
748-
cpus[i].coreIndex = coreIndex;
749748
}
750749

751750
/* Set core & thread indices to zero for cpu0 (average) */

0 commit comments

Comments
 (0)