mirror of
https://github.com/openvswitch/ovs
synced 2025-10-19 14:37:21 +00:00
ovs-numa: Introduce function to set current thread affinity.
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>
This commit is contained in:
@@ -2839,7 +2839,8 @@ pmd_thread_main(void *f_)
|
|||||||
|
|
||||||
/* Stores the pmd thread's 'pmd' to 'per_pmd_key'. */
|
/* Stores the pmd thread's 'pmd' to 'per_pmd_key'. */
|
||||||
ovsthread_setspecific(pmd->dp->per_pmd_key, pmd);
|
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);
|
poll_cnt = pmd_load_queues_and_ports(pmd, &poll_list);
|
||||||
reload:
|
reload:
|
||||||
emc_cache_init(&pmd->flow_cache);
|
emc_cache_init(&pmd->flow_cache);
|
||||||
|
@@ -3502,24 +3502,12 @@ netdev_dpdk_register(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
void
|
||||||
pmd_thread_setaffinity_cpu(unsigned cpu)
|
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. */
|
/* NON_PMD_CORE_ID is reserved for use by non pmd threads. */
|
||||||
ovs_assert(cpu != NON_PMD_CORE_ID);
|
ovs_assert(cpu != NON_PMD_CORE_ID);
|
||||||
RTE_PER_LCORE(_lcore_id) = cpu;
|
RTE_PER_LCORE(_lcore_id) = cpu;
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
|
@@ -25,7 +25,7 @@ struct smap;
|
|||||||
|
|
||||||
void netdev_dpdk_register(void);
|
void netdev_dpdk_register(void);
|
||||||
void free_dpdk_buf(struct dp_packet *);
|
void free_dpdk_buf(struct dp_packet *);
|
||||||
int pmd_thread_setaffinity_cpu(unsigned cpu);
|
void dpdk_set_lcore_id(unsigned cpu);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
@@ -45,10 +45,10 @@ free_dpdk_buf(struct dp_packet *buf OVS_UNUSED)
|
|||||||
/* Nothing */
|
/* Nothing */
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline void
|
||||||
pmd_thread_setaffinity_cpu(unsigned cpu OVS_UNUSED)
|
dpdk_set_lcore_id(unsigned cpu OVS_UNUSED)
|
||||||
{
|
{
|
||||||
return 0;
|
/* Nothing */
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* DPDK_NETDEV */
|
#endif /* DPDK_NETDEV */
|
||||||
|
@@ -473,3 +473,23 @@ ovs_numa_set_cpu_mask(const char *cmask)
|
|||||||
core->available = false;
|
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__ */
|
||||||
|
}
|
||||||
|
@@ -54,6 +54,7 @@ unsigned ovs_numa_get_unpinned_core_on_numa(int numa_id);
|
|||||||
void ovs_numa_unpin_core(unsigned core_id);
|
void ovs_numa_unpin_core(unsigned core_id);
|
||||||
struct ovs_numa_dump *ovs_numa_dump_cores_on_numa(int numa_id);
|
struct ovs_numa_dump *ovs_numa_dump_cores_on_numa(int numa_id);
|
||||||
void ovs_numa_dump_destroy(struct ovs_numa_dump *);
|
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) \
|
#define FOR_EACH_CORE_ON_NUMA(ITER, DUMP) \
|
||||||
LIST_FOR_EACH((ITER), list_node, &(DUMP)->dump)
|
LIST_FOR_EACH((ITER), list_node, &(DUMP)->dump)
|
||||||
|
Reference in New Issue
Block a user