]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Thread.cc: Make set_affinity private and correct behavior 3983/head
authorHaomai Wang <haomaiwang@gmail.com>
Thu, 19 Mar 2015 06:56:23 +0000 (14:56 +0800)
committerHaomai Wang <haomaiwang@gmail.com>
Fri, 20 Mar 2015 03:00:56 +0000 (11:00 +0800)
Signed-off-by: Haomai Wang <haomaiwang@gmail.com>
src/common/Thread.cc

index 188d94a789b4a224a5e093a3f6c91f003ce23f4e..07e12499be6530b1f6abd8669e95c06e94188cdf 100644 (file)
 #include <sched.h>
 #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;
 }