Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp1862097rwn; Fri, 16 Sep 2022 01:49:23 -0700 (PDT) X-Google-Smtp-Source: AMsMyM75KXinQ2xftmAiagXwdhn/TMvBRnI2jE3g3BM4gm2sw5xrG1CO0TYE4csW2HzZfUmitxDR X-Received: by 2002:a17:90b:4c91:b0:202:a345:b771 with SMTP id my17-20020a17090b4c9100b00202a345b771mr15382750pjb.128.1663318163745; Fri, 16 Sep 2022 01:49:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663318163; cv=none; d=google.com; s=arc-20160816; b=zgZGtfwYgsIjFIlMeQIOYydfsG3iLiPlPCKhU91ecIvCCx7/YSHdm4g+X9tPifpT8V RkHcdQrunMaFhjKgOQSEozD718A/OZtH6cRFMnh6VaFK9mUxOExbf0hKHnPNEaIeVhg2 yAbIBB47q3Iqy6Q9iQ8DYqcCMrAKl2H0kMVoUmlx4TR1hMJT7hG+h5+cXx+9Fa9vBEp8 0P4fTP/DnwWCASzw0eSm24vMiueLBmTtC1RxbxLEOCePpyEqyz/CbxYo3AJT+tpzrP2e 1k+Rloy+02FGTozq1LEHgDmVhnVwaDR06gVm28PBPTlLCPzpDzz8+TQo3swndyWDseyl 8hAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=tKt+6OFmIt3Z0xnB+vzUXObwuSdNapz5e2blq4g9QGQ=; b=QsvNwxKKn6dbjh0uh4QziQ2SX3jhws0bAB23MEOpL4qCaF7X6PJdRxhJNyCHDpqdGv GvOXFqzxnWU/d0+RvkG1D0Nwy4BhKj1Vc3Gb1SBHLSnnctidl66sSNBg+YntbdN4oYzl j7aadbZRtnLLxu0wcz8zV9SpCFqbqfyC+Uj6Ap3ADlJ9tTrmc9jQ2TqdoDu6g3Wr6i+2 Welm+Au+mjdJce/GUoG0ZGXg+/LRqyP3jhHpmFI8S2Ps0gaofhQv3BQ6tAlRulWwQOmr BSTO3QK25fGztZR/m62XIYfcTtq5xQlYP2Ex2TaicdBOK1Dhk80u8Jn8f1k7KkdhmfhD //Hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Ll/VfUsK"; 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=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t16-20020a170902e85000b00177fd9637cbsi23657735plg.570.2022.09.16.01.49.12; Fri, 16 Sep 2022 01:49:23 -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=@linaro.org header.s=google header.b="Ll/VfUsK"; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230322AbiIPIEq (ORCPT + 99 others); Fri, 16 Sep 2022 04:04:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230190AbiIPIDd (ORCPT ); Fri, 16 Sep 2022 04:03:33 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51E53A50F8 for ; Fri, 16 Sep 2022 01:03:26 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id g3so13801654wrq.13 for ; Fri, 16 Sep 2022 01:03:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date; bh=tKt+6OFmIt3Z0xnB+vzUXObwuSdNapz5e2blq4g9QGQ=; b=Ll/VfUsKJx+YkFaTpFXyr99e2u1OICPXG8rEdBFbQDJKr8bNQ1ueCKgydggbMunYWJ RqP8wtXW2t5/JjF0yGqNWPD+Jp++VCePswHtCWvCpPTzQf9j+fP24sGKek8GTyhcFdKi /L+3GLrMRW0knpkuYvqBZ5L8G1DpAAK3yZd6GUyAaMfHE5P930wOl1SJAW5wkS7NKEL/ bfGDkw6xOBXeqbifbweMxb2ch3umYwe8MlcsiyQU2V0V/V1TmuUFoMsbyqKGel48rAXD Jeala/WM9kmOaCFS/PRIHgWQXfsQZSb/e4opsbQMLrGs0poFpmqNQR/6R4R1uYS/KXzo i/4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date; bh=tKt+6OFmIt3Z0xnB+vzUXObwuSdNapz5e2blq4g9QGQ=; b=JXeJWg/aonnnX8hAz2J+f0LKQElrs5/YRsxhP0Uwj5+6jDgy1pgqm+aKi1pWQefZij 5XptZbr2vMkVzu1GxpQFs+YNkQIkarZ8NQIc2ldXa2lYbmRPJiblqqgs+s3ahsaHT0RA AoPmNElFjKNTU7VgACRcb+1EE05PKQtqNQVo/3UwBLLLADB4IO7gOQbUV6jEG7NNA2dl SVIYYo/M45nIj+E0QwVc4RpK79g0JGcjv+EVNmLFJ7KZtqqv3LFTdQan9YJ8qrv0HCVO StkgP6/CQi+pGLDPOk3t/ATlG7V/vSgMJQvN/RrBivuJ6vhbOBS4Eimw5OPJTJ/J1l+E Lxxg== X-Gm-Message-State: ACrzQf0Fy55BdK3HQmrXWr4kFnBnx0NWEo+/cy6DQPEv7zHbgLv6NHXt N04JApK1vqNPNIuBbR217IryHQ== X-Received: by 2002:a05:6000:10d2:b0:228:d60b:6d5a with SMTP id b18-20020a05600010d200b00228d60b6d5amr1932207wrx.146.1663315404718; Fri, 16 Sep 2022 01:03:24 -0700 (PDT) Received: from localhost.localdomain ([2a01:e0a:f:6020:9ab:1164:827a:1548]) by smtp.gmail.com with ESMTPSA id c9-20020adffb49000000b00228dbf15072sm4418116wrs.62.2022.09.16.01.03.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 01:03:23 -0700 (PDT) From: Vincent Guittot To: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, linux-kernel@vger.kernel.org, parth@linux.ibm.com Cc: qais.yousef@arm.com, chris.hyser@oracle.com, valentin.schneider@arm.com, patrick.bellasi@matbug.net, David.Laight@aculab.com, pjt@google.com, pavel@ucw.cz, tj@kernel.org, qperret@google.com, tim.c.chen@linux.intel.com, joshdon@google.com, Vincent Guittot Subject: [PATCH v4 6/8] sched/fair: Add sched group latency support Date: Fri, 16 Sep 2022 10:03:03 +0200 Message-Id: <20220916080305.29574-7-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220916080305.29574-1-vincent.guittot@linaro.org> References: <20220916080305.29574-1-vincent.guittot@linaro.org> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS 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 Task can set its latency priority, which is then used to decide to preempt the current running entity of the cfs, but sched group entities still have the default latency offset. Add a latency field in task group to set the latency offset of the sched_eneities of the group, which will be used against other entities in the parent cfs when deciding which entity to schedule first. Signed-off-by: Vincent Guittot --- kernel/sched/core.c | 24 ++++++++++++++++++++++++ kernel/sched/fair.c | 33 +++++++++++++++++++++++++++++++++ kernel/sched/sched.h | 4 ++++ 3 files changed, 61 insertions(+) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 13cf794708ee..bfea862a3588 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -10860,6 +10860,19 @@ static int cpu_idle_write_s64(struct cgroup_subsys_state *css, { return sched_group_set_idle(css_tg(css), idle); } + +static s64 cpu_latency_read_s64(struct cgroup_subsys_state *css, + struct cftype *cft) +{ + return css_tg(css)->latency_offset; +} + +static int cpu_latency_write_s64(struct cgroup_subsys_state *css, + struct cftype *cft, s64 latency) +{ + return sched_group_set_latency(css_tg(css), latency); +} + #endif static struct cftype cpu_legacy_files[] = { @@ -10874,6 +10887,11 @@ static struct cftype cpu_legacy_files[] = { .read_s64 = cpu_idle_read_s64, .write_s64 = cpu_idle_write_s64, }, + { + .name = "latency", + .read_s64 = cpu_latency_read_s64, + .write_s64 = cpu_latency_write_s64, + }, #endif #ifdef CONFIG_CFS_BANDWIDTH { @@ -11091,6 +11109,12 @@ static struct cftype cpu_files[] = { .read_s64 = cpu_idle_read_s64, .write_s64 = cpu_idle_write_s64, }, + { + .name = "latency", + .flags = CFTYPE_NOT_ON_ROOT, + .read_s64 = cpu_latency_read_s64, + .write_s64 = cpu_latency_write_s64, + }, #endif #ifdef CONFIG_CFS_BANDWIDTH { diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index a20eadb0af97..6cc4f2a9725d 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -11769,6 +11769,7 @@ int alloc_fair_sched_group(struct task_group *tg, struct task_group *parent) goto err; tg->shares = NICE_0_LOAD; + tg->latency_offset = 0; init_cfs_bandwidth(tg_cfs_bandwidth(tg)); @@ -11867,6 +11868,9 @@ void init_tg_cfs_entry(struct task_group *tg, struct cfs_rq *cfs_rq, } se->my_q = cfs_rq; + + se->latency_offset = tg->latency_offset; + /* guarantee group entities always have weight */ update_load_set(&se->load, NICE_0_LOAD); se->parent = parent; @@ -11997,6 +12001,35 @@ int sched_group_set_idle(struct task_group *tg, long idle) return 0; } +int sched_group_set_latency(struct task_group *tg, long latency) +{ + int i; + + if (tg == &root_task_group) + return -EINVAL; + + if (abs(latency) > sysctl_sched_latency) + return -EINVAL; + + mutex_lock(&shares_mutex); + + if (tg->latency_offset == latency) { + mutex_unlock(&shares_mutex); + return 0; + } + + tg->latency_offset = latency; + + for_each_possible_cpu(i) { + struct sched_entity *se = tg->se[i]; + + WRITE_ONCE(se->latency_offset, latency); + } + + mutex_unlock(&shares_mutex); + return 0; +} + #else /* CONFIG_FAIR_GROUP_SCHED */ void free_fair_sched_group(struct task_group *tg) { } diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index a4cb8058f1b2..619132f4f480 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -406,6 +406,8 @@ struct task_group { /* A positive value indicates that this is a SCHED_IDLE group. */ int idle; + /* latency constraint of the group. */ + int latency_offset; #ifdef CONFIG_SMP /* @@ -519,6 +521,8 @@ extern int sched_group_set_shares(struct task_group *tg, unsigned long shares); extern int sched_group_set_idle(struct task_group *tg, long idle); +extern int sched_group_set_latency(struct task_group *tg, long latency); + #ifdef CONFIG_SMP extern void set_task_rq_fair(struct sched_entity *se, struct cfs_rq *prev, struct cfs_rq *next); -- 2.17.1