From: "Kirill A. Shutemov" <kirill@shutemov.name>
To: Paul Menage <menage@google.com>, Li Zefan <lizf@cn.fujitsu.com>,
Andrew Morton <akpm@linux-foundation.org>,
Thomas Gleixner <tglx@linutronix.de>
Cc: containers@lists.linux-foundation.org,
jacob.jun.pan@linux.intel.com,
Arjan van de Ven <arjan@linux.intel.com>,
linux-kernel@vger.kernel.org, Matt Helsley <matthltc@us.ibm.com>,
linux-api@vger.kernel.org, Kay Sievers <kay.sievers@vrfy.org>,
lennart@poettering.net, harald@redhat.com, david@fubar.dk,
greg@kroah.com, "Kirill A. Shutemov" <kirill@shutemov.name>
Subject: [PATCH, v10 3/3] cgroups: introduce timer slack controller
Date: Tue, 11 Oct 2011 19:15:29 +0300 [thread overview]
Message-ID: <1318349729-3108-4-git-send-email-kirill@shutemov.name> (raw)
In-Reply-To: <1318349729-3108-1-git-send-email-kirill@shutemov.name>
From: "Kirill A. Shutemov" <kirill@shutemov.name>
Every task_struct has timer_slack_ns value. This value uses to round up
poll() and select() timeout values. This feature can be useful in
mobile environment where combined wakeups are desired.
Originally, prctl() was the only way to change timer slack value of
a process. So you was not able change timer slack value of another
process.
cgroup subsys "timer_slack" implements timer slack controller. It
provides a way to set minimal timer slack value for a group of tasks.
If a task belongs to a cgroup with minimal timer slack value higher than
task's value, cgroup's value will be applied.
Timer slack controller allows to implement setting timer slack value of
a process based on a policy. For example, you can create foreground and
background cgroups and move tasks between them based on system state.
Idea-by: Jacob Pan <jacob.jun.pan@linux.intel.com>
Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
---
Documentation/cgroups/timer_slack.txt | 72 +++++++++++++++++++
include/linux/cgroup_subsys.h | 7 ++
include/linux/sched.h | 4 +
init/Kconfig | 8 ++
kernel/Makefile | 1 +
kernel/cgroup_timer_slack.c | 124 +++++++++++++++++++++++++++++++++
6 files changed, 216 insertions(+), 0 deletions(-)
create mode 100644 Documentation/cgroups/timer_slack.txt
create mode 100644 kernel/cgroup_timer_slack.c
diff --git a/Documentation/cgroups/timer_slack.txt b/Documentation/cgroups/timer_slack.txt
new file mode 100644
index 0000000..6e9cb6a
--- /dev/null
+++ b/Documentation/cgroups/timer_slack.txt
@@ -0,0 +1,72 @@
+Timer Slack Controller
+======================
+
+Overview
+--------
+
+Every task_struct has timer_slack_ns value. This value is used to round
+up poll() and select() timeout values. This feature can be useful in
+mobile environment where combined wakeups are desired.
+
+Originally, prctl() was the only way to change timer slack value of
+a process. So you was not able change timer slack value of another
+process.
+
+cgroup subsys "timer_slack" implements timer slack controller. It
+provides a way to set minimal timer slack value for a group of tasks.
+If a task belongs to a cgroup with minimal timer slack value higher than
+task's value, cgroup's value will be applied.
+
+Timer slack controller allows to implement setting timer slack value of
+a process based on a policy. For example, you can create foreground and
+background cgroups and move tasks between them based on system state.
+
+User interface
+--------------
+
+To get timer slack controller functionality you need to enable it in
+kernel configuration:
+
+CONFIG_CGROUP_TIMER_SLACK=y
+
+The controller provides two files:
+
+# mount -t cgroup -o timer_slack none /sys/fs/cgroup
+# ls /sys/fs/cgroup/timer_slack.*
+/sys/fs/cgroup/timer_slack.effective_slack_ns
+/sys/fs/cgroup/timer_slack.min_slack_ns
+
+By default timer_slack.min_slack_ns is 0:
+
+# cat /sys/fs/cgroup/timer_slack.min_slack_ns
+0
+
+You can set it to some value:
+
+# echo 50000 > /sys/fs/cgroup/timer_slack.min_slack_ns
+# cat /sys/fs/cgroup/timer_slack.min_slack_ns
+50000
+
+Tasks still can set task's value below 50000 using prctl(), but in this
+case cgroup's value will be applied.
+
+Timer slack controller supports hierarchical groups.
+
+# mkdir /sys/fs/cgroup/a
+# cat /sys/fs/cgroup/a/timer_slack.min_slack_ns
+50000
+# echo 70000 > /sys/fs/cgroup/a/timer_slack.min_slack_ns
+# cat /sys/fs/cgroup/a/timer_slack.min_slack_ns
+70000
+
+You can set any value you want, but effective value will the highest value
+up by hierarchy. You can see effective timer slack value for the cgroup from
+timer_slack.effective_slack_ns file:
+
+# cat /sys/fs/cgroup/a/timer_slack.effective_slack_ns
+70000
+# echo 100000 > /sys/fs/cgroup/timer_slack.min_slack_ns
+# cat /sys/fs/cgroup/a/timer_slack.min_slack_ns
+70000
+# cat /sys/fs/cgroup/a/timer_slack.effective_slack_ns
+100000
diff --git a/include/linux/cgroup_subsys.h b/include/linux/cgroup_subsys.h
index 5425822..2c8148f 100644
--- a/include/linux/cgroup_subsys.h
+++ b/include/linux/cgroup_subsys.h
@@ -72,3 +72,10 @@ SUBSYS(tasks)
#endif
/* */
+
+#ifdef CONFIG_CGROUP_TIMER_SLACK
+SUBSYS(timer_slack)
+#endif
+
+/* */
+
diff --git a/include/linux/sched.h b/include/linux/sched.h
index d79e300..37c19ec 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -2719,11 +2719,15 @@ static inline unsigned long rlimit_max(unsigned int limit)
return task_rlimit_max(current, limit);
}
+#ifdef CONFIG_CGROUP_TIMER_SLACK
+extern unsigned long task_get_effective_timer_slack(struct task_struct *tsk);
+#else
static inline unsigned long task_get_effective_timer_slack(
struct task_struct *tsk)
{
return tsk->timer_slack_ns;
}
+#endif
#endif /* __KERNEL__ */
diff --git a/init/Kconfig b/init/Kconfig
index 6dfc8c3..71ea5dd 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -603,6 +603,14 @@ config CGROUP_FREEZER
Provides a way to freeze and unfreeze all tasks in a
cgroup.
+config CGROUP_TIMER_SLACK
+ bool "Timer slack cgroup controller"
+ help
+ Provides a way to set minimal timer slack value for tasks in
+ a cgroup.
+ It's useful in mobile devices where certain background apps
+ are attached to a cgroup and combined wakeups are desired.
+
config CGROUP_DEVICE
bool "Device controller for cgroups"
help
diff --git a/kernel/Makefile b/kernel/Makefile
index 7469ecc..93672f5 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -61,6 +61,7 @@ obj-$(CONFIG_COMPAT) += compat.o
obj-$(CONFIG_CGROUPS) += cgroup.o
obj-$(CONFIG_CGROUP_FREEZER) += cgroup_freezer.o
obj-$(CONFIG_CGROUP_TASK_COUNTER) += cgroup_task_counter.o
+obj-$(CONFIG_CGROUP_TIMER_SLACK) += cgroup_timer_slack.o
obj-$(CONFIG_CPUSETS) += cpuset.o
obj-$(CONFIG_UTS_NS) += utsname.o
obj-$(CONFIG_USER_NS) += user_namespace.o
diff --git a/kernel/cgroup_timer_slack.c b/kernel/cgroup_timer_slack.c
new file mode 100644
index 0000000..9824807
--- /dev/null
+++ b/kernel/cgroup_timer_slack.c
@@ -0,0 +1,124 @@
+/*
+ * cgroup_timer_slack.c - control group timer slack subsystem
+ *
+ * Copyright Nokia Corparation, 2011
+ * Author: Kirill A. Shutemov
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+#include <linux/cgroup.h>
+#include <linux/slab.h>
+
+struct cgroup_subsys timer_slack_subsys;
+struct tslack_cgroup {
+ struct cgroup_subsys_state css;
+ unsigned long min_slack_ns;
+};
+
+static struct tslack_cgroup *cgroup_to_tslack(struct cgroup *cgroup)
+{
+ struct cgroup_subsys_state *css;
+
+ css = cgroup_subsys_state(cgroup, timer_slack_subsys.subsys_id);
+ return container_of(css, struct tslack_cgroup, css);
+}
+
+static struct cgroup_subsys_state *tslack_create(struct cgroup_subsys *subsys,
+ struct cgroup *cgroup)
+{
+ struct tslack_cgroup *tslack_cgroup;
+
+ tslack_cgroup = kmalloc(sizeof(*tslack_cgroup), GFP_KERNEL);
+ if (!tslack_cgroup)
+ return ERR_PTR(-ENOMEM);
+
+ if (cgroup->parent) {
+ struct tslack_cgroup *parent;
+
+ parent = cgroup_to_tslack(cgroup->parent);
+ tslack_cgroup->min_slack_ns = parent->min_slack_ns;
+ } else
+ tslack_cgroup->min_slack_ns = 0UL;
+
+ return &tslack_cgroup->css;
+}
+
+static void tslack_destroy(struct cgroup_subsys *tslack_cgroup,
+ struct cgroup *cgroup)
+{
+ kfree(cgroup_to_tslack(cgroup));
+}
+
+static u64 tslack_read_min(struct cgroup *cgroup, struct cftype *cft)
+{
+ return cgroup_to_tslack(cgroup)->min_slack_ns;
+}
+
+static int tslack_write_min(struct cgroup *cgroup, struct cftype *cft, u64 val)
+{
+ if (val > ULONG_MAX)
+ return -EINVAL;
+
+ cgroup_to_tslack(cgroup)->min_slack_ns = val;
+
+ return 0;
+}
+
+static u64 tslack_read_effective(struct cgroup *cgroup, struct cftype *cft)
+{
+ unsigned long min;
+
+ min = cgroup_to_tslack(cgroup)->min_slack_ns;
+ while (cgroup->parent) {
+ cgroup = cgroup->parent;
+ min = max(cgroup_to_tslack(cgroup)->min_slack_ns, min);
+ }
+
+ return min;
+}
+
+static struct cftype files[] = {
+ {
+ .name = "min_slack_ns",
+ .read_u64 = tslack_read_min,
+ .write_u64 = tslack_write_min,
+ },
+ {
+ .name = "effective_slack_ns",
+ .read_u64 = tslack_read_effective,
+ },
+};
+
+static int tslack_populate(struct cgroup_subsys *subsys, struct cgroup *cgroup)
+{
+ return cgroup_add_files(cgroup, subsys, files, ARRAY_SIZE(files));
+}
+
+struct cgroup_subsys timer_slack_subsys = {
+ .name = "timer_slack",
+ .subsys_id = timer_slack_subsys_id,
+ .create = tslack_create,
+ .destroy = tslack_destroy,
+ .populate = tslack_populate,
+};
+
+unsigned long task_get_effective_timer_slack(struct task_struct *tsk)
+{
+ struct cgroup *cgroup;
+ unsigned long slack;
+
+ rcu_read_lock();
+ cgroup = task_cgroup(tsk, timer_slack_subsys.subsys_id);
+ slack = tslack_read_effective(cgroup, NULL);
+ rcu_read_unlock();
+
+ return max(tsk->timer_slack_ns, slack);
+}
--
1.7.6.3
next prev parent reply other threads:[~2011-10-11 16:15 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-11 16:15 [PATCH, v10 0/3] Introduce timer slack controller Kirill A. Shutemov
2011-10-11 16:15 ` [PATCH, v10 1/3] hrtimer: introduce effective timer slack Kirill A. Shutemov
2011-10-11 16:15 ` [PATCH, v10 2/3] hrtimer: implement PR_GET_EFFECTIVE_TIMERSLACK Kirill A. Shutemov
2011-10-11 16:15 ` Kirill A. Shutemov [this message]
[not found] ` <1318349729-3108-4-git-send-email-kirill-oKw7cIdHH8eLwutG50LtGA@public.gmane.org>
2011-10-11 16:49 ` [PATCH, v10 3/3] cgroups: introduce timer slack controller Kirill A. Shutemov
2011-10-14 22:43 ` Andrew Morton
[not found] ` <20111014154348.ae6267aa.akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
2011-10-14 23:34 ` Kirill A. Shutemov
2011-10-15 11:20 ` Lennart Poettering
2011-10-15 19:11 ` Peter Zijlstra
2011-10-17 1:39 ` Lennart Poettering
[not found] ` <20111017013921.GA30035-kS5D54t9nk0aINubkmmoJbNAH6kLmebB@public.gmane.org>
2011-10-17 3:22 ` Matthew Garrett
[not found] ` <20111017032232.GA4816-1xO5oi07KQx4cg9Nei1l7Q@public.gmane.org>
2011-10-17 5:21 ` Arjan van de Ven
[not found] ` <4E9BBB6D.4050004-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2011-10-17 7:36 ` Peter Zijlstra
2011-10-17 9:38 ` Thomas Gleixner
2011-10-17 12:46 ` Matthew Garrett
[not found] ` <20111017124647.GA12838-1xO5oi07KQx4cg9Nei1l7Q@public.gmane.org>
2011-10-17 13:06 ` Peter Zijlstra
2011-10-17 14:11 ` Matthew Garrett
[not found] ` <20111017141147.GA14581-1xO5oi07KQx4cg9Nei1l7Q@public.gmane.org>
2011-10-17 14:28 ` Peter Zijlstra
2011-10-17 14:35 ` Arjan van de Ven
[not found] ` <4E9C3D39.9020109-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2011-10-17 14:45 ` Peter Zijlstra
2011-10-17 14:40 ` Matthew Garrett
2011-10-17 14:49 ` Peter Zijlstra
2011-10-17 14:59 ` Matthew Garrett
2011-10-17 15:11 ` Peter Zijlstra
2011-10-17 15:19 ` Matthew Garrett
[not found] ` <20111017151920.GA16664-1xO5oi07KQx4cg9Nei1l7Q@public.gmane.org>
2011-10-17 15:21 ` Peter Zijlstra
2011-10-17 15:31 ` Matthew Garrett
[not found] ` <20111017153142.GA17047-1xO5oi07KQx4cg9Nei1l7Q@public.gmane.org>
2011-10-17 16:36 ` Peter Zijlstra
2011-10-17 16:49 ` Matthew Garrett
2011-10-17 15:48 ` Alan Cox
[not found] ` <20111017164839.3887ee3e-qBU/x9rampVanCEyBjwyrvXRex20P6io@public.gmane.org>
2011-10-17 16:33 ` Peter Zijlstra
2011-10-17 15:18 ` Peter Zijlstra
2011-10-17 7:34 ` Peter Zijlstra
2011-10-17 13:55 ` Lennart Poettering
2011-10-17 7:28 ` Peter Zijlstra
2011-10-17 19:46 ` Valdis.Kletnieks-PjAqaU27lzQ
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=1318349729-3108-4-git-send-email-kirill@shutemov.name \
--to=kirill@shutemov.name \
--cc=akpm@linux-foundation.org \
--cc=arjan@linux.intel.com \
--cc=containers@lists.linux-foundation.org \
--cc=david@fubar.dk \
--cc=greg@kroah.com \
--cc=harald@redhat.com \
--cc=jacob.jun.pan@linux.intel.com \
--cc=kay.sievers@vrfy.org \
--cc=lennart@poettering.net \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lizf@cn.fujitsu.com \
--cc=matthltc@us.ibm.com \
--cc=menage@google.com \
--cc=tglx@linutronix.de \
/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).