linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: k-onishi <princeontrojanhorse@gmail.com>
To: mingo@redhat.com
Cc: peterz@infradead.org, linux-kernel@vger.kernel.org,
	princeontrojanhorse@gmail.com
Subject: [PATCH] feat(CFS Bandwidth): add an interface for CFS Bandwidth
Date: Sun, 28 Apr 2019 16:32:06 +0900	[thread overview]
Message-ID: <20190428073207.6733-1-princeontrojanhorse@gmail.com> (raw)

I added an interface which is more intuitive
and takes less write/read systemcalls.

I think that most people don't really care period
and quota of CFS Bandwidth,

They just use it like
"I will allow this process to use 50% of single core" in most cases.

But I know that we still need to care period and quota in some cases.

Please consider for merging this if you like, thanks.

Signed-off-by: k-onishi <princeontrojanhorse@gmail.com>
---
 kernel/sched/core.c | 46 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 4778c48a7fda..27338c727d7c 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -6700,6 +6700,35 @@ long tg_get_cfs_period(struct task_group *tg)
 	return cfs_period_us;
 }
 
+int tg_set_cfs_percent(struct task_group *tg, long cfs_percent)
+{
+	u64 quota, period;
+
+	if (cfs_percent < 0)
+		return -EINVAL;
+
+	period = 1 * NSEC_PER_SEC;
+	quota = cfs_percent * 10 * USEC_PER_SECUL;
+	return tg_set_cfs_bandwidth(tg, period, quota);
+}
+
+long tg_get_cfs_percent(struct task_group *tg)
+{
+	u64 quota, period;
+
+	if (tg->cfs_bandwidth.quota == RUNTIME_INF)
+		return -1;
+
+	quota = tg->cfs_bandwidth.quota;
+	period = tg->cfs_bandwidth.period;
+
+	do_div(quota, 10);
+	do_div(period, NSEC_PER_USEC);
+	do_div(quota, period);
+
+	return quota;
+}
+
 static s64 cpu_cfs_quota_read_s64(struct cgroup_subsys_state *css,
 				  struct cftype *cft)
 {
@@ -6724,6 +6753,18 @@ static int cpu_cfs_period_write_u64(struct cgroup_subsys_state *css,
 	return tg_set_cfs_period(css_tg(css), cfs_period_us);
 }
 
+static s64 cpu_cfs_percent_read_u64(struct cgroup_subsys_state *css,
+				   struct cftype *cft)
+{
+	return tg_get_cfs_percent(css_tg(css));
+}
+
+static int cpu_cfs_percent_write_u64(struct cgroup_subsys_state *css,
+				   struct cftype *cftype, u64 cfs_percent)
+{
+	return tg_set_cfs_percent(css_tg(css), cfs_percent);
+}
+
 struct cfs_schedulable_data {
 	struct task_group *tg;
 	u64 period, quota;
@@ -6876,6 +6917,11 @@ static struct cftype cpu_legacy_files[] = {
 		.read_u64 = cpu_cfs_period_read_u64,
 		.write_u64 = cpu_cfs_period_write_u64,
 	},
+	{
+		.name = "cfs_percent",
+		.read_s64 = cpu_cfs_percent_read_u64,
+		.write_u64 = cpu_cfs_percent_write_u64,
+	},
 	{
 		.name = "stat",
 		.seq_show = cpu_cfs_stat_show,
-- 
2.17.1


             reply	other threads:[~2019-04-28  7:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-28  7:32 k-onishi [this message]
2019-04-29  7:55 ` [PATCH] feat(CFS Bandwidth): add an interface for CFS Bandwidth Peter Zijlstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190428073207.6733-1-princeontrojanhorse@gmail.com \
    --to=princeontrojanhorse@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).