aboutsummaryrefslogtreecommitdiffstats
path: root/Affinity.c
diff options
context:
space:
mode:
authorDaniel Lange <DLange@git.local>2024-01-10 11:17:08 +0100
committerDaniel Lange <DLange@git.local>2024-01-10 11:17:08 +0100
commite7372d18a1a661d8c3dba9f51e1f17b5f94171a7 (patch)
treee8270dd60ec096bee8157dbadf029e15ed584592 /Affinity.c
parent937052b231259a47d881d539ad5748245ef55b99 (diff)
downloaddebian_htop-e7372d18a1a661d8c3dba9f51e1f17b5f94171a7.tar.gz
debian_htop-e7372d18a1a661d8c3dba9f51e1f17b5f94171a7.tar.bz2
debian_htop-e7372d18a1a661d8c3dba9f51e1f17b5f94171a7.zip
New upstream version 3.3.0
Diffstat (limited to 'Affinity.c')
-rw-r--r--Affinity.c47
1 files changed, 32 insertions, 15 deletions
diff --git a/Affinity.c b/Affinity.c
index dc6a7fb..fab239e 100644
--- a/Affinity.c
+++ b/Affinity.c
@@ -10,8 +10,10 @@ in the source distribution for its full text.
#include "Affinity.h"
+#include <assert.h>
#include <stdlib.h>
+#include "Process.h"
#include "XUtils.h"
#if defined(HAVE_LIBHWLOC)
@@ -27,11 +29,11 @@ in the source distribution for its full text.
#endif
-Affinity* Affinity_new(ProcessList* pl) {
+Affinity* Affinity_new(Machine* host) {
Affinity* this = xCalloc(1, sizeof(Affinity));
this->size = 8;
this->cpus = xCalloc(this->size, sizeof(unsigned int));
- this->pl = pl;
+ this->host = host;
return this;
}
@@ -49,17 +51,16 @@ void Affinity_add(Affinity* this, unsigned int id) {
this->used++;
}
-
#if defined(HAVE_LIBHWLOC)
-Affinity* Affinity_get(const Process* proc, ProcessList* pl) {
+static Affinity* Affinity_get(const Process* p, Machine* host) {
hwloc_cpuset_t cpuset = hwloc_bitmap_alloc();
- bool ok = (hwloc_get_proc_cpubind(pl->topology, proc->pid, cpuset, HTOP_HWLOC_CPUBIND_FLAG) == 0);
+ bool ok = (hwloc_get_proc_cpubind(host->topology, Process_getPid(p), cpuset, HTOP_HWLOC_CPUBIND_FLAG) == 0);
Affinity* affinity = NULL;
if (ok) {
- affinity = Affinity_new(pl);
+ affinity = Affinity_new(host);
if (hwloc_bitmap_last(cpuset) == -1) {
- for (unsigned int i = 0; i < pl->existingCPUs; i++) {
+ for (unsigned int i = 0; i < host->existingCPUs; i++) {
Affinity_add(affinity, i);
}
} else {
@@ -73,27 +74,27 @@ Affinity* Affinity_get(const Process* proc, ProcessList* pl) {
return affinity;
}
-bool Affinity_set(Process* proc, Arg arg) {
+static bool Affinity_set(Process* p, Arg arg) {
Affinity* this = arg.v;
hwloc_cpuset_t cpuset = hwloc_bitmap_alloc();
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);
+ bool ok = (hwloc_set_proc_cpubind(this->host->topology, Process_getPid(p), cpuset, HTOP_HWLOC_CPUBIND_FLAG) == 0);
hwloc_bitmap_free(cpuset);
return ok;
}
#elif defined(HAVE_AFFINITY)
-Affinity* Affinity_get(const Process* proc, ProcessList* pl) {
+static Affinity* Affinity_get(const Process* p, Machine* host) {
cpu_set_t cpuset;
- bool ok = (sched_getaffinity(proc->pid, sizeof(cpu_set_t), &cpuset) == 0);
+ bool ok = (sched_getaffinity(Process_getPid(p), sizeof(cpu_set_t), &cpuset) == 0);
if (!ok)
return NULL;
- Affinity* affinity = Affinity_new(pl);
- for (unsigned int i = 0; i < pl->existingCPUs; i++) {
+ Affinity* affinity = Affinity_new(host);
+ for (unsigned int i = 0; i < host->existingCPUs; i++) {
if (CPU_ISSET(i, &cpuset)) {
Affinity_add(affinity, i);
}
@@ -101,15 +102,31 @@ Affinity* Affinity_get(const Process* proc, ProcessList* pl) {
return affinity;
}
-bool Affinity_set(Process* proc, Arg arg) {
+static bool Affinity_set(Process* p, Arg arg) {
Affinity* this = arg.v;
cpu_set_t cpuset;
CPU_ZERO(&cpuset);
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);
+ bool ok = (sched_setaffinity(Process_getPid(p), sizeof(unsigned long), &cpuset) == 0);
return ok;
}
#endif
+
+#if defined(HAVE_LIBHWLOC) || defined(HAVE_AFFINITY)
+
+bool Affinity_rowSet(Row* row, Arg arg) {
+ Process* p = (Process*) row;
+ assert(Object_isA((const Object*) p, (const ObjectClass*) &Process_class));
+ return Affinity_set(p, arg);
+}
+
+Affinity* Affinity_rowGet(const Row* row, Machine* host) {
+ const Process* p = (const Process*) row;
+ assert(Object_isA((const Object*) p, (const ObjectClass*) &Process_class));
+ return Affinity_get(p, host);
+}
+
+#endif /* HAVE_LIBHWLOC || HAVE_AFFINITY */

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