]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common/numa: Skip the DPDK thread when setting NUMA affinity 44276/head
authorChunsong Feng <fengchunsong@huawei.com>
Mon, 27 Dec 2021 13:03:21 +0000 (13:03 +0000)
committerChunsong Feng <fengchunsong@huawei.com>
Mon, 27 Dec 2021 13:09:33 +0000 (13:09 +0000)
The CPU affinity of the DPDK thread has been set during DPDK initialization.
Do not modify the DPDK affinity when setting NUMA affinity.

Signed-off-by: Chunsong Feng <fengchunsong@huawei.com>
Reviewed-by: luo rixin <luorixin@huawei.com>
Reviewed-by: Han Fengzhe <hanfengzhe@hisilicon.com>
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;