Message ID | 20240301023109.336707-1-zhengzucheng@huawei.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-87839-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2097:b0:108:e6aa:91d0 with SMTP id gs23csp817046dyb; Thu, 29 Feb 2024 18:33:48 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWEvxuKL/759EzXsN72aDKj+TpSUVgv+VfKUM4erDEXC/DZ03m2gcN5GTnpV6Gp1AECm7iS58J0uITOQN0mH7HQKApOnw== X-Google-Smtp-Source: AGHT+IEGZnJj6JozFDeGu40wN9PJMalZflTuz1HVirK0bX6xWVOlzX2OsQLmqqkWWDP0Mh+znQk1 X-Received: by 2002:a05:6102:661:b0:472:73fb:5350 with SMTP id z1-20020a056102066100b0047273fb5350mr224397vsf.20.1709260428315; Thu, 29 Feb 2024 18:33:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709260428; cv=pass; d=google.com; s=arc-20160816; b=ho7oTpP3zhDBDzOYWMpTgUOfCBw0KDLLPCL6WmXegYP4sWbYVf8BTt5bNTIgwe1MUE 2RnrumfNMcAscrtSxbnkKnm1zuqKcaOQgiCq8PiOWydimwZ4MQaGAJu292DdrAKhrVod j4hX9jSqkBgTzhPPzWwnvdzli68l/XGY9zSVKBCO47Znb6hUuWzIAGzyU5nABcXbiSGD RwlsFdl+eXcdyPCNJ+AjCsTOyTw/Edh9nwPdt/BfsyKGeAYiAKFgnqRSN8uWJ0Qvmyn7 FRPaX40soYVdx1pfXOBACx3ApONzdCHtQGIrcBSgMhTI0FIdu7Zw938uMNsuZOqh2XIN G9ZA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=Quk7qV+Pnr4Av0dirjuEoNVC8YvNT1LdmdtXevsYuSU=; fh=DIwSO9WkQqpMPBwDmUhjDBFgURpIhCfq95Nt5mVk5v4=; b=RpVWMd56Xf3Mqfk8tYAjWpcNyJfa3s6PUMVPEfg99xZAQp4mZ//xoXnyGKV1LaaxHo 5A0vuYl3xgSKtYD5abyrVQFo0yI2dG32oRjbcr/iZsA+5H0A5R7nborHx3Um30791F4n v80PwshuoQgxyQKhGu3XRfcXVbTFsZfuYD+gfp5HzHTLeoAnezALjO7pFfIjhB7+e5v2 r6HQjdXnHm8y+/r70B+YZGFYBTZEiSplDrdNCuVtyTtH8OE3kGpbAAZpDOf21+qwm6TO CLCsCzY7iDYRURK5kJHVnRdNwXOvTJAJr40ezla6P0GqJn2UF+Ih4Pd8ikKUh4cWX+KL O4sA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-87839-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87839-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id i17-20020ac84891000000b0042c5c5855e1si2520884qtq.736.2024.02.29.18.33.48 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 18:33:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-87839-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-87839-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87839-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 1CAF81C229EE for <ouuuleilei@gmail.com>; Fri, 1 Mar 2024 02:33:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6F33A4204C; Fri, 1 Mar 2024 02:33:26 +0000 (UTC) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (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 97AE73FE23 for <linux-kernel@vger.kernel.org>; Fri, 1 Mar 2024 02:33:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709260405; cv=none; b=W8IrC0yTOwiXn8FjE/ATWp8s0HtY7Dq8+btb/oGKSUG4dtWaxWPUJLjAZNP4BD86N5JYk9sscqhOOwZ2vXPjgh6EN3NhHsWoIP+gYhzUZ1z7jYugYgTgomYsnL6rcrrsZFPik2oaOAkUvBeDBywerrqVO4Due9D4kr++FD3AZiQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709260405; c=relaxed/simple; bh=iZ+aQa0XNT8LUz/3ls5SxUXbAIgi8tHpYdadT1LDUtU=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=qGqxUL4gFVHD6Tavdz+xsxdZlPFMcQhG1NZOahss6AXOeWHRMHPMCiIxPqtXv1tb/KJOOqCaho9dcq5xD7+gLCsi0vP1YeHuLEpLbPVnp1V7E93nr/tRwlPSDmBa/mNJPzIvUarKXTpdh7/ZfIvMfzWLbAkPQ4RGza9FqGG47uk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4TmBsk1yYCzvWCX; Fri, 1 Mar 2024 10:31:06 +0800 (CST) Received: from canpemm500006.china.huawei.com (unknown [7.192.105.130]) by mail.maildlp.com (Postfix) with ESMTPS id 06DCD140258; Fri, 1 Mar 2024 10:33:18 +0800 (CST) Received: from huawei.com (10.67.174.116) by canpemm500006.china.huawei.com (7.192.105.130) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Fri, 1 Mar 2024 10:33:17 +0800 From: Zheng Zucheng <zhengzucheng@huawei.com> To: <mingo@redhat.com>, <peterz@infradead.org>, <juri.lelli@redhat.com>, <vincent.guittot@linaro.org>, <dietmar.eggemann@arm.com>, <rostedt@goodmis.org>, <bsegall@google.com>, <mgorman@suse.de>, <bristot@redhat.com>, <vschneid@redhat.com>, <wuyun.abel@bytedance.com>, <joshdon@google.com> CC: <linux-kernel@vger.kernel.org> Subject: [PATCH -next] sched/fair: Fix task migrated to isolated cpus Date: Fri, 1 Mar 2024 02:31:09 +0000 Message-ID: <20240301023109.336707-1-zhengzucheng@huawei.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To canpemm500006.china.huawei.com (7.192.105.130) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792289463020833541 X-GMAIL-MSGID: 1792289463020833541 |
Series |
[-next] sched/fair: Fix task migrated to isolated cpus
|
|
Commit Message
zhengzucheng
March 1, 2024, 2:31 a.m. UTC
On the wakeup path with hyperthreading, select cpu only looks at
task->cpus_ptr to see if the task can run on the target cpu. If isolcpus
kernel parameter is set, and isolated cpus will be part of mask
task->cpus_ptr, tasks were migrated to our isolated cpus.
Steps to reproduce on my 32-CPU hyperthreads machine:
1. with boot parameter: "isolcpus=0,1"
(thread lists: 0,16 and 1,17)
2. cgcreate -g cpuset:test
echo 0-31 > /sys/fs/cgroup/cpuset/test/cpuset.cpus
echo 0 > /sys/fs/cgroup/cpuset/test/cpuset.mems
cgexec -g cpuset:test "test_threads"
3. some threads will be migrated to the isolated cpu0/1.
Fix it by checking the valid domain mask in select_idle_smt() and
select_idle_core()
Fixes: 9fe1f127b913 ("sched/fair: Merge select_idle_core/cpu()")
Fixes: 3e6efe87cd5c ("sched/fair: Remove redundant check in select_idle_smt()")
Cc: stable@vger.kernel.org # v5.12+
Signed-off-by: Zheng Zucheng <zhengzucheng@huawei.com>
---
kernel/sched/fair.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
Comments
Hi Zucheng, thanks for the bugfix. But it has already been addressed by the following patches in tip/sched/core: 8aeaffef8c6e ("sched/fair: Take the scheduling domain into account in select_idle_smt()") 23d04d8c6b8e ("sched/fair: Take the scheduling domain into account in select_idle_core()") On 3/1/24 10:31 AM, Zheng Zucheng Wrote: > On the wakeup path with hyperthreading, select cpu only looks at > task->cpus_ptr to see if the task can run on the target cpu. If isolcpus > kernel parameter is set, and isolated cpus will be part of mask > task->cpus_ptr, tasks were migrated to our isolated cpus. > > Steps to reproduce on my 32-CPU hyperthreads machine: > 1. with boot parameter: "isolcpus=0,1" > (thread lists: 0,16 and 1,17) > 2. cgcreate -g cpuset:test > echo 0-31 > /sys/fs/cgroup/cpuset/test/cpuset.cpus > echo 0 > /sys/fs/cgroup/cpuset/test/cpuset.mems > cgexec -g cpuset:test "test_threads" > 3. some threads will be migrated to the isolated cpu0/1. > > Fix it by checking the valid domain mask in select_idle_smt() and > select_idle_core() > > Fixes: 9fe1f127b913 ("sched/fair: Merge select_idle_core/cpu()") > Fixes: 3e6efe87cd5c ("sched/fair: Remove redundant check in select_idle_smt()") > Cc: stable@vger.kernel.org # v5.12+ > Signed-off-by: Zheng Zucheng <zhengzucheng@huawei.com> > --- > kernel/sched/fair.c | 12 ++++++------ > 1 file changed, 6 insertions(+), 6 deletions(-) > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index 533547e3c90a..e6552c77e0f1 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -7289,7 +7289,7 @@ static int select_idle_core(struct task_struct *p, int core, struct cpumask *cpu > if (!available_idle_cpu(cpu)) { > idle = false; > if (*idle_cpu == -1) { > - if (sched_idle_cpu(cpu) && cpumask_test_cpu(cpu, p->cpus_ptr)) { > + if (sched_idle_cpu(cpu) && cpumask_test_cpu(cpu, cpus)) { > *idle_cpu = cpu; > break; > } > @@ -7297,7 +7297,7 @@ static int select_idle_core(struct task_struct *p, int core, struct cpumask *cpu > } > break; > } > - if (*idle_cpu == -1 && cpumask_test_cpu(cpu, p->cpus_ptr)) > + if (*idle_cpu == -1 && cpumask_test_cpu(cpu, cpus)) > *idle_cpu = cpu; > } > > @@ -7311,12 +7311,12 @@ static int select_idle_core(struct task_struct *p, int core, struct cpumask *cpu > /* > * Scan the local SMT mask for idle CPUs. > */ > -static int select_idle_smt(struct task_struct *p, int target) > +static int select_idle_smt(struct task_struct *p, struct sched_domain *sd, int target) > { > int cpu; > > for_each_cpu_and(cpu, cpu_smt_mask(target), p->cpus_ptr) { > - if (cpu == target) > + if (cpu == target || !cpumask_test_cpu(cpu, sched_domain_span(sd))) > continue; > if (available_idle_cpu(cpu) || sched_idle_cpu(cpu)) > return cpu; > @@ -7341,7 +7341,7 @@ static inline int select_idle_core(struct task_struct *p, int core, struct cpuma > return __select_idle_cpu(core, p); > } > > -static inline int select_idle_smt(struct task_struct *p, int target) > +static inline int select_idle_smt(struct task_struct *p, struct sched_domain *sd, int target) > { > return -1; > } > @@ -7591,7 +7591,7 @@ static int select_idle_sibling(struct task_struct *p, int prev, int target) > has_idle_core = test_idle_cores(target); > > if (!has_idle_core && cpus_share_cache(prev, target)) { > - i = select_idle_smt(p, prev); > + i = select_idle_smt(p, sd, prev); > if ((unsigned int)i < nr_cpumask_bits) > return i; > }
Ah yes indeed. I didn't notice that it was fixed,thanks! 在 2024/3/1 11:28, Abel Wu 写道: > Hi Zucheng, thanks for the bugfix. But it has already been addressed > by the following patches in tip/sched/core: > > 8aeaffef8c6e ("sched/fair: Take the scheduling domain into account in > select_idle_smt()") > 23d04d8c6b8e ("sched/fair: Take the scheduling domain into account in > select_idle_core()") > > On 3/1/24 10:31 AM, Zheng Zucheng Wrote: >> On the wakeup path with hyperthreading, select cpu only looks at >> task->cpus_ptr to see if the task can run on the target cpu. If isolcpus >> kernel parameter is set, and isolated cpus will be part of mask >> task->cpus_ptr, tasks were migrated to our isolated cpus. >> >> Steps to reproduce on my 32-CPU hyperthreads machine: >> 1. with boot parameter: "isolcpus=0,1" >> (thread lists: 0,16 and 1,17) >> 2. cgcreate -g cpuset:test >> echo 0-31 > /sys/fs/cgroup/cpuset/test/cpuset.cpus >> echo 0 > /sys/fs/cgroup/cpuset/test/cpuset.mems >> cgexec -g cpuset:test "test_threads" >> 3. some threads will be migrated to the isolated cpu0/1. >> >> Fix it by checking the valid domain mask in select_idle_smt() and >> select_idle_core() >> >> Fixes: 9fe1f127b913 ("sched/fair: Merge select_idle_core/cpu()") >> Fixes: 3e6efe87cd5c ("sched/fair: Remove redundant check in >> select_idle_smt()") >> Cc: stable@vger.kernel.org # v5.12+ >> Signed-off-by: Zheng Zucheng <zhengzucheng@huawei.com> >> --- >> kernel/sched/fair.c | 12 ++++++------ >> 1 file changed, 6 insertions(+), 6 deletions(-) >> >> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c >> index 533547e3c90a..e6552c77e0f1 100644 >> --- a/kernel/sched/fair.c >> +++ b/kernel/sched/fair.c >> @@ -7289,7 +7289,7 @@ static int select_idle_core(struct task_struct >> *p, int core, struct cpumask *cpu >> if (!available_idle_cpu(cpu)) { >> idle = false; >> if (*idle_cpu == -1) { >> - if (sched_idle_cpu(cpu) && cpumask_test_cpu(cpu, >> p->cpus_ptr)) { >> + if (sched_idle_cpu(cpu) && cpumask_test_cpu(cpu, >> cpus)) { >> *idle_cpu = cpu; >> break; >> } >> @@ -7297,7 +7297,7 @@ static int select_idle_core(struct task_struct >> *p, int core, struct cpumask *cpu >> } >> break; >> } >> - if (*idle_cpu == -1 && cpumask_test_cpu(cpu, p->cpus_ptr)) >> + if (*idle_cpu == -1 && cpumask_test_cpu(cpu, cpus)) >> *idle_cpu = cpu; >> } >> @@ -7311,12 +7311,12 @@ static int select_idle_core(struct >> task_struct *p, int core, struct cpumask *cpu >> /* >> * Scan the local SMT mask for idle CPUs. >> */ >> -static int select_idle_smt(struct task_struct *p, int target) >> +static int select_idle_smt(struct task_struct *p, struct >> sched_domain *sd, int target) >> { >> int cpu; >> for_each_cpu_and(cpu, cpu_smt_mask(target), p->cpus_ptr) { >> - if (cpu == target) >> + if (cpu == target || !cpumask_test_cpu(cpu, >> sched_domain_span(sd))) >> continue; >> if (available_idle_cpu(cpu) || sched_idle_cpu(cpu)) >> return cpu; >> @@ -7341,7 +7341,7 @@ static inline int select_idle_core(struct >> task_struct *p, int core, struct cpuma >> return __select_idle_cpu(core, p); >> } >> -static inline int select_idle_smt(struct task_struct *p, int target) >> +static inline int select_idle_smt(struct task_struct *p, struct >> sched_domain *sd, int target) >> { >> return -1; >> } >> @@ -7591,7 +7591,7 @@ static int select_idle_sibling(struct >> task_struct *p, int prev, int target) >> has_idle_core = test_idle_cores(target); >> if (!has_idle_core && cpus_share_cache(prev, target)) { >> - i = select_idle_smt(p, prev); >> + i = select_idle_smt(p, sd, prev); >> if ((unsigned int)i < nr_cpumask_bits) >> return i; >> } > > .
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 533547e3c90a..e6552c77e0f1 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -7289,7 +7289,7 @@ static int select_idle_core(struct task_struct *p, int core, struct cpumask *cpu if (!available_idle_cpu(cpu)) { idle = false; if (*idle_cpu == -1) { - if (sched_idle_cpu(cpu) && cpumask_test_cpu(cpu, p->cpus_ptr)) { + if (sched_idle_cpu(cpu) && cpumask_test_cpu(cpu, cpus)) { *idle_cpu = cpu; break; } @@ -7297,7 +7297,7 @@ static int select_idle_core(struct task_struct *p, int core, struct cpumask *cpu } break; } - if (*idle_cpu == -1 && cpumask_test_cpu(cpu, p->cpus_ptr)) + if (*idle_cpu == -1 && cpumask_test_cpu(cpu, cpus)) *idle_cpu = cpu; } @@ -7311,12 +7311,12 @@ static int select_idle_core(struct task_struct *p, int core, struct cpumask *cpu /* * Scan the local SMT mask for idle CPUs. */ -static int select_idle_smt(struct task_struct *p, int target) +static int select_idle_smt(struct task_struct *p, struct sched_domain *sd, int target) { int cpu; for_each_cpu_and(cpu, cpu_smt_mask(target), p->cpus_ptr) { - if (cpu == target) + if (cpu == target || !cpumask_test_cpu(cpu, sched_domain_span(sd))) continue; if (available_idle_cpu(cpu) || sched_idle_cpu(cpu)) return cpu; @@ -7341,7 +7341,7 @@ static inline int select_idle_core(struct task_struct *p, int core, struct cpuma return __select_idle_cpu(core, p); } -static inline int select_idle_smt(struct task_struct *p, int target) +static inline int select_idle_smt(struct task_struct *p, struct sched_domain *sd, int target) { return -1; } @@ -7591,7 +7591,7 @@ static int select_idle_sibling(struct task_struct *p, int prev, int target) has_idle_core = test_idle_cores(target); if (!has_idle_core && cpus_share_cache(prev, target)) { - i = select_idle_smt(p, prev); + i = select_idle_smt(p, sd, prev); if ((unsigned int)i < nr_cpumask_bits) return i; }