From patchwork Tue Feb 13 06:16:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Damato X-Patchwork-Id: 200236 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp354035dyb; Mon, 12 Feb 2024 22:18:08 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWfLTa/FH26wG7/30Bssi5UTGL39qJQn2xcwvw/LWsgICnnqjGqKDKhUOl+VXNP1HkfQSmPjOdOTRmoqVrk+FIM3+9h5g== X-Google-Smtp-Source: AGHT+IGVbjNVH0FvnR40OagAIp1gwTvTtm4SRwR4/NIZPTeg9ED2xB1d4htbFKknaDWRsLWp0ZNr X-Received: by 2002:a05:622a:104c:b0:42d:aa92:ce2 with SMTP id f12-20020a05622a104c00b0042daa920ce2mr1993868qte.27.1707805088433; Mon, 12 Feb 2024 22:18:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707805088; cv=pass; d=google.com; s=arc-20160816; b=O/pu5SNsIuYsrSqxLWsus8V3DyMS8ZO/rGumGrYFdvoxzI0pDlX0lsQjOvS4QKJW6Y qgp7QE1+/zYJWyAhf4fTfvCL1YwEpoERQr9RQfeqDQL1KH7EM/tB9ncQtwhHVGz4Pbjh E0KQy2dBrTi66xmSrjpAL+0FcFXfWJ7n7W+Bqw9z6dH5rTKsOK6IvxDUFHQgWO4SxEgP ylknBVp0DpK1due/9IfOlklC2CaqaXhPen/uJ3y7UVFFAvJU8hf0+YICt1xwYrMJmUmq fFsb8gNOg4LONwNcNURlD6f1ci348gl57khd3yd6aA4w0TmUxK5cbvYdmDYvyJvVwbS7 6eqw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=TWK7Tcl4v78WKhBmDih4hp4aKoxAkEp5jIDo2VrMgEA=; fh=o1g3XBKqq7VqvTu4UTz/wBgemkH2gvk1M+raIP8exW4=; b=ATfhOsTCfsKYeq6ToFq5Lwwshji+kGZ5U9IXU/rVmTKqof0o0Gx3nWUj+1Imuy+YSS NVN9bnV7JWEI2xxBKKalEGH3uH1k5tj70G+SHA8MUPF442AlBEQE/yOtKqkFCHiOqp5Q PeQjrw+g32WGA7QNvyNbwwLKeUGFKgc6Gj1Kjw40sA8T5ZaY0kR+dzwWFA9sm+vOOvFP ufXAK5rw5Y3OHT3yF8FyygFvgc6lWW6o5KLU7i8wKcbDbATXu3zHXagefTYiAOW9Zzlw dIRe93btqHYY64Nq33vOv/vZU22k83DPgz+TC2SZI9wWhJpu+mgwQnWI00sHVudnPKDF HW8A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@fastly.com header.s=google header.b=dZcIsh7s; arc=pass (i=1 spf=pass spfdomain=fastly.com dkim=pass dkdomain=fastly.com dmarc=pass fromdomain=fastly.com); spf=pass (google.com: domain of linux-kernel+bounces-62999-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62999-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fastly.com X-Forwarded-Encrypted: i=2; AJvYcCUxUMlfswo865bnICRBS9vKu2XZEKt3xYThm0AgiKwhqwuhXIkpzQ192ytZbqzgbQVfxIDc91+igjXH8RKrD4ztPmW4aQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id x5-20020ac85385000000b0042cee77dd50si1961539qtp.238.2024.02.12.22.18.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 22:18:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62999-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@fastly.com header.s=google header.b=dZcIsh7s; arc=pass (i=1 spf=pass spfdomain=fastly.com dkim=pass dkdomain=fastly.com dmarc=pass fromdomain=fastly.com); spf=pass (google.com: domain of linux-kernel+bounces-62999-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62999-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fastly.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 2F7D21C21BC3 for ; Tue, 13 Feb 2024 06:18:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 07D57179AE; Tue, 13 Feb 2024 06:17:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b="dZcIsh7s" Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 18E06134DE for ; Tue, 13 Feb 2024 06:17:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707805023; cv=none; b=eaJPjKnxBd6K/p8CTHoA3NEleiKBRJonANhebfQFSkP+sRhP3miQ8QFFxosY3rVkz5rpVDa+bWe0+DwcaLGBaC9u6blcwm0xpP9caPaR08ZtDZvFXMEu8J/UgN+v4IwvBHEaC2nUNK4t970uc0pazYSJnf5BB6dFX5tTT0Cm4Fc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707805023; c=relaxed/simple; bh=+BdDiZtulZrbvLpADjlE62DUPuOp3KejqJWNkuE2SMM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=su5RvpiM7/KkoMHMvThPeuKj5u4xmj8r2qlzS1kq/UGCyc5uSG15AfIAgUZLELCWJ6J58/DbmKR6MKw/+ZX4nlLk2ELvNkVNCJNd3qcg74RIzP42IaOuZQ8f1AhanMyhGI39DezCvk2y9ooWqO8aNMJzi8qhIkuxeAxGES/tDcs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fastly.com; spf=pass smtp.mailfrom=fastly.com; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b=dZcIsh7s; arc=none smtp.client-ip=209.85.210.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fastly.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fastly.com Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-6e0a4823881so1397279b3a.0 for ; Mon, 12 Feb 2024 22:17:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1707805021; x=1708409821; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TWK7Tcl4v78WKhBmDih4hp4aKoxAkEp5jIDo2VrMgEA=; b=dZcIsh7sDKQJ8LRc01yzKn89AtehuAqcEwEA7cApStZTVvKuDvLarwxXCqdhW+DKT8 YLp4Q4Aay2K4aQwkFeTqnllQm0f3qLq9ajXahrohZlc5vAFUhyMo1XCZhVn3FLiJHcp0 NTTaFSvxWtlgMwV7Ap5IGyzgbVBd3cAQfzs/Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707805021; x=1708409821; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TWK7Tcl4v78WKhBmDih4hp4aKoxAkEp5jIDo2VrMgEA=; b=O5V1XZqPxbIsu+TW+3CwSr952N51ffWNx2i9aSm6HUgrAtsEohwnIPNfMtsLkMXEj5 9+tgzKvVhb+Us6hwFI+tzDzv/I+HShlAOFiW+C31l32nE2aIIixo3Ii4Yewa2YkuMVNL XoK8EaL0bjB2PcbXZ8N/LGYNDvPDstwFeu8KN8jB0ljFXmIMtlPmJrvkaFgM9Ee3OrPq xvsCBw/2DsE5rMsvHD0DgwO1J57OmcRSg1gWPLhr3D/ePumPzYcUWBS5Qhx7OhlSFLby CdY0dFXU6VmGEE6dqIHI1KKmbFLEttu1zi0MF44qQr2CMUCYF2ch7aPBOjNnO9Vn1zrf HTFA== X-Gm-Message-State: AOJu0YzUNq2EAZJ/tzgr+hsUGQEgy7lUuT1hNB/u2mMc6jOfrDx5sa0p vpfZW6Mxz6caVrR7RJZCxdmJ2ncYcRtyt9FEYZ1K0Trtprp8SSSE1653lN2bNlSowUocrPEUhxR 80IqzyVPpSXqTD9OmgkSwopTejY3woq46/2RmJLsh0vc3ki9JVNa22V/6qnpK5I+zIoGBQopRKp FaQGY260fibiy1Go5/3HKQnMxjZkinOuWG32RImQzxhT0= X-Received: by 2002:a05:6a00:bc6:b0:6e0:99d6:490 with SMTP id x6-20020a056a000bc600b006e099d60490mr7327725pfu.21.1707805020617; Mon, 12 Feb 2024 22:17:00 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXmL7Vz3PAAYJ2YuBcOicTcHD7G3MPIBgpPVxgOqWx57ckQb0LQsp+zo+1xBYVJvVxX1xnFMSlslqEurFjhd8BN1Ask2EQZc6mdjdKDIMOrD2H0lpbgk0puZwOgN13OsNWKlrdGSpZQkn99PMb/TF7Oj1g/IwqZQq5GO+n3XY6NDDlRAtv12zlRd0iJIDQMrq7FkJSptx6nz6yJAAagghDmHZIA9mwS4SqtRXSu3uJqtwLYyikPd5fzSj0z4vZx78G9/mykhCZyiEGpwlQkKn63Jis6NDCbIJxOJsjVE0w5tj5tfF91tqmc3P213LPGsFXADlJRzdIJB//0Ulx206ft3k7pQWfiWaGLP5U4RECb/+vlQxJkkviTJuDmWX7O1JcYb4w5gdEt7RG4FG9CSrJ3JD7sSFtfiPLmpmKlPamtwsXW6cFbL/F06xzeuX0PLxAxn1O16eKif/KlZfe/lU/gZQfwRBIMdKexiAyTmgInf0DAvzL142wZqKm6vdLgmm4VbYXpnlpgP8utTiAXPZAKZzb2dnMUxVKYLzCP62FKYAYD0md7sF9dz4n2FLx1qDWBzGhXgJhHpdvg65qvOan1XyFJTk5wI0x9FBMjuUvRwkjUb2YMyMNjTcY9t34= Received: from localhost.localdomain ([2620:11a:c018:0:ea8:be91:8d1:f59b]) by smtp.gmail.com with ESMTPSA id n19-20020a638f13000000b005dc87f5dfcfsm342936pgd.78.2024.02.12.22.16.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 22:17:00 -0800 (PST) From: Joe Damato To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: chuck.lever@oracle.com, jlayton@kernel.org, linux-api@vger.kernel.org, brauner@kernel.org, edumazet@google.com, davem@davemloft.net, alexander.duyck@gmail.com, sridhar.samudrala@intel.com, kuba@kernel.org, willemdebruijn.kernel@gmail.com, weiwan@google.com, David.Laight@ACULAB.COM, arnd@arndb.de, sdf@google.com, amritha.nambiar@intel.com, Joe Damato , Alexander Viro , Jan Kara , linux-fsdevel@vger.kernel.org (open list:FILESYSTEMS (VFS and infrastructure)) Subject: [PATCH net-next v8 1/4] eventpoll: support busy poll per epoll instance Date: Tue, 13 Feb 2024 06:16:42 +0000 Message-Id: <20240213061652.6342-2-jdamato@fastly.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240213061652.6342-1-jdamato@fastly.com> References: <20240213061652.6342-1-jdamato@fastly.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790763428244798157 X-GMAIL-MSGID: 1790763428244798157 Allow busy polling on a per-epoll context basis. The per-epoll context usec timeout value is preferred, but the pre-existing system wide sysctl value is still supported if it specified. busy_poll_usecs is a u32, but in a follow up patch the ioctl provided to the user only allows setting a value from 0 to S32_MAX. Signed-off-by: Joe Damato Acked-by: Stanislav Fomichev Reviewed-by: Eric Dumazet --- fs/eventpoll.c | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/fs/eventpoll.c b/fs/eventpoll.c index 3534d36a1474..401f865eced9 100644 --- a/fs/eventpoll.c +++ b/fs/eventpoll.c @@ -227,6 +227,8 @@ struct eventpoll { #ifdef CONFIG_NET_RX_BUSY_POLL /* used to track busy poll napi_id */ unsigned int napi_id; + /* busy poll timeout */ + u32 busy_poll_usecs; #endif #ifdef CONFIG_DEBUG_LOCK_ALLOC @@ -387,11 +389,41 @@ static inline int ep_events_available(struct eventpoll *ep) } #ifdef CONFIG_NET_RX_BUSY_POLL +/** + * busy_loop_ep_timeout - check if busy poll has timed out. The timeout value + * from the epoll instance ep is preferred, but if it is not set fallback to + * the system-wide global via busy_loop_timeout. + * + * @start_time: The start time used to compute the remaining time until timeout. + * @ep: Pointer to the eventpoll context. + * + * Return: true if the timeout has expired, false otherwise. + */ +static bool busy_loop_ep_timeout(unsigned long start_time, + struct eventpoll *ep) +{ + unsigned long bp_usec = READ_ONCE(ep->busy_poll_usecs); + + if (bp_usec) { + unsigned long end_time = start_time + bp_usec; + unsigned long now = busy_loop_current_time(); + + return time_after(now, end_time); + } else { + return busy_loop_timeout(start_time); + } +} + +static bool ep_busy_loop_on(struct eventpoll *ep) +{ + return !!ep->busy_poll_usecs || net_busy_loop_on(); +} + static bool ep_busy_loop_end(void *p, unsigned long start_time) { struct eventpoll *ep = p; - return ep_events_available(ep) || busy_loop_timeout(start_time); + return ep_events_available(ep) || busy_loop_ep_timeout(start_time, ep); } /* @@ -404,7 +436,7 @@ static bool ep_busy_loop(struct eventpoll *ep, int nonblock) { unsigned int napi_id = READ_ONCE(ep->napi_id); - if ((napi_id >= MIN_NAPI_ID) && net_busy_loop_on()) { + if (napi_id >= MIN_NAPI_ID && ep_busy_loop_on(ep)) { napi_busy_loop(napi_id, nonblock ? NULL : ep_busy_loop_end, ep, false, BUSY_POLL_BUDGET); if (ep_events_available(ep)) @@ -425,12 +457,12 @@ static bool ep_busy_loop(struct eventpoll *ep, int nonblock) */ static inline void ep_set_busy_poll_napi_id(struct epitem *epi) { - struct eventpoll *ep; + struct eventpoll *ep = epi->ep; unsigned int napi_id; struct socket *sock; struct sock *sk; - if (!net_busy_loop_on()) + if (!ep_busy_loop_on(ep)) return; sock = sock_from_file(epi->ffd.file); @@ -442,7 +474,6 @@ static inline void ep_set_busy_poll_napi_id(struct epitem *epi) return; napi_id = READ_ONCE(sk->sk_napi_id); - ep = epi->ep; /* Non-NAPI IDs can be rejected * or @@ -2058,6 +2089,9 @@ static int do_epoll_create(int flags) error = PTR_ERR(file); goto out_free_fd; } +#ifdef CONFIG_NET_RX_BUSY_POLL + ep->busy_poll_usecs = 0; +#endif ep->file = file; fd_install(fd, file); return fd;