diff --git a/CHANGELOG.md b/CHANGELOG.md index 98b9de5f4..f46ab93a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -76,6 +76,10 @@ Added `spdk_nvme_ctrlr_get_opts` to retrieve the current controller options. Updated DPDK submodule to DPDK 21.08. +### util + +The `spdk_fd_group_add` API now takes a `name` parameter. + ## v21.07 ### accel_fw diff --git a/include/spdk/fd_group.h b/include/spdk/fd_group.h index 3a16ab5cd..5aac1e10b 100644 --- a/include/spdk/fd_group.h +++ b/include/spdk/fd_group.h @@ -110,11 +110,19 @@ int spdk_fd_group_get_fd(struct spdk_fd_group *fgrp); * \param efd File descriptor of the event source. * \param fn Called each time there are events in event source. * \param arg Function argument for fn. + * \param name Name of the event source. * * \return 0 if success or -errno if failed */ -int spdk_fd_group_add(struct spdk_fd_group *fgrp, - int efd, spdk_fd_fn fn, void *arg); +int spdk_fd_group_add(struct spdk_fd_group *fgrp, int efd, + spdk_fd_fn fn, void *arg, const char *name); + +/* + * \brief Register an event source with the name set to the string of the + * callback function. + */ +#define SPDK_FD_GROUP_ADD(fgrp, efd, fn, arg) \ + spdk_fd_group_add(fgrp, efd, fn, arg, #fn) /** * Unregister one event source from one fgrp. diff --git a/lib/event/reactor.c b/lib/event/reactor.c index 695b0e1bd..e825a79c6 100644 --- a/lib/event/reactor.c +++ b/lib/event/reactor.c @@ -1150,7 +1150,8 @@ _schedule_thread(void *arg1, void *arg2) int rc; efd = spdk_thread_get_interrupt_fd(thread); - rc = spdk_fd_group_add(reactor->fgrp, efd, thread_process_interrupts, thread); + rc = SPDK_FD_GROUP_ADD(reactor->fgrp, efd, + thread_process_interrupts, thread); if (rc < 0) { SPDK_ERRLOG("Failed to schedule spdk_thread: %s.\n", spdk_strerror(-rc)); } @@ -1413,7 +1414,7 @@ reactor_interrupt_init(struct spdk_reactor *reactor) goto err; } - rc = spdk_fd_group_add(reactor->fgrp, reactor->resched_fd, reactor_schedule_thread_event, + rc = SPDK_FD_GROUP_ADD(reactor->fgrp, reactor->resched_fd, reactor_schedule_thread_event, reactor); if (rc) { close(reactor->resched_fd); @@ -1429,7 +1430,7 @@ reactor_interrupt_init(struct spdk_reactor *reactor) goto err; } - rc = spdk_fd_group_add(reactor->fgrp, reactor->events_fd, + rc = SPDK_FD_GROUP_ADD(reactor->fgrp, reactor->events_fd, event_queue_run_batch, reactor); if (rc) { spdk_fd_group_remove(reactor->fgrp, reactor->resched_fd); diff --git a/lib/thread/thread.c b/lib/thread/thread.c index c7218939a..5dc7f3ecb 100644 --- a/lib/thread/thread.c +++ b/lib/thread/thread.c @@ -1263,8 +1263,7 @@ period_poller_interrupt_init(struct spdk_poller *poller) return -errno; } - rc = spdk_fd_group_add(fgrp, timerfd, - interrupt_timerfd_process, poller); + rc = SPDK_FD_GROUP_ADD(fgrp, timerfd, interrupt_timerfd_process, poller); if (rc < 0) { close(timerfd); return rc; @@ -1352,7 +1351,8 @@ busy_poller_interrupt_init(struct spdk_poller *poller) return -errno; } - rc = spdk_fd_group_add(poller->thread->fgrp, busy_efd, poller->fn, poller->arg); + rc = spdk_fd_group_add(poller->thread->fgrp, busy_efd, + poller->fn, poller->arg, poller->name); if (rc < 0) { close(busy_efd); return rc; @@ -2487,7 +2487,8 @@ thread_interrupt_create(struct spdk_thread *thread) return rc; } - return spdk_fd_group_add(thread->fgrp, thread->msg_fd, thread_interrupt_msg_process, thread); + return SPDK_FD_GROUP_ADD(thread->fgrp, thread->msg_fd, + thread_interrupt_msg_process, thread); } #else static int @@ -2516,7 +2517,7 @@ spdk_interrupt_register(int efd, spdk_interrupt_fn fn, return NULL; } - ret = spdk_fd_group_add(thread->fgrp, efd, fn, arg); + ret = spdk_fd_group_add(thread->fgrp, efd, fn, arg, name); if (ret != 0) { SPDK_ERRLOG("thread %s: failed to add fd %d: %s\n", diff --git a/lib/util/Makefile b/lib/util/Makefile index f08543de6..5acca39c3 100644 --- a/lib/util/Makefile +++ b/lib/util/Makefile @@ -34,8 +34,8 @@ SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..) include $(SPDK_ROOT_DIR)/mk/spdk.common.mk -SO_VER := 3 -SO_MINOR := 1 +SO_VER := 4 +SO_MINOR := 0 C_SRCS = base64.c bit_array.c cpuset.c crc16.c crc32.c crc32c.c crc32_ieee.c \ dif.c fd.c file.c iov.c math.c pipe.c strerror_tls.c string.c uuid.c \ diff --git a/lib/util/fd_group.c b/lib/util/fd_group.c index 217ca43f1..1f69ad2bd 100644 --- a/lib/util/fd_group.c +++ b/lib/util/fd_group.c @@ -39,6 +39,8 @@ #include #endif +#define SPDK_MAX_EVENT_NAME_LEN 256 + enum event_handler_state { /* The event_handler is added into an fd_group waiting for event, * but not currently in the execution of a wait loop. @@ -63,6 +65,7 @@ struct event_handler { void *fn_arg; /* file descriptor of the interrupt event */ int fd; + char name[SPDK_MAX_EVENT_NAME_LEN + 1]; }; struct spdk_fd_group { @@ -82,8 +85,8 @@ spdk_fd_group_get_fd(struct spdk_fd_group *fgrp) #ifdef __linux__ int -spdk_fd_group_add(struct spdk_fd_group *fgrp, - int efd, spdk_fd_fn fn, void *arg) +spdk_fd_group_add(struct spdk_fd_group *fgrp, int efd, spdk_fd_fn fn, + void *arg, const char *name) { struct event_handler *ehdlr = NULL; struct epoll_event epevent = {0}; @@ -111,6 +114,7 @@ spdk_fd_group_add(struct spdk_fd_group *fgrp, ehdlr->fn = fn; ehdlr->fn_arg = arg; ehdlr->state = EVENT_HANDLER_STATE_WAITING; + snprintf(ehdlr->name, sizeof(ehdlr->name), "%s", name); epevent.events = EPOLLIN; epevent.data.ptr = ehdlr; @@ -313,8 +317,8 @@ spdk_fd_group_wait(struct spdk_fd_group *fgrp, int timeout) #else int -spdk_fd_group_add(struct spdk_fd_group *fgrp, - int efd, spdk_fd_fn fn, void *arg) +spdk_fd_group_add(struct spdk_fd_group *fgrp, int efd, spdk_fd_fn fn, + void *arg, const char *name) { return -ENOTSUP; }