diff options
108 files changed, 72722 insertions, 3299 deletions
diff --git a/Affinity.c b/Affinity.c new file mode 100644 index 00000000..0b2bd465 --- /dev/null +++ b/Affinity.c @@ -0,0 +1,36 @@ + +#include "config.h" +#include "Affinity.h" +#include <stdlib.h> + +/*{ + +typedef struct Affinity_ { + int size; + int used; + int* cpus; +} Affinity; + +}*/ + +Affinity* Affinity_new() { + Affinity* this = calloc(sizeof(Affinity), 1); + this->size = 8; + this->cpus = calloc(sizeof(int), this->size); + return this; +} + +void Affinity_delete(Affinity* this) { + free(this->cpus); + free(this); +} + +void Affinity_add(Affinity* this, int id) { + if (this->used == this->size) { + this->size *= 2; + this->cpus = realloc(this->cpus, sizeof(int) * this->size); + } + this->cpus[this->used] = id; + this->used++; +} + diff --git a/AffinityPanel.c b/AffinityPanel.c index b3ea4123..504638e7 100644 --- a/AffinityPanel.c +++ b/AffinityPanel.c @@ -1,9 +1,8 @@ +#include "ProcessList.h" #include "AffinityPanel.h" - #include "Panel.h" #include "CheckItem.h" -#include "ProcessList.h" #include "debug.h" #include <assert.h> @@ -26,25 +25,33 @@ static HandlerResult AffinityPanel_eventHandler(Panel* this, int ch) { return result; } -Panel* AffinityPanel_new(ProcessList* pl, unsigned long mask) { +Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity) { Panel* this = Panel_new(1, 1, 1, 1, CHECKITEM_CLASS, true, ListItem_compare); this->eventHandler = AffinityPanel_eventHandler; Panel_setHeader(this, "Use CPUs:"); + int curCpu = 0; for (int i = 0; i < pl->cpuCount; i++) { char number[10]; snprintf(number, 9, "%d", ProcessList_cpuId(pl, i)); - Panel_add(this, (Object*) CheckItem_new(String_copy(number), NULL, mask & (1 << i))); + bool mode; + if (curCpu < affinity->used && affinity->cpus[curCpu] == i) { + mode = true; + curCpu++; + } else { + mode = false; + } + Panel_add(this, (Object*) CheckItem_new(String_copy(number), NULL, mode)); } return this; } -unsigned long AffinityPanel_getAffinity(Panel* this) { +Affinity* AffinityPanel_getAffinity(Panel* this) { + Affinity* affinity = Affinity_new(); int size = Panel_size(this); - unsigned long mask = 0; for (int i = 0; i < size; i++) { if (CheckItem_get((CheckItem*)Panel_get(this, i))) - mask = mask | (1 << i); + Affinity_add(affinity, i); } - return mask; + return affinity; } diff --git a/AffinityPanel.h b/AffinityPanel.h index 4324610b..8ab39633 100644 --- a/AffinityPanel.h +++ b/AffinityPanel.h @@ -3,16 +3,15 @@ #ifndef HEADER_AffinityPanel #define HEADER_AffinityPanel - +#include "ProcessList.h" #include "Panel.h" #include "CheckItem.h" -#include "ProcessList.h" #include "debug.h" #include <assert.h> -Panel* AffinityPanel_new(ProcessList* pl, unsigned long mask); +Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity); -unsigned long AffinityPanel_getAffinity(Panel* this); +Affinity* AffinityPanel_getAffinity(Panel* this); #endif diff --git a/DebugMemory.c b/DebugMemory.c index f9f38e70..7a0f584d 100644 --- a/DebugMemory.c +++ b/DebugMemory.c @@ -1,5 +1,4 @@ -#define _GNU_SOURCE #include <string.h> #include <stdlib.h> #include <stdio.h> diff --git a/DebugMemory.h b/DebugMemory.h index ea262089..a67a5f2b 100644 --- a/DebugMemory.h +++ b/DebugMemory.h @@ -3,7 +3,6 @@ #ifndef HEADER_DebugMemory #define HEADER_DebugMemory -#define _GNU_SOURCE #include <string.h> #include <stdlib.h> #include <stdio.h> diff --git a/Makefile.am b/Makefile.am index 9bf73e48..57651a93 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,9 +1,9 @@ -if HAVE_PLPA -SUBDIRS = plpa-1.3.2 +if HAVE_HWLOC +SUBDIRS = hwloc-1.2.1 endif -ACLOCAL_AMFLAGS=-I m4 +ACLOCAL_AMFLAGS = -I m4 -I hwloc-1.2.1/config bin_PROGRAMS = htop dist_man_MANS = htop.1 @@ -15,6 +15,7 @@ pixmapdir = $(datadir)/pixmaps pixmap_DATA = htop.png htop_CFLAGS = -pedantic -Wall -std=c99 -rdynamic -D_XOPEN_SOURCE_EXTENDED +AM_CFLAGS = AM_CPPFLAGS = -DSYSCONFDIR=\"$(sysconfdir)\" myhtopsources = AvailableMetersPanel.c CategoriesPanel.c CheckItem.c \ @@ -24,7 +25,7 @@ LoadAverageMeter.c MemoryMeter.c Meter.c MetersPanel.c Object.c Panel.c \ BatteryMeter.c Process.c ProcessList.c RichString.c ScreenManager.c Settings.c \ SignalItem.c SignalsPanel.c String.c SwapMeter.c TasksMeter.c TraceScreen.c \ UptimeMeter.c UsersTable.c Vector.c AvailableColumnsPanel.c AffinityPanel.c \ -HostnameMeter.c OpenFilesScreen.c +HostnameMeter.c OpenFilesScreen.c Affinity.c myhtopheaders = AvailableColumnsPanel.h AvailableMetersPanel.h \ CategoriesPanel.h CheckItem.h ClockMeter.h ColorsPanel.h ColumnsPanel.h \ @@ -33,14 +34,17 @@ Hashtable.h Header.h htop.h ListItem.h LoadAverageMeter.h MemoryMeter.h \ BatteryMeter.h Meter.h MetersPanel.h Object.h Panel.h ProcessList.h RichString.h \ ScreenManager.h Settings.h SignalItem.h SignalsPanel.h String.h \ SwapMeter.h TasksMeter.h TraceScreen.h UptimeMeter.h UsersTable.h Vector.h \ -Process.h AffinityPanel.h HostnameMeter.h OpenFilesScreen.h +Process.h AffinityPanel.h HostnameMeter.h OpenFilesScreen.h Affinity.h SUFFIXES = .h BUILT_SOURCES = $(myhtopheaders) htop_SOURCES = $(myhtopheaders) $(myhtopsources) config.h debug.h -if HAVE_PLPA -htop_LDADD = $(top_builddir)/plpa-1.3.2/src/libplpa/libplpa_included.la + +if HAVE_HWLOC +htop_LDADD = $(HWLOC_EMBEDDED_LDADD) $(HWLOC_EMBEDDED_LIBS) +AM_CFLAGS += $(HWLOC_EMBEDDED_CFLAGS) +AM_CPPFLAGS += $(HWLOC_EMBEDDED_CPPFLAGS) endif profile: @@ -9,7 +9,6 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#define _GNU_SOURCE #include "RichString.h" #include "Object.h" #include "CRT.h" @@ -5,13 +5,13 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ -#define _GNU_SOURCE #include "ProcessList.h" #include "Object.h" #include "CRT.h" #include "String.h" #include "Process.h" #include "RichString.h" +#include "Affinity.h" #include "debug.h" @@ -29,8 +29,8 @@ in the source distribution for its full text. #include <sched.h> #include <time.h> -#ifdef HAVE_PLPA -#include <plpa.h> +#ifdef HAVE_HWLOC +#include <hwloc/linux.h> #endif // This works only with glibc 2.1+. On earlier versions @@ -535,15 +535,36 @@ bool Process_setPriority(Process* this, int priority) { return (err == 0); } -#ifdef HAVE_PLPA -unsigned long Process_getAffinity(Process* this) { - unsigned long mask = 0; - plpa_sched_getaffinity(this->pid, sizeof(unsigned long), (plpa_cpu_set_t*) &mask); - return mask; +#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); + Affinity* affinity = NULL; + if (ok) { + affinity = Affinity_new(); + if (hwloc_bitmap_last(cpuset) == -1) { + for (int i = 0; i < this->pl->cpuCount; i++) { + Affinity_add(affinity, i); + } + } else { + unsigned int id; + hwloc_bitmap_foreach_begin(id, cpuset); + Affinity_add(affinity, id); + hwloc_bitmap_foreach_end(); + } + } + hwloc_bitmap_free(cpuset); + return affinity; } -bool Process_setAffinity(Process* this, unsigned long mask) { - return (plpa_sched_setaffinity(this->pid, sizeof(unsigned long), (plpa_cpu_set_t*) &mask) == 0); +bool Process_setAffinity(Process* this, Affinity* affinity) { + hwloc_cpuset_t cpuset = hwloc_bitmap_alloc(); + for (int i = 0; i < affinity->used; i++) { + hwloc_bitmap_set(cpuset, affinity->cpus[i]); + } + bool ok = (hwloc_linux_set_ |