cpu: better check for num cpus
authorRobert Swiecki <robert@swiecki.net>
Wed, 21 Jun 2017 15:57:21 +0000 (17:57 +0200)
committerRobert Swiecki <robert@swiecki.net>
Wed, 21 Jun 2017 15:57:21 +0000 (17:57 +0200)
cpu.c

diff --git a/cpu.c b/cpu.c
index 150b757a881c4ffe5e109e0b8c8c68df311ed889..d8a989e691e8bb1d07e6b0fd14fc3662c38cab37 100644 (file)
--- a/cpu.c
+++ b/cpu.c
@@ -39,7 +39,7 @@ static void cpuSetRandomCpu(cpu_set_t * mask, size_t mask_size, size_t cpu_num)
        for (;;) {
                uint64_t n = utilRnd64() % cpu_num;
                if (!CPU_ISSET_S(n, mask_size, mask)) {
-                       LOG_D("Setting allowed CPU: %" PRIx64 " of [0-%zu]", n, cpu_num - 1);
+                       LOG_D("Setting allowed CPU: %" PRIu64 " of [0-%zu]", n, cpu_num - 1);
                        CPU_SET_S(n, mask_size, mask);
                        break;
                }
@@ -53,11 +53,15 @@ bool cpuInit(struct nsjconf_t *nsjconf)
                PLOG_W("sysconf(_SC_NPROCESSORS_ONLN) returned %ld", all_cpus);
                return false;
        }
-       if (nsjconf->max_cpus >= (size_t) all_cpus) {
+       if (nsjconf->max_cpus > (size_t) all_cpus) {
                LOG_W("Requested number of CPUs:%zu is bigger than CPUs online:%ld",
                      nsjconf->max_cpus, all_cpus);
                return true;
        }
+       if (nsjconf->max_cpus == (size_t) all_cpus) {
+               LOG_D("All CPUs requested (%zu of %ld)", nsjconf->max_cpus, all_cpus);
+               return true;
+       }
        if (nsjconf->max_cpus == 0) {
                LOG_D("No max_cpus limit set");
                return true;