summaryrefslogtreecommitdiffstats
path: root/Machine.c
diff options
context:
space:
mode:
authorNathan Scott <nathans@redhat.com>2023-05-02 09:02:22 +1000
committerNathan Scott <nathans@redhat.com>2023-05-08 13:06:07 +1000
commit0bdade1b6cb40c5bd374a93ac0489058a7421bb5 (patch)
tree0e0225f7dbf6867402c5ed3481a705d01941f42e /Machine.c
parente4ebe18b67c366d367231a1123b057c82018cf5b (diff)
Introduce Machine class for host-specific info (split from ProcessList)
First stage in sanitizing the process list structure so that htop can support other types of lists too (cgroups, filesystems, ...), in the not-too-distant future. This introduces struct Machine for system-wide information while keeping process-list information in ProcessList (now much less). Next step is to propogate this separation into each platform, to match these core changes.
Diffstat (limited to 'Machine.c')
-rw-r--r--Machine.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/Machine.c b/Machine.c
new file mode 100644
index 00000000..63a996ef
--- /dev/null
+++ b/Machine.c
@@ -0,0 +1,60 @@
+/*
+htop - Machine.c
+(C) 2023 Red Hat, Inc.
+(C) 2004,2005 Hisham H. Muhammad
+Released under the GNU GPLv2+, see the COPYING file
+in the source distribution for its full text.
+*/
+
+#include "Machine.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "CRT.h"
+#include "Hashtable.h"
+#include "Macros.h"
+#include "Platform.h"
+#include "XUtils.h"
+
+
+void Machine_init(Machine* this, UsersTable* usersTable, uid_t userId) {
+ this->usersTable = usersTable;
+ this->userId = userId;
+
+ // always maintain valid realtime timestamps
+ Platform_gettime_realtime(&this->realtime, &this->realtimeMs);
+
+#ifdef HAVE_LIBHWLOC
+ this->topologyOk = false;
+ if (hwloc_topology_init(&this->topology) == 0) {
+ this->topologyOk =
+ #if HWLOC_API_VERSION < 0x00020000
+ /* try to ignore the top-level machine object type */
+ 0 == hwloc_topology_ignore_type_keep_structure(this->topology, HWLOC_OBJ_MACHINE) &&
+ /* ignore caches, which don't add structure */
+ 0 == hwloc_topology_ignore_type_keep_structure(this->topology, HWLOC_OBJ_CORE) &&
+ 0 == hwloc_topology_ignore_type_keep_structure(this->topology, HWLOC_OBJ_CACHE) &&
+ 0 == hwloc_topology_set_flags(this->topology, HWLOC_TOPOLOGY_FLAG_WHOLE_SYSTEM) &&
+ #else
+ 0 == hwloc_topology_set_all_types_filter(this->topology, HWLOC_TYPE_FILTER_KEEP_STRUCTURE) &&
+ #endif
+ 0 == hwloc_topology_load(this->topology);
+ }
+#endif
+}
+
+void Machine_done(Machine* this) {
+#ifdef HAVE_LIBHWLOC
+ if (this->topologyOk) {
+ hwloc_topology_destroy(this->topology);
+ }
+#else
+ (void)this;
+#endif
+}
+
+void Machine_addList(Machine* this, struct ProcessList_ *pl) {
+ // currently only process lists are supported
+ this->pl = pl;
+}

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