diff options
author | Christian Göttsche <cgzones@googlemail.com> | 2021-02-17 17:38:35 +0100 |
---|---|---|
committer | Benny Baumann <BenBE@geshi.org> | 2021-03-19 23:30:54 +0100 |
commit | a11d01568c5e7bc5570fd48fa0703d837c4bcd84 (patch) | |
tree | 3e298e81123789ed6ae288e5bd32e91ebfb3ff01 /linux | |
parent | 53bcc5cbffbdd69e0e08bd33c5e357dd5b753456 (diff) |
Use unsigned types for CPU counts and associated variables
Diffstat (limited to 'linux')
-rw-r--r-- | linux/LinuxProcessList.c | 27 | ||||
-rw-r--r-- | linux/Platform.c | 2 | ||||
-rw-r--r-- | linux/Platform.h | 2 |
3 files changed, 15 insertions, 16 deletions
diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 2225c713..7df17fd9 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -166,7 +166,7 @@ static void LinuxProcessList_initNetlinkSocket(LinuxProcessList* this) { static void LinuxProcessList_updateCPUcount(ProcessList* super, FILE* stream) { LinuxProcessList* this = (LinuxProcessList*) super; - int cpus = 0; + unsigned int cpus = 0; char buffer[PROC_LINE_LENGTH + 1]; while (fgets(buffer, sizeof(buffer), stream)) { if (String_startsWith(buffer, "cpu")) { @@ -1269,7 +1269,7 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, openat_arg_ return false; } - int cpus = pl->cpuCount; + unsigned int cpus = pl->cpuCount; bool hideKernelThreads = settings->hideKernelThreads; bool hideUserlandThreads = settings->hideUserlandThreads; while ((entry = readdir(dir)) != NULL) { @@ -1765,8 +1765,8 @@ static inline double LinuxProcessList_scanCPUTime(ProcessList* super) { rewind(file); - int cpus = super->cpuCount; - for (int i = 0; i <= cpus; i++) { + unsigned int cpus = super->cpuCount; + for (unsigned int i = 0; i <= cpus; i++) { char buffer[PROC_LINE_LENGTH + 1]; unsigned long long int usertime, nicetime, systemtime, idletime; unsigned long long int ioWait = 0, irq = 0, softIrq = 0, steal = 0, guest = 0, guestnice = 0; @@ -1780,8 +1780,8 @@ static inline double LinuxProcessList_scanCPUTime(ProcessList* super) { if (i == 0) { (void) sscanf(buffer, "cpu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu", &usertime, &nicetime, &systemtime, &idletime, &ioWait, &irq, &softIrq, &steal, &guest, &guestnice); } else { - int cpuid; - (void) sscanf(buffer, "cpu%4d %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu", &cpuid, &usertime, &nicetime, &systemtime, &idletime, &ioWait, &irq, &softIrq, &steal, &guest, &guestnice); + unsigned int cpuid; + (void) sscanf(buffer, "cpu%4u %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu", &cpuid, &usertime, &nicetime, &systemtime, &idletime, &ioWait, &irq, &softIrq, &steal, &guest, &guestnice); assert(cpuid == i - 1); } // Guest time is already accounted in usertime @@ -1841,7 +1841,7 @@ static inline double LinuxProcessList_scanCPUTime(ProcessList* super) { } static int scanCPUFreqencyFromSysCPUFreq(LinuxProcessList* this) { - int cpus = this->super.cpuCount; + unsigned int cpus = this->super.cpuCount; int numCPUsWithFrequency = 0; unsigned long totalFrequency = 0; @@ -1859,9 +1859,9 @@ static int scanCPUFreqencyFromSysCPUFreq(LinuxProcessList* this) { return -1; } - for (int i = 0; i < cpus; ++i) { + for (unsigned int i = 0; i < cpus; ++i) { char pathBuffer[64]; - xSnprintf(pathBuffer, sizeof(pathBuffer), "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq", i); + xSnprintf(pathBuffer, sizeof(pathBuffer), "/sys/devices/system/cpu/cpu%u/cpufreq/scaling_cur_freq", i); struct timespec start; if (i == 0) @@ -1905,7 +1905,7 @@ static void scanCPUFreqencyFromCPUinfo(LinuxProcessList* this) { if (file == NULL) return; - int cpus = this->super.cpuCount; + unsigned int cpus = this->super.cpuCount; int numCPUsWithFrequency = 0; double totalFrequency = 0; int cpuid = -1; @@ -1928,7 +1928,7 @@ static void scanCPUFreqencyFromCPUinfo(LinuxProcessList* this) { (sscanf(buffer, "clock : %lfMHz", &frequency) == 1) || (sscanf(buffer, "clock: %lfMHz", &frequency) == 1) ) { - if (cpuid < 0 || cpuid > (cpus - 1)) { + if (cpuid < 0 || (unsigned int)cpuid > (cpus - 1)) { continue; } @@ -1951,10 +1951,9 @@ static void scanCPUFreqencyFromCPUinfo(LinuxProcessList* this) { } static void LinuxProcessList_scanCPUFrequency(LinuxProcessList* this) { - int cpus = this->super.cpuCount; - assert(cpus > 0); + unsigned int cpus = this->super.cpuCount; - for (int i = 0; i <= cpus; i++) { + for (unsigned int i = 0; i <= cpus; i++) { this->cpus[i].frequency = NAN; } diff --git a/linux/Platform.c b/linux/Platform.c index 1655c7df..b0eaf113 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -236,7 +236,7 @@ int Platform_getMaxPid() { return maxPid; } -double Platform_setCPUValues(Meter* this, int cpu) { +double Platform_setCPUValues(Meter* this, unsigned int cpu) { const LinuxProcessList* pl = (const LinuxProcessList*) this->pl; const CPUData* cpuData = &(pl->cpus[cpu]); double total = (double) ( cpuData->totalPeriod == 0 ? 1 : cpuData->totalPeriod); diff --git a/linux/Platform.h b/linux/Platform.h index 299d261a..fbf8be36 100644 --- a/linux/Platform.h +++ b/linux/Platform.h @@ -48,7 +48,7 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen); int Platform_getMaxPid(void); -double Platform_setCPUValues(Meter* this, int cpu); +double Platform_setCPUValues(Meter* this, unsigned int cpu); void Platform_setMemoryValues(Meter* this); |