From nobody Fri Feb 13 17:30:42 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4EB00E7D0BB for ; Fri, 22 Sep 2023 01:40:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230029AbjIVBk5 (ORCPT ); Thu, 21 Sep 2023 21:40:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229458AbjIVBkz (ORCPT ); Thu, 21 Sep 2023 21:40:55 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3AA0E8 for ; Thu, 21 Sep 2023 18:40:49 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-59c07ca1b44so23280317b3.3 for ; Thu, 21 Sep 2023 18:40:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695346849; x=1695951649; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=IaJ0E6dYO97vx8l4rgkUr4paQrUz4gH2WWfMfHShIIo=; b=jllCmc8dO/Zqs5+PsljVyMFXnVHxo3XrXiIurh+he/HCmlBlEBTdLmthuwSUwBmmBh H5IkPbszIQbv5PwT0d4OIqpJ8WHo9W6unkDbJ6P/A04/5isMHEA2AnNALvlk2ujV322/ AgSFifJ+5MS0XDMATw8yE4NVCGpnHfpf78JDPbX67QhGVmQpdrG57pVfzEF3do/JMOjx yOKQwa1wJzKLMP+v5VNASYwc/MaLayrb8+7KDqmuRXal9iQejPDwUhDRqsmU33ocn991 ORW/v48xyAVFiw2PTDb5HrZKIxVTWXYH2Ue7qPWObwXb8ULcHbuXKJCaL/eJeQy2ahmf FmMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695346849; x=1695951649; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=IaJ0E6dYO97vx8l4rgkUr4paQrUz4gH2WWfMfHShIIo=; b=OH7YyCz9KOqJdtfe1vV12OSB72MOg5tlBdXVGPpEUXKft0zu3NiZFuX7aIqaeX4RGB P4iCw6O70pjEOtq3PVMsMmoMsnIA+sVbldxvXDmGUyhnXyvFAHLH8miANybPCfwPCuRe LQ10HrpT9EXNgckGApFRUFKXjx1M/TLNL3wYaG7kI/AFDZhjE5rxuSI76k9nHJWn9TgV rRivhC8w3eHHsVLplstExdewxtIxmDnN8Px9Cmu7tmy5yIBcywfNBkNkxk0N9ocOrfIk 5DyGkkNp5BPWell3EF4Kgc/DhDo7Q46McYJdkoeMCwda2NQNBexF8DcGDQaP6UeKVJrh LfSg== X-Gm-Message-State: AOJu0Yytps5m9TOA0ZQ9Lqo+FvdKUkLW+ohrurlqKWKm/MaQXJDToYYr Tw9xJ6M5Vd25KZDvXrDsR/+OX0fvxOCV X-Google-Smtp-Source: AGHT+IH7VFr1cKctb5cxPoppK93lwdxEHFNvD2AzuIR4XAEnR8hyr+vVBC+lR3XDA02kfA+RNe2I2Tf4kU0k X-Received: from joshdon-desktop.svl.corp.google.com ([2620:15c:2a3:200:fba6:21f7:70ce:4c75]) (user=joshdon job=sendgmr) by 2002:a81:ae57:0:b0:59b:ee27:bbe9 with SMTP id g23-20020a81ae57000000b0059bee27bbe9mr95784ywk.9.1695346849175; Thu, 21 Sep 2023 18:40:49 -0700 (PDT) Date: Thu, 21 Sep 2023 18:37:50 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.515.g380fc7ccd1-goog Message-ID: <20230922013750.874131-1-joshdon@google.com> Subject: [PATCH v2] sched: fix warning in bandwidth distribution From: Josh Don To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot Cc: Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , linux-kernel@vger.kernel.org, Josh Don Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" We've observed the following warning being hit in distribute_cfs_runtime(): SCHED_WARN_ON(cfs_rq->runtime_remaining > 0) We have the following race: - cpu0: running bandwidth distribution (distribute_cfs_runtime). Inspects the local cfs_rq and makes its runtime_remaining positive. However, we defer unthrottling the local cfs_rq until after considering all remote cfs_rq's. - cpu1: starts running bandwidth distribution from the slack timer. When it finds the cfs_rq for cpu 0 on the throttled list, it observers the that the cfs_rq is throttled, yet is not on the CSD list, and has a positive runtime_remaining, thus triggering the warning in distribute_cfs_runtime. To fix this, we can rework the local unthrottling logic to put the local cfs_rq on a local list, so that any future bandwidth distributions will realize that the cfs_rq is about to be unthrottled. Signed-off-by: Josh Don --- v2: Fix build error on !CONFIG_SMP kernel/sched/fair.c | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 384900bf87eb..3d1886ea18fe 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -5743,13 +5743,16 @@ static void unthrottle_cfs_rq_async(struct cfs_rq *= cfs_rq) =20 static bool distribute_cfs_runtime(struct cfs_bandwidth *cfs_b) { - struct cfs_rq *local_unthrottle =3D NULL; int this_cpu =3D smp_processor_id(); u64 runtime, remaining =3D 1; bool throttled =3D false; struct cfs_rq *cfs_rq; struct rq_flags rf; struct rq *rq; +#ifdef CONFIG_SMP + struct cfs_rq *tmp; + LIST_HEAD(local_unthrottle); +#endif =20 rcu_read_lock(); list_for_each_entry_rcu(cfs_rq, &cfs_b->throttled_cfs_rq, @@ -5786,11 +5789,21 @@ static bool distribute_cfs_runtime(struct cfs_bandw= idth *cfs_b) =20 /* we check whether we're throttled above */ if (cfs_rq->runtime_remaining > 0) { - if (cpu_of(rq) !=3D this_cpu || - SCHED_WARN_ON(local_unthrottle)) +#ifdef CONFIG_SMP + if (cpu_of(rq) !=3D this_cpu) { unthrottle_cfs_rq_async(cfs_rq); - else - local_unthrottle =3D cfs_rq; + } else { + /* + * We currently only expect to be unthrottling + * a single cfs_rq locally. + */ + SCHED_WARN_ON(!list_empty(&local_unthrottle)); + list_add_tail(&cfs_rq->throttled_csd_list, + &local_unthrottle); + } +#else + unthrottle_cfs_rq_async(cfs_rq); +#endif } else { throttled =3D true; } @@ -5798,15 +5811,25 @@ static bool distribute_cfs_runtime(struct cfs_bandw= idth *cfs_b) next: rq_unlock_irqrestore(rq, &rf); } - rcu_read_unlock(); =20 - if (local_unthrottle) { - rq =3D cpu_rq(this_cpu); +#ifdef CONFIG_SMP + list_for_each_entry_safe(cfs_rq, tmp, &local_unthrottle, + throttled_csd_list) { + struct rq *rq =3D rq_of(cfs_rq); + rq_lock_irqsave(rq, &rf); - if (cfs_rq_throttled(local_unthrottle)) - unthrottle_cfs_rq(local_unthrottle); + + list_del_init(&cfs_rq->throttled_csd_list); + + if (cfs_rq_throttled(cfs_rq)) + unthrottle_cfs_rq(cfs_rq); + rq_unlock_irqrestore(rq, &rf); } + SCHED_WARN_ON(!list_empty(&local_unthrottle)); +#endif + + rcu_read_unlock(); =20 return throttled; } --=20 2.42.0.515.g380fc7ccd1-goog