Commit 47182bd7 authored by Daniel Verkamp's avatar Daniel Verkamp Committed by Jim Harris
Browse files

io_channel: allow user to provide a thread name



This moves the thread name setting code into the generic SPDK thread
setup code, so now all spdk_threads can be named, not just ones created
by the event framework.

Change-Id: I6c824cf4bcf12fe64a8e2fc7cdc2d6c949021e40
Signed-off-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
Reviewed-on: https://review.gerrithub.io/375220


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 02f088bb
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -50,6 +50,13 @@ makes it explicit that the default is being used.
spdk_bs_io_readv_blob() and spdk_bs_io_writev_blob() were added to enable
scattered payloads.

### Event Framework

The ability to set a thread name, previously only used by the reactor code, is
now part of the `spdk_thread_allocate()` API.  Users may specify a thread name
which will show up in tools like `gdb`.


## v17.07: Build system improvements, userspace vhost-blk target, and GPT bdev

### Build System
+1 −1
Original line number Diff line number Diff line
@@ -196,7 +196,7 @@ spdk_fio_init_thread(struct thread_data *td)
		return -1;
	}

	fio_thread->thread = spdk_allocate_thread(spdk_fio_send_msg, fio_thread);
	fio_thread->thread = spdk_allocate_thread(spdk_fio_send_msg, fio_thread, "fio_thread");
	if (!fio_thread->thread) {
		spdk_ring_free(fio_thread->ring);
		free(fio_thread);
+10 −1
Original line number Diff line number Diff line
@@ -66,8 +66,12 @@ typedef void (*spdk_channel_for_each_cpl)(void *io_device, void *ctx);
 *          called on the same thread that spdk_allocate_thread
 *          was called from.
 * @param thread_ctx Context that will be passed to fn.
 * @param name Human-readable name for the thread; can be retrieved with spdk_thread_get_name().
 *             The string is copied, so the pointed-to data only needs to be valid during the
 *             spdk_allocate_thread() call.  May be NULL to specify no name.
 */
struct spdk_thread *spdk_allocate_thread(spdk_thread_pass_msg fn, void *thread_ctx);
struct spdk_thread *spdk_allocate_thread(spdk_thread_pass_msg fn, void *thread_ctx,
		const char *name);

/**
 * \brief Releases any resources related to the calling thread for I/O channel allocation.
@@ -85,6 +89,11 @@ void spdk_free_thread(void);
 */
struct spdk_thread *spdk_get_thread(void);

/**
 * \brief Get a thread's name.
 */
const char *spdk_thread_get_name(const struct spdk_thread *thread);

/**
 * \brief Send a message to the given thread. The message
 * may be sent asynchronously - i.e. spdk_thread_send_msg
+3 −31
Original line number Diff line number Diff line
@@ -36,14 +36,6 @@
#include "spdk_internal/event.h"
#include "spdk_internal/log.h"

#ifdef __linux__
#include <sys/prctl.h>
#endif

#ifdef __FreeBSD__
#include <pthread_np.h>
#endif

#include "spdk/log.h"
#include "spdk/io_channel.h"
#include "spdk/env.h"
@@ -207,27 +199,6 @@ _spdk_event_queue_run_batch(struct spdk_reactor *reactor)
	return count;
}

/**
 *
 * \brief Set current reactor thread name to "reactor <cpu #>".
 *
 * This makes the reactor threads distinguishable in top and gdb.
 */
static void set_reactor_thread_name(uint32_t lcore)
{
	char thread_name[16];

	snprintf(thread_name, sizeof(thread_name), "reactor_%u", lcore);

#if defined(__linux__)
	prctl(PR_SET_NAME, thread_name, 0, 0, 0);
#elif defined(__FreeBSD__)
	pthread_set_name_np(pthread_self(), thread_name);
#else
#error missing platform support for thread name
#endif
}

static void
spdk_poller_insert_timer(struct spdk_reactor *reactor, struct spdk_poller *poller, uint64_t now)
{
@@ -335,9 +306,10 @@ _spdk_reactor_run(void *arg)
	uint64_t		spin_cycles, sleep_cycles;
	uint32_t		sleep_us;
	uint32_t 		timer_poll_count;
	char			thread_name[32];

	spdk_allocate_thread(_spdk_reactor_send_msg, &reactor->lcore);
	set_reactor_thread_name(reactor->lcore);
	snprintf(thread_name, sizeof(thread_name), "reactor_%u", reactor->lcore);
	spdk_allocate_thread(_spdk_reactor_send_msg, &reactor->lcore, thread_name);
	SPDK_NOTICELOG("Reactor started on core %u on socket %u\n", reactor->lcore,
		       reactor->socket_id);

+1 −2
Original line number Diff line number Diff line
@@ -440,7 +440,7 @@ _spdk_send_msg(spdk_thread_fn fn, void *ctx, void *thread_ctx)
void SpdkInitializeThread(void)
{
	if (g_fs != NULL) {
		spdk_allocate_thread(_spdk_send_msg, NULL);
		spdk_allocate_thread(_spdk_send_msg, NULL, "spdk_rocksdb");
		g_sync_args.channel = spdk_fs_alloc_io_channel_sync(g_fs);
	}
}
@@ -481,7 +481,6 @@ spdk_rocksdb_run(void *arg1, void *arg2)
{
	struct spdk_bdev *bdev;

	pthread_setname_np(pthread_self(), "spdk");
	bdev = spdk_bdev_get_by_name(g_bdev_name.c_str());

	if (bdev == NULL) {
Loading