Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp6022560ybi; Wed, 12 Jun 2019 12:34:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqxki0oinT8zOoRON0XUr/re55sxFVwBhPtX/5GQ898tImwlctObEb/ew/NRGY26pUg0dGon X-Received: by 2002:a17:902:2aa8:: with SMTP id j37mr41618954plb.316.1560368068772; Wed, 12 Jun 2019 12:34:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560368068; cv=none; d=google.com; s=arc-20160816; b=TfVUfFRHW03ACVNx3IyEQXdAhR+8LKzQ7Nk1QZKi/xGcbLgvKgUGf7t+rNMKM1hS4R 0IJXvDXysHjildu9ODTsamYfAveOXZUaOadsbixYfgQh5dkMBeWu05lEiZV923AxEK4I q5u3+kKtivj/yKNIgdTH4FFGy4i+QIVJsrqR24NfCeYMlbXwDA08QIwnhIQPv9XmYmG7 6N79w0hTMR20i6PjC+9X/83U3igiVL5+dqJLmg7vulyuHk1PUG4etcK3BaQ0N4KGnuP+ AeHU2PbjBHNcinXArmIWD377a2bGJ1wUWHdXGUchf/fhKNf4R0DqXvcIbhWpFisBTsbe Bsng== 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=pAUL5SULkLxDGplbqYZ53sL5JH7qo4QecMLmEzu9v3U=; b=L7TNGygoouLHO6GhxB2AQF/mo/60SdEekn19AOSlmYdQRDUe9jsOZx046uATzolk2Y Q2tyuW7D3vFKY3/rbS1Duwn8da/3nSvQEdaeCQwQMOVBs7OxABM8Y7oYz9wOfrgDtyKB zO7shlVrs4ouzb4ICKvCev9BJdQmPg9jGU0R6Ys1xN5gY0ZmOKMDfbL41PZMKMgT14hN dXUM43z5a9lQxQZDuKcnrcxEJIPORsQlPz/4dg/qUaMqqoWBxqU8pUOvjJ74Hmx8NnA2 AI8/E9XzOy3EE6XvZd88jIuvURYelvXWB770rbhi9CVV4eVsm1VODwqN/o1pwE5gifcf 12iA== 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 b4si476225plz.225.2019.06.12.12.34.14; Wed, 12 Jun 2019 12:34:28 -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 S1728693AbfFLTcs (ORCPT + 99 others); Wed, 12 Jun 2019 15:32:48 -0400 Received: from shelob.surriel.com ([96.67.55.147]:50490 "EHLO shelob.surriel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728524AbfFLTcs (ORCPT ); Wed, 12 Jun 2019 15:32:48 -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 1hb8z1-0001BN-VX; Wed, 12 Jun 2019 15:32:31 -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 4/8] sched,fair: remove cfs rqs from leaf_cfs_rq_list bottom up Date: Wed, 12 Jun 2019 15:32:23 -0400 Message-Id: <20190612193227.993-5-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 Reducing the overhead of the CPU controller is achieved by not walking all the sched_entities every time a task is enqueued or dequeued. One of the things being checked every single time is whether the cfs_rq is on the rq->leaf_cfs_rq_list. By only removing a cfs_rq from the list once it no longer has children on the list, we can avoid walking the sched_entity hierarchy if the bottom cfs_rq is on the list, once the runqueues have been flattened. Signed-off-by: Rik van Riel --- kernel/sched/fair.c | 17 +++++++++++++++++ kernel/sched/sched.h | 1 + 2 files changed, 18 insertions(+) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index aebd43d74468..dcc521d251e3 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -285,6 +285,13 @@ static inline bool list_add_leaf_cfs_rq(struct cfs_rq *cfs_rq) cfs_rq->on_list = 1; + /* + * If the tmp_alone_branch cursor was moved, it means a child cfs_rq + * is already on the list ahead of us. + */ + if (rq->tmp_alone_branch != &rq->leaf_cfs_rq_list) + cfs_rq->children_on_list++; + /* * Ensure we either appear before our parent (if already * enqueued) or force our parent to appear after us when it is @@ -310,6 +317,7 @@ static inline bool list_add_leaf_cfs_rq(struct cfs_rq *cfs_rq) * list. */ rq->tmp_alone_branch = &rq->leaf_cfs_rq_list; + cfs_rq->tg->parent->cfs_rq[cpu]->children_on_list++; return true; } @@ -358,6 +366,11 @@ static inline void list_del_leaf_cfs_rq(struct cfs_rq *cfs_rq) if (rq->tmp_alone_branch == &cfs_rq->leaf_cfs_rq_list) rq->tmp_alone_branch = cfs_rq->leaf_cfs_rq_list.prev; + if (cfs_rq->tg->parent) { + int cpu = cpu_of(rq); + cfs_rq->tg->parent->cfs_rq[cpu]->children_on_list--; + } + list_del_rcu(&cfs_rq->leaf_cfs_rq_list); cfs_rq->on_list = 0; } @@ -7688,6 +7701,10 @@ static inline bool cfs_rq_is_decayed(struct cfs_rq *cfs_rq) if (cfs_rq->avg.util_sum) return false; + /* Remove decayed parents once their decayed children are gone. */ + if (cfs_rq->children_on_list) + return false; + return true; } diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 5be14cee61f9..18494b1a9bac 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -556,6 +556,7 @@ struct cfs_rq { * This list is used during load balance. */ int on_list; + int children_on_list; struct list_head leaf_cfs_rq_list; struct task_group *tg; /* group that "owns" this runqueue */ -- 2.20.1