From patchwork Sat Nov 9 05:02:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Damato X-Patchwork-Id: 13869256 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 E92D0146D68 for ; Sat, 9 Nov 2024 05:03:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731128594; cv=none; b=W8Y/SSRruVzflS1XB7n2+z9g5hvbF/iWCqRcer1u3XV2q+zFpwXlbIs8Fd2D5p0haO/ZiM7dLU1o84a3AwrSPhiLyRD1VBJiW/KgaYE03ilAYMNJpTd4g/V0gItwFEBBerfe4r8tPQJfaQHehUCnRLCY33Mr10EPE+OOB/fCiw8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731128594; c=relaxed/simple; bh=ZvawQy978AWawDyo2L5Npe51s7GUMbBNxiumv6HwfAk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=drB5F4am1wq4VJtecD66H4EZNYCP/Jsf4OM3cTcnEfD2uAipY57Ubc4jBaN97UB4GaNOvOToDj76tF5/4d8yzncXxO10UH7vuKiGRGqSdYdntDPwCcOvfikJSRdGkwRVq+ELLe6v6+uS2yNGlTEid1nwdVpfVC1ogYWNmtEz270= 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=Uw7saS7t; arc=none smtp.client-ip=209.85.214.177 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="Uw7saS7t" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-20c8c50fdd9so27613485ad.0 for ; Fri, 08 Nov 2024 21:03:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1731128592; x=1731733392; 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=Uw7saS7t6nDjDRO/ouEsGgh12nKYkz2eVEu3kVJrFEsTjF7VKN2+cEJrOn6gH+G2VZ SehZ6JocVSOLlrEjgNFlPfvf4YEau2R9RYxBiOz+Du2bs5XmCG/ah7r19A4DQB9kh/0T 1HR7ZOWtetrC9HUGbXfaGU79f1lA8QdaA1iSc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731128592; x=1731733392; 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=teD3JJoo3ZZqFIzHyVTV3E3Aw6JeS9Hr/LaMi+tk9Ll+FJmtxqW5Hp0ixhNFT8ZhZ1 DXBzLn6XElNZXfnc+lx2eeN5Ajv9tUd5H/q24TTsy2+cafNaf6GgvkAsl01LQaUL/qsK DcLC8tkCVFUtdVjr72NpcLiN47wDLLwTleUW+94XOoLRj6q9RvzYVV+iRrG9U+oYVwoI bYWG9AXLeWZOg0Vvo5LDhsTD1oII6fMWvGmOV8n3kqXSj+mUIipskyXWlw9FIzeiaCKC eJQ0P4NBwj+HRM3j+NeYS03MWbvFa1Gmj9n3UM74dii8/YeNhmzM30p6hDHnc9oy4Qy5 UwVA== X-Gm-Message-State: AOJu0Yyv0gXwI22nydmAshR8vdyCTgrpGhpLWXWjyqdjf9/O7TKesHEE bJuHTFFAGZteWKVazjzH/pwBNEepT7FSUJ+Nt2Oi6HbYUqsAMET7s5FLhXDm+X/EnGBOC2DTLvw kukvxnsxTfiWkkgv24lnRifp68op2IJe0b72/+WXrNb5hjySyMlCqyo6KACF3i784HO7NXuKeA3 XBW8oSjxzlbkiOi1mwYlbOJeCrMxOow0bSaiw= X-Google-Smtp-Source: AGHT+IFwub+z7xSI5MikFyIEn8D0noXN6MBqpDdrXm/q6wfIDmeAVnqBQrYEukM/mMoyt3Kx3OMjPA== X-Received: by 2002:a17:902:d4c9:b0:20c:c482:1d72 with SMTP id d9443c01a7336-2118377ebd2mr82909855ad.20.1731128591788; Fri, 08 Nov 2024 21:03:11 -0800 (PST) Received: from localhost.localdomain ([2620:11a:c019:0:65e:3115:2f58:c5fd]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21177e5853csm39182305ad.186.2024.11.08.21.03.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2024 21:03:11 -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 v9 4/6] eventpoll: Control irq suspension for prefer_busy_poll Date: Sat, 9 Nov 2024 05:02:34 +0000 Message-Id: <20241109050245.191288-5-jdamato@fastly.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241109050245.191288-1-jdamato@fastly.com> References: <20241109050245.191288-1-jdamato@fastly.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org 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)