From nobody Sun Feb 8 00:03:47 2026 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) (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 540981AB515 for ; Thu, 29 Aug 2024 13:13:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724937183; cv=none; b=aiPbmqRxU2f7M+naJk75+s+oUHYWb8uP5uNO4UaWJENTa7OTyk8hkhhr3ZVFe42Gf9PKHHruOAJfQaxanm7MgVwNohGhjuQkTmpROUIoz/s0KWPcAe07OvSiR/7CUM8GueLwW65GuG6S8xKsTg8QRWKxHT7yboPZgGGc+cl0o98= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724937183; c=relaxed/simple; bh=TY/JWmRiSZtiMQ0TAf+u6i4UVWxaSuovZzLy2w5lMjc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=b1yjC6tWUlYzUVHuvQOF+ENv1oJNeJ7WnuN0XCEuKn8chy8qcMV5pDxqONPNeEmKMmPZxI0C+ntqlk48DCbAm8YwpSd0PjTFsokw8hfv6NOyyBTO/uiVHRQOMDAFVPRCf0th2kutlkjlsZqLBs2sAkP/ecblOdeN2u9pscGI2NU= 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=J7BARKZT; arc=none smtp.client-ip=209.85.216.47 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="J7BARKZT" Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-2d3da6d3f22so468652a91.0 for ; Thu, 29 Aug 2024 06:13:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1724937181; x=1725541981; 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=22aHmfqwjI90w/pPkOedAr7NxRy2oPkhi9j2dLkCk3E=; b=J7BARKZTBJlurgm2QemHh9gZCzRCexXHiZFc55cvdyKqlIrZJYqbi0oY3e3fUoJ4sR d3F5seEjZaSvBVtWvxkWVTW4BgQ2tBb6tUQX/JoN5x4jqFBgFid4ihnHtloQUyeJqQU0 9QbzfLXODbUShWZvptvJAkrxnKXMsmVYSNXb4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724937181; x=1725541981; 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=22aHmfqwjI90w/pPkOedAr7NxRy2oPkhi9j2dLkCk3E=; b=PKoQcyo2ia5cCp0PRSapTbtahD0rW4Wc4Aj8Z7avt+928NnSTLTO1P6EYMJQn1ZCVo 3Fr5wxUGsVdKAQVaLvEXtN0gPvMJ4SpiPKh9ZV+nhQXPtjNBOTny/OUxEAWSFknK0Acs PnCdiE6tXnxeKpmYrqorEaWynBrfGKNrPhFi96nXEscygethp9DeRRPLKwsQTRe9StCn SE40YAUcJsuBcu2MzV3lIIq9BmepdSrmrvdzHXTk/kjO4NNxbZY33ehgj7PkrzpRbfx5 8hLnC1ftXpdk4t/xM4NQXm+YeMFFi/v2V+De1zCvo8u87Z+vrmglm/v5EyNNlatvBhTH umjw== X-Forwarded-Encrypted: i=1; AJvYcCVcEZaY1Ry7OKh03iZf62MYy0FKGLBGQxvGTGHoGOmwRmeKWQGTMwz193qGiTKc97ERmzfNRl1u2/5Yvu8=@vger.kernel.org X-Gm-Message-State: AOJu0YyhW+8CuYCyOptgVnGOboGv6gnX7GpihxBFsziWhCRJqgxPexLn nv8IAhcDq+utEY2EA0P3JvEw+pGkECJBOmjBb3ly/HHK+W6FJxx++AzK3UByn4Y= X-Google-Smtp-Source: AGHT+IFvljfc/Yc183V5qkQ42ui0+yJbXNPmaZhUq6obEMakZydtd3fXFn77oKh/p+qGKoJg8oZ3Lg== X-Received: by 2002:a17:90b:1c01:b0:2d0:153f:ce00 with SMTP id 98e67ed59e1d1-2d85649ea90mr2664660a91.41.1724937181433; Thu, 29 Aug 2024 06:13:01 -0700 (PDT) Received: from localhost.localdomain ([2620:11a:c019:0:65e:3115:2f58:c5fd]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-205152b13c9sm10991065ad.62.2024.08.29.06.12.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2024 06:12:58 -0700 (PDT) From: Joe Damato To: netdev@vger.kernel.org Cc: edumazet@google.com, amritha.nambiar@intel.com, sridhar.samudrala@intel.com, sdf@fomichev.me, bjorn@rivosinc.com, hch@infradead.org, willy@infradead.org, willemdebruijn.kernel@gmail.com, skhawaja@google.com, kuba@kernel.org, Joe Damato , Martin Karsten , "David S. Miller" , Paolo Abeni , Jiri Pirko , Sebastian Andrzej Siewior , Lorenzo Bianconi , Breno Leitao , Johannes Berg , Alexander Lobakin , linux-kernel@vger.kernel.org (open list) Subject: [PATCH net-next 1/5] net: napi: Make napi_defer_hard_irqs per-NAPI Date: Thu, 29 Aug 2024 13:11:57 +0000 Message-Id: <20240829131214.169977-2-jdamato@fastly.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240829131214.169977-1-jdamato@fastly.com> References: <20240829131214.169977-1-jdamato@fastly.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Allow per-NAPI defer_hard_irqs setting. The existing sysfs parameter is respected; writes to sysfs will write to all NAPI structs for the device and the net_device defer_hard_irq field. Reads from sysfs will read from the net_device field. sysfs code was updated to guard against what appears to be a potential overflow as the field is an int, but the value passed in is an unsigned long. The ability to set defer_hard_irqs on specific NAPI instances will be added in a later commit, via netdev-genl. Signed-off-by: Joe Damato Reviewed-by: Martin Karsten Tested-by: Martin Karsten --- include/linux/netdevice.h | 23 +++++++++++++++++++++++ net/core/dev.c | 29 ++++++++++++++++++++++++++--- net/core/net-sysfs.c | 5 ++++- 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index fce70990b209..7d53380da4c0 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -371,6 +371,7 @@ struct napi_struct { struct list_head rx_list; /* Pending GRO_NORMAL skbs */ int rx_count; /* length of rx_list */ unsigned int napi_id; + int defer_hard_irqs; struct hrtimer timer; struct task_struct *thread; /* control-path-only fields follow */ @@ -534,6 +535,28 @@ static inline void napi_schedule_irqoff(struct napi_st= ruct *n) __napi_schedule_irqoff(n); } =20 +/** + * napi_get_defer_hard_irqs - get the NAPI's defer_hard_irqs + * @n: napi struct to get the defer_hard_irqs field from + * + * Returns the per-NAPI value of the defar_hard_irqs field. + */ +int napi_get_defer_hard_irqs(const struct napi_struct *n); + +/** + * napi_set_defer_hard_irqs - set the defer_hard_irqs for a napi + * @n: napi_struct to set the defer_hard_irqs field + * @defer: the value the field should be set to + */ +void napi_set_defer_hard_irqs(struct napi_struct *n, int defer); + +/** + * netdev_set_defer_hard_irqs - set defer_hard_irqs for all NAPIs of a net= dev + * @netdev: the net_device for which all NAPIs will have their defer_hard_= irqs set + * @defer: the defer_hard_irqs value to set + */ +void netdev_set_defer_hard_irqs(struct net_device *netdev, int defer); + /** * napi_complete_done - NAPI processing complete * @n: NAPI context diff --git a/net/core/dev.c b/net/core/dev.c index 63987b8b7c85..f7baff0da057 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -6212,6 +6212,28 @@ void __napi_schedule_irqoff(struct napi_struct *n) } EXPORT_SYMBOL(__napi_schedule_irqoff); =20 +int napi_get_defer_hard_irqs(const struct napi_struct *n) +{ + return READ_ONCE(n->defer_hard_irqs); +} +EXPORT_SYMBOL_GPL(napi_get_defer_hard_irqs); + +void napi_set_defer_hard_irqs(struct napi_struct *n, int defer) +{ + WRITE_ONCE(n->defer_hard_irqs, defer); +} +EXPORT_SYMBOL_GPL(napi_set_defer_hard_irqs); + +void netdev_set_defer_hard_irqs(struct net_device *netdev, int defer) +{ + struct napi_struct *napi; + + WRITE_ONCE(netdev->napi_defer_hard_irqs, defer); + list_for_each_entry(napi, &netdev->napi_list, dev_list) + napi_set_defer_hard_irqs(napi, defer); +} +EXPORT_SYMBOL_GPL(netdev_set_defer_hard_irqs); + bool napi_complete_done(struct napi_struct *n, int work_done) { unsigned long flags, val, new, timeout =3D 0; @@ -6230,7 +6252,7 @@ bool napi_complete_done(struct napi_struct *n, int wo= rk_done) if (work_done) { if (n->gro_bitmask) timeout =3D READ_ONCE(n->dev->gro_flush_timeout); - n->defer_hard_irqs_count =3D READ_ONCE(n->dev->napi_defer_hard_irqs); + n->defer_hard_irqs_count =3D napi_get_defer_hard_irqs(n); } if (n->defer_hard_irqs_count > 0) { n->defer_hard_irqs_count--; @@ -6368,7 +6390,7 @@ static void busy_poll_stop(struct napi_struct *napi, = void *have_poll_lock, bpf_net_ctx =3D bpf_net_ctx_set(&__bpf_net_ctx); =20 if (flags & NAPI_F_PREFER_BUSY_POLL) { - napi->defer_hard_irqs_count =3D READ_ONCE(napi->dev->napi_defer_hard_irq= s); + napi->defer_hard_irqs_count =3D napi_get_defer_hard_irqs(napi); timeout =3D READ_ONCE(napi->dev->gro_flush_timeout); if (napi->defer_hard_irqs_count && timeout) { hrtimer_start(&napi->timer, ns_to_ktime(timeout), HRTIMER_MODE_REL_PINN= ED); @@ -6650,6 +6672,7 @@ void netif_napi_add_weight(struct net_device *dev, st= ruct napi_struct *napi, INIT_HLIST_NODE(&napi->napi_hash_node); hrtimer_init(&napi->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_PINNED); napi->timer.function =3D napi_watchdog; + napi_set_defer_hard_irqs(napi, READ_ONCE(dev->napi_defer_hard_irqs)); init_gro_hash(napi); napi->skb =3D NULL; INIT_LIST_HEAD(&napi->rx_list); @@ -11032,7 +11055,7 @@ void netdev_sw_irq_coalesce_default_on(struct net_d= evice *dev) =20 if (!IS_ENABLED(CONFIG_PREEMPT_RT)) { dev->gro_flush_timeout =3D 20000; - dev->napi_defer_hard_irqs =3D 1; + netdev_set_defer_hard_irqs(dev, 1); } } EXPORT_SYMBOL_GPL(netdev_sw_irq_coalesce_default_on); diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index 0e2084ce7b75..8272f0144d81 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -425,7 +425,10 @@ NETDEVICE_SHOW_RW(gro_flush_timeout, fmt_ulong); =20 static int change_napi_defer_hard_irqs(struct net_device *dev, unsigned lo= ng val) { - WRITE_ONCE(dev->napi_defer_hard_irqs, val); + if (val > S32_MAX) + return -EINVAL; + + netdev_set_defer_hard_irqs(dev, (int)val); return 0; } =20 --=20 2.25.1 From nobody Sun Feb 8 00:03:47 2026 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.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 59F4915E5C0 for ; Thu, 29 Aug 2024 13:13:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724937187; cv=none; b=TEDUcdjeBZoL0U5nkQvezm3bOfro1TfB+pC/Gyg/8w5cH5NVpI96H6ceYuiEvnT203wNeGMhl7BjrPz9EKFdCwqPt7sJbOzMtXIPXe8WXj7jGhQVhc82Y9mFR5ZvPypQc6q15Y3xHhgdjRoVcYthE/1wyAMAq4nkaZe6f8d+9Mc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724937187; c=relaxed/simple; bh=hI4+39auvENKp36mFZMcEI8Wdw4l29SOp94j/CNObFg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=OCopo1B0mZm0B8YZW7yj5vrtXfHST3Oy7Rp0SRp7KSZWVDAXlvrg9f+mS3Xk0cd8ORTijlP7ki5KRy93BA7+gYlkX3ge9V4Q+OSw3EXbjfrduoiqjjtLSZnPYepspCo31WIRGS4X8GB9UNDFRAZgudrUsYaZCuY7osP93n4jkeI= 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=aFO1iV4r; arc=none smtp.client-ip=209.85.214.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="aFO1iV4r" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-2020ac89cabso6410445ad.1 for ; Thu, 29 Aug 2024 06:13:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1724937186; x=1725541986; 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=QwTZLEJ2ZNvenqmXoy3WWd4FEjeXbWDB+TnZ5AXOvhg=; b=aFO1iV4rweXgViHmecblQiVE/N7wC6Gt8Suo+QyIXbeUuL0Zd6DNz1E2+eQkW5lIIm UX498E/QnOwlewLP2uwbWufdfVIm3t++q1i/SXbwqUXcXx40sY6thcfQhWrCPIby5QDL NyfpqU7YpU0JtnMdgD4zCzXgSYVDI5kBhlG0c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724937186; x=1725541986; 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=QwTZLEJ2ZNvenqmXoy3WWd4FEjeXbWDB+TnZ5AXOvhg=; b=sQ0xHfY1O09syIkmIamTRSmfj7R9EWlLCp3li2/W3/rfhyzUKdNifvAX3YwHu0I5ti Ahmtck4lw/TXiseZltGAauY1rsP2Ut3NtZK5aWvDNbzMKR/Yx3IQMIrwIlH++TQOAMwq +lSiWotsP+2k8brD1HO1WU6K13HbJRa4GcDR38maA49qS7y/kGUSUmUkUAq35OkstnEm 6+Tqx6uF1aIAsP4dlkEbZhwQpamUSUVVatnglxBsLzxY6Dw5AkLqj42OZ4o9NA5HcDNY EdUYjREb8iXoLe2WvPxxSQxH0PG+T2IQ6WSgc8L0ZhD6uMgEX8UHCTkedqPwcXj7+max E4Zg== X-Forwarded-Encrypted: i=1; AJvYcCWKttulYOVn+M6YzRNjtPBL3hTrYMkAZuEKgNWTu4bcKIFxaZzk8U7JX64mj1siDSFzJ+2fI9A7E785Mcc=@vger.kernel.org X-Gm-Message-State: AOJu0Yxu+wnGJMyt9Xw6Xymm3+tliDjDmC9BB4o3ex6N0eSyPUvzCpss LXhgNDFWj4Jd+MeHbXwAUinyVur+WMGC2MHXzQOYZlmZKQly4DvELeB9/Ym44GE= X-Google-Smtp-Source: AGHT+IHEgtDmE2CuvduFpYds2GdlAP6Z4Pt5/esDzsjD/wrNuL1lTsangnC1P7Fn1KVRiDEbmgMxJA== X-Received: by 2002:a05:6a20:c886:b0:1ca:ccd0:582b with SMTP id adf61e73a8af0-1cce0fea613mr2633025637.10.1724937185537; Thu, 29 Aug 2024 06:13:05 -0700 (PDT) Received: from localhost.localdomain ([2620:11a:c019:0:65e:3115:2f58:c5fd]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-205152b13c9sm10991065ad.62.2024.08.29.06.13.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2024 06:13:05 -0700 (PDT) From: Joe Damato To: netdev@vger.kernel.org Cc: edumazet@google.com, amritha.nambiar@intel.com, sridhar.samudrala@intel.com, sdf@fomichev.me, bjorn@rivosinc.com, hch@infradead.org, willy@infradead.org, willemdebruijn.kernel@gmail.com, skhawaja@google.com, kuba@kernel.org, Joe Damato , Martin Karsten , Donald Hunter , "David S. Miller" , Paolo Abeni , Jesper Dangaard Brouer , Xuan Zhuo , Daniel Jurgens , linux-kernel@vger.kernel.org (open list) Subject: [PATCH net-next 2/5] netdev-genl: Dump napi_defer_hard_irqs Date: Thu, 29 Aug 2024 13:11:58 +0000 Message-Id: <20240829131214.169977-3-jdamato@fastly.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240829131214.169977-1-jdamato@fastly.com> References: <20240829131214.169977-1-jdamato@fastly.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Support dumping defer_hard_irqs for a NAPI ID. Signed-off-by: Joe Damato Reviewed-by: Martin Karsten Tested-by: Martin Karsten --- Documentation/netlink/specs/netdev.yaml | 6 ++++++ include/uapi/linux/netdev.h | 1 + net/core/netdev-genl.c | 5 +++++ tools/include/uapi/linux/netdev.h | 1 + 4 files changed, 13 insertions(+) diff --git a/Documentation/netlink/specs/netdev.yaml b/Documentation/netlin= k/specs/netdev.yaml index 959755be4d7f..ee4f99fd4574 100644 --- a/Documentation/netlink/specs/netdev.yaml +++ b/Documentation/netlink/specs/netdev.yaml @@ -244,6 +244,11 @@ attribute-sets: threaded mode. If NAPI is not in threaded mode (i.e. uses nor= mal softirq context), the attribute will be absent. type: u32 + - + name: defer-hard-irqs + doc: The number of consecutive empty polls before IRQ deferral ends + and hardware IRQs are re-enabled. + type: s32 - name: queue attributes: @@ -593,6 +598,7 @@ operations: - ifindex - irq - pid + - defer-hard-irqs dump: request: attributes: diff --git a/include/uapi/linux/netdev.h b/include/uapi/linux/netdev.h index 43742ac5b00d..43bb1aad9611 100644 --- a/include/uapi/linux/netdev.h +++ b/include/uapi/linux/netdev.h @@ -121,6 +121,7 @@ enum { NETDEV_A_NAPI_ID, NETDEV_A_NAPI_IRQ, NETDEV_A_NAPI_PID, + NETDEV_A_NAPI_DEFER_HARD_IRQS, =20 __NETDEV_A_NAPI_MAX, NETDEV_A_NAPI_MAX =3D (__NETDEV_A_NAPI_MAX - 1) diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c index 05f9515d2c05..79b14ad6f4bb 100644 --- a/net/core/netdev-genl.c +++ b/net/core/netdev-genl.c @@ -160,6 +160,7 @@ static int netdev_nl_napi_fill_one(struct sk_buff *rsp, struct napi_struct *napi, const struct genl_info *info) { + int napi_defer_hard_irqs; void *hdr; pid_t pid; =20 @@ -188,6 +189,10 @@ netdev_nl_napi_fill_one(struct sk_buff *rsp, struct na= pi_struct *napi, goto nla_put_failure; } =20 + napi_defer_hard_irqs =3D napi_get_defer_hard_irqs(napi); + if (nla_put_s32(rsp, NETDEV_A_NAPI_DEFER_HARD_IRQS, napi_defer_hard_irqs)) + goto nla_put_failure; + genlmsg_end(rsp, hdr); =20 return 0; diff --git a/tools/include/uapi/linux/netdev.h b/tools/include/uapi/linux/n= etdev.h index 43742ac5b00d..43bb1aad9611 100644 --- a/tools/include/uapi/linux/netdev.h +++ b/tools/include/uapi/linux/netdev.h @@ -121,6 +121,7 @@ enum { NETDEV_A_NAPI_ID, NETDEV_A_NAPI_IRQ, NETDEV_A_NAPI_PID, + NETDEV_A_NAPI_DEFER_HARD_IRQS, =20 __NETDEV_A_NAPI_MAX, NETDEV_A_NAPI_MAX =3D (__NETDEV_A_NAPI_MAX - 1) --=20 2.25.1 From nobody Sun Feb 8 00:03:47 2026 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (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 1B9961AE056 for ; Thu, 29 Aug 2024 13:13:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724937192; cv=none; b=A5tq5bW87q1dTitB3opkLREoX+JWlMl2gNgKq84mfcxUNsinp/MqcMikMYcISG5MJ/5u7cFQog5d418mMQsiSVNdfktXMd/GJC4Nxc73vU1PjveZzxkJS3KNNMvZ8/HsfZJBjKeGpNCdQLbbNYUSMP+EiiFMqqIrEvmjWdFMX4E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724937192; c=relaxed/simple; bh=NfMMj+y0jjd3+zEO9SA39G8wNB8TIgOiJ9flYi/rUVs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=p82mF86wQH5HnaU0A16pIhsj38tOweHfj0Y3vm2abOJulWF/SfAnveOfDJ5dqsLPIbazyRGyU35EKT+gnPZNny75bAZEvjQ5TSEZzwh+cVMUfLW68lGT8FhyVEV6Oy4B2+g2IAai8qjlnhIEEb/2wkuRRQMW7qMgNdqmvcWqqRQ= 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=JYvjlZBh; arc=none smtp.client-ip=209.85.214.179 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="JYvjlZBh" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-20219a0fe4dso5057125ad.2 for ; Thu, 29 Aug 2024 06:13:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1724937190; x=1725541990; 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=J76VgAVWfMg9eT/1kj4172Eex7vGiEhRt/GH9utayOA=; b=JYvjlZBhSxGqvyqWdJiXYfT3gjK9poCuMaItgyU3cUnWxaCi6KnEIYvM7QH5U4Z5Re 2DBbCqJQwOBP6fguAwhR/OADKpyEi+QB/Ru43uyaSLE7x234IO1wqO9YLdVjLmTU1N9P 5Pi4lxgVjuyzJIqVS90aMs4ZIey9nt8+Ikt4o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724937190; x=1725541990; 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=J76VgAVWfMg9eT/1kj4172Eex7vGiEhRt/GH9utayOA=; b=G67Spp2N16IN2ivzrfCcWqAZoV63ZiHQdNpVXeTx5hNL+26iztRT/6LCR4LF1KBSFm EMh+d7jycc5rU8Wzg+VN+ruY3CsBgvs5QZWp2mLnc8hyP3VnJSMI9i4NOTFzTk/UShzW QgM+5oMJcqJNPbTruL/DlzgXKntGRgACHjbC4MbFn/A3cJD9I6+ezexwcKzs77VFxzQ6 bz71diBlRFcz4aKELTAygaqZh7vGSKaBrkArHAoUfdnhvhIEvbuloZgT8ljtnp4hSbst rJWv8c2Q7sL3YB0OqvsFWNFwZLdvHoi/rBsGQIZ1qWDcaW6HAPMO7Z+ynOWhWy2kYi5N ViZA== X-Forwarded-Encrypted: i=1; AJvYcCWNVxppVnqAUa+XdQBmPAfJGFAbx9vGr0X9JGgn6OT7Wp86xTO3aKIbkLlzMDKtcnSJwDvkSa3/NQr6nMo=@vger.kernel.org X-Gm-Message-State: AOJu0Yy0UU7onypT2vQf+7w48c0ENdx+JZDu5dlYp37r6U5LySLDx9+w HuvIhHMe8q0MrNlp4xr6Us/ytYBcuNrb4ZZnSx1E3nEqrdThMdTnPNz2A4cW2r8= X-Google-Smtp-Source: AGHT+IGRrAws7CHX7jP1QU0EU6Idn1nTO6GPORRmwPdsv5pW4OpP6YLYsyLZx6bewfvVf8tm7K2EKQ== X-Received: by 2002:a17:902:ec88:b0:202:883:bd6 with SMTP id d9443c01a7336-2050c4c8a3fmr36374235ad.63.1724937189882; Thu, 29 Aug 2024 06:13:09 -0700 (PDT) Received: from localhost.localdomain ([2620:11a:c019:0:65e:3115:2f58:c5fd]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-205152b13c9sm10991065ad.62.2024.08.29.06.13.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2024 06:13:09 -0700 (PDT) From: Joe Damato To: netdev@vger.kernel.org Cc: edumazet@google.com, amritha.nambiar@intel.com, sridhar.samudrala@intel.com, sdf@fomichev.me, bjorn@rivosinc.com, hch@infradead.org, willy@infradead.org, willemdebruijn.kernel@gmail.com, skhawaja@google.com, kuba@kernel.org, Joe Damato , Martin Karsten , "David S. Miller" , Paolo Abeni , Jiri Pirko , Sebastian Andrzej Siewior , Lorenzo Bianconi , Breno Leitao , Johannes Berg , Alexander Lobakin , Heiner Kallweit , linux-kernel@vger.kernel.org (open list) Subject: [PATCH net-next 3/5] net: napi: Make gro_flush_timeout per-NAPI Date: Thu, 29 Aug 2024 13:11:59 +0000 Message-Id: <20240829131214.169977-4-jdamato@fastly.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240829131214.169977-1-jdamato@fastly.com> References: <20240829131214.169977-1-jdamato@fastly.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Allow per-NAPI gro_flush_timeout setting. The existing sysfs parameter is respected; writes to sysfs will write to all NAPI structs for the device and the net_device gro_flush_timeout field. Reads from sysfs will read from the net_device field. The ability to set gro_flush_timeout on specific NAPI instances will be added in a later commit, via netdev-genl. Signed-off-by: Joe Damato Reviewed-by: Martin Karsten Tested-by: Martin Karsten --- include/linux/netdevice.h | 26 ++++++++++++++++++++++++++ net/core/dev.c | 32 ++++++++++++++++++++++++++++---- net/core/net-sysfs.c | 2 +- 3 files changed, 55 insertions(+), 5 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 7d53380da4c0..d00024d9f857 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -372,6 +372,7 @@ struct napi_struct { int rx_count; /* length of rx_list */ unsigned int napi_id; int defer_hard_irqs; + unsigned long gro_flush_timeout; struct hrtimer timer; struct task_struct *thread; /* control-path-only fields follow */ @@ -557,6 +558,31 @@ void napi_set_defer_hard_irqs(struct napi_struct *n, i= nt defer); */ void netdev_set_defer_hard_irqs(struct net_device *netdev, int defer); =20 +/** + * napi_get_gro_flush_timeout - get the gro_flush_timeout + * @n: napi struct to get the gro_flush_timeout from + * + * Returns the per-NAPI value of the gro_flush_timeout field. + */ +unsigned long napi_get_gro_flush_timeout(const struct napi_struct *n); + +/** + * napi_set_gro_flush_timeout - set the gro_flush_timeout for a napi + * @n: napi struct to set the gro_flush_timeout + * @timeout: timeout value to set + * + * napi_set_gro_flush_timeout sets the per-NAPI gro_flush_timeout + */ +void napi_set_gro_flush_timeout(struct napi_struct *n, unsigned long timeo= ut); + +/** + * netdev_set_gro_flush_timeout - set gro_flush_timeout for all NAPIs of a= netdev + * @netdev: the net_device for which all NAPIs will have their gro_flush_t= imeout set + * @timeout: the timeout value to set + */ +void netdev_set_gro_flush_timeout(struct net_device *netdev, + unsigned long timeout); + /** * napi_complete_done - NAPI processing complete * @n: NAPI context diff --git a/net/core/dev.c b/net/core/dev.c index f7baff0da057..3f7cb1085efa 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -6234,6 +6234,29 @@ void netdev_set_defer_hard_irqs(struct net_device *n= etdev, int defer) } EXPORT_SYMBOL_GPL(netdev_set_defer_hard_irqs); =20 +unsigned long napi_get_gro_flush_timeout(const struct napi_struct *n) +{ + return READ_ONCE(n->gro_flush_timeout); +} +EXPORT_SYMBOL_GPL(napi_get_gro_flush_timeout); + +void napi_set_gro_flush_timeout(struct napi_struct *n, unsigned long timeo= ut) +{ + WRITE_ONCE(n->gro_flush_timeout, timeout); +} +EXPORT_SYMBOL_GPL(napi_set_gro_flush_timeout); + +void netdev_set_gro_flush_timeout(struct net_device *netdev, + unsigned long timeout) +{ + struct napi_struct *napi; + + WRITE_ONCE(netdev->gro_flush_timeout, timeout); + list_for_each_entry(napi, &netdev->napi_list, dev_list) + napi_set_gro_flush_timeout(napi, timeout); +} +EXPORT_SYMBOL_GPL(netdev_set_gro_flush_timeout); + bool napi_complete_done(struct napi_struct *n, int work_done) { unsigned long flags, val, new, timeout =3D 0; @@ -6251,12 +6274,12 @@ bool napi_complete_done(struct napi_struct *n, int = work_done) =20 if (work_done) { if (n->gro_bitmask) - timeout =3D READ_ONCE(n->dev->gro_flush_timeout); + timeout =3D napi_get_gro_flush_timeout(n); n->defer_hard_irqs_count =3D napi_get_defer_hard_irqs(n); } if (n->defer_hard_irqs_count > 0) { n->defer_hard_irqs_count--; - timeout =3D READ_ONCE(n->dev->gro_flush_timeout); + timeout =3D napi_get_gro_flush_timeout(n); if (timeout) ret =3D false; } @@ -6391,7 +6414,7 @@ static void busy_poll_stop(struct napi_struct *napi, = void *have_poll_lock, =20 if (flags & NAPI_F_PREFER_BUSY_POLL) { napi->defer_hard_irqs_count =3D napi_get_defer_hard_irqs(napi); - timeout =3D READ_ONCE(napi->dev->gro_flush_timeout); + timeout =3D napi_get_gro_flush_timeout(napi); if (napi->defer_hard_irqs_count && timeout) { hrtimer_start(&napi->timer, ns_to_ktime(timeout), HRTIMER_MODE_REL_PINN= ED); skip_schedule =3D true; @@ -6673,6 +6696,7 @@ void netif_napi_add_weight(struct net_device *dev, st= ruct napi_struct *napi, hrtimer_init(&napi->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_PINNED); napi->timer.function =3D napi_watchdog; napi_set_defer_hard_irqs(napi, READ_ONCE(dev->napi_defer_hard_irqs)); + napi_set_gro_flush_timeout(napi, READ_ONCE(dev->gro_flush_timeout)); init_gro_hash(napi); napi->skb =3D NULL; INIT_LIST_HEAD(&napi->rx_list); @@ -11054,7 +11078,7 @@ void netdev_sw_irq_coalesce_default_on(struct net_d= evice *dev) WARN_ON(dev->reg_state =3D=3D NETREG_REGISTERED); =20 if (!IS_ENABLED(CONFIG_PREEMPT_RT)) { - dev->gro_flush_timeout =3D 20000; + netdev_set_gro_flush_timeout(dev, 20000); netdev_set_defer_hard_irqs(dev, 1); } } diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index 8272f0144d81..ff545a422b1f 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -408,7 +408,7 @@ NETDEVICE_SHOW_RW(tx_queue_len, fmt_dec); =20 static int change_gro_flush_timeout(struct net_device *dev, unsigned long = val) { - WRITE_ONCE(dev->gro_flush_timeout, val); + netdev_set_gro_flush_timeout(dev, val); return 0; } =20 --=20 2.25.1 From nobody Sun Feb 8 00:03:47 2026 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 1E6CB1ABECB for ; Thu, 29 Aug 2024 13:13:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724937198; cv=none; b=uDTx95RlYszxWawOs8ozl5kFEKXf04nNBrO5c++ehWre9LI7IXnJwRdH51V/ntJE9CjT5hzTJP2rf1nQRZwvJtoZTw9AAzjPFnLjsPm5UCUA0pCJOVTt0dRSr3D/qE/6/a6BqLXO6tp+pcqrRudN3QLjzOmRVxtP9Fy86SXpFi4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724937198; c=relaxed/simple; bh=LY6teNijKykhT8LcLXhvWcqr0xTJvW1UGMeUYMcjQ5s=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NWYRh/YMJA9aMO8Jsuvnia5gXAIV5BBos7ZTm/wMeHLk8iZOBwJ7xT7YqjPxjk4/qM+Z0OCkqjIJUTBVe4Lyzqq12G+SXj7Mq0/yTiLb7IVWh9v+tfUJYRjTQAYf/ArESpeqH6xkqe6mEcrePTvWXDOCUIt20lUhBLeQAHkV7tg= 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=wlLeaS9M; arc=none smtp.client-ip=209.85.214.171 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="wlLeaS9M" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-201d5af11a4so5486945ad.3 for ; Thu, 29 Aug 2024 06:13:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1724937196; x=1725541996; 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=xgl23lpxXcxLJcPC+/6yHZPVWll0h2Oag84ZBhf9v4w=; b=wlLeaS9Mzv3fVUmTrC0babPDTSzUzrz+xiybCXNIXNgBuU0n2b5bpu+AAhB5aH1KvA V73HjzUmv9D1QXpjhDaRDsluiFYbbzBRuKLQ9/7H0g1/QLln18niPvvOddZh3FcsavUD 1WUdYUx9xNUCmy+yKS2FiCi+OjHy3qWa8xT9s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724937196; x=1725541996; 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=xgl23lpxXcxLJcPC+/6yHZPVWll0h2Oag84ZBhf9v4w=; b=hrKwtVFEoohC0fat4hW8FHAncU25MK8Ad0sWyxDAV2TWvWp/EJJlQDxaKfd1nFuSQC WsNzVLoCIyDy67NFyguMllAm/H76hIc1mRAwtNgPJcCN0uNqs4s9kMJmAglM8yoZV0Er MoF2mHXqmhNaUBqdrU3aMIG9W4BP3ppbow/ZBsaYwokWSyyxbsyDPE/N8NqL9HKNzSGJ zK5Q7nbXBshSLRoIsy8lG/KV3BL/7B9ngSfrrGMRpd55FN8QH2l/9N3tE9Erz7Y9gc6R 4m5msxaYiRhTuGDaRL+j7fVptfb4Bp/RQcyharqxEMH0EhE/vtqiHv7g86dmMl6RpLvy 4PVA== X-Forwarded-Encrypted: i=1; AJvYcCULxxyC7ff91E2buLfeqV73mSjVuD9E0XTYTccS/BS619dEOTBOujgUoevQrgkQYG5Zsnfx+W/Onbo75SM=@vger.kernel.org X-Gm-Message-State: AOJu0YzlPnGCVeMD6ywQQqCEEA9tO627zwFOc+8q+LnqPWrGoV1lHIkx uXfvfNN3xLEU0laUErFMkX/bl3LelfxJMe6Og/CkNTeVXVr4uGks/0cdVkJM+JY= X-Google-Smtp-Source: AGHT+IEai9uG2TpaQ3GILW0DtKC65AC9xQAh8DUHKEnc/3a9ZsdmyX3Zn9R455FKvzhgMm7/6Ry8RQ== X-Received: by 2002:a17:902:e851:b0:202:3dcf:8c38 with SMTP id d9443c01a7336-2050c453f85mr29456225ad.44.1724937194835; Thu, 29 Aug 2024 06:13:14 -0700 (PDT) Received: from localhost.localdomain ([2620:11a:c019:0:65e:3115:2f58:c5fd]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-205152b13c9sm10991065ad.62.2024.08.29.06.13.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2024 06:13:13 -0700 (PDT) From: Joe Damato To: netdev@vger.kernel.org Cc: edumazet@google.com, amritha.nambiar@intel.com, sridhar.samudrala@intel.com, sdf@fomichev.me, bjorn@rivosinc.com, hch@infradead.org, willy@infradead.org, willemdebruijn.kernel@gmail.com, skhawaja@google.com, kuba@kernel.org, Joe Damato , Martin Karsten , Donald Hunter , "David S. Miller" , Paolo Abeni , Jesper Dangaard Brouer , Xuan Zhuo , Larysa Zaremba , linux-kernel@vger.kernel.org (open list) Subject: [PATCH net-next 4/5] netdev-genl: Dump gro_flush_timeout Date: Thu, 29 Aug 2024 13:12:00 +0000 Message-Id: <20240829131214.169977-5-jdamato@fastly.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240829131214.169977-1-jdamato@fastly.com> References: <20240829131214.169977-1-jdamato@fastly.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Support dumping gro_flush_timeout for a NAPI ID. Signed-off-by: Joe Damato Reviewed-by: Martin Karsten Tested-by: Martin Karsten --- Documentation/netlink/specs/netdev.yaml | 6 ++++++ include/uapi/linux/netdev.h | 1 + net/core/netdev-genl.c | 6 ++++++ tools/include/uapi/linux/netdev.h | 1 + 4 files changed, 14 insertions(+) diff --git a/Documentation/netlink/specs/netdev.yaml b/Documentation/netlin= k/specs/netdev.yaml index ee4f99fd4574..290894962ac4 100644 --- a/Documentation/netlink/specs/netdev.yaml +++ b/Documentation/netlink/specs/netdev.yaml @@ -249,6 +249,11 @@ attribute-sets: doc: The number of consecutive empty polls before IRQ deferral ends and hardware IRQs are re-enabled. type: s32 + - + name: gro-flush-timeout + doc: The timeout, in nanoseconds, of when to trigger the NAPI + watchdog timer and schedule NAPI processing. + type: u64 - name: queue attributes: @@ -599,6 +604,7 @@ operations: - irq - pid - defer-hard-irqs + - gro-flush-timeout dump: request: attributes: diff --git a/include/uapi/linux/netdev.h b/include/uapi/linux/netdev.h index 43bb1aad9611..b088a34e9254 100644 --- a/include/uapi/linux/netdev.h +++ b/include/uapi/linux/netdev.h @@ -122,6 +122,7 @@ enum { NETDEV_A_NAPI_IRQ, NETDEV_A_NAPI_PID, NETDEV_A_NAPI_DEFER_HARD_IRQS, + NETDEV_A_NAPI_GRO_FLUSH_TIMEOUT, =20 __NETDEV_A_NAPI_MAX, NETDEV_A_NAPI_MAX =3D (__NETDEV_A_NAPI_MAX - 1) diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c index 79b14ad6f4bb..2eee95d05fe0 100644 --- a/net/core/netdev-genl.c +++ b/net/core/netdev-genl.c @@ -161,6 +161,7 @@ netdev_nl_napi_fill_one(struct sk_buff *rsp, struct nap= i_struct *napi, const struct genl_info *info) { int napi_defer_hard_irqs; + unsigned long gro_flush_timeout; void *hdr; pid_t pid; =20 @@ -193,6 +194,11 @@ netdev_nl_napi_fill_one(struct sk_buff *rsp, struct na= pi_struct *napi, if (nla_put_s32(rsp, NETDEV_A_NAPI_DEFER_HARD_IRQS, napi_defer_hard_irqs)) goto nla_put_failure; =20 + gro_flush_timeout =3D napi_get_gro_flush_timeout(napi); + if (nla_put_u64_64bit(rsp, NETDEV_A_NAPI_GRO_FLUSH_TIMEOUT, + gro_flush_timeout, NETDEV_A_DEV_PAD)) + goto nla_put_failure; + genlmsg_end(rsp, hdr); =20 return 0; diff --git a/tools/include/uapi/linux/netdev.h b/tools/include/uapi/linux/n= etdev.h index 43bb1aad9611..b088a34e9254 100644 --- a/tools/include/uapi/linux/netdev.h +++ b/tools/include/uapi/linux/netdev.h @@ -122,6 +122,7 @@ enum { NETDEV_A_NAPI_IRQ, NETDEV_A_NAPI_PID, NETDEV_A_NAPI_DEFER_HARD_IRQS, + NETDEV_A_NAPI_GRO_FLUSH_TIMEOUT, =20 __NETDEV_A_NAPI_MAX, NETDEV_A_NAPI_MAX =3D (__NETDEV_A_NAPI_MAX - 1) --=20 2.25.1 From nobody Sun Feb 8 00:03:47 2026 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.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 217791A7062 for ; Thu, 29 Aug 2024 13:13:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724937203; cv=none; b=tIiiooS6S+d8ci/MViT1azKprxnCwClY5749DiMnxsDzQc3FOis62uoLcRd/tEE5m8jbyeQ/TkaHzQxwZrtG3BzN/awBiW7md9TwNdKX7IVIf6mtw27ndIpN1WS2H/zvYdhdZkuBm67coZA3HItXZITGkbhmTnD2UbEwDFZ+NG4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724937203; c=relaxed/simple; bh=0L8vN7Z5mU6GUGAu+SGn6arcn3NkZa7mF5sCgHhz5AY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gAyo3jxN3OnVEVi3ee97zmBjCYqrVt1M21anGEEW0XBxVGLFVDX+p3vb4PHcqAJm+oaAyeD9BUTVA4XSPNGn8PrI8ksXCrBXpDdWOZkNj6xsxoiIfBS/fpLXT4zgozaneKWZGDUc79Pou3AFzGstku4IFJGBCnuT5zFAP/cPl1k= 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=c6VyC+39; arc=none smtp.client-ip=209.85.214.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="c6VyC+39" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-20230059241so5505705ad.3 for ; Thu, 29 Aug 2024 06:13:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1724937201; x=1725542001; 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=PCqHkNfsdp0hrimdEM7KiFJuq1/lUKdseFAqTrtspZc=; b=c6VyC+39I54k2m6MfY9zsHt77g5pFuvX6ctu7ZkaEO66Hwds/OiS3JiKRmFVUePTeO lO0cAB2AKNmJI9HbtLZRl5VBW9QZwZmyy063EMQbH39PN4T2Q8uZeGXd8zodaSzTwWR4 zDk6RXYqfZLOrbFQvMFA4jw83DZsSIfi6WeHU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724937201; x=1725542001; 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=PCqHkNfsdp0hrimdEM7KiFJuq1/lUKdseFAqTrtspZc=; b=AXxLRlGBib87sQoMMUImB3nxN+zDdBD90WKyHhd2fw/WI3X8Vocl0OtEbV+XrzQdJ1 Va94dqMZ0L5RYsmnHQfoZGPdSl2vGr+AW+ktuL5Y3B6lxtJ6r8uW8o1uHbwtEjpOACmC DxcKUgH7BlfnX2AOiApRHy6iM9i2CwizI5oyfRG9G7qzv8HijA3prTO2JgtDIgWME6Pq G7OkFVNkPSLIi2ZDGjK9HuXfoQDBTiEoBd7JXqKVHn8UCYrYKldQBNRHEBRh+WvI57Pe H2t8cozWKUmpwVgxYbsC9dVnsBMcHW62quKo0guQC4d/py3/HxJd3GRzJyx5n4sOzleH b4sA== X-Forwarded-Encrypted: i=1; AJvYcCWdVYZzpJp6uSsUbNx0zLNz2kx8xB7uFfL8qDW0HpOcqSF63Ggv0/POO6Lu1BflSeHB5O0JeAp4wnvIraU=@vger.kernel.org X-Gm-Message-State: AOJu0Yz+Mhu0oL9HIpznzQpK2R94XCViqW43eVZi7ZwhnbedRuWZ4YVi amxT85rndTr9OJW2XO7wl+zK2P0UJKo/VqmdKsHoVW3qYbGbFDy2tpWVUe2+qZs= X-Google-Smtp-Source: AGHT+IFAQmZRTQuLJSgAof5JbEL5kQEBY3Ia8dWCEJbF82Axvc0yD6suQQ96GHf2y+oqmB4/3JkcbA== X-Received: by 2002:a17:902:dacf:b0:202:859:f85 with SMTP id d9443c01a7336-2050c3d6af6mr31252725ad.24.1724937201013; Thu, 29 Aug 2024 06:13:21 -0700 (PDT) Received: from localhost.localdomain ([2620:11a:c019:0:65e:3115:2f58:c5fd]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-205152b13c9sm10991065ad.62.2024.08.29.06.13.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2024 06:13:20 -0700 (PDT) From: Joe Damato To: netdev@vger.kernel.org Cc: edumazet@google.com, amritha.nambiar@intel.com, sridhar.samudrala@intel.com, sdf@fomichev.me, bjorn@rivosinc.com, hch@infradead.org, willy@infradead.org, willemdebruijn.kernel@gmail.com, skhawaja@google.com, kuba@kernel.org, Joe Damato , Martin Karsten , Donald Hunter , "David S. Miller" , Paolo Abeni , Jesper Dangaard Brouer , Xuan Zhuo , Daniel Jurgens , linux-kernel@vger.kernel.org (open list) Subject: [PATCH net-next 5/5] netdev-genl: Support setting per-NAPI config values Date: Thu, 29 Aug 2024 13:12:01 +0000 Message-Id: <20240829131214.169977-6-jdamato@fastly.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240829131214.169977-1-jdamato@fastly.com> References: <20240829131214.169977-1-jdamato@fastly.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add support to set per-NAPI defer_hard_irqs and gro_flush_timeout. Signed-off-by: Joe Damato Reviewed-by: Martin Karsten Tested-by: Martin Karsten --- Documentation/netlink/specs/netdev.yaml | 11 ++++++ include/uapi/linux/netdev.h | 1 + net/core/netdev-genl-gen.c | 14 ++++++++ net/core/netdev-genl-gen.h | 1 + net/core/netdev-genl.c | 45 +++++++++++++++++++++++++ tools/include/uapi/linux/netdev.h | 1 + 6 files changed, 73 insertions(+) diff --git a/Documentation/netlink/specs/netdev.yaml b/Documentation/netlin= k/specs/netdev.yaml index 290894962ac4..cb7049a1d6d8 100644 --- a/Documentation/netlink/specs/netdev.yaml +++ b/Documentation/netlink/specs/netdev.yaml @@ -631,6 +631,17 @@ operations: - rx-bytes - tx-packets - tx-bytes + - + name: napi-set + doc: Set configurable NAPI instance settings. + attribute-set: napi + flags: [ admin-perm ] + do: + request: + attributes: + - id + - defer-hard-irqs + - gro-flush-timeout =20 mcast-groups: list: diff --git a/include/uapi/linux/netdev.h b/include/uapi/linux/netdev.h index b088a34e9254..4c5bfbc85504 100644 --- a/include/uapi/linux/netdev.h +++ b/include/uapi/linux/netdev.h @@ -188,6 +188,7 @@ enum { NETDEV_CMD_QUEUE_GET, NETDEV_CMD_NAPI_GET, NETDEV_CMD_QSTATS_GET, + NETDEV_CMD_NAPI_SET, =20 __NETDEV_CMD_MAX, NETDEV_CMD_MAX =3D (__NETDEV_CMD_MAX - 1) diff --git a/net/core/netdev-genl-gen.c b/net/core/netdev-genl-gen.c index 8350a0afa9ec..5ddb5d926850 100644 --- a/net/core/netdev-genl-gen.c +++ b/net/core/netdev-genl-gen.c @@ -74,6 +74,13 @@ static const struct nla_policy netdev_qstats_get_nl_poli= cy[NETDEV_A_QSTATS_SCOPE [NETDEV_A_QSTATS_SCOPE] =3D NLA_POLICY_MASK(NLA_UINT, 0x1), }; =20 +/* NETDEV_CMD_NAPI_SET - set */ +static const struct nla_policy netdev_napi_set_nl_policy[NETDEV_A_NAPI_GRO= _FLUSH_TIMEOUT + 1] =3D { + [NETDEV_A_NAPI_ID] =3D { .type =3D NLA_U32, }, + [NETDEV_A_NAPI_DEFER_HARD_IRQS] =3D { .type =3D NLA_S32 }, + [NETDEV_A_NAPI_GRO_FLUSH_TIMEOUT] =3D { .type =3D NLA_U64 }, +}; + /* Ops table for netdev */ static const struct genl_split_ops netdev_nl_ops[] =3D { { @@ -151,6 +158,13 @@ static const struct genl_split_ops netdev_nl_ops[] =3D= { .maxattr =3D NETDEV_A_QSTATS_SCOPE, .flags =3D GENL_CMD_CAP_DUMP, }, + { + .cmd =3D NETDEV_CMD_NAPI_SET, + .doit =3D netdev_nl_napi_set_doit, + .policy =3D netdev_napi_set_nl_policy, + .maxattr =3D NETDEV_A_NAPI_GRO_FLUSH_TIMEOUT, + .flags =3D GENL_ADMIN_PERM | GENL_CMD_CAP_DO, + }, }; =20 static const struct genl_multicast_group netdev_nl_mcgrps[] =3D { diff --git a/net/core/netdev-genl-gen.h b/net/core/netdev-genl-gen.h index 4db40fd5b4a9..b70cb0f20acb 100644 --- a/net/core/netdev-genl-gen.h +++ b/net/core/netdev-genl-gen.h @@ -28,6 +28,7 @@ int netdev_nl_queue_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb); int netdev_nl_napi_get_doit(struct sk_buff *skb, struct genl_info *info); int netdev_nl_napi_get_dumpit(struct sk_buff *skb, struct netlink_callback= *cb); +int netdev_nl_napi_set_doit(struct sk_buff *skb, struct genl_info *info); int netdev_nl_qstats_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb); =20 diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c index 2eee95d05fe0..43dd30eadbc6 100644 --- a/net/core/netdev-genl.c +++ b/net/core/netdev-genl.c @@ -299,6 +299,51 @@ int netdev_nl_napi_get_dumpit(struct sk_buff *skb, str= uct netlink_callback *cb) return err; } =20 +static int +netdev_nl_napi_set_config(struct napi_struct *napi, struct genl_info *info) +{ + u64 gro_flush_timeout =3D 0; + int defer =3D 0; + + if (info->attrs[NETDEV_A_NAPI_DEFER_HARD_IRQS]) { + defer =3D nla_get_s32(info->attrs[NETDEV_A_NAPI_DEFER_HARD_IRQS]); + if (defer < 0) + return -EINVAL; + napi_set_defer_hard_irqs(napi, defer); + } + + if (info->attrs[NETDEV_A_NAPI_GRO_FLUSH_TIMEOUT]) { + gro_flush_timeout =3D nla_get_u64(info->attrs[NETDEV_A_NAPI_GRO_FLUSH_TI= MEOUT]); + napi_set_gro_flush_timeout(napi, gro_flush_timeout); + } + + return 0; +} + +int netdev_nl_napi_set_doit(struct sk_buff *skb, struct genl_info *info) +{ + struct napi_struct *napi; + u32 napi_id; + int err; + + if (GENL_REQ_ATTR_CHECK(info, NETDEV_A_NAPI_ID)) + return -EINVAL; + + napi_id =3D nla_get_u32(info->attrs[NETDEV_A_NAPI_ID]); + + rtnl_lock(); + + napi =3D napi_by_id(napi_id); + if (napi) + err =3D netdev_nl_napi_set_config(napi, info); + else + err =3D -EINVAL; + + rtnl_unlock(); + + return err; +} + static int netdev_nl_queue_fill_one(struct sk_buff *rsp, struct net_device *netdev, u32 q_idx, u32 q_type, const struct genl_info *info) diff --git a/tools/include/uapi/linux/netdev.h b/tools/include/uapi/linux/n= etdev.h index b088a34e9254..4c5bfbc85504 100644 --- a/tools/include/uapi/linux/netdev.h +++ b/tools/include/uapi/linux/netdev.h @@ -188,6 +188,7 @@ enum { NETDEV_CMD_QUEUE_GET, NETDEV_CMD_NAPI_GET, NETDEV_CMD_QSTATS_GET, + NETDEV_CMD_NAPI_SET, =20 __NETDEV_CMD_MAX, NETDEV_CMD_MAX =3D (__NETDEV_CMD_MAX - 1) --=20 2.25.1