summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Rys <martin@rys.pw>2024-01-30 23:05:13 +0100
committercgzones <cgzones@googlemail.com>2024-03-27 21:06:23 +0100
commit240dd4ab50e1a753905c711f99c57408e18d08a3 (patch)
tree0581f77d9ddc3c3e6e43777698b5f2cd3a0fe806
parent3016a5f28b72f98c81f566d21794cc354d083d4d (diff)
Linux: Correctly mark trailing offline CPU threads
-rw-r--r--linux/LinuxMachine.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/linux/LinuxMachine.c b/linux/LinuxMachine.c
index 626ca97f..c636be15 100644
--- a/linux/LinuxMachine.c
+++ b/linux/LinuxMachine.c
@@ -408,7 +408,9 @@ static void LinuxMachine_scanCPUTime(LinuxMachine* this) {
if (!file)
CRT_fatalError("Cannot open " PROCSTATFILE);
- unsigned int lastAdjCpuId = 0;
+ // Add an extra phantom thread for a later loop
+ bool adjCpuIdProcessed[super->existingCPUs+2];
+ memset(adjCpuIdProcessed, 0, sizeof(adjCpuIdProcessed));
for (unsigned int i = 0; i <= super->existingCPUs; i++) {
char buffer[PROC_LINE_LENGTH + 1];
@@ -439,12 +441,6 @@ static void LinuxMachine_scanCPUTime(LinuxMachine* this) {
if (adjCpuId > super->existingCPUs)
break;
- for (unsigned int j = lastAdjCpuId + 1; j < adjCpuId; j++) {
- // Skipped an ID, but /proc/stat is ordered => got offline CPU
- memset(&(this->cpuData[j]), '\0', sizeof(CPUData));
- }
- lastAdjCpuId = adjCpuId;
-
// Guest time is already accounted in usertime
usertime -= guest;
nicetime -= guestnice;
@@ -482,6 +478,21 @@ static void LinuxMachine_scanCPUTime(LinuxMachine* this) {
cpuData->stealTime = steal;
cpuData->guestTime = virtalltime;
cpuData->totalTime = totaltime;
+
+ adjCpuIdProcessed[adjCpuId] = true;
+ }
+
+ // Set the extra phantom thread as checked to make sure to mark trailing offline threads correctly in the loop
+ adjCpuIdProcessed[super->existingCPUs+1] = true;
+ unsigned int lastAdjCpuIdProcessed = 0;
+ for (unsigned int i = 0; i <= super->existingCPUs+1; i++) {
+ if (adjCpuIdProcessed[i]) {
+ for (unsigned int j = lastAdjCpuIdProcessed+1; j < i; j++) {
+ // Skipped an ID, but /proc/stat is ordered => threads in between are offline
+ memset(&(this->cpuData[j]), '\0', sizeof(CPUData));
+ }
+ lastAdjCpuIdProcessed = i;
+ }
}
this->period = (double)this->cpuData[0].totalPeriod / super->activeCPUs;

© 2014-2024 Faster IT GmbH | imprint | privacy policy