lib/env: add spdk_unaffinitize_thread

This can be used by threads within SPDK to undo the
affinitization done either by DPDK (for DPDK lcores)
or by inheriting the parent's thread when using
pthread_create().

This will be used by the stub app to unaffinitize
the reactor core to allow the scheduler to flexibly
move it to an idle core.

Signed-off-by: Jim Harris <james.r.harris@intel.com>
Change-Id: I7e550953cd9dcd7fd9d98bfbb70660994f2eefcd

Reviewed-on: https://review.gerrithub.io/366680
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Jim Harris 2017-06-22 12:48:33 -07:00
parent c588baab29
commit c09bfe8965
3 changed files with 24 additions and 28 deletions

View File

@ -177,23 +177,6 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid,
fio_file_set_size_known(f);
}
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'
@ -234,7 +217,7 @@ static int spdk_fio_setup(struct thread_data *td)
opts.mem_size = 512;
spdk_env_init(&opts);
spdk_env_initialized = true;
cpu_core_unaffinitized();
spdk_unaffinitize_thread();
}
for_each_file(td, f, i) {

View File

@ -376,6 +376,11 @@ int spdk_pci_addr_parse(struct spdk_pci_addr *addr, const char *bdf);
*/
int spdk_pci_addr_fmt(char *bdf, size_t sz, const struct spdk_pci_addr *addr);
/**
* Removes any CPU affinitization from the current thread.
*/
void spdk_unaffinitize_thread(void);
/**
* Call a function with CPU affinity unset.
*

View File

@ -228,19 +228,12 @@ void spdk_delay_us(unsigned int us)
rte_delay_us(us);
}
void *
spdk_call_unaffinitized(void *cb(void *arg), void *arg)
void
spdk_unaffinitize_thread(void)
{
rte_cpuset_t orig_cpuset, new_cpuset;
void *ret;
rte_cpuset_t new_cpuset;
long num_cores, i;
if (cb == NULL) {
return NULL;
}
rte_thread_get_affinity(&orig_cpuset);
CPU_ZERO(&new_cpuset);
num_cores = sysconf(_SC_NPROCESSORS_CONF);
@ -251,6 +244,21 @@ spdk_call_unaffinitized(void *cb(void *arg), void *arg)
}
rte_thread_set_affinity(&new_cpuset);
}
void *
spdk_call_unaffinitized(void *cb(void *arg), void *arg)
{
rte_cpuset_t orig_cpuset;
void *ret;
if (cb == NULL) {
return NULL;
}
rte_thread_get_affinity(&orig_cpuset);
spdk_unaffinitize_thread();
ret = cb(arg);