blktrace: Use number of online CPUs
authorAbutalib Aghayev <agayev@gmail.com>
Tue, 9 Feb 2016 15:17:50 +0000 (08:17 -0700)
committerJens Axboe <axboe@fb.com>
Tue, 9 Feb 2016 15:17:50 +0000 (08:17 -0700)
Currently, blktrace uses _SC_NPROCESSORS_CONF to find out the number of
CPUs.  This is a problem, because if you reduce the number of online
CPUs by passing kernel parameter maxcpus, then blktrace fails to start
with the error:

FAILED to start thread on CPU 4: 22/Invalid argument
FAILED to start thread on CPU 5: 22/Invalid argument
...

The attached patch fixes it to use _SC_NPROCESSORS_ONLN.

Signed-off-by: Jens Axboe <axboe@fb.com>
blktrace.c
btreplay/btreplay.c
verify_blkparse.c

index 3c8fb4c43885c48b2c73d113ce282df5bb007ce4..b445524b1f0b8b38ae9d13f030d7cdf171558a78 100644 (file)
@@ -2663,9 +2663,9 @@ int main(int argc, char *argv[])
 
        setlocale(LC_NUMERIC, "en_US");
        pagesize = getpagesize();
-       ncpus = sysconf(_SC_NPROCESSORS_CONF);
+       ncpus = sysconf(_SC_NPROCESSORS_ONLN);
        if (ncpus < 0) {
-               fprintf(stderr, "sysconf(_SC_NPROCESSORS_CONF) failed %d/%s\n",
+               fprintf(stderr, "sysconf(_SC_NPROCESSORS_ONLN) failed %d/%s\n",
                        errno, strerror(errno));
                ret = 1;
                goto out;
index 2a1e1cca0f72c22968466d153789ff3ec0d3a8ab..6d195640a3792ad2929fefcddd9fad9cc74f5f29 100644 (file)
@@ -502,8 +502,8 @@ static inline void start_iter(void)
  */
 static void get_ncpus(void)
 {
-#ifdef _SC_NPROCESSORS_CONF
-       ncpus = sysconf(_SC_NPROCESSORS_CONF);
+#ifdef _SC_NPROCESSORS_ONLN
+       ncpus = sysconf(_SC_NPROCESSORS_ONLN);
 #else
        int nrcpus = 4096;
        cpu_set_t * cpus;
index 5689f43176af9d1480c8adee6f90343870178ff7..3f3e92a563c9a50d7168cc498eecc2ff30525053 100644 (file)
@@ -16,8 +16,8 @@ int main(int argc, char *argv[])
        unsigned int seq;
        FILE *f;
 
-#ifdef _SC_NPROCESSORS_CONF
-       MAX_CPUS = sysconf(_SC_NPROCESSORS_CONF);
+#ifdef _SC_NPROCESSORS_ONLN
+       MAX_CPUS = sysconf(_SC_NPROCESSORS_ONLN);
        if (MAX_CPUS < 1)
        {
                fprintf(stderr, "Could not determine number of CPUs online:\n%s\n",