Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966045AbeAJP7O (ORCPT + 1 other); Wed, 10 Jan 2018 10:59:14 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:55750 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965901AbeAJP7M (ORCPT ); Wed, 10 Jan 2018 10:59:12 -0500 From: Christoph Hellwig To: viro@zeniv.linux.org.uk Cc: Avi Kivity , linux-aio@kvack.org, linux-fsdevel@vger.kernel.org, netdev@vger.kernel.org, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 04/32] net: refactor socket_poll Date: Wed, 10 Jan 2018 16:58:25 +0100 Message-Id: <20180110155853.32348-5-hch@lst.de> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180110155853.32348-1-hch@lst.de> References: <20180110155853.32348-1-hch@lst.de> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: Factor out two busy poll related helpers for late reuse, and remove a command that isn't very helpful, especially with the __poll_t annotations in place. Signed-off-by: Christoph Hellwig --- include/net/busy_poll.h | 15 +++++++++++++++ net/socket.c | 21 ++++----------------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/include/net/busy_poll.h b/include/net/busy_poll.h index 71c72a939bf8..c5187438af38 100644 --- a/include/net/busy_poll.h +++ b/include/net/busy_poll.h @@ -121,6 +121,21 @@ static inline void sk_busy_loop(struct sock *sk, int nonblock) #endif } +static inline void sock_poll_busy_loop(struct socket *sock, __poll_t events) +{ + if (sk_can_busy_loop(sock->sk) && + events && (events & POLL_BUSY_LOOP)) { + /* once, only if requested by syscall */ + sk_busy_loop(sock->sk, 1); + } +} + +/* if this socket can poll_ll, tell the system call */ +static inline __poll_t sock_poll_busy_flag(struct socket *sock) +{ + return sk_can_busy_loop(sock->sk) ? POLL_BUSY_LOOP : 0; +} + /* used in the NIC receive handler to mark the skb */ static inline void skb_mark_napi_id(struct sk_buff *skb, struct napi_struct *napi) diff --git a/net/socket.c b/net/socket.c index 092baa464afc..db11e48a375b 100644 --- a/net/socket.c +++ b/net/socket.c @@ -1097,24 +1097,11 @@ EXPORT_SYMBOL(sock_create_lite); /* No kernel lock held - perfect */ static __poll_t sock_poll(struct file *file, poll_table *wait) { - __poll_t busy_flag = 0; - struct socket *sock; - - /* - * We can't return errors to poll, so it's either yes or no. - */ - sock = file->private_data; - - if (sk_can_busy_loop(sock->sk)) { - /* this socket can poll_ll so tell the system call */ - busy_flag = POLL_BUSY_LOOP; - - /* once, only if requested by syscall */ - if (wait && (wait->_key & POLL_BUSY_LOOP)) - sk_busy_loop(sock->sk, 1); - } + struct socket *sock = file->private_data; + __poll_t events = poll_requested_events(wait); - return busy_flag | sock->ops->poll(file, sock, wait); + sock_poll_busy_loop(sock, events); + return sock->ops->poll(file, sock, wait) | sock_poll_busy_flag(sock); } static int sock_mmap(struct file *file, struct vm_area_struct *vma) -- 2.14.2