From patchwork Mon Aug 12 12:57:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Damato X-Patchwork-Id: 13760529 X-Patchwork-Delegate: kuba@kernel.org 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 725ED17C210 for ; Mon, 12 Aug 2024 12:57:41 +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=1723467462; cv=none; b=Eg4Gvw60RYy/kGLoA75oyVIPkuIsoGHbVQnfoB6QiXJu++8OOLUvoRxZui63SODNNJ4HuYnNC8OMq3D35XbbooT6dr8eIgFeQ3W2eDQkR6zBBWSX4h02mVTUzMfpIwBonQMtqU4DBPz4itGn78++X6g9ZdNprxctNc6O7Teg+Mc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723467462; c=relaxed/simple; bh=UU9YetgXXPCskdk6gOfxmmZ7JeMKgrNe4FVwpCMuu7g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pXjNsYYh5Da8D7PJs5Pg8byVq+dwAtmKhxHex35jr5DwCSxXbIFYc//QRO17P+YpvNfn0l408ASEV+gU6eul5Vii8jws+H4atjv6rvgdMjxHzxgTrvGFq6dUaOnAY4g1JnNZw4hsNRbCQFAp4d+UI/aBNGqY90Yg7q2ewvOw0/k= 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=t1qzOMRC; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b="t1qzOMRC" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-70d28023accso3369026b3a.0 for ; Mon, 12 Aug 2024 05:57:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1723467460; x=1724072260; 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=RRh17J0oYLnjpYt6fboaKb0SXYeVubbfK7YpxWdImGw=; b=t1qzOMRCzLoLVFMdl9j4OULHGrKVqNM6OAwft6kY3ZNdygezIUd5b9eA4/rZBNby+u tTlUiRQXaHfPZOIo6nFV1Go7/BMx48zGkIGbuWSYo7QFj0OPhGC766pffV/1WAtx/eDh 9V3y/Bc969IjfOQd0PWvHcJ3Eut5ftI+i27Lo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723467460; x=1724072260; 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=RRh17J0oYLnjpYt6fboaKb0SXYeVubbfK7YpxWdImGw=; b=DetmF89RetBOqIngjMH36tcRTcKwso78pLdJgjZiTm2wwV3+cEfZu7WlQnktBtQMuq JG2MXwgUhIEcu2ieGEXTgq+0d1f1Mta4FyGxCoKfNvl6vNDDVpX5Qycz9Z1UoRQ03mX7 DKKGvfddyRYDUMqT7XnRw9Rf3m0Xijefs/YDQdR5cH9dyIGQvJ2MII9P0JrnFJW5XkT9 2aSSjt1HJLSJwWVIFit94k8Q3ZPLxrLJe1d+HSUW2n7Uo+8XjiopuEOFd5DOOg8CPfG2 THBFzEq9gTuIg0jLOf6yezcvO/Jn1eLBie3KAotJNoBp7QVP/FtlWKJbQQHw+Dmxp3nj 0nqA== X-Gm-Message-State: AOJu0YxoWxEpGkE5MnPyl+NRNc+AAiyCryM4JUi1s91XvFCkhCjN8q4Z NCNwqCiapP1mMqRLyDFhM0Q4DoqLGDlTR/B78VSCY5sqTC/qo4kuZVRG8vAehb8ZdrXivtHdI8B 329bHg8eFJnowafLvz1AM9qc5gY2Iy2MKCHxYVgSQCjIrWBKWT7IiRZffsGjwiPRTHR+c/pIu9l kAv3VnZ6rChqXJ/DzI/STHoR5oyPyegIzTue2B0Q== X-Google-Smtp-Source: AGHT+IEq9qb5amGbSMq5W4M/QmN7S0NtNcAlbtlnwHYghOllBYYxaVtW9gHS8KIZ2Q+wiEkV50eorQ== X-Received: by 2002:a05:6a20:c78f:b0:1c4:a49b:403 with SMTP id adf61e73a8af0-1c8d75dfd98mr314810637.46.1723467460243; Mon, 12 Aug 2024 05:57:40 -0700 (PDT) Received: from localhost.localdomain ([2620:11a:c019:0:65e:3115:2f58:c5fd]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d1c9ca6fafsm8183368a91.34.2024.08.12.05.57.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Aug 2024 05:57:39 -0700 (PDT) From: Joe Damato To: netdev@vger.kernel.org Cc: mkarsten@uwaterloo.ca, amritha.nambiar@intel.com, sridhar.samudrala@intel.com, sdf@fomichev.me, Joe Damato , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Jiri Pirko , Sebastian Andrzej Siewior , Lorenzo Bianconi , Daniel Borkmann , Breno Leitao , Johannes Berg , Alexander Lobakin , Heiner Kallweit , linux-doc@vger.kernel.org (open list:DOCUMENTATION), linux-kernel@vger.kernel.org (open list) Subject: [RFC net-next 1/5] net: Add sysfs parameter irq_suspend_timeout Date: Mon, 12 Aug 2024 12:57:04 +0000 Message-Id: <20240812125717.413108-2-jdamato@fastly.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240812125717.413108-1-jdamato@fastly.com> References: <20240812125717.413108-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 X-Patchwork-State: RFC From: Martin Karsten This patch doesn't change any behavior but prepares the code for other changes in the following commits which use irq_suspend_timeout as a timeout for IRQ suspension. Signed-off-by: Martin Karsten Co-developed-by: Joe Damato Signed-off-by: Joe Damato Tested-by: Joe Damato Tested-by: Martin Karsten --- Documentation/networking/napi.rst | 3 +++ include/linux/netdevice.h | 2 ++ net/core/dev.c | 3 ++- net/core/net-sysfs.c | 18 ++++++++++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Documentation/networking/napi.rst b/Documentation/networking/napi.rst index 7bf7b95c4f7a..0a029dd6d77e 100644 --- a/Documentation/networking/napi.rst +++ b/Documentation/networking/napi.rst @@ -192,6 +192,9 @@ The ``gro_flush_timeout`` sysfs configuration of the netdevice is reused to control the delay of the timer, while ``napi_defer_hard_irqs`` controls the number of consecutive empty polls before NAPI gives up and goes back to using hardware IRQs. +``irq_suspend_timeout`` is used to determine how long an application can +completely suspend IRQs. It is used in combination with SO_PREFER_BUSY_POLL, +which can be set on a per-epoll context basis with EPIOCSPARAMS ioctl. .. _poll: diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 0ef3eaa23f4b..31867bb2ff65 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -1857,6 +1857,7 @@ enum netdev_reg_state { * @gro_flush_timeout: timeout for GRO layer in NAPI * @napi_defer_hard_irqs: If not zero, provides a counter that would * allow to avoid NIC hard IRQ, on busy queues. + * @irq_suspend_timeout: IRQ suspension timeout * * @rx_handler: handler for received packets * @rx_handler_data: XXX: need comments on this one @@ -2060,6 +2061,7 @@ struct net_device { struct netdev_rx_queue *_rx; unsigned long gro_flush_timeout; int napi_defer_hard_irqs; + unsigned long irq_suspend_timeout; unsigned int gro_max_size; unsigned int gro_ipv4_max_size; rx_handler_func_t __rcu *rx_handler; diff --git a/net/core/dev.c b/net/core/dev.c index 751d9b70e6ad..bf45c90aebcd 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -11937,6 +11937,7 @@ static void __init net_dev_struct_check(void) CACHELINE_ASSERT_GROUP_MEMBER(struct net_device, net_device_read_rx, _rx); CACHELINE_ASSERT_GROUP_MEMBER(struct net_device, net_device_read_rx, gro_flush_timeout); CACHELINE_ASSERT_GROUP_MEMBER(struct net_device, net_device_read_rx, napi_defer_hard_irqs); + CACHELINE_ASSERT_GROUP_MEMBER(struct net_device, net_device_read_rx, irq_suspend_timeout); CACHELINE_ASSERT_GROUP_MEMBER(struct net_device, net_device_read_rx, gro_max_size); CACHELINE_ASSERT_GROUP_MEMBER(struct net_device, net_device_read_rx, gro_ipv4_max_size); CACHELINE_ASSERT_GROUP_MEMBER(struct net_device, net_device_read_rx, rx_handler); @@ -11948,7 +11949,7 @@ static void __init net_dev_struct_check(void) #ifdef CONFIG_NET_XGRESS CACHELINE_ASSERT_GROUP_MEMBER(struct net_device, net_device_read_rx, tcx_ingress); #endif - CACHELINE_ASSERT_GROUP_SIZE(struct net_device, net_device_read_rx, 104); + CACHELINE_ASSERT_GROUP_SIZE(struct net_device, net_device_read_rx, 112); } /* diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index 0e2084ce7b75..fb6f3327310f 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -440,6 +440,23 @@ static ssize_t napi_defer_hard_irqs_store(struct device *dev, } NETDEVICE_SHOW_RW(napi_defer_hard_irqs, fmt_dec); +static int change_irq_suspend_timeout(struct net_device *dev, unsigned long val) +{ + WRITE_ONCE(dev->irq_suspend_timeout, val); + return 0; +} + +static ssize_t irq_suspend_timeout_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + if (!capable(CAP_NET_ADMIN)) + return -EPERM; + + return netdev_store(dev, attr, buf, len, change_irq_suspend_timeout); +} +NETDEVICE_SHOW_RW(irq_suspend_timeout, fmt_ulong); + static ssize_t ifalias_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) { @@ -664,6 +681,7 @@ static struct attribute *net_class_attrs[] __ro_after_init = { &dev_attr_tx_queue_len.attr, &dev_attr_gro_flush_timeout.attr, &dev_attr_napi_defer_hard_irqs.attr, + &dev_attr_irq_suspend_timeout.attr, &dev_attr_phys_port_id.attr, &dev_attr_phys_port_name.attr, &dev_attr_phys_switch_id.attr, From patchwork Mon Aug 12 12:57:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Damato X-Patchwork-Id: 13760530 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (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 4BAA817C7B2 for ; Mon, 12 Aug 2024 12:57:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723467466; cv=none; b=pxzkmW1fzlyQIU5uH9Ajb164HQQJnNvDlb0Ihib6rItp5gRcGNectEOeTEEIQtCI9W42p9YONtBE7Nx565DbXCRqe5M+OwLjkXcuztJOKbBKF68RXNoP6Wkql48EE8/thc7/vffFA9ejV44OiX/qSCTWGuKiTm/l0rYzRIZTwvE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723467466; c=relaxed/simple; bh=h81+Cf/FoIZArgzM6U1M000nT8tJrt3BvAa1EBt9mlY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=La1se7wWqrBKqnaapW2Q9cxl7Md6Lu2XFA4bjwnYuCSAdWnBZ8dRM3hTr4wCvjoMgzPhYzV8Zez6+D5SSIfWZ/Q6DoUHtrNKfM8RN/k5u1QoQ4m7g1UxyqRgHhk0jBn3CMhXdaFov1lvGzF6PB08OYwipSA+8l/3fdTR9ykBZKQ= 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=jp28N/u3; arc=none smtp.client-ip=209.85.216.51 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="jp28N/u3" Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-2d1bb65e906so2716835a91.3 for ; Mon, 12 Aug 2024 05:57:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1723467464; x=1724072264; 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=zdwsD6mRq8PotE0EC67/Ywu4UmR2u6X+2YPXiDZOTRo=; b=jp28N/u3NsM2SHHQWhp0prleYeBYN456Y5vtCJGXJsODa2wRvkc/GACe5npFY82/24 0z9IiZYZ25fRU06QqMDLYwhNtQq0wi2eztCvSmMTm6mxJCJQlq4+d6gJrlhSxs2nMI8L vj/kzobj4cWizYOE9QJ4WZfDtuNe/U5VRZ8tQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723467464; x=1724072264; 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=zdwsD6mRq8PotE0EC67/Ywu4UmR2u6X+2YPXiDZOTRo=; b=Vgl1SFHD23o2NkLcoUW64lqxUsZxmKrYtSlL4y2QtCYuZ57j2dz1aN8fq3C+mshjX7 ex7wDxHDjS/7eGImq1CL2qCUpLkDHrobapwOagqRtEv4QAAVCDaG4N7px+AbBnCrxS+s hav28rHbR3CjvE0sgYRLvk7O/xKc8DG1sS/ypVb2zoo0Vnl95swz74jCMmGlNWlhu64k GNuhec/WD9MtXcKQpro8KsJk9IfWOho+N2oiVXFDGdaqbYCSmwZM3FmDSp0hR8u+d4Ec D/Gwzrj7oRNHFtMj+tsqjYPqW9rbKZ+0Sr8C/SMR1sLjEBpbKbgjQg6qH+LfQAsyBn8s QUsQ== X-Gm-Message-State: AOJu0YyXGV+h1SOEd57Klx+B6sTUbL0XRblk5qcgyIWC2MM2VY8mwaAx 79b1Zb46BCvQZX9zX2StDJAwiGeAX/GC5OWytpZhdRci0t5DN/61Iiey6jcKX//A/WsZ3nlBsY5 JszzUMMdgMUi8mpsfwW8LrXMeFavFsv6MHkOm6zIEvAc316TqK7izUg7WsbgMqL6QPoswunqoZi nwlWgaxrFEWHiZ6QP6MQTuCwv7LePYqXOMJFzI5Q== X-Google-Smtp-Source: AGHT+IHrTHT2rsvnZv/5M1nDOg/Mw5GaQZCHX9VDi3Sxjxr2CexacVo7Wrdip4TS79zOg2LzcHRmsA== X-Received: by 2002:a17:90b:350c:b0:2c9:64fb:1c7e with SMTP id 98e67ed59e1d1-2d39250f830mr128288a91.14.1723467464066; Mon, 12 Aug 2024 05:57:44 -0700 (PDT) Received: from localhost.localdomain ([2620:11a:c019:0:65e:3115:2f58:c5fd]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d1c9ca6fafsm8183368a91.34.2024.08.12.05.57.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Aug 2024 05:57:43 -0700 (PDT) From: Joe Damato To: netdev@vger.kernel.org Cc: mkarsten@uwaterloo.ca, amritha.nambiar@intel.com, sridhar.samudrala@intel.com, sdf@fomichev.me, Joe Damato , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jiri Pirko , Sebastian Andrzej Siewior , Lorenzo Bianconi , Daniel Borkmann , linux-kernel@vger.kernel.org (open list) Subject: [RFC net-next 2/5] net: Suspend softirq when prefer_busy_poll is set Date: Mon, 12 Aug 2024 12:57:05 +0000 Message-Id: <20240812125717.413108-3-jdamato@fastly.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240812125717.413108-1-jdamato@fastly.com> References: <20240812125717.413108-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 X-Patchwork-State: RFC From: Martin Karsten When NAPI_F_PREFER_BUSY_POLL is set during busy_poll_stop and the irq_suspend_timeout sysfs is nonzero, this timeout is used to defer softirq scheduling, potentially longer than gro_flush_timeout. This can be used to effectively suspend softirq processing during the time it takes for an application to process data and return to the next busy-poll. The call to napi->poll in busy_poll_stop might lead to an invocation of napi_complete_done, but the prefer-busy flag is still set at that time, so the same logic is used to defer softirq scheduling for irq_suspend_timeout. Signed-off-by: Martin Karsten Co-developed-by: Joe Damato Signed-off-by: Joe Damato Tested-by: Joe Damato Tested-by: Martin Karsten --- net/core/dev.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index bf45c90aebcd..a19470253eb4 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -6214,7 +6214,6 @@ bool napi_complete_done(struct napi_struct *n, int work_done) { unsigned long flags, val, new, timeout = 0; bool ret = true; - /* * 1) Don't let napi dequeue from the cpu poll list * just in case its running on a different cpu. @@ -6230,7 +6229,12 @@ bool napi_complete_done(struct napi_struct *n, int work_done) timeout = READ_ONCE(n->dev->gro_flush_timeout); n->defer_hard_irqs_count = READ_ONCE(n->dev->napi_defer_hard_irqs); } - if (n->defer_hard_irqs_count > 0) { + if (napi_prefer_busy_poll(n)) { + timeout = READ_ONCE(n->dev->irq_suspend_timeout); + if (timeout) + ret = false; + } + if (ret && n->defer_hard_irqs_count > 0) { n->defer_hard_irqs_count--; timeout = READ_ONCE(n->dev->gro_flush_timeout); if (timeout) @@ -6349,7 +6353,6 @@ static void busy_poll_stop(struct napi_struct *napi, void *have_poll_lock, bool skip_schedule = false; unsigned long timeout; int rc; - /* Busy polling means there is a high chance device driver hard irq * could not grab NAPI_STATE_SCHED, and that NAPI_STATE_MISSED was * set in napi_schedule_prep(). @@ -6366,9 +6369,13 @@ static void busy_poll_stop(struct napi_struct *napi, void *have_poll_lock, bpf_net_ctx = bpf_net_ctx_set(&__bpf_net_ctx); if (flags & NAPI_F_PREFER_BUSY_POLL) { - napi->defer_hard_irqs_count = READ_ONCE(napi->dev->napi_defer_hard_irqs); - timeout = READ_ONCE(napi->dev->gro_flush_timeout); - if (napi->defer_hard_irqs_count && timeout) { + timeout = READ_ONCE(napi->dev->irq_suspend_timeout); + if (!timeout) { + napi->defer_hard_irqs_count = READ_ONCE(napi->dev->napi_defer_hard_irqs); + if (napi->defer_hard_irqs_count) + timeout = READ_ONCE(napi->dev->gro_flush_timeout); + } + if (timeout) { hrtimer_start(&napi->timer, ns_to_ktime(timeout), HRTIMER_MODE_REL_PINNED); skip_schedule = true; } From patchwork Mon Aug 12 12:57:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Damato X-Patchwork-Id: 13760531 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) (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 6768317CA04 for ; Mon, 12 Aug 2024 12:57:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723467470; cv=none; b=uypvtLU0X+sGm5JSG/kThpTkwZFc4ytmcDwwSxZ0i7o0HErEv4bX/gLdjEOfVirRvCJRFXL+hhsWNRoUlbg/ZDfEyPA1JB0aHDiwuEoohZc8/TLlxTb0wGWbIq7Lcb84zp5tNgDiDEXuAeJiWfWyIaqdRWl13zWvmdr03N4F6Ds= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723467470; c=relaxed/simple; bh=7D4nSopAswje42tiwfemXKteeIJlxL8CBnP83xM8vMg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=W2r34mlcxD+MBmt9Nt8ZbgsjxB+R+r8PkfLLZpfwgVMRqdG8c/7F+wzK34zTy89QToYu9dRZLYA6dRu62DHVAxZW/rhPeq6alnzzR9cE5Ol2ubvcIBHH1PPezI3HD2i1r/lMBAu7ULx2A13mDcMnIb0LrTQRxfFzClZvNmzYJZA= 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=csCCVyQY; arc=none smtp.client-ip=209.85.216.48 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="csCCVyQY" Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-2cb53da06a9so2849406a91.0 for ; Mon, 12 Aug 2024 05:57:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1723467468; x=1724072268; 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=R8EIjZ+dOaHiyTQHWoEcWpqwaxp1crrF3ZUUT4V7ceY=; b=csCCVyQYpAGMV/2jvPAAWSan3sxedvdHRjPQypPCYy4s/ao6ZEqMU86RT84rxmv4Vs /gTMds7ik6xVnflvP/cLASq5l3I0NTKJdi/kU6o3hZpmLRbfsGFxuwCmJhFN/1/IV6W0 bz5bYHsoR5nrvBBhAih5Nj772TDLiX/t7EZTQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723467468; x=1724072268; 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=R8EIjZ+dOaHiyTQHWoEcWpqwaxp1crrF3ZUUT4V7ceY=; b=SABWxrgE9EZZSgnUECB3pC1Z30fDJrra7LSyHYQnQ7R47Nrzv6DyczXn+ZApjLbu9p im/rs256QX24toOBAXnQe5pmNFJNut4Jxo0G/utb1yvTXBx85PbFncO264HoRl04m9Dh bSwTR7JEWdSEisspFho2gHlCkim6MmWDJLhZbYwruBzZqfskTwOQlfd4FCVhUMO0bbWb jhRnTQr77FzGKOSS2O3O0B/vWiMcE2jD6Tp0vAmy5f4k9TsYuI6ZzvqV5P74CM2/Ilyv CDI5tp+WHP5f330nO5uCLohkECFqNv1/XvLkKWU5wKSwFj+BNBHyL2FU9QvUDKanVEdL Le4A== X-Gm-Message-State: AOJu0YzHtztLG2yBpUy+wMpCDtY2DOlRay4j07F69lmwcdojhGzVv6nM HNh39OMAcuTmGilKP80hWaAzu9A/1kIQdP8Obo6VA+j3af0h5cgdMIFiOFf8jaTnjuhoFYac2rk OurNTwTgTtyAk12CI+SZo2LFNVLe7+B1+ZxMvDSEjwlS4KPdhK1oXT9TTUizo4jh5Qoxs6WHlP9 zPgDcGSl47X53WnvN4zdOrF6v5fTnOdxtxRl4vIA== X-Google-Smtp-Source: AGHT+IGhoYSk07I5fC4BrCFew7CkXaFEzmv02TFPAarMCe+LsdgSiAssK/J9JSq72T4HY5C3UL3rwg== X-Received: by 2002:a17:90b:350c:b0:2c8:2236:e2c3 with SMTP id 98e67ed59e1d1-2d392abdd84mr10304a91.17.1723467467903; Mon, 12 Aug 2024 05:57:47 -0700 (PDT) Received: from localhost.localdomain ([2620:11a:c019:0:65e:3115:2f58:c5fd]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d1c9ca6fafsm8183368a91.34.2024.08.12.05.57.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Aug 2024 05:57:47 -0700 (PDT) From: Joe Damato To: netdev@vger.kernel.org Cc: mkarsten@uwaterloo.ca, amritha.nambiar@intel.com, sridhar.samudrala@intel.com, sdf@fomichev.me, Joe Damato , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jiri Pirko , Sebastian Andrzej Siewior , Lorenzo Bianconi , Daniel Borkmann , linux-kernel@vger.kernel.org (open list) Subject: [RFC net-next 3/5] net: Add control functions for irq suspension Date: Mon, 12 Aug 2024 12:57:06 +0000 Message-Id: <20240812125717.413108-4-jdamato@fastly.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240812125717.413108-1-jdamato@fastly.com> References: <20240812125717.413108-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 X-Patchwork-State: RFC From: Martin Karsten The napi_suspend_irqs routine bootstraps irq suspension by elongating the defer timeout to irq_suspend_timeout. The napi_resume_irqs routine effectly cancels irq suspension by forcing the napi to be scheduled immediately. Signed-off-by: Martin Karsten Co-developed-by: Joe Damato Signed-off-by: Joe Damato Tested-by: Joe Damato Tested-by: Martin Karsten --- include/net/busy_poll.h | 3 +++ net/core/dev.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/net/busy_poll.h b/include/net/busy_poll.h index 9b09acac538e..f095b2bdeee1 100644 --- a/include/net/busy_poll.h +++ b/include/net/busy_poll.h @@ -52,6 +52,9 @@ void napi_busy_loop_rcu(unsigned int napi_id, bool (*loop_end)(void *, unsigned long), void *loop_end_arg, bool prefer_busy_poll, u16 budget); +void napi_suspend_irqs(unsigned int napi_id); +void napi_resume_irqs(unsigned int napi_id); + #else /* CONFIG_NET_RX_BUSY_POLL */ static inline unsigned long net_busy_loop_on(void) { diff --git a/net/core/dev.c b/net/core/dev.c index a19470253eb4..bd23f2c68558 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -6505,6 +6505,39 @@ void napi_busy_loop(unsigned int napi_id, } EXPORT_SYMBOL(napi_busy_loop); +void napi_suspend_irqs(unsigned int napi_id) +{ + struct napi_struct *napi; + + rcu_read_lock(); + napi = napi_by_id(napi_id); + if (napi) { + unsigned long timeout = READ_ONCE(napi->dev->irq_suspend_timeout); + + if (timeout) + hrtimer_start(&napi->timer, ns_to_ktime(timeout), HRTIMER_MODE_REL_PINNED); + } + rcu_read_unlock(); +} +EXPORT_SYMBOL(napi_suspend_irqs); + +void napi_resume_irqs(unsigned int napi_id) +{ + struct napi_struct *napi; + + rcu_read_lock(); + napi = napi_by_id(napi_id); + if (napi) { + if (READ_ONCE(napi->dev->irq_suspend_timeout)) { + local_bh_disable(); + napi_schedule(napi); + local_bh_enable(); + } + } + rcu_read_unlock(); +} +EXPORT_SYMBOL(napi_resume_irqs); + #endif /* CONFIG_NET_RX_BUSY_POLL */ static void napi_hash_add(struct napi_struct *napi) From patchwork Mon Aug 12 12:57:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Damato X-Patchwork-Id: 13760532 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) (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 A5F2217D340 for ; Mon, 12 Aug 2024 12:57:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723467472; cv=none; b=AW51Tj4GJynnKRd8GZn6ZRAF+4m685A+Hi6x196w6KDMW6rIC4WhBKAavyysphoClHd2dnMQfJ791HtAymonpHk3rBi2LJmVHxjp6ZZ0PyQoRh0uiqid00DDQDjbFaz/mw00mQKjV0Al5S3mnKmkk6hhUkpkFWl9HrAF2Qp9P0E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723467472; c=relaxed/simple; bh=uGO5dEJrzAGpkDGXLrC8ztAywM3dRMCy6F4elADygWk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=XMr8BHsOvi7F8RsMGx/CXew7H+FoVF51vxOScT27Q2KDc34vGpZUEvQe5LemUU2VXmSHs3dcPy3FWgDj7Xyu4u9PsPuzi/GyWoO8sRnhDiiHOF+otoNYaleNJ/5keh998qpvFvcegHPHvb4h8AehiQVixr8Q3ggbL9et8uZ5YSE= 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=Ec759tHm; arc=none smtp.client-ip=209.85.216.43 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="Ec759tHm" Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-2cb4b7fef4aso3380544a91.0 for ; Mon, 12 Aug 2024 05:57:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1723467469; x=1724072269; 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=Ec759tHmiiGhgXoUEENfBjcubXA0apvXqhwmY2HjIeK4pU4mXeTqHHRpIzpRCmZydv ZEUTnBcD/A6jnVUa2hdCfp0Wsxdetqt8g/7KVs4/H9bV1MeKqWEQFvbwtPI2P/HKRYLH B2I3+X/BFppZjTgk5y7WYuZWqm8ilH+/sg7w4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723467469; x=1724072269; 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=gOB0zDuzzfk4oU+D3ELGpNV5OhYC1M1Sp0Z0p9LgPPFyg6WznWVkAR54+UB8Rjv4q7 mfEoB8sQiX9g+YR0lomVbS8tzzazZ0LgW1S6XdYiHC0ea4Rz3Jbdlylu4+JxNKELK5ua +vSJ6W6fT0mx5AE/KC/aZmtmfKtjwYaPA3uoJXxBcHxyjjLGB4e8e5IG7lZmUAESFY2t YwIV8Ha0Rccyju5TYuL0E/lbTDoWK5dmnLrcvQVXxrHf9QfTddL5aRBLZOb9iOnnsfEP Rpv+J4qMJbJ8qxFCEvbrgeVxHUHeslmzG8RU3LQ7tUEvYnQjBDzBWhPkcrK+81Z0C8qJ FyRQ== X-Gm-Message-State: AOJu0Yyh6OvMPKSM+sAGorUkHwXdimoOweROJWvnvo/u+gyhp3BOINnm AW+ayOQGllwrDbTLEtre8ATjshWP2u6NoNxt737XMvDpJ4GX5bSpH/xywu0DPGIlaisEQ468y9Q 7yfSDV/ebwlHTJTvBZiFwuqkjK4da78VFTF+vA87zYMBB35kBAKrb54RUGyTgl94sejgt9Ri8OR OSVXyNj31Ehn4UFPgESvZ1pXKbFoifOCfVF/T7iw== X-Google-Smtp-Source: AGHT+IGFlBi1X8/Y7i5u30ax6RMbfkRifnWc7b7YQe3Aid69JjvZ1u0IpdtiYAyCV6l+7Dbup8PUIQ== X-Received: by 2002:a17:90a:53e1:b0:2cd:40ef:4764 with SMTP id 98e67ed59e1d1-2d392510ccamr117032a91.17.1723467469481; Mon, 12 Aug 2024 05:57:49 -0700 (PDT) Received: from localhost.localdomain ([2620:11a:c019:0:65e:3115:2f58:c5fd]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d1c9ca6fafsm8183368a91.34.2024.08.12.05.57.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Aug 2024 05:57:49 -0700 (PDT) From: Joe Damato To: netdev@vger.kernel.org Cc: mkarsten@uwaterloo.ca, amritha.nambiar@intel.com, sridhar.samudrala@intel.com, sdf@fomichev.me, 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: [RFC net-next 4/5] eventpoll: Trigger napi_busy_loop, if prefer_busy_poll is set Date: Mon, 12 Aug 2024 12:57:07 +0000 Message-Id: <20240812125717.413108-5-jdamato@fastly.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240812125717.413108-1-jdamato@fastly.com> References: <20240812125717.413108-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 X-Patchwork-State: RFC 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 Mon Aug 12 12:57:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Damato X-Patchwork-Id: 13760533 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (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 183BF17DE15 for ; Mon, 12 Aug 2024 12:57:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723467473; cv=none; b=ccj6Pg/mmgf5RbP4FgPDv+HnQtRlSu5P29DJkvpAnwxSBnLpykNoPB28Lp/m3MBctCq3PDyuebUgHo/Maki53fCFuswzqxXsbQCOFLevpAOfYNNrLWGXkVO/6TA8tsRPsqTO/iNEYqUZ6eqCF3YAAKJNgArsLAyB1eV2eXSu3pg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723467473; c=relaxed/simple; bh=ayLYRx3QKfi6gmR7b4DhUiYvDsWYqJuL4KCn2w5LCzE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZCbPYbmNarbDsfy+27pI6+XVJWUV/6X9I62mERrd+E55Szf75kHh5DXHysZI76OLqR7Yupt58PN3kNstXiSWelJx87UzxR0Ty24MejsY2+vjQ8ZBOIVWuB7OpLWygQAepOYqCbxvSfWPUfGA2qcVp8KqEg+0BX1K4OwQ42VTrcE= 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=ubMnQW0u; arc=none smtp.client-ip=209.85.215.182 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="ubMnQW0u" Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-7a23fbb372dso2585618a12.0 for ; Mon, 12 Aug 2024 05:57:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1723467471; x=1724072271; 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=GsO15pwNsB215SzDNzNe7pDnu6o5GjMMYX4qU8sz+wY=; b=ubMnQW0uWxTuFizaWewZgJbZ97O4EkKDpmEsQFN7xS4dEszQFfFkx4eGTDO8LuJm4H 3pnCBEA+HEoUMQ+iClrGRVvOUCY9RialylxtfhtgqDeDWf8R+Vxow786n5CRWIXzw7/j i+ZDNJ/QQHrP0hL78HO7J+1cSvqk14KxFqURY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723467471; x=1724072271; 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=GsO15pwNsB215SzDNzNe7pDnu6o5GjMMYX4qU8sz+wY=; b=MSwVkczK7vcxQR8OM9ZULQxWlhsfjjOPGSo4NmDQONnYmtKSnOy1ExzDQ67iQxCwWQ nlA99WNHiWrTmGTlKYeUOoFFZ5V5LE+t/KtY7fczQjxNwm11o5jFR22+bZZHLAnq1Cz9 93zVlK8d22fyC7h4rca6pHmcO0xku8c1d1FgfUEtBie2RyfufBXJiSY5Hao3yutmsjaD CVTitQPU6rzf1qaF1W2JqymVdiCa1zjDx/DnNn/e/r981srucAYQYAAsFNKBBKuqe1T0 Cm5BWBJcE8Vv3UwE9CYroqusPUCXO2I3dHG24inYjzPlE+UaRQASB/AvG8PKfbFcnMTJ FJzg== X-Gm-Message-State: AOJu0Yz3/xTznEZxnSBJIu511Wm4IYCKmVn0GDaw1llBbe4lfzIqPL2a xdAnXGAgSBqUNoIwP62VApLjGjFmstEkuXQz4Ti50oPanfU2U6u1XngzKbBtsHT/P5sOB9DeldU bj1GS5048M6XN4mCH9TFsdVrYqd3Ew4umeH66247bZucUV4Mb2iS8as0BPQV+fPLJOwJX5jmbQ8 UcH+in836OKfRtZDoUEszCr15BeCkgGmIXc4bL7w== X-Google-Smtp-Source: AGHT+IFORSWX0ysgwFR7RQ99ft+D14MIbt0Ie8vdK9uiCSKuM0XLaRfZUtZDgUJaa+RQRY7CagNyAw== X-Received: by 2002:a17:90a:bf05:b0:2c5:10a6:e989 with SMTP id 98e67ed59e1d1-2d39265846bmr99107a91.35.1723467471060; Mon, 12 Aug 2024 05:57:51 -0700 (PDT) Received: from localhost.localdomain ([2620:11a:c019:0:65e:3115:2f58:c5fd]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d1c9ca6fafsm8183368a91.34.2024.08.12.05.57.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Aug 2024 05:57:50 -0700 (PDT) From: Joe Damato To: netdev@vger.kernel.org Cc: mkarsten@uwaterloo.ca, amritha.nambiar@intel.com, sridhar.samudrala@intel.com, sdf@fomichev.me, 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: [RFC net-next 5/5] eventpoll: Control irq suspension for prefer_busy_poll Date: Mon, 12 Aug 2024 12:57:08 +0000 Message-Id: <20240812125717.413108-6-jdamato@fastly.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240812125717.413108-1-jdamato@fastly.com> References: <20240812125717.413108-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 X-Patchwork-State: RFC 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 --- fs/eventpoll.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/fs/eventpoll.c b/fs/eventpoll.c index cc47f72005ed..d74b5b9c1f51 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,14 @@ 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); +} + #else static inline bool ep_busy_loop(struct eventpoll *ep, int nonblock) @@ -557,6 +567,10 @@ static long ep_eventpoll_bp_ioctl(struct file *file, unsigned int cmd, return -EOPNOTSUPP; } +static void ep_suspend_napi_irqs(struct eventpoll *ep) +{ +} + #endif /* CONFIG_NET_RX_BUSY_POLL */ /* @@ -788,6 +802,10 @@ static bool ep_refcount_dec_and_test(struct eventpoll *ep) static void ep_free(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); mutex_destroy(&ep->mtx); free_uid(ep->user); wakeup_source_unregister(ep->ws); @@ -2005,8 +2023,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)