From nobody Sun Nov 24 04:44:21 2024 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.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 66D3B148FF9 for ; Fri, 8 Nov 2024 02:39:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731033580; cv=none; b=RLgkpbHtkyu7mNcou4n26xjoiIzKGyEDS5nI0wuaRyuqCBqfjUFs+j3z3bgL3lLXHkCwys+wEZT4eEObE8+qIHNn6Uo2mPQPstmcnFGWezvHH8SRJfVWJtUbC0SRwllNdSoxwD3obfr5n8JWwgRnuBAUrFu15I7LMRwJXOTxrTQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731033580; c=relaxed/simple; bh=qdi7EZQuEEMN3wiZppPLQdX1SCk2Zw8iZ75pu39cHVE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dWkDbLAN7AHxR6sxYut8gP9wUrwvkYrcV7N79+l1I6gddQFOC/tgSM6xMBYEsjKxH5I3sDZvqDZtFWONunnMR/vxsoKhwJnKiDo9bDt4gF610ir9Pid0LXG3ZSiluVcuUFCkttyeN5eANefn0vbx2YwPnB7vkAb4/1PwG76i7h0= 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=HLproQll; arc=none smtp.client-ip=209.85.210.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="HLproQll" Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-7240d93fffdso890142b3a.2 for ; Thu, 07 Nov 2024 18:39:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1731033578; x=1731638378; 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=caqFJ5c+kF6pXY5SxWq1Dvuvko4/3vnOEXbPCOsfprg=; b=HLproQllcGl8hh5zN9vO0gcwcTweUKga9ddc5Qx1JqJn1mO0FPeIffK8Qa4szdOlKe vLH6iNb7Jjj7tgi8aWC2zAih2Gt8Eq2Pa6RjbWa63S+gcyNCTbnUXKvyjXB+mCXQtbUA 7wC9Cq6hJV527pZuMD0cX1WgA+YSIdF3XzUYI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731033578; x=1731638378; 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=caqFJ5c+kF6pXY5SxWq1Dvuvko4/3vnOEXbPCOsfprg=; b=qaGCV4m8ycO/6OMzD0xSqcsk32V7PA4Y59+tznQF62HEVNB2WzVzsa2tlCpWHON/IH gFuEWXiqnGzVTqpsK/cTCtDa/5Uuid+IZqJmHSArE3i6eV/hvdO0xctQNdwoY35qtuwa +qBMImtx0TJSe83PHB2jZdKPe6PzDSEuhabqfV69dcAyUmpFJ9doZuhSLQW/O1KQNQKt 7qVXRmufzc+mOHT1OsFuRheIZO/6fLPMU1HfFFFzAeiUkdOOfnuxhrSkhdG/0vsvoeXJ GRk1/GZ4ujNWxXQ1qdlgwWB3wTZigzT2AkGJUU69OV6/gBCMNMR+X+XUARZzUqJ/2sDT LTBQ== X-Forwarded-Encrypted: i=1; AJvYcCURNbyaQJlUVC463ObVbfAMpbishVNb+hssITBySL8xVxT13E+WbriDSu4RjlJm1RYiQhPZ6aTvyQQKAos=@vger.kernel.org X-Gm-Message-State: AOJu0YwQ6QLSgjoHwI1MId+NQqyteJgrmkhwrjBI+5z0aJ9zTL/yb7U4 PmknUmg0SnfpXXtF6WcMXXqZMbozVqSJdoZhBm+JW7HQ4rtsnMzwv5XuCGS+LLY= X-Google-Smtp-Source: AGHT+IHlFfbm0Pmfbo0flkKxCD1GouwjzrjeY1kIQiwWltEO4U94IT6WQ5s5XJWqpCXOwa6ta+3bbA== X-Received: by 2002:a05:6a00:2a0e:b0:71e:8023:c718 with SMTP id d2e1a72fcca58-7241328f296mr1946828b3a.8.1731033577717; Thu, 07 Nov 2024 18:39:37 -0800 (PST) Received: from localhost.localdomain ([2620:11a:c019:0:65e:3115:2f58:c5fd]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-724079a403fsm2561208b3a.105.2024.11.07.18.39.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2024 18:39:37 -0800 (PST) From: Joe Damato To: netdev@vger.kernel.org Cc: corbet@lwn.net, hdanton@sina.com, bagasdotme@gmail.com, pabeni@redhat.com, namangulati@google.com, edumazet@google.com, amritha.nambiar@intel.com, sridhar.samudrala@intel.com, sdf@fomichev.me, peter@typeblog.net, m2shafiei@uwaterloo.ca, bjorn@rivosinc.com, hch@infradead.org, willy@infradead.org, willemdebruijn.kernel@gmail.com, skhawaja@google.com, kuba@kernel.org, Martin Karsten , Joe Damato , "David S. Miller" , Simon Horman , David Ahern , Sebastian Andrzej Siewior , Lorenzo Bianconi , Alexander Lobakin , linux-kernel@vger.kernel.org (open list) Subject: [PATCH net-next v7 2/6] net: Add control functions for irq suspension Date: Fri, 8 Nov 2024 02:38:58 +0000 Message-Id: <20241108023912.98416-3-jdamato@fastly.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241108023912.98416-1-jdamato@fastly.com> References: <20241108023912.98416-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" 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 effectively 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 Acked-by: Stanislav Fomichev Reviewed-by: Sridhar Samudrala --- v7: - This is now patch 2 instead of patch 3; patch 2 from v6 was dropped. v1 -> v2: - Added a comment to napi_resume_irqs. include/net/busy_poll.h | 3 +++ net/core/dev.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/include/net/busy_poll.h b/include/net/busy_poll.h index f03040baaefd..c858270141bc 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); =20 +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 4d910872963f..81f5e4175a6a 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -6507,6 +6507,45 @@ void napi_busy_loop(unsigned int napi_id, } EXPORT_SYMBOL(napi_busy_loop); =20 +void napi_suspend_irqs(unsigned int napi_id) +{ + struct napi_struct *napi; + + rcu_read_lock(); + napi =3D napi_by_id(napi_id); + if (napi) { + unsigned long timeout =3D napi_get_irq_suspend_timeout(napi); + + 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 =3D napi_by_id(napi_id); + if (napi) { + /* If irq_suspend_timeout is set to 0 between the call to + * napi_suspend_irqs and now, the original value still + * determines the safety timeout as intended and napi_watchdog + * will resume irq processing. + */ + if (napi_get_irq_suspend_timeout(napi)) { + local_bh_disable(); + napi_schedule(napi); + local_bh_enable(); + } + } + rcu_read_unlock(); +} +EXPORT_SYMBOL(napi_resume_irqs); + #endif /* CONFIG_NET_RX_BUSY_POLL */ =20 static void __napi_hash_add_with_id(struct napi_struct *napi, --=20 2.25.1