From patchwork Fri Aug 23 17:30:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Damato X-Patchwork-Id: 13775598 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) (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 73628191F81 for ; Fri, 23 Aug 2024 17:31:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724434316; cv=none; b=cM0sPO+9UwnZq7WUM6doXVyRYaK3wMMMfzqs/hi+FvAn1TO4ZDW1NQZ0Xs7fi7xP01PjJGuPdXxiX8R4Sc0tbDQmQhPoo1yo1rGCSqwr1zMWpD+1Lvu90UBAHb1f+xvP3pDqQtDMbQaBoWwamurDqasp1RItCBc19XL2L22V/70= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724434316; c=relaxed/simple; bh=uGO5dEJrzAGpkDGXLrC8ztAywM3dRMCy6F4elADygWk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=POFOAZbIXbmricoucEAhChBhyb5TTIIMZyjYwI94kISWhQuuIGV9n2fa1zjQxdMqkctcz7tbeBtnqFinQEC4cLnhvOY+abOGhscnMZ3ietDaF/JzSKw+uOuu2xXHRN14914Wcjnx1hiGGDOVKiFbfVmT/4+isFnK/L40ufMzKJo= 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=twgo/R6y; arc=none smtp.client-ip=209.85.215.180 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="twgo/R6y" Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-6bce380eb96so1344767a12.0 for ; Fri, 23 Aug 2024 10:31:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1724434315; x=1725039115; 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=58S4qbuyYKoKQjyHpzs28ekwRvFYt2yreo1eLG7u1fM=; b=twgo/R6yBWs7WuZvoSdye6GCNXPvb0JViHYT4zcpQCEdfcSfBy9yJycfC/01CrerAK 9I+R4bRipMWIkMu3GKP4zVmpOGxR0x71MkkOcYk+R6e2CfJwm6D2OJBlUFih08NCNNbS P4esa7u4fAZ6UfK+wpk6ek8BwEDw7BKiE6XGM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724434315; x=1725039115; 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=58S4qbuyYKoKQjyHpzs28ekwRvFYt2yreo1eLG7u1fM=; b=S0SBhCZVZThTP3+LMBzrvWUso3iReNJPQCDsItEeloimJp45TRVCb36JEesVeUKRec fnB50onUjGgc4tRukyPzWl7SGpAvecW+TRbGWg4etco/Kjnn0v61tEK5hvBJOJqmWvlz O0BRcoYWR+NZWsqizKENGKUSqZgKlZvY6VqWY/zX5QWBy2iZcR0mhPCc3J5UBr3Jnnos 7PcHhhx1TR9zRScMLOQP8xunE5P7FRHP5YckC43hOSvjNp9QE5rkUYQHorx8IO0Z9v/k 7t5qB3hUmUegFb5gjwqR6R4Z3FfnWxi7WtfM1l5CaFXYSQZ818RLYf65LcO4IFV+aP8J dOlQ== X-Forwarded-Encrypted: i=1; AJvYcCU+Z8G2y3Vun4+X51uadej24EOJiAvTqx93zYBV8HWeirCBe+yOSmNHERS4TVeFU5Gj5KM7FYCNw/HMZBrb@vger.kernel.org X-Gm-Message-State: AOJu0Yzsb4Y1jdW9/NIjgIoJKltWGSsUubuoO7tHXosH6ngn9rIlu0/r yQtOxbRJ4PpMPWWZny50392ADMYrTcXZirI3Lajw+Bfx8ZujM705SI7sP8+JQMY= X-Google-Smtp-Source: AGHT+IERjh31UHWhIZDePORqNzeJZelgKL0ItV5Or+5rM0DaNHnsupMW/bNRFrWJoppeQW8QJR6Ong== X-Received: by 2002:a05:6a20:9f4a:b0:1c4:c879:b77f with SMTP id adf61e73a8af0-1cc89d7e4b6mr3579864637.27.1724434314568; Fri, 23 Aug 2024 10:31:54 -0700 (PDT) Received: from localhost.localdomain ([2620:11a:c019:0:65e:3115:2f58:c5fd]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7143430964fsm3279624b3a.150.2024.08.23.10.31.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Aug 2024 10:31:54 -0700 (PDT) From: Joe Damato To: netdev@vger.kernel.org Cc: 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 4/6] eventpoll: Trigger napi_busy_loop, if prefer_busy_poll is set Date: Fri, 23 Aug 2024 17:30:55 +0000 Message-Id: <20240823173103.94978-5-jdamato@fastly.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240823173103.94978-1-jdamato@fastly.com> References: <20240823173103.94978-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 --- fs/eventpoll.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/eventpoll.c b/fs/eventpoll.c index f53ca4f7fced..cc47f72005ed 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 !!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 Fri Aug 23 17:30:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Damato X-Patchwork-Id: 13775599 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (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 2FA4A192B6D for ; Fri, 23 Aug 2024 17:31:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724434318; cv=none; b=qyYQAIgKcDqGq9y/ZhNgrg+Mb+puERpMkKU4zte+PThkulXYpuazXS8FOxcHKjaGzwpCpBq2Xsk63yEuWpZcZC13OD2Nf0Bc9F5hpqnQir5CP9sRPb9FLl0Xgf5irDfdcVtFmDGY1wKG0QZnXX2iCnVE8T8pp7tnX+Cmkq1eeBE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724434318; c=relaxed/simple; bh=x08ZrLW3d91mrWZQmC/v9H7iJRa473+4x/SsWYtS3JE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SsssUIItGMIzn6wWDiJG6WP7qBe6kr8ey4pwV51Wc9JzDuSlH6kVH7Tu6azDByL8rQN2ewS9zZ4UvjNM5MbkzYpyIr8aduvKYYi6mV3wufpQUswuFg9uyzHjcwr2d5zlA557aix4JxisYXUeM3n6DLAKHmA7vzZVd0j0GXwe/W4= 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=UDZ0sT8u; arc=none smtp.client-ip=209.85.210.178 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="UDZ0sT8u" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-71433cba1b7so1811114b3a.0 for ; Fri, 23 Aug 2024 10:31:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1724434316; x=1725039116; 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=IoqQBySxLV4Sefg/kJRVr1Dr3C923zx/iiQfn4tblTE=; b=UDZ0sT8u5MrIFsQ3wnGp9F9y8pQUiZjszYOkWFxo0DmRD7PgI+tWFNlusmmu2kUoI4 7Y51sqGcrLLr9mdv95q3Xg5gPbYTJJwQh280N/zECe56Ppl2iIuY2WwaGeMFHAFrTixS fL8fumpgh/G5j6qj65gnWQugCyPUtzs5Zxseo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724434316; x=1725039116; 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=IoqQBySxLV4Sefg/kJRVr1Dr3C923zx/iiQfn4tblTE=; b=Q38GnB+iPusiTeGkLACy0l/SnMr/MeVZiHVmrrQ2a3smapemuZ/mFc3iEVT4dn09sh ETuBHEzbA+Z9MpJ0DBQm01i3VEHKBZM9Vlt57o96PwImDCEo1TxYgGcozGaiasRy6/Sq 2xjYqimAL18Mw2S1+CPJB+oVQIVD1vvCOU1rzqEIBQpZlsMQCFscQUyWl1nzCY1gh8Am xDKNQ9KBsERV6H94neT4wA00FglnzhNLZCa6SzfL4HQC4pTK8PjHO1o9ASyGzBQsrJUD hjwt/kZbqCftCDvymPuHAqbhMOI5/8oStlYGOEKoZPhShxPHKIq4oYpR8Sfb49IX5tI5 aDAg== X-Forwarded-Encrypted: i=1; AJvYcCUyV47ILaPUEn/tyJUV9LUfjPQoowpm5NChVJf5zoU8JwamJmvAYsYik46u0XBhm2EjGh/5z45sGX9pOKeq@vger.kernel.org X-Gm-Message-State: AOJu0YyCBD3Hz7Sc72h+SWK550969SiaZuXNKaUOL0U/b8x2xxXKfHlK 5AUoJxNvge+kMbKUrJ7d0Ubs3BTvuSD7S7alnJAN7u5+c4Dvcps2f0r8OmF1q8g= X-Google-Smtp-Source: AGHT+IHXsgl2NQYO+yMV9X1gIfvGuclsqseoRzkfOcO3p7twoiEGni5X0dIXcScV5If78qjNaxucOA== X-Received: by 2002:a05:6a00:3e2a:b0:710:5605:a986 with SMTP id d2e1a72fcca58-714454098b9mr3730824b3a.0.1724434316322; Fri, 23 Aug 2024 10:31:56 -0700 (PDT) Received: from localhost.localdomain ([2620:11a:c019:0:65e:3115:2f58:c5fd]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7143430964fsm3279624b3a.150.2024.08.23.10.31.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Aug 2024 10:31:56 -0700 (PDT) From: Joe Damato To: netdev@vger.kernel.org Cc: 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 5/6] eventpoll: Control irq suspension for prefer_busy_poll Date: Fri, 23 Aug 2024 17:30:56 +0000 Message-Id: <20240823173103.94978-6-jdamato@fastly.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240823173103.94978-1-jdamato@fastly.com> References: <20240823173103.94978-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 --- 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 | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/fs/eventpoll.c b/fs/eventpoll.c index cc47f72005ed..5dbe717c06b4 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,13 @@ 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 +813,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 +2031,10 @@ 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) { + ep_suspend_napi_irqs(ep); return res; + } } if (timed_out)