Merge branch 'cpu_proc_stat' of cgzones/htop

This commit is contained in:
Daniel Lange 2021-03-21 17:48:02 +01:00
commit 63019065dc
32 changed files with 88 additions and 89 deletions

View File

@ -30,7 +30,7 @@ in the source distribution for its full text.
Affinity* Affinity_new(ProcessList* pl) { Affinity* Affinity_new(ProcessList* pl) {
Affinity* this = xCalloc(1, sizeof(Affinity)); Affinity* this = xCalloc(1, sizeof(Affinity));
this->size = 8; this->size = 8;
this->cpus = xCalloc(this->size, sizeof(int)); this->cpus = xCalloc(this->size, sizeof(unsigned int));
this->pl = pl; this->pl = pl;
return this; return this;
} }
@ -40,10 +40,10 @@ void Affinity_delete(Affinity* this) {
free(this); free(this);
} }
void Affinity_add(Affinity* this, int id) { void Affinity_add(Affinity* this, unsigned int id) {
if (this->used == this->size) { if (this->used == this->size) {
this->size *= 2; 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->cpus[this->used] = id;
this->used++; this->used++;
@ -59,7 +59,7 @@ Affinity* Affinity_get(const Process* proc, ProcessList* pl) {
if (ok) { if (ok) {
affinity = Affinity_new(pl); affinity = Affinity_new(pl);
if (hwloc_bitmap_last(cpuset) == -1) { 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); Affinity_add(affinity, i);
} }
} else { } else {
@ -76,7 +76,7 @@ Affinity* Affinity_get(const Process* proc, ProcessList* pl) {
bool Affinity_set(Process* proc, Arg arg) { bool Affinity_set(Process* proc, Arg arg) {
Affinity* this = arg.v; Affinity* this = arg.v;
hwloc_cpuset_t cpuset = hwloc_bitmap_alloc(); 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]); hwloc_bitmap_set(cpuset, this->cpus[i]);
} }
bool ok = (hwloc_set_proc_cpubind(this->pl->topology, proc->pid, cpuset, HTOP_HWLOC_CPUBIND_FLAG) == 0); 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; return NULL;
Affinity* affinity = Affinity_new(pl); 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)) { if (CPU_ISSET(i, &cpuset)) {
Affinity_add(affinity, i); Affinity_add(affinity, i);
} }
@ -105,7 +105,7 @@ bool Affinity_set(Process* proc, Arg arg) {
Affinity* this = arg.v; Affinity* this = arg.v;
cpu_set_t cpuset; cpu_set_t cpuset;
CPU_ZERO(&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); CPU_SET(this->cpus[i], &cpuset);
} }
bool ok = (sched_setaffinity(proc->pid, sizeof(unsigned long), &cpuset) == 0); bool ok = (sched_setaffinity(proc->pid, sizeof(unsigned long), &cpuset) == 0);

View File

@ -27,16 +27,16 @@ in the source distribution for its full text.
typedef struct Affinity_ { typedef struct Affinity_ {
ProcessList* pl; ProcessList* pl;
int size; unsigned int size;
int used; unsigned int used;
int* cpus; unsigned int* cpus;
} Affinity; } Affinity;
Affinity* Affinity_new(ProcessList* pl); Affinity* Affinity_new(ProcessList* pl);
void Affinity_delete(Affinity* this); 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) #if defined(HAVE_LIBHWLOC) || defined(HAVE_LINUX_AFFINITY)

View File

