btreplay: fix sched_{set|get}affinity
[blktrace.git] / btreplay / btreplay.c
index 2a1525e046620ecae71d2b8eea88b8da921c7e93..5bf47ffe693b2592274f4159567a396e3eec7451 100644 (file)
@@ -513,7 +513,7 @@ realloc:
        size = CPU_ALLOC_SIZE(nrcpus);
        CPU_ZERO_S(size, cpus);
 
-       if (sched_getaffinity(getpid(), size, cpus)) {
+       if (sched_getaffinity(0, size, cpus)) {
                if( errno == EINVAL && nrcpus < (4096<<4) ) {
                        CPU_FREE(cpus);
                        nrcpus <<= 1;
@@ -552,16 +552,17 @@ static void pin_to_cpu(struct thr_info *tip)
 
        CPU_ZERO_S(size, cpus);
        CPU_SET_S(tip->cpu, size, cpus);
-       if (sched_setaffinity(getpid(), size, cpus)) {
+       if (sched_setaffinity(0, size, cpus)) {
                fatal("sched_setaffinity", ERR_SYSCALL, "Failed to pin CPU\n");
                /*NOTREACHED*/
        }
+       assert(tip->cpu == sched_getcpu());
 
        if (verbose > 1) {
                int i;
                cpu_set_t *now = CPU_ALLOC(ncpus);
 
-               (void)sched_getaffinity(getpid(), size, now);
+               (void)sched_getaffinity(0, size, now);
                fprintf(tip->vfp, "Pinned to CPU %02d ", tip->cpu);
                for (i = 0; i < ncpus; i++)
                        fprintf(tip->vfp, "%1d", CPU_ISSET_S(i, size, now));