Received: by 10.223.148.5 with SMTP id 5csp6278414wrq; Wed, 17 Jan 2018 11:38:47 -0800 (PST) X-Google-Smtp-Source: ACJfBov5iUyoEFu+YVu40Fo3dIMbkA8HwNMq5vUuadqHrK5G5WY/Idluknock87Z+kDltdbkG44e X-Received: by 10.98.11.218 with SMTP id 87mr4528311pfl.99.1516217927779; Wed, 17 Jan 2018 11:38:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516217927; cv=none; d=google.com; s=arc-20160816; b=Eta7HMfrCJQcXHSPFIu+3sCdWiWA+sBuCMFnzxtCis1ph03L3LIrJkw3gPmK+GorKr TlrXm7tC3lTZdkMXM5zOOsoVvEOyMNm8vhzb5246vySlu9SWyHm6F/ZSHl+ApfZqmY/1 UegzIq8dc9ReKWMmJOf0TxhfS+ZTI7gjXob+n/ccdhb9A1ksnxmvevcg9HRe2VtVholM kET73QKnbOXNZlqP5nK5ujNaEmV8TOilqoTabptjyZcKn5j6lxls+yvM72/2lG6DXsWm F6+aqTgVX0siFTb3aHfhz7/r34PsyCG/npV/0Hc02D4/CKXlestrKAqpXHjzqnpD/reE MX9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=MY2ptnAZYiQQPtXTYgcduxajBY/6NK+w75P5FYXeg6s=; b=onOkk69w9hD2HodZqw0N9o3SlSxlfQZSdHCqMxhu9RhoYZ3/uOd62xedSmzbvq2nVI bqrOThdBXnNzz1lHqBuhf/MjYQKav4r5hT1IhWc/13Y2h1rlMS7F9pevZUlNK1iPs4Ff 5C3iwtaGi5TVTOFv43matWi21/R7egeABU5Cq12ASdFpHjMOmwxR4JBAu4EUE0qlwMYs 1QIzn07OEarmXFK/OZ1xQ5Je7uNzpth9YzIyro0k0o6/FWRHN1Sg7VqpKcvHOX2gL7O0 wG/HsWPcC0sqlImNr1LoUOhxuymnJSwJ+WBE0FDO1X5eJ+8ybK5VLShqkcS1VMShggC8 gsfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=AVZT6Cx3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t9si5256187plq.349.2018.01.17.11.38.33; Wed, 17 Jan 2018 11:38:47 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=AVZT6Cx3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753666AbeAQT2m (ORCPT + 99 others); Wed, 17 Jan 2018 14:28:42 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:39197 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753547AbeAQT2i (ORCPT ); Wed, 17 Jan 2018 14:28:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=MY2ptnAZYiQQPtXTYgcduxajBY/6NK+w75P5FYXeg6s=; b=AVZT6Cx3RrbGRWT1sUNwRhYsu tTygphg32bPFMieyUxQei801/xZzAM9JRUNYB5qIHgYbQv6yqPO0By0hqxtGqeA0xZ6d6zEPr3ol+ /AzTEzVgrxQ1haqR+0Ti3VZk4pSNe8gOnMbVIxwIdV8NGDqGJZc5lNbSByNO2yjy4BJszELE4fD4H xD/JCYAXiLZ8rZn25o7wIgAtmBU4S5pIwW0FcAfd5sbFSQwfNHXc+3HD0D+nLUSxktcv3M3fAO6lJ eryUDn7UJ/ldxDQAejDKQw4zsi49WjmFe2zNDHsf/TRg0lD+vtYvjDIPUszh/fsyQ+oR8RWWRdak4 o9wJBAKqQ==; Received: from 77.117.185.35.wireless.dyn.drei.com ([77.117.185.35] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.89 #1 (Red Hat Linux)) id 1ebtO0-00034v-Oz; Wed, 17 Jan 2018 19:28:37 +0000 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 15/36] net: refactor socket_poll Date: Wed, 17 Jan 2018 20:27:21 +0100 Message-Id: <20180117192742.710-16-hch@lst.de> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180117192742.710-1-hch@lst.de> References: <20180117192742.710-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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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