From d9561c444fe3b08188c11bec4198beed4f52cf51 Mon Sep 17 00:00:00 2001 From: Ziye Yang Date: Fri, 11 Oct 2019 12:53:10 +0800 Subject: [PATCH] env/dpdk: Exclude the orig cpuset in spdk_unaffinitize_thread The patch of this purpose is to exclude the CPU cores occupied by the DPDK thread. To mitigate the corner case, we only do it when the number of online CPU cores is larger than then DPDK thread occupied cpu cores. The purpose is uset to improve the performance and avoid the contention between DPDK thread and user's own thread. Change-Id: I1a4a28074df97c55ac531440aea41059a75543f6 Signed-off-by: Ziye Yang Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/471000 Tested-by: SPDK CI Jenkins Reviewed-by: JinYu Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto --- lib/env_dpdk/env.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/env_dpdk/env.c b/lib/env_dpdk/env.c index e808fae45..a5aad56a1 100644 --- a/lib/env_dpdk/env.c +++ b/lib/env_dpdk/env.c @@ -339,8 +339,8 @@ void spdk_pause(void) void spdk_unaffinitize_thread(void) { - rte_cpuset_t new_cpuset; - long num_cores, i; + rte_cpuset_t new_cpuset, orig_cpuset; + long num_cores, i, orig_num_cores; CPU_ZERO(&new_cpuset); @@ -351,6 +351,16 @@ spdk_unaffinitize_thread(void) CPU_SET(i, &new_cpuset); } + rte_thread_get_affinity(&orig_cpuset); + orig_num_cores = CPU_COUNT(&orig_cpuset); + if (orig_num_cores < num_cores) { + for (i = 0; i < orig_num_cores; i++) { + if (CPU_ISSET(i, &orig_cpuset)) { + CPU_CLR(i, &new_cpuset); + } + } + } + rte_thread_set_affinity(&new_cpuset); }