Commit df96ddcc authored by Krzysztof Goreczny's avatar Krzysztof Goreczny Committed by Tomasz Zawadzki
Browse files

thread: Add API that allows to select interrupt event type



New API call spdk_interrupt_register_for_events() - variant of
spdk_interrupt_register() with additional event type argument.

It's needed to use interrupt mode also on events other than the
SPDK_INTERRUPT_EVENT_IN.

Change-Id: Ied1d3faf737c7efb028075eadb722b72234b9363
Signed-off-by: default avatarKrzysztof Goreczny <krzysztof.goreczny@dell.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/23030


Reviewed-by: default avatarBoris Glimcher <Boris.Glimcher@emc.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
parent ab7269b7
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -2,6 +2,11 @@

## v24.09: (Upcoming Release)

### thread

New function `spdk_interrupt_register_for_events()` build on top of `spdk_fd_group_add_for_events()`.
See below for details.

### util

New function `spdk_fd_group_add_for_events()` was added alongside the existing `spdk_fd_group_add()`.
+32 −2
Original line number Diff line number Diff line
@@ -827,8 +827,10 @@ struct spdk_interrupt;
typedef int (*spdk_interrupt_fn)(void *ctx);

/**
 * Register an spdk_interrupt on the current thread. The provided function
 * will be called any time the associated file descriptor is written to.
 * Register an spdk_interrupt on the current thread.
 *
 * The provided function will be called any time a SPDK_INTERRUPT_EVENT_IN event
 * triggers on the associated file descriptor.
 *
 * \param efd File descriptor of the spdk_interrupt.
 * \param fn Called each time there are events in spdk_interrupt.
@@ -842,6 +844,27 @@ typedef int (*spdk_interrupt_fn)(void *ctx);
struct spdk_interrupt *spdk_interrupt_register(int efd, spdk_interrupt_fn fn,
		void *arg, const char *name);

/**
 * Register an spdk_interrupt with specific event types on the current thread.
 *
 * The provided function will be called any time one of specified event types triggers on
 * the associated file descriptor.
 * Event types argument is a bit mask composed by ORing together
 * enum spdk_interrupt_event_types values.
 *
 * \param efd File descriptor of the spdk_interrupt.
 * \param events Event notification types.
 * \param fn Called each time there are events in spdk_interrupt.
 * \param arg Function argument for fn.
 * \param name Human readable name for the spdk_interrupt. Pointer of the spdk_interrupt
 * name is set if NULL.
 *
 * \return a pointer to the spdk_interrupt registered on the current thread on success
 * or NULL on failure.
 */
struct spdk_interrupt *spdk_interrupt_register_for_events(int efd, uint32_t events,
		spdk_interrupt_fn fn, void *arg, const char *name);

/*
 * \brief Register an spdk_interrupt on the current thread with setting its name
 * to the string of the spdk_interrupt function name.
@@ -849,6 +872,13 @@ struct spdk_interrupt *spdk_interrupt_register(int efd, spdk_interrupt_fn fn,
#define SPDK_INTERRUPT_REGISTER(efd, fn, arg)	\
	spdk_interrupt_register(efd, fn, arg, #fn)

/*
 * \brief Register an spdk_interrupt on the current thread with specific event types
 * and with setting its name to the string of the spdk_interrupt function name.
 */
#define SPDK_INTERRUPT_REGISTER_FOR_EVENTS(efd, events, fn, arg)	\
	spdk_interrupt_register_for_events(efd, events, fn, arg, #fn)

/**
 * Unregister an spdk_interrupt on the current thread.
 *
+1 −1
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk

SO_VER := 10
SO_MINOR := 0
SO_MINOR := 1

C_SRCS = thread.c iobuf.c
LIBNAME = thread
+1 −0
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@
	spdk_io_channel_iter_get_ctx;
	spdk_for_each_channel_continue;
	spdk_interrupt_register;
	spdk_interrupt_register_for_events;
	spdk_interrupt_unregister;
	spdk_interrupt_set_event_types;
	spdk_thread_get_interrupt_fd;
+8 −1
Original line number Diff line number Diff line
@@ -2815,6 +2815,13 @@ _interrupt_wrapper(void *ctx)
struct spdk_interrupt *
spdk_interrupt_register(int efd, spdk_interrupt_fn fn,
			void *arg, const char *name)
{
	return spdk_interrupt_register_for_events(efd, SPDK_INTERRUPT_EVENT_IN, fn, arg, name);
}

struct spdk_interrupt *
spdk_interrupt_register_for_events(int efd, uint32_t events, spdk_interrupt_fn fn, void *arg,
				   const char *name)
{
	struct spdk_thread *thread;
	struct spdk_interrupt *intr;
@@ -2848,7 +2855,7 @@ spdk_interrupt_register(int efd, spdk_interrupt_fn fn,
	intr->fn = fn;
	intr->arg = arg;

	ret = spdk_fd_group_add(thread->fgrp, efd, _interrupt_wrapper, intr, intr->name);
	ret = spdk_fd_group_add_for_events(thread->fgrp, efd, events, _interrupt_wrapper, intr, intr->name);

	if (ret != 0) {
		SPDK_ERRLOG("thread %s: failed to add fd %d: %s\n",