Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1527377pxb; Thu, 4 Mar 2021 13:48:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJzlsBl+TVBHsk/DNIng+6Mkg8+qfIKGSYBOGT7teUiLyDTAAtvpd7G/DR9ku4RsyKmQN9Or X-Received: by 2002:a17:906:d1d5:: with SMTP id bs21mr6593612ejb.242.1614894512001; Thu, 04 Mar 2021 13:48:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614894511; cv=none; d=google.com; s=arc-20160816; b=ugrvhH1A8j1JnKyJyb03FX3B8pgxS3qJONXmOQCA11H0xcVlVJvjtEwLb3UNecCBX2 Y2YG80i9n3aCCWSRo9qjA5wRUcFGxdrzO6b3GT5/5WoSMDfrZbfgfeoZDvyjx72goM7l dBNrjmNVrKgKekvlIcv1gyYx/em2GCaiw6Wwj/8sRponrBMZLbfwHvysZlX6wa3kvfz7 Gwg3hfFiSPUkqDANAx0gqeHF+5hdAlZan510NwEY8N0V6C7EOZD8LfJYVxcO8PkYA47d 4Dm9mAmtjBX3bBKhGi/dTFFD/PP3f6Z85lYAl8d6VYhyAToMOC1xGLJlUdeT/0PLBG0B Dg7g== 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=eXdL0nmNs95bfYZR8480kySxyqBsiglCQla+I5KC730=; b=TjPv9jsBdo4BFNjosL20ETttT7mtFO3EZFEmC1bi1FZlwDi5wbIcVMcJJYswVU8NLT R3fs93Q75v2/blLIlcGqZYSHbgXAc7wctt9W3ItDRDDkPMb/EqRU0ERuN/A6Qxa/Zu9z pTv47RdeCnAmhZFdc8Soui+h04EZIwgoaMogvQa5VsXdWhSCQ0ImZP5kX29ayffXZw4Z YPf+uh82b0Ffyi/1FDnGHaowq2QyjTP6yHNXPw03YN/PgpT/diB7GK8TpXqlcvURCofR BX56+zkNDwfRMzOkksVGnD3R7gRTqWr0/e84EdjKWstTbLX4qcgERLTdSCX5t4EU//uw +Q3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=1Ye5PFAF; dkim=neutral (no key) header.i=@linutronix.de header.b=8Qwnhyj1; 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 o11si236188ejb.453.2021.03.04.13.48.08; Thu, 04 Mar 2021 13:48:31 -0800 (PST) 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=1Ye5PFAF; dkim=neutral (no key) header.i=@linutronix.de header.b=8Qwnhyj1; 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 S1359787AbhCCOu4 (ORCPT + 99 others); Wed, 3 Mar 2021 09:50:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1843042AbhCCKYv (ORCPT ); Wed, 3 Mar 2021 05:24:51 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59586C08EC49; Wed, 3 Mar 2021 01:49:41 -0800 (PST) Date: Wed, 03 Mar 2021 09:49:37 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1614764977; 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=eXdL0nmNs95bfYZR8480kySxyqBsiglCQla+I5KC730=; b=1Ye5PFAF5yt+CP7sglDD85O7za+yZOMMLCi/CFxCwb5VS5He06sT6DtFByRZBRNcj+KEX7 +szveMbuQp+4pqrGHbIWewE82d+6Eb/uQXpBACiX9cXBpJEl29js/Dp2GgHCDSHgLv1xEA 11gMtEAdB1yrGAXuaXxKg7laYLPPRYUr1J2B6cF8CSc5lHueCvxyFgzbUX2greIaPLYeEc 8zlYeVnMLJWOQ6bpU4T3Z3xl2WChqZn/JnjCbl71A/T3FGLAT1KgJohGgqyXaQR1bEs1ww NcJ8q9oQ/UJBsnd/4+BKuLyugJaOVcROLd/yfyZP49Pgfswp9cEbKMXeWY65zQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1614764977; 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=eXdL0nmNs95bfYZR8480kySxyqBsiglCQla+I5KC730=; b=8Qwnhyj1b2/OAHEyQx1KI+W+3RR7gQ6PW8JsEJIy1u9UOgBQ2Egg2Qbm0sWGc0IN2g5hY9 LsKVoK8F270tnuAw== 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: Trigger the update of blocked load on newly idle cpu Cc: Vincent Guittot , "Peter Zijlstra (Intel)" , Valentin Schneider , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20210224133007.28644-7-vincent.guittot@linaro.org> References: <20210224133007.28644-7-vincent.guittot@linaro.org> MIME-Version: 1.0 Message-ID: <161476497709.20312.16132151672736837410.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: 63dbe695827f0f612a0cdbc82a43a974bcd536cd Gitweb: https://git.kernel.org/tip/63dbe695827f0f612a0cdbc82a43a974bcd536cd Author: Vincent Guittot AuthorDate: Wed, 24 Feb 2021 14:30:06 +01:00 Committer: Peter Zijlstra CommitterDate: Wed, 03 Mar 2021 10:32:59 +01:00 sched/fair: Trigger the update of blocked load on newly idle cpu Instead of waking up a random and already idle CPU, we can take advantage of this_cpu being about to enter idle to run the ILB and update the blocked load. Signed-off-by: Vincent Guittot Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Valentin Schneider Link: https://lkml.kernel.org/r/20210224133007.28644-7-vincent.guittot@linaro.org --- kernel/sched/core.c | 2 +- kernel/sched/fair.c | 24 +++++++++++++++++++++--- kernel/sched/idle.c | 6 ++++++ kernel/sched/sched.h | 7 +++++++ 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index f9dfb34..361974e 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -737,7 +737,7 @@ static void nohz_csd_func(void *info) /* * Release the rq::nohz_csd. */ - flags = atomic_fetch_andnot(NOHZ_KICK_MASK, nohz_flags(cpu)); + flags = atomic_fetch_andnot(NOHZ_KICK_MASK | NOHZ_NEWILB_KICK, nohz_flags(cpu)); WARN_ON(!(flags & NOHZ_KICK_MASK)); rq->idle_balance = idle_cpu(cpu); diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 356a245..e87e1b3 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -10453,6 +10453,24 @@ static bool nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) return true; } +/* + * Check if we need to run the ILB for updating blocked load before entering + * idle state. + */ +void nohz_run_idle_balance(int cpu) +{ + unsigned int flags; + + flags = atomic_fetch_andnot(NOHZ_NEWILB_KICK, nohz_flags(cpu)); + + /* + * Update the blocked load only if no SCHED_SOFTIRQ is about to happen + * (ie NOHZ_STATS_KICK set) and will do the same. + */ + if ((flags == NOHZ_NEWILB_KICK) && !need_resched()) + _nohz_idle_balance(cpu_rq(cpu), NOHZ_STATS_KICK, CPU_IDLE); +} + static void nohz_newidle_balance(struct rq *this_rq) { int this_cpu = this_rq->cpu; @@ -10474,10 +10492,10 @@ static void nohz_newidle_balance(struct rq *this_rq) return; /* - * Blocked load of idle CPUs need to be updated. - * Kick an ILB to update statistics. + * Set the need to trigger ILB in order to update blocked load + * before entering idle state. */ - kick_ilb(NOHZ_STATS_KICK); + atomic_or(NOHZ_NEWILB_KICK, nohz_flags(this_cpu)); } #else /* !CONFIG_NO_HZ_COMMON */ diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c index 7199e6f..7a92d60 100644 --- a/kernel/sched/idle.c +++ b/kernel/sched/idle.c @@ -261,6 +261,12 @@ exit_idle: static void do_idle(void) { int cpu = smp_processor_id(); + + /* + * Check if we need to update blocked load + */ + nohz_run_idle_balance(cpu); + /* * If the arch has a polling bit, we maintain an invariant: * diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 10a1522..0ddc9a6 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -2385,9 +2385,11 @@ extern void cfs_bandwidth_usage_dec(void); #ifdef CONFIG_NO_HZ_COMMON #define NOHZ_BALANCE_KICK_BIT 0 #define NOHZ_STATS_KICK_BIT 1 +#define NOHZ_NEWILB_KICK_BIT 2 #define NOHZ_BALANCE_KICK BIT(NOHZ_BALANCE_KICK_BIT) #define NOHZ_STATS_KICK BIT(NOHZ_STATS_KICK_BIT) +#define NOHZ_NEWILB_KICK BIT(NOHZ_NEWILB_KICK_BIT) #define NOHZ_KICK_MASK (NOHZ_BALANCE_KICK | NOHZ_STATS_KICK) @@ -2398,6 +2400,11 @@ extern void nohz_balance_exit_idle(struct rq *rq); static inline void nohz_balance_exit_idle(struct rq *rq) { } #endif +#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON) +extern void nohz_run_idle_balance(int cpu); +#else +static inline void nohz_run_idle_balance(int cpu) { } +#endif #ifdef CONFIG_SMP static inline