Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp716821rdh; Sun, 24 Sep 2023 08:37:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFR2oCI8q9uVGBbMt1QvSopYToVIyS/sjNNhSMArPyK3/SSweJNyauJsZ7Mv4xzHBNe5qr2 X-Received: by 2002:a05:6808:23d1:b0:3ab:8295:f2f1 with SMTP id bq17-20020a05680823d100b003ab8295f2f1mr7078538oib.45.1695569825106; Sun, 24 Sep 2023 08:37:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695569825; cv=none; d=google.com; s=arc-20160816; b=NNK2/jqjW+L/4w/gbk7B8luDIA7FjDtVcMpycM6m8d6OLtGBES8rR0r38JPYuii7rM BTDXL+JekGU+83k6nQg1Y/c/To4rqxSIdD9nOXyG+nH2B4oJgGcpGL5NAYvQnF6S4oum BA5SDv/Q1uwHGozuVL+dpB1Vbhwm1LZD2NJBcH4nyGT+DgCtaVAiNiAiO9x196QFqjDU NhIrRyMEm8lx2ZhzzpgTB5iUcRuFUgrJLSCRque7UeEToPZepERz5Wg+w2qCHMNnc3v8 7msAt7RnkpnGqbHhp0M2xJCAwt4oH9lEheWQItS5O858w0RiTtO1j74237XGQhxqViXA x0hA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:sender:dkim-signature; bh=p7EbfklJOHAT6VS7URBc22mn46gMxt5c5h+c3ThYaKM=; fh=5ViOKAlwuIKKuOGmK49gJRYpczJpkf0p0lkA5d8Nb94=; b=0dyvYrmJG94A+Lp07ef6PZ595DnUQBs7Use02NzGukmEHlrRI8QR6/c48bcEEltOo3 BVQ2Se0GVUCBy8ELro4iZ6+/o0WsV9zxUK3TPCUHgX5uJS6oDvFgniipm7/bMoAvydLt 5sEfT9ZP/R4WVwBnS63yxjlup7dWQRXWtoDWz4WRgW49TA9ZXCBUGznufaJXRQ4zl2vK 5PiQoK+7n9ZOpfZmUeK5eHeclw5loNOHtzJBKKFENW8sUMVHvjGqvE5Vv11Otmg0OkKK pNb8lFLH5Ba6JaKMXgDzzDA2j9q56dANit8orzCchFvgddNNM+/OegtIt8BWWhe3p6eA j/xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=JOJMuFqU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id h11-20020a65480b000000b00577dd005706si8002547pgs.779.2023.09.24.08.36.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 08:37:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=JOJMuFqU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id C4ADA8047563; Sun, 24 Sep 2023 03:12:48 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229809AbjIXKMr (ORCPT + 99 others); Sun, 24 Sep 2023 06:12:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229654AbjIXKMq (ORCPT ); Sun, 24 Sep 2023 06:12:46 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9045A103 for ; Sun, 24 Sep 2023 03:12:39 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-522bd411679so5390147a12.0 for ; Sun, 24 Sep 2023 03:12:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695550358; x=1696155158; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:from:to:cc:subject:date:message-id :reply-to; bh=p7EbfklJOHAT6VS7URBc22mn46gMxt5c5h+c3ThYaKM=; b=JOJMuFqUhQsWNAZM10UFZvFtn0csLO9d5CkBsCEJhGcCoCrgCHzaSqSiYwBh5t2+WK ZZoCB6Npcl1e5w7E8hPPUD93XoEWjt8i057/6EIkAsu991khu/gGPmXXGAp+n0dff1bU 2eGEFoBjliMyhIFrzT+OzuWi1RJpex6OI7pxrJwsrRfkoHIZ5lerlUT4+lMje4M+cBpD z+zTmgwYi2nru42nARj/xRmR8e7UgGe2nk9q72FTWy1pY31WcDTFJgVHJ8vT3Ty/zJNH J9uH7sBbsGeNBo0EzQJLexm4+g2/Zdtu7sDw5KOl2ZvURwmAGRYKtzcriM+192tH7bs/ CC9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695550358; x=1696155158; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=p7EbfklJOHAT6VS7URBc22mn46gMxt5c5h+c3ThYaKM=; b=RHpwHFxeLGRNRjtKVid3cWtEikCvJg6bpqHPKqaMJ6wTOaUd2RdHQIiREi/tNxcyxF u23Q7Siz8TJHcYKW9ZILZ+N7JNjEl2QL9nNgxiId/4jj0jUs4t6OzVFGftgshdZkueWj AcgDO72yW1qtVe11RjcqbaUzHokMk7jkylz+47eHvjhYc+8k64M8SLmx46cymC3k0BZa EdGO1cagRmAUrxSTpw7dkFnOqqa0H0OGZfXPHPtjZ4e5vw6j39Y88Wzj23A1J66qpB1L oJ/kQRXXni2OPUPsP6mwUUHeUMDqvtLW4RbK/XkFe+GHoB2zAgT538XyFvDie52e9Qxf GqEg== X-Gm-Message-State: AOJu0Ywy6ZiWsZxZN+hBzW9LYefwHWyCGjk88ffER6ta6EJ3sOpLlABd s7izR48/qUmU3y5+92L4V2s= X-Received: by 2002:a17:906:2d4:b0:9a2:143e:a071 with SMTP id 20-20020a17090602d400b009a2143ea071mr3799973ejk.17.1695550357787; Sun, 24 Sep 2023 03:12:37 -0700 (PDT) Received: from gmail.com (195-38-113-94.pool.digikabel.hu. [195.38.113.94]) by smtp.gmail.com with ESMTPSA id sd6-20020a170906ce2600b0098e34446464sm4892349ejb.25.2023.09.24.03.12.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 03:12:37 -0700 (PDT) Sender: Ingo Molnar Date: Sun, 24 Sep 2023 12:12:35 +0200 From: Ingo Molnar To: Josh Don Cc: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] sched: fix warning in bandwidth distribution Message-ID: References: <20230922230535.296350-1-joshdon@google.com> <20230922230535.296350-2-joshdon@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230922230535.296350-2-joshdon@google.com> X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Sun, 24 Sep 2023 03:12:49 -0700 (PDT) * Josh Don wrote: > 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 > --- > kernel/sched/fair.c | 36 +++++++++++++++++++++++++----------- > 1 file changed, 25 insertions(+), 11 deletions(-) > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index 8f4e63fc8900..de002dab28cf 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -5743,13 +5743,13 @@ 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 cfs_rq *cfs_rq, *tmp; > struct rq_flags rf; > struct rq *rq; > + LIST_HEAD(local_unthrottle); > > rcu_read_lock(); > list_for_each_entry_rcu(cfs_rq, &cfs_b->throttled_cfs_rq, > @@ -5784,11 +5784,17 @@ 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)) > + 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 { > throttled = true; > } > @@ -5796,15 +5802,23 @@ 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); > + 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)); > + > + rcu_read_unlock(); Thanks, this looks much cleaner. When the warning hits, we don't have any other side-effects, such as bad behavior or data corruption, correct? Under that assumption I've queued your fix in tip:sched/core, for a v6.7 merge, and not in tip:sched/urgent for a v6.6 merge, but let me know if I'm reading the code wrong... Thanks, Ingo