Commit d108dcf5 authored by Tomasz Zawadzki's avatar Tomasz Zawadzki
Browse files

test/bdevio: simplify thread allocation



This test was designed with 3 cores in mind,
where ut_thread and io_thread were always on separate
cores.

This patch just simplifies the logic for doing exactly that.

Signed-off-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Change-Id: Ica0b594d2be20df0fa430e290e97f0b34be17c62
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/6233


Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
parent 62ab898c
Loading
Loading
Loading
Loading
+14 −30
Original line number Diff line number Diff line
@@ -1259,48 +1259,32 @@ static void
test_main(void *arg1)
{
	struct spdk_cpuset tmpmask = {};
	const struct spdk_cpuset *appmask;
	uint32_t cpu, init_cpu;
	uint32_t i;

	pthread_mutex_init(&g_test_mutex, NULL);
	pthread_cond_init(&g_test_cond, NULL);

	appmask = spdk_app_get_core_mask();

	if (spdk_cpuset_count(appmask) < 3) {
	/* This test runs specifically on at least three cores.
	 * g_thread_init is the app_thread on main core from event framework.
	 * Next two are only for the tests and should always be on separate CPU cores. */
	if (spdk_env_get_core_count() < 3) {
		spdk_app_stop(-1);
		return;
	}

	init_cpu = spdk_env_get_current_core();
	SPDK_ENV_FOREACH_CORE(i) {
		if (i == spdk_env_get_current_core()) {
			g_thread_init = spdk_get_thread();

	for (cpu = 0; cpu < SPDK_ENV_LCORE_ID_ANY; cpu++) {
		if (cpu != init_cpu && spdk_cpuset_get_cpu(appmask, cpu)) {
			spdk_cpuset_zero(&tmpmask);
			spdk_cpuset_set_cpu(&tmpmask, cpu, true);
			g_thread_ut = spdk_thread_create("ut_thread", &tmpmask);
			break;
		}
	}

	if (cpu == SPDK_ENV_LCORE_ID_ANY) {
		spdk_app_stop(-1);
		return;
			continue;
		}

	for (cpu++; cpu < SPDK_ENV_LCORE_ID_ANY; cpu++) {
		if (cpu != init_cpu && spdk_cpuset_get_cpu(appmask, cpu)) {
		spdk_cpuset_zero(&tmpmask);
			spdk_cpuset_set_cpu(&tmpmask, cpu, true);
		spdk_cpuset_set_cpu(&tmpmask, i, true);
		if (g_thread_ut == NULL) {
			g_thread_ut = spdk_thread_create("ut_thread", &tmpmask);
		} else if (g_thread_io == NULL) {
			g_thread_io = spdk_thread_create("io_thread", &tmpmask);
			break;
		}
		}

	if (cpu == SPDK_ENV_LCORE_ID_ANY) {
		spdk_app_stop(-1);
		return;
	}

	if (g_wait_for_tests) {