From nobody Thu Nov 28 22:35:54 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 7E5F41B010C for ; Thu, 26 Sep 2024 22:49:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727390958; cv=none; b=IXbx9v7l6zx4Vh+i4Xq1D+F0k7aBrVtXVBHFeqw/cCN/ZhxPqrZzqoTj7Nfgp2j1KYsCc35TTVP4eg+hKSMNJ+e9KpItGxloSvJhhlvIaPkWVUMyPeBBi6LhsnqPiHwp/4uHGskllX8rtRF/giWMQmHQ+JpoQr+8La0q3Aus0ms= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727390958; c=relaxed/simple; bh=0P3cw1hR9bRTtfA3GkNVPSqmTI3laEGRCvS0ucnfa+o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mQeVQY2n3vShbAtkh0Tiphx3zfX9JDdugdvgB2vt97XE3cSDZ0NUNUYABuo7gs4jJ3lt8NWNowQvQwc1v5x8vBteejqzG3cr9V9Dz4MO2IyF19m3ciI8a8kf1xm9qx568CQjH8KYIIdNhUV9RbRAL6iH0ZbZgzt7PuPXKuzQspw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CSRjgxaK; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CSRjgxaK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 370C1C4CECE; Thu, 26 Sep 2024 22:49:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727390958; bh=0P3cw1hR9bRTtfA3GkNVPSqmTI3laEGRCvS0ucnfa+o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CSRjgxaKBDq9huQ+NP2aSSsEPA4znsDF9fYKi49YQHnimwX6ef7noEMc3hgoh4447 RB21Nw0zRgwENDf2H8AQtWYmAA7ARhsEgxhZZNz8XmrFXtl91KGGX87ihKgXKKZMmR mwX0c/TR/Z/I0LIgL9mcLOZfzYa3MfXGpyRmNRdD5Wzz+X30XLqJUl+zEnbLSOhc5Y QoncazrS/qKejP96Akq7cQzDVRf4pM2mLMf0unlx6vXwttpuIN7lk8Kv+bCGXbQIye 1rFxnPTN9D8Wzimkbc4cY2By3ax614PPe4nTHEokLqg5uFbqG0hAP8YaJyedYNqvwH nXxLIJTPR5PVQ== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Russell King , linux-arm-kernel@lists.infradead.org, Andrew Morton , Peter Zijlstra , Thomas Gleixner , Dave Martin , Nicolas Pitre Subject: [PATCH 01/20] arm/bL_switcher: Use kthread_run_on_cpu() Date: Fri, 27 Sep 2024 00:48:49 +0200 Message-ID: <20240926224910.11106-2-frederic@kernel.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240926224910.11106-1-frederic@kernel.org> References: <20240926224910.11106-1-frederic@kernel.org> 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" Use the proper API instead of open coding it. Reviewed-by: Dave Martin Acked-by: Nicolas Pitre Signed-off-by: Frederic Weisbecker --- arch/arm/common/bL_switcher.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/arch/arm/common/bL_switcher.c b/arch/arm/common/bL_switcher.c index 9a9aa53547a6..d1e82a318e3b 100644 --- a/arch/arm/common/bL_switcher.c +++ b/arch/arm/common/bL_switcher.c @@ -307,13 +307,11 @@ static struct task_struct *bL_switcher_thread_create(= int cpu, void *arg) { struct task_struct *task; =20 - task =3D kthread_create_on_node(bL_switcher_thread, arg, - cpu_to_node(cpu), "kswitcher_%d", cpu); - if (!IS_ERR(task)) { - kthread_bind(task, cpu); - wake_up_process(task); - } else + task =3D kthread_run_on_cpu(bL_switcher_thread, arg, + cpu, "kswitcher_%d"); + if (IS_ERR(task)) pr_err("%s failed for CPU %d\n", __func__, cpu); + return task; } =20 --=20 2.46.0 From nobody Thu Nov 28 22:35:54 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 660D51B0132 for ; Thu, 26 Sep 2024 22:49:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727390961; cv=none; b=qYanZ3ajkL6o8fkOzH18WrUWehhQDyRPRsHKDUMQ+wIDi7T6IZkjIF6LNxmheBhzGTFC3Abi/MxO2nuWFO8fHfQlnuy/nY331F6VNn31Trv/B+Lgx+kRy+8fDYbtCJ61gH9s+pEjZaM7i+LUEpHV0NNCVhSMDMKZ5o03XrCHks4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727390961; c=relaxed/simple; bh=IoZPaCv863UIRZr027aVdH0TUkaWU86goti0yjIS6gg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p+0gM8ko+RNQbpy8tQV5e3z04Qv/5NWzWJ44aVhN5QPY1Tci0Zj3KmiQ6ww62IUgcfrrRJRSw3wO7xKsa3FdCAweSTanK3kIxwNTnOC0b8hWLxCE5oVtpKyx2xaaC/Oda4gKSSy4fj7KzKz8Tc9P69SBnLhnG6a9PoawJlQL70s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=U2hFLO8T; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="U2hFLO8T" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5C984C4CEC9; Thu, 26 Sep 2024 22:49:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727390960; bh=IoZPaCv863UIRZr027aVdH0TUkaWU86goti0yjIS6gg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U2hFLO8TVLpXed/PO8bgaQChLsEVO9vBLiU/qf2289Myb6BL0gr2NKwazqBvUsLwx 7wVi1axumlXMWfRDy+cwHzwmOwWePtR7tdL/5DWBWofhdVwSND2gOcn1x1CWxuU9Gk JWw3WVJF7DrTNbKP34keg4vaIuYVO/yi/+VnPIWv+5Pc2iUZfH5d/6AsekRekntuEU UISHVVdOIAfSKquSmHqMRyg+DZ9lSJwNHiUQjlJ0vV/soCrtV9FBjHUPjfgo2klb4g EKS7gUmP77XIYQQQS/kvS9aEG2qoGF6ebiD6BX2X9pCKTKwzVGE9sYbDcWgTjVtHHB +nxwrY/j0geVQ== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Fenghua Yu , Reinette Chatre , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Andrew Morton , Peter Zijlstra , Thomas Gleixner Subject: [PATCH 02/20] x86/resctrl: Use kthread_run_on_cpu() Date: Fri, 27 Sep 2024 00:48:50 +0200 Message-ID: <20240926224910.11106-3-frederic@kernel.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240926224910.11106-1-frederic@kernel.org> References: <20240926224910.11106-1-frederic@kernel.org> 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" Use the proper API instead of open coding it. Acked-by: Reinette Chatre Signed-off-by: Frederic Weisbecker --- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 28 +++++++---------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/pseudo_lock.c b/arch/x86/kernel/cp= u/resctrl/pseudo_lock.c index e69489d48625..ae1f0c28eee6 100644 --- a/arch/x86/kernel/cpu/resctrl/pseudo_lock.c +++ b/arch/x86/kernel/cpu/resctrl/pseudo_lock.c @@ -1205,20 +1205,14 @@ static int pseudo_lock_measure_cycles(struct rdtgro= up *rdtgrp, int sel) plr->cpu =3D cpu; =20 if (sel =3D=3D 1) - thread =3D kthread_create_on_node(measure_cycles_lat_fn, plr, - cpu_to_node(cpu), - "pseudo_lock_measure/%u", - cpu); + thread =3D kthread_run_on_cpu(measure_cycles_lat_fn, plr, + cpu, "pseudo_lock_measure/%u"); else if (sel =3D=3D 2) - thread =3D kthread_create_on_node(measure_l2_residency, plr, - cpu_to_node(cpu), - "pseudo_lock_measure/%u", - cpu); + thread =3D kthread_run_on_cpu(measure_l2_residency, plr, + cpu, "pseudo_lock_measure/%u"); else if (sel =3D=3D 3) - thread =3D kthread_create_on_node(measure_l3_residency, plr, - cpu_to_node(cpu), - "pseudo_lock_measure/%u", - cpu); + thread =3D kthread_run_on_cpu(measure_l3_residency, plr, + cpu, "pseudo_lock_measure/%u"); else goto out; =20 @@ -1226,8 +1220,6 @@ static int pseudo_lock_measure_cycles(struct rdtgroup= *rdtgrp, int sel) ret =3D PTR_ERR(thread); goto out; } - kthread_bind(thread, cpu); - wake_up_process(thread); =20 ret =3D wait_event_interruptible(plr->lock_thread_wq, plr->thread_done =3D=3D 1); @@ -1315,18 +1307,14 @@ int rdtgroup_pseudo_lock_create(struct rdtgroup *rd= tgrp) =20 plr->thread_done =3D 0; =20 - thread =3D kthread_create_on_node(pseudo_lock_fn, rdtgrp, - cpu_to_node(plr->cpu), - "pseudo_lock/%u", plr->cpu); + thread =3D kthread_run_on_cpu(pseudo_lock_fn, rdtgrp, + plr->cpu, "pseudo_lock/%u"); if (IS_ERR(thread)) { ret =3D PTR_ERR(thread); rdt_last_cmd_printf("Locking thread returned error %d\n", ret); goto out_cstates; } =20 - kthread_bind(thread, plr->cpu); - wake_up_process(thread); - ret =3D wait_event_interruptible(plr->lock_thread_wq, plr->thread_done =3D=3D 1); if (ret < 0) { --=20 2.46.0 From nobody Thu Nov 28 22:35:54 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 327AB1AFB2E for ; Thu, 26 Sep 2024 22:49:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727390963; cv=none; b=EnYsESc39qSQPRHHHHw+IiR+AaA6hKOOxXJrSzlLaY2aq5+pjVPLY0vYd3oAiuftOVYcPbqUvYus63neYW6hSeaVT/rDibs5m75XAnQHPrZQ0LBKRLae4jEZYMwLNX0ochk0f9C4YgZcfP3oQrAAPepA+IlouYVqj/M1XPJ79p4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727390963; c=relaxed/simple; bh=FNDnC4NnSKXZi0fBd7+r+3GeRTH7g/FrYIGmJ7rL3+g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M0LDP9Oorrpaa4i+c3+8kYJ5CkitCvyD6NaC33Y+YiEqb3X02OmxP6k0e332L4TPZK7am+7YicARYMC48YS7tFomid1nieuEh7jFP7cIukqsSnBR4XCTdZBDH73RJZ1hU4BAns0g7s2PEMfuO0Uf3SU6e+V1+aCl6Ipuk2N7x/g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iIgaUP7Z; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iIgaUP7Z" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E56DC4CED0; Thu, 26 Sep 2024 22:49:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727390962; bh=FNDnC4NnSKXZi0fBd7+r+3GeRTH7g/FrYIGmJ7rL3+g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iIgaUP7ZzM8sluTdnxV7RYe/ra6qR89+gIe5xvdzIBmOA7Ptx5nPeBif7FlVpMPll //FVrVnuYmTYKCuFbiJqGnW/p5fjJr6XbM7KTBIYE4UHUoe8gEtcxXso1LgaWGUwmb bsdd4XYdUDrIxTACL/C9PVLaeBn819oDZBvRePz7UMQiogrISjUL6wLFOKU9GVQ35x JUmE9dijH610yl21BqWm+Of7mDzLNxPMQoCloyvmXaoTnfIOBS/HHk8gbghFn48dcZ A8FGoFJ3MJ0EfFMUQfakDvW+o5CU0VaInu2XxBMgB8LgTTT5XSOzFZ9VLzO5HdpaNW TM89+HgtBAkpw== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Dinh Nguyen , Andrew Morton , Peter Zijlstra , Thomas Gleixner Subject: [PATCH 03/20] firmware: stratix10-svc: Use kthread_run_on_cpu() Date: Fri, 27 Sep 2024 00:48:51 +0200 Message-ID: <20240926224910.11106-4-frederic@kernel.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240926224910.11106-1-frederic@kernel.org> References: <20240926224910.11106-1-frederic@kernel.org> 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" Use the proper API instead of open coding it. Signed-off-by: Frederic Weisbecker --- drivers/firmware/stratix10-svc.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/firmware/stratix10-svc.c b/drivers/firmware/stratix10-= svc.c index 528f37417aea..4cf5bd5647a4 100644 --- a/drivers/firmware/stratix10-svc.c +++ b/drivers/firmware/stratix10-svc.c @@ -967,18 +967,15 @@ int stratix10_svc_send(struct stratix10_svc_chan *cha= n, void *msg) /* first client will create kernel thread */ if (!chan->ctrl->task) { chan->ctrl->task =3D - kthread_create_on_node(svc_normal_to_secure_thread, - (void *)chan->ctrl, - cpu_to_node(cpu), - "svc_smc_hvc_thread"); + kthread_run_on_cpu(svc_normal_to_secure_thread, + (void *)chan->ctrl, + cpu, "svc_smc_hvc_thread"); if (IS_ERR(chan->ctrl->task)) { dev_err(chan->ctrl->dev, "failed to create svc_smc_hvc_thread\n"); kfree(p_data); return -EINVAL; } - kthread_bind(chan->ctrl->task, cpu); - wake_up_process(chan->ctrl->task); } =20 pr_debug("%s: sent P-va=3D%p, P-com=3D%x, P-size=3D%u\n", __func__, --=20 2.46.0 From nobody Thu Nov 28 22:35:54 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 54FEB1B07BF; Thu, 26 Sep 2024 22:49:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727390965; cv=none; b=LLF+1fLOdZi8paQofzIxaIWLiP/vf6IrpjDkLkYPJp4UkI/gkAN7QSMwqNfXiABYrBY24rvigLNOoczSjtb/ascr+/1CasPhVdFbnYH53CJ2N/S7f0sUV0FvZjY+r0si0vXilYS1jFTjH0hjUrLynheZCSj+f1UZgPCN51vOfYE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727390965; c=relaxed/simple; bh=4yWGGyiLUE5LgminEo1+3BKAknZRJAj6SQQ4Ov4Yt6k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lf26gn/AzLITM2H953HGO9zsxTUuUmbD0S9OYJcL2ztW2YSpVT/JgpABYoSVirMJf3YnHyeXMH8wzRVdzyWiP4gCQumfxDrTJrw6K9lFG8JPSCk/8IOyXDvy0tyEm1Dz0PtqvJv1k8AEJi0H9OlMfEIslGCYEA5UBGVvdydFAzY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=k564yRZp; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="k564yRZp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0EB30C4CED1; Thu, 26 Sep 2024 22:49:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727390965; bh=4yWGGyiLUE5LgminEo1+3BKAknZRJAj6SQQ4Ov4Yt6k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k564yRZp8pOLJHoBbfm/GOdk2+Caaj7NNScqdhv/mPScQTthzq01ka8TAu7kEpL1n Q0/UkRBBoC+BGKtg8+S4xroXlOOc5LjCUvtwXglhSiVAyHpl7QL2rnSxvk85hGrZ7+ yjs6fFuMhLz/oi6EdW1RqmT4Y2H5t6fyXa8Q4rae/mLsKyZMWTlIT3/lITiTin4s/b gIqsiriOY21JwYw+99K2acb54RBMWSEvtuYQl6KHUiqgbVcHhmX3Ws2REz388v2Y1D 9JTpvXwG/AURaqzkzmaksZhL8ExMpD6roOHA8c4CUn7+FJtI5DVQji79/NN2ctqZkt Q4uRPdzMxV82A== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Saurav Kashyap , Javed Hasan , GR-QLogic-Storage-Upstream@marvell.com, "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Andrew Morton , Peter Zijlstra , Thomas Gleixner Subject: [PATCH 04/20] scsi: bnx2fc: Use kthread_create_on_cpu() Date: Fri, 27 Sep 2024 00:48:52 +0200 Message-ID: <20240926224910.11106-5-frederic@kernel.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240926224910.11106-1-frederic@kernel.org> References: <20240926224910.11106-1-frederic@kernel.org> 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" Use the proper API instead of open coding it. However it looks like bnx2fc_percpu_io_thread() kthread could be replaced by the use of a high prio workqueue instead. Signed-off-by: Frederic Weisbecker --- drivers/scsi/bnx2fc/bnx2fc_fcoe.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/scsi/bnx2fc/bnx2fc_fcoe.c b/drivers/scsi/bnx2fc/bnx2fc= _fcoe.c index f49783b89d04..36126030e76d 100644 --- a/drivers/scsi/bnx2fc/bnx2fc_fcoe.c +++ b/drivers/scsi/bnx2fc/bnx2fc_fcoe.c @@ -2610,14 +2610,11 @@ static int bnx2fc_cpu_online(unsigned int cpu) =20 p =3D &per_cpu(bnx2fc_percpu, cpu); =20 - thread =3D kthread_create_on_node(bnx2fc_percpu_io_thread, - (void *)p, cpu_to_node(cpu), - "bnx2fc_thread/%d", cpu); + thread =3D kthread_create_on_cpu(bnx2fc_percpu_io_thread, + (void *)p, cpu, "bnx2fc_thread/%d"); if (IS_ERR(thread)) return PTR_ERR(thread); =20 - /* bind thread to the cpu */ - kthread_bind(thread, cpu); p->iothread =3D thread; wake_up_process(thread); return 0; --=20 2.46.0 From nobody Thu Nov 28 22:35:54 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 613AF1B140D; Thu, 26 Sep 2024 22:49:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727390968; cv=none; b=kci0CCR0gxFZ1wWme+xR0ybKW9b9n1/kzOAOpbO6of6blHMf9uUlSGKEWjo2NwpdZpU7Wmk2pJF5kAj2zogrmdEA4qGkbOFnR0UCUf10/9YrcggsJYO5BhVX0ByD8Wqkv/rbdtytSsa/IkGxEwFvtwAnVu/D8tFPabjQg63XOAU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727390968; c=relaxed/simple; bh=LFXpL5/nrAXstPiOj0IbxTit69TGzKOpoS47R1I/bUE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M54J4GhQS6OgIC6tbgNnpLdi7eI/hn9UpdAqmh6F38twV36ChvaBngfyBT89bAe3IgR8sqBRFAJqHVTjkp+uDkxcxA0vUY/5mXnYKHk4bjXCJTBnvrOPo3vBY+4w5ZKgDbcfzBB/6cmTkVuI00cU3H9EMUZncLw57QOybz1JAbA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NmBba2Un; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NmBba2Un" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AF0F3C4CEC9; Thu, 26 Sep 2024 22:49:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727390967; bh=LFXpL5/nrAXstPiOj0IbxTit69TGzKOpoS47R1I/bUE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NmBba2UnkZIb9p6p1rdb6P8aQjl7oareIrQ/4NATZEsBVRZPvbzcwJ/17rvFdqNF7 nh9SMwxXzKEbJrwdEzlB+Ic6vxFBVSF9EoJC83mwgn5m0WDFtBQUHbNMUg6aQAFgP3 I7FRMUdm0a6+mxHwLRxQXfGdtmicY62IkURK7hiP5lUIi3zIo6mjUGqxaRiEsTfYHw DryZHn1hDRxSO0e3ICeZG7QU0t59qbS2vGn6qzwO279/DrCTJRytQkPWwU4BUlRFXi CBqEE2XNowZhHd2s452qZlR9tKpsg5Cow1O6Ey4fvHl/0RxKmU6tyZce4F8Cv1BFTb wgwSCjvGBPZAw== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Nilesh Javali , Manish Rangankar , GR-QLogic-Storage-Upstream@marvell.com, "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Andrew Morton , Peter Zijlstra , Thomas Gleixner Subject: [PATCH 05/20] scsi: bnx2i: Use kthread_create_on_cpu() Date: Fri, 27 Sep 2024 00:48:53 +0200 Message-ID: <20240926224910.11106-6-frederic@kernel.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240926224910.11106-1-frederic@kernel.org> References: <20240926224910.11106-1-frederic@kernel.org> 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" Use the proper API instead of open coding it. However it looks like bnx2i_percpu_io_thread() kthread could be replaced by the use of a high prio workqueue instead. Signed-off-by: Frederic Weisbecker --- drivers/scsi/bnx2i/bnx2i_init.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/scsi/bnx2i/bnx2i_init.c b/drivers/scsi/bnx2i/bnx2i_ini= t.c index 872ad37e2a6e..cecc3a026762 100644 --- a/drivers/scsi/bnx2i/bnx2i_init.c +++ b/drivers/scsi/bnx2i/bnx2i_init.c @@ -415,14 +415,11 @@ static int bnx2i_cpu_online(unsigned int cpu) =20 p =3D &per_cpu(bnx2i_percpu, cpu); =20 - thread =3D kthread_create_on_node(bnx2i_percpu_io_thread, (void *)p, - cpu_to_node(cpu), - "bnx2i_thread/%d", cpu); + thread =3D kthread_create_on_cpu(bnx2i_percpu_io_thread, (void *)p, + cpu, "bnx2i_thread/%d"); if (IS_ERR(thread)) return PTR_ERR(thread); =20 - /* bind thread to the cpu */ - kthread_bind(thread, cpu); p->iothread =3D thread; wake_up_process(thread); return 0; --=20 2.46.0 From nobody Thu Nov 28 22:35:54 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 EDFE81B1436; Thu, 26 Sep 2024 22:49:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727390972; cv=none; b=tzM1JkT7CfGlJVH4nkwGMufAPhHY24Es9TjQI3ZLqZyQyScEp/51+xUoVnpZSPjq0wWtGwMIblkamWKfJ86sGfk4TMLHhRgMauH3V+C1EYJ3wxvq+5FTS0vGILVrLJcpBiOujxHSXrT7E9wzRSF4FKN5LSENhvqi+ilGDmUvSXc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727390972; c=relaxed/simple; bh=5gm2IlkjuHTv5aCOZyyCN0NSeTSEuIS/Liq2NVx+RNo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ukIn9MV3Q+WChj/73PAzqUMpReu6QpJwWWRyLs3iAKQSICXwcOE0Cdhh+16lXlEDxP3zZjdkF+LqJkf5kkW5kepSUpfKSq6AYURZUE33Lt5AlZHPms1cIyRpa+jiL0jlaijMmQ+ffY/vikUcUleRyUFLK+JTHIZ5muNgT3gsS7c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AsPooocQ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="AsPooocQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4093BC4CECE; Thu, 26 Sep 2024 22:49:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727390970; bh=5gm2IlkjuHTv5aCOZyyCN0NSeTSEuIS/Liq2NVx+RNo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AsPooocQwt6AD8CjWHTD1VqXF5cvd1y5cvFsThSUgXIJCfXz9YWinQqcGbR4R+dvJ 2oCDFGGPInTDzYMwAV1CSWmKPKa2TVB24H73pIVQfK+nNkSYqgJSwdBKCNnImexAyv Z8f4UhBLpTR4YhmCah+PiC6wmo5pfR2GrXeQoHC/X2YNgMq6wj6w1G0Rd8f5y+DOYn J92vGX7gLWj27Kh0wRf6CH6oAybPa8FsvvncfoYCQ9GumuzPoC0/3eFcEo+Yuiy/4q PoDjTE89r79OjbiG0O1UpdzHuUPE0zFlnIIHWlFGnZpaUmFxtyn76HkrRRQ10rktpq Ak2+2K498ZSug== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Nilesh Javali , Manish Rangankar , GR-QLogic-Storage-Upstream@marvell.com, "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Andrew Morton , Peter Zijlstra , Thomas Gleixner Subject: [PATCH 06/20] scsi: qedi: Use kthread_create_on_cpu() Date: Fri, 27 Sep 2024 00:48:54 +0200 Message-ID: <20240926224910.11106-7-frederic@kernel.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240926224910.11106-1-frederic@kernel.org> References: <20240926224910.11106-1-frederic@kernel.org> 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" Use the proper API instead of open coding it. However it looks like qedi_percpu_io_thread() kthread could be replaced by the use of a high prio workqueue instead. Signed-off-by: Frederic Weisbecker --- drivers/scsi/qedi/qedi_main.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/qedi/qedi_main.c b/drivers/scsi/qedi/qedi_main.c index c5aec26019d6..4b2a9cd811c4 100644 --- a/drivers/scsi/qedi/qedi_main.c +++ b/drivers/scsi/qedi/qedi_main.c @@ -1960,13 +1960,11 @@ static int qedi_cpu_online(unsigned int cpu) struct qedi_percpu_s *p =3D this_cpu_ptr(&qedi_percpu); struct task_struct *thread; =20 - thread =3D kthread_create_on_node(qedi_percpu_io_thread, (void *)p, - cpu_to_node(cpu), - "qedi_thread/%d", cpu); + thread =3D kthread_create_on_cpu(qedi_percpu_io_thread, (void *)p, + cpu, "qedi_thread/%d"); if (IS_ERR(thread)) return PTR_ERR(thread); =20 - kthread_bind(thread, cpu); p->iothread =3D thread; wake_up_process(thread); return 0; --=20 2.46.0 From nobody Thu Nov 28 22:35:54 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 D62D31B14F8 for ; Thu, 26 Sep 2024 22:49:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727390973; cv=none; b=g1q6NMQah5WMxZaLP5xl2Lgj0rDjGiVxqi2QWlf1a2EEJxZC8+N3DFsh36od6kYy3yHWgeQGKcuPIMAXOleXEvn8+zeT7Bd3jGxnKJJTUPKSwWezA67B5TIPLy20n+SsvgaIgskgoCp3QwkzzaqM8hjLTxJ0HmcD9xD6W1ScPtk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727390973; c=relaxed/simple; bh=bRL09e91cC7LQEEs/ysPp5d5gcrpXYKGy36AOC6GrXg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JQfwhCSWLLRszjj2Zk6J/B7RYPBle4mkKfFIQ9eZD3KzpjjJyqxfzTeuKnPdDLN9kfLXUv7gq993z46XRBfU96ZL8MNINa/is5Djnaw0Z7iCwp6/ajWlQyrC3DOVYCVWYRmy8plrUOYq5P8OqY39eNtmvka7B0zDwubXh6L/jNc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jDZdbpy4; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jDZdbpy4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E5459C4CEC5; Thu, 26 Sep 2024 22:49:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727390972; bh=bRL09e91cC7LQEEs/ysPp5d5gcrpXYKGy36AOC6GrXg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jDZdbpy4WqqifeDkegM8x1sVTl+yI6iQ0P8bBrCuvgR1jYI1u6GHF6NzZa0ERvibI cAkhHAH8POAjsMrWv8dUzeYrp7H2lW1xLce+GVcY0pLcxBKiCOZ2QSeSYanU76SraB IZBNevGY31bNGdaOCTyF2PZz+cIa9D1f+oAxxrdyywwWBtq2xFfddeIVVA5tdgy2VB 5VbETBCp8ypSUyBL5sVZzchrOvhIngYb38QGkAPgQs55AXjpxGQybbuhvuMqpZnC3Q xS+tZyEcX27kdmIVc/JQekudFEh4jPBZBZemzhpPuY/XXDC1dD7CiBeQ6fdw/enqkP hUzv6Z71aJMOA== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, Andrew Morton , Peter Zijlstra , Thomas Gleixner Subject: [PATCH 07/20] soc/qman: test: Use kthread_run_on_cpu() Date: Fri, 27 Sep 2024 00:48:55 +0200 Message-ID: <20240926224910.11106-8-frederic@kernel.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240926224910.11106-1-frederic@kernel.org> References: <20240926224910.11106-1-frederic@kernel.org> 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" Use the proper API instead of open coding it. However it looks like kthreads here could be replaced by the use of a per-cpu workqueue instead. Signed-off-by: Frederic Weisbecker --- drivers/soc/fsl/qbman/qman_test_stash.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/soc/fsl/qbman/qman_test_stash.c b/drivers/soc/fsl/qbma= n/qman_test_stash.c index b7e8e5ec884c..f4d3c2146f4f 100644 --- a/drivers/soc/fsl/qbman/qman_test_stash.c +++ b/drivers/soc/fsl/qbman/qman_test_stash.c @@ -108,14 +108,12 @@ static int on_all_cpus(int (*fn)(void)) .fn =3D fn, .started =3D ATOMIC_INIT(0) }; - struct task_struct *k =3D kthread_create(bstrap_fn, &bstrap, - "hotpotato%d", cpu); + struct task_struct *k =3D kthread_run_on_cpu(bstrap_fn, &bstrap, + cpu, "hotpotato%d"); int ret; =20 if (IS_ERR(k)) return -ENOMEM; - kthread_bind(k, cpu); - wake_up_process(k); /* * If we call kthread_stop() before the "wake up" has had an * effect, then the thread may exit with -EINTR without ever --=20 2.46.0 From nobody Thu Nov 28 22:35:54 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 B48A81B1504 for ; Thu, 26 Sep 2024 22:49:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727390974; cv=none; b=D2KyPSgtMa9VkesE4H1TmpYX/d7S6Qv/hhfCINKTAOnX+VfNA2XOXfz53N+lI2QWfqChzsqZv9yvpqgq0thRoXsFUmop4LhrKHP/zxc8s0VrHiDegzXx6CM9iChrl+NK+EtlJHhDK3kXyd/+OQZGT0nb0XDp8KiFrt9YY3DejLw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727390974; c=relaxed/simple; bh=SrPlU9tOI0Lf76otTW5ESwvT98+pgbNcqxervWYqjX4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=raskwDAb+jjK4DpT8nr59+/1zEN+KTerC/Li3YIE5UJXs6jYDBXmvpbdWmCpuoSMZBU9j0h+JN1hNgAOBVh1xFj8JRqJM/NIReOHH0lqz3QyAAlWxnpiWiwaf8TwI0GATUVxkKjZPerQ2blCPcwgvni6jxGMj3pnfBr8d3NUSAs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HELp0UUq; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HELp0UUq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7D61C4CECE; Thu, 26 Sep 2024 22:49:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727390974; bh=SrPlU9tOI0Lf76otTW5ESwvT98+pgbNcqxervWYqjX4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HELp0UUqg1+FQIIMC0NR8Sf8pG2tPjbxeayOqS91nDq2E7TQIkUS9lOo0UNjoQ3DY iicgTnusuLGJtBQzmbCpt/OJFRGDEV0B23+K9jLrKvIU0dw58ANXoxiL9UGnKe9MK3 NQyx+spJlki9pUEpF/Ledwcxwdc2pOfwgZC0BgDnARyunvHOk/eSiHLIhK3usGS9wO AlRuODGu2bkfkeEzIUK2E4XDsb6kkX529sXHLn5HVWCH+lII/OnQ9FqYXDX1Fh2RRw 2KnVvhxMnjI27mUDo/4pZWvSoAwYRXm1dSwiHRwB7XmMY4H9RvhEvcX6d9Ob8rY94B vofw81gFSaUoQ== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Kees Cook , Andrew Morton , Peter Zijlstra , Thomas Gleixner Subject: [PATCH 08/20] kallsyms: Use kthread_run_on_cpu() Date: Fri, 27 Sep 2024 00:48:56 +0200 Message-ID: <20240926224910.11106-9-frederic@kernel.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240926224910.11106-1-frederic@kernel.org> References: <20240926224910.11106-1-frederic@kernel.org> 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" Use the proper API instead of open coding it. Signed-off-by: Frederic Weisbecker --- kernel/kallsyms_selftest.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/kernel/kallsyms_selftest.c b/kernel/kallsyms_selftest.c index 873f7c445488..cf4af5728307 100644 --- a/kernel/kallsyms_selftest.c +++ b/kernel/kallsyms_selftest.c @@ -435,13 +435,11 @@ static int __init kallsyms_test_init(void) { struct task_struct *t; =20 - t =3D kthread_create(test_entry, NULL, "kallsyms_test"); + t =3D kthread_run_on_cpu(test_entry, NULL, 0, "kallsyms_test"); if (IS_ERR(t)) { pr_info("Create kallsyms selftest task failed\n"); return PTR_ERR(t); } - kthread_bind(t, 0); - wake_up_process(t); =20 return 0; } --=20 2.46.0 From nobody Thu Nov 28 22:35:54 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 3AC6A1B1D48 for ; Thu, 26 Sep 2024 22:49:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727390976; cv=none; b=ImezHW/MFpv9N5lajqXDUJxkF7A+pxqz4sUwkVDN4aB6nuVGzJHOrpvyfUB+34D0Huw6gI092kd2wYF9FlTE6/evKrgxCe66CYsGIB+6udGdeooenBi8e1xSwNZ3slPd0L03r8Y+iEn/7r0ZkbBnJiK9hU4MEpzuKVAuV1VReDA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727390976; c=relaxed/simple; bh=4bqmk1ZZmgmxj/TbraN0t20xxY3kUbWb7QrpoxYbtKU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WggLMQQstH05zx9VkAhK3xMwEcE/LdgmrfFdbpfrE20jcpeXS7r7FoEnEz4uBmr2DpTd13bbVqbVF/pLkFAnQD73FYHduqFLW/eTAvvXbABQ+ULwvvwJUO2TKKbtDlhyES6t+SB5y+Go3TKvYaYkDD5L3btWBy/2qUv0hcgMmEg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eqm67Wlf; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="eqm67Wlf" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B1EC6C4CEC9; Thu, 26 Sep 2024 22:49:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727390976; bh=4bqmk1ZZmgmxj/TbraN0t20xxY3kUbWb7QrpoxYbtKU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eqm67Wlfpj1a9q4r0rWiUQ6VNI3pdYtXYeZ1kPUWdNeC1J8QYSvzi4AKIm/+BjkEs 9yvi726EVpGamoBVIerKWT36P/KWqXGpCBXmSOkQXituuteR4taQOKs+T9CZ+H31jp 3kN+t/H3AL+S50VnN5Ir6Ca7E52QJxYCMkUg4qjZoslAldtuXJYDG5dLzpE1kjKSnG RaHtNGDbB9H9Ad9h1fADQUWhIgwwAQSzmzwZiZPwUD63bnWxeRrvj38RfTLr6GG9MW R1sqH4yME6Jt397thewUtldFusSBa7PZ6Ll1JgxtHP20Ti2S55bnKsGs6PVqmOz5im 9YX5SpDRPu6FQ== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Matt Wu , Andrew Morton , Peter Zijlstra , Thomas Gleixner Subject: [PATCH 09/20] lib: test_objpool: Use kthread_run_on_cpu() Date: Fri, 27 Sep 2024 00:48:57 +0200 Message-ID: <20240926224910.11106-10-frederic@kernel.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240926224910.11106-1-frederic@kernel.org> References: <20240926224910.11106-1-frederic@kernel.org> 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" Use the proper API instead of open coding it. Reviewed-by: Matt Wu Signed-off-by: Frederic Weisbecker --- lib/test_objpool.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/lib/test_objpool.c b/lib/test_objpool.c index 5a3f6961a70f..896c0131c9a8 100644 --- a/lib/test_objpool.c +++ b/lib/test_objpool.c @@ -371,14 +371,10 @@ static int ot_start_sync(struct ot_test *test) if (!cpu_online(cpu)) continue; =20 - work =3D kthread_create_on_node(ot_thread_worker, item, - cpu_to_node(cpu), "ot_worker_%d", cpu); - if (IS_ERR(work)) { + work =3D kthread_run_on_cpu(ot_thread_worker, item, + cpu, "ot_worker_%d"); + if (IS_ERR(work)) pr_err("failed to create thread for cpu %d\n", cpu); - } else { - kthread_bind(work, cpu); - wake_up_process(work); - } } =20 /* wait a while to make sure all threads waiting at start line */ @@ -562,14 +558,9 @@ static int ot_start_async(struct ot_test *test) if (!cpu_online(cpu)) continue; =20 - work =3D kthread_create_on_node(ot_thread_worker, item, - cpu_to_node(cpu), "ot_worker_%d", cpu); - if (IS_ERR(work)) { + work =3D kthread_run_on_cpu(ot_thread_worker, item, cpu, "ot_worker_%d"); + if (IS_ERR(work)) pr_err("failed to create thread for cpu %d\n", cpu); - } else { - kthread_bind(work, cpu); - wake_up_process(work); - } } =20 /* wait a while to make sure all threads waiting at start line */ --=20 2.46.0 From nobody Thu Nov 28 22:35:54 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 6786C1B1D7B for ; Thu, 26 Sep 2024 22:49:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727390978; cv=none; b=Wnpb7cwdgN52ekrNqR7nBf9rTFpDbljzyLUye/OpbiANCm/60/huM14NwBGdGsLGo21JyEnziF/qI4Y+A5JXcs3QOrTY1xtnFbjxsu23yX3vS9OmFYGvdzemo1d7ASFjPsruZes7QDBfFIgU8STO31czrOIFCLIDhiQVB/nyk6k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727390978; c=relaxed/simple; bh=gUr/DwSlgazKo3bDvjslR9a806r1mqijOu77KKoOn+4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aiUogZ3LpGy9S1upQqG7ydKe1dD/p29fX4EUuGu+feduV0vGEmoMB9ikeeCknwNqaF9QAzry5+3ZXU3JI/bVjAMeZ4tcwGrEkTwewV6OB3edzSsEO8SfD3hTkO1ULs3naHckD/ndEoTSqTRGJ5BMh1gwai15gVxJLZfhfPEAYXw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PI0uI4kM; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PI0uI4kM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 76B1FC4CEC5; Thu, 26 Sep 2024 22:49:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727390978; bh=gUr/DwSlgazKo3bDvjslR9a806r1mqijOu77KKoOn+4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PI0uI4kME+DTI8MIVSdNq38EBh3qQ9TTcYVDw0KXx3n4nL25xmce6HsrwNwdw9OCL aLgS5keF+hY4D96b7UQkcg/Rvsj/+9h9jei+GivK3vskF9Lf50mS66/C2xHHzhunAM uPdqkbLimEipNPnlVnNjtPrzXosDJBfl5t6JjvdJ24MKVGg0aiCZ0swPFfXUKAN5oS sutl4UKqQ6wOJNKxm6yibHyi4z1Pdamj38pO5+HNORfjnYBJtzJqgOcmbu6lCr7iDC /dOCEiiQDQ/F+AFgGgpq1ZLG1bmSSW17sZt8wmESR1J5lHAPpNJ/gwrAaQmQlawUlY UunnRHaSsfqow== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Morton , Peter Zijlstra , Thomas Gleixner Subject: [PATCH 10/20] net: pktgen: Use kthread_create_on_node() Date: Fri, 27 Sep 2024 00:48:58 +0200 Message-ID: <20240926224910.11106-11-frederic@kernel.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240926224910.11106-1-frederic@kernel.org> References: <20240926224910.11106-1-frederic@kernel.org> 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" Use the proper API instead of open coding it. Signed-off-by: Frederic Weisbecker Reviewed-by: Eric Dumazet --- net/core/pktgen.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/net/core/pktgen.c b/net/core/pktgen.c index 34f68ef74b8f..7fcb4fc7a5d6 100644 --- a/net/core/pktgen.c +++ b/net/core/pktgen.c @@ -3883,17 +3883,14 @@ static int __net_init pktgen_create_thread(int cpu,= struct pktgen_net *pn) list_add_tail(&t->th_list, &pn->pktgen_threads); init_completion(&t->start_done); =20 - p =3D kthread_create_on_node(pktgen_thread_worker, - t, - cpu_to_node(cpu), - "kpktgend_%d", cpu); + p =3D kthread_create_on_cpu(pktgen_thread_worker, t, cpu, "kpktgend_%d"); if (IS_ERR(p)) { pr_err("kthread_create_on_node() failed for cpu %d\n", t->cpu); list_del(&t->th_list); kfree(t); return PTR_ERR(p); } - kthread_bind(p, cpu); + t->tsk =3D p; =20 pe =3D proc_create_data(t->tsk->comm, 0600, pn->proc_dir, --=20 2.46.0 From nobody Thu Nov 28 22:35:54 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 C3CD61B2523; Thu, 26 Sep 2024 22:49:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727390981; cv=none; b=U1Xyydh3vnqgKlKQnHQGW7puOM2Rx1QGy0P6W0q1FK+XtFEvcjBycTXlBZ9wW48vBCbzzuBjVkJ9Ln7W2t0WV2dayCq9lnMF7TBfJmAkNZxB0AfFnPeGrXw0wFoaZNgdfNzSeQI/RtoAy7Qy7ng/l0epFwo9QVPYlBHkC70YWF8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727390981; c=relaxed/simple; bh=92oEHSM6E5QZI86HEze8W34mCNCuSP+gt4f24shWjnc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GyzA6gM8n3Z/t+Zd1X6/bzYE/vXeOcd68Ranw6k8Zmc674QKsI8Ls6fIQhK4o5mq8vtRLja95KWZhwojNL94JSmNSI8NBz+ZwV4tKiI5hnf+mmYWOLrdGrFqYzOvflmHBgFP+NwUPdDLoKInOliFdngf/yc+EOrOpJW5lUFfMJc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OFOzyMhs; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OFOzyMhs" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A699EC4CEC9; Thu, 26 Sep 2024 22:49:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727390981; bh=92oEHSM6E5QZI86HEze8W34mCNCuSP+gt4f24shWjnc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OFOzyMhsolEevHbP5JheK/yJ2si1BnSND7B0gJHO4BQ729HVM9s9J1QexXf9Uh+En bi8R19DQalwlsOGmVSKSZAkwf/sdUTNZ0Fr/CPppxA4QVcFCtcldRMgFfMWjNxbGkm zCaXGzb3Ne+x7Ltl7pDAhty21/NSJ4KZrbPaQlaXMMJ7LbodhDfiOtxAl44i/N+j1H R7cVtGRSDj6cSzB6j9J7LuZwfO3VDbO1k+PIg4/C5K3/JeogOODGuKTAmJA7Q78AU6 yh8S2+6wUdxDoBUlLpUKtZp8gE0yHnmuHsFEbUMvHR/zBF6c2B+31Y6J8ZA+xDQEJ+ jtF9W8+zKlpGg== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Will Deacon , Peter Zijlstra , Vincent Guittot , Thomas Gleixner , Michal Hocko , Vlastimil Babka , "Paul E. McKenney" , Neeraj Upadhyay , Joel Fernandes , Boqun Feng , Zqiang , Uladzislau Rezki , rcu@vger.kernel.org, Michal Hocko Subject: [PATCH 11/20] sched: Handle CPU isolation on last resort fallback rq selection Date: Fri, 27 Sep 2024 00:48:59 +0200 Message-ID: <20240926224910.11106-12-frederic@kernel.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240926224910.11106-1-frederic@kernel.org> References: <20240926224910.11106-1-frederic@kernel.org> 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" When a kthread or any other task has an affinity mask that is fully offline or unallowed, the scheduler reaffines the task to all possible CPUs as a last resort. This default decision doesn't mix up very well with nohz_full CPUs that are part of the possible cpumask but don't want to be disturbed by unbound kthreads or even detached pinned user tasks. Make the fallback affinity setting aware of nohz_full. This applies to all architectures supporting nohz_full except arm32. However this architecture that overrides the task possible mask is unlikely to be willing to integrate new development. Suggested-by: Michal Hocko Signed-off-by: Frederic Weisbecker --- kernel/sched/core.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 43e453ab7e20..d4b759c1cbf1 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -3421,6 +3421,21 @@ void kick_process(struct task_struct *p) } EXPORT_SYMBOL_GPL(kick_process); =20 +static const struct cpumask *task_cpu_fallback_mask(struct task_struct *t) +{ + const struct cpumask *mask; + + mask =3D task_cpu_possible_mask(p); + /* + * Architectures that overrides the task possible mask + * must handle CPU isolation. + */ + if (mask !=3D cpu_possible_mask) + return mask; + else + return housekeeping_cpumask(HK_TYPE_TICK); +} + /* * ->cpus_ptr is protected by both rq->lock and p->pi_lock * @@ -3489,7 +3504,7 @@ static int select_fallback_rq(int cpu, struct task_st= ruct *p) * * More yuck to audit. */ - do_set_cpus_allowed(p, task_cpu_possible_mask(p)); + do_set_cpus_allowed(p, task_cpu_fallback_mask(p)); state =3D fail; break; case fail: --=20 2.46.0 From nobody Thu Nov 28 22:35:54 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 CDB681B29A8; Thu, 26 Sep 2024 22:49:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727390985; cv=none; b=qXBpLTWZjsluDtnYzBlZJVV+s0U9DneO9hKX0uw1i2r4yCAQ1OY//Jmfhk7YYoCA83lz2fw9jMfBtheqMgMFkPTsg7pqgupM7H3N0mGF4tWGO55ZmHUU5BP7ejsDgeoAIGod9CKCBMNXys7bsWrhOhrrkbaeSj5UDWef2k8Qxtg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727390985; c=relaxed/simple; bh=OmLFF6xgwbA0hM9UsQOF4k2zgh/bcASGVcZgCAmI/wE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WV2HmF3chBd5bVr9wKLAcGxp3F9mvkN9g3AoQuVucfaF5whkM7+lhPar5WBQw3Sg6YJ9l4HEZvIkMVzKZfDOZr2cZLAGbxQRO5fzXsj2eu9jz4WNYbubGCfVogSlzKwtgayWQPUh9twNECQJfUZXxme2cQahLRpGrxR8m5DHMVQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TZybb+rL; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TZybb+rL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 14BFEC4CECE; Thu, 26 Sep 2024 22:49:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727390985; bh=OmLFF6xgwbA0hM9UsQOF4k2zgh/bcASGVcZgCAmI/wE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TZybb+rLGew6y4q8nSczjj8DHRzJC7OPnSggLAYdW0ADMoiewKcozZLiLAW5sPq4b z/w7b2NScoCYFn5Y/Vu1k0LnkOv267r9y6sguOW4Nv2aO4I7KXAEGOqyeRdLQChUMM 4cTaoClZ1K67txUjJeVPMY4Il+eDer2maAH5KqQoz0Z9Yw9rGHdsmUmNnXCXQE0T10 MCioZOjqH18cVl7ms8sVxuKS31EpXnLgg1Dlb0+4pwj9q3OZxhffnGHGs/ou8q3fwC YN471CMyZJ3Ua5hJe27BPWBvBRj3fkTtvgx7DdcqZcLHY6H98mFfFSQVAxEosOWDlo CNXTOM4e0Ln8Q== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Andrew Morton , Kees Cook , Peter Zijlstra , Thomas Gleixner , Michal Hocko , Vlastimil Babka , linux-mm@kvack.org, "Paul E. McKenney" , Neeraj Upadhyay , Joel Fernandes , Boqun Feng , Zqiang , rcu@vger.kernel.org, Uladzislau Rezki Subject: [PATCH 12/20] kthread: Make sure kthread hasn't started while binding it Date: Fri, 27 Sep 2024 00:49:00 +0200 Message-ID: <20240926224910.11106-13-frederic@kernel.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240926224910.11106-1-frederic@kernel.org> References: <20240926224910.11106-1-frederic@kernel.org> 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" Make sure the kthread is sleeping in the schedule_preempt_disabled() call before calling its handler when kthread_bind[_mask]() is called on it. This provides a sanity check verifying that the task is not randomly blocked later at some point within its function handler, in which case it could be just concurrently awaken, leaving the call to do_set_cpus_allowed() without any effect until the next voluntary sleep. Rely on the wake-up ordering to ensure that the newly introduced "started" field returns the expected value: TASK A TASK B ------ ------ READ kthread->started wake_up_process(B) rq_lock() ... rq_unlock() // RELEASE schedule() rq_lock() // ACQUIRE // schedule task B rq_unlock() WRITE kthread->started Similarly, writing kthread->started before subsequent voluntary sleeps will be visible after calling wait_task_inactive() in __kthread_bind_mask(), reporting potential misuse of the API. Upcoming patches will make further use of this facility. Acked-by: Vlastimil Babka Signed-off-by: Frederic Weisbecker --- kernel/kthread.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kernel/kthread.c b/kernel/kthread.c index db4ceb0f503c..1527a522cdd3 100644 --- a/kernel/kthread.c +++ b/kernel/kthread.c @@ -53,6 +53,7 @@ struct kthread_create_info struct kthread { unsigned long flags; unsigned int cpu; + int started; int result; int (*threadfn)(void *); void *data; @@ -382,6 +383,8 @@ static int kthread(void *_create) schedule_preempt_disabled(); preempt_enable(); =20 + self->started =3D 1; + ret =3D -EINTR; if (!test_bit(KTHREAD_SHOULD_STOP, &self->flags)) { cgroup_kthread_ready(); @@ -540,7 +543,9 @@ static void __kthread_bind(struct task_struct *p, unsig= ned int cpu, unsigned int =20 void kthread_bind_mask(struct task_struct *p, const struct cpumask *mask) { + struct kthread *kthread =3D to_kthread(p); __kthread_bind_mask(p, mask, TASK_UNINTERRUPTIBLE); + WARN_ON_ONCE(kthread->started); } =20 /** @@ -554,7 +559,9 @@ void kthread_bind_mask(struct task_struct *p, const str= uct cpumask *mask) */ void kthread_bind(struct task_struct *p, unsigned int cpu) { + struct kthread *kthread =3D to_kthread(p); __kthread_bind(p, cpu, TASK_UNINTERRUPTIBLE); + WARN_ON_ONCE(kthread->started); } EXPORT_SYMBOL(kthread_bind); =20 --=20 2.46.0 From nobody Thu Nov 28 22:35:54 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 093011B0113; Thu, 26 Sep 2024 22:49:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727390989; cv=none; b=S+Vcpu57A9yGer8aF7DEyZjy7wfi9t/NtFEr21uUoPy48h9nSf/+ESRgem1zyHsFQI/u0WPZ794YHBKwSkzLwA0AMJRkFVhM6EMvlXE5PKUEdtDHZ0INSLfGmKjw0L9oSecJaXO/BDt8RM5KKUjsCPbu5S0xrIKJtCnldOtULLQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727390989; c=relaxed/simple; bh=bE1OM/op4+e/YyAtntgPKGkBQ7JAfe3Vd2i3n+7WjN8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L19qrHtoty7OX88/amCd4jPK0EAZNxgWyxR0exHE8o/yNRVrMZx2cKZWZxa0znZe3A6H7RABMBNOtMJiSeNFi0gcOe5IXshECp+YHBVT8BPxD0jwGCvcNdPMh5lR8zM1xfscYC4jj74tbE/b/3OIdzYkfbpKKBolq7kG1Ht0o3E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lyeZP9PW; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lyeZP9PW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B97D7C4CECF; Thu, 26 Sep 2024 22:49:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727390988; bh=bE1OM/op4+e/YyAtntgPKGkBQ7JAfe3Vd2i3n+7WjN8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lyeZP9PWK4kodAkIS7yTyNhlbSAraYXy5xoRG+4jGTQgHQpPMG/SpnI8qwYvYWXHN 2n5SVdMmIQKyc28FIyY6jAWXZSFbIDk6s3gnVQeBr0LRLKKQlX9IM9vojf/i73iQqD CfCm3C+5NVgQBGW+P/HXiSTEfAolKpVXHCSG1YKaW1j4jcoJQOX3jab5KUWQOAmqUA CDsPW6j8jql2Dz6xVR+fFUfQx3zOCu0yD4gRCsNFASNmCFinYbw3AUOYceXe10QK0l fA7mxZEWvX0uj8fKH8Sz+UHIWEgZI1Vlifl6t85IucnruBVsouNjrOEnm0aK52cFE0 lwZINyZQN4z5w== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Andrew Morton , Kees Cook , Peter Zijlstra , Thomas Gleixner , Michal Hocko , Vlastimil Babka , linux-mm@kvack.org, "Paul E. McKenney" , Neeraj Upadhyay , Joel Fernandes , Boqun Feng , Uladzislau Rezki , Zqiang , rcu@vger.kernel.org Subject: [PATCH 13/20] kthread: Default affine kthread to its preferred NUMA node Date: Fri, 27 Sep 2024 00:49:01 +0200 Message-ID: <20240926224910.11106-14-frederic@kernel.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240926224910.11106-1-frederic@kernel.org> References: <20240926224910.11106-1-frederic@kernel.org> 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" Kthreads attached to a preferred NUMA node for their task structure allocation can also be assumed to run preferrably within that same node. A more precise affinity is usually notified by calling kthread_create_on_cpu() or kthread_bind[_mask]() before the first wakeup. For the others, a default affinity to the node is desired and sometimes implemented with more or less success when it comes to deal with hotplug events and nohz_full / CPU Isolation interactions: - kcompactd is affine to its node and handles hotplug but not CPU Isolation - kswapd is affine to its node and ignores hotplug and CPU Isolation - A bunch of drivers create their kthreads on a specific node and don't take care about affining further. Handle that default node affinity preference at the generic level instead, provided a kthread is created on an actual node and doesn't apply any specific affinity such as a given CPU or a custom cpumask to bind to before its first wake-up. This generic handling is aware of CPU hotplug events and CPU isolation such that: * When a housekeeping CPU goes up that is part of the node of a given kthread, the related task is re-affined to that own node if it was previously running on the default last resort online housekeeping set from other nodes. * When a housekeeping CPU goes down while it was part of the node of a kthread, the running task is migrated (or the sleeping task is woken up) automatically by the scheduler to other housekeepers within the same node or, as a last resort, to all housekeepers from other nodes. Acked-by: Vlastimil Babka Signed-off-by: Frederic Weisbecker --- include/linux/cpuhotplug.h | 1 + kernel/kthread.c | 106 ++++++++++++++++++++++++++++++++++++- 2 files changed, 106 insertions(+), 1 deletion(-) diff --git a/include/linux/cpuhotplug.h b/include/linux/cpuhotplug.h index 2361ed4d2b15..228f27150a93 100644 --- a/include/linux/cpuhotplug.h +++ b/include/linux/cpuhotplug.h @@ -239,6 +239,7 @@ enum cpuhp_state { CPUHP_AP_WORKQUEUE_ONLINE, CPUHP_AP_RANDOM_ONLINE, CPUHP_AP_RCUTREE_ONLINE, + CPUHP_AP_KTHREADS_ONLINE, CPUHP_AP_BASE_CACHEINFO_ONLINE, CPUHP_AP_ONLINE_DYN, CPUHP_AP_ONLINE_DYN_END =3D CPUHP_AP_ONLINE_DYN + 40, diff --git a/kernel/kthread.c b/kernel/kthread.c index 1527a522cdd3..736276d313c2 100644 --- a/kernel/kthread.c +++ b/kernel/kthread.c @@ -35,6 +35,9 @@ static DEFINE_SPINLOCK(kthread_create_lock); static LIST_HEAD(kthread_create_list); struct task_struct *kthreadd_task; =20 +static LIST_HEAD(kthreads_hotplug); +static DEFINE_MUTEX(kthreads_hotplug_lock); + struct kthread_create_info { /* Information passed to kthread() from kthreadd. */ @@ -53,6 +56,7 @@ struct kthread_create_info struct kthread { unsigned long flags; unsigned int cpu; + unsigned int node; int started; int result; int (*threadfn)(void *); @@ -64,6 +68,8 @@ struct kthread { #endif /* To store the full name if task comm is truncated. */ char *full_name; + struct task_struct *task; + struct list_head hotplug_node; }; =20 enum KTHREAD_BITS { @@ -122,8 +128,11 @@ bool set_kthread_struct(struct task_struct *p) =20 init_completion(&kthread->exited); init_completion(&kthread->parked); + INIT_LIST_HEAD(&kthread->hotplug_node); p->vfork_done =3D &kthread->exited; =20 + kthread->task =3D p; + kthread->node =3D tsk_fork_get_node(current); p->worker_private =3D kthread; return true; } @@ -314,6 +323,11 @@ void __noreturn kthread_exit(long result) { struct kthread *kthread =3D to_kthread(current); kthread->result =3D result; + if (!list_empty(&kthread->hotplug_node)) { + mutex_lock(&kthreads_hotplug_lock); + list_del(&kthread->hotplug_node); + mutex_unlock(&kthreads_hotplug_lock); + } do_exit(0); } EXPORT_SYMBOL(kthread_exit); @@ -339,6 +353,48 @@ void __noreturn kthread_complete_and_exit(struct compl= etion *comp, long code) } EXPORT_SYMBOL(kthread_complete_and_exit); =20 +static void kthread_fetch_affinity(struct kthread *kthread, struct cpumask= *cpumask) +{ + cpumask_and(cpumask, cpumask_of_node(kthread->node), + housekeeping_cpumask(HK_TYPE_KTHREAD)); + + if (cpumask_empty(cpumask)) + cpumask_copy(cpumask, housekeeping_cpumask(HK_TYPE_KTHREAD)); +} + +static void kthread_affine_node(void) +{ + struct kthread *kthread =3D to_kthread(current); + cpumask_var_t affinity; + + WARN_ON_ONCE(kthread_is_per_cpu(current)); + + if (kthread->node =3D=3D NUMA_NO_NODE) { + housekeeping_affine(current, HK_TYPE_RCU); + } else { + if (!zalloc_cpumask_var(&affinity, GFP_KERNEL)) { + WARN_ON_ONCE(1); + return; + } + + mutex_lock(&kthreads_hotplug_lock); + WARN_ON_ONCE(!list_empty(&kthread->hotplug_node)); + list_add_tail(&kthread->hotplug_node, &kthreads_hotplug); + /* + * The node cpumask is racy when read from kthread() but: + * - a racing CPU going down will either fail on the subsequent + * call to set_cpus_allowed_ptr() or be migrated to housekeepers + * afterwards by the scheduler. + * - a racing CPU going up will be handled by kthreads_online_cpu() + */ + kthread_fetch_affinity(kthread, affinity); + set_cpus_allowed_ptr(current, affinity); + mutex_unlock(&kthreads_hotplug_lock); + + free_cpumask_var(affinity); + } +} + static int kthread(void *_create) { static const struct sched_param param =3D { .sched_priority =3D 0 }; @@ -369,7 +425,6 @@ static int kthread(void *_create) * back to default in case they have been changed. */ sched_setscheduler_nocheck(current, SCHED_NORMAL, ¶m); - set_cpus_allowed_ptr(current, housekeeping_cpumask(HK_TYPE_KTHREAD)); =20 /* OK, tell user we're spawned, wait for stop or wakeup */ __set_current_state(TASK_UNINTERRUPTIBLE); @@ -385,6 +440,9 @@ static int kthread(void *_create) =20 self->started =3D 1; =20 + if (!(current->flags & PF_NO_SETAFFINITY)) + kthread_affine_node(); + ret =3D -EINTR; if (!test_bit(KTHREAD_SHOULD_STOP, &self->flags)) { cgroup_kthread_ready(); @@ -779,6 +837,52 @@ int kthreadd(void *unused) return 0; } =20 +/* + * Re-affine kthreads according to their preferences + * and the newly online CPU. The CPU down part is handled + * by select_fallback_rq() which default re-affines to + * housekeepers in case the preferred affinity doesn't + * apply anymore. + */ +static int kthreads_online_cpu(unsigned int cpu) +{ + cpumask_var_t affinity; + struct kthread *k; + int ret; + + guard(mutex)(&kthreads_hotplug_lock); + + if (list_empty(&kthreads_hotplug)) + return 0; + + if (!zalloc_cpumask_var(&affinity, GFP_KERNEL)) + return -ENOMEM; + + ret =3D 0; + + list_for_each_entry(k, &kthreads_hotplug, hotplug_node) { + if (WARN_ON_ONCE((k->task->flags & PF_NO_SETAFFINITY) || + kthread_is_per_cpu(k->task) || + k->node =3D=3D NUMA_NO_NODE)) { + ret =3D -EINVAL; + continue; + } + kthread_fetch_affinity(k, affinity); + set_cpus_allowed_ptr(k->task, affinity); + } + + free_cpumask_var(affinity); + + return ret; +} + +static int kthreads_init(void) +{ + return cpuhp_setup_state(CPUHP_AP_KTHREADS_ONLINE, "kthreads:online", + kthreads_online_cpu, NULL); +} +early_initcall(kthreads_init); + void __kthread_init_worker(struct kthread_worker *worker, const char *name, struct lock_class_key *key) --=20 2.46.0 From nobody Thu Nov 28 22:35:54 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 95D691B012A for ; Thu, 26 Sep 2024 22:49:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727390991; cv=none; b=gYGjZYuplyBGFGB/nQvW3hlBnfLalfpvsNYKiasOM9pbASHlL131d+1KkcopWhP7E1DVlM8Rv4XMoRkN47GzfnUUaAjyfyAUacqmFEl+dVBTwkIGerCvQvG6odLW4NP/l2l16ZVYhlevSCB87l1gsJhMsq/+TXrI8zb/SbdwCYU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727390991; c=relaxed/simple; bh=7BtrEplH3qQrg9kZixHgQN9470zkhnd7tdHddmuV+9U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NPctabkuGWUFG6gNZDf3lmOh0+dHWAf/hYo0H03YDFEvhhmvERq2MtbQ5TnEy/UNZJaz74Cu2K9/yYBXgnq30uyKOkqkNsEuhof0AX5qGLAw45FBhPcjRkptMFwlHGRaGleuT3XhwqFbrNKmyaEgsD7EzVCwv2bLwgZu4gngsa8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=psM8YQFN; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="psM8YQFN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F665C4CED0; Thu, 26 Sep 2024 22:49:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727390991; bh=7BtrEplH3qQrg9kZixHgQN9470zkhnd7tdHddmuV+9U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=psM8YQFN5mZ3FzBukGKWEToWhZzCosyMS0j5KLWvaT8kWVGcT5tEVHkD15uycwmmo tJ1LttkAxj4ZweWz/08s7Kgrwh2kGdoUVn4gLfJeqPwS+NB/xmOBSSQswp/UECwOIh ImitrWdjMszxOjTusfjUOiF5fXo5SsImb1ftjw8izmEPoA7IYlRPXVL1aPmEFgkVha uz9CHu3SywKw1F3hqctu0GEWLSFVSBAT7sCkOes64A/1ubJODn4AmG897NX7CnsoNf 6WWjkBU5HcTp5GdJ+RK/iH5GUuE618/1yJujZ9W5ZMCLOA21ySARoJat1rQNAlhCN2 tJrXoHP8jA27g== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Michal Hocko , Vlastimil Babka , Andrew Morton , linux-mm@kvack.org, Peter Zijlstra , Thomas Gleixner , Michal Hocko Subject: [PATCH 14/20] mm: Create/affine kcompactd to its preferred node Date: Fri, 27 Sep 2024 00:49:02 +0200 Message-ID: <20240926224910.11106-15-frederic@kernel.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240926224910.11106-1-frederic@kernel.org> References: <20240926224910.11106-1-frederic@kernel.org> 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" Kcompactd is dedicated to a specific node. As such it wants to be preferrably affine to it, memory and CPUs-wise. Use the proper kthread API to achieve that. As a bonus it takes care of CPU-hotplug events and CPU-isolation on its behalf. Acked-by: Vlastimil Babka Acked-by: Michal Hocko Signed-off-by: Frederic Weisbecker --- mm/compaction.c | 43 +++---------------------------------------- 1 file changed, 3 insertions(+), 40 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index a2b16b08cbbf..a31c0f5758cf 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -3154,15 +3154,9 @@ void wakeup_kcompactd(pg_data_t *pgdat, int order, i= nt highest_zoneidx) static int kcompactd(void *p) { pg_data_t *pgdat =3D (pg_data_t *)p; - struct task_struct *tsk =3D current; long default_timeout =3D msecs_to_jiffies(HPAGE_FRAG_CHECK_INTERVAL_MSEC); long timeout =3D default_timeout; =20 - const struct cpumask *cpumask =3D cpumask_of_node(pgdat->node_id); - - if (!cpumask_empty(cpumask)) - set_cpus_allowed_ptr(tsk, cpumask); - set_freezable(); =20 pgdat->kcompactd_max_order =3D 0; @@ -3233,10 +3227,12 @@ void __meminit kcompactd_run(int nid) if (pgdat->kcompactd) return; =20 - pgdat->kcompactd =3D kthread_run(kcompactd, pgdat, "kcompactd%d", nid); + pgdat->kcompactd =3D kthread_create_on_node(kcompactd, pgdat, nid, "kcomp= actd%d", nid); if (IS_ERR(pgdat->kcompactd)) { pr_err("Failed to start kcompactd on node %d\n", nid); pgdat->kcompactd =3D NULL; + } else { + wake_up_process(pgdat->kcompactd); } } =20 @@ -3254,30 +3250,6 @@ void __meminit kcompactd_stop(int nid) } } =20 -/* - * It's optimal to keep kcompactd on the same CPUs as their memory, but - * not required for correctness. So if the last cpu in a node goes - * away, we get changed to run anywhere: as the first one comes back, - * restore their cpu bindings. - */ -static int kcompactd_cpu_online(unsigned int cpu) -{ - int nid; - - for_each_node_state(nid, N_MEMORY) { - pg_data_t *pgdat =3D NODE_DATA(nid); - const struct cpumask *mask; - - mask =3D cpumask_of_node(pgdat->node_id); - - if (cpumask_any_and(cpu_online_mask, mask) < nr_cpu_ids) - /* One of our CPUs online: restore mask */ - if (pgdat->kcompactd) - set_cpus_allowed_ptr(pgdat->kcompactd, mask); - } - return 0; -} - static int proc_dointvec_minmax_warn_RT_change(const struct ctl_table *tab= le, int write, void *buffer, size_t *lenp, loff_t *ppos) { @@ -3337,15 +3309,6 @@ static struct ctl_table vm_compaction[] =3D { static int __init kcompactd_init(void) { int nid; - int ret; - - ret =3D cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, - "mm/compaction:online", - kcompactd_cpu_online, NULL); - if (ret < 0) { - pr_err("kcompactd: failed to register hotplug callbacks.\n"); - return ret; - } =20 for_each_node_state(nid, N_MEMORY) kcompactd_run(nid); --=20 2.46.0 From nobody Thu Nov 28 22:35:54 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 77D571B07A4 for ; Thu, 26 Sep 2024 22:49:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727390993; cv=none; b=EpWm+8+BNgi7LOqFdUdtbixlE4ckjmYWxb2eadEicKJLBfKr0/ikWPAIT2JwZ9iu5uYE5N5sIZGktq/B/ZhD7hsoIGARqOCNm2VWIHOSKrcm/zb/wfMLouLw0wigW2MGObPBL7BLtG3Hy5SEyev7I5Z0dCok341zIxn1K+NCKmI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727390993; c=relaxed/simple; bh=GGwHDTPCelnTuLQKmOHE+XEiEGRzn3nDzNLPlrg5wLQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TF3XKiVuj7CKtd1Z89L6c/FJECApN/GmCz5RcdTqF50pxXrACXLMtV2OFLhulcrlsEPS8eBPUvsygpsorZ1cT3Rozi1mfkYatLi1f56cFPAGZ0OR000mrn4Yy79MQKGcdvPuejEtStoAEvpQw9WO6YOkev+N3aTUuxY3UyKEiis= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qPdT/czz; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qPdT/czz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85329C4CECE; Thu, 26 Sep 2024 22:49:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727390993; bh=GGwHDTPCelnTuLQKmOHE+XEiEGRzn3nDzNLPlrg5wLQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qPdT/czzAUkVt9taXAsYs8HYqiPAzFsD1PahFMGeLLa7p2XkOjqAGBmtuWIxHHZzI L73JueO4kixmDYeWu4a8O6Hn0pH8EOVcPCTshEGMwt/hCvhT5sU0By3wHdlwzQxZeg iJQwSFGkPH8DB3lu63k2EugRuJGZ1VPzYDgoxy+UIi4yJzBy0vF7kxHNXBsdPjwhgf kgXfavf0yn90bg42dxvHuz0QrUskQDnr4er73zhZEdFiHbE93hnfsomY8jIU0clpCq dnEuS0e4bCA/Mg/ntuju71is5DUonzaMun23oaFLmCDFNQiEx7M05CYRWIWd2qVizV vL26k62znYIuQ== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Michal Hocko , Vlastimil Babka , linux-mm@kvack.org, Andrew Morton , Peter Zijlstra , Thomas Gleixner , Michal Hocko Subject: [PATCH 15/20] mm: Create/affine kswapd to its preferred node Date: Fri, 27 Sep 2024 00:49:03 +0200 Message-ID: <20240926224910.11106-16-frederic@kernel.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240926224910.11106-1-frederic@kernel.org> References: <20240926224910.11106-1-frederic@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable kswapd is dedicated to a specific node. As such it wants to be preferrably affine to it, memory and CPUs-wise. Use the proper kthread API to achieve that. As a bonus it takes care of CPU-hotplug events and CPU-isolation on its behalf. Acked-by: Vlastimil Babka Acked-by: Michal Hocko Signed-off-by: Frederic Weisbecker --- mm/vmscan.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 749cdc110c74..2f2b75536d9c 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -7162,10 +7162,6 @@ static int kswapd(void *p) unsigned int highest_zoneidx =3D MAX_NR_ZONES - 1; pg_data_t *pgdat =3D (pg_data_t *)p; struct task_struct *tsk =3D current; - const struct cpumask *cpumask =3D cpumask_of_node(pgdat->node_id); - - if (!cpumask_empty(cpumask)) - set_cpus_allowed_ptr(tsk, cpumask); =20 /* * Tell the memory management that we're a "memory allocator", @@ -7334,13 +7330,15 @@ void __meminit kswapd_run(int nid) =20 pgdat_kswapd_lock(pgdat); if (!pgdat->kswapd) { - pgdat->kswapd =3D kthread_run(kswapd, pgdat, "kswapd%d", nid); + pgdat->kswapd =3D kthread_create_on_node(kswapd, pgdat, nid, "kswapd%d",= nid); if (IS_ERR(pgdat->kswapd)) { /* failure at boot is fatal */ pr_err("Failed to start kswapd on node %d=EF=BC=8Cret=3D%ld\n", nid, PTR_ERR(pgdat->kswapd)); BUG_ON(system_state < SYSTEM_RUNNING); pgdat->kswapd =3D NULL; + } else { + wake_up_process(pgdat->kswapd); } } pgdat_kswapd_unlock(pgdat); --=20 2.46.0 From nobody Thu Nov 28 22:35:55 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 39A471B2536; Thu, 26 Sep 2024 22:49:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727390997; cv=none; b=d7eOX6ha8z4LTfzjhEWJ9lf6dB1r7vQSWeqGAAeCfMgRwYDLR8exPJp0bhe7IdKTdZc3pVWSGHVB3RGOWCb0QdRRLqmJghacTyrv3bAsE1pjp0fqazQDgpuGms667CTreUrxtlqtqgVq6D+mCD7KEP50pRv+BWp+KAlbd45etKQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727390997; c=relaxed/simple; bh=m1Tcj1zEK+qAK6ToFK+B33y3KL3pudrwFEmXyRTSR20=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SFznQOQ5ngElsRGvCOjrlanV92hb7QO1WqiczLzVlXziwLiyqB2h0xgW62vMOnSKEse+u/1yf/gjFuQISuRKs6inQJZYPX/fQwO2faKgZRIJu39xUY4dTssLCV0RmQLGVAc1r+Qt/khgaS4qTY2xHBqa5+OFfcsklMcJQjdQxNI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iWWKYk8L; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iWWKYk8L" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D5996C4CED1; Thu, 26 Sep 2024 22:49:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727390997; bh=m1Tcj1zEK+qAK6ToFK+B33y3KL3pudrwFEmXyRTSR20=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iWWKYk8L61abF7LxWDWRGHMgy+nOKnnunvJUW6jJ41wneZPY/6lNIfMOqSed6R/gW jYrTjTIZIFOLj5S9/D62bKvAsDKJlVPJ2WzeTRs1NDsf+swIeolOnOhhlyqYZwrjg8 C3/ohAwI76aHXOJp2XqCIN+THlWHkX+Dtjz2+LU4B7XMIRnGUgqj7s9Brak89HhBCs XLWJeiAf4oZhQIlBTJ63ZQvlf9wr3Mos+fhlYgs/hiXgr1bxJwGQ87/eZuQ290s0yE 6biSgYOA3Bmkgv2xZ+CrpL2IyvqvrMNfjI8hKSfgjFL8+HhCyyLz68L7TfR8fcZFpO 4sV4ZR3ULcjMQ== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Andrew Morton , Kees Cook , Peter Zijlstra , Thomas Gleixner , Michal Hocko , Vlastimil Babka , linux-mm@kvack.org, "Paul E. McKenney" , Neeraj Upadhyay , Joel Fernandes , Boqun Feng , Uladzislau Rezki , Zqiang , rcu@vger.kernel.org Subject: [PATCH 16/20] kthread: Implement preferred affinity Date: Fri, 27 Sep 2024 00:49:04 +0200 Message-ID: <20240926224910.11106-17-frederic@kernel.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240926224910.11106-1-frederic@kernel.org> References: <20240926224910.11106-1-frederic@kernel.org> 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" Affining kthreads follow either of four existing different patterns: 1) Per-CPU kthreads must stay affine to a single CPU and never execute relevant code on any other CPU. This is currently handled by smpboot code which takes care of CPU-hotplug operations. 2) Kthreads that _have_ to be affine to a specific set of CPUs and can't run anywhere else. The affinity is set through kthread_bind_mask() and the subsystem takes care by itself to handle CPU-hotplug operations. 3) Kthreads that prefer to be affine to a specific NUMA node. That preferred affinity is applied by default when an actual node ID is passed on kthread creation, provided the kthread is not per-CPU and no call to kthread_bind_mask() has been issued before the first wake-up. 4) Similar to the previous point but kthreads have a preferred affinity different than a node. It is set manually like any other task and CPU-hotplug is supposed to be handled by the relevant subsystem so that the task is properly reaffined whenever a given CPU from the preferred affinity comes up. Also care must be taken so that the preferred affinity doesn't cross housekeeping cpumask boundaries. Provide a function to handle the last usecase, mostly reusing the current node default affinity infrastructure. kthread_affine_preferred() is introduced, to be used just like kthread_bind_mask(), right after kthread creation and before the first wake up. The kthread is then affine right away to the cpumask passed through the API if it has online housekeeping CPUs. Otherwise it will be affine to all online housekeeping CPUs as a last resort. As with node affinity, it is aware of CPU hotplug events such that: * When a housekeeping CPU goes up that is part of the preferred affinity of a given kthread, the related task is re-affined to that preferred affinity if it was previously running on the default last resort online housekeeping set. * When a housekeeping CPU goes down while it was part of the preferred affinity of a kthread, the running task is migrated (or the sleeping task is woken up) automatically by the scheduler to other housekeepers within the preferred affinity or, as a last resort, to all housekeepers from other nodes. Acked-by: Vlastimil Babka Signed-off-by: Frederic Weisbecker --- include/linux/kthread.h | 1 + kernel/kthread.c | 68 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 62 insertions(+), 7 deletions(-) diff --git a/include/linux/kthread.h b/include/linux/kthread.h index b11f53c1ba2e..30209bdf83a2 100644 --- a/include/linux/kthread.h +++ b/include/linux/kthread.h @@ -85,6 +85,7 @@ kthread_run_on_cpu(int (*threadfn)(void *data), void *dat= a, void free_kthread_struct(struct task_struct *k); void kthread_bind(struct task_struct *k, unsigned int cpu); void kthread_bind_mask(struct task_struct *k, const struct cpumask *mask); +int kthread_affine_preferred(struct task_struct *p, const struct cpumask *= mask); int kthread_stop(struct task_struct *k); int kthread_stop_put(struct task_struct *k); bool kthread_should_stop(void); diff --git a/kernel/kthread.c b/kernel/kthread.c index 736276d313c2..91037533afda 100644 --- a/kernel/kthread.c +++ b/kernel/kthread.c @@ -70,6 +70,7 @@ struct kthread { char *full_name; struct task_struct *task; struct list_head hotplug_node; + struct cpumask *preferred_affinity; }; =20 enum KTHREAD_BITS { @@ -327,6 +328,11 @@ void __noreturn kthread_exit(long result) mutex_lock(&kthreads_hotplug_lock); list_del(&kthread->hotplug_node); mutex_unlock(&kthreads_hotplug_lock); + + if (kthread->preferred_affinity) { + kfree(kthread->preferred_affinity); + kthread->preferred_affinity =3D NULL; + } } do_exit(0); } @@ -355,9 +361,17 @@ EXPORT_SYMBOL(kthread_complete_and_exit); =20 static void kthread_fetch_affinity(struct kthread *kthread, struct cpumask= *cpumask) { - cpumask_and(cpumask, cpumask_of_node(kthread->node), - housekeeping_cpumask(HK_TYPE_KTHREAD)); + const struct cpumask *pref; =20 + if (kthread->preferred_affinity) { + pref =3D kthread->preferred_affinity; + } else { + if (WARN_ON_ONCE(kthread->node =3D=3D NUMA_NO_NODE)) + return; + pref =3D cpumask_of_node(kthread->node); + } + + cpumask_and(cpumask, pref, housekeeping_cpumask(HK_TYPE_KTHREAD)); if (cpumask_empty(cpumask)) cpumask_copy(cpumask, housekeeping_cpumask(HK_TYPE_KTHREAD)); } @@ -440,7 +454,7 @@ static int kthread(void *_create) =20 self->started =3D 1; =20 - if (!(current->flags & PF_NO_SETAFFINITY)) + if (!(current->flags & PF_NO_SETAFFINITY) && !self->preferred_affinity) kthread_affine_node(); =20 ret =3D -EINTR; @@ -837,12 +851,53 @@ int kthreadd(void *unused) return 0; } =20 +int kthread_affine_preferred(struct task_struct *p, const struct cpumask *= mask) +{ + struct kthread *kthread =3D to_kthread(p); + cpumask_var_t affinity; + unsigned long flags; + int ret; + + if (!wait_task_inactive(p, TASK_UNINTERRUPTIBLE) || kthread->started) { + WARN_ON(1); + return -EINVAL; + } + + WARN_ON_ONCE(kthread->preferred_affinity); + + if (!zalloc_cpumask_var(&affinity, GFP_KERNEL)) + return -ENOMEM; + + kthread->preferred_affinity =3D kzalloc(sizeof(struct cpumask), GFP_KERNE= L); + if (!kthread->preferred_affinity) { + ret =3D -ENOMEM; + goto out; + } + + mutex_lock(&kthreads_hotplug_lock); + cpumask_copy(kthread->preferred_affinity, mask); + WARN_ON_ONCE(!list_empty(&kthread->hotplug_node)); + list_add_tail(&kthread->hotplug_node, &kthreads_hotplug); + kthread_fetch_affinity(kthread, affinity); + + /* It's safe because the task is inactive. */ + raw_spin_lock_irqsave(&p->pi_lock, flags); + do_set_cpus_allowed(p, affinity); + raw_spin_unlock_irqrestore(&p->pi_lock, flags); + + mutex_unlock(&kthreads_hotplug_lock); +out: + free_cpumask_var(affinity); + + return 0; +} + /* * Re-affine kthreads according to their preferences * and the newly online CPU. The CPU down part is handled * by select_fallback_rq() which default re-affines to - * housekeepers in case the preferred affinity doesn't - * apply anymore. + * housekeepers from other nodes in case the preferred + * affinity doesn't apply anymore. */ static int kthreads_online_cpu(unsigned int cpu) { @@ -862,8 +917,7 @@ static int kthreads_online_cpu(unsigned int cpu) =20 list_for_each_entry(k, &kthreads_hotplug, hotplug_node) { if (WARN_ON_ONCE((k->task->flags & PF_NO_SETAFFINITY) || - kthread_is_per_cpu(k->task) || - k->node =3D=3D NUMA_NO_NODE)) { + kthread_is_per_cpu(k->task))) { ret =3D -EINVAL; continue; } --=20 2.46.0 From nobody Thu Nov 28 22:35:55 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 80D001B29C9; Thu, 26 Sep 2024 22:50:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727391000; cv=none; b=KZrgkC9+Aqqm8HI8KXPM1uppVOSiaNa6QFoP8055+7HWIkxV5OrXUFcsnO8gQhOMlseYF1OU3pXK5a8WYP4QCdhQmHg6mZsZHqGrRxnoxLz8A8hj9JHPoNICfQc5EeRmdjkZsjnO1Sicp8aMweybjEfoF8AjCbr/YVRkQNQduXo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727391000; c=relaxed/simple; bh=+P4kzizCeNOj1Ff6ZQgJUmeNr/qO1N9UQodOY09ijkk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A6uSieDb1d3IYwuhG8+CiDIiK3SuveyzkyZ0DC35HBcdxd9kpck3wyXa0SHCB2P3sro5wcvA2B5m+hQbae3/H9K4DbG808wET9dESYW7JovMnXDUV9axXK6ECFX9hKng5NFEo3yT0g38qTGwNQoVEx69SU9jdD6DvDbv1tT9i2M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PtxSAIGX; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PtxSAIGX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7DFA1C4CECE; Thu, 26 Sep 2024 22:49:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727391000; bh=+P4kzizCeNOj1Ff6ZQgJUmeNr/qO1N9UQodOY09ijkk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PtxSAIGXraxeSEcnRb5c6or1mDuRelDxeTl4uTsmPJoNX4SkfcLp8zfw6DI3U6IKo hGeCb0rW4cmP1twq+Q/Ux7r7kQ0c+3/feiQC/OFLvPd5+mPm44hnrWQpUEi8QAo2HN /AeZndBE6GOjR0iiD3XUIS4vvlr2Byt76Pi3DYp/LK1n/HKBKlFBZLyIVDhhYE25Mq 3uAyq78eTTKQ20XvaHSoz0+r7uc7qqhTighQfrX9aQgV7QWXOIO9K+FycdA466YzZY 1p5v51Na8Y6gMtVNn1HfNWfQLDlkNSi2OI/oAz7bcxdGDDVD2djD6m1wCqTBSno0yx 8rauYfzaiZfxw== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , "Paul E. McKenney" , Uladzislau Rezki , Neeraj Upadhyay , Joel Fernandes , Boqun Feng , Zqiang , rcu@vger.kernel.org, Andrew Morton , Peter Zijlstra , Thomas Gleixner , Michal Hocko , Vlastimil Babka Subject: [PATCH 17/20] rcu: Use kthread preferred affinity for RCU boost Date: Fri, 27 Sep 2024 00:49:05 +0200 Message-ID: <20240926224910.11106-18-frederic@kernel.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240926224910.11106-1-frederic@kernel.org> References: <20240926224910.11106-1-frederic@kernel.org> 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" Now that kthreads have an infrastructure to handle preferred affinity against CPU hotplug and housekeeping cpumask, convert RCU boost to use it instead of handling all the constraints by itself. Acked-by: Paul E. McKenney Signed-off-by: Frederic Weisbecker --- kernel/rcu/tree.c | 27 +++++++++++++++++++-------- kernel/rcu/tree_plugin.h | 11 ++--------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index a60616e69b66..c1e9f0818d51 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -149,7 +149,6 @@ static int rcu_scheduler_fully_active __read_mostly; =20 static void rcu_report_qs_rnp(unsigned long mask, struct rcu_node *rnp, unsigned long gps, unsigned long flags); -static struct task_struct *rcu_boost_task(struct rcu_node *rnp); static void invoke_rcu_core(void); static void rcu_report_exp_rdp(struct rcu_data *rdp); static void sync_sched_exp_online_cleanup(int cpu); @@ -5007,6 +5006,22 @@ int rcutree_prepare_cpu(unsigned int cpu) return 0; } =20 +static void rcu_thread_affine_rnp(struct task_struct *t, struct rcu_node *= rnp) +{ + cpumask_var_t affinity; + int cpu; + + if (!zalloc_cpumask_var(&affinity, GFP_KERNEL)) + return; + + for_each_leaf_node_possible_cpu(rnp, cpu) + cpumask_set_cpu(cpu, affinity); + + kthread_affine_preferred(t, affinity); + + free_cpumask_var(affinity); +} + /* * Update kthreads affinity during CPU-hotplug changes. * @@ -5026,19 +5041,18 @@ static void rcutree_affinity_setting(unsigned int c= pu, int outgoingcpu) unsigned long mask; struct rcu_data *rdp; struct rcu_node *rnp; - struct task_struct *task_boost, *task_exp; + struct task_struct *task_exp; =20 rdp =3D per_cpu_ptr(&rcu_data, cpu); rnp =3D rdp->mynode; =20 - task_boost =3D rcu_boost_task(rnp); task_exp =3D rcu_exp_par_gp_task(rnp); =20 /* - * If CPU is the boot one, those tasks are created later from early + * If CPU is the boot one, this task is created later from early * initcall since kthreadd must be created first. */ - if (!task_boost && !task_exp) + if (!task_exp) return; =20 if (!zalloc_cpumask_var(&cm, GFP_KERNEL)) @@ -5060,9 +5074,6 @@ static void rcutree_affinity_setting(unsigned int cpu= , int outgoingcpu) if (task_exp) set_cpus_allowed_ptr(task_exp, cm); =20 - if (task_boost) - set_cpus_allowed_ptr(task_boost, cm); - mutex_unlock(&rnp->kthread_mutex); =20 free_cpumask_var(cm); diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h index 1c7cbd145d5e..223f3a02351e 100644 --- a/kernel/rcu/tree_plugin.h +++ b/kernel/rcu/tree_plugin.h @@ -1217,16 +1217,13 @@ static void rcu_spawn_one_boost_kthread(struct rcu_= node *rnp) raw_spin_lock_irqsave_rcu_node(rnp, flags); rnp->boost_kthread_task =3D t; raw_spin_unlock_irqrestore_rcu_node(rnp, flags); + sp.sched_priority =3D kthread_prio; sched_setscheduler_nocheck(t, SCHED_FIFO, &sp); + rcu_thread_affine_rnp(t, rnp); wake_up_process(t); /* get to TASK_INTERRUPTIBLE quickly. */ } =20 -static struct task_struct *rcu_boost_task(struct rcu_node *rnp) -{ - return READ_ONCE(rnp->boost_kthread_task); -} - #else /* #ifdef CONFIG_RCU_BOOST */ =20 static void rcu_initiate_boost(struct rcu_node *rnp, unsigned long flags) @@ -1243,10 +1240,6 @@ static void rcu_spawn_one_boost_kthread(struct rcu_n= ode *rnp) { } =20 -static struct task_struct *rcu_boost_task(struct rcu_node *rnp) -{ - return NULL; -} #endif /* #else #ifdef CONFIG_RCU_BOOST */ =20 /* --=20 2.46.0 From nobody Thu Nov 28 22:35:55 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 48C0C1B2ED5; Thu, 26 Sep 2024 22:50:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727391004; cv=none; b=V1HSns4nv+aKi5D88YbMLq5pfpGdkoRrlaeVAeKYp/HTQ0kFOYZKeNHvzWmhzlYR3B2gwNpPp7StD3k8AqoSoba1PsgXJiVrOulGr2d0hcI9j7ee6o4TO31VvHWizVONBJ/I3IKlFYbQlnldDvEIZMAOv2vgy6wWpLknBiDGxeQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727391004; c=relaxed/simple; bh=RXq2bB5DoKDocGNG0/VP6/WISAYwDUKtYUPfrdT95y8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=W0k2A74Wi3EAm3/lZ/dUopum98uEKgeVnMlGWS6ui95aJryD86ebKYR0Xy+GzqYj7NJoYHFRYG3s7utfJ7fL9lfHooHiyywfukVMTVSDhWmcvRGNG2EPg+OkbAnAeWYWScW06MEw0hZgEfwiB601/N1jxkFiijs6/HJ5FRa2j6g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Nk66THNm; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Nk66THNm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C46B0C4CECD; Thu, 26 Sep 2024 22:50:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727391003; bh=RXq2bB5DoKDocGNG0/VP6/WISAYwDUKtYUPfrdT95y8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Nk66THNmmU+VDDA3GP1MyvDe+1U8iGLogZB0wDqe/pxeeQE/+1zYgSiSbt2AUL0a5 NnrTKUiDQKCDmAv4ov6gdJ7ytxKbWjS3TBpPbiq6mNFiAhYaDCYtOoJBfKew3Rl8UQ KpNYpoI4csBN/96OnUoPg4xn2VWT4U948ICe2PI03/as8peDnD6vQZ7Dtgxt5RYu5Q Rex9d0Ix6en9/8BAgs6aOOyj2t1YZ418z7NFSUyGWxKD0qB91NXQYQ0EEqwrW/ahUS PtDnM7hl1SlXLgA1P/+qlRLLtj0JrCuysiMfx9nkLhyeYt2CWuVNqsyIGXUudd+XoS +BZWAB9p8GyUg== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , "Paul E. McKenney" , Uladzislau Rezki , Neeraj Upadhyay , Joel Fernandes , Boqun Feng , Zqiang , rcu@vger.kernel.org, Andrew Morton , Peter Zijlstra , Thomas Gleixner , Michal Hocko , Vlastimil Babka Subject: [PATCH 18/20] kthread: Unify kthread_create_on_cpu() and kthread_create_worker_on_cpu() automatic format Date: Fri, 27 Sep 2024 00:49:06 +0200 Message-ID: <20240926224910.11106-19-frederic@kernel.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240926224910.11106-1-frederic@kernel.org> References: <20240926224910.11106-1-frederic@kernel.org> 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" kthread_create_on_cpu() uses the CPU argument as an implicit and unique printf argument to add to the format whereas kthread_create_worker_on_cpu() still relies on explicitly passing the printf arguments. This difference in behaviour is error prone and doesn't help standardizing per-CPU kthread names. Unify the behaviours and convert kthread_create_worker_on_cpu() to use the printf behaviour of kthread_create_on_cpu(). Signed-off-by: Frederic Weisbecker --- fs/erofs/zdata.c | 2 +- include/linux/kthread.h | 21 +++++++++++---- kernel/kthread.c | 59 ++++++++++++++++++++++++----------------- 3 files changed, 52 insertions(+), 30 deletions(-) diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index 8936790618c6..050aaa016ec8 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -318,7 +318,7 @@ static void erofs_destroy_percpu_workers(void) static struct kthread_worker *erofs_init_percpu_worker(int cpu) { struct kthread_worker *worker =3D - kthread_create_worker_on_cpu(cpu, 0, "erofs_worker/%u", cpu); + kthread_create_worker_on_cpu(cpu, 0, "erofs_worker/%u"); =20 if (IS_ERR(worker)) return worker; diff --git a/include/linux/kthread.h b/include/linux/kthread.h index 30209bdf83a2..0c66e7c1092a 100644 --- a/include/linux/kthread.h +++ b/include/linux/kthread.h @@ -187,13 +187,24 @@ extern void __kthread_init_worker(struct kthread_work= er *worker, =20 int kthread_worker_fn(void *worker_ptr); =20 -__printf(2, 3) +__printf(3, 4) +struct kthread_worker *kthread_create_worker_on_node(unsigned int flags, + int node, + const char namefmt[], ...); + +#define kthread_create_worker(flags, namefmt, ...) \ +({ \ + struct kthread_worker *__kw \ + =3D kthread_create_worker_on_node(flags, NUMA_NO_NODE, \ + namefmt, ## __VA_ARGS__); \ + if (!IS_ERR(__kw)) \ + wake_up_process(__kw->task); \ + __kw; \ +}) + struct kthread_worker * -kthread_create_worker(unsigned int flags, const char namefmt[], ...); - -__printf(3, 4) struct kthread_worker * kthread_create_worker_on_cpu(int cpu, unsigned int flags, - const char namefmt[], ...); + const char namefmt[]); =20 bool kthread_queue_work(struct kthread_worker *worker, struct kthread_work *work); diff --git a/kernel/kthread.c b/kernel/kthread.c index 91037533afda..7eb93c248c59 100644 --- a/kernel/kthread.c +++ b/kernel/kthread.c @@ -1028,12 +1028,11 @@ int kthread_worker_fn(void *worker_ptr) EXPORT_SYMBOL_GPL(kthread_worker_fn); =20 static __printf(3, 0) struct kthread_worker * -__kthread_create_worker(int cpu, unsigned int flags, - const char namefmt[], va_list args) +__kthread_create_worker_on_node(unsigned int flags, int node, + const char namefmt[], va_list args) { struct kthread_worker *worker; struct task_struct *task; - int node =3D NUMA_NO_NODE; =20 worker =3D kzalloc(sizeof(*worker), GFP_KERNEL); if (!worker) @@ -1041,20 +1040,14 @@ __kthread_create_worker(int cpu, unsigned int flags, =20 kthread_init_worker(worker); =20 - if (cpu >=3D 0) - node =3D cpu_to_node(cpu); - task =3D __kthread_create_on_node(kthread_worker_fn, worker, - node, namefmt, args); + node, namefmt, args); if (IS_ERR(task)) goto fail_task; =20 - if (cpu >=3D 0) - kthread_bind(task, cpu); - worker->flags =3D flags; worker->task =3D task; - wake_up_process(task); + return worker; =20 fail_task: @@ -1065,6 +1058,7 @@ __kthread_create_worker(int cpu, unsigned int flags, /** * kthread_create_worker - create a kthread worker * @flags: flags modifying the default behavior of the worker + * @node: task structure for the thread is allocated on this node * @namefmt: printf-style name for the kthread worker (task). * * Returns a pointer to the allocated worker on success, ERR_PTR(-ENOMEM) @@ -1072,25 +1066,49 @@ __kthread_create_worker(int cpu, unsigned int flags, * when the caller was killed by a fatal signal. */ struct kthread_worker * -kthread_create_worker(unsigned int flags, const char namefmt[], ...) +kthread_create_worker_on_node(unsigned int flags, int node, const char nam= efmt[], ...) { struct kthread_worker *worker; va_list args; =20 va_start(args, namefmt); - worker =3D __kthread_create_worker(-1, flags, namefmt, args); + worker =3D __kthread_create_worker_on_node(flags, node, namefmt, args); va_end(args); =20 + if (worker) + wake_up_process(worker->task); + + return worker; +} +EXPORT_SYMBOL(kthread_create_worker_on_node); + +static __printf(3, 4) struct kthread_worker * +__kthread_create_worker_on_cpu(int cpu, unsigned int flags, + const char namefmt[], ...) +{ + struct kthread_worker *worker; + va_list args; + + va_start(args, namefmt); + worker =3D __kthread_create_worker_on_node(flags, cpu_to_node(cpu), + namefmt, args); + va_end(args); + + if (worker) { + kthread_bind(worker->task, cpu); + wake_up_process(worker->task); + } + return worker; } -EXPORT_SYMBOL(kthread_create_worker); =20 /** * kthread_create_worker_on_cpu - create a kthread worker and bind it * to a given CPU and the associated NUMA node. * @cpu: CPU number * @flags: flags modifying the default behavior of the worker - * @namefmt: printf-style name for the kthread worker (task). + * @namefmt: printf-style name for the thread. Format is restricted + * to "name.*%u". Code fills in cpu number. * * Use a valid CPU number if you want to bind the kthread worker * to the given CPU and the associated NUMA node. @@ -1122,16 +1140,9 @@ EXPORT_SYMBOL(kthread_create_worker); */ struct kthread_worker * kthread_create_worker_on_cpu(int cpu, unsigned int flags, - const char namefmt[], ...) + const char namefmt[]) { - struct kthread_worker *worker; - va_list args; - - va_start(args, namefmt); - worker =3D __kthread_create_worker(cpu, flags, namefmt, args); - va_end(args); - - return worker; + return __kthread_create_worker_on_cpu(cpu, flags, namefmt, cpu); } EXPORT_SYMBOL(kthread_create_worker_on_cpu); =20 --=20 2.46.0 From nobody Thu Nov 28 22:35:55 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 7C6FD1B2EF6; Thu, 26 Sep 2024 22:50:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727391007; cv=none; b=AQiQU27/i6uSDfKDhDtpOKkjA10JfB1MngHvnmTIR1uXEuwJHOaDid/u4r43vGFPZNA4XF65ffBkeyvfkGF14gYBoazs1k4vq0tUoAup3YCABB3TGy58UDhSQw7dn/pp3d+pbqozJRch3tXhgg/2JX6Tz6oE6zblY2fHAgFRqzs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727391007; c=relaxed/simple; bh=gbiEmsoL5oIwV/Hij/zvEWwIxGGA6Grm6wu0OWzI9zg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X0euZ0GmuLcw2IpYbx4wvJEGP284BZviptYTL7Nkb+QvDNk7czodyU72hdb4X+Gt8LhnckmmFSASGni4g7twgjc3ZVn2WJXxKCjz6Ieu708NiczjysILaSP30SCjJd1E6txSS5Z60TS0LJCdraFT2OR5pfUDpid4rJiK6Sg2P4M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZFE+Yzme; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZFE+Yzme" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C250C4CED0; Thu, 26 Sep 2024 22:50:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727391007; bh=gbiEmsoL5oIwV/Hij/zvEWwIxGGA6Grm6wu0OWzI9zg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZFE+YzmebD7kQeesRNrbAaA599cGULwfSJEd9ImUAsaNsXiqD3uCvATnwqfzlLNG0 JXRGe5g1mKZ1piB9Ohjiy+g6vsJcfvw7aaNU7ydUNJ4+zqiyJM5BDr6oGcm37eYkLl n8jGwPMk5LEY4f5GLtz8H9fSqWm77iW9mKUFRCcfxSCczdH/5CkQGk2AoZM5qw3sJx EstxYn3d8pdbyYMcOuWn+Q81y4EHZlAMPQvNaJ8lQZCcwLwgXERZteQsmVDZKrdiuV YLqY3EVDReNWPxKKS5uR4Ujkwva93dqe130T1e5IYt+5dSZ2mLZuJeSTH6wgr/WOZp VWssfKto7vZDQ== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , "Paul E. McKenney" , Uladzislau Rezki , Neeraj Upadhyay , Joel Fernandes , Boqun Feng , Zqiang , rcu@vger.kernel.org, Andrew Morton , Peter Zijlstra , Thomas Gleixner , Michal Hocko , Vlastimil Babka Subject: [PATCH 19/20] treewide: Introduce kthread_run_worker[_on_cpu]() Date: Fri, 27 Sep 2024 00:49:07 +0200 Message-ID: <20240926224910.11106-20-frederic@kernel.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240926224910.11106-1-frederic@kernel.org> References: <20240926224910.11106-1-frederic@kernel.org> 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" kthread_create() creates a kthread without running it yet. kthread_run() creates a kthread and runs it. On the other hand, kthread_create_worker() creates a kthread worker and runs it. This difference in behaviours is confusing. Also there is no way to create a kthread worker and affine it using kthread_bind_mask() or kthread_affine_preferred() before starting it. Consolidate the behaviours and introduce kthread_run_worker[_on_cpu]() that behaves just like kthread_run(). kthread_create_worker[_on_cpu]() will now only create a kthread worker without starting it. Signed-off-by: Frederic Weisbecker Acked-by: Paul E. McKenney --- arch/x86/kvm/i8254.c | 2 +- crypto/crypto_engine.c | 2 +- drivers/cpufreq/cppc_cpufreq.c | 2 +- drivers/gpu/drm/drm_vblank_work.c | 2 +- .../drm/i915/gem/selftests/i915_gem_context.c | 2 +- drivers/gpu/drm/i915/gt/selftest_execlists.c | 2 +- drivers/gpu/drm/i915/gt/selftest_hangcheck.c | 2 +- drivers/gpu/drm/i915/gt/selftest_slpc.c | 2 +- drivers/gpu/drm/i915/selftests/i915_request.c | 8 ++-- drivers/gpu/drm/msm/disp/msm_disp_snapshot.c | 2 +- drivers/gpu/drm/msm/msm_atomic.c | 2 +- drivers/gpu/drm/msm/msm_gpu.c | 2 +- drivers/gpu/drm/msm/msm_kms.c | 2 +- .../platform/chips-media/wave5/wave5-vpu.c | 2 +- drivers/net/dsa/mv88e6xxx/chip.c | 2 +- drivers/net/ethernet/intel/ice/ice_dpll.c | 2 +- drivers/net/ethernet/intel/ice/ice_gnss.c | 2 +- drivers/net/ethernet/intel/ice/ice_ptp.c | 2 +- drivers/platform/chrome/cros_ec_spi.c | 2 +- drivers/ptp/ptp_clock.c | 2 +- drivers/spi/spi.c | 2 +- drivers/usb/typec/tcpm/tcpm.c | 2 +- drivers/vdpa/vdpa_sim/vdpa_sim.c | 2 +- drivers/watchdog/watchdog_dev.c | 2 +- fs/erofs/zdata.c | 2 +- include/linux/kthread.h | 48 ++++++++++++++++--- kernel/kthread.c | 31 +++--------- kernel/rcu/tree.c | 4 +- kernel/sched/ext.c | 2 +- kernel/workqueue.c | 2 +- net/dsa/tag_ksz.c | 2 +- net/dsa/tag_ocelot_8021q.c | 2 +- net/dsa/tag_sja1105.c | 2 +- 33 files changed, 83 insertions(+), 66 deletions(-) diff --git a/arch/x86/kvm/i8254.c b/arch/x86/kvm/i8254.c index cd57a517d04a..d7ab8780ab9e 100644 --- a/arch/x86/kvm/i8254.c +++ b/arch/x86/kvm/i8254.c @@ -681,7 +681,7 @@ struct kvm_pit *kvm_create_pit(struct kvm *kvm, u32 fla= gs) pid_nr =3D pid_vnr(pid); put_pid(pid); =20 - pit->worker =3D kthread_create_worker(0, "kvm-pit/%d", pid_nr); + pit->worker =3D kthread_run_worker(0, "kvm-pit/%d", pid_nr); if (IS_ERR(pit->worker)) goto fail_kthread; =20 diff --git a/crypto/crypto_engine.c b/crypto/crypto_engine.c index e60a0eb628e8..c7c16da5e649 100644 --- a/crypto/crypto_engine.c +++ b/crypto/crypto_engine.c @@ -517,7 +517,7 @@ struct crypto_engine *crypto_engine_alloc_init_and_set(= struct device *dev, crypto_init_queue(&engine->queue, qlen); spin_lock_init(&engine->queue_lock); =20 - engine->kworker =3D kthread_create_worker(0, "%s", engine->name); + engine->kworker =3D kthread_run_worker(0, "%s", engine->name); if (IS_ERR(engine->kworker)) { dev_err(dev, "failed to create crypto request pump task\n"); return NULL; diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c index 1a5ad184d28f..9b91cba133c9 100644 --- a/drivers/cpufreq/cppc_cpufreq.c +++ b/drivers/cpufreq/cppc_cpufreq.c @@ -241,7 +241,7 @@ static void __init cppc_freq_invariance_init(void) if (fie_disabled) return; =20 - kworker_fie =3D kthread_create_worker(0, "cppc_fie"); + kworker_fie =3D kthread_run_worker(0, "cppc_fie"); if (IS_ERR(kworker_fie)) { pr_warn("%s: failed to create kworker_fie: %ld\n", __func__, PTR_ERR(kworker_fie)); diff --git a/drivers/gpu/drm/drm_vblank_work.c b/drivers/gpu/drm/drm_vblank= _work.c index 1752ffb44e1d..9cc71120246f 100644 --- a/drivers/gpu/drm/drm_vblank_work.c +++ b/drivers/gpu/drm/drm_vblank_work.c @@ -277,7 +277,7 @@ int drm_vblank_worker_init(struct drm_vblank_crtc *vbla= nk) =20 INIT_LIST_HEAD(&vblank->pending_work); init_waitqueue_head(&vblank->work_wait_queue); - worker =3D kthread_create_worker(0, "card%d-crtc%d", + worker =3D kthread_run_worker(0, "card%d-crtc%d", vblank->dev->primary->index, vblank->pipe); if (IS_ERR(worker)) diff --git a/drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c b/driver= s/gpu/drm/i915/gem/selftests/i915_gem_context.c index 89d4dc8b60c6..eb0158e43417 100644 --- a/drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c +++ b/drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c @@ -369,7 +369,7 @@ static int live_parallel_switch(void *arg) if (!data[n].ce[0]) continue; =20 - worker =3D kthread_create_worker(0, "igt/parallel:%s", + worker =3D kthread_run_worker(0, "igt/parallel:%s", data[n].ce[0]->engine->name); if (IS_ERR(worker)) { err =3D PTR_ERR(worker); diff --git a/drivers/gpu/drm/i915/gt/selftest_execlists.c b/drivers/gpu/drm= /i915/gt/selftest_execlists.c index 222ca7c44951..81c31396eceb 100644 --- a/drivers/gpu/drm/i915/gt/selftest_execlists.c +++ b/drivers/gpu/drm/i915/gt/selftest_execlists.c @@ -3574,7 +3574,7 @@ static int smoke_crescendo(struct preempt_smoke *smok= e, unsigned int flags) arg[id].batch =3D NULL; arg[id].count =3D 0; =20 - worker[id] =3D kthread_create_worker(0, "igt/smoke:%d", id); + worker[id] =3D kthread_run_worker(0, "igt/smoke:%d", id); if (IS_ERR(worker[id])) { err =3D PTR_ERR(worker[id]); break; diff --git a/drivers/gpu/drm/i915/gt/selftest_hangcheck.c b/drivers/gpu/drm= /i915/gt/selftest_hangcheck.c index 9ce8ff1c04fe..9d3aeb237295 100644 --- a/drivers/gpu/drm/i915/gt/selftest_hangcheck.c +++ b/drivers/gpu/drm/i915/gt/selftest_hangcheck.c @@ -1025,7 +1025,7 @@ static int __igt_reset_engines(struct intel_gt *gt, threads[tmp].engine =3D other; threads[tmp].flags =3D flags; =20 - worker =3D kthread_create_worker(0, "igt/%s", + worker =3D kthread_run_worker(0, "igt/%s", other->name); if (IS_ERR(worker)) { err =3D PTR_ERR(worker); diff --git a/drivers/gpu/drm/i915/gt/selftest_slpc.c b/drivers/gpu/drm/i915= /gt/selftest_slpc.c index 4ecc4ae74a54..e218b229681f 100644 --- a/drivers/gpu/drm/i915/gt/selftest_slpc.c +++ b/drivers/gpu/drm/i915/gt/selftest_slpc.c @@ -489,7 +489,7 @@ static int live_slpc_tile_interaction(void *arg) return -ENOMEM; =20 for_each_gt(gt, i915, i) { - threads[i].worker =3D kthread_create_worker(0, "igt/slpc_parallel:%d", g= t->info.id); + threads[i].worker =3D kthread_run_worker(0, "igt/slpc_parallel:%d", gt->= info.id); =20 if (IS_ERR(threads[i].worker)) { ret =3D PTR_ERR(threads[i].worker); diff --git a/drivers/gpu/drm/i915/selftests/i915_request.c b/drivers/gpu/dr= m/i915/selftests/i915_request.c index acae30a04a94..88870844b5bd 100644 --- a/drivers/gpu/drm/i915/selftests/i915_request.c +++ b/drivers/gpu/drm/i915/selftests/i915_request.c @@ -492,7 +492,7 @@ static int mock_breadcrumbs_smoketest(void *arg) for (n =3D 0; n < ncpus; n++) { struct kthread_worker *worker; =20 - worker =3D kthread_create_worker(0, "igt/%d", n); + worker =3D kthread_run_worker(0, "igt/%d", n); if (IS_ERR(worker)) { ret =3D PTR_ERR(worker); ncpus =3D n; @@ -1645,7 +1645,7 @@ static int live_parallel_engines(void *arg) for_each_uabi_engine(engine, i915) { struct kthread_worker *worker; =20 - worker =3D kthread_create_worker(0, "igt/parallel:%s", + worker =3D kthread_run_worker(0, "igt/parallel:%s", engine->name); if (IS_ERR(worker)) { err =3D PTR_ERR(worker); @@ -1806,7 +1806,7 @@ static int live_breadcrumbs_smoketest(void *arg) unsigned int i =3D idx * ncpus + n; struct kthread_worker *worker; =20 - worker =3D kthread_create_worker(0, "igt/%d.%d", idx, n); + worker =3D kthread_run_worker(0, "igt/%d.%d", idx, n); if (IS_ERR(worker)) { ret =3D PTR_ERR(worker); goto out_flush; @@ -3219,7 +3219,7 @@ static int perf_parallel_engines(void *arg) =20 memset(&engines[idx].p, 0, sizeof(engines[idx].p)); =20 - worker =3D kthread_create_worker(0, "igt:%s", + worker =3D kthread_run_worker(0, "igt:%s", engine->name); if (IS_ERR(worker)) { err =3D PTR_ERR(worker); diff --git a/drivers/gpu/drm/msm/disp/msm_disp_snapshot.c b/drivers/gpu/drm= /msm/disp/msm_disp_snapshot.c index e75b97127c0d..2be00b11e557 100644 --- a/drivers/gpu/drm/msm/disp/msm_disp_snapshot.c +++ b/drivers/gpu/drm/msm/disp/msm_disp_snapshot.c @@ -109,7 +109,7 @@ int msm_disp_snapshot_init(struct drm_device *drm_dev) =20 mutex_init(&kms->dump_mutex); =20 - kms->dump_worker =3D kthread_create_worker(0, "%s", "disp_snapshot"); + kms->dump_worker =3D kthread_run_worker(0, "%s", "disp_snapshot"); if (IS_ERR(kms->dump_worker)) DRM_ERROR("failed to create disp state task\n"); =20 diff --git a/drivers/gpu/drm/msm/msm_atomic.c b/drivers/gpu/drm/msm/msm_ato= mic.c index 9c45d641b521..a7a2384044ff 100644 --- a/drivers/gpu/drm/msm/msm_atomic.c +++ b/drivers/gpu/drm/msm/msm_atomic.c @@ -115,7 +115,7 @@ int msm_atomic_init_pending_timer(struct msm_pending_ti= mer *timer, timer->kms =3D kms; timer->crtc_idx =3D crtc_idx; =20 - timer->worker =3D kthread_create_worker(0, "atomic-worker-%d", crtc_idx); + timer->worker =3D kthread_run_worker(0, "atomic-worker-%d", crtc_idx); if (IS_ERR(timer->worker)) { int ret =3D PTR_ERR(timer->worker); timer->worker =3D NULL; diff --git a/drivers/gpu/drm/msm/msm_gpu.c b/drivers/gpu/drm/msm/msm_gpu.c index a274b8466423..15f74e9dfc9e 100644 --- a/drivers/gpu/drm/msm/msm_gpu.c +++ b/drivers/gpu/drm/msm/msm_gpu.c @@ -859,7 +859,7 @@ int msm_gpu_init(struct drm_device *drm, struct platfor= m_device *pdev, gpu->funcs =3D funcs; gpu->name =3D name; =20 - gpu->worker =3D kthread_create_worker(0, "gpu-worker"); + gpu->worker =3D kthread_run_worker(0, "gpu-worker"); if (IS_ERR(gpu->worker)) { ret =3D PTR_ERR(gpu->worker); gpu->worker =3D NULL; diff --git a/drivers/gpu/drm/msm/msm_kms.c b/drivers/gpu/drm/msm/msm_kms.c index af6a6fcb1173..8db9f3afb8ac 100644 --- a/drivers/gpu/drm/msm/msm_kms.c +++ b/drivers/gpu/drm/msm/msm_kms.c @@ -269,7 +269,7 @@ int msm_drm_kms_init(struct device *dev, const struct d= rm_driver *drv) /* initialize event thread */ ev_thread =3D &priv->event_thread[drm_crtc_index(crtc)]; ev_thread->dev =3D ddev; - ev_thread->worker =3D kthread_create_worker(0, "crtc_event:%d", crtc->ba= se.id); + ev_thread->worker =3D kthread_run_worker(0, "crtc_event:%d", crtc->base.= id); if (IS_ERR(ev_thread->worker)) { ret =3D PTR_ERR(ev_thread->worker); DRM_DEV_ERROR(dev, "failed to create crtc_event kthread\n"); diff --git a/drivers/media/platform/chips-media/wave5/wave5-vpu.c b/drivers= /media/platform/chips-media/wave5/wave5-vpu.c index 7273254ecb03..c49f5ed461cf 100644 --- a/drivers/media/platform/chips-media/wave5/wave5-vpu.c +++ b/drivers/media/platform/chips-media/wave5/wave5-vpu.c @@ -231,7 +231,7 @@ static int wave5_vpu_probe(struct platform_device *pdev) dev_err(&pdev->dev, "failed to get irq resource, falling back to polling= \n"); hrtimer_init(&dev->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_PINNED); dev->hrtimer.function =3D &wave5_vpu_timer_callback; - dev->worker =3D kthread_create_worker(0, "vpu_irq_thread"); + dev->worker =3D kthread_run_worker(0, "vpu_irq_thread"); if (IS_ERR(dev->worker)) { dev_err(&pdev->dev, "failed to create vpu irq worker\n"); ret =3D PTR_ERR(dev->worker); diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/c= hip.c index 5b4e2ce5470d..a5908e2ff2cf 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -393,7 +393,7 @@ static int mv88e6xxx_irq_poll_setup(struct mv88e6xxx_ch= ip *chip) kthread_init_delayed_work(&chip->irq_poll_work, mv88e6xxx_irq_poll); =20 - chip->kworker =3D kthread_create_worker(0, "%s", dev_name(chip->dev)); + chip->kworker =3D kthread_run_worker(0, "%s", dev_name(chip->dev)); if (IS_ERR(chip->kworker)) return PTR_ERR(chip->kworker); =20 diff --git a/drivers/net/ethernet/intel/ice/ice_dpll.c b/drivers/net/ethern= et/intel/ice/ice_dpll.c index cd95705d1e7f..1f11a24387f3 100644 --- a/drivers/net/ethernet/intel/ice/ice_dpll.c +++ b/drivers/net/ethernet/intel/ice/ice_dpll.c @@ -2050,7 +2050,7 @@ static int ice_dpll_init_worker(struct ice_pf *pf) struct kthread_worker *kworker; =20 kthread_init_delayed_work(&d->work, ice_dpll_periodic_work); - kworker =3D kthread_create_worker(0, "ice-dplls-%s", + kworker =3D kthread_run_worker(0, "ice-dplls-%s", dev_name(ice_pf_to_dev(pf))); if (IS_ERR(kworker)) return PTR_ERR(kworker); diff --git a/drivers/net/ethernet/intel/ice/ice_gnss.c b/drivers/net/ethern= et/intel/ice/ice_gnss.c index c8ea1af51ad3..fcd1f808b696 100644 --- a/drivers/net/ethernet/intel/ice/ice_gnss.c +++ b/drivers/net/ethernet/intel/ice/ice_gnss.c @@ -182,7 +182,7 @@ static struct gnss_serial *ice_gnss_struct_init(struct = ice_pf *pf) pf->gnss_serial =3D gnss; =20 kthread_init_delayed_work(&gnss->read_work, ice_gnss_read); - kworker =3D kthread_create_worker(0, "ice-gnss-%s", dev_name(dev)); + kworker =3D kthread_run_worker(0, "ice-gnss-%s", dev_name(dev)); if (IS_ERR(kworker)) { kfree(gnss); return NULL; diff --git a/drivers/net/ethernet/intel/ice/ice_ptp.c b/drivers/net/etherne= t/intel/ice/ice_ptp.c index ef2e858f49bb..cd7da48bdf91 100644 --- a/drivers/net/ethernet/intel/ice/ice_ptp.c +++ b/drivers/net/ethernet/intel/ice/ice_ptp.c @@ -3185,7 +3185,7 @@ static int ice_ptp_init_work(struct ice_pf *pf, struc= t ice_ptp *ptp) /* Allocate a kworker for handling work required for the ports * connected to the PTP hardware clock. */ - kworker =3D kthread_create_worker(0, "ice-ptp-%s", + kworker =3D kthread_run_worker(0, "ice-ptp-%s", dev_name(ice_pf_to_dev(pf))); if (IS_ERR(kworker)) return PTR_ERR(kworker); diff --git a/drivers/platform/chrome/cros_ec_spi.c b/drivers/platform/chrom= e/cros_ec_spi.c index 86a3d32a7763..08f566cc1480 100644 --- a/drivers/platform/chrome/cros_ec_spi.c +++ b/drivers/platform/chrome/cros_ec_spi.c @@ -715,7 +715,7 @@ static int cros_ec_spi_devm_high_pri_alloc(struct devic= e *dev, int err; =20 ec_spi->high_pri_worker =3D - kthread_create_worker(0, "cros_ec_spi_high_pri"); + kthread_run_worker(0, "cros_ec_spi_high_pri"); =20 if (IS_ERR(ec_spi->high_pri_worker)) { err =3D PTR_ERR(ec_spi->high_pri_worker); diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c index c56cd0f63909..89a4420972e7 100644 --- a/drivers/ptp/ptp_clock.c +++ b/drivers/ptp/ptp_clock.c @@ -295,7 +295,7 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_i= nfo *info, =20 if (ptp->info->do_aux_work) { kthread_init_delayed_work(&ptp->aux_work, ptp_aux_kworker); - ptp->kworker =3D kthread_create_worker(0, "ptp%d", ptp->index); + ptp->kworker =3D kthread_run_worker(0, "ptp%d", ptp->index); if (IS_ERR(ptp->kworker)) { err =3D PTR_ERR(ptp->kworker); pr_err("failed to create ptp aux_worker %d\n", err); diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index c1dad30a4528..f2f4b6ee25d4 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -2053,7 +2053,7 @@ static int spi_init_queue(struct spi_controller *ctlr) ctlr->busy =3D false; ctlr->queue_empty =3D true; =20 - ctlr->kworker =3D kthread_create_worker(0, dev_name(&ctlr->dev)); + ctlr->kworker =3D kthread_run_worker(0, dev_name(&ctlr->dev)); if (IS_ERR(ctlr->kworker)) { dev_err(&ctlr->dev, "failed to create message pump kworker\n"); return PTR_ERR(ctlr->kworker); diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index fc619478200f..66ae934ad196 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -7577,7 +7577,7 @@ struct tcpm_port *tcpm_register_port(struct device *d= ev, struct tcpc_dev *tcpc) mutex_init(&port->lock); mutex_init(&port->swap_lock); =20 - port->wq =3D kthread_create_worker(0, dev_name(dev)); + port->wq =3D kthread_run_worker(0, dev_name(dev)); if (IS_ERR(port->wq)) return ERR_CAST(port->wq); sched_set_fifo(port->wq->task); diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_= sim.c index 8ffea8430f95..c204fc8e471a 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c @@ -229,7 +229,7 @@ struct vdpasim *vdpasim_create(struct vdpasim_dev_attr = *dev_attr, dev =3D &vdpasim->vdpa.dev; =20 kthread_init_work(&vdpasim->work, vdpasim_work_fn); - vdpasim->worker =3D kthread_create_worker(0, "vDPA sim worker: %s", + vdpasim->worker =3D kthread_run_worker(0, "vDPA sim worker: %s", dev_attr->name); if (IS_ERR(vdpasim->worker)) goto err_iommu; diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_de= v.c index 4190cb800cc4..19698d87dc57 100644 --- a/drivers/watchdog/watchdog_dev.c +++ b/drivers/watchdog/watchdog_dev.c @@ -1229,7 +1229,7 @@ int __init watchdog_dev_init(void) { int err; =20 - watchdog_kworker =3D kthread_create_worker(0, "watchdogd"); + watchdog_kworker =3D kthread_run_worker(0, "watchdogd"); if (IS_ERR(watchdog_kworker)) { pr_err("Failed to create watchdog kworker\n"); return PTR_ERR(watchdog_kworker); diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index 050aaa016ec8..bf6b4d8cb283 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -318,7 +318,7 @@ static void erofs_destroy_percpu_workers(void) static struct kthread_worker *erofs_init_percpu_worker(int cpu) { struct kthread_worker *worker =3D - kthread_create_worker_on_cpu(cpu, 0, "erofs_worker/%u"); + kthread_run_worker_on_cpu(cpu, 0, "erofs_worker/%u"); =20 if (IS_ERR(worker)) return worker; diff --git a/include/linux/kthread.h b/include/linux/kthread.h index 0c66e7c1092a..8d27403888ce 100644 --- a/include/linux/kthread.h +++ b/include/linux/kthread.h @@ -193,19 +193,53 @@ struct kthread_worker *kthread_create_worker_on_node(= unsigned int flags, const char namefmt[], ...); =20 #define kthread_create_worker(flags, namefmt, ...) \ -({ \ - struct kthread_worker *__kw \ - =3D kthread_create_worker_on_node(flags, NUMA_NO_NODE, \ - namefmt, ## __VA_ARGS__); \ - if (!IS_ERR(__kw)) \ - wake_up_process(__kw->task); \ - __kw; \ + kthread_create_worker_on_node(flags, NUMA_NO_NODE, namefmt, ## __VA_ARGS_= _); + +/** + * kthread_run_worker - create and wake a kthread worker. + * @flags: flags modifying the default behavior of the worker + * @namefmt: printf-style name for the thread. + * + * Description: Convenient wrapper for kthread_create_worker() followed by + * wake_up_process(). Returns the kthread_worker or ERR_PTR(-ENOMEM). + */ +#define kthread_run_worker(flags, namefmt, ...) \ +({ \ + struct kthread_worker *__kw \ + =3D kthread_create_worker(flags, namefmt, ## __VA_ARGS__); \ + if (!IS_ERR(__kw)) \ + wake_up_process(__kw->task); \ + __kw; \ }) =20 struct kthread_worker * kthread_create_worker_on_cpu(int cpu, unsigned int flags, const char namefmt[]); =20 +/** + * kthread_run_worker_on_cpu - create and wake a cpu bound kthread worker. + * @cpu: CPU number + * @flags: flags modifying the default behavior of the worker + * @namefmt: printf-style name for the thread. Format is restricted + * to "name.*%u". Code fills in cpu number. + * + * Description: Convenient wrapper for kthread_create_worker_on_cpu() + * followed by wake_up_process(). Returns the kthread_worker or + * ERR_PTR(-ENOMEM). + */ +static inline struct kthread_worker * +kthread_run_worker_on_cpu(int cpu, unsigned int flags, + const char namefmt[]) +{ + struct kthread_worker *kw; + + kw =3D kthread_create_worker_on_cpu(cpu, flags, namefmt); + if (!IS_ERR(kw)) + wake_up_process(kw->task); + + return kw; +} + bool kthread_queue_work(struct kthread_worker *worker, struct kthread_work *work); =20 diff --git a/kernel/kthread.c b/kernel/kthread.c index 7eb93c248c59..d9fee08e9a66 100644 --- a/kernel/kthread.c +++ b/kernel/kthread.c @@ -1075,33 +1075,10 @@ kthread_create_worker_on_node(unsigned int flags, i= nt node, const char namefmt[] worker =3D __kthread_create_worker_on_node(flags, node, namefmt, args); va_end(args); =20 - if (worker) - wake_up_process(worker->task); - return worker; } EXPORT_SYMBOL(kthread_create_worker_on_node); =20 -static __printf(3, 4) struct kthread_worker * -__kthread_create_worker_on_cpu(int cpu, unsigned int flags, - const char namefmt[], ...) -{ - struct kthread_worker *worker; - va_list args; - - va_start(args, namefmt); - worker =3D __kthread_create_worker_on_node(flags, cpu_to_node(cpu), - namefmt, args); - va_end(args); - - if (worker) { - kthread_bind(worker->task, cpu); - wake_up_process(worker->task); - } - - return worker; -} - /** * kthread_create_worker_on_cpu - create a kthread worker and bind it * to a given CPU and the associated NUMA node. @@ -1142,7 +1119,13 @@ struct kthread_worker * kthread_create_worker_on_cpu(int cpu, unsigned int flags, const char namefmt[]) { - return __kthread_create_worker_on_cpu(cpu, flags, namefmt, cpu); + struct kthread_worker *worker; + + worker =3D kthread_create_worker_on_node(flags, cpu_to_node(cpu), namefmt= , cpu); + if (worker) + kthread_bind(worker->task, cpu); + + return worker; } EXPORT_SYMBOL(kthread_create_worker_on_cpu); =20 diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index c1e9f0818d51..a44228b0949a 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -4902,7 +4902,7 @@ static void rcu_spawn_exp_par_gp_kworker(struct rcu_n= ode *rnp) if (rnp->exp_kworker) return; =20 - kworker =3D kthread_create_worker(0, name, rnp_index); + kworker =3D kthread_run_worker(0, name, rnp_index); if (IS_ERR_OR_NULL(kworker)) { pr_err("Failed to create par gp kworker on %d/%d\n", rnp->grplo, rnp->grphi); @@ -4929,7 +4929,7 @@ static void __init rcu_start_exp_gp_kworker(void) const char *name =3D "rcu_exp_gp_kthread_worker"; struct sched_param param =3D { .sched_priority =3D kthread_prio }; =20 - rcu_exp_gp_kworker =3D kthread_create_worker(0, name); + rcu_exp_gp_kworker =3D kthread_run_worker(0, name); if (IS_ERR_OR_NULL(rcu_exp_gp_kworker)) { pr_err("Failed to create %s!\n", name); rcu_exp_gp_kworker =3D NULL; diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c index c09e3dc38c34..4835fa4d9326 100644 --- a/kernel/sched/ext.c +++ b/kernel/sched/ext.c @@ -4885,7 +4885,7 @@ static struct kthread_worker *scx_create_rt_helper(co= nst char *name) { struct kthread_worker *helper; =20 - helper =3D kthread_create_worker(0, name); + helper =3D kthread_run_worker(0, name); if (helper) sched_set_fifo(helper->task); return helper; diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 9949ffad8df0..f5c7447ae1de 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -7814,7 +7814,7 @@ static void __init wq_cpu_intensive_thresh_init(void) unsigned long thresh; unsigned long bogo; =20 - pwq_release_worker =3D kthread_create_worker(0, "pool_workqueue_release"); + pwq_release_worker =3D kthread_run_worker(0, "pool_workqueue_release"); BUG_ON(IS_ERR(pwq_release_worker)); =20 /* if the user set it to a specific value, keep it */ diff --git a/net/dsa/tag_ksz.c b/net/dsa/tag_ksz.c index 281bbac5539d..c33d4bf17929 100644 --- a/net/dsa/tag_ksz.c +++ b/net/dsa/tag_ksz.c @@ -66,7 +66,7 @@ static int ksz_connect(struct dsa_switch *ds) if (!priv) return -ENOMEM; =20 - xmit_worker =3D kthread_create_worker(0, "dsa%d:%d_xmit", + xmit_worker =3D kthread_run_worker(0, "dsa%d:%d_xmit", ds->dst->index, ds->index); if (IS_ERR(xmit_worker)) { ret =3D PTR_ERR(xmit_worker); diff --git a/net/dsa/tag_ocelot_8021q.c b/net/dsa/tag_ocelot_8021q.c index 8e8b1bef6af6..6ce0bc166792 100644 --- a/net/dsa/tag_ocelot_8021q.c +++ b/net/dsa/tag_ocelot_8021q.c @@ -110,7 +110,7 @@ static int ocelot_connect(struct dsa_switch *ds) if (!priv) return -ENOMEM; =20 - priv->xmit_worker =3D kthread_create_worker(0, "felix_xmit"); + priv->xmit_worker =3D kthread_run_worker(0, "felix_xmit"); if (IS_ERR(priv->xmit_worker)) { err =3D PTR_ERR(priv->xmit_worker); kfree(priv); diff --git a/net/dsa/tag_sja1105.c b/net/dsa/tag_sja1105.c index 3e902af7eea6..02adec693811 100644 --- a/net/dsa/tag_sja1105.c +++ b/net/dsa/tag_sja1105.c @@ -707,7 +707,7 @@ static int sja1105_connect(struct dsa_switch *ds) =20 spin_lock_init(&priv->meta_lock); =20 - xmit_worker =3D kthread_create_worker(0, "dsa%d:%d_xmit", + xmit_worker =3D kthread_run_worker(0, "dsa%d:%d_xmit", ds->dst->index, ds->index); if (IS_ERR(xmit_worker)) { err =3D PTR_ERR(xmit_worker); --=20 2.46.0 From nobody Thu Nov 28 22:35:55 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 6B0951B3725; Thu, 26 Sep 2024 22:50:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727391010; cv=none; b=Ji9g3Mtm+10nviW+VjlRN9XCeaqaXyDTXz1ZFyErxOjQCVunUB73WIij7gdxXiYfQaB6Bnfv6FKlgVX5+zvWG/WkfUm6goADqcNh/GV2OEXR1vi3IhvorwpesXMTffmofe6um8FLHtExVnv7Cic2VGbCxnvR+OrkUIEcCUCi5mI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727391010; c=relaxed/simple; bh=HhhGy9lcKYwacFx42C9dv/c41qI/bpaVk8il7/rFSP0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OxJN2YknHdTR7n9Nd029iPpIoQSWBPrUcfmaV/52IwwcH6o5ZHKPaa3VvqYRUfQyu/vYvjNJLWovInyiSQVHK27iqHcTXVN8aQ9McvyzE5xRdbep8s9+/HClFISrqPBX29y52c/j92A+n5VWwqGTEZ2FVc4NAMMojOqMKeBYOwg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZpSrgBYH; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZpSrgBYH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7193BC4CECF; Thu, 26 Sep 2024 22:50:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727391010; bh=HhhGy9lcKYwacFx42C9dv/c41qI/bpaVk8il7/rFSP0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZpSrgBYH+mrXHuAzre0ZglTpX5h6cK+vBuIqQVKelJ4h80/S1PgwtOa3rgHq+dmC0 qkXdmbR82RgmwbwxO5KMxAWV6vXCcWe5afkH9AQwfxYVVf2pppWXzU8bb7OaC+CIty 9/TchZOG+DEp/p/IJvVpGm9Fe35F43uO/VUFwLLO6k+vCUpaPs3tzNa1MOWAanEDfV bWcVxBLv7WLfr7UVkJLWzTKMBMhp4ECJXJkfsJZVQ5kh4FLl0lUhB9rXiLfIwWe+q0 3ZWcBWhrXM6ne0TevxHaqv3JCz0RNLYW/gmiKsMRXnUOKAeqfz6JX9Iq6hFc3BX+e4 gtuiXSaZAHmhg== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , "Paul E. McKenney" , Uladzislau Rezki , Neeraj Upadhyay , Joel Fernandes , Boqun Feng , Zqiang , rcu@vger.kernel.org, Andrew Morton , Peter Zijlstra , Thomas Gleixner , Michal Hocko , Vlastimil Babka Subject: [PATCH 20/20] rcu: Use kthread preferred affinity for RCU exp kworkers Date: Fri, 27 Sep 2024 00:49:08 +0200 Message-ID: <20240926224910.11106-21-frederic@kernel.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240926224910.11106-1-frederic@kernel.org> References: <20240926224910.11106-1-frederic@kernel.org> 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" Now that kthreads have an infrastructure to handle preferred affinity against CPU hotplug and housekeeping cpumask, convert RCU exp workers to use it instead of handling all the constraints by itself. Acked-by: Paul E. McKenney Signed-off-by: Frederic Weisbecker --- kernel/rcu/tree.c | 105 +++++++++------------------------------------- 1 file changed, 19 insertions(+), 86 deletions(-) diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index a44228b0949a..d377a162c56c 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -4890,6 +4890,22 @@ rcu_boot_init_percpu_data(int cpu) rcu_boot_init_nocb_percpu_data(rdp); } =20 +static void rcu_thread_affine_rnp(struct task_struct *t, struct rcu_node *= rnp) +{ + cpumask_var_t affinity; + int cpu; + + if (!zalloc_cpumask_var(&affinity, GFP_KERNEL)) + return; + + for_each_leaf_node_possible_cpu(rnp, cpu) + cpumask_set_cpu(cpu, affinity); + + kthread_affine_preferred(t, affinity); + + free_cpumask_var(affinity); +} + struct kthread_worker *rcu_exp_gp_kworker; =20 static void rcu_spawn_exp_par_gp_kworker(struct rcu_node *rnp) @@ -4902,7 +4918,7 @@ static void rcu_spawn_exp_par_gp_kworker(struct rcu_n= ode *rnp) if (rnp->exp_kworker) return; =20 - kworker =3D kthread_run_worker(0, name, rnp_index); + kworker =3D kthread_create_worker(0, name, rnp_index); if (IS_ERR_OR_NULL(kworker)) { pr_err("Failed to create par gp kworker on %d/%d\n", rnp->grplo, rnp->grphi); @@ -4912,16 +4928,9 @@ static void rcu_spawn_exp_par_gp_kworker(struct rcu_= node *rnp) =20 if (IS_ENABLED(CONFIG_RCU_EXP_KTHREAD)) sched_setscheduler_nocheck(kworker->task, SCHED_FIFO, ¶m); -} =20 -static struct task_struct *rcu_exp_par_gp_task(struct rcu_node *rnp) -{ - struct kthread_worker *kworker =3D READ_ONCE(rnp->exp_kworker); - - if (!kworker) - return NULL; - - return kworker->task; + rcu_thread_affine_rnp(kworker->task, rnp); + wake_up_process(kworker->task); } =20 static void __init rcu_start_exp_gp_kworker(void) @@ -5006,79 +5015,6 @@ int rcutree_prepare_cpu(unsigned int cpu) return 0; } =20 -static void rcu_thread_affine_rnp(struct task_struct *t, struct rcu_node *= rnp) -{ - cpumask_var_t affinity; - int cpu; - - if (!zalloc_cpumask_var(&affinity, GFP_KERNEL)) - return; - - for_each_leaf_node_possible_cpu(rnp, cpu) - cpumask_set_cpu(cpu, affinity); - - kthread_affine_preferred(t, affinity); - - free_cpumask_var(affinity); -} - -/* - * Update kthreads affinity during CPU-hotplug changes. - * - * Set the per-rcu_node kthread's affinity to cover all CPUs that are - * served by the rcu_node in question. The CPU hotplug lock is still - * held, so the value of rnp->qsmaskinit will be stable. - * - * We don't include outgoingcpu in the affinity set, use -1 if there is - * no outgoing CPU. If there are no CPUs left in the affinity set, - * this function allows the kthread to execute on any CPU. - * - * Any future concurrent calls are serialized via ->kthread_mutex. - */ -static void rcutree_affinity_setting(unsigned int cpu, int outgoingcpu) -{ - cpumask_var_t cm; - unsigned long mask; - struct rcu_data *rdp; - struct rcu_node *rnp; - struct task_struct *task_exp; - - rdp =3D per_cpu_ptr(&rcu_data, cpu); - rnp =3D rdp->mynode; - - task_exp =3D rcu_exp_par_gp_task(rnp); - - /* - * If CPU is the boot one, this task is created later from early - * initcall since kthreadd must be created first. - */ - if (!task_exp) - return; - - if (!zalloc_cpumask_var(&cm, GFP_KERNEL)) - return; - - mutex_lock(&rnp->kthread_mutex); - mask =3D rcu_rnp_online_cpus(rnp); - for_each_leaf_node_possible_cpu(rnp, cpu) - if ((mask & leaf_node_cpu_bit(rnp, cpu)) && - cpu !=3D outgoingcpu) - cpumask_set_cpu(cpu, cm); - cpumask_and(cm, cm, housekeeping_cpumask(HK_TYPE_RCU)); - if (cpumask_empty(cm)) { - cpumask_copy(cm, housekeeping_cpumask(HK_TYPE_RCU)); - if (outgoingcpu >=3D 0) - cpumask_clear_cpu(outgoingcpu, cm); - } - - if (task_exp) - set_cpus_allowed_ptr(task_exp, cm); - - mutex_unlock(&rnp->kthread_mutex); - - free_cpumask_var(cm); -} - /* * Has the specified (known valid) CPU ever been fully online? */ @@ -5107,7 +5043,6 @@ int rcutree_online_cpu(unsigned int cpu) if (rcu_scheduler_active =3D=3D RCU_SCHEDULER_INACTIVE) return 0; /* Too early in boot for scheduler work. */ sync_sched_exp_online_cleanup(cpu); - rcutree_affinity_setting(cpu, -1); =20 // Stop-machine done, so allow nohz_full to disable tick. tick_dep_clear(TICK_DEP_BIT_RCU); @@ -5324,8 +5259,6 @@ int rcutree_offline_cpu(unsigned int cpu) rnp->ffmask &=3D ~rdp->grpmask; raw_spin_unlock_irqrestore_rcu_node(rnp, flags); =20 - rcutree_affinity_setting(cpu, cpu); - // nohz_full CPUs need the tick for stop-machine to work quickly tick_dep_set(TICK_DEP_BIT_RCU); return 0; --=20 2.46.0