Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp12955516rwd; Fri, 23 Jun 2023 13:16:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ58WtGrXCgA0/wz8fXJE5ZRW40EY3vt8Bp/KNoEwraNSAmHVbIP+icZTUfsmtfaEW/O/jy0 X-Received: by 2002:a05:6a21:3401:b0:124:bb55:f244 with SMTP id yn1-20020a056a21340100b00124bb55f244mr5975756pzb.30.1687551372233; Fri, 23 Jun 2023 13:16:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687551372; cv=none; d=google.com; s=arc-20160816; b=NBjAsmjwS11vZeTJLuTI1RSrOpr2g0eGPLK84jQ1SHvYxXtewB9IvIOdjk9GSypG+c sqHEs8NRXUmz1pcbfyvfW1TWgdywnPgj7iYbsjt+bAcfqvaW9wh1uP2LB0dzerFDYNax yKEh9ZfuwMUnbf76EZnCRB6WUUFQn0n17o8Eaqy0ftjZ6rOaeSATJ4mXQZ44bO6VKDBq C7CDz+hJJTbK8a0KO2AN7ii9ZixwvqPVptAtct05nwXAnA9W5s9ki4FUX0jQV5DMmhEm JAMflIlfsy/3im1mUCrfVTXcLPVqejC5qe9cGjhZG8YrRhT53NVpelHk+9t6D5xB0Jvj Os/w== 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=bRaQkpW8TcfPoBNjOHA2HT8r7AuFWY474S3n34c5w7Y=; fh=O6In+8hokvsw1pBnVpVt9U6Ix7vd1sLKmZf89mqiKCY=; b=o7uGg07AoPmaUclLsqAaex3oMH0kfGUAgELn0Gntib4/izajwz94Y4PShMUMN2RVm6 rJmbLVKHvFXW4eUdjHFkfOykaeMKezHggbqtX5p7hYF28YmZoAEoKRe3c83MjoEYNV08 GkAbP80ctkN51AHFZcB0vy7l4ipdtbHJ3xI0G2+UmgyN9yRSO3T7bJb6MrjwSZU23Xyd EaBvRPEESa3IZP1S6arU91GJpBMlxqWLb5kiCn+QX1/VVemHjb1kcf5GU/rMl8UoUfVJ /bL2e9hxLOoWkRd23IOIGDEzRxravWMxtfWMx8/J8DbWBsqk33eDVAZ9JsVz+qRhxg7A T4aQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WEJl1umW; 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 n66-20020a634045000000b00543a881db09si145738pga.402.2023.06.23.13.15.59; Fri, 23 Jun 2023 13:16:12 -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=WEJl1umW; 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 S231765AbjFWUAr (ORCPT + 99 others); Fri, 23 Jun 2023 16:00:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229620AbjFWUAp (ORCPT ); Fri, 23 Jun 2023 16:00:45 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D5702736 for ; Fri, 23 Jun 2023 12:59:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687550393; 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=bRaQkpW8TcfPoBNjOHA2HT8r7AuFWY474S3n34c5w7Y=; b=WEJl1umWI5s29vHRlb6NTPYlpKzniH15JEjW+i9lcLbj6v+ivE9AIqQzd4bqP4h8i20e2k EpRLehU2yT41F/wvl9Pp9CJRf7SRtvE0nuDXcaLg9Oz2Lphp4fVqNliJwD6RWHhod8D9iE aggXv3RlvhWDGNM7HUT27ZdisOpmN88= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-344-ITDEfdwjNmy5KdCgUGIWsA-1; Fri, 23 Jun 2023 15:59:51 -0400 X-MC-Unique: ITDEfdwjNmy5KdCgUGIWsA-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 942F93813F3C; Fri, 23 Jun 2023 19:59:50 +0000 (UTC) Received: from lorien.usersys.redhat.com (unknown [10.22.33.48]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DE86DC00049; Fri, 23 Jun 2023 19:59:49 +0000 (UTC) Date: Fri, 23 Jun 2023 15:59:47 -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: <20230623195947.GC766130@lorien.usersys.redhat.com> References: <20230622132751.2900081-1-pauld@redhat.com> <20230622213730.GE727646@lorien.usersys.redhat.com> <20230623130859.GA766130@lorien.usersys.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Fri, Jun 23, 2023 at 11:59:09AM -0700 Benjamin Segall wrote: > Phil Auld writes: > > > 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. > > > > That is unfortunate. I suppose then you'd wind up needing both this > extra bit in PNT to handle the switch into nr_running == 1 territory, > and a "HZ_BW && nr_running == 1 && curr is fair && curr->on_rq && > curr->cfs_rq->runtime_enabled" check in sched_can_stop_tick to catch > edge cases. (I think that would be sufficient, if an annoyingly long set > of conditionals) > Right. That's more or less what the version I'm testing now does. Thanks again. Cheers, Phil --