Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp27310ybd; Fri, 28 Jun 2019 13:50:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqwSBJXiynhiK84RFNbwj8fuljijVjM81xCendKWPVKu4Tm29DMwwFrf1VQEeHtERH2Axnn+ X-Received: by 2002:a63:7c0e:: with SMTP id x14mr10946997pgc.65.1561755052596; Fri, 28 Jun 2019 13:50:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561755052; cv=none; d=google.com; s=arc-20160816; b=V2rjn/iQHghnR8f77wk4ste4HAYGUQjxYs+NBZqJZO7/K5LBpKBlGBDU151nAekI63 wC0xJxXSxFua4q3CnMgPPnxyq0aeT3FBETqAeEDG3PFxkuxShjV/HshfmjaYpeAg2vA8 M0lskMxw48PopsGAzPSTzdxZSZijgDvDuVlmTl4nTqgzPe/CKcq88uL26qwOOc+XThMG zkNRAT3t4yk4S870byxr4a3RvV5WzzOP17/ceWGlOdmSDBUhCmH0F5r55omp0XnFEveJ Ax827GUMr8fALEEjT/u+BBt28iMcrZHSH4f/GE+H+E1QoDiayZkIyYitr3QA6PaC6rLf /o3w== 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=eAkhVnA1DiWekDqx1VgephStnT/E0m1vcR0VEzIkw60=; b=LU0zjl0QvusHtwAkN7NIG7MVokXbpz/XTqNZQdgjNjljM+gEjqeez64lq3Y6WWFkQL sfwhHGm68HskxoMK4pYndVAZEZTdkCCeMLQFN8L2iGKljMEK3uJrjRvUPHIWrHKJUGCJ S/GND07QMWlgYWaEXoPbgHiBTaDTtgoSwuLZjruhi0Rhsm/BEFB4y7/0Lntc+d5k5lrp UDexei5bjdz1J7X6wpx30Af5SqzC/uuguh/KegUhNmkiOuk5tXZIgG0ug8xTLR1iACwe Iyi8yieFksTGASY96ZYcbg9SWHdyo4EvkF8N5P1BmFI8FAxAZyfJ1dZKM1G5V3tayyPv +pLA== 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 w2si2908139pgr.396.2019.06.28.13.50.36; Fri, 28 Jun 2019 13:50:52 -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 S1726835AbfF1Utg (ORCPT + 99 others); Fri, 28 Jun 2019 16:49:36 -0400 Received: from shelob.surriel.com ([96.67.55.147]:38548 "EHLO shelob.surriel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726789AbfF1Utg (ORCPT ); Fri, 28 Jun 2019 16:49:36 -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 1hgxo6-0007TL-Nu; Fri, 28 Jun 2019 16:49:18 -0400 From: Rik van Riel To: linux-kernel@vger.kernel.org Cc: kernel-team@fb.com, pjt@google.com, dietmar.eggemann@arm.com, peterz@infradead.org, mingo@redhat.com, morten.rasmussen@arm.com, tglx@linutronix.de, mgorman@techsingularity.net, vincent.guittot@linaro.org, Rik van Riel Subject: [PATCH 08/10] sched,fair: refactor enqueue/dequeue_entity Date: Fri, 28 Jun 2019 16:49:11 -0400 Message-Id: <20190628204913.10287-9-riel@surriel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190628204913.10287-1-riel@surriel.com> References: <20190628204913.10287-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 | 64 +++++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 22 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 8da2823401ca..a751e7a9b228 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -3480,7 +3480,7 @@ 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; @@ -3509,6 +3509,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; } #ifndef CONFIG_64BIT @@ -3725,9 +3727,10 @@ static inline void update_misfit_status(struct task_struct *p, struct rq *rq) #define SKIP_AGE_LOAD 0x0 #define DO_ATTACH 0x0 -static inline void update_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *se, int not_used1) +static inline bool update_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *se, int not_used1) { cfs_rq_util_change(cfs_rq, 0); + return false; } static inline void remove_entity_load_avg(struct sched_entity *se) {} @@ -3850,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) { @@ -3874,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); @@ -3950,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. @@ -3966,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); @@ -3990,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 @@ -5156,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); /* @@ -5238,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