From 69f439eff387a6ecb52734e400b297a3c85f2285 Mon Sep 17 00:00:00 2001 From: Daniel Lange Date: Tue, 21 Sep 2021 08:35:19 +0200 Subject: New upstream version 3.1.0 --- Affinity.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'Affinity.c') diff --git a/Affinity.c b/Affinity.c index c157885..c1e73cc 100644 --- a/Affinity.c +++ b/Affinity.c @@ -14,7 +14,7 @@ in the source distribution for its full text. #include "XUtils.h" -#ifdef HAVE_LIBHWLOC +#if defined(HAVE_LIBHWLOC) #include #include #ifdef __linux__ @@ -22,7 +22,7 @@ in the source distribution for its full text. #else #define HTOP_HWLOC_CPUBIND_FLAG HWLOC_CPUBIND_PROCESS #endif -#elif defined(HAVE_LINUX_AFFINITY) +#elif defined(HAVE_AFFINITY) #include #endif @@ -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,32 +40,32 @@ 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++; } -#ifdef HAVE_LIBHWLOC +#if defined(HAVE_LIBHWLOC) -Affinity* Affinity_get(Process* proc, ProcessList* pl) { +Affinity* Affinity_get(const Process* proc, ProcessList* pl) { hwloc_cpuset_t cpuset = hwloc_bitmap_alloc(); bool ok = (hwloc_get_proc_cpubind(pl->topology, proc->pid, cpuset, HTOP_HWLOC_CPUBIND_FLAG) == 0); Affinity* affinity = NULL; 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->existingCPUs; i++) { Affinity_add(affinity, i); } } else { - unsigned int id; - hwloc_bitmap_foreach_begin(id, cpuset); - Affinity_add(affinity, id); + int id; + hwloc_bitmap_foreach_begin(id, cpuset) + Affinity_add(affinity, (unsigned)id); hwloc_bitmap_foreach_end(); } } @@ -76,7 +76,7 @@ Affinity* Affinity_get(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); @@ -84,16 +84,16 @@ bool Affinity_set(Process* proc, Arg arg) { return ok; } -#elif defined(HAVE_LINUX_AFFINITY) +#elif defined(HAVE_AFFINITY) -Affinity* Affinity_get(Process* proc, ProcessList* pl) { +Affinity* Affinity_get(const Process* proc, ProcessList* pl) { cpu_set_t cpuset; bool ok = (sched_getaffinity(proc->pid, sizeof(cpu_set_t), &cpuset) == 0); if (!ok) return NULL; Affinity* affinity = Affinity_new(pl); - for (int i = 0; i < pl->cpuCount; i++) { + for (unsigned int i = 0; i < pl->existingCPUs; 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); -- cgit v1.2.3