From: Jens Axboe <[email protected]>
To: [email protected]
Cc: [email protected], [email protected],
Jens Axboe <[email protected]>
Subject: [PATCH 2/9] eventpoll: add helper to remove wait entry from wait queue head
Date: Mon, 3 Feb 2025 09:23:40 -0700 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
__epoll_wait_remove() is the core helper, it kills a given
wait_queue_entry from the eventpoll wait_queue_head. Use it internally,
and provide an overall helper, epoll_wait_remove(), which takes a struct
file and provides the same functionality.
Signed-off-by: Jens Axboe <[email protected]>
---
fs/eventpoll.c | 58 +++++++++++++++++++++++++--------------
include/linux/eventpoll.h | 3 ++
2 files changed, 40 insertions(+), 21 deletions(-)
diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index 73b639caed3d..01edbee5c766 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -1980,6 +1980,42 @@ static int ep_autoremove_wake_function(struct wait_queue_entry *wq_entry,
return ret;
}
+static int __epoll_wait_remove(struct eventpoll *ep,
+ struct wait_queue_entry *wait, int timed_out)
+{
+ int eavail;
+
+ /*
+ * We were woken up, thus go and try to harvest some events. If timed
+ * out and still on the wait queue, recheck eavail carefully under
+ * lock, below.
+ */
+ eavail = 1;
+
+ if (!list_empty_careful(&wait->entry)) {
+ write_lock_irq(&ep->lock);
+ /*
+ * If the thread timed out and is not on the wait queue, it
+ * means that the thread was woken up after its timeout expired
+ * before it could reacquire the lock. Thus, when wait.entry is
+ * empty, it needs to harvest events.
+ */
+ if (timed_out)
+ eavail = list_empty(&wait->entry);
+ __remove_wait_queue(&ep->wq, wait);
+ write_unlock_irq(&ep->lock);
+ }
+
+ return eavail;
+}
+
+int epoll_wait_remove(struct file *file, struct wait_queue_entry *wait)
+{
+ if (is_file_epoll(file))
+ return __epoll_wait_remove(file->private_data, wait, false);
+ return -EINVAL;
+}
+
/**
* ep_poll - Retrieves ready events, and delivers them to the caller-supplied
* event buffer.
@@ -2100,27 +2136,7 @@ static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events,
HRTIMER_MODE_ABS);
__set_current_state(TASK_RUNNING);
- /*
- * We were woken up, thus go and try to harvest some events.
- * If timed out and still on the wait queue, recheck eavail
- * carefully under lock, below.
- */
- eavail = 1;
-
- if (!list_empty_careful(&wait.entry)) {
- write_lock_irq(&ep->lock);
- /*
- * If the thread timed out and is not on the wait queue,
- * it means that the thread was woken up after its
- * timeout expired before it could reacquire the lock.
- * Thus, when wait.entry is empty, it needs to harvest
- * events.
- */
- if (timed_out)
- eavail = list_empty(&wait.entry);
- __remove_wait_queue(&ep->wq, &wait);
- write_unlock_irq(&ep->lock);
- }
+ eavail = __epoll_wait_remove(ep, &wait, timed_out);
}
}
diff --git a/include/linux/eventpoll.h b/include/linux/eventpoll.h
index f37fea931c44..1301fc74aca0 100644
--- a/include/linux/eventpoll.h
+++ b/include/linux/eventpoll.h
@@ -29,6 +29,9 @@ void eventpoll_release_file(struct file *file);
int epoll_wait(struct file *file, struct epoll_event __user *events,
int maxevents, struct timespec64 *to);
+/* Remove wait entry */
+int epoll_wait_remove(struct file *file, struct wait_queue_entry *wait);
+
/*
* This is called from inside fs/file_table.c:__fput() to unlink files
* from the eventpoll interface. We need to have this facility to cleanup
--
2.47.2
next prev parent reply other threads:[~2025-02-03 16:31 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-03 16:23 [PATCHSET 0/9] io_uring epoll wait support Jens Axboe
2025-02-03 16:23 ` [PATCH 1/9] eventpoll: abstract out main epoll reaper into a function Jens Axboe
2025-02-03 16:23 ` Jens Axboe [this message]
2025-02-03 16:23 ` [PATCH 3/9] eventpoll: abstract out ep_try_send_events() helper Jens Axboe
2025-02-03 16:23 ` [PATCH 4/9] eventpoll: add struct wait_queue_entry argument to epoll_wait() Jens Axboe
2025-02-03 16:23 ` [PATCH 5/9] eventpoll: add ep_poll_queue() loop Jens Axboe
2025-02-03 16:23 ` [PATCH 6/9] io_uring/epoll: remove CONFIG_EPOLL guards Jens Axboe
2025-02-03 16:23 ` [PATCH 7/9] io_uring/poll: pull ownership handling into poll.h Jens Axboe
2025-02-03 16:23 ` [PATCH 8/9] io_uring/epoll: add support for IORING_OP_EPOLL_WAIT Jens Axboe
2025-02-03 16:23 ` [PATCH 9/9] io_uring/epoll: add multishot " Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox