]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/common/numa.cc
import quincy beta 17.1.0
[ceph.git] / ceph / src / common / numa.cc
index 87fde6e68af8a68247228b56f1f9c728e2310b93..7af8247f2a531165b3aa8fd6140cf4cafcceafda 100644 (file)
@@ -156,6 +156,32 @@ static int easy_readdir(const std::string& dir, std::set<std::string> *out)
   return 0;
 }
 
+static std::string get_task_comm(pid_t tid)
+{
+  static const char* comm_fmt = "/proc/self/task/%d/comm";
+  char comm_name[strlen(comm_fmt) + 8];
+  snprintf(comm_name, sizeof(comm_name), comm_fmt, tid);
+  int fd = open(comm_name, O_CLOEXEC | O_RDONLY);
+  if (fd == -1) {
+    return "";
+  }
+  // see linux/sched.h
+  static constexpr int TASK_COMM_LEN = 16;
+  char name[TASK_COMM_LEN];
+  ssize_t n = safe_read(fd, name, sizeof(name));
+  close(fd);
+  if (n < 0) {
+    return "";
+  }
+  assert(n <= sizeof(name));
+  if (name[n - 1] == '\n') {
+    name[n - 1] = '\0';
+  } else {
+    name[n] = '\0';
+  }
+  return name;
+}
+
 int set_cpu_affinity_all_threads(size_t cpu_set_size, cpu_set_t *cpu_set)
 {
   // first set my affinity
@@ -179,6 +205,14 @@ int set_cpu_affinity_all_threads(size_t cpu_set_size, cpu_set_t *cpu_set)
       if (!tid) {
        continue;  // wtf
       }
+      #ifdef HAVE_DPDK
+      std::string thread_name = get_task_comm(tid);
+      static const char *dpdk_worker_name = "lcore-worker";
+      if (!thread_name.compare(0, strlen(dpdk_worker_name), dpdk_worker_name)) {
+       // ignore dpdk reactor thread, as it takes case of numa by itself
+        continue;
+      }
+      #endif
       r = sched_setaffinity(tid, cpu_set_size, cpu_set);
       if (r < 0) {
        return -errno;