summaryrefslogtreecommitdiffstats
path: root/Process.c
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2011-11-18 06:08:56 +0000
committerHisham Muhammad <hisham@gobolinux.org>2011-11-18 06:08:56 +0000
commit7ca10817122d3b7b30fabb1cadb75e5ee14b364e (patch)
tree14fa282dcad8eac9401fa463484b0b1693f43e1f /Process.c
parent38856488815711138aa9d0ba32cca66694717171 (diff)
Mega-commit with features and tweaks for 1.0:
* Performance improvements * Support for splitting CPU meters into two or four columns (thanks to Wim Heirman) * Switch from PLPA, which is now deprecated, to HWLOC. * Bring back support for native Linux sched_setaffinity, so we don't have to use HWLOC where we don't need to. * Support for typing in user names and column fields in selection panels.
Diffstat (limited to 'Process.c')
-rw-r--r--Process.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/Process.c b/Process.c
index 31c87406..02d13966 100644
--- a/Process.c
+++ b/Process.c
@@ -567,6 +567,7 @@ bool Process_setPriority(Process* this, int priority) {
}
#ifdef HAVE_HWLOC
+
Affinity* Process_getAffinity(Process* this) {
hwloc_cpuset_t cpuset = hwloc_bitmap_alloc();
bool ok = (hwloc_linux_get_tid_cpubind(this->pl->topology, this->pid, cpuset) == 0);
@@ -597,6 +598,31 @@ bool Process_setAffinity(Process* this, Affinity* affinity) {
hwloc_bitmap_free(cpuset);
return ok;
}
+
+#elif HAVE_NATIVE_AFFINITY
+
+Affinity* Process_getAffinity(Process* this) {
+ cpu_set_t cpuset;
+ bool ok = (sched_getaffinity(this->pid, sizeof(cpu_set_t), &cpuset) == 0);
+ if (!ok) return NULL;
+ Affinity* affinity = Affinity_new();
+ for (int i = 0; i < this->pl->cpuCount; i++) {
+ if (CPU_ISSET(i, &cpuset))
+ Affinity_add(affinity, i);
+ }
+ return affinity;
+}
+
+bool Process_setAffinity(Process* this, Affinity* affinity) {
+ cpu_set_t cpuset;
+ CPU_ZERO(&cpuset);
+ for (int i = 0; i < affinity->used; i++) {
+ CPU_SET(affinity->cpus[i], &cpuset);
+ }
+ bool ok = (sched_setaffinity(this->pid, sizeof(unsigned long), &cpuset) == 0);
+ return ok;
+}
+
#endif
void Process_sendSignal(Process* this, int sgn) {

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