diff options
author | Nathan Scott <nathans@redhat.com> | 2023-08-22 16:11:05 +1000 |
---|---|---|
committer | Nathan Scott <nathans@redhat.com> | 2023-08-30 13:11:57 +1000 |
commit | 0f751e991d399769fb8d7800f7c4bccec2ca7f60 (patch) | |
tree | 34cd7838f7ebf51049816f9acb6a63cea175af06 /Affinity.c | |
parent | 68f4f10f012d11bd57bb725fe4113b2af937fc1d (diff) |
Introduce Row and Table classes for screens beyond top-processes
This commit refactors the Process and ProcessList structures such
they each have a new parent - Row and Table, respectively. These
new classes handle screen updates relating to anything that could
be represented in tabular format, e.g. cgroups, filesystems, etc,
without us having to reimplement the display logic repeatedly for
each new entity.
Diffstat (limited to 'Affinity.c')
-rw-r--r-- | Affinity.c | 34 |
1 files changed, 25 insertions, 9 deletions
@@ -12,6 +12,7 @@ in the source distribution for its full text. #include <stdlib.h> +#include "Process.h" #include "XUtils.h" #if defined(HAVE_LIBHWLOC) @@ -49,12 +50,11 @@ void Affinity_add(Affinity* this, unsigned int id) { this->used++; } - #if defined(HAVE_LIBHWLOC) -Affinity* Affinity_get(const Process* proc, Machine* host) { +static Affinity* Affinity_get(const Process* p, Machine* host) { hwloc_cpuset_t cpuset = hwloc_bitmap_alloc(); - bool ok = (hwloc_get_proc_cpubind(host->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(host); @@ -73,22 +73,22 @@ Affinity* Affinity_get(const Process* proc, Machine* host) { 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->host->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, Machine* host) { +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; @@ -101,15 +101,31 @@ Affinity* Affinity_get(const Process* proc, Machine* host) { 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 */ |