Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1900984pxb; Sun, 31 Oct 2021 03:19:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwl/xyqO7098OlbPGlHwslnbZuWqCPGFZ4woMS7J2vo0lxJztAVI8X5phuuXibUTsYggUKf X-Received: by 2002:a05:6e02:1562:: with SMTP id k2mr14971290ilu.135.1635675580274; Sun, 31 Oct 2021 03:19:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635675580; cv=none; d=google.com; s=arc-20160816; b=rZ5GRiMG5Nzv/vJZY1FLJVwjAsfafNFW6zELBRuqh8J+nvKXkhvMOQd2wnLNc+fZts JnK7lUOZ7jLVEImHlJ0BIKTGZMl39uTIHyCDVR1yI5HP/uVD1TS8Pz/5Q3ydeZTgwDb4 dAefc4zHnIu0B44AALFF5tmJ9S9Ll7n6t7ixz9S/SR+z3Nfk8KZN4mr/hqoskIu9/G8j aSRGhhZYdxU8xdOFq6DObANynThv3u7y8Dq6o2IGlIeS6eqMODZ0fmbY+vjFdPvOR/dN fU0IsiT+4ZTtdNjPnOdLFLY05xYol8g42tn+epgFre2COxn8SmysCZKjnHKJfJJRlWa3 MBMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=xnW2hm8mdRSXiMT1Z38l2h6CPdmFFJ+QxIxB1b6lpjE=; b=eTaATYztU+903gMrkXYY8giSYquUuC/uV3vBOURApyvpUgZlOcXH295oiSG1meUyx9 wx0D6auch8Ds/kzdviioc9eS4UpRn7AbNktaUscE2HyuIlzg0HUOGuV3RlYcr7rYo3ms if89LE3+1SRd9R9DF/6Ov5lRIfuWkSHs/QNaFqZb7saBhKjrIwsBGlLiNJ7c7JZyReOD 9ziSJKMBlHHT+N3Ss5liIwVn0+Syu2M2PC0jq2+f2dXVA4xRVVNt4GTjjVH0xl0Sw0MI OorZwUGrWbv2I8GDsmCrqIzqEvaJa45+vvl6r/d0PJ897cipHIlckuHfKgj8r3yQExne uV8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=bsgzHLTA; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j18si6904801jat.2.2021.10.31.03.19.09; Sun, 31 Oct 2021 03:19:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=bsgzHLTA; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231356AbhJaKTC (ORCPT + 99 others); Sun, 31 Oct 2021 06:19:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229877AbhJaKS7 (ORCPT ); Sun, 31 Oct 2021 06:18:59 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3B55C061746; Sun, 31 Oct 2021 03:16:27 -0700 (PDT) Date: Sun, 31 Oct 2021 10:16:25 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1635675386; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xnW2hm8mdRSXiMT1Z38l2h6CPdmFFJ+QxIxB1b6lpjE=; b=bsgzHLTAoSfg+GIChepr+Y/fBOezI2CX0s70qEHZmATLohLNnyUj5qa6PSc4JBK6Z1ZxHK gHmWoNn7O0vj41gQopRLKFZ+4UHmtp/Ne/oKLMSun4C3FqvBJGIiwWpQtxXnQrfoK7jjd6 Nl/u9BRMwHuBfJb9ktqLujaJnvOk96voiUPruG6Tcc+6JeV+pBY+S5Rrmy8hdsMUnYpyG9 fEW6dRQFmiQkTuZ8n8aX4nNM3hbYQJFl6G81KW52vU5MxzsVzmvuedPvpv9cIDXE+HCeRN 9g4Ca1YFL4lJQtkQaa4xHWmZ4AMMOfUNgvNXm4PG2ZqT/PXyqEPtBIisy/oWrg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1635675386; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xnW2hm8mdRSXiMT1Z38l2h6CPdmFFJ+QxIxB1b6lpjE=; b=EppxFTTQG1Ed1YRkYYthvO38s2vIa7COC6fs0AfJ96Vt+bRw6UKQ+rMsMmfCaLA+xwRIdU nrsE9epdqWh0ANAQ== From: "tip-bot2 for Vincent Guittot" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] sched/fair: Wait before decaying max_newidle_lb_cost Cc: Vincent Guittot , "Peter Zijlstra (Intel)" , Dietmar Eggemann , Mel Gorman , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20211019123537.17146-4-vincent.guittot@linaro.org> References: <20211019123537.17146-4-vincent.guittot@linaro.org> MIME-Version: 1.0 Message-ID: <163567538547.626.13303083323341603297.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the sched/core branch of tip: Commit-ID: e60b56e46b384cee1ad34e6adc164d883049c6c3 Gitweb: https://git.kernel.org/tip/e60b56e46b384cee1ad34e6adc164d883049c6c3 Author: Vincent Guittot AuthorDate: Tue, 19 Oct 2021 14:35:35 +02:00 Committer: Peter Zijlstra CommitterDate: Sun, 31 Oct 2021 11:11:38 +01:00 sched/fair: Wait before decaying max_newidle_lb_cost Decay max_newidle_lb_cost only when it has not been updated for a while and ensure to not decay a recently changed value. Signed-off-by: Vincent Guittot Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Dietmar Eggemann Acked-by: Mel Gorman Link: https://lore.kernel.org/r/20211019123537.17146-4-vincent.guittot@linaro.org --- include/linux/sched/topology.h | 2 +- kernel/sched/fair.c | 36 ++++++++++++++++++++++++--------- kernel/sched/topology.c | 2 +- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/include/linux/sched/topology.h b/include/linux/sched/topology.h index 2f9166f..c07bfa2 100644 --- a/include/linux/sched/topology.h +++ b/include/linux/sched/topology.h @@ -105,7 +105,7 @@ struct sched_domain { /* idle_balance() stats */ u64 max_newidle_lb_cost; - unsigned long next_decay_max_lb_cost; + unsigned long last_decay_max_lb_cost; u64 avg_scan_cost; /* select_idle_sibling */ diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index c4c3686..e50fd75 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -10239,6 +10239,30 @@ void update_max_interval(void) max_load_balance_interval = HZ*num_online_cpus()/10; } +static inline bool update_newidle_cost(struct sched_domain *sd, u64 cost) +{ + if (cost > sd->max_newidle_lb_cost) { + /* + * Track max cost of a domain to make sure to not delay the + * next wakeup on the CPU. + */ + sd->max_newidle_lb_cost = cost; + sd->last_decay_max_lb_cost = jiffies; + } else if (time_after(jiffies, sd->last_decay_max_lb_cost + HZ)) { + /* + * Decay the newidle max times by ~1% per second to ensure that + * it is not outdated and the current max cost is actually + * shorter. + */ + sd->max_newidle_lb_cost = (sd->max_newidle_lb_cost * 253) / 256; + sd->last_decay_max_lb_cost = jiffies; + + return true; + } + + return false; +} + /* * It checks each scheduling domain to see if it is due to be balanced, * and initiates a balancing operation if so. @@ -10262,14 +10286,9 @@ static void rebalance_domains(struct rq *rq, enum cpu_idle_type idle) for_each_domain(cpu, sd) { /* * Decay the newidle max times here because this is a regular - * visit to all the domains. Decay ~1% per second. + * visit to all the domains. */ - if (time_after(jiffies, sd->next_decay_max_lb_cost)) { - sd->max_newidle_lb_cost = - (sd->max_newidle_lb_cost * 253) / 256; - sd->next_decay_max_lb_cost = jiffies + HZ; - need_decay = 1; - } + need_decay = update_newidle_cost(sd, 0); max_cost += sd->max_newidle_lb_cost; /* @@ -10911,8 +10930,7 @@ static int newidle_balance(struct rq *this_rq, struct rq_flags *rf) t1 = sched_clock_cpu(this_cpu); domain_cost = t1 - t0; - if (domain_cost > sd->max_newidle_lb_cost) - sd->max_newidle_lb_cost = domain_cost; + update_newidle_cost(sd, domain_cost); curr_cost += domain_cost; t0 = t1; diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index e812467..30169c7 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -1568,7 +1568,7 @@ sd_init(struct sched_domain_topology_level *tl, .last_balance = jiffies, .balance_interval = sd_weight, .max_newidle_lb_cost = 0, - .next_decay_max_lb_cost = jiffies, + .last_decay_max_lb_cost = jiffies, .child = child, #ifdef CONFIG_SCHED_DEBUG .name = tl->name,