]> granicus.if.org Git - procps-ng/commitdiff
library: improve support of dynamic numa nodes, <stat>
authorJim Warner <james.warner@comcast.net>
Sat, 17 Sep 2016 07:22:22 +0000 (02:22 -0500)
committerCraig Small <csmall@enc.com.au>
Wed, 21 Sep 2016 11:06:12 +0000 (21:06 +1000)
If, in fact, numa nodes are dynamic (like that current
total of on-line cpus) the existing logic was lacking.
It included an early return before checking the total.

So, this commit ensures that the nodes total is always
set or updated consistently in only a single function.
There's no need to set it at the time 'new' is called.

[ and since under our existing code this nodes total ]
[ could never possibly have been zero, the erroneous ]
[ test (with the early return) has now been whacked! ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
proc/stat.c

index a9288c48847a185b218a1ee1124f859b4126c155..d81f817e507e3cc5cab5b9863c2720aed25b2b13 100644 (file)
@@ -450,21 +450,19 @@ static int stat_make_numa_hist (
     struct hist_tic *cpu_ptr, *nod_ptr;
     int i, node;
 
-    if (info->libnuma_handle == NULL
-    || (!info->nodes.total)) {
+    if (info->libnuma_handle == NULL)
         return 0;
-    }
 
     /* are numa nodes dynamic like online cpus can be?
        ( and be careful, this libnuma call returns the highest node id in use, )
        ( NOT an actual number of nodes - some of those 'slots' might be unused ) */
     info->nodes.total = info->our_max_node() + 1;
 
-    if (!info->nodes.hist.n_alloc
-    || !(info->nodes.total < info->nodes.hist.n_alloc)) {
+    if (info->nodes.hist.n_alloc == 0
+    || (info->nodes.total >= info->nodes.hist.n_alloc)) {
         info->nodes.hist.n_alloc = info->nodes.total + NEWOLD_INCR;
         info->nodes.hist.tics = realloc(info->nodes.hist.tics, info->nodes.hist.n_alloc * sizeof(struct hist_tic));
-        if (!(info->nodes.hist.tics))
+        if (info->nodes.hist.tics == NULL)
             return -ENOMEM;
     }
 
@@ -856,9 +854,8 @@ PROCPS_EXPORT int procps_stat_new (
     || (p->libnuma_handle = dlopen("libnuma.so.1", RTLD_LAZY))) {
         p->our_max_node = dlsym(p->libnuma_handle, "numa_max_node");
         p->our_node_of_cpu = dlsym(p->libnuma_handle, "numa_node_of_cpu");
-        if (p->our_max_node && p->our_node_of_cpu)
-            p->nodes.total = p->our_max_node() + 1;
-        else {
+        if (p->our_max_node == NULL
+        || (p->our_node_of_cpu == NULL)) {
             // this dlclose is safe - we've yet to call numa_node_of_cpu
             // ( there's one other dlclose which has now been disabled )
             dlclose(p->libnuma_handle);
@@ -869,7 +866,6 @@ PROCPS_EXPORT int procps_stat_new (
     p->libnuma_handle = (void *)-1;
     p->our_max_node = fake_max_node;
     p->our_node_of_cpu = fake_node_of_cpu;
-    p->nodes.total = fake_max_node() + 1;
  #endif
 #endif