[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20190109164025.24554-7-rpenyaev@suse.de>
Date: Wed, 9 Jan 2019 17:40:16 +0100
From: Roman Penyaev <rpenyaev@...e.de>
To: unlisted-recipients:; (no To-header on input)
Cc: Roman Penyaev <rpenyaev@...e.de>,
Andrew Morton <akpm@...ux-foundation.org>,
Davidlohr Bueso <dbueso@...e.de>,
Jason Baron <jbaron@...mai.com>,
Al Viro <viro@...iv.linux.org.uk>,
"Paul E. McKenney" <paulmck@...ux.vnet.ibm.com>,
Linus Torvalds <torvalds@...ux-foundation.org>,
Andrea Parri <andrea.parri@...rulasolutions.com>,
linux-fsdevel@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [RFC PATCH 06/15] epoll: introduce various of helpers for user structure lengths calculations
Helpers for lengths-from-number and number-from-lengths calculations.
Among them:
ep_polled_by_user()
- returns true if epoll was created with EPOLL_USERPOLL
ep_user_ring_events_available()
- returns true if there is something in user ring buffer
Signed-off-by: Roman Penyaev <rpenyaev@...e.de>
Cc: Andrew Morton <akpm@...ux-foundation.org>
Cc: Davidlohr Bueso <dbueso@...e.de>
Cc: Jason Baron <jbaron@...mai.com>
Cc: Al Viro <viro@...iv.linux.org.uk>
Cc: "Paul E. McKenney" <paulmck@...ux.vnet.ibm.com>
Cc: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: Andrea Parri <andrea.parri@...rulasolutions.com>
Cc: linux-fsdevel@...r.kernel.org
Cc: linux-kernel@...r.kernel.org
---
fs/eventpoll.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 59 insertions(+)
diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index 9ec682b6488f..ae288f62aa4c 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -438,6 +438,65 @@ static void ep_nested_calls_init(struct nested_calls *ncalls)
spin_lock_init(&ncalls->lock);
}
+static inline unsigned int to_items_length(unsigned int nr)
+{
+ struct eventpoll *ep;
+
+ return (sizeof(*ep->user_header) +
+ (nr << ilog2(sizeof(ep->user_header->items[0]))));
+}
+
+static inline unsigned int to_index_length(unsigned int nr)
+{
+ struct eventpoll *ep;
+
+ return nr << ilog2(sizeof(*ep->user_index));
+}
+
+static inline unsigned int to_items_bm_length(unsigned int nr)
+{
+ return ALIGN(nr, 8) >> 3;
+}
+
+static inline unsigned int to_items_nr(unsigned int len)
+{
+ struct eventpoll *ep;
+
+ return (len - sizeof(*ep->user_header)) >>
+ ilog2(sizeof(ep->user_header->items[0]));
+}
+
+static inline unsigned int to_items_bm_nr(unsigned int len)
+{
+ return len << 3;
+}
+
+static inline unsigned int ep_max_items_nr(struct eventpoll *ep)
+{
+ return to_items_nr(ep->header_length);
+}
+
+static inline unsigned int ep_max_index_nr(struct eventpoll *ep)
+{
+ return ep->index_length >> ilog2(sizeof(*ep->user_index));
+}
+
+static inline unsigned int ep_max_items_bm_nr(struct eventpoll *ep)
+{
+ return to_items_bm_nr(ep->items_bm_length);
+}
+
+static inline bool ep_polled_by_user(struct eventpoll *ep)
+{
+ return !!ep->user_header;
+}
+
+static inline bool ep_user_ring_events_available(struct eventpoll *ep)
+{
+ return ep_polled_by_user(ep) &&
+ ep->user_header->head != ep->user_header->tail;
+}
+
/**
* ep_events_available - Checks if ready events might be available.
*
--
2.19.1
Powered by blists - more mailing lists