Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3733850iog; Tue, 28 Jun 2022 01:20:07 -0700 (PDT) X-Google-Smtp-Source: AGRyM1soUH6e23uvlq7KS4EOVtwqerVAojWh+Cim3UZ6Tsi9oFryD1dQ0UTD9nX9WkBi6cfUxxn1 X-Received: by 2002:a05:6402:d05:b0:425:b5c8:faeb with SMTP id eb5-20020a0564020d0500b00425b5c8faebmr21338189edb.273.1656404407161; Tue, 28 Jun 2022 01:20:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656404407; cv=none; d=google.com; s=arc-20160816; b=N+H4vnD6bqchBszdHhqc+B1G9EzsSbsbAuiz3QE8K4z0dvTNuSlAZmDMtmlorN2cA1 CwqgF4RM8xFjfIyTeqbOw1lVUatitFgo6xjQPrqx9UwuM+UeUnCqXLlZBjS8rr3PNJqI OfRHtwIBY7H65J3cBzlVESAiI4bk7UcYLQSPOXROxUZxLalsb5XCQIu9bo7ddMCYeZ4V ZUDRJ54CIPq//20Xn7xWUvC5BENWkOqG2T4fS7joqX5/6rwVQKg558eZe5cPH2TPJ/t9 E9kpV0qRSuajVRE7mfiWRMrH4q81GotSv7F46UWIg+9MahCra8l8dE7eSpUAzILnppK0 3phA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=1Odet9MrIoPis7w0durX9ulwH551sb9R8SD7gdoKx50=; b=q+APX1i4ApgUn2/MNrWXTNItoeULinWCDVQCwKipegE9P35bHiPGNmHjV1PFvueWZ9 DdUbpm4IbyqnjbhWLxwEFXq4QthztE4lJNPvBfJipA+JVh3IyU/K/uR8IhHwjAz+/qU2 PYSAd4PjMd3b6tAuNIMb/hPq7SYU/shtymOoPpy6G/QduD64XM84cVVzdDeIeDa45uGf iW3E7gSCJnL//7U+vqeYqpnTHXLWejUZjdslt1CZe+DzoqEPE9WHYDTAwtjRZ/9DTU0Y 2ohBAkHkpKRLzAJ9rM9fkB2dhLGvY5hIYaeKgm8PhqDaVqQy6iQiCBX7lnhbAepjrV78 GCkA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cs17-20020a170906dc9100b007157ddd2e51si15687549ejc.882.2022.06.28.01.19.40; Tue, 28 Jun 2022 01:20:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243379AbiF1H5o (ORCPT + 99 others); Tue, 28 Jun 2022 03:57:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343783AbiF1H5h (ORCPT ); Tue, 28 Jun 2022 03:57:37 -0400 Received: from out30-45.freemail.mail.aliyun.com (out30-45.freemail.mail.aliyun.com [115.124.30.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4689C1B786 for ; Tue, 28 Jun 2022 00:57:36 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R191e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046049;MF=cruzzhao@linux.alibaba.com;NM=1;PH=DS;RN=10;SR=0;TI=SMTPD_---0VHgOW0s_1656403052; Received: from rt2b04371.sqa.tbc.tbsite.net(mailfrom:CruzZhao@linux.alibaba.com fp:SMTPD_---0VHgOW0s_1656403052) by smtp.aliyun-inc.com; Tue, 28 Jun 2022 15:57:33 +0800 From: Cruz Zhao 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 Cc: linux-kernel@vger.kernel.org Subject: [PATCH 1/3] sched/core: Fix the bug that task won't enqueue into core tree when update cookie Date: Tue, 28 Jun 2022 15:57:23 +0800 Message-Id: <1656403045-100840-2-git-send-email-CruzZhao@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1656403045-100840-1-git-send-email-CruzZhao@linux.alibaba.com> References: <1656403045-100840-1-git-send-email-CruzZhao@linux.alibaba.com> X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In function sched_core_update_cookie(), a task will enqueue into the core tree only when it enqueued before, that is, if an uncookied task is cookied, it will not enqueue into the core tree until it enqueue again, which will result in unnecessary force idle. Here follows the scenario: CPU x and CPU y are a pair of SMT siblings. 1. Start task a running on CPU x without sleeping, and task b and task c running on CPU y without sleeping. 2. We create a cookie and share it to task a and task b, and then we create another cookie and share it to task c. 3. Simpling core_forceidle_sum of task a and b from /proc/PID/sched And we will find out that core_forceidle_sum of task a takes 30% time of the sampling period, which shouldn't happen as task a and b have the same cookie. Then we migrate task a to CPU x', migrate task b and c to CPU y', where CPU x' and CPU y' are a pair of SMT siblings, and sampling again, we will found out that core_forceidle_sum of task a and b are almost zero. To solve this problem, we enqueue the task into the core tree if it's on rq. Fixes: 6e33cad0af49("sched: Trivial core scheduling cookie management") Signed-off-by: Cruz Zhao --- kernel/sched/core_sched.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/sched/core_sched.c b/kernel/sched/core_sched.c index 38a2cec..ba2466c 100644 --- a/kernel/sched/core_sched.c +++ b/kernel/sched/core_sched.c @@ -75,7 +75,7 @@ static unsigned long sched_core_update_cookie(struct task_struct *p, old_cookie = p->core_cookie; p->core_cookie = cookie; - if (enqueued) + if (task_on_rq_queued(p)) sched_core_enqueue(rq, p); /* -- 1.8.3.1