Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp2528457rdb; Wed, 15 Nov 2023 03:35:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IFp8/54uaTJyyYJXs++xjCemSV7O1iDZM9lx7SwmvavnSQP4ebbkWSSXAiXxu8rhAhjDNqF X-Received: by 2002:a17:902:e552:b0:1cc:2c45:757a with SMTP id n18-20020a170902e55200b001cc2c45757amr5511234plf.10.1700048099742; Wed, 15 Nov 2023 03:34:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700048099; cv=none; d=google.com; s=arc-20160816; b=iBfCajwfs1xeCqQiPdSvDYaIex44hAZrn5KEAtL0K420len5ScRKsgV4lCxRinyDDN +Ut3G90guhl+lsWTQNjPqfDLIdiUfHGyG5zmgSF4G1ro9Q9jChhAA6F+t/U/SSuMCAU9 NUFpWQaieq95RiSKCLpWjlRKybU6/v42noBfwi9khxXXO4wPuj8B/W7HeA9VJlGfz8ui Y2u1NtapXaUGSrh4MLSL8Ptrk2Q7B0amkTmt0degwzk8h5DDzn0lNkSH7Mv1IPUnBmvl wXBD3muSib9iY7Lc/L2Nl+x3TBwO0d6jishT0Y0UTlCG2I5/UZngr+cMHuNO7+1yI4z1 jzpg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=uaycZAxoOJkvDTnIxYpCXWAhUOBGd20vZXyAVgu3ZtQ=; fh=QlmRtWuTYJDhaxF0GCu0nvK7RUqeTMNKD6hMg0kv7eo=; b=sKSLjDO1rC9HYOc7Hz+Eh6u2UPRghJWko0QmTa1xEkkwgYM4zA3ymJTdwvTCFlbp5H Q36+MXY9Hq4hfCunPY0UeztYwTgVpyLaJcjfR7X7zTrStNGBqYVzxiLfevIoplhcLSnM In2anofVgbMx92Wjq70YMFgWIUJNKRUzBlUkxCe7dlUo7SUjSOb2r0sNs/f+1G169STY o6hXodVgcw1tY6EnBXdjCYpiPLrX69aNiFhswDXukXBhBsx5C1uml0+bUzqZHHyDyOHu i0cJzDJO+3fDSYccEnctiujMBdZw10k46DAQcxdXE7M+BQsYlmeTkYlQuxuIwjKTHzeG fqnQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id u8-20020a170902bf4800b001cdfbd8790esi9798788pls.173.2023.11.15.03.34.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 03:34:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id CE56380C2551; Wed, 15 Nov 2023 03:34:50 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234963AbjKOLeF (ORCPT + 99 others); Wed, 15 Nov 2023 06:34:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234922AbjKOLd6 (ORCPT ); Wed, 15 Nov 2023 06:33:58 -0500 Received: from out30-133.freemail.mail.aliyun.com (out30-133.freemail.mail.aliyun.com [115.124.30.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F7CD11C for ; Wed, 15 Nov 2023 03:33:54 -0800 (PST) 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=ay29a033018045176;MF=cruzzhao@linux.alibaba.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---0VwSxxNu_1700048032; Received: from localhost.localdomain(mailfrom:CruzZhao@linux.alibaba.com fp:SMTPD_---0VwSxxNu_1700048032) by smtp.aliyun-inc.com; Wed, 15 Nov 2023 19:33:52 +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, vschneid@redhat.com, joel@joelfernandes.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH 3/4] sched/fair: introduce core_vruntime and core_min_vruntime Date: Wed, 15 Nov 2023 19:33:40 +0800 Message-Id: <20231115113341.13261-4-CruzZhao@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231115113341.13261-1-CruzZhao@linux.alibaba.com> References: <20231115113341.13261-1-CruzZhao@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 15 Nov 2023 03:34:51 -0800 (PST) To compare the priority of sched_entity from different cpus of a core, we introduce core_vruntime to struct sched_entity and core_min_vruntime to struct cfs_rq. cfs_rq->core->core_min_vruntime records the min vruntime of the cfs_rqs of the same task_group among the core, and se->core_vruntime is the vruntime relative to se->cfs_rq->core->core_min_vruntime. Signed-off-by: Cruz Zhao --- include/linux/sched.h | 3 +++ kernel/sched/fair.c | 52 ++++++++++++++++++++++++++++++++++++++----- kernel/sched/sched.h | 1 + 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index 292c31697248..df481a8ebc07 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -562,6 +562,9 @@ struct sched_entity { u64 sum_exec_runtime; u64 prev_sum_exec_runtime; u64 vruntime; +#ifdef CONFIG_SCHED_CORE + u64 core_vruntime; +#endif s64 vlag; u64 slice; diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 61cbaa3cc385..60b2fd437474 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -750,30 +750,58 @@ static u64 __update_min_vruntime(struct cfs_rq *cfs_rq, u64 vruntime) return min_vruntime; } +#ifdef CONFIG_SCHED_CORE +static u64 __update_core_min_vruntime(struct cfs_rq *cfs_rq, u64 vruntime) +{ + u64 min_vruntime = cfs_rq->core_min_vruntime; + s64 delta = (s64)(vruntime - min_vruntime); + + return delta > 0 ? vruntime : min_vruntime; +} +#endif + static void update_min_vruntime(struct cfs_rq *cfs_rq) { struct sched_entity *se = __pick_first_entity(cfs_rq); struct sched_entity *curr = cfs_rq->curr; u64 vruntime = cfs_rq->min_vruntime; +#ifdef CONFIG_SCHED_CORE + u64 core_vruntime = cfs_rq->core->min_vruntime; +#endif if (curr) { - if (curr->on_rq) + if (curr->on_rq) { vruntime = curr->vruntime; - else +#ifdef CONFIG_SCHED_CORE + core_vruntime = curr->core_vruntime; +#endif + } else { curr = NULL; + } } if (se) { - if (!curr) + if (!curr) { vruntime = se->vruntime; - else +#ifdef CONFIG_SCHED_CORE + core_vruntime = se->core_vruntime; +#endif + } else { vruntime = min_vruntime(vruntime, se->vruntime); +#ifdef CONFIG_SCHED_CORE + core_vruntime = min_vruntime(core_vruntime, se->core_vruntime); +#endif + } } /* ensure we never gain time by being placed backwards. */ u64_u32_store(cfs_rq->min_vruntime, __update_min_vruntime(cfs_rq, vruntime)); +#ifdef CONFIG_SCHED_CORE + u64_u32_store(cfs_rq->core->core_min_vruntime, + __update_core_min_vruntime(cfs_rq->core, vruntime)); +#endif } static inline bool __entity_less(struct rb_node *a, const struct rb_node *b) @@ -1137,6 +1165,7 @@ static void update_curr(struct cfs_rq *cfs_rq) struct sched_entity *curr = cfs_rq->curr; u64 now = rq_clock_task(rq_of(cfs_rq)); u64 delta_exec; + u64 delta_exec_fair; if (unlikely(!curr)) return; @@ -1158,7 +1187,11 @@ static void update_curr(struct cfs_rq *cfs_rq) curr->sum_exec_runtime += delta_exec; schedstat_add(cfs_rq->exec_clock, delta_exec); - curr->vruntime += calc_delta_fair(delta_exec, curr); + delta_exec_fair = calc_delta_fair(delta_exec, curr); + curr->vruntime += delta_exec_fair; +#ifdef CONFIG_SCHED_CORE + curr->core_vruntime += delta_exec_fair; +#endif update_deadline(cfs_rq, curr); update_min_vruntime(cfs_rq); @@ -5009,6 +5042,9 @@ static void place_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) { u64 vslice, vruntime = avg_vruntime(cfs_rq); +#ifdef CONFIG_SCHED_CORE + u64 core_vruntime = cfs_rq->core->core_min_vruntime + vruntime - cfs_rq->min_vruntime; +#endif s64 lag = 0; se->slice = sysctl_sched_base_slice; @@ -5091,6 +5127,9 @@ place_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) } se->vruntime = vruntime - lag; +#ifdef CONFIG_SCHED_CORE + se->core_vruntime = core_vruntime - lag; +#endif /* * When joining the competition; the exisiting tasks will be, @@ -12655,6 +12694,9 @@ void init_cfs_rq(struct cfs_rq *cfs_rq) { cfs_rq->tasks_timeline = RB_ROOT_CACHED; u64_u32_store(cfs_rq->min_vruntime, (u64)(-(1LL << 20))); +#ifdef CONFIG_SCHED_CORE + u64_u32_store(cfs_rq->core_min_vruntime, (u64)(-(1LL << 20))); +#endif #ifdef CONFIG_SMP raw_spin_lock_init(&cfs_rq->removed.lock); #endif diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 62fca54223a1..f9d3701481f1 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -545,6 +545,7 @@ struct cfs_rq { u64 exec_clock; u64 min_vruntime; #ifdef CONFIG_SCHED_CORE + u64 core_min_vruntime; unsigned int forceidle_seq; u64 min_vruntime_fi; struct cfs_rq *core; -- 2.39.3