[v2] eal/interrupts: add function to allow interruptible epoll
Checks
Commit Message
The existing definition of rte_epoll_wait retries if interrupted
by a signal. This behavior makes it hard to use rte_epoll_wait
for applications that want to use signals do do things like
exit polling loop and shutdown.
Since changing existing semantic might break applications, add
a new rte_epoll_wait_interruptible() function that does the
same thing as rte_epoll_wait but will return -1 and errno of EINTR
if it receives a signal.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Reviewed-by: Harman Kalra <hkalra@marvell.com>
---
v2 -- rebase onto current code organization
simplify logic to make it clear how common the code is
Note: the documentation of the new version is intentionally the
the same as the original one.
lib/librte_eal/freebsd/eal_interrupts.c | 12 +++++++++
lib/librte_eal/include/rte_eal_interrupts.h | 23 +++++++++++++++++
lib/librte_eal/linux/eal_interrupts.c | 28 +++++++++++++++++----
lib/librte_eal/rte_eal_version.map | 3 +++
4 files changed, 61 insertions(+), 5 deletions(-)
Comments
On Fri, Sep 4, 2020 at 1:28 AM Stephen Hemminger
<stephen@networkplumber.org> wrote:
>
> The existing definition of rte_epoll_wait retries if interrupted
> by a signal. This behavior makes it hard to use rte_epoll_wait
> for applications that want to use signals do do things like
> exit polling loop and shutdown.
>
> Since changing existing semantic might break applications, add
> a new rte_epoll_wait_interruptible() function that does the
> same thing as rte_epoll_wait but will return -1 and errno of EINTR
> if it receives a signal.
>
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> Reviewed-by: Harman Kalra <hkalra@marvell.com>
You will certainly argue that the existing function had no unit test
but we want to fix this at some point.
Can a unit test be added?
Thanks.
On Mon, 14 Sep 2020 10:56:33 +0200
David Marchand <david.marchand@redhat.com> wrote:
> On Fri, Sep 4, 2020 at 1:28 AM Stephen Hemminger
> <stephen@networkplumber.org> wrote:
> >
> > The existing definition of rte_epoll_wait retries if interrupted
> > by a signal. This behavior makes it hard to use rte_epoll_wait
> > for applications that want to use signals do do things like
> > exit polling loop and shutdown.
> >
> > Since changing existing semantic might break applications, add
> > a new rte_epoll_wait_interruptible() function that does the
> > same thing as rte_epoll_wait but will return -1 and errno of EINTR
> > if it receives a signal.
> >
> > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> > Reviewed-by: Harman Kalra <hkalra@marvell.com>
>
> You will certainly argue that the existing function had no unit test
> but we want to fix this at some point.
> Can a unit test be added?
The whole interrupt system really has no test, if it did then epoll
would be part of that.
04/09/2020 01:28, Stephen Hemminger:
> The existing definition of rte_epoll_wait retries if interrupted
> by a signal. This behavior makes it hard to use rte_epoll_wait
> for applications that want to use signals do do things like
> exit polling loop and shutdown.
>
> Since changing existing semantic might break applications, add
> a new rte_epoll_wait_interruptible() function that does the
> same thing as rte_epoll_wait but will return -1 and errno of EINTR
> if it receives a signal.
>
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> Reviewed-by: Harman Kalra <hkalra@marvell.com>
Applied, thanks
@@ -684,6 +684,18 @@ rte_epoll_wait(int epfd, struct rte_epoll_event *events,
return -ENOTSUP;
}
+int
+rte_epoll_wait_interruptible(int epfd, struct rte_epoll_event *events,
+ int maxevents, int timeout)
+{
+ RTE_SET_USED(epfd);
+ RTE_SET_USED(events);
+ RTE_SET_USED(maxevents);
+ RTE_SET_USED(timeout);
+
+ return -ENOTSUP;
+}
+
int
rte_epoll_ctl(int epfd, int op, int fd, struct rte_epoll_event *event)
{
@@ -87,6 +87,7 @@ struct rte_intr_handle {
/**
* It waits for events on the epoll instance.
+ * Retries if signal received.
*
* @param epfd
* Epoll instance fd on which the caller wait for events.
@@ -105,6 +106,28 @@ int
rte_epoll_wait(int epfd, struct rte_epoll_event *events,
int maxevents, int timeout);
+/**
+ * It waits for events on the epoll instance.
+ * Does not retry if signal received.
+ *
+ * @param epfd
+ * Epoll instance fd on which the caller wait for events.
+ * @param events
+ * Memory area contains the events that will be available for the caller.
+ * @param maxevents
+ * Up to maxevents are returned, must greater than zero.
+ * @param timeout
+ * Specifying a timeout of -1 causes a block indefinitely.
+ * Specifying a timeout equal to zero cause to return immediately.
+ * @return
+ * - On success, returns the number of available event.
+ * - On failure, a negative value.
+ */
+__rte_experimental
+int
+rte_epoll_wait_interruptible(int epfd, struct rte_epoll_event *events,
+ int maxevents, int timeout);
+
/**
* It performs control operations on epoll instance referred by the epfd.
* It requests that the operation op be performed for the target fd.
@@ -1275,9 +1275,9 @@ rte_intr_tls_epfd(void)
return RTE_PER_LCORE(_epfd);
}
-int
-rte_epoll_wait(int epfd, struct rte_epoll_event *events,
- int maxevents, int timeout)
+static int
+eal_epoll_wait(int epfd, struct rte_epoll_event *events,
+ int maxevents, int timeout, bool interruptible)
{
struct epoll_event evs[maxevents];
int rc;
@@ -1298,8 +1298,12 @@ rte_epoll_wait(int epfd, struct rte_epoll_event *events,
rc = eal_epoll_process_event(evs, rc, events);
break;
} else if (rc < 0) {
- if (errno == EINTR)
- continue;
+ if (errno == EINTR) {
+ if (interruptible)
+ return -1;
+ else
+ continue;
+ }
/* epoll_wait fail */
RTE_LOG(ERR, EAL, "epoll_wait returns with fail %s\n",
strerror(errno));
@@ -1314,6 +1318,20 @@ rte_epoll_wait(int epfd, struct rte_epoll_event *events,
return rc;
}
+int
+rte_epoll_wait(int epfd, struct rte_epoll_event *events,
+ int maxevents, int timeout)
+{
+ return eal_epoll_wait(epfd, events, maxevents, timeout, false);
+}
+
+int
+rte_epoll_wait_interruptible(int epfd, struct rte_epoll_event *events,
+ int maxevents, int timeout)
+{
+ return eal_epoll_wait(epfd, events, maxevents, timeout, true);
+}
+
static inline void
eal_epoll_data_safe_free(struct rte_epoll_event *ev)
{
@@ -397,6 +397,9 @@ EXPERIMENTAL {
rte_mp_disable;
rte_thread_register;
rte_thread_unregister;
+
+ # added in 20.11
+ rte_epoll_wait_interruptible;
};
INTERNAL {