summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Pen <r.peniaev@gmail.com>2016-04-23 13:44:09 +0200
committerJens Axboe <axboe@fb.com>2016-04-25 08:53:18 -0600
commit7338236ab386515bbcecf5c05bca6a034c12d0b9 (patch)
tree461034e37be148ddd0a8ef0676b4a7b0635eb5dd
parentf6541f75f2822252b057f08e9f5f0c40d4079a8c (diff)
downloadblktrace-7338236ab386515bbcecf5c05bca6a034c12d0b9.tar.gz
blktrace-7338236ab386515bbcecf5c05bca6a034c12d0b9.tar.bz2
btreplay: fix sched_{set|get}affinity
getpid() is a pid of a process, at least tid must be provided. But if zero is passed, then calling thread will be used. That exactly what is needed. Signed-off-by: Roman Pen <r.peniaev@gmail.com> Cc: Jens Axboe <axboe@fb.com> Cc: <linux-btrace@vger.kernel.org> Signed-off-by: Jens Axboe <axboe@fb.com>
-rw-r--r--btreplay/btreplay.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/btreplay/btreplay.c b/btreplay/btreplay.c
index 2a1525e..5bf47ff 100644
--- a/btreplay/btreplay.c
+++ b/btreplay/btreplay.c
@@ -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));