Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp884869pxy; Wed, 28 Apr 2021 16:30:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxRjWTag4rildWmhyz2wFoHabX/EhTuqzyy/qAzfoJdb24uRQZGlSRHADFL+LA0N3YCc3Xc X-Received: by 2002:a17:902:59dc:b029:ed:7e32:ff4a with SMTP id d28-20020a17090259dcb02900ed7e32ff4amr3506640plj.50.1619652631797; Wed, 28 Apr 2021 16:30:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619652631; cv=none; d=google.com; s=arc-20160816; b=zWBQd83GE9heTtga/Q+28xBDgWn+7WRTxSJgtEzlb1aIqC3gSdVIIPwEaMKW918VWG zGUrRMF3/Lzpp75uSXlxPH/VMNfbIQqUSOm+dXZPN9jV8n17eEmQtXCJavyPT1hhos9F 8ZCz0KX4nbg4FoonsLLWQXClFjtdAR0G0PZmP6lVHAWy4+pZThkYaLKSmZ03fzCSN78r xDv8jorLAhYConJlVKVWst55VHbQUSWtD0ndy58uCb5+x1jkeiJMU/7J4UMdzbs0HswX eum006YUt3V3YQ2bVeo221uk5j9VCB7gZQA8xgXS1woxnwiEPZE29kBQ+5sEArZVCS/k Wd+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=v8foyHQlNkbGET6ChRpZL7Zd/zRUdjQXUGk2lF+yl4Q=; b=nB+UqIE/r9pi8/yMCdcfkS47bLzzAjG2jW5hYfmZFCb2mpJpC5gtuHWvPjevaSomV9 lYNqJa85N9aHjV6xYMRUnMgBv8zkbipa28O5J0PPNy7B8TTFvBnsImudBm7rXmGfEvAq qaZG8S8AfsEhnHxn5LAresS7P2Q+6vBlhMKq2JlPWvpJ3wWT4TJ1NY0iFzxehrCbyJWE n4bjZ3TW/52EaA6Og4Vzv62IV2yaQoG4mOvOvHvZCm7OOcoMfV/gBy4wsRBVYk8nz8yQ hU1URZQPwiDWGVn3SmbZ+OK/QYzXJsWRbCSwgkktqkMtp6gKymHqYn/xNsyhh3tnI4of 48ZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=A6OpmmBN; 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=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i17si1343049pjz.86.2021.04.28.16.30.18; Wed, 28 Apr 2021 16:30:31 -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=@redhat.com header.s=mimecast20190719 header.b=A6OpmmBN; 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=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234365AbhD1X33 (ORCPT + 99 others); Wed, 28 Apr 2021 19:29:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:57437 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233754AbhD1X31 (ORCPT ); Wed, 28 Apr 2021 19:29:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619652521; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=v8foyHQlNkbGET6ChRpZL7Zd/zRUdjQXUGk2lF+yl4Q=; b=A6OpmmBNtXwr8HABIBBYe00jdwgJFr9EU7rh5qg7IHw6bW+iWwKvfMo4MH1Ybzw7mVLkp1 wcup5HCEgK8XhQ5cDSM0XfIsCe05Fq0OpExlG3Zq3o5IgDMZ9iizt4zk1L1g+cAP0eOiw8 ZkJMzo9rIK61dhgrCAgKNXUOyIqRVF4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-51-yw8Y_fgQN-K7prP6lG3Geg-1; Wed, 28 Apr 2021 19:28:39 -0400 X-MC-Unique: yw8Y_fgQN-K7prP6lG3Geg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 581BC10054F6; Wed, 28 Apr 2021 23:28:37 +0000 (UTC) Received: from p1g2.redhat.com (ovpn-114-20.rdu2.redhat.com [10.10.114.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 51FF161008; Wed, 28 Apr 2021 23:28:35 +0000 (UTC) From: Scott Wood To: Ingo Molnar , Peter Zijlstra , Vincent Guittot Cc: Dietmar Eggemann , Steven Rostedt , Mel Gorman , Valentin Schneider , linux-kernel@vger.kernel.org, linux-rt-users@vger.kernel.org, Sebastian Andrzej Siewior , Thomas Gleixner , Scott Wood Subject: [PATCH v2 3/3] sched/fair: break out of newidle balancing if an RT task appears Date: Wed, 28 Apr 2021 18:28:21 -0500 Message-Id: <20210428232821.2506201-4-swood@redhat.com> In-Reply-To: <20210428232821.2506201-1-swood@redhat.com> References: <20210428232821.2506201-1-swood@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The CFS load balancer can take a little while, to the point of it having a special LBF_NEED_BREAK flag, when the task moving code takes a breather. However, at that point it will jump right back in to load balancing, without checking whether the CPU has gained any runnable real time (or deadline) tasks. Break out of load balancing in the CPU_NEWLY_IDLE case, to allow the scheduling of the RT task. Without this, latencies of over 1ms are seen on large systems. Signed-off-by: Rik van Riel Reported-by: Clark Williams Signed-off-by: Clark Williams [swood: Limit change to newidle] Signed-off-by: Scott Wood --- v2: Only break out of newidle balancing kernel/sched/fair.c | 24 ++++++++++++++++++++---- kernel/sched/sched.h | 6 ++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index aa8c87b6aff8..c3500c963af2 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -9502,10 +9502,21 @@ imbalanced_active_balance(struct lb_env *env) return 0; } -static int need_active_balance(struct lb_env *env) +static bool stop_balance_early(struct lb_env *env) +{ + return env->idle == CPU_NEWLY_IDLE && rq_has_higher_tasks(env->dst_rq); +} + +static int need_active_balance(struct lb_env *env, int *continue_balancing) { struct sched_domain *sd = env->sd; + /* Run the realtime task now; load balance later. */ + if (stop_balance_early(env)) { + *continue_balancing = 0; + return 0; + } + if (asym_active_balance(env)) return 1; @@ -9550,7 +9561,7 @@ static int should_we_balance(struct lb_env *env) * to do the newly idle load balance. */ if (env->idle == CPU_NEWLY_IDLE) - return 1; + return !rq_has_higher_tasks(env->dst_rq); /* Try to find first idle CPU */ for_each_cpu_and(cpu, group_balance_mask(sg), env->cpus) { @@ -9660,6 +9671,11 @@ static int load_balance(int this_cpu, struct rq *this_rq, local_irq_restore(rf.flags); + if (stop_balance_early(&env)) { + *continue_balancing = 0; + goto out; + } + if (env.flags & LBF_NEED_BREAK) { env.flags &= ~LBF_NEED_BREAK; goto more_balance; @@ -9743,7 +9759,7 @@ static int load_balance(int this_cpu, struct rq *this_rq, if (idle != CPU_NEWLY_IDLE) sd->nr_balance_failed++; - if (need_active_balance(&env)) { + if (need_active_balance(&env, continue_balancing)) { unsigned long flags; raw_spin_lock_irqsave(&busiest->lock, flags); @@ -9787,7 +9803,7 @@ static int load_balance(int this_cpu, struct rq *this_rq, sd->nr_balance_failed = 0; } - if (likely(!active_balance) || need_active_balance(&env)) { + if (likely(!active_balance) || need_active_balance(&env, continue_balancing)) { /* We were unbalanced, so reset the balancing interval */ sd->balance_interval = sd->min_interval; } diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 10a1522b1e30..88be4ed58924 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -1987,6 +1987,12 @@ static inline struct cpuidle_state *idle_get_state(struct rq *rq) return rq->idle_state; } + +/* Is there a task of a high priority class? */ +static inline bool rq_has_higher_tasks(struct rq *rq) +{ + return unlikely(rq->nr_running != rq->cfs.h_nr_running); +} #else static inline void idle_set_state(struct rq *rq, struct cpuidle_state *idle_state) -- 2.27.0