forked from AndDiSa/android_kernel_asus_grouper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PATCH, v9] cgroups: introduce timer slack controller
- Loading branch information
Showing
13 changed files
with
247 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
Timer Slack Controller | ||
====================== | ||
|
||
Overview | ||
-------- | ||
|
||
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. | ||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/* | ||
* 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> | ||
#include <linux/err.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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters