From patchwork Fri Sep 22 01:37:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Don X-Patchwork-Id: 143181 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5325985vqi; Thu, 21 Sep 2023 21:58:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE5CxTLNBN/9DDzQvxU3ebbgJOHSNKwaHmqm6OV7TZf25nCrorwkOj+kNOoU4AYOJL5Zlsd X-Received: by 2002:a05:6a20:9384:b0:138:60e:9c4 with SMTP id x4-20020a056a20938400b00138060e09c4mr8840331pzh.23.1695358720755; Thu, 21 Sep 2023 21:58:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695358720; cv=none; d=google.com; s=arc-20160816; b=xbu+GQ/8o5MuOazcHoezyOdbKgMW7I3WFnu1aCfPTVMHStrOScmzxdaS9nIK2Y8Xlk 6dcxvc2JoFp3hlxbfCW2NU7BU1HSVOQQMY0u+35cN7jx8R6w1mPMtdQAML4vcHcxbt8Z MG5wO+X0+BczDVg5pjCFZQYDw3zXebWXF7i1epdcrCKpnJGNyCI9JwZU45l1xr3yUu5Z x2nGNYou/jw97ySStzKzsTQWeOIIK+biHcdVWfKMlb0XZdzBhSnDT4w3UWp/357HZq4B K1lhrlQgx+HJcpZE+qYlhXG+Fc797e0G4eXkwokUBh4y1GQCDLYqKF/WUmvTVW0Zo2kY CSEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=IaJ0E6dYO97vx8l4rgkUr4paQrUz4gH2WWfMfHShIIo=; fh=UiXA54t1odHEprHSYfremupcP9Fl4Cqag0pTl7oSZd4=; b=i8YckRCry7TT6pUy0XH+nOr3jMmwyRHqw148tM0SS2JsNyzgD+1WYlXyKIq92xg/87 DdVQd6090Yu7kzvwREPIZg0cAVvdxELzgyAYkOPunEUm9EzJ2o7iYMMEsskmXyg8JN6x 9PD6yQ50QFrK8lWEWwIl8nDc09FUBbe6pD1++E4ijRMZdqt1lvdJbAQ7eUOHCcjfFJPP 5mxf6dV0DxGnRgzGaEUNSHjkLim8uSVj+xhHrrapbjd1pzVPGdqXfQWsAKamK9PlCfNb LMfv9lnKyXBF91bMXBRVq7cBkUdelVTNxOtbm0InlsB3+zlbKEt5OM9fWPWYtb7gz0cT tn1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=jllCmc8d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id b12-20020a17090ae38c00b00263a923c189si3004281pjz.100.2023.09.21.21.58.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 21:58:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=jllCmc8d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 7DE9A82FCE97; Thu, 21 Sep 2023 18:41:04 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229914AbjIVBk5 (ORCPT + 30 others); 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-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 X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 21 Sep 2023 18:41:04 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777712466089141025 X-GMAIL-MSGID: 1777712466089141025 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) static bool distribute_cfs_runtime(struct cfs_bandwidth *cfs_b) { - struct cfs_rq *local_unthrottle = NULL; int this_cpu = smp_processor_id(); u64 runtime, remaining = 1; bool throttled = 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 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_bandwidth *cfs_b) /* we check whether we're throttled above */ if (cfs_rq->runtime_remaining > 0) { - if (cpu_of(rq) != this_cpu || - SCHED_WARN_ON(local_unthrottle)) +#ifdef CONFIG_SMP + if (cpu_of(rq) != this_cpu) { unthrottle_cfs_rq_async(cfs_rq); - else - local_unthrottle = 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 = true; } @@ -5798,15 +5811,25 @@ static bool distribute_cfs_runtime(struct cfs_bandwidth *cfs_b) next: rq_unlock_irqrestore(rq, &rf); } - rcu_read_unlock(); - if (local_unthrottle) { - rq = cpu_rq(this_cpu); +#ifdef CONFIG_SMP + list_for_each_entry_safe(cfs_rq, tmp, &local_unthrottle, + throttled_csd_list) { + struct rq *rq = 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(); return throttled; }