Commit 9bea56c0 authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Tomasz Zawadzki
Browse files

example/nvmf: Enlarge critical section guarded by g_mutex in nvmf_schedule_spdk_thread()



nvmf_schedule_spdk_thread() is not so performance critical but
should work as designed. Guard the whole operation to decide the target
core by g_mutex. This matches the reactor's _reactor_schedule_thread().

If _reactor_schedule_thread() is refined, change this accordingly too.

Signed-off-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: I9382230577442897d4d2d22b85b1ae4edd77aa98
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/2536


Community-CI: Mellanox Build Bot
Community-CI: Broadcom CI
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent aaca23fb
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -237,14 +237,13 @@ nvmf_schedule_spdk_thread(struct spdk_thread *thread)
	 * Here we use the mutex.The way the actual SPDK event framework
	 * solves this is by using internal rings for messages between reactors
	 */
	for (i = 0; i < spdk_env_get_core_count(); i++) {
	pthread_mutex_lock(&g_mutex);
	for (i = 0; i < spdk_env_get_core_count(); i++) {
		if (g_next_reactor == NULL) {
			g_next_reactor = TAILQ_FIRST(&g_reactors);
		}
		nvmf_reactor = g_next_reactor;
		g_next_reactor = TAILQ_NEXT(g_next_reactor, link);
		pthread_mutex_unlock(&g_mutex);

		/* each spdk_thread has the core affinity */
		if (spdk_cpuset_get_cpu(cpumask, nvmf_reactor->core)) {
@@ -254,6 +253,7 @@ nvmf_schedule_spdk_thread(struct spdk_thread *thread)
			break;
		}
	}
	pthread_mutex_unlock(&g_mutex);

	if (i == spdk_env_get_core_count()) {
		fprintf(stderr, "failed to schedule spdk thread\n");