@ -382,8 +382,8 @@ Panel* AffinityPanel_new(ProcessList* pl, const Affinity* affinity, int* width)
Panel_setHeader(super, "Use CPUs:"); Panel_setHeader(super, "Use CPUs:");
int curCpu = 0; unsigned int curCpu = 0;
for (int i = 0; i < pl->cpuCount; i++) { for (unsigned int i = 0; i < pl->cpuCount; i++) {
char number[16]; char number[16];
xSnprintf(number, 9, "CPU %d", Settings_cpuId(pl->settings, i)); xSnprintf(number, 9, "CPU %d", Settings_cpuId(pl->settings, i));
unsigned cpu_width = 4 + strlen(number); unsigned cpu_width = 4 + strlen(number);
@ -422,12 +422,12 @@ Affinity* AffinityPanel_getAffinity(Panel* super, ProcessList* pl) {
Affinity* affinity = Affinity_new(pl); Affinity* affinity = Affinity_new(pl);
#ifdef HAVE_LIBHWLOC #ifdef HAVE_LIBHWLOC
int i; unsigned int i;
hwloc_bitmap_foreach_begin(i, this->workCpuset) hwloc_bitmap_foreach_begin(i, this->workCpuset)
Affinity_add(affinity, i); Affinity_add(affinity, i);
hwloc_bitmap_foreach_end(); hwloc_bitmap_foreach_end();
#else #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); const MaskItem* item = (const MaskItem*)Vector_get(this->cpuids, i);
if (item->value) { if (item->value) {
Affinity_add(affinity, item->cpu); Affinity_add(affinity, item->cpu);

View File

@ -30,7 +30,7 @@ static void AvailableMetersPanel_delete(Object* object) {
free(this); 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); const Meter* meter = Header_addMeterByClass(header, type, param, column);
Panel_add(panel, (Object*) Meter_toListItem(meter, false)); Panel_add(panel, (Object*) Meter_toListItem(meter, false));
Panel_setSelected(panel, Panel_size(panel) - 1); Panel_setSelected(panel, Panel_size(panel) - 1);
@ -45,7 +45,7 @@ static HandlerResult AvailableMetersPanel_eventHandler(Panel* super, int ch) {
if (!selected) if (!selected)
return IGNORED; return IGNORED;
int param = selected->key & 0xff; unsigned int param = selected->key & 0xff;
int type = selected->key >> 16; int type = selected->key >> 16;
HandlerResult result = IGNORED; HandlerResult result = IGNORED;
bool update = false; bool update = false;
@ -114,10 +114,10 @@ AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Header* heade
} }
// Handle (&CPUMeter_class) // Handle (&CPUMeter_class)
const MeterClass* type = &CPUMeter_class; const MeterClass* type = &CPUMeter_class;
int cpus = pl->cpuCount; unsigned int cpus = pl->cpuCount;
if (cpus > 1) { if (cpus > 1) {
Panel_add(super, (Object*) ListItem_new("CPU average", 0)); 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]; char buffer[50];
xSnprintf(buffer, sizeof(buffer), "%s %d", type->uiName, Settings_cpuId(this->settings, i - 1)); xSnprintf(buffer, sizeof(buffer), "%s %d", type->uiName, Settings_cpuId(this->settings, i - 1));
Panel_add(super, (Object*) ListItem_new(buffer, i)); Panel_add(super, (Object*) ListItem_new(buffer, i));

View File

@ -35,23 +35,23 @@ static const int CPUMeter_attributes[] = {
}; };
typedef struct CPUMeterData_ { typedef struct CPUMeterData_ {
int cpus; unsigned int cpus;
Meter** meters; Meter** meters;
} CPUMeterData; } CPUMeterData;
static void CPUMeter_init(Meter* this) { static void CPUMeter_init(Meter* this) {
int cpu = this->param; unsigned int cpu = this->param;
if (cpu == 0) { if (cpu == 0) {
Meter_setCaption(this, "Avg"); Meter_setCaption(this, "Avg");
} else if (this->pl->cpuCount > 1) { } else if (this->pl->cpuCount > 1) {
char caption[10]; 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); Meter_setCaption(this, caption);
} }
} }
static void CPUMeter_updateValues(Meter* this) { static void CPUMeter_updateValues(Meter* this) {
int cpu = this->param; unsigned int cpu = this->param;
if (cpu > this->pl->cpuCount) { if (cpu > this->pl->cpuCount) {
xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "absent"); xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "absent");
for (uint8_t i = 0; i < this->curItems; i++) 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) { static void AllCPUsMeter_getRange(const Meter* this, int* start, int* count) {
const CPUMeterData* data = this->meterData; const CPUMeterData* data = this->meterData;
int cpus = data->cpus; unsigned int cpus = data->cpus;
switch(Meter_name(this)[0]) { switch(Meter_name(this)[0]) {
default: default:
case 'A': // All case 'A': // All
@ -196,7 +196,7 @@ static void AllCPUsMeter_updateValues(Meter* this) {
} }
static void CPUMeterCommonInit(Meter* this, int ncol) { static void CPUMeterCommonInit(Meter* this, int ncol) {
int cpus = this->pl->cpuCount; unsigned int cpus = this->pl->cpuCount;
CPUMeterData* data = this->meterData; CPUMeterData* data = this->meterData;
if (!data) { if (!data) {
data = this->meterData = xMalloc(sizeof(CPUMeterData)); data = this->meterData = xMalloc(sizeof(CPUMeterData));

View File

@ -71,7 +71,7 @@ void Header_writeBackToSettings(const Header* this) {
const Meter* meter = (Meter*) Vector_get(vec, i); const Meter* meter = (Meter*) Vector_get(vec, i);
char* name; char* name;
if (meter->param) { if (meter->param) {
xAsprintf(&name, "%s(%d)", As_Meter(meter)->name, meter->param); xAsprintf(&name, "%s(%u)", As_Meter(meter)->name, meter->param);
} else { } else {
xAsprintf(&name, "%s", As_Meter(meter)->name); 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]; Vector* meters = this->columns[column];
char* paren = strchr(name, '('); char* paren = strchr(name, '(');
int param = 0; unsigned int param = 0;
if (paren) { if (paren) {
int ok = sscanf(paren, "(%10d)", &param); int ok = sscanf(paren, "(%10u)", &param);
if (!ok) if (!ok)
param = 0; param = 0;
*paren = '\0'; *paren = '\0';
@ -118,7 +118,7 @@ void Header_setMode(Header* this, int i, MeterModeId mode, int column) {
Meter_setMode(meter, mode); 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]; Vector* meters = this->columns[column];
Meter* meter = Meter_new(this->pl, param, type); Meter* meter = Meter_new(this->pl, param, type);

View File

@ -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); 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); int Header_size(const Header* this, int column);

View File

@ -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)); Meter* this = xCalloc(1, sizeof(Meter));
Object_setClass(this, type); Object_setClass(this, type);
this->h = 1; this->h = 1;
@ -140,7 +140,7 @@ ListItem* Meter_toListItem(const Meter* this, bool moving) {
} }
char number[10]; char number[10];
if (this->param > 0) { if (this->param > 0) {
xSnprintf(number, sizeof(number), " %d", this->param); xSnprintf(number, sizeof(number), " %u", this->param);
} else { } else {
number[0] = '\0'; number[0] = '\0';
} }

View File

@ -95,7 +95,7 @@ struct Meter_ {
char* caption; char* caption;
int mode; int mode;
int param; unsigned int param;
GraphData* drawData; GraphData* drawData;
int h; int h;
int columnWidthCount; /*<< only used internally by the Header */ int columnWidthCount; /*<< only used internally by the Header */
@ -125,7 +125,7 @@ typedef enum {
extern const MeterClass Meter_class; 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); int Meter_humanUnit(char* buffer, unsigned long int value, size_t size);

View File

@ -59,10 +59,10 @@ typedef struct ProcessList_ {
bool topologyOk; bool topologyOk;
#endif #endif
int totalTasks; unsigned int totalTasks;
int runningTasks; unsigned int runningTasks;
int userlandThreads; unsigned int userlandThreads;
int kernelThreads; unsigned int kernelThreads;
memory_t totalMem; memory_t totalMem;
memory_t usedMem; memory_t usedMem;
@ -75,7 +75,7 @@ typedef struct ProcessList_ {
memory_t usedSwap; memory_t usedSwap;
memory_t cachedSwap; memory_t cachedSwap;
int cpuCount; unsigned int cpuCount;
time_t scanTs; time_t scanTs;
} ProcessList; } ProcessList;

View File

@ -54,7 +54,7 @@ static void Settings_readMeterModes(Settings* this, const char* line, int column
this->columns[column].modes = modes; 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 }; int sizes[] = { 3, 3 };
if (initialCpuCount > 4 && initialCpuCount <= 128) { if (initialCpuCount > 4 && initialCpuCount <= 128) {
sizes[1]++; sizes[1]++;
@ -125,7 +125,7 @@ static void readFields(ProcessField* fields, uint32_t* flags, const char* line)
String_freeArray(ids); 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"); FILE* fd = fopen(fileName, "r");
if (!fd) if (!fd)
return false; return false;
@ -344,7 +344,7 @@ int Settings_write(const Settings* this) {
return r; return r;
} }
Settings* Settings_new(int initialCpuCount) { Settings* Settings_new(unsigned int initialCpuCount) {
Settings* this = xCalloc(1, sizeof(Settings)); Settings* this = xCalloc(1, sizeof(Settings));
this->sortKey = PERCENT_CPU; this->sortKey = PERCENT_CPU;

View File

@ -89,7 +89,7 @@ void Settings_delete(Settings* this);
int Settings_write(const Settings* this); int Settings_write(const Settings* this);
Settings* Settings_new(int initialCpuCount); Settings* Settings_new(unsigned int initialCpuCount);
void Settings_invertSortOrder(Settings* this); void Settings_invertSortOrder(Settings* this);

View File

@ -184,7 +184,7 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) {
/* Get the time difference */ /* Get the time difference */
dpl->global_diff = 0; 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) { 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]; dpl->global_diff += dpl->curr_load[i].cpu_ticks[j] - dpl->prev_load[i].cpu_ticks[j];
} }

View File

@ -182,12 +182,12 @@ int Platform_getMaxPid() {
static double Platform_setCPUAverageValues(Meter* mtr) { static double Platform_setCPUAverageValues(Meter* mtr) {
const ProcessList* dpl = mtr->pl; const ProcessList* dpl = mtr->pl;
int cpus = dpl->cpuCount; unsigned int cpus = dpl->cpuCount;
double sumNice = 0.0; double sumNice = 0.0;
double sumNormal = 0.0; double sumNormal = 0.0;
double sumKernel = 0.0; double sumKernel = 0.0;
double sumPercent = 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); sumPercent += Platform_setCPUValues(mtr, i);
sumNice += mtr->values[CPU_METER_NICE]; sumNice += mtr->values[CPU_METER_NICE];
sumNormal += mtr->values[CPU_METER_NORMAL]; sumNormal += mtr->values[CPU_METER_NORMAL];
@ -199,7 +199,7 @@ static double Platform_setCPUAverageValues(Meter* mtr) {
return sumPercent / cpus; return sumPercent / cpus;
} }
double Platform_setCPUValues(Meter* mtr, int cpu) { double Platform_setCPUValues(Meter* mtr, unsigned int cpu) {
if (cpu == 0) { if (cpu == 0) {
return Platform_setCPUAverageValues(mtr); return Platform_setCPUAverageValues(mtr);

View File

@ -47,7 +47,7 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen);
int Platform_getMaxPid(void); int Platform_getMaxPid(void);
double Platform_setCPUValues(Meter* mtr, int cpu); double Platform_setCPUValues(Meter* mtr, unsigned int cpu);
void Platform_setMemoryValues(Meter* mtr); void Platform_setMemoryValues(Meter* mtr);

View File

@ -139,8 +139,8 @@ void ProcessList_delete(ProcessList* this) {
static inline void DragonFlyBSDProcessList_scanCPUTime(ProcessList* pl) { static inline void DragonFlyBSDProcessList_scanCPUTime(ProcessList* pl) {
const DragonFlyBSDProcessList* dfpl = (DragonFlyBSDProcessList*) pl; const DragonFlyBSDProcessList* dfpl = (DragonFlyBSDProcessList*) pl;
int cpus = pl->cpuCount; // actual CPU count unsigned int cpus = pl->cpuCount; // actual CPU count
int maxcpu = cpus; // max iteration (in case we have average + smp) unsigned int maxcpu = cpus; // max iteration (in case we have average + smp)
int cp_times_offset; int cp_times_offset;
assert(cpus > 0); 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); 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) { if (cpus == 1) {
// single CPU box // single CPU box
cp_time_n = dfpl->cp_time_n; cp_time_n = dfpl->cp_time_n;

View File

@ -157,9 +157,9 @@ int Platform_getMaxPid() {
return maxPid; return maxPid;
} }
double Platform_setCPUValues(Meter* this, int cpu) { double Platform_setCPUValues(Meter* this, unsigned int cpu) {
const DragonFlyBSDProcessList* fpl = (const DragonFlyBSDProcessList*) this->pl; const DragonFlyBSDProcessList* fpl = (const DragonFlyBSDProcessList*) this->pl;
int cpus = this->pl->cpuCount; unsigned int cpus = this->pl->cpuCount;
const CPUData* cpuData; const CPUData* cpuData;
if (cpus == 1) { if (cpus == 1) {

View File

@ -41,7 +41,7 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen);
int Platform_getMaxPid(void); int Platform_getMaxPid(void);
double Platform_setCPUValues(Meter* this, int cpu); double Platform_setCPUValues(Meter* this, unsigned int cpu);
void Platform_setMemoryValues(Meter* this); void Platform_setMemoryValues(Meter* this);

View File

@ -175,8 +175,8 @@ void ProcessList_delete(ProcessList* this) {
static inline void FreeBSDProcessList_scanCPU(ProcessList* pl) { static inline void FreeBSDProcessList_scanCPU(ProcessList* pl) {
const FreeBSDProcessList* fpl = (FreeBSDProcessList*) pl; const FreeBSDProcessList* fpl = (FreeBSDProcessList*) pl;
int cpus = pl->cpuCount; // actual CPU count unsigned int cpus = pl->cpuCount; // actual CPU count
int maxcpu = cpus; // max iteration (in case we have average + smp) unsigned int maxcpu = cpus; // max iteration (in case we have average + smp)
int cp_times_offset; int cp_times_offset;
assert(cpus > 0); 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); 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) { if (cpus == 1) {
// single CPU box // single CPU box
cp_time_n = fpl->cp_time_n; cp_time_n = fpl->cp_time_n;
@ -287,7 +287,7 @@ static inline void FreeBSDProcessList_scanCPU(ProcessList* pl) {
if (cpus > 1) { if (cpus > 1) {
if (pl->settings->showCPUTemperature) { if (pl->settings->showCPUTemperature) {
double maxTemp = NAN; 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; const double coreTemp = fpl->cpus[i].temperature;
if (isnan(coreTemp)) if (isnan(coreTemp))
continue; continue;
@ -302,7 +302,7 @@ static inline void FreeBSDProcessList_scanCPU(ProcessList* pl) {
const double coreZeroFreq = fpl->cpus[1].frequency; const double coreZeroFreq = fpl->cpus[1].frequency;
double freqSum = coreZeroFreq; double freqSum = coreZeroFreq;
if (!isnan(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)) if (isnan(fpl->cpus[i].frequency))
fpl->cpus[i].frequency = coreZeroFreq; fpl->cpus[i].frequency = coreZeroFreq;

View File

@ -179,9 +179,9 @@ int Platform_getMaxPid() {
return maxPid; return maxPid;
} }
double Platform_setCPUValues(Meter* this, int cpu) { double Platform_setCPUValues(Meter* this, unsigned int cpu) {
const FreeBSDProcessList* fpl = (const FreeBSDProcessList*) this->pl; const FreeBSDProcessList* fpl = (const FreeBSDProcessList*) this->pl;
int cpus = this->pl->cpuCount; unsigned int cpus = this->pl->cpuCount;
const CPUData* cpuData; const CPUData* cpuData;
if (cpus == 1) { if (cpus == 1) {

View File

@ -42,7 +42,7 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen);
int Platform_getMaxPid(void); int Platform_getMaxPid(void);
double Platform_setCPUValues(Meter* this, int cpu); double Platform_setCPUValues(Meter* this, unsigned int cpu);
void Platform_setMemoryValues(Meter* this); void Platform_setMemoryValues(Meter* this);

View File

@ -166,7 +166,7 @@ static void LinuxProcessList_initNetlinkSocket(LinuxProcessList* this) {
static void LinuxProcessList_updateCPUcount(ProcessList* super, FILE* stream) { static void LinuxProcessList_updateCPUcount(ProcessList* super, FILE* stream) {
LinuxProcessList* this = (LinuxProcessList*) super; LinuxProcessList* this = (LinuxProcessList*) super;
int cpus = 0; unsigned int cpus = 0;
char buffer[PROC_LINE_LENGTH + 1]; char buffer[PROC_LINE_LENGTH + 1];
while (fgets(buffer, sizeof(buffer), stream)) { while (fgets(buffer, sizeof(buffer), stream)) {
if (String_startsWith(buffer, "cpu")) { if (String_startsWith(buffer, "cpu")) {
@ -1269,7 +1269,7 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, openat_arg_
return false; return false;
} }
int cpus = pl->cpuCount; unsigned int cpus = pl->cpuCount;
bool hideKernelThreads = settings->hideKernelThreads; bool hideKernelThreads = settings->hideKernelThreads;
bool hideUserlandThreads = settings->hideUserlandThreads; bool hideUserlandThreads = settings->hideUserlandThreads;
while ((entry = readdir(dir)) != NULL) { while ((entry = readdir(dir)) != NULL) {
@ -1765,8 +1765,8 @@ static inline double LinuxProcessList_scanCPUTime(ProcessList* super) {
rewind(file); rewind(file);
int cpus = super->cpuCount; unsigned int cpus = super->cpuCount;
for (int i = 0; i <= cpus; i++) { for (unsigned int i = 0; i <= cpus; i++) {
char buffer[PROC_LINE_LENGTH + 1]; char buffer[PROC_LINE_LENGTH + 1];
unsigned long long int usertime, nicetime, systemtime, idletime; unsigned long long int usertime, nicetime, systemtime, idletime;
unsigned long long int ioWait = 0, irq = 0, softIrq = 0, steal = 0, guest = 0, guestnice = 0; 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) { 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); (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 { } else {
int cpuid; unsigned 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); (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); assert(cpuid == i - 1);
} }
// Guest time is already accounted in usertime // Guest time is already accounted in usertime
@ -1841,7 +1841,7 @@ static inline double LinuxProcessList_scanCPUTime(ProcessList* super) {
} }
static int scanCPUFreqencyFromSysCPUFreq(LinuxProcessList* this) { static int scanCPUFreqencyFromSysCPUFreq(LinuxProcessList* this) {
int cpus = this->super.cpuCount; unsigned int cpus = this->super.cpuCount;
int numCPUsWithFrequency = 0; int numCPUsWithFrequency = 0;
unsigned long totalFrequency = 0; unsigned long totalFrequency = 0;
@ -1859,9 +1859,9 @@ static int scanCPUFreqencyFromSysCPUFreq(LinuxProcessList* this) {
return -1; return -1;
} }
for (int i = 0; i < cpus; ++i) { for (unsigned int i = 0; i < cpus; ++i) {
char pathBuffer[64]; 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; struct timespec start;
if (i == 0) if (i == 0)
@ -1905,7 +1905,7 @@ static void scanCPUFreqencyFromCPUinfo(LinuxProcessList* this) {
if (file == NULL) if (file == NULL)
return; return;
int cpus = this->super.cpuCount; unsigned int cpus = this->super.cpuCount;
int numCPUsWithFrequency = 0; int numCPUsWithFrequency = 0;
double totalFrequency = 0; double totalFrequency = 0;
int cpuid = -1; int cpuid = -1;
@ -1928,7 +1928,7 @@ static void scanCPUFreqencyFromCPUinfo(LinuxProcessList* this) {
(sscanf(buffer, "clock : %lfMHz", &frequency) == 1) || (sscanf(buffer, "clock : %lfMHz", &frequency) == 1) ||
(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; continue;
} }
@ -1951,10 +1951,9 @@ static void scanCPUFreqencyFromCPUinfo(LinuxProcessList* this) {
} }
static void LinuxProcessList_scanCPUFrequency(LinuxProcessList* this) { static void LinuxProcessList_scanCPUFrequency(LinuxProcessList* this) {
int cpus = this->super.cpuCount; unsigned int cpus = this->super.cpuCount;
assert(cpus > 0);
for (int i = 0; i <= cpus; i++) { for (unsigned int i = 0; i <= cpus; i++) {
this->cpus[i].frequency = NAN; this->cpus[i].frequency = NAN;
} }

View File

@ -236,7 +236,7 @@ int Platform_getMaxPid() {
return maxPid; 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 LinuxProcessList* pl = (const LinuxProcessList*) this->pl;
const CPUData* cpuData = &(pl->cpus[cpu]); const CPUData* cpuData = &(pl->cpus[cpu]);
double total = (double) ( cpuData->totalPeriod == 0 ? 1 : cpuData->totalPeriod); double total = (double) ( cpuData->totalPeriod == 0 ? 1 : cpuData->totalPeriod);

View File

@ -48,7 +48,7 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen);
int Platform_getMaxPid(void); int Platform_getMaxPid(void);
double Platform_setCPUValues(Meter* this, int cpu); double Platform_setCPUValues(Meter* this, unsigned int cpu);
void Platform_setMemoryValues(Meter* this); void Platform_setMemoryValues(Meter* this);

View File

@ -63,7 +63,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui
CRT_fatalError("pagesize sysconf call failed"); CRT_fatalError("pagesize sysconf call failed");
pageSizeKB = pageSize / ONE_K; 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; CPUData* d = opl->cpus + i;
d->totalTime = 1; d->totalTime = 1;
d->totalPeriod = 1; d->totalPeriod = 1;
@ -313,7 +313,7 @@ static void OpenBSDProcessList_scanCPUTime(OpenBSDProcessList* this) {
u_int64_t kernelTimes[CPUSTATES] = {0}; u_int64_t kernelTimes[CPUSTATES] = {0};
u_int64_t avg[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); getKernelCPUTimes(i, kernelTimes);
CPUData* cpu = this->cpus + i + 1; CPUData* cpu = this->cpus + i + 1;
kernelCPUTimesToHtop(kernelTimes, cpu); kernelCPUTimesToHtop(kernelTimes, cpu);

View File

@ -166,7 +166,7 @@ int Platform_getMaxPid() {
return 99999; 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 OpenBSDProcessList* pl = (const OpenBSDProcessList*) this->pl;
const CPUData* cpuData = &(pl->cpus[cpu]); const CPUData* cpuData = &(pl->cpus[cpu]);
double total = cpuData->totalPeriod == 0 ? 1 : cpuData->totalPeriod; double total = cpuData->totalPeriod == 0 ? 1 : cpuData->totalPeriod;

View File

@ -44,7 +44,7 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen);
int Platform_getMaxPid(void); int Platform_getMaxPid(void);
double Platform_setCPUValues(Meter* this, int cpu); double Platform_setCPUValues(Meter* this, unsigned int cpu);
void Platform_setMemoryValues(Meter* this); void Platform_setMemoryValues(Meter* this);

View File

@ -177,9 +177,9 @@ int Platform_getMaxPid() {
return vproc; return vproc;
} }
double Platform_setCPUValues(Meter* this, int cpu) { double Platform_setCPUValues(Meter* this, unsigned int cpu) {
const SolarisProcessList* spl = (const SolarisProcessList*) this->pl; const SolarisProcessList* spl = (const SolarisProcessList*) this->pl;
int cpus = this->pl->cpuCount; unsigned int cpus = this->pl->cpuCount;
const CPUData* cpuData = NULL; const CPUData* cpuData = NULL;
if (cpus == 1) { if (cpus == 1) {

View File

@ -59,7 +59,7 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen);
int Platform_getMaxPid(void); int Platform_getMaxPid(void);
double Platform_setCPUValues(Meter* this, int cpu); double Platform_setCPUValues(Meter* this, unsigned int cpu);
void Platform_setMemoryValues(Meter* this); void Platform_setMemoryValues(Meter* this);

View File

@ -69,7 +69,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui
static inline void SolarisProcessList_scanCPUTime(ProcessList* pl) { static inline void SolarisProcessList_scanCPUTime(ProcessList* pl) {
const SolarisProcessList* spl = (SolarisProcessList*) pl; const SolarisProcessList* spl = (SolarisProcessList*) pl;
int cpus = pl->cpuCount; unsigned int cpus = pl->cpuCount;
kstat_t* cpuinfo = NULL; kstat_t* cpuinfo = NULL;
kstat_named_t* idletime = NULL; kstat_named_t* idletime = NULL;
kstat_named_t* intrtime = NULL; kstat_named_t* intrtime = NULL;
@ -91,7 +91,7 @@ static inline void SolarisProcessList_scanCPUTime(ProcessList* pl) {
} }
// Calculate per-CPU statistics first // 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 (spl->kd != NULL) {
if ((cpuinfo = kstat_lookup(spl->kd, "cpu", i, "sys")) != NULL) { if ((cpuinfo = kstat_lookup(spl->kd, "cpu", i, "sys")) != NULL) {
if (kstat_read(spl->kd, cpuinfo, NULL) != -1) { if (kstat_read(spl->kd, cpuinfo, NULL) != -1) {

View File

@ -93,7 +93,7 @@ int Platform_getMaxPid() {
return 1; return 1;
} }
double Platform_setCPUValues(Meter* this, int cpu) { double Platform_setCPUValues(Meter* this, unsigned int cpu) {
(void) cpu; (void) cpu;
double* v = this->values; double* v = this->values;

View File

@ -37,7 +37,7 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen);
int Platform_getMaxPid(void); int Platform_getMaxPid(void);
double Platform_setCPUValues(Meter* this, int cpu); double Platform_setCPUValues(Meter* this, unsigned int cpu);
void Platform_setMemoryValues(Meter* this); void Platform_setMemoryValues(Meter* this);