Commit 29f02008 authored by Krzysztof Goreczny's avatar Krzysztof Goreczny Committed by Jim Harris
Browse files

sock: Add interrupt APIs for socket groups



Add spdk_sock_group_register_interrupt() API for setting interrupts on
the socket groups.
Only POSIX and SSL sockets are supported.

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


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

## v24.09: (Upcoming Release)

### sock

New functions that allows to register interrupt for given socket group:
`spdk_sock_group_register_interrupt()`
`spdk_sock_group_unregister_interrupt()`
Both uses API exposed by the thread.h, see below for details.
Support implemented only for the POSIX and SSL sockets.

### thread

New function `spdk_interrupt_register_for_events()` build on top of `spdk_fd_group_add_for_events()`.
+34 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
#include "spdk/queue.h"
#include "spdk/json.h"
#include "spdk/assert.h"
#include "spdk/thread.h"

#ifdef __cplusplus
extern "C" {
@@ -645,6 +646,39 @@ const char *spdk_sock_get_default_impl(void);;
 */
void spdk_sock_write_config_json(struct spdk_json_write_ctx *w);

/**
 * Register an spdk_interrupt with specific event types on the current thread for the given socket group.
 *
 * 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 group Socket group.
 * \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.
 *
 * \return 0 on success or non-zero on failure.
 */
int spdk_sock_group_register_interrupt(struct spdk_sock_group *group, uint32_t events,
				       spdk_interrupt_fn fn, void *arg, const char *name);

/*
 * \brief Register an spdk_interrupt on the current thread for the given socket group
 * and with setting its name to the string of the spdk_interrupt function name.
 */
#define SPDK_SOCK_GROUP_REGISTER_INTERRUPT(sock, events, fn, arg)	\
	spdk_sock_group_register_interrupt(sock, events, fn, arg, #fn)

/**
 * Unregister an spdk_interrupt for the given socket group from the current thread.
 *
 * \param group Socket group.
 */
void spdk_sock_group_unregister_interrupt(struct spdk_sock_group *group);

#ifdef __cplusplus
}
#endif
+3 −0
Original line number Diff line number Diff line
@@ -108,6 +108,9 @@ struct spdk_net_impl {
	int (*group_impl_remove_sock)(struct spdk_sock_group_impl *group, struct spdk_sock *sock);
	int (*group_impl_poll)(struct spdk_sock_group_impl *group, int max_events,
			       struct spdk_sock **socks);
	int (*group_impl_register_interrupt)(struct spdk_sock_group_impl *group, uint32_t events,
					     spdk_interrupt_fn fn, void *arg, const char *name);
	void (*group_impl_unregister_interrupt)(struct spdk_sock_group_impl *group);
	int (*group_impl_close)(struct spdk_sock_group_impl *group);

	int (*get_opts)(struct spdk_sock_impl_opts *opts, size_t *len);
+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 := 9
SO_VER := 10
SO_MINOR := 0

C_SRCS = sock.c sock_rpc.c
+34 −0
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@
#include "spdk/env.h"
#include "spdk/util.h"
#include "spdk/trace.h"
#include "spdk/thread.h"
#include "spdk_internal/trace_defs.h"

#define SPDK_SOCK_DEFAULT_PRIORITY 0
@@ -957,6 +958,39 @@ spdk_sock_get_default_impl(void)
	return NULL;
}

int
spdk_sock_group_register_interrupt(struct spdk_sock_group *group, uint32_t events,
				   spdk_interrupt_fn fn,
				   void *arg, const char *name)
{
	struct spdk_sock_group_impl *group_impl = NULL;
	int rc;

	assert(group != NULL);
	assert(fn != NULL);

	STAILQ_FOREACH_FROM(group_impl, &group->group_impls, link) {
		rc = group_impl->net_impl->group_impl_register_interrupt(group_impl, events, fn, arg, name);
		if (rc != 0) {
			return rc;
		}
	}

	return 0;
}

void
spdk_sock_group_unregister_interrupt(struct spdk_sock_group *group)
{
	struct spdk_sock_group_impl *group_impl = NULL;

	assert(group != NULL);

	STAILQ_FOREACH_FROM(group_impl, &group->group_impls, link) {
		group_impl->net_impl->group_impl_unregister_interrupt(group_impl);
	}
}

SPDK_LOG_REGISTER_COMPONENT(sock)

SPDK_TRACE_REGISTER_FN(sock_trace, "sock", TRACE_GROUP_SOCK)
Loading