From 177ab97b6e91f23b475dd8320d8315392f44596c Mon Sep 17 00:00:00 2001 From: Ziye Yang Date: Thu, 20 Apr 2017 13:22:58 +0800 Subject: [PATCH] fio_plugin: Reset the cpu core affinity after spdk_env_init The reaon is that rte_eal_init called in spdk_env_init binds the master thread on master core, we need to restore the affinity. Change-Id: I4eb2d36b74404c1af6d242c4fd5c403bd3d5036c Signed-off-by: Ziye Yang --- examples/nvme/fio_plugin/fio_plugin.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/examples/nvme/fio_plugin/fio_plugin.c b/examples/nvme/fio_plugin/fio_plugin.c index f3857e51c6..3b27ffa014 100644 --- a/examples/nvme/fio_plugin/fio_plugin.c +++ b/examples/nvme/fio_plugin/fio_plugin.c @@ -179,6 +179,23 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid, fio_ctrlr->ns_list = fio_ns; } +static void +cpu_core_unaffinitized(void) +{ + cpu_set_t mask; + int i; + int num = sysconf(_SC_NPROCESSORS_CONF); + + CPU_ZERO(&mask); + for (i = 0; i < num; i++) { + CPU_SET(i, &mask); + } + + if (pthread_setaffinity_np(pthread_self(), sizeof(mask), &mask) < 0) { + SPDK_ERRLOG("set thread affinity failed\n"); + } +} + /* Called once at initialization. This is responsible for gathering the size of * each "file", which in our case are in the form * 'key=value [key=value] ... ns=value' @@ -216,6 +233,7 @@ static int spdk_fio_setup(struct thread_data *td) opts.dpdk_mem_size = 512; spdk_env_init(&opts); spdk_env_initialized = true; + cpu_core_unaffinitized(); } for_each_file(td, f, i) {