From patchwork Tue Mar 5 11:53:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13582267 X-Patchwork-Delegate: kuba@kernel.org Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0B65256758 for ; Tue, 5 Mar 2024 12:00:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709640022; cv=none; b=oCJWkN0VC/YL2pQR/BtvKZLw5aQok2Yw9ODdl2P6LusdCAQpDoCoU7JVcy8ylm5UF38lSWVEg4detsHQD2WEPR5ef8jTnZwIp6OqR0rZB2Wut0PXMGU3iUp9477Qb/eSryU7NqPgf+Kr/NiCKCIF/RoaizaMi5eSq6UGWilrIRw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709640022; c=relaxed/simple; bh=Mv3v/NMtd1XS9qne058p3PtUn1yBmAHQg4G4wooe36M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iUOGkwp2gAwxgxJU7vPet4zdjYZrM15MqxHIktd+/OHQGEh/s/R0CE6oOcSVefTKj97Yw0dTUj78IZghyW+Ho1Z7cNeUNykGp9Yq5L0h2GLxLf4TQRMJy17WqwDLGNUsinC7lVrvqdYy5Gf1C80qUHnmm+W/MQYr3fjYBAljAFQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=DZ3h48p+; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=8bADG7Sp; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="DZ3h48p+"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="8bADG7Sp" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1709640019; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vCaddM3xhV5JRs0tRmSplPAY+US5sUgMjs8JDnagyZE=; b=DZ3h48p+voZxi1/NwKvdziJRoZkTOFdyX/XTtlILdx/ZYhtz/PNjdbqfWRB+vxYnth8FrV T8lH6e1TsW14AgT/qUwPNfvASOMqxHs8D08fYcRwi01Pgi0lLbMcJywhjCKMkXsL06FfM0 QURZsTjcyGaL1/t/JedHNMbxXu3SUfsDadZfOQEAmOsdnOpcquYU1CFXA9IwUOGUIVzL4S nY60yAApNh3hM3TQzmrAlA/TIwZC4KwVA8t+DlAhID8pmpAkyeoJeY3YHETZv/TPSAHkg2 HsBhceiK5GQYKrexzk1ufxjf+mhXA1wwh3TDXR/vrMDMSHVp5Zk+iqazYI1bVg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1709640019; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vCaddM3xhV5JRs0tRmSplPAY+US5sUgMjs8JDnagyZE=; b=8bADG7Sp5olzgv8cxDMIbP8V9v83B2HcF+EQMsf4WJesoYB28evW9qAWRlh/QQp3mtnH1l U48Fu9eaJJ7DeCAA== To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Jesper Dangaard Brouer , Paolo Abeni , Thomas Gleixner , Wander Lairson Costa , Yan Zhai , Sebastian Andrzej Siewior Subject: [PATCH v4 net-next 1/4] net: Remove conditional threaded-NAPI wakeup based on task state. Date: Tue, 5 Mar 2024 12:53:19 +0100 Message-ID: <20240305120002.1499223-2-bigeasy@linutronix.de> In-Reply-To: <20240305120002.1499223-1-bigeasy@linutronix.de> References: <20240305120002.1499223-1-bigeasy@linutronix.de> 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 A NAPI thread is scheduled by first setting NAPI_STATE_SCHED bit. If successful (the bit was not yet set) then the NAPI_STATE_SCHED_THREADED is set but only if thread's state is not TASK_INTERRUPTIBLE (is TASK_RUNNING) followed by task wakeup. If the task is idle (TASK_INTERRUPTIBLE) then the NAPI_STATE_SCHED_THREADED bit is not set. The thread is no relying on the bit but always leaving the wait-loop after returning from schedule() because there must have been a wakeup. The smpboot-threads implementation for per-CPU threads requires an explicit condition and does not support "if we get out of schedule() then there must be something to do". Removing this optimisation simplifies the following integration. Set NAPI_STATE_SCHED_THREADED unconditionally on wakeup and rely on it in the wait path by removing the `woken' condition. Acked-by: Jakub Kicinski Signed-off-by: Sebastian Andrzej Siewior --- net/core/dev.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index fe054cbd41e92..fe1055fe0b55c 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -4436,13 +4436,7 @@ static inline void ____napi_schedule(struct softnet_data *sd, */ thread = READ_ONCE(napi->thread); if (thread) { - /* Avoid doing set_bit() if the thread is in - * INTERRUPTIBLE state, cause napi_thread_wait() - * makes sure to proceed with napi polling - * if the thread is explicitly woken from here. - */ - if (READ_ONCE(thread->__state) != TASK_INTERRUPTIBLE) - set_bit(NAPI_STATE_SCHED_THREADED, &napi->state); + set_bit(NAPI_STATE_SCHED_THREADED, &napi->state); wake_up_process(thread); return; } @@ -6723,8 +6717,6 @@ static int napi_poll(struct napi_struct *n, struct list_head *repoll) static int napi_thread_wait(struct napi_struct *napi) { - bool woken = false; - set_current_state(TASK_INTERRUPTIBLE); while (!kthread_should_stop()) { @@ -6733,15 +6725,13 @@ static int napi_thread_wait(struct napi_struct *napi) * Testing SCHED bit is not enough because SCHED bit might be * set by some other busy poll thread or by napi_disable(). */ - if (test_bit(NAPI_STATE_SCHED_THREADED, &napi->state) || woken) { + if (test_bit(NAPI_STATE_SCHED_THREADED, &napi->state)) { WARN_ON(!list_empty(&napi->poll_list)); __set_current_state(TASK_RUNNING); return 0; } schedule(); - /* woken being true indicates this thread owns this napi. */ - woken = true; set_current_state(TASK_INTERRUPTIBLE); } __set_current_state(TASK_RUNNING);