Commit 9c35e39c authored by Ben Walker's avatar Ben Walker Committed by Daniel Verkamp
Browse files

event: Move spdk_poller_register to io_channel



Make this generic and not directly dependent on
the event framework. That way our libraries can
register pollers without adding a dependency.

Change-Id: I7ad7a7ddc131596ca1791a7b0f43dabfda050f5f
Signed-off-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-on: https://review.gerrithub.io/387690


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarDariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Reviewed-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
parent 07a521db
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -15,6 +15,13 @@ A -r option command line option has been added to enable an alternative UNIX dom
or a TCP port in the format ip_addr:tcp_port (i.e. 127.0.0.1:5260).  The Rpc configuration file
section is now deprecated and will be removed in the v18.04 release.

### I/O Channels

spdk_poller_register() and spdk_poller_unregister() were moved from the event
framework (include/spdk/event.h) to the I/O channel library
(include/spdk/io_channel.h). This allows code that doesn't depend on the event
framework to request registration and unregistration of pollers.

## v17.10: Logical Volumes

### New dependencies
+5 −4
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@

#include "spdk/bdev.h"
#include "spdk/event.h"
#include "spdk/io_channel.h"
#include "spdk/log.h"
#include "spdk/nvme.h"
#include "spdk/util.h"
@@ -126,7 +127,7 @@ _nvmf_tgt_start_subsystem(void *arg1, void *arg2)

	spdk_nvmf_subsystem_start(subsystem);

	spdk_poller_register(&app_subsys->poller, subsystem_poll, app_subsys, 0);
	app_subsys->poller = spdk_poller_register(subsystem_poll, app_subsys, 0);
}

void
@@ -275,7 +276,7 @@ nvmf_tgt_create_poll_group(void *arg1, void *arg2)
		SPDK_ERRLOG("Failed to create poll group for core %u\n", g_tgt.core);
	}

	spdk_poller_register(&pg->poller, nvmf_tgt_poll_group_poll, pg, 0);
	pg->poller = spdk_poller_register(nvmf_tgt_poll_group_poll, pg, 0);
	g_active_poll_groups++;

	spdk_event_call(event);
@@ -342,7 +343,7 @@ nvmf_tgt_advance_state(void *arg1, void *arg2)
			break;
		}
		case NVMF_TGT_INIT_START_ACCEPTOR:
			spdk_poller_register(&g_acceptor_poller, acceptor_poll, g_tgt.tgt,
			g_acceptor_poller = spdk_poller_register(acceptor_poll, g_tgt.tgt,
					    g_spdk_nvmf_tgt_conf.acceptor_poll_rate);
			SPDK_NOTICELOG("Acceptor running\n");
			g_tgt.state = NVMF_TGT_RUNNING;
+30 −12
Original line number Diff line number Diff line
@@ -125,9 +125,9 @@ spdk_fio_bdev_init_done(void *cb_arg, int rc)
	*(bool *)cb_arg = true;
}

