From patchwork Sun Mar 19 07:56:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wuchi X-Patchwork-Id: 71718 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp631237wrt; Sun, 19 Mar 2023 01:11:25 -0700 (PDT) X-Google-Smtp-Source: AK7set+xPxD1DZRqarzAqM/HTKIWbgmWzYSH2HLU5XUaGXdIdDg2oHX+Jc7tYgP/9jyo6h/HP6fa X-Received: by 2002:a17:903:2283:b0:19e:7c33:3722 with SMTP id b3-20020a170903228300b0019e7c333722mr16530486plh.40.1679213485472; Sun, 19 Mar 2023 01:11:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679213485; cv=none; d=google.com; s=arc-20160816; b=ooZAivQqpVBwZ5+QxG9B5btVXnzlAodjom49vTgQwm1k4iP0AXdY5satplOiLPz97K HerJkBHhrTJkTT1CMfGPxgbeuCvMPdsEM8OVPufjmLFlkLMa7mLMMytoKymiEsZxLRA6 Ssm423Wbx8CZtEREvwW0qCKqSfr9FWPmplPN2/LUrnF1z6+8UMWhB3NTNjwWxmhu8VoI Tj35C6t7fxbLRaNYojox2+HwdLRXP40FUc75hwQ8J5aKGQnWHXbaS44fKLvV3KtdeZJ+ L3r6Zl2dN9BltUj8fPbhySgJxl6U7CHe5ZTjZRsKme+eqyZD4C+3JapaF+mlDZMA3BqG X3iA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=pZUnST3j21m9F9a4UvCxqzWQ39NSngcoRf1fNjlPMo0=; b=r0HT/keOnzEYFH3PwpDFQM8qGsQK7Drs2Y4wNbq8G/gbkaQtWg8eVvJ/ZaNySC1D8g 3AsceUZtCFPEuGxoy7kfkhqf1HxTBEZSZBzLYOOYI/JdQE8UHKUrdvLJWmmrDw4txxCU 3hd180FiGRw8KmiLruE0RG6WGLCduAjzZwZYiIVfBf6Nn0xOle1beA/TQUL88TPQElyo cXDzK+Dq5Zcgk4ZkirFfx1ZhmM0LsI0P/+NSZVFGhB0+sfkixIpORRhCALOo3G5LVhgr abKbij7thztgUk9DbXxcoo36j1QTZ1mVDnYlogghUvAyRDKZWgeJkqgME2WINfWZKLFY K3xQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=FCcBCCEN; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kl6-20020a170903074600b0019aacc74ea2si6692637plb.386.2023.03.19.01.11.10; Sun, 19 Mar 2023 01:11:25 -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; dkim=pass header.i=@gmail.com header.s=20210112 header.b=FCcBCCEN; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230032AbjCSH5N (ORCPT + 99 others); Sun, 19 Mar 2023 03:57:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229468AbjCSH5J (ORCPT ); Sun, 19 Mar 2023 03:57:09 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84AA0EF93 for ; Sun, 19 Mar 2023 00:56:51 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id p20so9477949plw.13 for ; Sun, 19 Mar 2023 00:56:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679212611; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=pZUnST3j21m9F9a4UvCxqzWQ39NSngcoRf1fNjlPMo0=; b=FCcBCCENooJi8ff/XjxTocVx4aMrEp949GQloXOFJwFmaSniqIumwl/FfGil8QZoBS VjFYllNxi0mhg52pG17LuMdNRyvkt69qvEEpEI71390aK9ugaiwnbjacM1SDOcvCUDVS JLHte1i/kvKD5Dxf7G/WvCUrkChH5CCAuWlxryrWo8Gk1CpOAm/q/JXtsJ7bKRrshpJH hxrs/MDFqDQjy/Bh/Sr9Ov55FYgDp9HsLo1AIHU7+EhmHxQFD/5rqoGHX84hmT+ldCX0 OJ150t+Y6ZISDY2aOXRlLdmVZbFnSkg62AHQ2hp10K3Wj8k1QFHk957f1peVB0VfK1sW v4LQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679212611; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=pZUnST3j21m9F9a4UvCxqzWQ39NSngcoRf1fNjlPMo0=; b=aZJQkHIKjpr9sgf/VUmxqf1ZIP/cLWwEkXSnIuxDU9ZDgcddcTlaa0wSwM0WphsaQm fjjb/0lqQYYR7DQgM2qrszE+D+pc3lb3Otc+8q3gOWyPlZsheTpw++KU8FhnoaiVxCjO bOrEegmQfccDGeQAq/HNeO4GvpFebcau7qLIFsPQNX+e1vOFIHWBU3tLsRJqnOv0k26U rqJyIjw/aTDtHpKuJY5RVk+UsKyRASYC0A7DrXNtzIniqvAg8D7HiYzfZI9NJPzt/nNC H/PkZbdrcoklzkJC/5cuQFwLlXChNZRHY35uCEDo+5kQT1P767nlSsaGeqkSb96BcPpp FipA== X-Gm-Message-State: AO0yUKXUHQieh6MqB5TjqRO5I7RbYCI+z82H1GQEfbn4l3RlPnPJ1Zg6 Ke3Wul4K2evXvoN3XkVciH7Tb1FFhJayNw== X-Received: by 2002:a17:902:f681:b0:19e:8076:9bd2 with SMTP id l1-20020a170902f68100b0019e80769bd2mr15021430plg.17.1679212610839; Sun, 19 Mar 2023 00:56:50 -0700 (PDT) Received: from localhost.localdomain ([139.177.225.237]) by smtp.gmail.com with ESMTPSA id p11-20020a170902bd0b00b001994e74c094sm4307797pls.275.2023.03.19.00.56.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Mar 2023 00:56:50 -0700 (PDT) From: wuchi 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 Cc: linux-kernel@vger.kernel.org Subject: [PATCH] sched/core: Reduce cost of sched_move_task when config autogroup Date: Sun, 19 Mar 2023 15:56:43 +0800 Message-Id: <20230319075643.28312-1-wuchi.zero@gmail.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760782959536788568?= X-GMAIL-MSGID: =?utf-8?q?1760782959536788568?= Some sched_move_task calls of autogroup is useless when the task_struct->sched_task_group isn't changed because of task_group of cpu_cgroup overlay task_group of autogroup. The overlay key codes are as follows: sched_cgroup_fork->autogroup_task_group->task_wants_autogroup sched_change_group->autogroup_task_group->autogroup_task_group sched_move_task eg: task A belongs to cpu_cgroup0 and autogroup0, it will always to cpu_cgroup0 when doing exit. So there is no need to do {de|en}queue. The call graph is as follow. do_exit sched_autogroup_exit_task sched_move_task dequeue_task sched_change_group A.sched_task_group = sched_get_task_group enqueue_task So do some check before dequeue task in sched_move_task. Signed-off-by: wuchi --- kernel/sched/core.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index a380f34789a2..acc9a0e391f4 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -10330,7 +10330,7 @@ void sched_release_group(struct task_group *tg) spin_unlock_irqrestore(&task_group_lock, flags); } -static void sched_change_group(struct task_struct *tsk) +static struct task_group *sched_get_task_group(struct task_struct *tsk) { struct task_group *tg; @@ -10342,7 +10342,28 @@ static void sched_change_group(struct task_struct *tsk) tg = container_of(task_css_check(tsk, cpu_cgrp_id, true), struct task_group, css); tg = autogroup_task_group(tsk, tg); - tsk->sched_task_group = tg; + + return tg; +} + +static bool sched_task_group_changed(struct task_struct *tsk) +{ + /* + * Some sched_move_task calls of autogroup is useless when the + * task_struct->sched_task_group isn't changed because of task_group + * of cpu_cgroup overlay task_group of autogroup. so do some check + * before dequeue task in sched_move_task. + */ +#ifdef CONFIG_SCHED_AUTOGROUP + return sched_get_task_group(tsk) != tsk->sched_task_group; +#else + return true; +#endif /* CONFIG_SCHED_AUTOGROUP */ +} + +static void sched_change_group(struct task_struct *tsk) +{ + tsk->sched_task_group = sched_get_task_group(tsk); #ifdef CONFIG_FAIR_GROUP_SCHED if (tsk->sched_class->task_change_group) @@ -10369,6 +10390,9 @@ void sched_move_task(struct task_struct *tsk) rq = task_rq_lock(tsk, &rf); update_rq_clock(rq); + if (!sched_task_group_changed(tsk)) + goto unlock; + running = task_current(rq, tsk); queued = task_on_rq_queued(tsk); @@ -10391,6 +10415,7 @@ void sched_move_task(struct task_struct *tsk) resched_curr(rq); } +unlock: task_rq_unlock(rq, tsk, &rf); }