From b0c30f6743c00ac98a890899339b22ef3d62d269 Mon Sep 17 00:00:00 2001 From: Haomai Wang Date: Thu, 19 Mar 2015 14:56:23 +0800 Subject: [PATCH] Thread.cc: Make set_affinity private and correct behavior Signed-off-by: Haomai Wang --- src/common/Thread.cc | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/common/Thread.cc b/src/common/Thread.cc index 188d94a789b4a..07e12499be653 100644 --- a/src/common/Thread.cc +++ b/src/common/Thread.cc @@ -31,6 +31,23 @@ #include #endif +static int _set_affinity(int id) +{ +#ifdef HAVE_SCHED + if (id >= 0 && id < CPU_SETSIZE) { + cpu_set_t cpuset; + CPU_ZERO(&cpuset); + + CPU_SET(id, &cpuset); + + if (sched_setaffinity(0, sizeof(cpuset), &cpuset) < 0) + return -errno; + /* guaranteed to take effect immediately */ + sched_yield(); + } +#endif + return 0; +} Thread::Thread() : thread_id(0), @@ -63,7 +80,7 @@ void *Thread::entry_wrapper() IOPRIO_PRIO_VALUE(ioprio_class, ioprio_priority)); } if (pid && cpuid >= 0) - set_affinity(cpuid); + _set_affinity(cpuid); return entry(); } @@ -168,19 +185,8 @@ int Thread::set_ioprio(int cls, int prio) int Thread::set_affinity(int id) { -#ifdef HAVE_SCHED - if (pid && id >= 0 && id < CPU_SETSIZE) { - cpu_set_t cpuset; - CPU_ZERO(&cpuset); - - CPU_SET(id, &cpuset); - - if (sched_setaffinity(0, sizeof(cpuset), &cpuset) < 0) - return -errno; - /* guaranteed to take effect immediately */ - sched_yield(); - } -#endif cpuid = id; + if (pid && ceph_gettid() == pid) + _set_affinity(id); return 0; } -- 2.39.5