Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2327881imm; Fri, 7 Sep 2018 14:44:52 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYHOR1/yXTp7YM/lqK9uDg37mKYQHiLFnZF+a4kfScSZBBk+q9mYoZ3rLO/56gHLLE+YHGk X-Received: by 2002:a63:e60c:: with SMTP id g12-v6mr10551512pgh.308.1536356692849; Fri, 07 Sep 2018 14:44:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536356692; cv=none; d=google.com; s=arc-20160816; b=DEhohazBl0w8uhtvQ/UkEwxJk773hoZlUw1hLW/Z4C8HFeXyyTS+V72PSv3vJxaq4O emAkxdcYGqO9DU/65RlklrQs0Muhny2UU2tJUv3xfrRb5Xgnd6Zrucg9CWOUW9uHeqfj GPnGXXhFcup8dsR8VqWIzpX1B49acY0iLl/8U4Vqu2/j4FKnt9EZy9NxSSRw2Wwt0SVH ugbiqh0BEMI81BMZ/cKQIVtgVWCgWlnHFHF1oDrFAJc0zU4v/D7N36vQgXERY1KFf7ge aKxeK1l6GtatzsxVXmU0Obg0+2+MIlqCIbQNcG+T5eOq/BU0nHxBk7bZPt6DdFKK8HrR Wr1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fL5FyRBsnH3lytedn56yQzL76vKd4bPrtf5yNw52c4E=; b=phwmCH34iyFufCgqCoMM/t3NmWcoqQ8VToUlhY20tDHufs/V+zi8Zb/dX8ESJ2+Mse esYLIrkFrOHEgjUEufvSz0EjaZcsXm0L76JNC78RJFR6I/Kt6gBRc6H7Cy5/Cg2/B5LA VeBtYB6QuFyzPSbxc64n8W7tH2L6DVBoSBt7SjvB37/mf3Vrx35IakK+2lbGiF+ihIgt qxo01D7kqRK+ET8rYN8gMYdubP1RtUCaU8N5IwT0Ay7gD41Ti6pDa8C+NWK4dIYurU4Y 0fV/uzkIZUL0dfJg15MkMYEqqQOuyPcvNH8OhgZ43ndvlffSihdyzchkUGMhZzi4MQTb jO6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b=AXfkI8G1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d130-v6si9736378pga.657.2018.09.07.14.44.37; Fri, 07 Sep 2018 14:44:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b=AXfkI8G1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730832AbeIHC0H (ORCPT + 99 others); Fri, 7 Sep 2018 22:26:07 -0400 Received: from smtp-fw-2101.amazon.com ([72.21.196.25]:13133 "EHLO smtp-fw-2101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730791AbeIHC0G (ORCPT ); Fri, 7 Sep 2018 22:26:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1536356591; x=1567892591; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fL5FyRBsnH3lytedn56yQzL76vKd4bPrtf5yNw52c4E=; b=AXfkI8G1d6dthi3Yj0ZpAWZGvVt0sDLGmdUBKn48YQRkh2eRvbpnuXZX NsSWRzB+R2vLSbArWiE+MI2wbRfXT5bWnvktvuuEQZii8VMhkgeud5VQo X+PEsVXPjuGQ9dEAjJhSSNGuXeHdcsIXhu0bHWcOrOObcmu8O3X2XsxK9 4=; X-IronPort-AV: E=Sophos;i="5.53,343,1531785600"; d="scan'208";a="696510041" Received: from iad6-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-1a-16acd5e0.us-east-1.amazon.com) ([10.124.125.2]) by smtp-border-fw-out-2101.iad2.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 07 Sep 2018 21:43:10 +0000 Received: from u7588a65da6b65f.ant.amazon.com (iad7-ws-svc-lb50-vlan2.amazon.com [10.0.93.210]) by email-inbound-relay-1a-16acd5e0.us-east-1.amazon.com (8.14.7/8.14.7) with ESMTP id w87Lh4uu021881 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Fri, 7 Sep 2018 21:43:07 GMT Received: from u7588a65da6b65f.ant.amazon.com (localhost [127.0.0.1]) by u7588a65da6b65f.ant.amazon.com (8.15.2/8.15.2/Debian-3) with ESMTPS id w87Lh2di027857 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 7 Sep 2018 23:43:03 +0200 Received: (from jschoenh@localhost) by u7588a65da6b65f.ant.amazon.com (8.15.2/8.15.2/Submit) id w87Lh1YA027856; Fri, 7 Sep 2018 23:43:01 +0200 From: =?UTF-8?q?Jan=20H=2E=20Sch=C3=B6nherr?= To: Ingo Molnar , Peter Zijlstra Cc: =?UTF-8?q?Jan=20H=2E=20Sch=C3=B6nherr?= , linux-kernel@vger.kernel.org Subject: [RFC 57/60] cosched: Add sysfs interface to configure coscheduling on cgroups Date: Fri, 7 Sep 2018 23:40:44 +0200 Message-Id: <20180907214047.26914-58-jschoenh@amazon.de> X-Mailer: git-send-email 2.9.3.1.gcba166c.dirty In-Reply-To: <20180907214047.26914-1-jschoenh@amazon.de> References: <20180907214047.26914-1-jschoenh@amazon.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add the sysfs interface to configure the scheduling domain hierarchy level at which coscheduling should happen for a cgroup. By default, task groups are created with a value of zero corresponding to regular task groups without any coscheduling. Note, that you cannot specify a value that goes beyond that of the root task group. The value for the root task group cannot be configured via this interface. It has to be configured with a command line argument, which will be added later. The function sdrq_update_root() will be filled in a follow-up commit. Signed-off-by: Jan H. Schönherr --- kernel/sched/core.c | 44 +++++++++++++++++++++++++++++++++++++++++ kernel/sched/cosched.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ kernel/sched/sched.h | 4 ++++ 3 files changed, 101 insertions(+) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 75de3b83a8c6..ad2ff9bc535c 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -6336,6 +6336,9 @@ void sched_offline_group(struct task_group *tg) { unsigned long flags; + /* Don't let offlining/destruction worry about coscheduling aspects */ + cosched_set_scheduled(tg, 0); + /* End participation in shares distribution: */ unregister_fair_sched_group(tg); @@ -6529,7 +6532,33 @@ static u64 cpu_shares_read_u64(struct cgroup_subsys_state *css, return (u64) scale_load_down(tg->shares); } +#endif /* CONFIG_FAIR_GROUP_SCHED */ + +#ifdef CONFIG_COSCHEDULING +static int cpu_scheduled_write_u64(struct cgroup_subsys_state *css, struct cftype *cftype, + u64 val) +{ + struct task_group *tg = css_tg(css); + + if (tg == &root_task_group) + return -EACCES; + + if (val > root_task_group.scheduled) + return -EINVAL; + + cosched_set_scheduled(tg, val); + return 0; +} +static u64 cpu_scheduled_read_u64(struct cgroup_subsys_state *css, struct cftype *cft) +{ + struct task_group *tg = css_tg(css); + + return cosched_get_scheduled(tg); +} +#endif /* !CONFIG_COSCHEDULING */ + +#ifdef CONFIG_FAIR_GROUP_SCHED #ifdef CONFIG_CFS_BANDWIDTH static DEFINE_MUTEX(cfs_constraints_mutex); @@ -6825,6 +6854,13 @@ static struct cftype cpu_legacy_files[] = { .write_u64 = cpu_shares_write_u64, }, #endif +#ifdef CONFIG_COSCHEDULING + { + .name = "scheduled", + .read_u64 = cpu_scheduled_read_u64, + .write_u64 = cpu_scheduled_write_u64, + }, +#endif #ifdef CONFIG_CFS_BANDWIDTH { .name = "cfs_quota_us", @@ -7012,6 +7048,14 @@ static struct cftype cpu_files[] = { .write_s64 = cpu_weight_nice_write_s64, }, #endif +#ifdef CONFIG_COSCHEDULING + /* FIXME: This is not conform to cgroup-v2 conventions. */ + { + .name = "scheduled", + .read_u64 = cpu_scheduled_read_u64, + .write_u64 = cpu_scheduled_write_u64, + }, +#endif #ifdef CONFIG_CFS_BANDWIDTH { .name = "max", diff --git a/kernel/sched/cosched.c b/kernel/sched/cosched.c index f2d51079b3db..7c8b8c8d2814 100644 --- a/kernel/sched/cosched.c +++ b/kernel/sched/cosched.c @@ -515,6 +515,59 @@ void cosched_offline_group(struct task_group *tg) list_del_rcu(&cfs->sdrq.tg_siblings); } +static void sdrq_update_root(struct sdrq *sdrq) +{ + /* TBD */ +} + +void cosched_set_scheduled(struct task_group *tg, int level) +{ + struct cfs_rq *cfs_rq; + unsigned long flags; + + raw_spin_lock_irqsave(&tg->lock, flags); + + /* + * Update the is_root-fields of all hierarchical CFS runqueues in this + * task group. To avoid repetitive enqueues and dequeues on every level + * change, we chose pre- or post-order traversal. + */ + if (level > tg->scheduled) { + /* + * roots move upwards: start reconfiguration at the top, so + * that everything is dequeued/enqueued only when we reach + * the previous scheduling level. + */ + tg->scheduled = level; + taskgroup_for_each_cfsrq_topdown(tg, cfs_rq) + sdrq_update_root(&cfs_rq->sdrq); + } + if (level < tg->scheduled) { + /* + * roots move downwards: start reconfiguration at the bottom, + * so that we do the dequeuing/enqueuing immediately, when we + * reach the new scheduling level. + */ + tg->scheduled = level; + taskgroup_for_each_cfsrq(tg, cfs_rq) + sdrq_update_root(&cfs_rq->sdrq); + } + + raw_spin_unlock_irqrestore(&tg->lock, flags); +} + +int cosched_get_scheduled(struct task_group *tg) +{ + unsigned long flags; + int level; + + raw_spin_lock_irqsave(&tg->lock, flags); + level = tg->scheduled; + raw_spin_unlock_irqrestore(&tg->lock, flags); + + return level; +} + /***************************************************************************** * Locking related functions *****************************************************************************/ diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index f6146feb7e55..e257451e05a5 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -1212,6 +1212,8 @@ void cosched_init_sdrq(struct task_group *tg, struct cfs_rq *cfs, struct cfs_rq *sd_parent, struct cfs_rq *tg_parent); void cosched_online_group(struct task_group *tg); void cosched_offline_group(struct task_group *tg); +void cosched_set_scheduled(struct task_group *tg, int level); +int cosched_get_scheduled(struct task_group *tg); struct rq *rq_lock_owned(struct rq *rq, struct rq_owner_flags *orf); void rq_unlock_owned(struct rq *rq, struct rq_owner_flags *orf); void rq_chain_init(struct rq_chain *rc, struct rq *rq); @@ -1226,6 +1228,8 @@ static inline void cosched_init_sdrq(struct task_group *tg, struct cfs_rq *cfs, struct cfs_rq *tg_parent) { } static inline void cosched_online_group(struct task_group *tg) { } static inline void cosched_offline_group(struct task_group *tg) { } +static inline void cosched_set_scheduled(struct task_group *tg, int level) { } +static inline int cosched_get_scheduled(struct task_group *tg) { return 0; } static inline struct rq *rq_lock_owned(struct rq *rq, struct rq_owner_flags *orf) { return rq; } static inline void rq_unlock_owned(struct rq *rq, struct rq_owner_flags *orf) { } static inline void rq_chain_init(struct rq_chain *rc, struct rq *rq) { } -- 2.9.3.1.gcba166c.dirty