Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp2355039rdf; Mon, 6 Nov 2023 11:32:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IHtwHvyzWWN6EznDM2VoYLgZ9+N4v34068a+uFQ2tJltLRPqXPJd+uJmGeT44NTRkczehZQ X-Received: by 2002:a17:903:434d:b0:1cc:3f6b:a4b6 with SMTP id lo13-20020a170903434d00b001cc3f6ba4b6mr21287261plb.56.1699299172577; Mon, 06 Nov 2023 11:32:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699299172; cv=none; d=google.com; s=arc-20160816; b=vk5yD46WbPXwX32rmjQDfx4fLy28mDVI6K2ktJT1vZrOnsYpNtMnVH85Ra/Y0u9lNE vYftGthh3fSrlN3qQpsvavWSoM7EZk8LQlCKdywEheZaP/+G6P+Hjmxx+HadEOdQWwDd olZ20jV3+2qnft6YzO0Crucik+H8atevDsjgEYTPJNBX6rQj7B03K32ngDpwLWWeWbOr gumHYTg2dxXfdQc8qOoy2NJrc2LGTpUpSWpJhcfEgoEOg9cciWLzbpLl4/z67TsdzNhL yAw1KljVPixKQE19L+teHAic1G8mDpFq7OEq6UwxazOq98BUNqTRDN0Py9TbemdJNE6N y2iQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=i7OTagdrCYJNoUUZ8+xdC4tMP9kaJwYxqUqoXu3+oM0=; fh=VPaN+orJ8iBLsOu4c363yD1VuIwopVw/devgFaoaKR8=; b=FDzIoNWt1bc4yJKQSi8E/K8iVcswoIztwAL2bzkXg95A0BOyCsU9IKZC86ATRU9ZeD HzhAUL2i0eWsPkow0yWgC3+mOMEUhDXw6zAGgbu8AZeDGc74hz4JLkXfJou9uVzk/+90 L3oeB51RGxZ5TOijnZ2S3608LT1LIMS3VJZnt/7JS3ZbR9VYdHWk6eREs0QEoSZEAz3V INYeKB9RINg+99QZr6sVsZYwz6BZDW9cizW847DyyiEuCAd4Tyj0CfkmPBneiCFkY1kn MiOiB0bzYecfhWuCmZvJ33/YmRFtwxPgnu5zh0rQO+hC1WLtHgqi9+MpPsVATWescm6O Sm6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b="UnbJzX/J"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id le16-20020a170902fb1000b001c4401a7e18si8282057plb.382.2023.11.06.11.32.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 11:32:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b="UnbJzX/J"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 9975980C3474; Mon, 6 Nov 2023 11:32:42 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231773AbjKFTcU (ORCPT + 99 others); Mon, 6 Nov 2023 14:32:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231277AbjKFTcS (ORCPT ); Mon, 6 Nov 2023 14:32:18 -0500 Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95DC8C6 for ; Mon, 6 Nov 2023 11:32:15 -0800 (PST) Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2c5629fdbf8so60728551fa.0 for ; Mon, 06 Nov 2023 11:32:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; t=1699299134; x=1699903934; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=i7OTagdrCYJNoUUZ8+xdC4tMP9kaJwYxqUqoXu3+oM0=; b=UnbJzX/JmQ0838ZNsdTCBLd962vTmfRHpiV9X2nvtdfo/Z86hNRBCf8yROwieKu3C0 x5yQkz84fntQjBeGf5XR6eKLH4i6AVzA3YZ/XHjlgWDB+8ozK30huKv0LqfMfQfPfUxF GouIEfuKmK2zRuYkO2FHStmDaQNkvabSVmuR8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699299134; x=1699903934; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=i7OTagdrCYJNoUUZ8+xdC4tMP9kaJwYxqUqoXu3+oM0=; b=tMwW4WhzZVAoIRb1kH5nNwfLI/jYSggfr7jRz57fSMcd6L07zaFHsyHIeATEMB9WRg cghgcSFdSN2kRzqrl2Id+kOW+nt39gmqa18d089/83UfZ9zLl7l/rbXdhPu3IRFcrghc UMqhJIemBh89/tXpZofymw939TxhyKhfUzarOM0zjGsO6SKzVtIBdYApBwvtIwrmZ8H+ vcnX/coAdIwHqsmx9ZxsnmtY5pcHd8dsZ/7pPiJu7Kjps92f6M+72YVySd3HJyLufPSr 8YACZCEbfb4DIRYEHYUgv59RKoC0dCKjmv0qgACSZx6fZ0XNmxYtQog184iYzazahZ6l kkLg== X-Gm-Message-State: AOJu0YwjkHsVRhfQxp/9bVvtOoIknQDoTkdKJebCBHEsmhbxlKaL9AS5 BqgRzmySw7GnZ76sRlUYfU1Qlv5v/0sYnAZt2JxGnA== X-Received: by 2002:a2e:9d47:0:b0:2c2:c450:c2d0 with SMTP id y7-20020a2e9d47000000b002c2c450c2d0mr21907921ljj.24.1699299133540; Mon, 06 Nov 2023 11:32:13 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Joel Fernandes Date: Mon, 6 Nov 2023 14:32:02 -0500 Message-ID: Subject: Re: [PATCH v5 6/7] sched/deadline: Deferrable dl server To: Daniel Bristot de Oliveira 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, Luca Abeni , Tommaso Cucinotta , Thomas Gleixner , Vineeth Pillai , Shuah Khan , Phil Auld Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email 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 (fry.vger.email [0.0.0.0]); Mon, 06 Nov 2023 11:32:42 -0800 (PST) Hi Daniel, On Sat, Nov 4, 2023 at 6:59=E2=80=AFAM Daniel Bristot de Oliveira wrote: > > Among the motivations for the DL servers is the real-time throttling > mechanism. This mechanism works by throttling the rt_rq after > running for a long period without leaving space for fair tasks. > > The base dl server avoids this problem by boosting fair tasks instead > of throttling the rt_rq. The point is that it boosts without waiting > for potential starvation, causing some non-intuitive cases. > > For example, an IRQ dispatches two tasks on an idle system, a fair > and an RT. The DL server will be activated, running the fair task > before the RT one. This problem can be avoided by deferring the > dl server activation. > > By setting the zerolax option, the dl_server will dispatch an > SCHED_DEADLINE reservation with replenished runtime, but throttled. > > The dl_timer will be set for (period - runtime) ns from start time. > Thus boosting the fair rq on its 0-laxity time with respect to > rt_rq. > > If the fair scheduler has the opportunity to run while waiting > for zerolax time, the dl server runtime will be consumed. If > the runtime is completely consumed before the zerolax time, the > server will be replenished while still in a throttled state. Then, > the dl_timer will be reset to the new zerolax time > > If the fair server reaches the zerolax time without consuming > its runtime, the server will be boosted, following CBS rules > (thus without breaking SCHED_DEADLINE). > > Signed-off-by: Daniel Bristot de Oliveira > --- > include/linux/sched.h | 2 + > kernel/sched/deadline.c | 100 +++++++++++++++++++++++++++++++++++++++- > kernel/sched/fair.c | 3 ++ > 3 files changed, 103 insertions(+), 2 deletions(-) > > diff --git a/include/linux/sched.h b/include/linux/sched.h > index 5ac1f252e136..56e53e6fd5a0 100644 > --- a/include/linux/sched.h > +++ b/include/linux/sched.h > @@ -660,6 +660,8 @@ struct sched_dl_entity { > unsigned int dl_non_contending : 1; > unsigned int dl_overrun : 1; > unsigned int dl_server : 1; > + unsigned int dl_zerolax : 1; > + unsigned int dl_zerolax_armed : 1; > > /* > * Bandwidth enforcement timer. Each -deadline task has its > diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c > index 1d7b96ca9011..69ee1fbd60e4 100644 > --- a/kernel/sched/deadline.c > +++ b/kernel/sched/deadline.c > @@ -772,6 +772,14 @@ static inline void replenish_dl_new_period(struct sc= hed_dl_entity *dl_se, > /* for non-boosted task, pi_of(dl_se) =3D=3D dl_se */ > dl_se->deadline =3D rq_clock(rq) + pi_of(dl_se)->dl_deadline; > dl_se->runtime =3D pi_of(dl_se)->dl_runtime; > + > + /* > + * If it is a zerolax reservation, throttle it. > + */ > + if (dl_se->dl_zerolax) { > + dl_se->dl_throttled =3D 1; > + dl_se->dl_zerolax_armed =3D 1; > + } > } > > /* > @@ -828,6 +836,7 @@ static inline void setup_new_dl_entity(struct sched_d= l_entity *dl_se) > * could happen are, typically, a entity voluntarily trying to overcome = its > * runtime, or it just underestimated it during sched_setattr(). > */ > +static int start_dl_timer(struct sched_dl_entity *dl_se); > static void replenish_dl_entity(struct sched_dl_entity *dl_se) > { > struct dl_rq *dl_rq =3D dl_rq_of_se(dl_se); > @@ -874,6 +883,28 @@ static void replenish_dl_entity(struct sched_dl_enti= ty *dl_se) > dl_se->dl_yielded =3D 0; > if (dl_se->dl_throttled) > dl_se->dl_throttled =3D 0; > + > + /* > + * If this is the replenishment of a zerolax reservation, > + * clear the flag and return. > + */ > + if (dl_se->dl_zerolax_armed) { > + dl_se->dl_zerolax_armed =3D 0; > + return; > + } > + > + /* > + * A this point, if the zerolax server is not armed, and the dead= line > + * is in the future, throttle the server and arm the zerolax time= r. > + */ > + if (dl_se->dl_zerolax && > + dl_time_before(dl_se->deadline - dl_se->runtime, rq_clock(rq)= )) { > + if (!is_dl_boosted(dl_se)) { > + dl_se->dl_zerolax_armed =3D 1; > + dl_se->dl_throttled =3D 1; > + start_dl_timer(dl_se); > + } > + } > } > > /* > @@ -1024,6 +1055,13 @@ static void update_dl_entity(struct sched_dl_entit= y *dl_se) > } > > replenish_dl_new_period(dl_se, rq); > + } else if (dl_server(dl_se) && dl_se->dl_zerolax) { > + /* > + * The server can still use its previous deadline, so thr= ottle > + * and arm the zero-laxity timer. > + */ > + dl_se->dl_zerolax_armed =3D 1; > + dl_se->dl_throttled =3D 1; > } > } > > @@ -1056,8 +1094,20 @@ static int start_dl_timer(struct sched_dl_entity *= dl_se) > * We want the timer to fire at the deadline, but considering > * that it is actually coming from rq->clock and not from > * hrtimer's time base reading. > + * > + * The zerolax reservation will have its timer set to the > + * deadline - runtime. At that point, the CBS rule will decide > + * if the current deadline can be used, or if a replenishment > + * is required to avoid add too much pressure on the system > + * (current u > U). > */ > - act =3D ns_to_ktime(dl_next_period(dl_se)); > + if (dl_se->dl_zerolax_armed) { > + WARN_ON_ONCE(!dl_se->dl_throttled); > + act =3D ns_to_ktime(dl_se->deadline - dl_se->runtime); Just a question, here if dl_se->deadline - dl_se->runtime is large, then does that mean that server activation will be much more into the future? So say I want to give CFS 30%, then it will take 70% of the period before CFS preempts RT thus "starving" CFS for this duration. I think that's Ok for smaller periods and runtimes, though. I think it does reserve the amount of required CFS bandwidth so it is probably OK, though it is perhaps letting RT run more initially (say if CFS tasks are not CPU bound and occasionally wake up, they will always be hit by the 70% latency AFAICS which may be large for large periods and small runtimes). I/we're currently trying these patches on ChromeOS as well. Just started going over it to understand the patch. Looking nice so far and thanks, - Joel