From patchwork Mon Nov 4 21:55:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Damato X-Patchwork-Id: 13862140 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (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 3CCBE1FE106 for ; Mon, 4 Nov 2024 21:56:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730757417; cv=none; b=LizywJkniJ6IwrC/L24aHJdA+It93Ys6l09GxO3GZFHSwQmOPvCXxsr07VO3JWZ9P0lJODJBi9+OisvlYDMdfWi4O6i4q1o9DKLkZJxmMa48tiSIoGD/mTM0cQ8kF+Am8An8ao5zfkj4vfDXbPiGQxYgyCI63FtT0iTnf3F790c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730757417; c=relaxed/simple; bh=QMGh9V+fCN/j+D0uLjcnIHw3s7shm5dxlUbsYTeYPOY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=s3ntc+Az/WhH6OpBnjCiIKOHcJkc3pXCzFodQXRuA7s/Ym0u0uFNsaXYoJ/UT8TdFgznk6EftipJ1ul3H7xVJ34n6LYCEtIGjo0hA3TW5lBqh6g5Eqyhsg1nw2QWbZ7k0fACf2pNrcpgaMZd8vjcIiYyZjXmJ3mbzrXdAQ689Vg= 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=rHg1+Xru; arc=none smtp.client-ip=209.85.214.169 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b="rHg1+Xru" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-20e6981ca77so49640785ad.2 for ; Mon, 04 Nov 2024 13:56:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1730757415; x=1731362215; 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=OCBpeWwUMYPpQhLDdrb3cMWwRM83RuSfCI6YlvdtYdM=; b=rHg1+XruwEqqH7mILatPJUnGyKpgR+YajrD2RzxapmO2XEkG4XfFS5XkanPnhP0sgY qp64YAnaMwu9V4togVQyqcjuv3K01SYXNo1sRMW5Xs9EO4VotxbNjG8e+z1cWvvwOTdE pwfUrGEcxtmi6aj64eTov5NUWgmr8DJvXCbgs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730757415; x=1731362215; 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=OCBpeWwUMYPpQhLDdrb3cMWwRM83RuSfCI6YlvdtYdM=; b=Qh0hYw3lGvDM8/WPwFa+zZZpZkKgs7/MeMPzA2T4IzXWtILu6SyREhZNIz3eqcen9B wvPpFKYOYpASQpBPpVyO0zDTUzJRKGDwijvNQLe5CSIYLI9dCZ5vGFoWQzCly1n5Zkov Co1T00+Qxfmvi5TQxVbElJU7fVOvO6loEkYxPYTWma99pMa+kI/GcBAb1wutUZ++FY9b NwYeTMw0A8RXB/V3vZQREOoNTIqC9Y9wNd5i6lOLH8vJ6Z2fBbrj7j6gE0ckO9UihcpX i6nWcq5eU+GwuFObbYfm6TNBWMFK1S/cj+prCY2iZ7l3s7KgV1irG7C86qY8GNaUcsjo IUyg== X-Forwarded-Encrypted: i=1; AJvYcCXSzbuB2KjzOH8zJpUdCAObJ6Th38GfL3Z10g1MCoT4DxcU6EAGZiJ4LDgTPHiwOjNSrB44Bzz31Ziuo8WN@vger.kernel.org X-Gm-Message-State: AOJu0YxGCyPoe5QqX+yeJ9iHigFXlNxFJKA76OhWoTEm+XrTUGPX8eFi rON0/sN7qJO/0DvJIhJeGZr97BNI5SBnLEMIhTtSGVgDFZHzNBfT9RQwO2hX7kY= X-Google-Smtp-Source: AGHT+IHWXLfYRnyjLLBm8m8/vH3IV4zCHF4QIeTTrl45VzFqWP55kOn1ZRaQZ6RVPpoxAWT4AQ1w/w== X-Received: by 2002:a17:902:cec9:b0:20c:872f:6963 with SMTP id d9443c01a7336-21103b1ce5amr244888585ad.33.1730757415610; Mon, 04 Nov 2024 13:56:55 -0800 (PST) Received: from localhost.localdomain ([2620:11a:c019:0:65e:3115:2f58:c5fd]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-211057062b8sm65860255ad.63.2024.11.04.13.56.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 13:56:55 -0800 (PST) From: Joe Damato To: netdev@vger.kernel.org Cc: corbet@lwn.net, hdanton@sina.com, bagasdotme@gmail.com, pabeni@redhat.com, namangulati@google.com, edumazet@google.com, amritha.nambiar@intel.com, sridhar.samudrala@intel.com, sdf@fomichev.me, peter@typeblog.net, m2shafiei@uwaterloo.ca, bjorn@rivosinc.com, hch@infradead.org, willy@infradead.org, willemdebruijn.kernel@gmail.com, skhawaja@google.com, kuba@kernel.org, Martin Karsten , Joe Damato , Alexander Viro , Christian Brauner , Jan Kara , linux-fsdevel@vger.kernel.org (open list:FILESYSTEMS (VFS and infrastructure)), linux-kernel@vger.kernel.org (open list) Subject: [PATCH net-next v6 4/7] eventpoll: Trigger napi_busy_loop, if prefer_busy_poll is set Date: Mon, 4 Nov 2024 21:55:28 +0000 Message-Id: <20241104215542.215919-5-jdamato@fastly.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241104215542.215919-1-jdamato@fastly.com> References: <20241104215542.215919-1-jdamato@fastly.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Martin Karsten Setting prefer_busy_poll now leads to an effectively nonblocking iteration though napi_busy_loop, even when busy_poll_usecs is 0. Signed-off-by: Martin Karsten Co-developed-by: Joe Damato Signed-off-by: Joe Damato Tested-by: Joe Damato Tested-by: Martin Karsten Acked-by: Stanislav Fomichev Reviewed-by: Sridhar Samudrala --- v1 -> v2: - Rebased to apply now that commit b9ca079dd6b0 ("eventpoll: Annotate data-race of busy_poll_usecs") has been picked up from VFS. fs/eventpoll.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/eventpoll.c b/fs/eventpoll.c index 1ae4542f0bd8..f9e0d9307dad 100644 --- a/fs/eventpoll.c +++ b/fs/eventpoll.c @@ -420,7 +420,9 @@ static bool busy_loop_ep_timeout(unsigned long start_time, static bool ep_busy_loop_on(struct eventpoll *ep) { - return !!READ_ONCE(ep->busy_poll_usecs) || net_busy_loop_on(); + return !!READ_ONCE(ep->busy_poll_usecs) || + READ_ONCE(ep->prefer_busy_poll) || + net_busy_loop_on(); } static bool ep_busy_loop_end(void *p, unsigned long start_time) From patchwork Mon Nov 4 21:55:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Damato X-Patchwork-Id: 13862141 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) (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 6447C1FEFA7 for ; Mon, 4 Nov 2024 21:56:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730757419; cv=none; b=GOzh4ELqPmSg51Z+iG2XsZtadyy8d9ROTXfRxFl+P7wRj3bbBVXds4qvzHX2n37qC9FDIsrZPzFChXR6/8+Eg6ilcMcCG31RWQdIw9EXidh+bF9aLn2FHGPLABByYOfHTlVN2Os9RUQEr2Dn9Cg90Aqy/zPm0NB5Ye6OhgxW4rs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730757419; c=relaxed/simple; bh=ZvawQy978AWawDyo2L5Npe51s7GUMbBNxiumv6HwfAk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hpKmR00C4UTSfUx5q2hpvfH3bb/31XcyF/WWQF05tVSPly0kHQH9AYcWGL8HSQSpwwVaIFjIg2UbDYqvHz0xU5wOKNp5jqYj8ab5TE5IJU+Vvgl+RaleCr+nqR9n7QYlHXH83mnC965ilH4RlpXKy2wvH7YT9zb4zjKi74NXCqQ= 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=jJEgP3sS; arc=none smtp.client-ip=209.85.216.44 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b="jJEgP3sS" Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-2e2ad9825a7so3450952a91.0 for ; Mon, 04 Nov 2024 13:56:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1730757418; x=1731362218; 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=U/mZBN4ImS6YyPeWvLF6rIBEjo5ZB0WxVpPyUomkuEI=; b=jJEgP3sSzB4zBbUJM4ZEQSZMZ6SPVxRfGqYfKMQMFy9GWk+EVXe8d4VZRnbyEr6RXa Pj/cDGkYzJ+rIksmLoQVLvIn9bmvcZrEVlBz/alsPkfQiNljqFXAdwbuucaDT9Rxkmmp Fe4XGqy9dKqhsSqvvmTvwET9/GJALQpIghiMo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730757418; x=1731362218; 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=U/mZBN4ImS6YyPeWvLF6rIBEjo5ZB0WxVpPyUomkuEI=; b=UHAxWTZtOGV8ULQYHn7H+ApP4U5wDezkvcC54eW0s2K1tHIq765hJYs/YaYGooMw1/ I3b/cnttIiZUpT90D+/B/j1Xmh/nvmsjINhNJRQN0sGnFHy2jR9JzsGZcJU+dkSQBJ7X 4NvMwxOA6Rjft4CmKRxsr3i+kmXq5VWWk9MOPHVCUn2Bk50fLx5fDjvAQc1ckqJ3PEus tRSoR23wZG+YUxuRYTj19wVpdsyY+alamNDZeDC80g++PNhCkbO/jKMylvBUI+2wknvn /QzYzmTOdyM3H00iab2u7ccrsOebbGZ2ydt6id9uMTDd+yjuhKbQ3ysLHUsGQh0+gyLM Szew== X-Forwarded-Encrypted: i=1; AJvYcCVtuYJ2byDArEIVX38evKemfIDbfRX6T95Zx1pHpTTcJXPGitThOd1AtQ+NsMGNCfG4lbKsmv5LxomOgjNs@vger.kernel.org X-Gm-Message-State: AOJu0YxCMgLrU8eREnhK1CA7ue7OYFG9nc0PBpOSXXFqictiNe6gfqd2 jtyvk3m305+XivEM/a48eaG6FUMcNjAxvqzYeHfeN9lyX3jUnMy4cg+KmiTtxBM= X-Google-Smtp-Source: AGHT+IENlIsq8+IIDsyU+nhB9TYp003iEeEe93gLutUdQX68yVgJFPhwu5VGXlQldD52ko60WmxTLA== X-Received: by 2002:a17:902:d54a:b0:20c:d2d9:766f with SMTP id d9443c01a7336-210c68986efmr450019785ad.14.1730757417754; Mon, 04 Nov 2024 13:56:57 -0800 (PST) Received: from localhost.localdomain ([2620:11a:c019:0:65e:3115:2f58:c5fd]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-211057062b8sm65860255ad.63.2024.11.04.13.56.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 13:56:57 -0800 (PST) From: Joe Damato To: netdev@vger.kernel.org Cc: corbet@lwn.net, hdanton@sina.com, bagasdotme@gmail.com, pabeni@redhat.com, namangulati@google.com, edumazet@google.com, amritha.nambiar@intel.com, sridhar.samudrala@intel.com, sdf@fomichev.me, peter@typeblog.net, m2shafiei@uwaterloo.ca, bjorn@rivosinc.com, hch@infradead.org, willy@infradead.org, willemdebruijn.kernel@gmail.com, skhawaja@google.com, kuba@kernel.org, Martin Karsten , Joe Damato , Alexander Viro , Christian Brauner , Jan Kara , linux-fsdevel@vger.kernel.org (open list:FILESYSTEMS (VFS and infrastructure)), linux-kernel@vger.kernel.org (open list) Subject: [PATCH net-next v6 5/7] eventpoll: Control irq suspension for prefer_busy_poll Date: Mon, 4 Nov 2024 21:55:29 +0000 Message-Id: <20241104215542.215919-6-jdamato@fastly.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241104215542.215919-1-jdamato@fastly.com> References: <20241104215542.215919-1-jdamato@fastly.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Martin Karsten When events are reported to userland and prefer_busy_poll is set, irqs are temporarily suspended using napi_suspend_irqs. If no events are found and ep_poll would go to sleep, irq suspension is cancelled using napi_resume_irqs. Signed-off-by: Martin Karsten Co-developed-by: Joe Damato Signed-off-by: Joe Damato Tested-by: Joe Damato Tested-by: Martin Karsten Acked-by: Stanislav Fomichev Reviewed-by: Sridhar Samudrala --- v5: - Only call ep_suspend_napi_irqs when ep_send_events returns a positive value. IRQs are not suspended in error (e.g. EINTR) cases. This issue was pointed out by Hillf Danton. rfc -> v1: - move irq resume code from ep_free to a helper which either resumes IRQs or does nothing if !defined(CONFIG_NET_RX_BUSY_POLL). fs/eventpoll.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/fs/eventpoll.c b/fs/eventpoll.c index f9e0d9307dad..83bcb559b89f 100644 --- a/fs/eventpoll.c +++ b/fs/eventpoll.c @@ -457,6 +457,8 @@ static bool ep_busy_loop(struct eventpoll *ep, int nonblock) * it back in when we have moved a socket with a valid NAPI * ID onto the ready list. */ + if (prefer_busy_poll) + napi_resume_irqs(napi_id); ep->napi_id = 0; return false; } @@ -540,6 +542,22 @@ static long ep_eventpoll_bp_ioctl(struct file *file, unsigned int cmd, } } +static void ep_suspend_napi_irqs(struct eventpoll *ep) +{ + unsigned int napi_id = READ_ONCE(ep->napi_id); + + if (napi_id >= MIN_NAPI_ID && READ_ONCE(ep->prefer_busy_poll)) + napi_suspend_irqs(napi_id); +} + +static void ep_resume_napi_irqs(struct eventpoll *ep) +{ + unsigned int napi_id = READ_ONCE(ep->napi_id); + + if (napi_id >= MIN_NAPI_ID && READ_ONCE(ep->prefer_busy_poll)) + napi_resume_irqs(napi_id); +} + #else static inline bool ep_busy_loop(struct eventpoll *ep, int nonblock) @@ -557,6 +575,14 @@ static long ep_eventpoll_bp_ioctl(struct file *file, unsigned int cmd, return -EOPNOTSUPP; } +static void ep_suspend_napi_irqs(struct eventpoll *ep) +{ +} + +static void ep_resume_napi_irqs(struct eventpoll *ep) +{ +} + #endif /* CONFIG_NET_RX_BUSY_POLL */ /* @@ -788,6 +814,7 @@ static bool ep_refcount_dec_and_test(struct eventpoll *ep) static void ep_free(struct eventpoll *ep) { + ep_resume_napi_irqs(ep); mutex_destroy(&ep->mtx); free_uid(ep->user); wakeup_source_unregister(ep->ws); @@ -2005,8 +2032,11 @@ static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events, * trying again in search of more luck. */ res = ep_send_events(ep, events, maxevents); - if (res) + if (res) { + if (res > 0) + ep_suspend_napi_irqs(ep); return res; + } } if (timed_out)