From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CFB263E63BF; Tue, 30 Jun 2026 09:03:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782810219; cv=none; b=jmKFKrivM82/8B+5/DJl5c91TKdnnifKlbPOTxxApgsxjFlGqlTtVN7MM441ALl3PrUC0MwXQU9KunV5+hwZl33lduJtEU3EbkPb/tng7+i/GF+ChI1Of/Jy7XA24fL0RS191awaqqjIVJZr+JppNYJWrm0+sILSY2quvbgCIZM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782810219; c=relaxed/simple; bh=mV69hGutkUUILuto6LXjvsX4uxGm2yUdT0geAF4MHDA=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=ne2M+rgOO2IxM6BLaR3bX0Cd0L9DMlt36BnA62CuluibRHKPoKYH6Bt9VoQcyw5C47ljNkxSj+52XzVv+KHr4Dyyd0cAGsrjTS1aXHtPiVE+Xyw/IZackODoXGieyzFxd9naNrhtGqAQbl6bkORN/2peNS1mtKA4Uhjo/zj0pi0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=sa+SHITx; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=D6Yxv1Cq; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="sa+SHITx"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="D6Yxv1Cq" Date: Tue, 30 Jun 2026 09:03:34 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1782810216; 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=MLH9oBXVZa34RbReDNic/4nfhotpTG8RHtBcXO4KMLU=; b=sa+SHITxGQN58XDfufxbjZVH4LUqdPCGy0YH91aXerDHWfPZ9LG4hXRIEWGPU4XUrKIItI 1jf0eKgpbaepbuc2/mJlIGypInOaL0LzYIcgofHnGJ3sD46k0Z3WpaauGNgk4uSzjmzED2 UxNnNzKsL40bRsLEr7Jt5LCsCQhwQregEq1HfRowgSRAylNmyXE0pyziFwSl8ILgbqIsmc gfK5DFznFbje1iayvI2rdXjQRwRAV+ZBQLStc0nhQWRvg/eb93rFuZ0nYFr/4R/Z9OXRWX 17P8BZIPc0tEUymba8Jw2luuufdcREvwzCjFKwAXZlG62Ule1MhNpeLNc6tRLg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1782810216; 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=MLH9oBXVZa34RbReDNic/4nfhotpTG8RHtBcXO4KMLU=; b=D6Yxv1CqeQvJE57m6qo1/mC3UZ1sYC+7PucVnDX6LQujU+S2zClHVzZ0+IAV/vZs4HIJ5f hfuNS48ywbClJWBQ== From: "tip-bot2 for Peter Zijlstra" 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: Reflow sched_balance_rq() Cc: "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20260618105627.GP49951@noisy.programming.kicks-ass.net> References: <20260618105627.GP49951@noisy.programming.kicks-ass.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <178281021463.3843924.17697492618086729638.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the sched/core branch of tip: Commit-ID: 296744614dd061287c9812a15521a64e292a90b4 Gitweb: https://git.kernel.org/tip/296744614dd061287c9812a15521a64e292= a90b4 Author: Peter Zijlstra AuthorDate: Thu, 18 Jun 2026 10:51:49 +02:00 Committer: Peter Zijlstra CommitterDate: Tue, 30 Jun 2026 10:56:56 +02:00 sched/fair: Reflow sched_balance_rq() Reflow to reduce indenting. Signed-off-by: Peter Zijlstra (Intel) Link: https://patch.msgid.link/20260618105627.GP49951@noisy.programming.kicks= -ass.net --- kernel/sched/fair.c | 128 ++++++++++++++++++++---------------------- kernel/sched/sched.h | 19 +++++- 2 files changed, 78 insertions(+), 69 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index ce836ed..ce05acf 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -13539,82 +13539,78 @@ more_balance: } } =20 - if (!ld_moved) { - schedstat_inc(sd->lb_failed[idle]); - /* - * Increment the failure counter only on periodic balance. - * We do not want newidle balance, which can be very - * frequent, pollute the failure counter causing - * excessive cache_hot migrations and active balances. - * - * Similarly for migration_misfit which is not related to - * load/util migration, don't pollute nr_balance_failed. - * - * The same for cache aware scheduling's allowance for - * load imbalance. If regular load balance does not - * migrate task due to LLC locality, it is a expected - * behavior and don't pollute nr_balance_failed. - * See can_migrate_task(). - */ - if (idle !=3D CPU_NEWLY_IDLE && - env.migration_type !=3D migrate_misfit && - !(env.flags & LBF_LLC_PINNED)) - sd->nr_balance_failed++; + if (ld_moved) { + sd->nr_balance_failed =3D 0; + goto out_unbalanced; + } =20 - if (need_active_balance(&env)) { - unsigned long flags; + schedstat_inc(sd->lb_failed[idle]); + /* + * Increment the failure counter only on periodic balance. + * We do not want newidle balance, which can be very + * frequent, pollute the failure counter causing + * excessive cache_hot migrations and active balances. + * + * Similarly for migration_misfit which is not related to + * load/util migration, don't pollute nr_balance_failed. + * + * The same for cache aware scheduling's allowance for + * load imbalance. If regular load balance does not + * migrate task due to LLC locality, it is a expected + * behavior and don't pollute nr_balance_failed. + * See can_migrate_task(). + */ + if (idle !=3D CPU_NEWLY_IDLE && + env.migration_type !=3D migrate_misfit && + !(env.flags & LBF_LLC_PINNED)) + sd->nr_balance_failed++; =20 - raw_spin_rq_lock_irqsave(busiest, flags); + if (!need_active_balance(&env)) + goto out_unbalanced; =20 - /* - * Don't kick the active_load_balance_cpu_stop, - * if the curr task on busiest CPU can't be - * moved to this_cpu: - */ - if (!cpumask_test_cpu(this_cpu, busiest->curr->cpus_ptr)) { - raw_spin_rq_unlock_irqrestore(busiest, flags); - goto out_one_pinned; - } + scoped_guard (raw_spin_rq_lock_irqsave, busiest) { + /* + * Don't kick the active_load_balance_cpu_stop, + * if the curr task on busiest CPU can't be + * moved to this_cpu: + */ + if (!cpumask_test_cpu(this_cpu, busiest->curr->cpus_ptr)) + goto out_one_pinned; =20 - /* Record that we found at least one task that could run on this_cpu */ - env.flags &=3D ~LBF_ALL_PINNED; + /* Record that we found at least one task that could run on this_cpu */ + env.flags &=3D ~LBF_ALL_PINNED; =20 - /* - * ->active_balance synchronizes accesses to - * ->active_balance_work. Once set, it's cleared - * only after active load balance is finished. - */ - if (busiest->active_balance) - goto no_active_balance; + /* + * ->active_balance synchronizes accesses to + * ->active_balance_work. Once set, it's cleared + * only after active load balance is finished. + */ + if (busiest->active_balance) + goto out_unbalanced; =20 - /* - * @busiest dropped its rq_lock in the middle of - * scheduling out its ->curr task (->on_rq :=3D 0), no - * need to forcefully punt it away with active balance. - */ - if (!busiest->curr->on_rq) - goto no_active_balance; - - busiest->active_balance =3D 1; - busiest->push_cpu =3D this_cpu; - active_balance =3D 1; -no_active_balance: - preempt_disable(); - raw_spin_rq_unlock_irqrestore(busiest, flags); - if (active_balance) { - stop_one_cpu_nowait(cpu_of(busiest), - active_load_balance_cpu_stop, busiest, - &busiest->active_balance_work); - } - preempt_enable(); - } - } else { - sd->nr_balance_failed =3D 0; + /* + * @busiest dropped its rq_lock in the middle of + * scheduling out its ->curr task (->on_rq :=3D 0), no + * need to forcefully punt it away with active balance. + */ + if (!busiest->curr->on_rq) + goto out_unbalanced; + + busiest->active_balance =3D 1; + busiest->push_cpu =3D this_cpu; + active_balance =3D 1; + preempt_disable(); + } + if (active_balance) { + stop_one_cpu_nowait(cpu_of(busiest), + active_load_balance_cpu_stop, busiest, + &busiest->active_balance_work); } + preempt_enable(); =20 +out_unbalanced: /* We were unbalanced, so reset the balancing interval */ sd->balance_interval =3D sd->min_interval; - goto out; =20 out_balanced: diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index e20823f..26ae13c 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -2021,7 +2021,8 @@ DEFINE_LOCK_GUARD_1(rq_lock, struct rq, rq_unlock(_T->lock, &_T->rf), struct rq_flags rf) =20 -DECLARE_LOCK_GUARD_1_ATTRS(rq_lock, __acquires(__rq_lockp(_T)), __releases(_= _rq_lockp(*(struct rq **)_T))); +DECLARE_LOCK_GUARD_1_ATTRS(rq_lock, __acquires(__rq_lockp(_T)), + __releases(__rq_lockp(*(struct rq **)_T))); #define class_rq_lock_constructor(_T) WITH_LOCK_GUARD_1_ATTRS(rq_lock, _T) =20 DEFINE_LOCK_GUARD_1(rq_lock_irq, struct rq, @@ -2029,7 +2030,8 @@ DEFINE_LOCK_GUARD_1(rq_lock_irq, struct rq, rq_unlock_irq(_T->lock, &_T->rf), struct rq_flags rf) =20 -DECLARE_LOCK_GUARD_1_ATTRS(rq_lock_irq, __acquires(__rq_lockp(_T)), __releas= es(__rq_lockp(*(struct rq **)_T))); +DECLARE_LOCK_GUARD_1_ATTRS(rq_lock_irq, __acquires(__rq_lockp(_T)), + __releases(__rq_lockp(*(struct rq **)_T))); #define class_rq_lock_irq_constructor(_T) WITH_LOCK_GUARD_1_ATTRS(rq_lock_ir= q, _T) =20 DEFINE_LOCK_GUARD_1(rq_lock_irqsave, struct rq, @@ -2037,9 +2039,20 @@ DEFINE_LOCK_GUARD_1(rq_lock_irqsave, struct rq, rq_unlock_irqrestore(_T->lock, &_T->rf), struct rq_flags rf) =20 -DECLARE_LOCK_GUARD_1_ATTRS(rq_lock_irqsave, __acquires(__rq_lockp(_T)), __re= leases(__rq_lockp(*(struct rq **)_T))); +DECLARE_LOCK_GUARD_1_ATTRS(rq_lock_irqsave, __acquires(__rq_lockp(_T)), + __releases(__rq_lockp(*(struct rq **)_T))); #define class_rq_lock_irqsave_constructor(_T) WITH_LOCK_GUARD_1_ATTRS(rq_loc= k_irqsave, _T) =20 +DEFINE_LOCK_GUARD_1(raw_spin_rq_lock_irqsave, struct rq, + raw_spin_rq_lock_irqsave(_T->lock, _T->flags), + raw_spin_rq_unlock_irqrestore(_T->lock, _T->flags), + unsigned long flags) + +DECLARE_LOCK_GUARD_1_ATTRS(raw_spin_rq_lock_irqsave, __acquires(__rq_lockp(_= T)), + __releases(__rq_lockp(*(struct rq **)_T))); +#define class_raw_spin_rq_lock_irqsave_constructor(_T) \ + WITH_LOCK_GUARD_1_ATTRS(raw_spin_rq_lock_irqsave, _T) + #define this_rq_lock_irq(...) __acquire_ret(_this_rq_lock_irq(__VA_ARGS__), = __rq_lockp(__ret)) static inline struct rq *_this_rq_lock_irq(struct rq_flags *rf) __acquires_r= et {