From patchwork Thu Aug 29 13:11:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Damato X-Patchwork-Id: 13783194 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) (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 E60EA1ABEAD for ; Thu, 29 Aug 2024 13:13:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724937184; cv=none; b=EhA11LT9eifmVahF1q6tiIoUlCLy+jy0Fh8h5+xfbYse2ih6CwxZePApLK6w2cIMQkIsa4cJvX70q0/7GjSuRGTMhRqRkSbFgmCmGZYJdz/wppB8YJVw+yeC6VLlHsvVGe0jEVxfzz5zgrFvhm69Hy9rF0zDrc9g+xKV6m7cjMo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724937184; c=relaxed/simple; bh=TY/JWmRiSZtiMQ0TAf+u6i4UVWxaSuovZzLy2w5lMjc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NMkXiEmVfxSFFdagLKueMRlaiCpRfsfiTDLym1tQO6imYA173pEvuFRMEdJNu8fISb5Y3BKpbY6P5lqzwfiIr+8iNZ6VKezQdcIVo1R+ekFQjWcCGDuRlgvhbjVWLKLe5RuppLdwH6LNzcVmr16FcjW5UUh4DhwA8d8+kggoBtM= 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=HK1gu2c9; arc=none smtp.client-ip=209.85.216.46 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="HK1gu2c9" Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-2d3d662631aso463142a91.1 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=1724937182; x=1725541982; 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=HK1gu2c9WoqwINdl5YK7paDHWnYm6bEGSpAb2vOEglwhfDLdEZ5oDzuV9B2pIP+4i6 5XmQPUw2kFWisoy8cMqfPZfov6bc8VNwCv/Fa1xMrDNvAU8xbPWDXNX7GivYa9PwZzw6 nRVaZdArI0+C3sRa2dSNkrvRMJhKVVrvcIeDo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724937182; x=1725541982; 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=EqLTwfzdruL9mXZwF7T5m6cxVn/Xlhlyd2vth3TA1GMkL+S9it7G1aLgDm/t2j7agR /mRjvXOTVP9BpDsUko7TIJxCcDmv9tQGtgl76YwqRIOU3WtUMZPmlzJQK/Vo4sXKcwAJ egFyHPiUZubZLyQdlbTct7dPW7VO/zhBvHRDfEV/H9oKDcp69M5dxZd3r6rD/ZJrGb0R MjV6nBQc+05NquQ89TB2gbNKyp+VPiAMY20p3NW+88Ms7mFccRuj1FJkAmfkoAPxwUlx YN4wLuzgpcj/Nyp673vMrxz0OR7izb4rggGsGw1IMxd7TfFZCWQhSUnY1zG9JzFsbnYq 0skQ== X-Gm-Message-State: AOJu0Yyd73PSb8G0qTOrBxrkq8KsYKkb+q0PRNzSytzImOgaUE6t7hS9 4GupaLaZJFt9tm3gKMuA4I5PnTAHnziWa019vh71+t58AzyRTnsvvfkAGDvElhBMCdNV7h2yyhC U1Cn2rH1V0JM6poLmUYQ/iiYKFdoJo88vkHyiLeoGQ/lDuxyJxM7IfFqjyxtlGm5E//Ir5Sv3x2 A+ptCuJ9+jWyJy2NYpWEjHyIZ4BtFVCMK9JclcGw== 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: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org 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_struct *n) __napi_schedule_irqoff(n); } +/** + * 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 netdev + * @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); +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 = 0; @@ -6230,7 +6252,7 @@ bool napi_complete_done(struct napi_struct *n, int work_done) if (work_done) { if (n->gro_bitmask) timeout = READ_ONCE(n->dev->gro_flush_timeout); - n->defer_hard_irqs_count = READ_ONCE(n->dev->napi_defer_hard_irqs); + n->defer_hard_irqs_count = 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 = 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); + napi->defer_hard_irqs_count = napi_get_defer_hard_irqs(napi); timeout = 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_PINNED); @@ -6650,6 +6672,7 @@ void netif_napi_add_weight(struct net_device *dev, struct napi_struct *napi, INIT_HLIST_NODE(&napi->napi_hash_node); hrtimer_init(&napi->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_PINNED); napi->timer.function = napi_watchdog; + napi_set_defer_hard_irqs(napi, READ_ONCE(dev->napi_defer_hard_irqs)); init_gro_hash(napi); napi->skb = NULL; INIT_LIST_HEAD(&napi->rx_list); @@ -11032,7 +11055,7 @@ void netdev_sw_irq_coalesce_default_on(struct net_device *dev) if (!IS_ENABLED(CONFIG_PREEMPT_RT)) { dev->gro_flush_timeout = 20000; - dev->napi_defer_hard_irqs = 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); static int change_napi_defer_hard_irqs(struct net_device *dev, unsigned long 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; } From patchwork Thu Aug 29 13:11:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Damato X-Patchwork-Id: 13783199 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (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 CF8D41AD413 for ; Thu, 29 Aug 2024 13:13:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724937188; cv=none; b=p2Arzq2bICrhs8Y8z/DJpMevBPK+ky9JbERn0x8RiZZGCEIMhhcsHRyk+hwSIQq/Im3MuKOMQu0he4NykvJXI4GbqEVcTSxkS/ysUKL3HQvnauL7bmDx+TY23RbBhySfdc0fuHxaDG9Rs87hJpm3hBVWB86KzpP/jlKZoqaGGCY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724937188; c=relaxed/simple; bh=hI4+39auvENKp36mFZMcEI8Wdw4l29SOp94j/CNObFg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IcWzvpgsVY2d/to4wkoneSqJaF8CwmrvweuhWXzzkd1qWJ9pp7JewyDel+kI40tOX1DuUh20r0A0L8l1Vn5ee6q7IXIUhvdih1vqIksHptHEntmoHmGMkXqu+0ePo09vDpKny1jCQqy4Db5hnG9xO9GxF1se3k/yn+3iiKmpLqU= 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.176 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-f176.google.com with SMTP id d9443c01a7336-2020e83eca1so6711225ad.2 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=Zvm39HeCLMym/0/Gj0LCht9lDS98ccmjJuOloYPhijlvlky4xxyP/SQY/tMoDGpWNx 4JWPpRTO9l4zJa8t9mBP0/YXtyoSe5gCoCd3g9FVf3g+1UQeTfQajIZyOBLoLyiex5UV /zTcy5aLPaL1UWUQfPNe7e9d+DPHFVNVaVg+HNowYGsiH6JbDdoeHXMcIvCDnQifXcnD udl96y2wtAdG/ZqiGqQzh/WaxEB22ug8VYTeUE05+cgIdTZG5TSCCN+GjfyZBIxvjE1F Ykxbk/D5KOIlEush2mvMKulJtlccq4i3NwGvP2CSx6ul0nUHyDr1eQ9zx20yT0Wg/ydk OrZw== X-Gm-Message-State: AOJu0Yz29KLvW5//AHnepFca7W0SlL4qcWG/100A3CgWQBIQViLLI0Zy k0Q9hmt5aZTf15A5UJsg2vQ9QSMyTcYnhja8L3CR49xUFPEvX2YXR8xWqhPcuXggemgvsdxSac6 WLpZZ/RjrY7EyCKsSdtfj2BXeLQAJpIF9jawdFddQ5p2C1s3+urCGwQ/ltmQCfo8YCWN2gVu7Bg OXiS6bIWJZ2azaPbsg/IQKOQBZQ4tlHyDcsE6/+Q== 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: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org 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/netlink/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 normal 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, __NETDEV_A_NAPI_MAX, NETDEV_A_NAPI_MAX = (__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; @@ -188,6 +189,10 @@ netdev_nl_napi_fill_one(struct sk_buff *rsp, struct napi_struct *napi, goto nla_put_failure; } + napi_defer_hard_irqs = 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); return 0; diff --git a/tools/include/uapi/linux/netdev.h b/tools/include/uapi/linux/netdev.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, __NETDEV_A_NAPI_MAX, NETDEV_A_NAPI_MAX = (__NETDEV_A_NAPI_MAX - 1) From patchwork Thu Aug 29 13:11:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Damato X-Patchwork-Id: 13783200 X-Patchwork-Delegate: kuba@kernel.org 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 465B415E5C0 for ; Thu, 29 Aug 2024 13:13:12 +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=1724937193; cv=none; b=hCpSbxOvYLrxdnqmjhFRH7+KYchbooBqE+OZBbDWrXzPVmsrOniuNoSiCFlww+1YzlSvaz22uaP+Tyx6EfGwmoSqyfIdgP7Gntnk+Iga9Q+wGz77E8vvDXFdSH9b0Uk06MbJhMRPdGsWA6bFe+6Os8FLXRqNInLg7ilaKzrh55M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724937193; c=relaxed/simple; bh=NfMMj+y0jjd3+zEO9SA39G8wNB8TIgOiJ9flYi/rUVs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rXnIiFtyTRpfjsyMfWL3+9BDy/OaSdCNgPFcE2gJJwNKywRLCn9cGCdApZ5ed5/+R/UYZO4iFDcN3xWcIeKQHo/JaMAD1v222TM/qePcr7dukIyhmcyExESMbI7uIDCjp/q740rrN3G5DiZWkKFUCEc6+iusfsS9rN4ktJhUQXQ= 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=NAJr87Rq; 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="NAJr87Rq" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-204eebfaebdso5259285ad.1 for ; Thu, 29 Aug 2024 06:13:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1724937191; x=1725541991; 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=NAJr87RqV3r8ed0p2EuJ8pdr44WC5sQ2JWpj3ZezIBRmKOJufZ2BVR1B+wDCZspX8Y 8EwbP6wJx/nnZMHJ0AAI8pH6GJCcjLzcNd/gMAHkUrMx+816BAJMWzgCsN/i+9qACMRo A6gq3j9PnQyc0fFJ+z9er3DlVKXsPBVH/VSxk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724937191; x=1725541991; 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=mJBztIWt7QLWhf7S5oEx6g9ZwayV70LmH1oFcYqsrLfzIv8kWgDEc1SGosxG4oL9Jc E81f/AUwCWSnElnH4+wRpKMFhbmzWre0tIm4oerfe15xMtUItPxFmYBb6AtrLlSbOHYv /RQsnYajgw5nPcwETQaTMfeKff4ca2evfw5frSEjyrJpfbE1OJzTgq4vPcgJYUOQqLmS bQaiINQ0qggvOAa10z/XZD47w/2exdMHnEOHJx2lfR5/GAWn3iy/OApoJL9LuZbUcUe+ ZlEghYEiyRIMz1W+zNN75HOwruvk7Dj0WRAiKMHI4+AzSEB2dJrqDuRokaEO58alD6ym 3EXw== X-Gm-Message-State: AOJu0Yw5okrfeRmp2HgOhPYqAr4Njq99ODaL2v/TeBq6gFn7TAEec9YM 3YpzO4DCPMPK9FHweTdU+yHpsTHgwt/0i/ZhD3FUlssatCVeeesqXH7PnFxqUEDhvZ/F+6UFM3w YuOe9dG62llW4Zom5PNeoizKLjbEIkYcFL6u9Y1QRHaDci3pgu/2QBCPra1E0GVlsRa2ll+Q9dI fJJdbzkL7XczXV8z6s4C2V19jz445+qGmpMWD3sw== 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: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org 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, int defer); */ void netdev_set_defer_hard_irqs(struct net_device *netdev, int defer); +/** + * 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 timeout); + +/** + * 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_timeout 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 *netdev, int defer) } EXPORT_SYMBOL_GPL(netdev_set_defer_hard_irqs); +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 timeout) +{ + 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 = 0; @@ -6251,12 +6274,12 @@ bool napi_complete_done(struct napi_struct *n, int work_done) if (work_done) { if (n->gro_bitmask) - timeout = READ_ONCE(n->dev->gro_flush_timeout); + timeout = napi_get_gro_flush_timeout(n); n->defer_hard_irqs_count = napi_get_defer_hard_irqs(n); } if (n->defer_hard_irqs_count > 0) { n->defer_hard_irqs_count--; - timeout = READ_ONCE(n->dev->gro_flush_timeout); + timeout = napi_get_gro_flush_timeout(n); if (timeout) ret = false; } @@ -6391,7 +6414,7 @@ static void busy_poll_stop(struct napi_struct *napi, void *have_poll_lock, if (flags & NAPI_F_PREFER_BUSY_POLL) { napi->defer_hard_irqs_count = napi_get_defer_hard_irqs(napi); - timeout = READ_ONCE(napi->dev->gro_flush_timeout); + timeout = napi_get_gro_flush_timeout(napi); if (napi->defer_hard_irqs_count && timeout) { hrtimer_start(&napi->timer, ns_to_ktime(timeout), HRTIMER_MODE_REL_PINNED); skip_schedule = true; @@ -6673,6 +6696,7 @@ void netif_napi_add_weight(struct net_device *dev, struct napi_struct *napi, hrtimer_init(&napi->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_PINNED); napi->timer.function = 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 = NULL; INIT_LIST_HEAD(&napi->rx_list); @@ -11054,7 +11078,7 @@ void netdev_sw_irq_coalesce_default_on(struct net_device *dev) WARN_ON(dev->reg_state == NETREG_REGISTERED); if (!IS_ENABLED(CONFIG_PREEMPT_RT)) { - dev->gro_flush_timeout = 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); 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; } From patchwork Thu Aug 29 13:12:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Damato X-Patchwork-Id: 13783201 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (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 59BCC1AED50 for ; Thu, 29 Aug 2024 13:13:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724937200; cv=none; b=S6bnM2Xt6fPQeUT3gHxP7iEZm4Ux354rGzTpapR9IK0SJGEfBew6EW1R53D3cAQQs50ROPTBLgPLxpgDxo/bOEpmiG2sO/6d2SD9kZviSTl/KyCe2QUqyQSM2fhKm8FhtgQa8bfgY8wpZJRJLOiem5LFuBMAbD34xeSyJFfxEIQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724937200; c=relaxed/simple; bh=LY6teNijKykhT8LcLXhvWcqr0xTJvW1UGMeUYMcjQ5s=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=RnyGg/jA+Z7sg1sewbZleXu/CrBtqc34CtHwvfzJb2e/m0Wg6lmoTKluIgwhD2UXvCFUPNBBEr7l11FRiQ2vzMENvR98ie41AQa88TOtaOeYJBCJiDtFAPdMyV3gRgYgUyf1yEPtTaxStfEVEnFuVJamPYNnMebj0GSbVQwWVPg= 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=dIx6Sn/I; arc=none smtp.client-ip=209.85.214.170 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="dIx6Sn/I" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-201d5af11a4so5487835ad.3 for ; Thu, 29 Aug 2024 06:13:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1724937198; x=1725541998; 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=dIx6Sn/I1y8uzjLXHRiKDU9nP8K3m7jBDQcKXN4C55BOskW0tECAZqzBsXiKKW5PsQ fHGjaQbmkrNTAVtQ0Q3nCsdk+8WnigIdl+cPjgpnkQPL7t4IG/OzcID41xMuVF6huTjS HqoR+ZqaPndr3FlnUMX3ldOiLdmP34qq79vWs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724937198; x=1725541998; 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=iwNN3vWwhWnoHQJk0jsWodWcf+RccLMwjiIxWjd+s5Mc26cmZuSWsJlEhoJC3Hf2Hp iK6AbVWTApKBum0yeQAk/UPzYUaAjyr7v0M6kB/HLOBiUJ83jd2/n6AhNQIYqY9jTr/V 3RSqO4Nquz1gvHn2C3FkKWkoaTATlpanvD7JDfxvOnC5mEpyGjksr06Tsx4BZ9WCnOij 4nt8+lmBXEngskGU8CjUxpQ1ViKHURE7cbpAMaMfbVzf2QqipXK0EbukHb6lkrpuOfQX kAx51Y8IsJOyiInz/UmP5HR8ymd1IJk4jfn2Og3ec98h0ViVxK4z743UaBnrfjwOiluj 5mJw== X-Gm-Message-State: AOJu0YwaAlnOO3KmhGk8IQzyW/vPcImjx0/JWs9ktB9pAlPMe5c/hLUV lOdSUI5Pa8xb8EHiI6xC78v/1tDn8LJNNyYFvZoN3IKz5js4A60YEfFki5Sq6+18YPbV8TEAN8l 72kFG8z2x31oyvvSWphkso6Y6czheRnYczZPa+XIhron/ZXGBEMOYo6WeMaWxABegZD+1FGlCZY HYs2bhbzSbdSmX8GYTzuvP+Kzn5sGv/wKG3riUag== 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: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org 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/netlink/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, __NETDEV_A_NAPI_MAX, NETDEV_A_NAPI_MAX = (__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 napi_struct *napi, const struct genl_info *info) { int napi_defer_hard_irqs; + unsigned long gro_flush_timeout; void *hdr; pid_t pid; @@ -193,6 +194,11 @@ netdev_nl_napi_fill_one(struct sk_buff *rsp, struct napi_struct *napi, if (nla_put_s32(rsp, NETDEV_A_NAPI_DEFER_HARD_IRQS, napi_defer_hard_irqs)) goto nla_put_failure; + gro_flush_timeout = 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); return 0; diff --git a/tools/include/uapi/linux/netdev.h b/tools/include/uapi/linux/netdev.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, __NETDEV_A_NAPI_MAX, NETDEV_A_NAPI_MAX = (__NETDEV_A_NAPI_MAX - 1) From patchwork Thu Aug 29 13:12:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Damato X-Patchwork-Id: 13783202 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.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 807B51ABEC2 for ; Thu, 29 Aug 2024 13:13:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724937204; cv=none; b=a85ZV39ry8gqVcAhwNhFprV3u4J5I27kLb+S64QSFbSivJxzwc4zdHPFjOJvdXgQ+UwrqCCoHqW2YfYViwJb8OuF/zKqS18dPaaPFxewUDB77bmZGrLr0HZzSFGg7qy48p3wl7byKcoXJVBLZ6b7m1fB4DIsQCiMT/Ao583Tb5Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724937204; c=relaxed/simple; bh=0L8vN7Z5mU6GUGAu+SGn6arcn3NkZa7mF5sCgHhz5AY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=k4pQYgafk+SqrIer1xlF5gupfz8FsBLNskk7BDH4Njt8aOGsXCVGBPuk/B0BMNd6Z/elU1QZnYuijIpA6V+V22ebCsdl0LOCmZZVcnKLjH+bTSYdJ8stOlc6mUQy5D3btgt4uhqeLxmDYeHJrFMAioe6TO1TSFCWaNVs9q05pvY= 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.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="c6VyC+39" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-2021aeee5e4so3855435ad.0 for ; Thu, 29 Aug 2024 06:13:22 -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=o3PDMTqPAYrJ4ox2y4lV6AcKUcOfDzc4av+wTVIta4yttTUxc/0/4zm05GJDzR6Hnn Hm0JrRf31SxtSdX6F2MjwmzYVrwg115uXI/EMeBaufAZ3yvUpCV2bMuXV7++qO0o+dG7 98gU2m+vuLtTWtg2/MEm6ylWwgwm2Xv4nFnPI5FneRT+B6et18QX0HbCBf8J67eUkG8v HDiExcQKfg+4pwS8OQyq5LzjF8gQcF1toU3YOZtd313wu/irVHpGp0Feqem5WT0SpHLh q4kK2vhiS3X+vC9xsqI4ajnFOiDz+lmLiZiv1Dr/eNajzIJuBRUaqTg+C1lwVeNwTmmg lqjA== X-Gm-Message-State: AOJu0YzRD7A3K++skeneqTsDdgQXgbd9jVDUyo84memd2RbE4tvYHw+o A2NzGVFkE6B8dYoXJACzHhuZZD4cfjSYwktItPc7BtP77/QqAYtpz53jb9M8PQJ+jO/FKKBHGg8 x59DzB8GdHPWCAVn3BazkQVMV5a/tivbsMvdYVHN2IP/YW6z/RMYYu+vVcRlLXIKBkQKPM6fEvn i6tq2N1DDklDw8E0BX11BCAzsoSLLAE6jppgr4QA== 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: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org 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/netlink/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 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, __NETDEV_CMD_MAX, NETDEV_CMD_MAX = (__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_policy[NETDEV_A_QSTATS_SCOPE [NETDEV_A_QSTATS_SCOPE] = NLA_POLICY_MASK(NLA_UINT, 0x1), }; +/* NETDEV_CMD_NAPI_SET - set */ +static const struct nla_policy netdev_napi_set_nl_policy[NETDEV_A_NAPI_GRO_FLUSH_TIMEOUT + 1] = { + [NETDEV_A_NAPI_ID] = { .type = NLA_U32, }, + [NETDEV_A_NAPI_DEFER_HARD_IRQS] = { .type = NLA_S32 }, + [NETDEV_A_NAPI_GRO_FLUSH_TIMEOUT] = { .type = NLA_U64 }, +}; + /* Ops table for netdev */ static const struct genl_split_ops netdev_nl_ops[] = { { @@ -151,6 +158,13 @@ static const struct genl_split_ops netdev_nl_ops[] = { .maxattr = NETDEV_A_QSTATS_SCOPE, .flags = GENL_CMD_CAP_DUMP, }, + { + .cmd = NETDEV_CMD_NAPI_SET, + .doit = netdev_nl_napi_set_doit, + .policy = netdev_napi_set_nl_policy, + .maxattr = NETDEV_A_NAPI_GRO_FLUSH_TIMEOUT, + .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, + }, }; static const struct genl_multicast_group netdev_nl_mcgrps[] = { 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); 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, struct netlink_callback *cb) return err; } +static int +netdev_nl_napi_set_config(struct napi_struct *napi, struct genl_info *info) +{ + u64 gro_flush_timeout = 0; + int defer = 0; + + if (info->attrs[NETDEV_A_NAPI_DEFER_HARD_IRQS]) { + defer = 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 = nla_get_u64(info->attrs[NETDEV_A_NAPI_GRO_FLUSH_TIMEOUT]); + 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 = nla_get_u32(info->attrs[NETDEV_A_NAPI_ID]); + + rtnl_lock(); + + napi = napi_by_id(napi_id); + if (napi) + err = netdev_nl_napi_set_config(napi, info); + else + err = -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/netdev.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, __NETDEV_CMD_MAX, NETDEV_CMD_MAX = (__NETDEV_CMD_MAX - 1)