static void
spdk_fio_start_poller(struct spdk_bdev_poller **ppoller,
		      spdk_bdev_poller_fn fn,
static struct spdk_poller *
spdk_fio_start_poller(void *thread_ctx,
		      spdk_thread_fn fn,
		      void *arg,
		      uint64_t period_microseconds)
{
@@ -137,13 +137,13 @@ spdk_fio_start_poller(struct spdk_bdev_poller **ppoller,
	fio_thread = g_thread;
	if (!fio_thread) {
		SPDK_ERRLOG("Expected local thread to be initialized, but it was not.\n");
		return;
		return NULL;
	}

	fio_poller = calloc(1, sizeof(*fio_poller));
	if (!fio_poller) {
		SPDK_ERRLOG("Unable to allocate poller\n");
		return;
		return NULL;
	}

	fio_poller->cb_fn = fn;
@@ -152,16 +152,25 @@ spdk_fio_start_poller(struct spdk_bdev_poller **ppoller,

	TAILQ_INSERT_TAIL(&fio_thread->pollers, fio_poller, link);

	*ppoller = (struct spdk_bdev_poller *)fio_poller;
	return (struct spdk_poller *)fio_poller;
}

static void
spdk_fio_stop_poller(struct spdk_bdev_poller **ppoller)
spdk_fio_bdev_start_poller(struct spdk_bdev_poller **ppoller,
			   spdk_bdev_poller_fn fn,
			   void *arg,
			   uint64_t period_microseconds)
{
	*ppoller = (struct spdk_bdev_poller *)spdk_poller_register(fn, arg, period_microseconds);
}

static void
spdk_fio_stop_poller(struct spdk_poller *poller, void *thread_ctx)
{
	struct spdk_fio_poller *fio_poller;
	struct spdk_fio_thread *fio_thread;

	fio_poller = *(struct spdk_fio_poller **)ppoller;
	fio_poller = (struct spdk_fio_poller *)poller;

	fio_thread = g_thread;
	if (!fio_thread) {
@@ -172,7 +181,12 @@ spdk_fio_stop_poller(struct spdk_bdev_poller **ppoller)
	TAILQ_REMOVE(&fio_thread->pollers, fio_poller, link);

	free(fio_poller);
	*ppoller = NULL;
}

static void
spdk_fio_bdev_stop_poller(struct spdk_bdev_poller **ppoller)
{
	spdk_poller_unregister((struct spdk_poller **)ppoller);
}

static int
@@ -196,7 +210,11 @@ spdk_fio_init_thread(struct thread_data *td)
		return -1;
	}

	fio_thread->thread = spdk_allocate_thread(spdk_fio_send_msg, fio_thread, "fio_thread");
	fio_thread->thread = spdk_allocate_thread(spdk_fio_send_msg,
			     spdk_fio_start_poller,
			     spdk_fio_stop_poller,
			     fio_thread,
			     "fio_thread");
	if (!fio_thread->thread) {
		spdk_ring_free(fio_thread->ring);
		free(fio_thread);
@@ -280,8 +298,8 @@ spdk_fio_init_env(struct thread_data *td)

	/* Initialize the bdev layer */
	spdk_bdev_initialize(spdk_fio_bdev_init_done, &done,
			     spdk_fio_start_poller,
			     spdk_fio_stop_poller);
			     spdk_fio_bdev_start_poller,
			     spdk_fio_bdev_stop_poller);

	do {
		/* Handle init and all cleanup events */
+0 −15
Original line number Diff line number Diff line
@@ -53,8 +53,6 @@ typedef void (*spdk_event_fn)(void *arg1, void *arg2);
 */
struct spdk_event;

typedef void (*spdk_poller_fn)(void *arg);

/**
 * \brief A poller is a function that is repeatedly called on an lcore.
 */
@@ -185,19 +183,6 @@ struct spdk_event *spdk_event_allocate(uint32_t lcore, spdk_event_fn fn,
 */
void spdk_event_call(struct spdk_event *event);

/**
 * \brief Register a poller on the current lcore.
 */
void spdk_poller_register(struct spdk_poller **ppoller,
			  spdk_poller_fn fn,
			  void *arg,
			  uint64_t period_microseconds);

/**
 * \brief Unregister a poller on the given lcore.
 */
void spdk_poller_unregister(struct spdk_poller **ppoller);

/**
 * \brief Enable or disable monitoring of context switches.
 */
+31 −1
Original line number Diff line number Diff line
@@ -44,11 +44,19 @@

struct spdk_thread;
struct spdk_io_channel;
struct spdk_poller;

typedef void (*spdk_thread_fn)(void *ctx);
typedef void (*spdk_thread_pass_msg)(spdk_thread_fn fn, void *ctx,
				     void *thread_ctx);

typedef void (*spdk_poller_fn)(void *ctx);
typedef struct spdk_poller *(*spdk_start_poller)(void *thread_ctx,
		spdk_poller_fn fn,
		void *arg,
		uint64_t period_microseconds);
typedef void (*spdk_stop_poller)(struct spdk_poller *poller, void *thread_ctx);

typedef int (*spdk_io_channel_create_cb)(void *io_device, void *ctx_buf);
typedef void (*spdk_io_channel_destroy_cb)(void *io_device, void *ctx_buf);

@@ -70,7 +78,10 @@ typedef void (*spdk_channel_for_each_cpl)(void *io_device, void *ctx, int status
 *             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 msg_fn,
		spdk_start_poller start_poller_fn,
		spdk_stop_poller stop_poller_fn,
		void *thread_ctx,
		const char *name);

/**
@@ -105,6 +116,25 @@ const char *spdk_thread_get_name(const struct spdk_thread *thread);
 */
void spdk_thread_send_msg(const struct spdk_thread *thread, spdk_thread_fn fn, void *ctx);

/**
 * \brief Register a poller on the current thread. The poller can be
 * unregistered by calling spdk_poller_unregister().
 *
 * @param fn This function will be called every `period_microseconds`
 * @param arg Passed to fn
 * @param period_microseconds How often to call `fn`. If 0, call `fn` as often as possible.
 */
struct spdk_poller *spdk_poller_register(spdk_thread_fn fn,
		void *arg,
		uint64_t period_microseconds);

/**
 * \brief Unregister a poller on the current thread.
 *
 * @param ppoller The poller to unregister.
 */
void spdk_poller_unregister(struct spdk_poller **ppoller);

/**
 * \brief Register the opaque io_device context as an I/O device.
 *
Loading