Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp6023637ybi; Wed, 12 Jun 2019 12:35:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqxZXvHt0mDSnTjJyCqZM99pyJNyR5nFj0goUDhZtSflCLtHe2Ex8BdXCYaOB4pUmeaQSPyO X-Received: by 2002:a63:191b:: with SMTP id z27mr26174446pgl.327.1560368141106; Wed, 12 Jun 2019 12:35:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560368141; cv=none; d=google.com; s=arc-20160816; b=sG5quuOgQf0hr9ZFmtp2jLPRukd+TmXcdth5FCuE7Ir8/DUSNoI2tlbOZSJZnvAFzi SZ8NY4hAS9M3empUNoNVYD64M8j5uhSAms/iZNESAUgFaOrgUU5LGQ6HGE6rWkyR3spf vSFPsEG5ju5itOfc5mG10FFWzgzvLa9S6qABfzGsgVX6HfXk/Emmwd6zzmaSwLnS9eKq 99EBLXz6ZY3hFror3e+F+CuUCmDP2tqh1snzJMkBc7hDJefxKsqabpvH1GfU1hgLoNNO SZGZl8Ld9fXko9Qn27pXo2nswsJmmoZF7obcU1zbHtN2lfErLFpUBl2BJMI5+Yt5J1A0 23MQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=+eVeHb2+GlrBW0finozHg2fAyDmgkRBFuSihaYiLiYs=; b=d6w/7MBmzkzG+XEpJmChn86hNu0mAO71jkIjDIEXkSq6kKlx0tvSREzCEr1hJEgpER 5MfElSeQy7DDjAevkTFwtj59fUXE417Z48a6cYfKTqbk1XgWSOGmGHJ8CU/f1l9jJerc m0C2K8RaUuu84u32Cq1k63axoeBXnqvSGMpxAajBGSdnvVbMHUOo9zZkxD9ttDHjT15u aYZw++6kPyGEaQFmCYItbVzeDesiKR2afssDiKnpBjVlFKTJLqeMuXaymV995+S/ZXA/ li8NWDgNvob+Jb3PcUEHbVzsngRVPiaF9hk6FZ/YBkEDNuNTkuBbnV31Whni9S8oNJfa eF6g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s20si472864plq.139.2019.06.12.12.35.24; Wed, 12 Jun 2019 12:35:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728904AbfFLTdF (ORCPT + 99 others); Wed, 12 Jun 2019 15:33:05 -0400 Received: from shelob.surriel.com ([96.67.55.147]:50474 "EHLO shelob.surriel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728503AbfFLTct (ORCPT ); Wed, 12 Jun 2019 15:32:49 -0400 Received: from imladris.surriel.com ([96.67.55.152]) by shelob.surriel.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92) (envelope-from ) id 1hb8z2-0001BN-2Y; Wed, 12 Jun 2019 15:32:32 -0400 From: Rik van Riel To: peterz@infradead.org Cc: mingo@redhat.com, linux-kernel@vger.kernel.org, kernel-team@fb.com, morten.rasmussen@arm.com, tglx@linutronix.de, dietmar.eggeman@arm.com, mgorman@techsingularity.com, vincent.guittot@linaro.org, Rik van Riel Subject: [PATCH 7/8] sched,fair: refactor enqueue/dequeue_entity Date: Wed, 12 Jun 2019 15:32:26 -0400 Message-Id: <20190612193227.993-8-riel@surriel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190612193227.993-1-riel@surriel.com> References: <20190612193227.993-1-riel@surriel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Refactor enqueue_entity, dequeue_entity, and update_load_avg, in order to split out the things we still want to happen at every level in the cgroup hierarchy with a flat runqueue from the things we only need to happen once. No functional changes. Signed-off-by: Rik van Riel --- kernel/sched/fair.c | 65 +++++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 23 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 35153a89d5c5..c2baf3c8a879 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -3481,17 +3481,17 @@ static void detach_entity_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *s #define DO_ATTACH 0x4 /* Update task and its cfs_rq load average */ -static inline void update_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) +static inline bool update_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) { u64 now = cfs_rq_clock_pelt(cfs_rq); - int decayed; + int decayed, updated = 0; /* * Track task load average for carrying it to new CPU after migrated, and * track group sched_entity load average for task_h_load calc in migration */ if (se->avg.last_update_time && !(flags & SKIP_AGE_LOAD)) - __update_load_avg_se(now, cfs_rq, se); + updated = __update_load_avg_se(now, cfs_rq, se); decayed = update_cfs_rq_load_avg(now, cfs_rq); decayed |= propagate_entity_load_avg(se); @@ -3510,6 +3510,8 @@ static inline void update_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *s } else if (decayed && (flags & UPDATE_TG)) update_tg_load_avg(cfs_rq, 0); + + return decayed | updated; } #ifndef CONFIG_64BIT @@ -3851,6 +3853,24 @@ static inline void check_schedstat_required(void) * CPU and an up-to-date min_vruntime on the destination CPU. */ +static bool +enqueue_entity_groups(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) +{ + /* + * When enqueuing a sched_entity, we must: + * - Update loads to have both entity and cfs_rq synced with now. + * - Add its load to cfs_rq->runnable_avg + * - For group_entity, update its weight to reflect the new share of + * its group cfs_rq + * - Add its new weight to cfs_rq->load.weight + */ + if (!update_load_avg(cfs_rq, se, UPDATE_TG | DO_ATTACH)) + return false; + + update_cfs_group(se); + return true; +} + static void enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) { @@ -3875,16 +3895,6 @@ enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) if (renorm && !curr) se->vruntime += cfs_rq->min_vruntime; - /* - * When enqueuing a sched_entity, we must: - * - Update loads to have both entity and cfs_rq synced with now. - * - Add its load to cfs_rq->runnable_avg - * - For group_entity, update its weight to reflect the new share of - * its group cfs_rq - * - Add its new weight to cfs_rq->load.weight - */ - update_load_avg(cfs_rq, se, UPDATE_TG | DO_ATTACH); - update_cfs_group(se); enqueue_runnable_load_avg(cfs_rq, se); account_entity_enqueue(cfs_rq, se); @@ -3951,14 +3961,9 @@ static void clear_buddies(struct cfs_rq *cfs_rq, struct sched_entity *se) static __always_inline void return_cfs_rq_runtime(struct cfs_rq *cfs_rq); -static void -dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) +static bool +dequeue_entity_groups(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) { - /* - * Update run-time statistics of the 'current'. - */ - update_curr(cfs_rq); - /* * When dequeuing a sched_entity, we must: * - Update loads to have both entity and cfs_rq synced with now. @@ -3967,7 +3972,21 @@ dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) * - For group entity, update its weight to reflect the new share * of its group cfs_rq. */ - update_load_avg(cfs_rq, se, UPDATE_TG); + if (!update_load_avg(cfs_rq, se, UPDATE_TG)) + return false; + update_cfs_group(se); + + return true; +} + +static void +dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) +{ + /* + * Update run-time statistics of the 'current'. + */ + update_curr(cfs_rq); + dequeue_runnable_load_avg(cfs_rq, se); update_stats_dequeue(cfs_rq, se, flags); @@ -3991,8 +4010,6 @@ dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) /* return excess runtime on last dequeue */ return_cfs_rq_runtime(cfs_rq); - update_cfs_group(se); - /* * Now advance min_vruntime if @se was the entity holding it back, * except when: DEQUEUE_SAVE && !DEQUEUE_MOVE, in this case we'll be @@ -5157,6 +5174,7 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags) if (se->on_rq) break; cfs_rq = cfs_rq_of(se); + enqueue_entity_groups(cfs_rq, se, flags); enqueue_entity(cfs_rq, se, flags); /* @@ -5239,6 +5257,7 @@ static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags) for_each_sched_entity(se) { cfs_rq = cfs_rq_of(se); + dequeue_entity_groups(cfs_rq, se, flags); dequeue_entity(cfs_rq, se, flags); /* -- 2.20.1