Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp10150597rwb; Fri, 25 Nov 2022 01:26:41 -0800 (PST) X-Google-Smtp-Source: AA0mqf4E4/wG8+pI4ZrI56X0/VV9RBI1ljYWK+Xo+snEdwueSSZhqtrKDXnVCIDw2j93xN1EKZHY X-Received: by 2002:a17:90b:3593:b0:218:6c32:fc6b with SMTP id mm19-20020a17090b359300b002186c32fc6bmr39393053pjb.122.1669368401511; Fri, 25 Nov 2022 01:26:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669368401; cv=none; d=google.com; s=arc-20160816; b=eb2pEe3AQtN1MbOfM/cxcEUcnlrBn8YPavvy9OKU8V6wpzy1qwx5PvKXR7gJWG9KAn o0l5LmXdmfSkaYfOoVxYJffmMdJA5hckQeOeEdi0EFB8vFVhcXGrke3lXXKRHwQBQn4k rbWGDf5j/d+Hndg6Eu3gg0k7Q53PeoYQ2bOjWaFanBbJ88567y9QZXl7VWWKCbTASkB5 zWDlE4yUTsV0ZBKhvVuMiVUORvheXcWHL3R8d9IePrAAUKrKVcFLR+5rPdzFgp6+GkLr hVU5Mtlgn3YFrkpi+ebAdH3s2OECT8a90nHJI69U0dUknQ8entVxIfAL5lIOojSvdgMb +Cjw== 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:dkim-signature; bh=uAfGoK08v60ApQLBAJVzswYfYs4HD0yYTDh0683H4fc=; b=O9o1KnR3DM/4JGHl1kgFuwGvYTX64rOA/Uu5dC0SmUCBhGtwt+buymrthr7lkTtBBl 5YY+Ib9v4qyIWbvvTIRPFg4J+MHY/Oqz2fLVbFcmyviMzuPJ+mkiCZZsnVGrTR6LeOCR By+7jRtWFPC5pMH0CkasbrAjjWU9i1OnMspCW5ynm1OeCeXKX3fxb76rKhgzlKZZrdq7 cbwM6Hczg+5cmhGuzyPGCItyAPlPVLbwdIOmMQX7zWE86lDsEH4042qGcm/+9AAPqIGT VJkeHN2+ySK/0kmKe8Zgw9YzLQYUXKU4+fIV17NvckpBDYS2BiBKp4nN3PjgIzPWPbI0 mK3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="PGk/pprK"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r11-20020a170903410b00b00176939b5cd9si3020675pld.578.2022.11.25.01.26.27; Fri, 25 Nov 2022 01:26:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="PGk/pprK"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229728AbiKYJNH (ORCPT + 86 others); Fri, 25 Nov 2022 04:13:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229682AbiKYJNE (ORCPT ); Fri, 25 Nov 2022 04:13:04 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CA3663AA for ; Fri, 25 Nov 2022 01:13:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=uAfGoK08v60ApQLBAJVzswYfYs4HD0yYTDh0683H4fc=; b=PGk/pprKsrCCePWlyccHY69C04 jO9m8NtmaTvplw+0ZsANv/OQcz91L0dEnul+FGZNbweMou5G7USM2ZCzjEb650fBk6L3YrqFqwL0/ CQLRzzIy/qZUZbb459WYgVio7LkS92OxHAlrbJbAhCmmi40yXrfCN0rq8LaNDDjj3VEPAB8uudKK5 otYDHw/EPnE6/8J1jONx95PNXJ2WPdWJCLVDOc65mnfnH6qxmWfxBzukDGNTtGdn7f9WU7cz+yBGN 02TbkePMQYWGpruF8x9XKW6zNBx9XpPgrkNoJ4yS7TJQ9M5x3rfmT3eeCsEFv1IInHPeHHEEcEUqC v3SvPEfA==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1oyUlV-009SZI-4Y; Fri, 25 Nov 2022 09:12:57 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 2BAF6300282; Fri, 25 Nov 2022 10:12:49 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id ED5E2205E4E96; Fri, 25 Nov 2022 10:12:48 +0100 (CET) Date: Fri, 25 Nov 2022 10:12:48 +0100 From: Peter Zijlstra To: Josh Don Cc: Chengming Zhou , Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , linux-kernel@vger.kernel.org, Tejun Heo , Michal =?iso-8859-1?Q?Koutn=FD?= , Christian Brauner , Zefan Li , Thomas Gleixner , Frederic Weisbecker , anna-maria@linutronix.de Subject: Re: [PATCH v3] sched: async unthrottling for cfs bandwidth Message-ID: References: <20221117005418.3499691-1-joshdon@google.com> <094299a3-f039-04c1-d749-2bea0bc14246@linux.dev> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham 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 On Fri, Nov 25, 2022 at 09:59:23AM +0100, Peter Zijlstra wrote: > On Fri, Nov 25, 2022 at 09:57:09AM +0100, Peter Zijlstra wrote: > > On Tue, Nov 22, 2022 at 11:35:48AM +0100, Peter Zijlstra wrote: > > > On Mon, Nov 21, 2022 at 11:37:14AM -0800, Josh Don wrote: > > > > Yep, this tradeoff feels "best", but there are some edge cases where > > > > this could potentially disrupt fairness. For example, if we have > > > > non-trivial W, a lot of cpus to iterate through for dispatching remote > > > > unthrottle, and quota is small. Doesn't help that the timer is pinned > > > > so that this will continually hit the same cpu. > > > > > > We could -- if we wanted to -- manually rotate the timer around the > > > relevant CPUs. Doing that sanely would require a bit of hrtimer surgery > > > though I'm afraid. > > > > Here; something like so should enable us to cycle the bandwidth timer. > > Just need to figure out a way to find another CPU or something. > > Some more preparation... And then I think something like so.. That migrates the timer to the CPU of the first throttled entry -- possibly not the best heuristic, but its the simplest. NOTE: none of this has seen a compiler up close. --- --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -5595,13 +5595,21 @@ static bool distribute_cfs_runtime(struc */ static int do_sched_cfs_period_timer(struct cfs_bandwidth *cfs_b, int overrun, unsigned long flags) { - int throttled; + struct cfs_rq *first_cfs_rq; + int throttled = 0; + int cpu; /* no need to continue the timer with no bandwidth constraint */ if (cfs_b->quota == RUNTIME_INF) goto out_deactivate; - throttled = !list_empty(&cfs_b->throttled_cfs_rq); + first_cfs_rq = list_first_entry_or_null(&cfs_b->throttled_cfs_rq, + struct cfs_rq, throttled_list); + if (first_cfs_rq) { + throttled = 1; + cpu = cpu_of(rq_of(first_cfs_rq)); + } + cfs_b->nr_periods += overrun; /* Refill extra burst quota even if cfs_b->idle */ @@ -5641,7 +5649,7 @@ static int do_sched_cfs_period_timer(str */ cfs_b->idle = 0; - return HRTIMER_RESTART; + return HRTIMER_RESTART_MIGRATE + cpu; out_deactivate: return HRTIMER_NORESTART;