From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64F09EB64D7 for ; Fri, 23 Jun 2023 13:09:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231243AbjFWNJw (ORCPT ); Fri, 23 Jun 2023 09:09:52 -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 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 > > -- > --