Commit b930f0dd authored by Krishna Kanth Reddy's avatar Krishna Kanth Reddy Committed by Tomasz Zawadzki
Browse files

lib/trace : Unregister tracing support for user created threads



Cleanup the tracing support whenever the user created threads
are exited.

fio_plugin is modified to verify the cleanup of tracing support
for the user created threads.

Change-Id: Ifebdf5d76f6cc190bde75d542797ce4455860c1a
Signed-off-by: default avatarKrishna Kanth Reddy <krish.reddy@samsung.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/21304


Community-CI: Mellanox Build Bot
Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent 4f0f474f
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -4,7 +4,8 @@

### trace

Added `spdk_trace_register_user_thread` to initialize trace environment
Added `spdk_trace_register_user_thread` to initialize trace environment and
`spdk_trace_unregister_user_thread` to de-initialize trace environment
for an user created thread.

Modified `spdk_trace_init` to take number of user created threads as a parameter.
+5 −0
Original line number Diff line number Diff line
@@ -1538,6 +1538,10 @@ spdk_fio_cleanup(struct thread_data *td)
	struct spdk_fio_qpair	*fio_qpair, *fio_qpair_tmp;
	struct spdk_fio_options *fio_options = td->eo;

	if (fio_options->spdk_tracing) {
		spdk_trace_unregister_user_thread();
	}

	TAILQ_FOREACH_SAFE(fio_qpair, &fio_thread->fio_qpair, link, fio_qpair_tmp) {
		TAILQ_REMOVE(&fio_thread->fio_qpair, fio_qpair, link);
		free(fio_qpair);
@@ -1864,6 +1868,7 @@ static void fio_exit
fio_spdk_unregister(void)
{
	if (g_spdk_env_initialized) {
		spdk_trace_cleanup();
		spdk_env_fini();
	}

+7 −0
Original line number Diff line number Diff line
@@ -291,6 +291,13 @@ int spdk_trace_init(const char *shm_name, uint64_t num_entries, uint32_t num_thr
 */
int spdk_trace_register_user_thread(void);

/**
 * De-initialize trace environment for an user created thread.
 *
 * \return 0 on success, else non-zero indicates a failure.
 */
int spdk_trace_unregister_user_thread(void);

/**
 * Unmap global trace memory structs.
 */
+1 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
	spdk_trace_register_description;
	spdk_trace_register_description_ext;
	spdk_trace_register_user_thread;
	spdk_trace_unregister_user_thread;
	spdk_trace_get_first_register_fn;
	spdk_trace_get_next_register_fn;
	spdk_trace_enable_tpoint_group;
+28 −6
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
static int g_trace_fd = -1;
static char g_shm_name[64];

static __thread uint32_t t_ut_array_index;
static __thread struct spdk_trace_history *t_ut_lcore_history;

uint32_t g_user_thread_index_start;
@@ -154,8 +155,6 @@ _spdk_trace_record(uint64_t tsc, uint16_t tpoint_id, uint16_t poller_id, uint32_
int
spdk_trace_register_user_thread(void)
{
	uint32_t ut_index;

	if (!g_ut_array) {
		SPDK_ERRLOG("user thread array not created\n");
		return -ENOMEM;
@@ -169,17 +168,40 @@ spdk_trace_register_user_thread(void)

	pthread_mutex_lock(&g_ut_array_mutex);

	ut_index = spdk_bit_array_find_first_clear(g_ut_array, 0);
	if (ut_index == UINT32_MAX) {
	t_ut_array_index = spdk_bit_array_find_first_clear(g_ut_array, 0);
	if (t_ut_array_index == UINT32_MAX) {
		SPDK_ERRLOG("could not find an entry in the user thread array\n");
		pthread_mutex_unlock(&g_ut_array_mutex);
		return -ENOENT;
	}

	t_ut_lcore_history = spdk_get_per_lcore_history(g_trace_histories,
			     ut_index + g_user_thread_index_start);
			     t_ut_array_index + g_user_thread_index_start);

	spdk_bit_array_set(g_ut_array, t_ut_array_index);

	pthread_mutex_unlock(&g_ut_array_mutex);

	return 0;
}

int
spdk_trace_unregister_user_thread(void)
{
	if (!g_ut_array) {
		SPDK_ERRLOG("user thread array not created\n");
		return -ENOMEM;
	}

	if (spdk_env_get_current_core() != SPDK_ENV_LCORE_ID_ANY) {
		SPDK_ERRLOG("cannot unregister an user thread from a dedicated cpu %d\n",
			    spdk_env_get_current_core());
		return -EINVAL;
	}

	pthread_mutex_lock(&g_ut_array_mutex);

	spdk_bit_array_set(g_ut_array, ut_index);
	spdk_bit_array_clear(g_ut_array, t_ut_array_index);

	pthread_mutex_unlock(&g_ut_array_mutex);