ovs-numa: Introduce function to set current thread affinity.
authorDaniele Di Proietto <diproiettod@vmware.com>
Tue, 7 Jun 2016 00:05:49 +0000 (17:05 -0700)
committerDaniele Di Proietto <diproiettod@vmware.com>
Tue, 7 Jun 2016 18:15:01 +0000 (11:15 -0700)
This commit moves the code that sets the pmd threads affinity from
netdev-dpdk to ovs-numa.  There's one small part left in netdev-dpdk, to
set the lcore_id.

Now dpif-netdev will call both modules (ovs-numa and netdev-dpdk) when
starting a pmd thread.

This change will allow having a dummy implementation of the set affinity
call, for testing purposes.

Signed-off-by: Daniele Di Proietto <diproiettod@vmware.com>
Acked-by: Ilya Maximets <i.maximets@samsung.com>
lib/dpif-netdev.c
lib/netdev-dpdk.c
lib/netdev-dpdk.h
lib/ovs-numa.c
lib/ovs-numa.h

index 61a939a..fcfd22e 100644 (file)
@@ -2839,7 +2839,8 @@ pmd_thread_main(void *f_)
 
     /* Stores the pmd thread's 'pmd' to 'per_pmd_key'. */
     ovsthread_setspecific(pmd->dp->per_pmd_key, pmd);
-    pmd_thread_setaffinity_cpu(pmd->core_id);
+    ovs_numa_thread_setaffinity_core(pmd->core_id);
+    dpdk_set_lcore_id(pmd->core_id);
     poll_cnt = pmd_load_queues_and_ports(pmd, &poll_list);
 reload:
     emc_cache_init(&pmd->flow_cache);
index 22891b2..19d355f 100644 (file)
@@ -3502,24 +3502,12 @@ netdev_dpdk_register(void)
 #endif
 }
 
-int
-pmd_thread_setaffinity_cpu(unsigned cpu)
+void
+dpdk_set_lcore_id(unsigned cpu)
 {
-    cpu_set_t cpuset;
-    int err;
-
-    CPU_ZERO(&cpuset);
-    CPU_SET(cpu, &cpuset);
-    err = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
-    if (err) {
-        VLOG_ERR("Thread affinity error %d",err);
-        return err;
-    }
     /* NON_PMD_CORE_ID is reserved for use by non pmd threads. */
     ovs_assert(cpu != NON_PMD_CORE_ID);
     RTE_PER_LCORE(_lcore_id) = cpu;
-
-    return 0;
 }
 
 static bool
index ee748e0..80bb834 100644 (file)
@@ -25,7 +25,7 @@ struct smap;
 
 void netdev_dpdk_register(void);
 void free_dpdk_buf(struct dp_packet *);
-int pmd_thread_setaffinity_cpu(unsigned cpu);
+void dpdk_set_lcore_id(unsigned cpu);
 
 #else
 
@@ -45,10 +45,10 @@ free_dpdk_buf(struct dp_packet *buf OVS_UNUSED)
     /* Nothing */
 }
 
-static inline int
-pmd_thread_setaffinity_cpu(unsigned cpu OVS_UNUSED)
+static inline void
+dpdk_set_lcore_id(unsigned cpu OVS_UNUSED)
 {
-    return 0;
+    /* Nothing */
 }
 
 #endif /* DPDK_NETDEV */
index 2ffdede..b56949f 100644 (file)
@@ -473,3 +473,23 @@ ovs_numa_set_cpu_mask(const char *cmask)
         core->available = false;
     }
 }
+
+int ovs_numa_thread_setaffinity_core(unsigned core_id)
+{
+#ifdef __linux__
+    cpu_set_t cpuset;
+    int err;
+
+    CPU_ZERO(&cpuset);
+    CPU_SET(core_id, &cpuset);
+    err = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
+    if (err) {
+        VLOG_ERR("Thread affinity error %d",err);
+        return err;
+    }
+
+    return 0;
+#else /* !__linux__ */
+    return EOPNOTSUPP;
+#endif /* __linux__ */
+}
index c2619d1..5b3444b 100644 (file)
@@ -54,6 +54,7 @@ unsigned ovs_numa_get_unpinned_core_on_numa(int numa_id);
 void ovs_numa_unpin_core(unsigned core_id);
 struct ovs_numa_dump *ovs_numa_dump_cores_on_numa(int numa_id);
 void ovs_numa_dump_destroy(struct ovs_numa_dump *);
+int ovs_numa_thread_setaffinity_core(unsigned core_id);
 
 #define FOR_EACH_CORE_ON_NUMA(ITER, DUMP)                    \
     LIST_FOR_EACH((ITER), list_node, &(DUMP)->dump)