From nobody Sat Apr 11 12:59:05 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78645C61DA4 for ; Mon, 6 Mar 2023 20:11:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230378AbjCFULC (ORCPT ); Mon, 6 Mar 2023 15:11:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230191AbjCFUK7 (ORCPT ); Mon, 6 Mar 2023 15:10:59 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FD4A4DE03 for ; Mon, 6 Mar 2023 12:09:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678133371; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Grvm3WHWtWaUdwJ9Qfi2o/ztDJyGIgGXieKrU2ipubo=; b=UjaSUUnR53NePlJ7Ep2lzb3p4zeY++XUMZx7cMXjkEahnIylKVJTtaJiMv9GQuk22tcXHi B/g65n4EWDjFMu9Qr9RgmJBhmKG0KO6sPRkG1PiwhSni23OZpdtslqGQBkfhW6QcifZ+0p NQ5XNenCp8+EfS90yOgacL7/n+JNkH8= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-125-DbWfXIfcNhCArXncUlTaqg-1; Mon, 06 Mar 2023 15:09:27 -0500 X-MC-Unique: DbWfXIfcNhCArXncUlTaqg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6617885A588; Mon, 6 Mar 2023 20:09:26 +0000 (UTC) Received: from llong.com (dhcp-17-153.bos.redhat.com [10.18.17.153]) by smtp.corp.redhat.com (Postfix) with ESMTP id 22F58400DFA1; Mon, 6 Mar 2023 20:09:26 +0000 (UTC) From: Waiman Long To: Tejun Heo , Zefan Li , Johannes Weiner , Shuah Khan Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Will Deacon , Peter Zijlstra , Waiman Long Subject: [PATCH 1/5] cgroup/cpuset: Skip task update if hotplug doesn't affect current cpuset Date: Mon, 6 Mar 2023 15:08:45 -0500 Message-Id: <20230306200849.376804-2-longman@redhat.com> In-Reply-To: <20230306200849.376804-1-longman@redhat.com> References: <20230306200849.376804-1-longman@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" If a hotplug event doesn't affect the current cpuset, there is no point to call hotplug_update_tasks() or hotplug_update_tasks_legacy(). So just skip it. Signed-off-by: Waiman Long Reviewed-by: Michal Koutn=C3=BD --- kernel/cgroup/cpuset.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 636f1c682ac0..a801abad3bac 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -3508,6 +3508,8 @@ static void cpuset_hotplug_update_tasks(struct cpuset= *cs, struct tmpmasks *tmp) update_tasks: cpus_updated =3D !cpumask_equal(&new_cpus, cs->effective_cpus); mems_updated =3D !nodes_equal(new_mems, cs->effective_mems); + if (!cpus_updated && !mems_updated) + goto unlock; /* Hotplug doesn't affect this cpuset */ =20 if (mems_updated) check_insane_mems_config(&new_mems); @@ -3519,6 +3521,7 @@ static void cpuset_hotplug_update_tasks(struct cpuset= *cs, struct tmpmasks *tmp) hotplug_update_tasks_legacy(cs, &new_cpus, &new_mems, cpus_updated, mems_updated); =20 +unlock: percpu_up_write(&cpuset_rwsem); } =20 --=20 2.31.1 From nobody Sat Apr 11 12:59:05 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 02A85C61DA4 for ; Mon, 6 Mar 2023 20:11:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230412AbjCFULS (ORCPT ); Mon, 6 Mar 2023 15:11:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230403AbjCFULD (ORCPT ); Mon, 6 Mar 2023 15:11:03 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90D364B820 for ; Mon, 6 Mar 2023 12:09:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678133370; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XMpGzFxDVrhKLpAq2mb4oo3DA00+S6OlDRBjGlenDeM=; b=P0Py6VEag06c8j/FtieA8fOuQ4IryLTGa0zjr61JFxCE0ZhHHSIozCYmlz1kHuO5zup+mx uw0bmEsw2UDeDrTVEuJi6aauzWcyCrGl8QcSHYd9SviDVK6eAeESY6s6BJysUNjkVA1kJy jSgNpFTFsblDnIPxE+WVyrgd/osIyzY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-672-qTnL-CUCNN6x3dhM75SdCw-1; Mon, 06 Mar 2023 15:09:27 -0500 X-MC-Unique: qTnL-CUCNN6x3dhM75SdCw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B1C51857A89; Mon, 6 Mar 2023 20:09:26 +0000 (UTC) Received: from llong.com (dhcp-17-153.bos.redhat.com [10.18.17.153]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6DA934010E7B; Mon, 6 Mar 2023 20:09:26 +0000 (UTC) From: Waiman Long To: Tejun Heo , Zefan Li , Johannes Weiner , Shuah Khan Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Will Deacon , Peter Zijlstra , Waiman Long Subject: [PATCH 2/5] cgroup/cpuset: Include offline CPUs when tasks' cpumasks in top_cpuset are updated Date: Mon, 6 Mar 2023 15:08:46 -0500 Message-Id: <20230306200849.376804-3-longman@redhat.com> In-Reply-To: <20230306200849.376804-1-longman@redhat.com> References: <20230306200849.376804-1-longman@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Similar to commit 3fb906e7fabb ("group/cpuset: Don't filter offline CPUs in cpuset_cpus_allowed() for top cpuset tasks"), the whole set of possible CPUs including offline ones should be used for setting cpumasks for tasks in the top cpuset when a cpuset partition is modified. Signed-off-by: Waiman Long --- kernel/cgroup/cpuset.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index a801abad3bac..bbf57dcb2f68 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1209,7 +1209,8 @@ void rebuild_sched_domains(void) * * Iterate through each task of @cs updating its cpus_allowed to the * effective cpuset's. As this function is called with cpuset_rwsem held, - * cpuset membership stays stable. + * cpuset membership stays stable. For top_cpuset, task_cpu_possible_mask() + * is used instead of effective_cpus. */ static void update_tasks_cpumask(struct cpuset *cs, struct cpumask *new_cp= us) { @@ -1219,15 +1220,18 @@ static void update_tasks_cpumask(struct cpuset *cs,= struct cpumask *new_cpus) =20 css_task_iter_start(&cs->css, 0, &it); while ((task =3D css_task_iter_next(&it))) { - /* - * Percpu kthreads in top_cpuset are ignored - */ - if (top_cs && (task->flags & PF_KTHREAD) && - kthread_is_per_cpu(task)) - continue; + const struct cpumask *possible_mask =3D task_cpu_possible_mask(task); =20 - cpumask_and(new_cpus, cs->effective_cpus, - task_cpu_possible_mask(task)); + if (top_cs) { + /* + * Percpu kthreads in top_cpuset are ignored + */ + if ((task->flags & PF_KTHREAD) && kthread_is_per_cpu(task)) + continue; + cpumask_andnot(new_cpus, possible_mask, cs->subparts_cpus); + } else { + cpumask_and(new_cpus, cs->effective_cpus, possible_mask); + } set_cpus_allowed_ptr(task, new_cpus); } css_task_iter_end(&it); --=20 2.31.1 From nobody Sat Apr 11 12:59:05 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6157FC61DA4 for ; Mon, 6 Mar 2023 20:11:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230371AbjCFULU (ORCPT ); Mon, 6 Mar 2023 15:11:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230404AbjCFULD (ORCPT ); Mon, 6 Mar 2023 15:11:03 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 929324C6F6 for ; Mon, 6 Mar 2023 12:09:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678133370; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZPOLCRRq9h+M6y4H0byc+i6v9jsYVGqazZOEyY69QjU=; b=HN9t6qD7WMIoJPm1w7ab1amofZyZR8nl882hEBK/qczwb9IRiD+0Bbz0tLQcpCg18ZRahB ScQCLvHjAHQxj+Vyefk481njsZ6mGFqL1b/LoUFBKMuZ0qjK7sQa1OHO3hBF9NtQF+7xg9 CXKoar3/FNvK6RL7ykbqE6lEOAPPQsI= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-626-WJXboG_qNv6uRFmfnQGtTw-1; Mon, 06 Mar 2023 15:09:27 -0500 X-MC-Unique: WJXboG_qNv6uRFmfnQGtTw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 07FEE3C025B2; Mon, 6 Mar 2023 20:09:27 +0000 (UTC) Received: from llong.com (dhcp-17-153.bos.redhat.com [10.18.17.153]) by smtp.corp.redhat.com (Postfix) with ESMTP id B89C940C83B6; Mon, 6 Mar 2023 20:09:26 +0000 (UTC) From: Waiman Long To: Tejun Heo , Zefan Li , Johannes Weiner , Shuah Khan Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Will Deacon , Peter Zijlstra , Waiman Long Subject: [PATCH 3/5] cgroup/cpuset: Find another usable CPU if none found in current cpuset Date: Mon, 6 Mar 2023 15:08:47 -0500 Message-Id: <20230306200849.376804-4-longman@redhat.com> In-Reply-To: <20230306200849.376804-1-longman@redhat.com> References: <20230306200849.376804-1-longman@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" On a system with asymmetric CPUs, a restricted task is one that can run only a selected subset of available CPUs. When a CPU goes offline or when "cpuset.cpus" is changed, it is possible that a restricted task may not have any runnable CPUs left in the current cpuset even if there is still some CPUs in effective_cpus. In this case, the restricted task cannot be run at all. There are several ways we may be able to handle this situation. Treating it like empty effective_cpus is probably too disruptive and is unfair to the normal tasks. So it is better to have some special handling for these restricted tasks. One possibility is to move the restricted tasks up the cpuset hierarchy, but it is tricky to do it right. Another solution is to assign other usable CPUs to these tasks. This patch implements the later alternative by finding one usable CPU by walking up the cpuset hierarchy and printing an informational message to let the users know that these restricted tasks are running in a cpuset with no usable CPU. Signed-off-by: Waiman Long --- kernel/cgroup/cpuset.c | 56 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index bbf57dcb2f68..aa8225daf1d3 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1202,6 +1202,38 @@ void rebuild_sched_domains(void) cpus_read_unlock(); } =20 +/* + * Find a usable effective (online) CPU up the cpuset hierarchy and return= it. + */ +static int find_usable_cpu(struct cpuset *cs, struct cpumask *new_cpus, + const struct cpumask *possible_mask) +{ + struct cpuset *parent; + unsigned long flags; + int cpu; + + /* + * When offlining cpu, some effective_cpus may not be up to date. + * So check cpu_online_mask to be sure. + */ + parent =3D parent_cs(cs); + while (parent && + (!cpumask_and(new_cpus, parent->effective_cpus, possible_mask) || + !cpumask_and(new_cpus, new_cpus, cpu_online_mask))) + parent =3D parent_cs(cs); + + /* Fall back to all possible online cpus, if necessary */ + if (!parent) + cpumask_and(new_cpus, possible_mask, cpu_online_mask); + + /* cpumask_any_distribute() has to be called with preemption disabled */ + local_irq_save(flags); + cpu =3D cpumask_any_distribute(new_cpus); + local_irq_restore(flags); + + return cpu; +} + /** * update_tasks_cpumask - Update the cpumasks of tasks in the cpuset. * @cs: the cpuset in which each task's cpus_allowed mask needs to be chan= ged @@ -1218,6 +1250,7 @@ static void update_tasks_cpumask(struct cpuset *cs, s= truct cpumask *new_cpus) struct task_struct *task; bool top_cs =3D cs =3D=3D &top_cpuset; =20 + percpu_rwsem_assert_held(&cpuset_rwsem); css_task_iter_start(&cs->css, 0, &it); while ((task =3D css_task_iter_next(&it))) { const struct cpumask *possible_mask =3D task_cpu_possible_mask(task); @@ -1232,7 +1265,28 @@ static void update_tasks_cpumask(struct cpuset *cs, = struct cpumask *new_cpus) } else { cpumask_and(new_cpus, cs->effective_cpus, possible_mask); } - set_cpus_allowed_ptr(task, new_cpus); + /* + * On systems with assymetric CPUs, it is possible that + * cpumask will become empty or set_cpus_allowed_ptr() will + * return an error even if we still have CPUs in + * effective_cpus. In this case, we find a usable CPU walking + * up the cpuset hierarchy and use that for this particular + * task with an informational message about the change in the + * hope that the users will adjust "cpuset.cpus" accordingly. + */ + if (cpumask_empty(new_cpus) || + set_cpus_allowed_ptr(task, new_cpus)) { + char name[80]; + int cpu; + + cpu =3D find_usable_cpu(cs, new_cpus, possible_mask); + cpumask_clear(new_cpus); + cpumask_set_cpu(cpu, new_cpus); + WARN_ON_ONCE(set_cpus_allowed_ptr(task, new_cpus)); + cgroup_name(cs->css.cgroup, name, sizeof(name)); + pr_info("cpuset: Restricted task %s(%d) in cpuset %s is forced to run o= n outside CPU %d\n", + task->comm, task->pid, name, cpu); + } } css_task_iter_end(&it); } --=20 2.31.1 From nobody Sat Apr 11 12:59:05 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8FFEC64EC4 for ; Mon, 6 Mar 2023 20:11:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230414AbjCFULE (ORCPT ); Mon, 6 Mar 2023 15:11:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230217AbjCFUK7 (ORCPT ); Mon, 6 Mar 2023 15:10:59 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD91E4D628 for ; Mon, 6 Mar 2023 12:09:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678133371; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8DOL1Xn5BRvEVzQbK0JT1QOBJzRVq//5ngfgMzTUxGY=; b=W/GVR5ndUDTkFss3pqrDlRSx5Qb1LumXj2WjTXplVlfC7gRB+v9Iu/2Pyf0ZmzIJiKilGM vjjR+dJUwGv1NU7HqDxaumpBnpRLZ3kL/p1lPqUPU3x8/410hUKPAbgsY6o5m8wi5OwTB8 mLjoyR9Yv8iv3ISxhlvXqnLRVktLMDk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-319-8Nd4UDtXP3uOUYxmG6HB6A-1; Mon, 06 Mar 2023 15:09:28 -0500 X-MC-Unique: 8Nd4UDtXP3uOUYxmG6HB6A-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5301D885625; Mon, 6 Mar 2023 20:09:27 +0000 (UTC) Received: from llong.com (dhcp-17-153.bos.redhat.com [10.18.17.153]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0FE9E400DFA1; Mon, 6 Mar 2023 20:09:27 +0000 (UTC) From: Waiman Long To: Tejun Heo , Zefan Li , Johannes Weiner , Shuah Khan Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Will Deacon , Peter Zijlstra , Waiman Long Subject: [PATCH 4/5] cgroup/cpuset: Add CONFIG_DEBUG_CPUSETS config for cpuset testing Date: Mon, 6 Mar 2023 15:08:48 -0500 Message-Id: <20230306200849.376804-5-longman@redhat.com> In-Reply-To: <20230306200849.376804-1-longman@redhat.com> References: <20230306200849.376804-1-longman@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Since commit 431c69fac05b ("cpuset: Honour task_cpu_possible_mask() in guarantee_online_cpus()"), task_cpu_possible_mask() is used within the cpuset code. However, it is hard to find a arm64 system that can actually makes task_cpu_possible_mask() return different cpu mask. As a result, it is hard to exercise the correctness of the code that handle exception cases due to task_cpu_possible_mask(). To help in exercising those code paths, we need a way to force task_cpu_possible_mask() to return a different cpu mask. This patch adds a new CONFIG_DEBUG_CPUSETS config option to enable some debug code to do just that. The idea is to create a debugfs file "debug_cpu_possible_mask" that holds the cpumask to be returned by task_cpu_possible_mask() when a task with name started with the special prefix "cstest" is used as the input argument. Userspace testing code is then able to exercise the different code that is affected by task_cpu_possible_mask(). Signed-off-by: Waiman Long --- init/Kconfig | 5 +++ kernel/cgroup/cpuset.c | 76 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) diff --git a/init/Kconfig b/init/Kconfig index 18f0bf50c468..2abaa830aff0 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1140,6 +1140,11 @@ config PROC_PID_CPUSET depends on CPUSETS default y =20 +config DEBUG_CPUSETS + bool "Enable cpuset debugging" + depends on CPUSETS && DEBUG_FS + default n + config CGROUP_DEVICE bool "Device controller" help diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index aa8225daf1d3..45051ebb6606 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -220,6 +220,29 @@ static inline bool is_prs_invalid(int prs_state) return prs_state < 0; } =20 +#ifdef CONFIG_DEBUG_CPUSETS +static struct cpumask debug_cpu_possible_mask; + +/* + * Debugging code for testing code involving task_cpu_possible_mask() + */ +static inline const struct cpumask * +__task_cpu_possible_mask(struct task_struct *p) +{ + const struct cpumask *mask =3D task_cpu_possible_mask(p); + + if (mask !=3D cpu_possible_mask) + return mask; + else if (!strncmp(p->comm, "cstest", 6)) + return &debug_cpu_possible_mask; + else + return cpu_possible_mask; +} + +#undef task_cpu_possible_mask +#define task_cpu_possible_mask(p) __task_cpu_possible_mask(p) +#endif /* CONFIG_DEBUG_CPUSETS */ + /* * Temporary cpumasks for working with partitions that are passed among * functions to avoid memory allocation in inner functions. @@ -4139,3 +4162,56 @@ void cpuset_task_status_allowed(struct seq_file *m, = struct task_struct *task) seq_printf(m, "Mems_allowed_list:\t%*pbl\n", nodemask_pr_args(&task->mems_allowed)); } + +#ifdef CONFIG_DEBUG_CPUSETS +#include + +/* + * Add a debugfs file "debug_cpu_possible_mask" that allows user to set + * a debug mask for testing. + */ +static ssize_t read_debug_mask(struct file *file, char __user *user_buf, + size_t count, loff_t *ppos) +{ + char buf[80]; + int len; + + len =3D snprintf(buf, sizeof(buf) - 1, "%*pbl\n", + cpumask_pr_args(&debug_cpu_possible_mask)); + return simple_read_from_buffer(user_buf, count, ppos, buf, len); +} + +static ssize_t write_debug_mask(struct file *file, const char __user *user= _buf, + size_t count, loff_t *ppos) +{ + unsigned int len; + char buf[80]; + int retval =3D 0; + + len =3D min(count, sizeof(buf) - 1); + if (copy_from_user(buf, user_buf, len)) + return -EFAULT; + + if (!*buf) + cpumask_clear(&debug_cpu_possible_mask); + else + retval =3D cpulist_parse(buf, &debug_cpu_possible_mask); + + return (retval < 0) ? retval : count; +} + +static const struct file_operations fops_debug_mask =3D { + .read =3D read_debug_mask, + .write =3D write_debug_mask, + .llseek =3D default_llseek, +}; + +static int __init create_debug_cpu_possible_mask(void) +{ + cpumask_copy(&debug_cpu_possible_mask, cpu_possible_mask); + debugfs_create_file("debug_cpu_possible_mask", 0600, NULL, NULL, + &fops_debug_mask); + return 0; +} +late_initcall(create_debug_cpu_possible_mask); +#endif /* CONFIG_DEBUG_CPUSETS */ --=20 2.31.1 From nobody Sat Apr 11 12:59:05 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76F5EC6FD1A for ; Mon, 6 Mar 2023 20:12:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230404AbjCFUMA (ORCPT ); Mon, 6 Mar 2023 15:12:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230386AbjCFULo (ORCPT ); Mon, 6 Mar 2023 15:11:44 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68E3E4E5D1 for ; Mon, 6 Mar 2023 12:09:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678133372; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XQ/fbLiMTxYvcy4Xv+isuWXHLsrugKjziame8MLcKpQ=; b=Dx8dhNPrgNv36jOv2+qcVSTN+Fumsl8tBZqrmv+W3RVAAVLh9KJvR7N+Afy698H2VVOa86 /7yRQ8RfG8C2+WFPG1ZNh8ivKjh0F6qW6FUYhrzwGfNTW5iGse/nskJetTncaaq2KmAcpd kmUuEkRm2nA9Z2aae8kVRJHOApZRLZo= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-317-5KLDa69LNIygZSqWcf9rbw-1; Mon, 06 Mar 2023 15:09:28 -0500 X-MC-Unique: 5KLDa69LNIygZSqWcf9rbw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9DEC93C20EE5; Mon, 6 Mar 2023 20:09:27 +0000 (UTC) Received: from llong.com (dhcp-17-153.bos.redhat.com [10.18.17.153]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5ABB940B40E4; Mon, 6 Mar 2023 20:09:27 +0000 (UTC) From: Waiman Long To: Tejun Heo , Zefan Li , Johannes Weiner , Shuah Khan Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Will Deacon , Peter Zijlstra , Waiman Long Subject: [PATCH 5/5] cgroup/cpuset: Minor updates to test_cpuset_prs.sh Date: Mon, 6 Mar 2023 15:08:49 -0500 Message-Id: <20230306200849.376804-6-longman@redhat.com> In-Reply-To: <20230306200849.376804-1-longman@redhat.com> References: <20230306200849.376804-1-longman@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This patch makes the following minor updates to the cpuset partition testing script test_cpuset_prs.sh. - Remove online_cpus function call as it will be called anyway on exit in cleanup. - Make the enabling of sched/verbose debugfs flag conditional on the "-v" verbose option and set DELAY_FACTOR to 2 in this case as cpuset partition operations are likely to be slowed down by enabling that. Signed-off-by: Waiman Long Reviewed-by: Kamalesh Babulal --- .../selftests/cgroup/test_cpuset_prs.sh | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/tools/testing/selftests/cgroup/test_cpuset_prs.sh b/tools/test= ing/selftests/cgroup/test_cpuset_prs.sh index 75c100de90ff..2b5215cc599f 100755 --- a/tools/testing/selftests/cgroup/test_cpuset_prs.sh +++ b/tools/testing/selftests/cgroup/test_cpuset_prs.sh @@ -15,13 +15,6 @@ skip_test() { =20 [[ $(id -u) -eq 0 ]] || skip_test "Test must be run as root!" =20 -# Set sched verbose flag, if available -if [[ -d /sys/kernel/debug/sched ]] -then - # Used to restore the original setting during cleanup - SCHED_DEBUG=3D$(cat /sys/kernel/debug/sched/verbose) - echo Y > /sys/kernel/debug/sched/verbose -fi =20 # Get wait_inotify location WAIT_INOTIFY=3D$(cd $(dirname $0); pwd)/wait_inotify @@ -37,10 +30,14 @@ CPUS=3D$(lscpu | grep "^CPU(s):" | sed -e "s/.*:[[:spac= e:]]*//") PROG=3D$1 VERBOSE=3D DELAY_FACTOR=3D1 +SCHED_DEBUG=3D while [[ "$1" =3D -* ]] do case "$1" in -v) VERBOSE=3D1 + # Enable sched/verbose can slow thing down + [[ $DELAY_FACTOR -eq 1 ]] && + DELAY_FACTOR=3D2 break ;; -d) DELAY_FACTOR=3D$2 @@ -54,6 +51,14 @@ do shift done =20 +# Set sched verbose flag if available when "-v" option is specified +if [[ -n "$VERBOSE" && -d /sys/kernel/debug/sched ]] +then + # Used to restore the original setting during cleanup + SCHED_DEBUG=3D$(cat /sys/kernel/debug/sched/verbose) + echo Y > /sys/kernel/debug/sched/verbose +fi + cd $CGROUP2 echo +cpuset > cgroup.subtree_control [[ -d test ]] || mkdir test @@ -65,7 +70,8 @@ cleanup() rmdir A1/A2/A3 A1/A2 A1 B1 > /dev/null 2>&1 cd .. rmdir test > /dev/null 2>&1 - echo "$SCHED_DEBUG" > /sys/kernel/debug/sched/verbose + [[ -n "$SCHED_DEBUG" ]] && + echo "$SCHED_DEBUG" > /sys/kernel/debug/sched/verbose } =20 # Pause in ms @@ -571,7 +577,6 @@ run_state_test() echo "Test $TEST[$I] failed result check!" eval echo \"\${$TEST[$I]}\" dump_states - online_cpus exit 1 } =20 @@ -582,7 +587,6 @@ run_state_test() eval echo \"\${$TEST[$I]}\" echo dump_states - online_cpus exit 1 } } @@ -594,7 +598,6 @@ run_state_test() eval echo \"\${$TEST[$I]}\" echo dump_states - online_cpus exit 1 } } --=20 2.31.1