summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2021-02-17 17:38:35 +0100
committerBenny Baumann <BenBE@geshi.org>2021-03-19 23:30:54 +0100
commita11d01568c5e7bc5570fd48fa0703d837c4bcd84 (patch)
tree3e298e81123789ed6ae288e5bd32e91ebfb3ff01
parent53bcc5cbffbdd69e0e08bd33c5e357dd5b753456 (diff)
Use unsigned types for CPU counts and associated variables
-rw-r--r--Affinity.c14
-rw-r--r--Affinity.h8
-rw-r--r--AffinityPanel.c8
-rw-r--r--AvailableMetersPanel.c8
-rw-r--r--CPUMeter.c12
-rw-r--r--Header.c8
-rw-r--r--Header.h2
-rw-r--r--Meter.c4
-rw-r--r--Meter.h4
-rw-r--r--ProcessList.h10
-rw-r--r--Settings.c6
-rw-r--r--Settings.h2
-rw-r--r--darwin/DarwinProcessList.c2
-rw-r--r--darwin/Platform.c6
-rw-r--r--darwin/Platform.h2
-rw-r--r--dragonflybsd/DragonFlyBSDProcessList.c6
-rw-r--r--dragonflybsd/Platform.c4
-rw-r--r--dragonflybsd/Platform.h2
-rw-r--r--freebsd/FreeBSDProcessList.c10
-rw-r--r--freebsd/Platform.c4
-rw-r--r--freebsd/Platform.h2
-rw-r--r--linux/LinuxProcessList.c27
-rw-r--r--linux/Platform.c2
-rw-r--r--linux/Platform.h2
-rw-r--r--openbsd/OpenBSDProcessList.c4
-rw-r--r--openbsd/Platform.c2
-rw-r--r--openbsd/Platform.h2
-rw-r--r--solaris/Platform.c4
-rw-r--r--solaris/Platform.h2
-rw-r--r--solaris/SolarisProcessList.c4
-rw-r--r--unsupported/Platform.c2
-rw-r--r--unsupported/Platform.h2
32 files changed, 88 insertions, 89 deletions
diff --git a/Affinity.c b/Affinity.c
index 6b39b399..ee6eb519 100644
--- a/Affinity.c
+++ b/Affinity.c
@@ -30,7 +30,7 @@ in the source distribution for its full text.
Affinity* Affinity_new(ProcessList* pl) {
Affinity* this = xCalloc(1, sizeof(Affinity));
this->size = 8;
- this->cpus = xCalloc(this->size, sizeof(int));
+ this->cpus = xCalloc(this->size, sizeof(unsigned int));
this->pl = pl;
return this;
}
@@ -40,10 +40,10 @@ void Affinity_delete(Affinity* this) {
free(this);
}
-void Affinity_add(Affinity* this, int id) {
+void Affinity_add(Affinity* this, unsigned int id) {
if (this->used == this->size) {
this->size *= 2;
- this->cpus = xRealloc(this->cpus, sizeof(int) * this->size);
+ this->cpus = xRealloc(this->cpus, sizeof(unsigned int) * this->size);
}
this->cpus[this->used] = id;
this->used++;
@@ -59,7 +59,7 @@ Affinity* Affinity_get(const Process* proc, ProcessList* pl) {
if (ok) {
affinity = Affinity_new(pl);
if (hwloc_bitmap_last(cpuset) == -1) {
- for (int i = 0; i < pl->cpuCount; i++) {
+ for (unsigned int i = 0; i < pl->cpuCount; i++) {
Affinity_add(affinity, i);
}
} else {
@@ -76,7 +76,7 @@ Affinity* Affinity_get(const Process* proc, ProcessList* pl) {
bool Affinity_set(Process* proc, Arg arg) {
Affinity* this = arg.v;
hwloc_cpuset_t cpuset = hwloc_bitmap_alloc();
- for (int i = 0; i < this->used; i++) {
+ for (unsigned int i = 0; i < this->used; i++) {
hwloc_bitmap_set(cpuset, this->cpus[i]);
}
bool ok = (hwloc_set_proc_cpubind(this->pl->topology, proc->pid, cpuset, HTOP_HWLOC_CPUBIND_FLAG) == 0);
@@ -93,7 +93,7 @@ Affinity* Affinity_get(const Process* proc, ProcessList* pl) {
return NULL;
Affinity* affinity = Affinity_new(pl);
- for (int i = 0; i < pl->cpuCount; i++) {
+ for (unsigned int i = 0; i < pl->cpuCount; i++) {
if (CPU_ISSET(i, &cpuset)) {
Affinity_add(affinity, i);
}
@@ -105,7 +105,7 @@ bool Affinity_set(Process* proc, Arg arg) {
Affinity* this = arg.v;
cpu_set_t cpuset;
CPU_ZERO(&cpuset);
- for (int i = 0; i < this->used; i++) {
+ for (unsigned int i = 0; i < this->used; i++) {
CPU_SET(this->cpus[i], &cpuset);
}
bool ok = (sched_setaffinity(proc->pid, sizeof(unsigned long), &cpuset) == 0);
diff --git a/Affinity.h b/Affinity.h
index 980b15b5..d28e848b 100644
--- a/Affinity.h
+++ b/Affinity.h
@@ -27,16 +27,16 @@ in the source distribution for its full text.
typedef struct Affinity_ {
ProcessList* pl;
- int size;
- int used;
- int* cpus;
+ unsigned int size;
+ unsigned int used;
+ unsigned int* cpus;
} Affinity;
Affinity* Affinity_new(ProcessList* pl);
void Affinity_delete(Affinity* this);
-void Affinity_add(Affinity* this, int id);
+void Affinity_add(Affinity* this, unsigned int id);
#if defined(HAVE_LIBHWLOC) || defined(HAVE_LINUX_AFFINITY)
diff --git a/AffinityPanel.c b/AffinityPanel.c
index 57211050..25169994 100644
--- a/AffinityPanel.c
+++ b/AffinityPanel.c
@@ -382,8 +382,8 @@ Panel* AffinityPanel_new(ProcessList* pl, const Affinity* affinity, int* width)
Panel_setHeader(super, "Use CPUs:");
- int curCpu = 0;
- for (int i = 0; i < pl->cpuCount; i++) {
+ unsigned int curCpu = 0;
+ for (unsigned int i = 0; i < pl->cpuCount; i++) {
char number[16];
xSnprintf(number, 9, "CPU %d", Settings_cpuId(pl->settings, i));
unsigned cpu_width = 4 + strlen(number);
@@ -422,12 +422,12 @@ Affinity* AffinityPanel_getAffinity(Panel* super, ProcessList* pl) {
Affinity* affinity = Affinity_new(pl);
#ifdef HAVE_LIBHWLOC
- int i;
+ unsigned int i;
hwloc_bitmap_foreach_begin(i, this->workCpuset)
Affinity_add(affinity, i);
hwloc_bitmap_foreach_end();
#else
- for (int i = 0; i < this->pl->cpuCount; i++) {
+ for (unsigned int i = 0; i < this->pl->cpuCount; i++) {
const MaskItem* item = (const MaskItem*)Vector_get(this->cpuids, i);
if (item->value) {
Affinity_add(affinity, item->cpu);
diff --git a/AvailableMetersPanel.c b/AvailableMetersPanel.c
index 5e5af67c..cb67c7f3 100644
--- a/AvailableMetersPanel.c
+++ b/AvailableMetersPanel.c
@@ -30,7 +30,7 @@ static void AvailableMetersPanel_delete(Object* object) {
free(this);
}
-static inline void AvailableMetersPanel_addMeter(Header* header, Panel* panel, const MeterClass* type, int param, int column) {
+static inline void AvailableMetersPanel_addMeter(Header* header, Panel* panel, const MeterClass* type, unsigned int param, int column) {
const Meter* meter = Header_addMeterByClass(header, type, param, column);
Panel_add(panel, (Object*) Meter_toListItem(meter, false));
Panel_setSelected(panel, Panel_size(panel) - 1);
@@ -45,7 +45,7 @@ static HandlerResult AvailableMetersPanel_eventHandler(Panel* super, int ch) {
if (!selected)
return IGNORED;
- int param = selected->key & 0xff;
+ unsigned int param = selected->key & 0xff;
int type = selected->key >> 16;
HandlerResult result = IGNORED;
bool update = false;
@@ -114,10 +114,10 @@ AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Header* heade
}
// Handle (&CPUMeter_class)
const MeterClass* type = &CPUMeter_class;
- int cpus = pl->cpuCount;
+ unsigned int cpus = pl->cpuCount;
if (cpus > 1) {
Panel_add(super, (Object*) ListItem_new("CPU average", 0));
- for (int i = 1; i <= cpus; i++) {
+ for (unsigned int i = 1; i <= cpus; i++) {
char buffer[50];
xSnprintf(buffer, sizeof(buffer), "%s %d", type->uiName, Settings_cpuId(this->settings, i - 1));
Panel_add(super, (Object*) ListItem_new(buffer, i));
diff --git a/CPUMeter.c b/CPUMeter.c
index 96da87e1..47437cc7 100644
--- a/CPUMeter.c
+++ b/CPUMeter.c
@@ -35,23 +35,23 @@ static const int CPUMeter_attributes[] = {
};
typedef struct CPUMeterData_ {
- int cpus;
+ unsigned int cpus;
Meter** meters;
} CPUMeterData;
static void CPUMeter_init(Meter* this) {
- int cpu = this->param;
+ unsigned int cpu = this->param;
if (cpu == 0) {
Meter_setCaption(this, "Avg");
} else if (this->pl->cpuCount > 1) {
char caption[10];
- xSnprintf(caption, sizeof(caption), "%3d", Settings_cpuId(this->pl->settings, cpu - 1));
+ xSnprintf(caption, sizeof(caption), "%3u", Settings_cpuId(this->pl->settings, cpu - 1));
Meter_setCaption(this, caption);
}
}
static void CPUMeter_updateValues(Meter* this) {
- int cpu = this->param;
+ unsigned int cpu = this->param;
if (cpu > this->pl->cpuCount) {
xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "absent");
for (uint8_t i = 0; i < this->curItems; i++)
@@ -168,7 +168,7 @@ static void CPUMeter_display(const Object* cast, RichString* out) {
static void AllCPUsMeter_getRange(const Meter* this, int* start, int* count) {
const CPUMeterData* data = this->meterData;
- int cpus = data->cpus;
+ unsigned int cpus = data->cpus;
switch(Meter_name(this)[0]) {
default:
case 'A': // All
@@ -196,7 +196,7 @@ static void AllCPUsMeter_updateValues(Meter* this) {
}
static void CPUMeterCommonInit(Meter* this, int ncol) {
- int cpus = this->pl->cpuCount;
+ unsigned int cpus = this->pl->cpuCount;
CPUMeterData* data = this->meterData;
if (!data) {
data = this->meterData = xMalloc(sizeof(CPUMeterData));
diff --git a/Header.c b/Header.c
index 85b0c281..d2d7f694 100644
--- a/Header.c
+++ b/Header.c
@@ -71,7 +71,7 @@ void Header_writeBackToSettings(const Header* this) {
const Meter* meter = (Meter*) Vector_get(vec, i);
char* name;
if (meter->param) {
- xAsprintf(&name, "%s(%d)", As_Meter(meter)->name, meter->param);
+ xAsprintf(&name, "%s(%u)", As_Meter(meter)->name, meter->param);
} else {
xAsprintf(&name, "%s", As_Meter(meter)->name);
}
@@ -85,9 +85,9 @@ MeterModeId Header_addMeterByName(Header* this, const char* name, int column) {
Vector* meters = this->columns[column];
char* paren = strchr(name, '(');
- int param = 0;
+ unsigned int param = 0;
if (paren) {
- int ok = sscanf(paren, "(%10d)", &param);
+ int ok = sscanf(paren, "(%10u)", &param);
if (!ok)
param = 0;
*paren = '\0';
@@ -118,7 +118,7 @@ void Header_setMode(Header* this, int i, MeterModeId mode, int column) {
Meter_setMode(meter, mode);
}
-Meter* Header_addMeterByClass(Header* this, const MeterClass* type, int param, int column) {
+Meter* Header_addMeterByClass(Header* this, const MeterClass* type, unsigned int param, int column) {
Vector* meters = this->columns[column];
Meter* meter = Meter_new(this->pl, param, type);
diff --git a/Header.h b/Header.h
index 02131f1f..6d13fc47 100644
--- a/Header.h
+++ b/Header.h
@@ -35,7 +35,7 @@ MeterModeId Header_addMeterByName(Header* this, const char* name, int column);
void Header_setMode(Header* this, int i, MeterModeId mode, int column);
-Meter* Header_addMeterByClass(Header* this, const MeterClass* type, int param, int column);
+Meter* Header_addMeterByClass(Header* this, const MeterClass* type, unsigned int param, int column);
int Header_size(const Header* this, int column);
diff --git a/Meter.c b/Meter.c
index 35927ed2..c964c158 100644
--- a/Meter.c
+++ b/Meter.c
@@ -32,7 +32,7 @@ const MeterClass Meter_class = {
}
};
-Meter* Meter_new(const struct ProcessList_* pl, int param, const MeterClass* type) {
+Meter* Meter_new(const struct ProcessList_* pl, unsigned int param, const MeterClass* type) {
Meter* this = xCalloc(1, sizeof(Meter));
Object_setClass(this, type);
this->h = 1;
@@ -140,7 +140,7 @@ ListItem* Meter_toListItem(const Meter* this, bool moving) {
}
char number[10];
if (this->param > 0) {
- xSnprintf(number, sizeof(number), " %d", this->param);
+ xSnprintf(number, sizeof(number), " %u", this->param);
} else {
number[0] = '\0';
}
diff --git a/Meter.h b/Meter.h
index ad30f3b1..ff691286 100644
--- a/Meter.h
+++ b/Meter.h
@@ -95,7 +95,7 @@ struct Meter_ {
char* caption;
int mode;
- int param;
+ unsigned int param;
GraphData* drawData;
int h;
int columnWidthCount; /*<< only used internally by the Header */
@@ -125,7 +125,7 @@ typedef enum {
extern const MeterClass Meter_class;
-Meter* Meter_new(const ProcessList* pl, int param, const MeterClass* type);
+Meter* Meter_new(const ProcessList* pl, unsigned int param, const MeterClass* type);
int Meter_humanUnit(char* buffer, unsigned long int value, size_t size);
diff --git a/ProcessList.h b/ProcessList.h
index d4fd1f60..bfbe0ab3 100644
--- a/ProcessList.h
+++ b/ProcessList.h
@@ -59,10 +59,10 @@ typedef struct ProcessList_ {
bool topologyOk;
#endif
- int totalTasks;
- int runningTasks;
- int userlandThreads;
- int kernelThreads;
+ unsigned int totalTasks;
+ unsigned int runningTasks;
+ unsigned int userlandThreads;
+ unsigned int kernelThreads;
memory_t totalMem;
memory_t usedMem;
@@ -75,7 +75,7 @@ typedef struct ProcessList_ {
memory_t usedSwap;
memory_t cachedSwap;
- int cpuCount;
+ unsigned int cpuCount;
time_t scanTs;
} ProcessList;
diff --git a/Settings.c b/Settings.c
index 3880bb16..8baad6a7 100644
--- a/Settings.c
+++ b/Settings.c
@@ -54,7 +54,7 @@ static void Settings_readMeterModes(Settings* this, const char* line, int column
this->columns[column].modes = modes;
}
-static void Settings_defaultMeters(Settings* this, int initialCpuCount) {
+static void Settings_defaultMeters(Settings* this, unsigned int initialCpuCount) {
int sizes[] = { 3, 3 };
if (initialCpuCount > 4 && initialCpuCount <= 128) {
sizes[1]++;
@@ -125,7 +125,7 @@ static void readFields(ProcessField* fields, uint32_t* flags, const char* line)
String_freeArray(ids);
}
-static bool Settings_read(Settings* this, const char* fileName, int initialCpuCount) {
+static bool Settings_read(Settings* this, const char* fileName, unsigned int initialCpuCount) {
FILE* fd = fopen(fileName, "r");
if (!fd)
return false;
@@ -344,7 +344,7 @@ int Settings_write(const Settings* this) {
return r;
}
-Settings* Settings_new(int initialCpuCount) {
+Settings* Settings_new(unsigned int initialCpuCount) {
Settings* this = xCalloc(1, sizeof(Settings));
this->sortKey = PERCENT_CPU;
diff --git a/Settings.h b/Settings.h
index 3e7abdee..f10b3055 100644
--- a/Settings.h
+++ b/Settings.h
@@ -89,7 +89,7 @@ void Settings_delete(Settings* this);
int Settings_write(const Settings* this);
-Settings* Settings_new(int initialCpuCount);
+Settings* Settings_new(unsigned int initialCpuCount);
void Settings_invertSortOrder(Settings* this);
diff --git a/darwin/DarwinProcessList.c b/darwin/DarwinProcessList.c
index 8bb2651a..27601f02 100644
--- a/darwin/DarwinProcessList.c
+++ b/darwin/DarwinProcessList.c
@@ -184,7 +184,7 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) {
/* Get the time difference */
dpl->global_diff = 0;
- for (int i = 0; i < dpl->super.cpuCount; ++i) {
+ for (unsigned int i = 0; i < dpl->super.cpuCount; ++i) {
for (size_t j = 0; j < CPU_STATE_MAX; ++j) {
dpl->global_diff += dpl->curr_load[i].cpu_ticks[j] - dpl->prev_load[i].cpu_ticks[j];
}
diff --git a/darwin/Platform.c b/darwin/Platform.c
index 932b1832..3842fddc 100644
--- a/darwin/Platform.c
+++ b/darwin/Platform.c
@@ -182,12 +182,12 @@ int Platform_getMaxPid() {
static double Platform_setCPUAverageValues(Meter* mtr) {
const ProcessList* dpl = mtr->pl;
- int cpus = dpl->cpuCount;
+ unsigned int cpus = dpl->cpuCount;
double sumNice = 0.0;
double sumNormal = 0.0;
double sumKernel = 0.0;
double sumPercent = 0.0;
- for (int i = 1; i <= cpus; i++) {
+ for (unsigned int i = 1; i <= cpus; i++) {
sumPercent += Platform_setCPUValues(mtr, i);
sumNice += mtr->values[CPU_METER_NICE];
sumNormal += mtr->values[CPU_METER_NORMAL];
@@ -199,7 +199,7 @@ static double Platform_setCPUAverageValues(Meter* mtr) {
return sumPercent / cpus;
}
-double Platform_setCPUValues(Meter* mtr, int cpu) {
+double Platform_setCPUValues(Meter* mtr, unsigned int cpu) {
if (cpu == 0) {
return Platform_setCPUAverageValues(mtr);
diff --git a/darwin/Platform.h b/darwin/Platform.h
index 83a9b651..4b2e75f4 100644
--- a/darwin/Platform.h
+++ b/darwin/Platform.h
@@ -47,7 +47,7 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen);
int Platform_getMaxPid(void);
-double Platform_setCPUValues(Meter* mtr, int cpu);
+double Platform_setCPUValues(Meter* mtr, unsigned int cpu);
void Platform_setMemoryValues(Meter* mtr);
diff --git a/dragonflybsd/DragonFlyBSDProcessList.c b/dragonflybsd/DragonFlyBSDProcessList.c
index 976dbea0..79c8f886 100644
--- a/dragonflybsd/DragonFlyBSDProcessList.c
+++ b/dragonflybsd/DragonFlyBSDProcessList.c
@@ -139,8 +139,8 @@ void ProcessList_delete(ProcessList* this) {
static inline void DragonFlyBSDProcessList_scanCPUTime(ProcessList* pl) {
const DragonFlyBSDProcessList* dfpl = (DragonFlyBSDProcessList*) pl;
- int cpus = pl->cpuCount; // actual CPU count
- int maxcpu = cpus; // max iteration (in case we have average + smp)
+ unsigned int cpus = pl->cpuCount; // actual CPU count
+ unsigned int maxcpu = cpus; // max iteration (in case we have average + smp)
int cp_times_offset;
assert(cpus > 0);
@@ -167,7 +167,7 @@ static inline void DragonFlyBSDProcessList_scanCPUTime(ProcessList* pl) {
sysctl(MIB_kern_cp_times, 2, dfpl->cp_times_n, &sizeof_cp_time_array, NULL, 0);
}
- for (int i = 0; i < maxcpu; i++) {
+ for (unsigned int i = 0; i < maxcpu; i++) {
if (cpus == 1) {
// single CPU box
cp_time_n = dfpl->cp_time_n;
diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c
index 1bbbf2c4..14fbbf0f 100644
--- a/dragonflybsd/Platform.c
+++ b/dragonflybsd/Platform.c
@@ -157,9 +157,9 @@ int Platform_getMaxPid() {
return maxPid;
}
-double Platform_setCPUValues(Meter* this, int cpu) {
+double Platform_setCPUValues(Meter* this, unsigned int cpu) {
const DragonFlyBSDProcessList* fpl = (const DragonFlyBSDProcessList*) this->pl;
- int cpus = this->pl->cpuCount;
+ unsigned int cpus = this->pl->cpuCount;
const CPUData* cpuData;
if (cpus == 1) {
diff --git a/dragonflybsd/Platform.h b/dragonflybsd/Platform.h
index 4defaaf8..2cac44df 100644
--- a/dragonflybsd/Platform.h
+++ b/dragonflybsd/Platform.h
@@ -41,7 +41,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);
diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c
index 87f2e4d5..628956d1 100644
--- a/freebsd/FreeBSDProcessList.c
+++ b/freebsd/FreeBSDProcessList.c
@@ -175,8 +175,8 @@ void ProcessList_delete(ProcessList* this) {
static inline void FreeBSDProcessList_scanCPU(ProcessList* pl) {
const FreeBSDProcessList* fpl = (FreeBSDProcessList*) pl;
- int cpus = pl->cpuCount; // actual CPU count
- int maxcpu = cpus; // max iteration (in case we have average + smp)
+ unsigned int cpus = pl->cpuCount; // actual CPU count
+ unsigned int maxcpu = cpus; // max iteration (in case we have average + smp)
int cp_times_offset;
assert(cpus > 0);
@@ -203,7 +203,7 @@ static inline void FreeBSDProcessList_scanCPU(ProcessList* pl) {
sysctl(MIB_kern_cp_times, 2, fpl->cp_times_n, &sizeof_cp_time_array, NULL, 0);
}
- for (int i = 0; i < maxcpu; i++) {
+ for (unsigned int i = 0; i < maxcpu; i++) {
if (cpus == 1) {
// single CPU box
cp_time_n = fpl->cp_time_n;
@@ -287,7 +287,7 @@ static inline void FreeBSDProcessList_scanCPU(ProcessList* pl) {
if (cpus > 1) {
if (pl->settings->showCPUTemperature) {
double maxTemp = NAN;
- for (int i = 1; i < maxcpu; i++) {
+ for (unsigned int i = 1; i < maxcpu; i++) {
const double coreTemp = fpl->cpus[i].temperature;
if (isnan(coreTemp))
continue;
@@ -302,7 +302,7 @@ static inline void FreeBSDProcessList_scanCPU(ProcessList* pl) {
const double coreZeroFreq = fpl->cpus[1].frequency;
double freqSum = coreZeroFreq;
if (!isnan(coreZeroFreq)) {
- for (int i = 2; i < maxcpu; i++) {
+ for (unsigned int i = 2; i < maxcpu; i++) {
if (isnan(fpl->cpus[i].frequency))
fpl->cpus[i].frequency = coreZeroFreq;
diff --git a/freebsd/Platform.c b/freebsd/Platform.c
index 453703c3..1ca080d0 100644
--- a/freebsd/Platform.c
+++ b/freebsd/Platform.c
@@ -179,9 +179,9 @@ int Platform_getMaxPid() {
return maxPid;
}
-double Platform_setCPUValues(Meter* this, int cpu) {
+double Platform_setCPUValues(Meter* this, unsigned int cpu) {
const FreeBSDProcessList* fpl = (const FreeBSDProcessList*) this->pl;
- int cpus = this->pl->cpuCount;
+ unsigned int cpus = this->pl->cpuCount;
const CPUData* cpuData;
if (cpus == 1) {
diff --git a/freebsd/Platform.h b/freebsd/Platform.h
index ab5c63cf..850fb75b 100644
--- a/freebsd/Platform.h
+++ b/freebsd/Platform.h
@@ -42,7 +42,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);
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);
diff --git a/openbsd/OpenBSDProcessList.c b/openbsd/OpenBSDProcessList.c
index ff5c9278..0a0c0a5f 100644
--- a/openbsd/OpenBSDProcessList.c
+++ b/openbsd/OpenBSDProcessList.c
@@ -63,7 +63,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui
CRT_fatalError("pagesize sysconf call failed");
pageSizeKB = pageSize / ONE_K;
- for (int i = 0; i <= pl->cpuCount; i++) {
+ for (unsigned int i = 0; i <= pl->cpuCount; i++) {
CPUData* d = opl->cpus + i;
d->totalTime = 1;
d->totalPeriod = 1;
@@ -313,7 +313,7 @@ static void OpenBSDProcessList_scanCPUTime(OpenBSDProcessList* this) {
u_int64_t kernelTimes[CPUSTATES] = {0};
u_int64_t avg[CPUSTATES] = {0};
- for (int i = 0; i < this->super.cpuCount; i++) {
+ for (unsigned int i = 0; i < this->super.cpuCount; i++) {
getKernelCPUTimes(i, kernelTimes);
CPUData* cpu = this->cpus + i + 1;
kernelCPUTimesToHtop(kernelTimes, cpu);
diff --git a/openbsd/Platform.c b/openbsd/Platform.c
index c57e6cc3..fee4b71b 100644
--- a/openbsd/Platform.c
+++ b/openbsd/Platform.c
@@ -166,7 +166,7 @@ int Platform_getMaxPid() {
return 99999;
}
-double Platform_setCPUValues(Meter* this, int cpu) {
+double Platform_setCPUValues(Meter* this, unsigned int cpu) {
const OpenBSDProcessList* pl = (const OpenBSDProcessList*) this->pl;
const CPUData* cpuData = &(pl->cpus[cpu]);
double total = cpuData->totalPeriod == 0 ? 1 : cpuData->totalPeriod;
diff --git a/openbsd/Platform.h b/openbsd/Platform.h
index bdd44a50..211b92f3 100644
--- a/openbsd/Platform.h
+++ b/openbsd/Platform.h
@@ -44,7 +44,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);
diff --git a/solaris/Platform.c b/solaris/Platform.c
index aa000e29..cadf092c 100644
--- a/solaris/Platform.c
+++ b/solaris/Platform.c
@@ -177,9 +177,9 @@ int Platform_getMaxPid() {
return vproc;
}
-double Platform_setCPUValues(Meter* this, int cpu) {
+double Platform_setCPUValues(Meter* this, unsigned int cpu) {
const SolarisProcessList* spl = (const SolarisProcessList*) this->pl;
- int cpus = this->pl->cpuCount;
+ unsigned int cpus = this->pl->cpuCount;
const CPUData* cpuData = NULL;
if (cpus == 1) {
diff --git a/solaris/Platform.h b/solaris/Platform.h
index bacadf07..8d08ad99 100644
--- a/solaris/Platform.h
+++ b/solaris/Platform.h
@@ -59,7 +59,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);
diff --git a/solaris/SolarisProcessList.c b/solaris/SolarisProcessList.c
index 1f24c9ab..5223addf 100644
--- a/solaris/SolarisProcessList.c
+++ b/solaris/SolarisProcessList.c
@@ -69,7 +69,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui
static inline void SolarisProcessList_scanCPUTime(ProcessList* pl) {
const SolarisProcessList* spl = (SolarisProcessList*) pl;
- int cpus = pl->cpuCount;
+ unsigned int cpus = pl->cpuCount;
kstat_t* cpuinfo = NULL;
kstat_named_t* idletime = NULL;
kstat_named_t* intrtime = NULL;
@@ -91,7 +91,7 @@ static inline void SolarisProcessList_scanCPUTime(ProcessList* pl) {
}
// Calculate per-CPU statistics first
- for (int i = 0; i < cpus; i++) {
+ for (unsigned int i = 0; i < cpus; i++) {
if (spl->kd != NULL) {
if ((cpuinfo = kstat_lookup(spl->kd, "cpu", i, "sys")) != NULL) {
if (kstat_read(spl->kd, cpuinfo, NULL) != -1) {
diff --git a/unsupported/Platform.c b/unsupported/Platform.c
index 9dc457b7..bdbc762e 100644
--- a/unsupported/Platform.c
+++ b/unsupported/Platform.c
@@ -93,7 +93,7 @@ int Platform_getMaxPid() {
return 1;
}
-double Platform_setCPUValues(Meter* this, int cpu) {
+double Platform_setCPUValues(Meter* this, unsigned int cpu) {
(void) cpu;
double* v = this->values;
diff --git a/unsupported/Platform.h b/unsupported/Platform.h
index 837daca4..9b89eb89 100644
--- a/unsupported/Platform.h
+++ b/unsupported/Platform.h
@@ -37,7 +37,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);

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