Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp12443528rwd; Fri, 23 Jun 2023 06:17:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4UpuPsDCw7cbEScR8KFmvBDZMA/5ol5ExGcQjXaoNtbTygzDTxf5XXlbpPsHxdqZ3xnLhb X-Received: by 2002:a17:902:d4d0:b0:1b7:c796:93ee with SMTP id o16-20020a170902d4d000b001b7c79693eemr628318plg.6.1687526250966; Fri, 23 Jun 2023 06:17:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687526250; cv=none; d=google.com; s=arc-20160816; b=HmyCOQfOmYlyxnl+jV7rFmk94xWudMLCZyaoKpLPmfIIJX8pYv/s6y2lJvksfmy8l1 VX67KEOmHFL+T5RjEYHTuBnsBZz3hBoyBfIOXg22Q3MP2F3H9FGnL/iHOizRO2QSNEzx q58ASvj3uKDwgzV0Tqtpv2CuGnCKv6gTwkFx3cPSJ/nldxKu6muQJoQH+R3NuYcpsg5w JMr/KA1gCGuri9p7xtQ34VkkgrVS6WgPDeMqA0x1+lepx+UI76tXcCdJpF0Vu0dMgoSl pekmCZ2iFbzOa4leDe95z4wj5SRIi0db8X4VuHi4MYoWpx3Fi0VbYS99Gfj8awfyFMR/ KP4w== 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=0K3DbJv11KIJK04q28nvvZV3mBzNSyKDIHy9E3PBbC0=; b=EArEgJr8M6giS/gHLQM2u+xhyAJl8m5PZTyZr+JZRS/qkoryHKw0tip76qIHJxoaLh orFomHMR1mLfq5raSwrysEy+oRzPjrUcW9oXaeLDoqWvLQ44ZjBpwCjO7rNDOFeRMotC vbKyoLEAx7slC1DoJ/J4EE3UbUSjOCTKsw1aOTVNwjPPRi7JF4ITP7kFwOf8gMuOdKsG 39+DGnDllHNnA2rTczvbEwd1hodDvDheNU0yRRbWE3Lln0QEqY0VCTj3Ex+ryTsV/FzW 3d8mqKgD6CrXAjNY9ChQZ65t52pNu56eipseawh69irsndiZ5sQEKJg5vkaqbmZZTQ8y iLMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=GlllHkEg; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r19-20020a170902c7d300b001b3f2ba0917si8163598pla.108.2023.06.23.06.17.05; Fri, 23 Jun 2023 06:17:30 -0700 (PDT) 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=@redhat.com header.s=mimecast20190719 header.b=GlllHkEg; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230125AbjFWNJv (ORCPT + 99 others); Fri, 23 Jun 2023 09:09:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229484AbjFWNJu (ORCPT ); Fri, 23 Jun 2023 09:09:50 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CA892130 for ; Fri, 23 Jun 2023 06:09:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687525746; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=0K3DbJv11KIJK04q28nvvZV3mBzNSyKDIHy9E3PBbC0=; b=GlllHkEgXmfIIBkSauU8NjaUSYGyYhXxUT1lC3ktXbKJOQnqRcx/KastGeX5uueolmfoFJ K8eGABMWgWqCnp0SJDvftYhDFxm+7fwrF0mm3X0MokY7MTpmRdb2e/vGWVqynMgxUFHBYo oZ2vxMprUm6F9ZLQ048H6ozSNM5Aptg= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-483-8TuChi_9M2yIhVWc9M6lng-1; Fri, 23 Jun 2023 09:09:02 -0400 X-MC-Unique: 8TuChi_9M2yIhVWc9M6lng-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3012910504B7; Fri, 23 Jun 2023 13:09:02 +0000 (UTC) Received: from lorien.usersys.redhat.com (unknown [10.22.33.48]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 95519C00049; Fri, 23 Jun 2023 13:09:01 +0000 (UTC) Date: Fri, 23 Jun 2023 09:08:59 -0400 From: Phil Auld To: Benjamin Segall Cc: linux-kernel@vger.kernel.org, Juri Lelli , Ingo Molnar , Daniel Bristot de Oliveira , Peter Zijlstra , Vincent Guittot , Dietmar Eggemann , Valentin Schneider , Steven Rostedt , Mel Gorman Subject: Re: [PATCH] Sched/fair: Block nohz tick_stop when cfs bandwidth in use Message-ID: <20230623130859.GA766130@lorien.usersys.redhat.com> References: <20230622132751.2900081-1-pauld@redhat.com> <20230622213730.GE727646@lorien.usersys.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230622213730.GE727646@lorien.usersys.redhat.com> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE 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 Thu, Jun 22, 2023 at 05:37:30PM -0400 Phil Auld wrote: > On Thu, Jun 22, 2023 at 01:49:52PM -0700 Benjamin Segall wrote: > > Phil Auld writes: > > > > > CFS bandwidth limits and NOHZ full don't play well together. Tasks > > > can easily run well past their quotas before a remote tick does > > > accounting. This leads to long, multi-period stalls before such > > > tasks can run again. Currentlyi, when presented with these conflicting > > > requirements the scheduler is favoring nohz_full and letting the tick > > > be stopped. However, nohz tick stopping is already best-effort, there > > > are a number of conditions that can prevent it, whereas cfs runtime > > > bandwidth is expected to be enforced. > > > > > > Make the scheduler favor bandwidth over stopping the tick by setting > > > TICK_DEP_BIT_SCHED when the only running task is a cfs task with > > > runtime limit enabled. > > > > > > Add sched_feat HZ_BW (off by default) to control this behavior. > > > > > > Signed-off-by: Phil Auld > > > Cc: Ingo Molnar > > > Cc: Peter Zijlstra > > > Cc: Vincent Guittot > > > Cc: Juri Lelli > > > Cc: Dietmar Eggemann > > > Cc: Valentin Schneider > > > Cc: Ben Segall > > > --- > > > kernel/sched/fair.c | 33 ++++++++++++++++++++++++++++++++- > > > kernel/sched/features.h | 2 ++ > > > 2 files changed, 34 insertions(+), 1 deletion(-) > > > > > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > > > index 373ff5f55884..880eadfac330 100644 > > > --- a/kernel/sched/fair.c > > > +++ b/kernel/sched/fair.c > > > @@ -6139,6 +6139,33 @@ static void __maybe_unused unthrottle_offline_cfs_rqs(struct rq *rq) > > > rcu_read_unlock(); > > > } > > > > > > +#ifdef CONFIG_NO_HZ_FULL > > > +/* called from pick_next_task_fair() */ > > > +static void sched_fair_update_stop_tick(struct rq *rq, struct task_struct *p) > > > +{ > > > + struct cfs_rq *cfs_rq = task_cfs_rq(p); > > > + int cpu = cpu_of(rq); > > > + > > > + if (!sched_feat(HZ_BW) || !cfs_bandwidth_used()) > > > + return; > > > + > > > + if (!tick_nohz_full_cpu(cpu)) > > > + return; > > > + > > > + if (rq->nr_running != 1 || !sched_can_stop_tick(rq)) > > > + return; > > > + > > > + /* > > > + * We know there is only one task runnable and we've just picked it. The > > > + * normal enqueue path will have cleared TICK_DEP_BIT_SCHED if we will > > > + * be otherwise able to stop the tick. Just need to check if we are using > > > + * bandwidth control. > > > + */ > > > + if (cfs_rq->runtime_enabled) > > > + tick_nohz_dep_set_cpu(cpu, TICK_DEP_BIT_SCHED); > > > +} > > > +#endif > > > > So from a CFS_BANDWIDTH pov runtime_enabled && nr_running == 1 seems > > fine. But working around sched_can_stop_tick instead of with it seems > > sketchy in general, and in an edge case like "migrate a task onto the > > cpu and then off again" you'd get sched_update_tick_dependency resetting > > the TICK_DEP_BIT and then not call PNT (ie a task wakes up onto this cpu > > without preempting, and then another cpu goes idle and pulls it, causing > > this cpu to go into nohz_full). > > > > The information to make these tests is not available in sched_can_stop_tick. > I did start there. When that is called, and we are likely to go nohz_full, > curr is null so it's hard to find the right cfs_rq to make that > runtime_enabled test against. We could, maybe, plumb the task being enqueued > in but it would not be valid for the dequeue path and would be a bit messy. > Sorry, mispoke... rq->curr == rq-idle not null. But still we don't have access to the task and its cfs_rq which will have runtime_enabled set. > But yes, I suppose you could end up in a state that is just as bad as today. > > Maybe I could add a redundant check in sched_can_stop_tick for when > nr_running == 1 and curr is not null and make sure the bit does not get > cleared. I'll look into that. > > > Thanks, > Phil > > -- > --