From patchwork Sat Nov 4 10:59:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Bristot de Oliveira X-Patchwork-Id: 161567 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp1580830vqu; Sat, 4 Nov 2023 04:01:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGv38yzXoqTWkq7caEeF+fbUW8WjOIAOF8s6Q/4iutzCCvPdqdL47i/sosFKkjtCRs0JXFV X-Received: by 2002:a05:6820:1e05:b0:586:a5f2:2a96 with SMTP id dh5-20020a0568201e0500b00586a5f22a96mr23349540oob.2.1699095674430; Sat, 04 Nov 2023 04:01:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699095674; cv=none; d=google.com; s=arc-20160816; b=aW/I27BzR+IpIrzsn0GDcC0qzR47qOoZQa4hXTY+mT2gydEsJ1QChGGtMhmVY5B4H4 SvQRzglsNgxIWcTO8u36e4N1wb40SjvtPu9ozofwf2+ALqK+9y9+Js/05uLxvM72yeGZ xuLCzZJkNl/RIgYqZagUFVDWELwjRnh9bk3frgFlPqVgd5061ObqZGWmoipYpyijkvyE i0bMF8B42mmxiv5ccsGzWluRB6TzxoxGLtsFN1GilUw9vMEeJR2ameIHZRmx6GyFnAbz 0J3wd9R//o6jqWD/32zvV5TxYPT+JWsR9BZvFHUuq4Sjz1qJ+N3BTnplq/soPYpJ+HCK ABXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ICfQqtpGLbtSe+vZQpTwV4N0+rpKS90oxrjezaRldEk=; fh=hclUZirF6ioy5RJ9ji4zprhkXEWhJA3xztaBC4vzfLk=; b=CjTcrZ/EyX46MP6JwQMMHfaBylc8ZOsVQU58v0KFHmxDRYa+phervjBE8SmPnyH4Dl CmaKBUOZ2MkAVr1Fm5D53hPDOrmQSyAzEqv4ZHpYvv3gPMIhJRV7s3j2z9y8HMFGJ2Jm QWN1zH4IDB2YmIhvXgBFBILZ9qxHy2bPmspExeTaEmCYQQ3npw4HK9qEodCzWcQgbt7v lfQyHlAQZbk/i9z31J8jo+U5Hw3wdEwnSo2oEQaCjUVhd1qDoTaUe5uwlFdt6rQr2vcC 8hIuUAg1s/nEX7KGqiBoW9dmLN7LWoyncLFAdDJFw4c7uRxI+rdzTpBARaDPDA5bplWF M18g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="AVL4/tyF"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id b1-20020a4ae801000000b005820ade092esi1396588oob.8.2023.11.04.04.01.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Nov 2023 04:01:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="AVL4/tyF"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 6DF82816F0E8; Sat, 4 Nov 2023 04:00:58 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231956AbjKDLAa (ORCPT + 35 others); Sat, 4 Nov 2023 07:00:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232340AbjKDLAB (ORCPT ); Sat, 4 Nov 2023 07:00:01 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BD1A10D0 for ; Sat, 4 Nov 2023 03:59:55 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA6D0C433CB; Sat, 4 Nov 2023 10:59:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699095594; bh=1Wn77Swl4Ek25DMos+AE5sSW8ut9WCzWOgUJJ0gtsq0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AVL4/tyFOIi4wjwakWUVUHTK1SgC3EDGT0aPFBbepSWJYrqLg/hCyg3TJSxgGJAFH 4Y5ql8Nt79JIvjdyx4Nk/qPbnC+Ce8docMPTFKHw7y3TwGlw5tC6pNsue0MC59fnlf jHXdHsPku61YscKt32ZrRq33ApU1h8W+DHxUs1qibKfUYmE9mWjoJgGdaBaonU0bm9 pK0QwHtiMcPO9PlG7vX8yP3Uk6T5QwfdeHkB0OvT351RjFqXzSJTNd5lMV3//aF0EA OveavfSOEmA1f7bysOFhnV0D3dTZTK472qdrNjbvge+p9HsWZJUVoh0Bk0b1UsALG2 2taGT7V0EqyAw== From: Daniel Bristot de Oliveira To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot Cc: 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 , Joel Fernandes , Vineeth Pillai , Shuah Khan , bristot@kernel.org, Phil Auld Subject: [PATCH v5 5/7] sched/fair: Add trivial fair server Date: Sat, 4 Nov 2023 11:59:22 +0100 Message-Id: <4e0d14eb6e0ec33055197ac7ddb57ef7ab3894a5.1699095159.git.bristot@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-1.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Sat, 04 Nov 2023 04:00:58 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781630946163531831 X-GMAIL-MSGID: 1781630946163531831 From: Peter Zijlstra Use deadline servers to service fair tasks. This patch adds a fair_server deadline entity which acts as a container for fair entities and can be used to fix starvation when higher priority (wrt fair) tasks are monopolizing CPU(s). [ dl_server do not account for rt ] Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Daniel Bristot de Oliveira --- kernel/sched/core.c | 1 + kernel/sched/deadline.c | 7 +++++++ kernel/sched/fair.c | 29 +++++++++++++++++++++++++++++ kernel/sched/sched.h | 4 ++++ 4 files changed, 41 insertions(+) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index a721f6776b12..939266d29681 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -10019,6 +10019,7 @@ void __init sched_init(void) #endif /* CONFIG_SMP */ hrtick_rq_init(rq); atomic_set(&rq->nr_iowait, 0); + fair_server_init(rq); #ifdef CONFIG_SCHED_CORE rq->core = rq; diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c index 541d547e1019..1d7b96ca9011 100644 --- a/kernel/sched/deadline.c +++ b/kernel/sched/deadline.c @@ -1382,6 +1382,13 @@ static void update_curr_dl_se(struct rq *rq, struct sched_dl_entity *dl_se, s64 resched_curr(rq); } + /* + * The fair server (sole dl_server) does not account for real-time + * workload because it is running fair work. + */ + if (dl_server(dl_se)) + return; + /* * Because -- for now -- we share the rt bandwidth, we need to * account our runtime there too, otherwise actual rt tasks diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index bc3a4bc6c438..b15f7f376a67 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -6600,6 +6600,9 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags) */ util_est_enqueue(&rq->cfs, p); + if (!rq->cfs.h_nr_running) + dl_server_start(&rq->fair_server); + /* * If in_iowait is set, the code below may not trigger any cpufreq * utilization updates, so do it here explicitly with the IOWAIT flag @@ -6744,6 +6747,9 @@ static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags) rq->next_balance = jiffies; dequeue_throttle: + if (!rq->cfs.h_nr_running) + dl_server_stop(&rq->fair_server); + util_est_update(&rq->cfs, p, task_sleep); hrtick_update(rq); } @@ -8396,6 +8402,29 @@ static struct task_struct *__pick_next_task_fair(struct rq *rq) return pick_next_task_fair(rq, NULL, NULL); } +static bool fair_server_has_tasks(struct sched_dl_entity *dl_se) +{ + return !!dl_se->rq->cfs.nr_running; +} + +static struct task_struct *fair_server_pick(struct sched_dl_entity *dl_se) +{ + return pick_next_task_fair(dl_se->rq, NULL, NULL); +} + +void fair_server_init(struct rq *rq) +{ + struct sched_dl_entity *dl_se = &rq->fair_server; + + init_dl_entity(dl_se); + + dl_se->dl_runtime = 50 * NSEC_PER_MSEC; + dl_se->dl_deadline = 1000 * NSEC_PER_MSEC; + dl_se->dl_period = 1000 * NSEC_PER_MSEC; + + dl_server_init(dl_se, rq, fair_server_has_tasks, fair_server_pick); +} + /* * Account for a descheduled task: */ diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 24a2bc7c453b..ec0e288c8e06 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -340,6 +340,8 @@ extern void dl_server_init(struct sched_dl_entity *dl_se, struct rq *rq, dl_server_has_tasks_f has_tasks, dl_server_pick_f pick); +extern void fair_server_init(struct rq *); + #ifdef CONFIG_CGROUP_SCHED struct cfs_rq; @@ -1005,6 +1007,8 @@ struct rq { struct rt_rq rt; struct dl_rq dl; + struct sched_dl_entity fair_server; + #ifdef CONFIG_FAIR_GROUP_SCHED /* list of leaf cfs_rq on this CPU: */ struct list_head leaf_cfs_rq_list;