From patchwork Wed Feb 6 16:14:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 157648 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp6589753jaa; Wed, 6 Feb 2019 08:14:35 -0800 (PST) X-Google-Smtp-Source: AHgI3IbHyL+S7KekkXtR9nJX2xDPPnhrwcjN3GzIi4aqfdYB6YaGHKKJytAYU+RIVWy3rRAE5s+t X-Received: by 2002:a62:6385:: with SMTP id x127mr11393391pfb.15.1549469675610; Wed, 06 Feb 2019 08:14:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549469675; cv=none; d=google.com; s=arc-20160816; b=xZgWaraQi1iN7GFdR2VsXyz4g6TV7xTLJTmlbqwCKSPHgsDwTxE2gAXLrt83pmN5+f ZGzxlE1M1CHpWqCDYeaDSWbUPAJE/vj4wtH6x1NJsMC/tZ2nIV86GpYV/sF+nvt3d95V ao76hsxCpt9EOMIQrqX96k/ffOQyl58qyTZHWS24o/kvscwhmDaJfpr4xGXMliHjIz18 12JwkclMYUnhcgWXMgtTetR2RDVPY2Adls8+wNftc8KAugocisU+d8vUyGwpWUOnTsiy c3hbpUljEuNs0SxDCUYopASYegNQybySu8Z+dDp0YgdxsTeOPhJlk1ArNZnY+foodQWI rk3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=EDVSHHteQjKl2FGFeIJNZ1MeClUNp/quRGzytDHcfMk=; b=Jkt0TvGNfIo4rCoLHIizD5bsDeB1bYHptQLlxG3zVHB4yzteaobLK8olZDrp0hodrl 4qFpzby3/KJxabXqpNaRiPNMhjyjRAzmATW+PHktuBujer1YhvHxFKugfXbPk19QjXuX XFRzKEvnGUQF3hvVJn7jXuFI5RjTkmEHZ41YMz8UR3QXWmq5kxZoRGqFj7QKqp4N3qXi 5HS9Ssj1ryAuxOQt6aLJLw6QcQvQAqH6SAcn7iLBwjWUAYA3CRFAxb0oFujvUWfvduHf 2ivt5FCts/zodN+KxEyvcB/P7ZNPC3M4rZsmWUzEwi0yqhWP2HaUvyBAUNFZw9AMOZ69 lbfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xZCxSRCm; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 142si6584186pfy.217.2019.02.06.08.14.35; Wed, 06 Feb 2019 08:14:35 -0800 (PST) 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; dkim=pass header.i=@linaro.org header.s=google header.b=xZCxSRCm; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730807AbfBFQOd (ORCPT + 31 others); Wed, 6 Feb 2019 11:14:33 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:37357 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729666AbfBFQOb (ORCPT ); Wed, 6 Feb 2019 11:14:31 -0500 Received: by mail-wr1-f68.google.com with SMTP id c8so1397982wrs.4 for ; Wed, 06 Feb 2019 08:14:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=EDVSHHteQjKl2FGFeIJNZ1MeClUNp/quRGzytDHcfMk=; b=xZCxSRCmUHLA5Pn7p3HteWgmDp/pBeQkOToANCesPf7qRj0nqnUASHBqao9AMFneWb zDqUU0PsOoKpTxfO92k1ITV16A68cAsXMJgCU1s2c8W7goNGmsbT5Q47ao1xfZLOb3lU CH07ysVe7hVMpRHlQeQxFccCttcTPANJNq6OcMOgPYT66jYyqbGPyUDhB74EVi7yyqWE swAWHKKrtP4MTPCtJNuOH5A+EXutiYbVRS5EuCd0B+1G4Odfa0IkKdYldTI2I6h1WCBd ebZhrIKLGmT2g37//8OFeX4n8MACv9Y9XTnaEmn9bms66kpUFYzkjlyapPxPAkWVcM/y 6vCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=EDVSHHteQjKl2FGFeIJNZ1MeClUNp/quRGzytDHcfMk=; b=RUp8whJV5vPOzfnosTR+/a3TJ7x4J/V0YLWDN81gT5XkAH1oq+RNcB5a05/9sk7m4p 8UcroiiNvVjShGzzqJDDEKR9wP+bvKxwqkn7hMkktdnhozmCm+M0N1lIGqddGNrQxynA /jIsg2HXyTpy6p20W3Nu6ukzB2M/q5WNPfnmKXP6hik6oQViYjYhWMvoCzkc8exOCWbJ QBJbD3cDRCgz8Ye/gOiK/rrxy7YezK77j5LZuzVpDMC24sBkgsFTeCGys0As75hxfSA/ iOCF4tsYgp5ev2MToTr24A0ykbjG1V+pVWM4x8HyvH+K+ouvCQaTMCF+HIZH+9l9sII8 iERA== X-Gm-Message-State: AHQUAuY2wP1E723jDIDZrbh7P6EWqRk+HioJgZVfrpcOCpzLIdLdB77l /DmDoxX8f9KsqXV4Yv66OBWBkKUVMhA= X-Received: by 2002:adf:ec83:: with SMTP id z3mr8829307wrn.264.1549469669652; Wed, 06 Feb 2019 08:14:29 -0800 (PST) Received: from localhost.localdomain ([2a01:e0a:f:6020:e4a1:3fb3:af18:c98a]) by smtp.gmail.com with ESMTPSA id y20sm27492328wra.51.2019.02.06.08.14.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 06 Feb 2019 08:14:28 -0800 (PST) From: Vincent Guittot To: linux-kernel@vger.kernel.org, mingo@redhat.com, peterz@infradead.org Cc: tj@kernel.org, sargun@sargun.me, xiexiuqi@huawei.com, xiezhipeng1@huawei.com, torvalds@linux-foundation.org, Vincent Guittot Subject: [PATCH 1/2] sched/fair: optimization of update_blocked_averages() Date: Wed, 6 Feb 2019 17:14:21 +0100 Message-Id: <1549469662-13614-2-git-send-email-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1549469662-13614-1-git-send-email-vincent.guittot@linaro.org> References: <1549469662-13614-1-git-send-email-vincent.guittot@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Removing a cfs_rq from rq->leaf_cfs_rq_list can break the parent/child ordering of the list when it will be added back. In order to remove an empty and fully decayed cfs_rq, we must remove its children too so they will be added back in the right order next time. With a normal decay of pelt, a parent will be empty and fully decayed if all children are empty and fully decayed too. In such a case, we just have to ensure that the whole branch will be added when a new task is enqueued. This is default behavior since : commit f6783319737f ("sched/fair: Fix insertion in rq->leaf_cfs_rq_list") In case of throttling, the pelt of throttled cfs_rq will not be updated whereas the parent will. This breaks the assumption made above unless we remove the children of a cfs_rq that is throttled. Then, they will be added back when unthrottled and a sched_entity will be enqueued. As throttled cfs_rq are now removed from the list, we can remove the associated test in update_blocked_averages(). Signed-off-by: Vincent Guittot --- kernel/sched/fair.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) -- 2.7.4 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index ffd1ae7..badf8173 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -346,6 +346,18 @@ static inline bool list_add_leaf_cfs_rq(struct cfs_rq *cfs_rq) static inline void list_del_leaf_cfs_rq(struct cfs_rq *cfs_rq) { if (cfs_rq->on_list) { + struct rq *rq = rq_of(cfs_rq); + + /* + * With cfs_rq being unthrottled/throttled during an enqueue, + * it can happen the tmp_alone_branch points the a leaf that + * we finally want to del. In this case, tmp_alone_branch moves + * to the prev element but it will point to rq->leaf_cfs_rq_list + * at the end of the enqueue. + */ + if (rq->tmp_alone_branch == &cfs_rq->leaf_cfs_rq_list) + rq->tmp_alone_branch = cfs_rq->leaf_cfs_rq_list.prev; + list_del_rcu(&cfs_rq->leaf_cfs_rq_list); cfs_rq->on_list = 0; } @@ -4438,6 +4450,10 @@ static int tg_unthrottle_up(struct task_group *tg, void *data) /* adjust cfs_rq_clock_task() */ cfs_rq->throttled_clock_task_time += rq_clock_task(rq) - cfs_rq->throttled_clock_task; + + /* Add cfs_rq with already running entity in the list */ + if (cfs_rq->nr_running >= 1) + list_add_leaf_cfs_rq(cfs_rq); } return 0; @@ -4449,8 +4465,10 @@ static int tg_throttle_down(struct task_group *tg, void *data) struct cfs_rq *cfs_rq = tg->cfs_rq[cpu_of(rq)]; /* group is entering throttled state, stop time */ - if (!cfs_rq->throttle_count) + if (!cfs_rq->throttle_count) { cfs_rq->throttled_clock_task = rq_clock_task(rq); + list_del_leaf_cfs_rq(cfs_rq); + } cfs_rq->throttle_count++; return 0; @@ -7699,10 +7717,6 @@ static void update_blocked_averages(int cpu) for_each_leaf_cfs_rq(rq, cfs_rq) { struct sched_entity *se; - /* throttled entities do not contribute to load */ - if (throttled_hierarchy(cfs_rq)) - continue; - if (update_cfs_rq_load_avg(cfs_rq_clock_pelt(cfs_rq), cfs_rq)) update_tg_load_avg(cfs_rq, 0);