Skip to contentSkip to conversation

cgroups: respect cgroup timer slack value in prctl

PATCH In review [email protected] 5 participants 7 messages Feb 1, 2011 – Feb 2, 2011 2 messages not in the archive cgroup

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cgroups: respect cgroup timer slack value in prctl

From: Jacob Pan <[email protected]>

Per cgroup timer slack value is used to manage task groups for more friendly power management behavior. Once a task is attached to a cgroup, we should not allow user to change (escape) the per cgroup restriction unless a more relaxed timer slack value is given by user via prctl.

---
 include/linux/cgroup.h      |   13 +++++++++++++
 kernel/cgroup_timer_slack.c |    4 ----
 kernel/sys.c                |   21 ++++++++++++++++++++-
 3 files changed, 33 insertions(+), 5 deletions(-)
include/linux/cgroup.h +13 -0
index ed4ba11..4405666 100644
@@ -627,6 +627,19 @@ bool css_is_ancestor(struct cgroup_subsys_state *cg,
 unsigned short css_id(struct cgroup_subsys_state *css);
 unsigned short css_depth(struct cgroup_subsys_state *css);
 
+#ifdef CONFIG_CGROUP_TIMER_SLACK
+struct timer_slack_cgroup {
+	struct cgroup_subsys_state css;
+	unsigned long timer_slack_ns;
+};
+
+static inline struct timer_slack_cgroup *task_timer_slack(struct task_struct *task)
+{
+	return container_of(task_subsys_state(task, timer_slack_subsys_id),
+			    struct timer_slack_cgroup, css);
+}
+#endif
+
 #else /* !CONFIG_CGROUPS */
 
 static inline int cgroup_init_early(void) { return 0; }
kernel/cgroup_timer_slack.c +0 -4
index daa452d..1de122a 100644
@@ -4,10 +4,6 @@
 #include <linux/slab.h>
 
 struct cgroup_subsys timer_slack_subsys;
-struct timer_slack_cgroup {
-	struct cgroup_subsys_state css;
-	unsigned long timer_slack_ns;
-};
 
 static struct timer_slack_cgroup *cgroup_to_tslack_cgroup(struct cgroup *cgroup)
 {
kernel/sys.c +20 -1
index 7f5a0cd..433fcdb 100644
@@ -37,6 +37,8 @@
 #include <linux/ptrace.h>
 #include <linux/fs_struct.h>
 #include <linux/gfp.h>
+#include <linux/cgroup.h>
+#include <linux/init_task.h>
 
 #include <linux/compat.h>
 #include <linux/syscalls.h>
@@ -1688,8 +1690,25 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
 			if (arg2 <= 0)
 				current->timer_slack_ns =
 					current->default_timer_slack_ns;
-			else
+			else {
+#ifdef CONFIG_CGROUP_TIMER_SLACK
+				/* only allow more relaxed slack value than
+				 * the attached timer slack cgroup allows.
+				 */
+				unsigned long cg_timer_slack;
+
+				rcu_read_lock();
+				cg_timer_slack = task_timer_slack(current)->timer_slack_ns;
+				rcu_read_unlock();
+				if (cg_timer_slack < arg2 || cg_timer_slack
+					== TIMER_SLACK_NS_DEFAULT)
+					current->timer_slack_ns = arg2;
+				else
+					return -EINVAL;
+#else
 				current->timer_slack_ns = arg2;
+#endif
+			}
 			error = 0;
 			break;
 		case PR_MCE_KILL:
Signature · 1 line
1.7.0.4

A message that is not in the archive (sent off-list or not yet received): 1296600103-15726-1-git-send-email-jacob.jun.pan-VuQAYsv1563Yd54FQh9/[email protected]

#2 lore raw
Quoted 8 lines · On Tue, Feb 01, 2011 at 02:41:43PM -0800…

From: Jacob Pan <jacob.jun.pan-VuQAYsv1563Yd54FQh9/[email protected]>

Per cgroup timer slack value is used to manage task groups for more friendly power management behavior. Once a task is attached to a cgroup, we should not allow user to change (escape) the per cgroup restriction unless a more relaxed timer slack value is given by user via prctl.

Quoted 4 lines
---
 include/linux/cgroup.h      |   13 +++++++++++++

Looks like the original two patches (one or more implementing:

Quoted 1 line
 kernel/cgroup_timer_slack.c |    4 ----

) were not sent to containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org ?

Quoted 66 lines
 kernel/sys.c                |   21 ++++++++++++++++++++-
 3 files changed, 33 insertions(+), 5 deletions(-)
include/linux/cgroup.h +13 -0
index ed4ba11..4405666 100644
@@ -627,6 +627,19 @@ bool css_is_ancestor(struct cgroup_subsys_state *cg,
 unsigned short css_id(struct cgroup_subsys_state *css);
 unsigned short css_depth(struct cgroup_subsys_state *css);
 
+#ifdef CONFIG_CGROUP_TIMER_SLACK
+struct timer_slack_cgroup {
+	struct cgroup_subsys_state css;
+	unsigned long timer_slack_ns;
+};
+
+static inline struct timer_slack_cgroup *task_timer_slack(struct task_struct *task)
+{
+	return container_of(task_subsys_state(task, timer_slack_subsys_id),
+			    struct timer_slack_cgroup, css);
+}
+#endif
+
 #else /* !CONFIG_CGROUPS */
 
 static inline int cgroup_init_early(void) { return 0; }
kernel/cgroup_timer_slack.c +0 -4
index daa452d..1de122a 100644
@@ -4,10 +4,6 @@
 #include <linux/slab.h>
 
 struct cgroup_subsys timer_slack_subsys;
-struct timer_slack_cgroup {
-	struct cgroup_subsys_state css;
-	unsigned long timer_slack_ns;
-};
 
 static struct timer_slack_cgroup *cgroup_to_tslack_cgroup(struct cgroup *cgroup)
 {
kernel/sys.c +8 -1
index 7f5a0cd..433fcdb 100644
@@ -37,6 +37,8 @@
 #include <linux/ptrace.h>
 #include <linux/fs_struct.h>
 #include <linux/gfp.h>
+#include <linux/cgroup.h>
+#include <linux/init_task.h>
 
 #include <linux/compat.h>
 #include <linux/syscalls.h>
@@ -1688,8 +1690,25 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
 			if (arg2 <= 0)
 				current->timer_slack_ns =
 					current->default_timer_slack_ns;
-			else
+			else {
+#ifdef CONFIG_CGROUP_TIMER_SLACK
+				/* only allow more relaxed slack value than
+				 * the attached timer slack cgroup allows.
+				 */
+				unsigned long cg_timer_slack;

kernel/sys.c SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3, · line 1708

Quoted 10 lines
kernel/sys.c +10 -0
+
+				rcu_read_lock();
+				cg_timer_slack = task_timer_slack(current)->timer_slack_ns;
+				rcu_read_unlock();
+				if (cg_timer_slack < arg2 || cg_timer_slack
+					== TIMER_SLACK_NS_DEFAULT)
+					current->timer_slack_ns = arg2;
+				else
+					return -EINVAL;
+#else

Looks like this could be an inline function which returns the minimum timer slack allowed for the task. Then the code here would be:

if (arg2 <= 0)

	current->timer_slack_ns = current->default_timer_slack_ns;
else {
	if (arg2 < min_timer_slack_ns(tsk))
		return -EINVAL; /* Can't set less than the minimum */
	current->timer_slack_ns = arg2;
}

and the #ifdef CONFIG_CGROUP_TIMER_SLACK bits could be in a header as usual.

Incidentally, shouldn't that really be -EPERM since it's not an invalid value -- just one that's not permitted due to restrictions imposed by the cgroup subsystem?

Quoted 13 lines
kernel/sys.c +2 -0
 				current->timer_slack_ns = arg2;
+#endif
+			}
 			error = 0;
 			break;
 		case PR_MCE_KILL:
Signature · 6 lines
1.7.0.4

_______________________________________________
Containers mailing list
Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
https://lists.linux-foundation.org/mailman/listinfo/containers
#3 lore raw
In reply to [email protected]
Quoted 8 lines · On Tue, Feb 01, 2011 at 02:41:43PM -0800, [email protected] wrote:

From: Jacob Pan <[email protected]>

Per cgroup timer slack value is used to manage task groups for more friendly power management behavior. Once a task is attached to a cgroup, we should not allow user to change (escape) the per cgroup restriction unless a more relaxed timer slack value is given by user via prctl.

Quoted 4 lines
---
 include/linux/cgroup.h      |   13 +++++++++++++

Looks like the original two patches (one or more implementing:

Quoted 1 line
 kernel/cgroup_timer_slack.c |    4 ----

) were not sent to [email protected] ?

Quoted 66 lines
 kernel/sys.c                |   21 ++++++++++++++++++++-
 3 files changed, 33 insertions(+), 5 deletions(-)
include/linux/cgroup.h +13 -0
index ed4ba11..4405666 100644
@@ -627,6 +627,19 @@ bool css_is_ancestor(struct cgroup_subsys_state *cg,
 unsigned short css_id(struct cgroup_subsys_state *css);
 unsigned short css_depth(struct cgroup_subsys_state *css);
 
+#ifdef CONFIG_CGROUP_TIMER_SLACK
+struct timer_slack_cgroup {
+	struct cgroup_subsys_state css;
+	unsigned long timer_slack_ns;
+};
+
+static inline struct timer_slack_cgroup *task_timer_slack(struct task_struct *task)
+{
+	return container_of(task_subsys_state(task, timer_slack_subsys_id),
+			    struct timer_slack_cgroup, css);
+}
+#endif
+
 #else /* !CONFIG_CGROUPS */
 
 static inline int cgroup_init_early(void) { return 0; }
kernel/cgroup_timer_slack.c +0 -4
index daa452d..1de122a 100644
@@ -4,10 +4,6 @@
 #include <linux/slab.h>
 
 struct cgroup_subsys timer_slack_subsys;
-struct timer_slack_cgroup {
-	struct cgroup_subsys_state css;
-	unsigned long timer_slack_ns;
-};
 
 static struct timer_slack_cgroup *cgroup_to_tslack_cgroup(struct cgroup *cgroup)
 {
kernel/sys.c +8 -1
index 7f5a0cd..433fcdb 100644
@@ -37,6 +37,8 @@
 #include <linux/ptrace.h>
 #include <linux/fs_struct.h>
 #include <linux/gfp.h>
+#include <linux/cgroup.h>
+#include <linux/init_task.h>
 
 #include <linux/compat.h>
 #include <linux/syscalls.h>
@@ -1688,8 +1690,25 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
 			if (arg2 <= 0)
 				current->timer_slack_ns =
 					current->default_timer_slack_ns;
-			else
+			else {
+#ifdef CONFIG_CGROUP_TIMER_SLACK
+				/* only allow more relaxed slack value than
+				 * the attached timer slack cgroup allows.
+				 */
+				unsigned long cg_timer_slack;

kernel/sys.c SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3, · line 1708

Quoted 10 lines
kernel/sys.c +10 -0
+
+				rcu_read_lock();
+				cg_timer_slack = task_timer_slack(current)->timer_slack_ns;
+				rcu_read_unlock();
+				if (cg_timer_slack < arg2 || cg_timer_slack
+					== TIMER_SLACK_NS_DEFAULT)
+					current->timer_slack_ns = arg2;
+				else
+					return -EINVAL;
+#else

Looks like this could be an inline function which returns the minimum timer slack allowed for the task. Then the code here would be:

if (arg2 <= 0)

	current->timer_slack_ns = current->default_timer_slack_ns;
else {
	if (arg2 < min_timer_slack_ns(tsk))
		return -EINVAL; /* Can't set less than the minimum */
	current->timer_slack_ns = arg2;
}

and the #ifdef CONFIG_CGROUP_TIMER_SLACK bits could be in a header as usual.

Incidentally, shouldn't that really be -EPERM since it's not an invalid value -- just one that's not permitted due to restrictions imposed by the cgroup subsystem?

Quoted 13 lines
kernel/sys.c +2 -0
 				current->timer_slack_ns = arg2;
+#endif
+			}
 			error = 0;
 			break;
 		case PR_MCE_KILL:
Signature · 6 lines
1.7.0.4

_______________________________________________
Containers mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/containers

A message that is not in the archive (sent off-list or not yet received): 20110202070743.GO16432-52DBMbEzqgQ/wnmkkaCWp/[email protected]

#5 lore raw
Quoted 11 lines · Matt Helsley
Quoted 9 lines · On Tue, Feb 01, 2011 at 02:41:43PM -0800…

From: Jacob Pan <jacob.jun.pan-VuQAYsv1563Yd54FQh9/[email protected]>

Per cgroup timer slack value is used to manage task groups for more friendly power management behavior. Once a task is attached to a cgroup, we should not allow user to change (escape) the per cgroup restriction unless a more relaxed timer slack value is given by user via prctl.

Quoted 8 lines
Quoted 2 lines
---
 include/linux/cgroup.h      |   13 +++++++++++++

Looks like the original two patches (one or more implementing:

Quoted 1 line
 kernel/cgroup_timer_slack.c |    4 ----

) were not sent to containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org ?

Hm..

https://lists.linux-foundation.org/pipermail/containers/2011-February/026415.html

Quoted 89 lines
Quoted 67 lines
 kernel/sys.c                |   21 ++++++++++++++++++++-
 3 files changed, 33 insertions(+), 5 deletions(-)
include/linux/cgroup.h +13 -0
index ed4ba11..4405666 100644
@@ -627,6 +627,19 @@ bool css_is_ancestor(struct cgroup_subsys_state *cg,
 unsigned short css_id(struct cgroup_subsys_state *css);
 unsigned short css_depth(struct cgroup_subsys_state *css);
 
+#ifdef CONFIG_CGROUP_TIMER_SLACK
+struct timer_slack_cgroup {
+	struct cgroup_subsys_state css;
+	unsigned long timer_slack_ns;
+};
+
+static inline struct timer_slack_cgroup *task_timer_slack(struct task_struct *task)
+{
+	return container_of(task_subsys_state(task, timer_slack_subsys_id),
+			    struct timer_slack_cgroup, css);
+}
+#endif
+
 #else /* !CONFIG_CGROUPS */
 
 static inline int cgroup_init_early(void) { return 0; }
kernel/cgroup_timer_slack.c +0 -4
index daa452d..1de122a 100644
@@ -4,10 +4,6 @@
 #include <linux/slab.h>
 
 struct cgroup_subsys timer_slack_subsys;
-struct timer_slack_cgroup {
-	struct cgroup_subsys_state css;
-	unsigned long timer_slack_ns;
-};
 
 static struct timer_slack_cgroup *cgroup_to_tslack_cgroup(struct cgroup *cgroup)
 {
kernel/sys.c +8 -1
index 7f5a0cd..433fcdb 100644
@@ -37,6 +37,8 @@
 #include <linux/ptrace.h>
 #include <linux/fs_struct.h>
 #include <linux/gfp.h>
+#include <linux/cgroup.h>
+#include <linux/init_task.h>
 
 #include <linux/compat.h>
 #include <linux/syscalls.h>
@@ -1688,8 +1690,25 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
 			if (arg2 <= 0)
 				current->timer_slack_ns =
 					current->default_timer_slack_ns;
-			else
+			else {
+#ifdef CONFIG_CGROUP_TIMER_SLACK
+				/* only allow more relaxed slack value than
+				 * the attached timer slack cgroup allows.
+				 */
+				unsigned long cg_timer_slack;

kernel/sys.c SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3, · line 1708

Quoted 10 lines
kernel/sys.c +10 -0
+
+				rcu_read_lock();
+				cg_timer_slack = task_timer_slack(current)->timer_slack_ns;
+				rcu_read_unlock();
+				if (cg_timer_slack < arg2 || cg_timer_slack
+					== TIMER_SLACK_NS_DEFAULT)
+					current->timer_slack_ns = arg2;
+				else
+					return -EINVAL;
+#else

Looks like this could be an inline function which returns the minimum timer slack allowed for the task. Then the code here would be:

if (arg2 <= 0)

	current->timer_slack_ns = current->default_timer_slack_ns;
else {
	if (arg2 < min_timer_slack_ns(tsk))
		return -EINVAL; /* Can't set less than the minimum */
	current->timer_slack_ns = arg2;
}
Quoted 6 lines

and the #ifdef CONFIG_CGROUP_TIMER_SLACK bits could be in a header as usual.

Incidentally, shouldn't that really be -EPERM since it's not an invalid value -- just one that's not permitted due to restrictions imposed by the cgroup subsystem?

I guess better to add more functionality to the cgroup subsystem. I'm going to implement timer_slack.min_slack_ns and timer_slack.max_slack_ns. prctl(2) will be modified to check these limits.

Quoted 13 lines
Quoted 13 lines
kernel/sys.c +2 -0
 				current->timer_slack_ns = arg2;
+#endif
+			}
 			error = 0;
 			break;
 		case PR_MCE_KILL:
Signature · 6 lines
1.7.0.4

_______________________________________________
Containers mailing list
Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
https://lists.linux-foundation.org/mailman/listinfo/containers
Signature · 1 line
 Kirill A. Shutemov
#6 lore raw
In reply to a message not in the archive
Quoted 11 lines · Matt Helsley
Quoted 9 lines · On Tue, Feb 01, 2011 at 02:41:43PM -0800…

From: Jacob Pan <jacob.jun.pan-VuQAYsv1563Yd54FQh9/[email protected]>

Per cgroup timer slack value is used to manage task groups for more friendly power management behavior. Once a task is attached to a cgroup, we should not allow user to change (escape) the per cgroup restriction unless a more relaxed timer slack value is given by user via prctl.

Quoted 8 lines
Quoted 2 lines
---
 include/linux/cgroup.h      |   13 +++++++++++++

Looks like the original two patches (one or more implementing:

Quoted 1 line
 kernel/cgroup_timer_slack.c |    4 ----

) were not sent to containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org ?

Oops, I didn't see the patches from Kirill A. Shutsemov that this apparently applies to, sorry. Odd, my mail client doesn't show a Cc for him on this thread... (added)

Cheers,
-Matt

Quoted 113 lines
Quoted 67 lines
 kernel/sys.c                |   21 ++++++++++++++++++++-
 3 files changed, 33 insertions(+), 5 deletions(-)
include/linux/cgroup.h +13 -0
index ed4ba11..4405666 100644
@@ -627,6 +627,19 @@ bool css_is_ancestor(struct cgroup_subsys_state *cg,
 unsigned short css_id(struct cgroup_subsys_state *css);
 unsigned short css_depth(struct cgroup_subsys_state *css);
 
+#ifdef CONFIG_CGROUP_TIMER_SLACK
+struct timer_slack_cgroup {
+	struct cgroup_subsys_state css;
+	unsigned long timer_slack_ns;
+};
+
+static inline struct timer_slack_cgroup *task_timer_slack(struct task_struct *task)
+{
+	return container_of(task_subsys_state(task, timer_slack_subsys_id),
+			    struct timer_slack_cgroup, css);
+}
+#endif
+
 #else /* !CONFIG_CGROUPS */
 
 static inline int cgroup_init_early(void) { return 0; }
kernel/cgroup_timer_slack.c +0 -4
index daa452d..1de122a 100644
@@ -4,10 +4,6 @@
 #include <linux/slab.h>
 
 struct cgroup_subsys timer_slack_subsys;
-struct timer_slack_cgroup {
-	struct cgroup_subsys_state css;
-	unsigned long timer_slack_ns;
-};
 
 static struct timer_slack_cgroup *cgroup_to_tslack_cgroup(struct cgroup *cgroup)
 {
kernel/sys.c +8 -1
index 7f5a0cd..433fcdb 100644
@@ -37,6 +37,8 @@
 #include <linux/ptrace.h>
 #include <linux/fs_struct.h>
 #include <linux/gfp.h>
+#include <linux/cgroup.h>
+#include <linux/init_task.h>
 
 #include <linux/compat.h>
 #include <linux/syscalls.h>
@@ -1688,8 +1690,25 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
 			if (arg2 <= 0)
 				current->timer_slack_ns =
 					current->default_timer_slack_ns;
-			else
+			else {
+#ifdef CONFIG_CGROUP_TIMER_SLACK
+				/* only allow more relaxed slack value than
+				 * the attached timer slack cgroup allows.
+				 */
+				unsigned long cg_timer_slack;

kernel/sys.c SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3, · line 1708

Quoted 10 lines
kernel/sys.c +10 -0
+
+				rcu_read_lock();
+				cg_timer_slack = task_timer_slack(current)->timer_slack_ns;
+				rcu_read_unlock();
+				if (cg_timer_slack < arg2 || cg_timer_slack
+					== TIMER_SLACK_NS_DEFAULT)
+					current->timer_slack_ns = arg2;
+				else
+					return -EINVAL;
+#else

Looks like this could be an inline function which returns the minimum timer slack allowed for the task. Then the code here would be:

if (arg2 <= 0)

	current->timer_slack_ns = current->default_timer_slack_ns;
else {
	if (arg2 < min_timer_slack_ns(tsk))
		return -EINVAL; /* Can't set less than the minimum */
	current->timer_slack_ns = arg2;
}

and the #ifdef CONFIG_CGROUP_TIMER_SLACK bits could be in a header as usual.

Incidentally, shouldn't that really be -EPERM since it's not an invalid value -- just one that's not permitted due to restrictions imposed by the cgroup subsystem?

Quoted 13 lines
kernel/sys.c +2 -0
 				current->timer_slack_ns = arg2;
+#endif
+			}
 			error = 0;
 			break;
 		case PR_MCE_KILL:
Signature · 6 lines
1.7.0.4

_______________________________________________
Containers mailing list
Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
https://lists.linux-foundation.org/mailman/listinfo/containers

_______________________________________________
Containers mailing list Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
https://lists.linux-foundation.org/mailman/listinfo/containers

#7 lore raw
In reply to Matt Helsley
Quoted 11 lines · Matt Helsley
Quoted 9 lines · On Tue, Feb 01, 2011 at 02:41:43PM -0800, [email protected] wrote:

From: Jacob Pan <[email protected]>

Per cgroup timer slack value is used to manage task groups for more friendly power management behavior. Once a task is attached to a cgroup, we should not allow user to change (escape) the per cgroup restriction unless a more relaxed timer slack value is given by user via prctl.

Quoted 8 lines
Quoted 2 lines
---
 include/linux/cgroup.h      |   13 +++++++++++++

Looks like the original two patches (one or more implementing:

Quoted 1 line
 kernel/cgroup_timer_slack.c |    4 ----

) were not sent to [email protected] ?

Hm..

https://lists.linux-foundation.org/pipermail/containers/2011-February/026415.html

Quoted 89 lines
Quoted 67 lines
 kernel/sys.c                |   21 ++++++++++++++++++++-
 3 files changed, 33 insertions(+), 5 deletions(-)
include/linux/cgroup.h +13 -0
index ed4ba11..4405666 100644
@@ -627,6 +627,19 @@ bool css_is_ancestor(struct cgroup_subsys_state *cg,
 unsigned short css_id(struct cgroup_subsys_state *css);
 unsigned short css_depth(struct cgroup_subsys_state *css);
 
+#ifdef CONFIG_CGROUP_TIMER_SLACK
+struct timer_slack_cgroup {
+	struct cgroup_subsys_state css;
+	unsigned long timer_slack_ns;
+};
+
+static inline struct timer_slack_cgroup *task_timer_slack(struct task_struct *task)
+{
+	return container_of(task_subsys_state(task, timer_slack_subsys_id),
+			    struct timer_slack_cgroup, css);
+}
+#endif
+
 #else /* !CONFIG_CGROUPS */
 
 static inline int cgroup_init_early(void) { return 0; }
kernel/cgroup_timer_slack.c +0 -4
index daa452d..1de122a 100644
@@ -4,10 +4,6 @@
 #include <linux/slab.h>
 
 struct cgroup_subsys timer_slack_subsys;
-struct timer_slack_cgroup {
-	struct cgroup_subsys_state css;
-	unsigned long timer_slack_ns;
-};
 
 static struct timer_slack_cgroup *cgroup_to_tslack_cgroup(struct cgroup *cgroup)
 {
kernel/sys.c +8 -1
index 7f5a0cd..433fcdb 100644
@@ -37,6 +37,8 @@
 #include <linux/ptrace.h>
 #include <linux/fs_struct.h>
 #include <linux/gfp.h>
+#include <linux/cgroup.h>
+#include <linux/init_task.h>
 
 #include <linux/compat.h>
 #include <linux/syscalls.h>
@@ -1688,8 +1690,25 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
 			if (arg2 <= 0)
 				current->timer_slack_ns =
 					current->default_timer_slack_ns;
-			else
+			else {
+#ifdef CONFIG_CGROUP_TIMER_SLACK
+				/* only allow more relaxed slack value than
+				 * the attached timer slack cgroup allows.
+				 */
+				unsigned long cg_timer_slack;

kernel/sys.c SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3, · line 1708

Quoted 10 lines
kernel/sys.c +10 -0
+
+				rcu_read_lock();
+				cg_timer_slack = task_timer_slack(current)->timer_slack_ns;
+				rcu_read_unlock();
+				if (cg_timer_slack < arg2 || cg_timer_slack
+					== TIMER_SLACK_NS_DEFAULT)
+					current->timer_slack_ns = arg2;
+				else
+					return -EINVAL;
+#else

Looks like this could be an inline function which returns the minimum timer slack allowed for the task. Then the code here would be:

if (arg2 <= 0)

	current->timer_slack_ns = current->default_timer_slack_ns;
else {
	if (arg2 < min_timer_slack_ns(tsk))
		return -EINVAL; /* Can't set less than the minimum */
	current->timer_slack_ns = arg2;
}
Quoted 6 lines

and the #ifdef CONFIG_CGROUP_TIMER_SLACK bits could be in a header as usual.

Incidentally, shouldn't that really be -EPERM since it's not an invalid value -- just one that's not permitted due to restrictions imposed by the cgroup subsystem?

I guess better to add more functionality to the cgroup subsystem. I'm going to implement timer_slack.min_slack_ns and timer_slack.max_slack_ns. prctl(2) will be modified to check these limits.

Quoted 13 lines
Quoted 13 lines
kernel/sys.c +2 -0
 				current->timer_slack_ns = arg2;
+#endif
+			}
 			error = 0;
 			break;
 		case PR_MCE_KILL:
Signature · 6 lines
1.7.0.4

_______________________________________________
Containers mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/containers
Signature · 1 line
 Kirill A. Shutemov
#8 lore raw
In reply to Matt Helsley
Quoted 11 lines · Matt Helsley
Quoted 9 lines · On Tue, Feb 01, 2011 at 02:41:43PM -0800, [email protected] wrote:

From: Jacob Pan <[email protected]>

Per cgroup timer slack value is used to manage task groups for more friendly power management behavior. Once a task is attached to a cgroup, we should not allow user to change (escape) the per cgroup restriction unless a more relaxed timer slack value is given by user via prctl.

Quoted 8 lines
Quoted 2 lines
---
 include/linux/cgroup.h      |   13 +++++++++++++

Looks like the original two patches (one or more implementing:

Quoted 1 line
 kernel/cgroup_timer_slack.c |    4 ----

) were not sent to [email protected] ?

Oops, I didn't see the patches from Kirill A. Shutsemov that this apparently applies to, sorry. Odd, my mail client doesn't show a Cc for him on this thread... (added)

Cheers,
-Matt

Quoted 113 lines
Quoted 67 lines
 kernel/sys.c                |   21 ++++++++++++++++++++-
 3 files changed, 33 insertions(+), 5 deletions(-)
include/linux/cgroup.h +13 -0
index ed4ba11..4405666 100644
@@ -627,6 +627,19 @@ bool css_is_ancestor(struct cgroup_subsys_state *cg,
 unsigned short css_id(struct cgroup_subsys_state *css);
 unsigned short css_depth(struct cgroup_subsys_state *css);
 
+#ifdef CONFIG_CGROUP_TIMER_SLACK
+struct timer_slack_cgroup {
+	struct cgroup_subsys_state css;
+	unsigned long timer_slack_ns;
+};
+
+static inline struct timer_slack_cgroup *task_timer_slack(struct task_struct *task)
+{
+	return container_of(task_subsys_state(task, timer_slack_subsys_id),
+			    struct timer_slack_cgroup, css);
+}
+#endif
+
 #else /* !CONFIG_CGROUPS */
 
 static inline int cgroup_init_early(void) { return 0; }
kernel/cgroup_timer_slack.c +0 -4
index daa452d..1de122a 100644
@@ -4,10 +4,6 @@
 #include <linux/slab.h>
 
 struct cgroup_subsys timer_slack_subsys;
-struct timer_slack_cgroup {
-	struct cgroup_subsys_state css;
-	unsigned long timer_slack_ns;
-};
 
 static struct timer_slack_cgroup *cgroup_to_tslack_cgroup(struct cgroup *cgroup)
 {
kernel/sys.c +8 -1
index 7f5a0cd..433fcdb 100644
@@ -37,6 +37,8 @@
 #include <linux/ptrace.h>
 #include <linux/fs_struct.h>
 #include <linux/gfp.h>
+#include <linux/cgroup.h>
+#include <linux/init_task.h>
 
 #include <linux/compat.h>
 #include <linux/syscalls.h>
@@ -1688,8 +1690,25 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
 			if (arg2 <= 0)
 				current->timer_slack_ns =
 					current->default_timer_slack_ns;
-			else
+			else {
+#ifdef CONFIG_CGROUP_TIMER_SLACK
+				/* only allow more relaxed slack value than
+				 * the attached timer slack cgroup allows.
+				 */
+				unsigned long cg_timer_slack;

kernel/sys.c SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3, · line 1708

Quoted 10 lines
kernel/sys.c +10 -0
+
+				rcu_read_lock();
+				cg_timer_slack = task_timer_slack(current)->timer_slack_ns;
+				rcu_read_unlock();
+				if (cg_timer_slack < arg2 || cg_timer_slack
+					== TIMER_SLACK_NS_DEFAULT)
+					current->timer_slack_ns = arg2;
+				else
+					return -EINVAL;
+#else

Looks like this could be an inline function which returns the minimum timer slack allowed for the task. Then the code here would be:

if (arg2 <= 0)

	current->timer_slack_ns = current->default_timer_slack_ns;
else {
	if (arg2 < min_timer_slack_ns(tsk))
		return -EINVAL; /* Can't set less than the minimum */
	current->timer_slack_ns = arg2;
}

and the #ifdef CONFIG_CGROUP_TIMER_SLACK bits could be in a header as usual.

Incidentally, shouldn't that really be -EPERM since it's not an invalid value -- just one that's not permitted due to restrictions imposed by the cgroup subsystem?

Quoted 13 lines
kernel/sys.c +2 -0
 				current->timer_slack_ns = arg2;
+#endif
+			}
 			error = 0;
 			break;
 		case PR_MCE_KILL:
Signature · 6 lines
1.7.0.4

_______________________________________________
Containers mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/containers

_______________________________________________
Containers mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/containers