From patchwork Wed Jan 9 16:40:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Penyaev X-Patchwork-Id: 10754529 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5E0ED13BF for ; Wed, 9 Jan 2019 16:42:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E24B29503 for ; Wed, 9 Jan 2019 16:42:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 41EE62950E; Wed, 9 Jan 2019 16:42:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CA40929507 for ; Wed, 9 Jan 2019 16:42:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726869AbfAIQmB (ORCPT ); Wed, 9 Jan 2019 11:42:01 -0500 Received: from mx2.suse.de ([195.135.220.15]:57620 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726586AbfAIQkk (ORCPT ); Wed, 9 Jan 2019 11:40:40 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id DE35CAF91; Wed, 9 Jan 2019 16:40:38 +0000 (UTC) From: Roman Penyaev Cc: Roman Penyaev , Andrew Morton , Davidlohr Bueso , Jason Baron , Al Viro , "Paul E. McKenney" , Linus Torvalds , Andrea Parri , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 06/15] epoll: introduce various of helpers for user structure lengths calculations Date: Wed, 9 Jan 2019 17:40:16 +0100 Message-Id: <20190109164025.24554-7-rpenyaev@suse.de> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190109164025.24554-1-rpenyaev@suse.de> References: <20190109164025.24554-1-rpenyaev@suse.de> MIME-Version: 1.0 To: unlisted-recipients:; (no To-header on input) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Cc: Andrew Morton Cc: Davidlohr Bueso Cc: Jason Baron Cc: Al Viro Cc: "Paul E. McKenney" Cc: Linus Torvalds Cc: Andrea Parri Cc: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.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. *