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@xxxxxxx> Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> Cc: Davidlohr Bueso <dbueso@xxxxxxx> Cc: Jason Baron <jbaron@xxxxxxxxxx> Cc: Al Viro <viro@xxxxxxxxxxxxxxxxxx> Cc: "Paul E. McKenney" <paulmck@xxxxxxxxxxxxxxxxxx> Cc: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> Cc: Andrea Parri <andrea.parri@xxxxxxxxxxxxxxxxxxxx> Cc: linux-fsdevel@xxxxxxxxxxxxxxx Cc: linux-kernel@xxxxxxxxxxxxxxx --- 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