LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH 0/2] CGroups _s64 files: Intro
@ 2008-03-05 10:20 menage
  2008-03-05 10:20 ` [PATCH 1/2] CGroups _s64 files: Add cgroups read_s64/write_s64 file methods menage
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: menage @ 2008-03-05 10:20 UTC (permalink / raw)
  To: Peter Zijlstra, akpm; +Cc: linux-kernel, containers

These patches add cgroups read_s64 and write_s64 control file methods
(the signed equivalent of read_u64/write_u64) and use them to
implement the cpu.rt_runtime_us control file in the CFS cgroup
subsystem.

Signed-off-by: Paul Menage <menage@google.com>

--

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] CGroups _s64 files: Add cgroups read_s64/write_s64 file methods
  2008-03-05 10:20 [PATCH 0/2] CGroups _s64 files: Intro menage
@ 2008-03-05 10:20 ` menage
  2008-03-05 10:20 ` [PATCH 2/2] CGroups _s64 files: Use read_s64/write_s64 in CFS cgroup for rt_runtime file menage
  2008-03-05 10:29 ` [PATCH 0/2] CGroups _s64 files: Intro Peter Zijlstra
  2 siblings, 0 replies; 4+ messages in thread
From: menage @ 2008-03-05 10:20 UTC (permalink / raw)
  To: Peter Zijlstra, akpm; +Cc: linux-kernel, containers

[-- Attachment #1: cgroup_read_s64.patch --]
[-- Type: text/plain, Size: 3808 bytes --]

These are the signed equivalents of the read_u64/write_u64 methods

Signed-off-by: Paul Menage <menage@google.com>

---
 include/linux/cgroup.h |    8 ++++++++
 kernel/cgroup.c        |   38 ++++++++++++++++++++++++++++----------
 2 files changed, 36 insertions(+), 10 deletions(-)

Index: read_s64-2.6.25-rc3-mm1/include/linux/cgroup.h
===================================================================
--- read_s64-2.6.25-rc3-mm1.orig/include/linux/cgroup.h
+++ read_s64-2.6.25-rc3-mm1/include/linux/cgroup.h
@@ -216,6 +216,10 @@ struct cftype {
 	 */
 	u64 (*read_u64) (struct cgroup *cgrp, struct cftype *cft);
 	/*
+	 * read_s64() is a signed version of read_u64()
+	 */
+	s64 (*read_s64) (struct cgroup *cgrp, struct cftype *cft);
+	/*
 	 * read_map() is used for defining a map of key/value
 	 * pairs. It should call cb->fill(cb, key, value) for each
 	 * entry. The key/value pairs (and their ordering) should not
@@ -234,6 +238,10 @@ struct cftype {
 	 * userspace. Use in place of write(); return 0 or error.
 	 */
 	int (*write_u64) (struct cgroup *cgrp, struct cftype *cft, u64 val);
+	/*
+	 * write_s64() is a signed version of write_u64()
+	 */
+	int (*write_s64) (struct cgroup *cgrp, struct cftype *cft, s64 val);
 
 	int (*release) (struct inode *inode, struct file *file);
 };
Index: read_s64-2.6.25-rc3-mm1/kernel/cgroup.c
===================================================================
--- read_s64-2.6.25-rc3-mm1.orig/kernel/cgroup.c
+++ read_s64-2.6.25-rc3-mm1/kernel/cgroup.c
@@ -1291,14 +1291,13 @@ enum cgroup_filetype {
 	FILE_RELEASE_AGENT,
 };
 
-static ssize_t cgroup_write_u64(struct cgroup *cgrp, struct cftype *cft,
+static ssize_t cgroup_write_X64(struct cgroup *cgrp, struct cftype *cft,
 				struct file *file,
 				const char __user *userbuf,
 				size_t nbytes, loff_t *unused_ppos)
 {
 	char buffer[64];
 	int retval = 0;
-	u64 val;
 	char *end;
 
 	if (!nbytes)
@@ -1310,12 +1309,17 @@ static ssize_t cgroup_write_u64(struct c
 
 	buffer[nbytes] = 0;     /* nul-terminate */
 	strstrip(buffer);
-	val = simple_strtoull(buffer, &end, 0);
-	if (*end)
-		return -EINVAL;
-
-	/* Pass to subsystem */
-	retval = cft->write_u64(cgrp, cft, val);
+	if (cft->write_u64) {
+		u64 val = simple_strtoull(buffer, &end, 0);
+		if (*end)
+			return -EINVAL;
+		retval = cft->write_u64(cgrp, cft, val);
+	} else {
+		s64 val = simple_strtoll(buffer, &end, 0);
+		if (*end)
+			return -EINVAL;
+		retval = cft->write_s64(cgrp, cft, val);
+	}
 	if (!retval)
 		retval = nbytes;
 	return retval;
@@ -1396,8 +1400,8 @@ static ssize_t cgroup_file_write(struct 
 		return -ENODEV;
 	if (cft->write)
 		return cft->write(cgrp, cft, file, buf, nbytes, ppos);
-	if (cft->write_u64)
-		return cgroup_write_u64(cgrp, cft, file, buf, nbytes, ppos);
+	if (cft->write_u64 || cft->write_s64)
+		return cgroup_write_X64(cgrp, cft, file, buf, nbytes, ppos);
 	return -EINVAL;
 }
 
@@ -1413,6 +1417,18 @@ static ssize_t cgroup_read_u64(struct cg
 	return simple_read_from_buffer(buf, nbytes, ppos, tmp, len);
 }
 
+static ssize_t cgroup_read_s64(struct cgroup *cgrp, struct cftype *cft,
+			       struct file *file,
+			       char __user *buf, size_t nbytes,
+			       loff_t *ppos)
+{
+	char tmp[64];
+	s64 val = cft->read_s64(cgrp, cft);
+	int len = sprintf(tmp, "%lld\n", (long long) val);
+
+	return simple_read_from_buffer(buf, nbytes, ppos, tmp, len);
+}
+
 static ssize_t cgroup_common_file_read(struct cgroup *cgrp,
 					  struct cftype *cft,
 					  struct file *file,
@@ -1469,6 +1485,8 @@ static ssize_t cgroup_file_read(struct f
 		return cft->read(cgrp, cft, file, buf, nbytes, ppos);
 	if (cft->read_u64)
 		return cgroup_read_u64(cgrp, cft, file, buf, nbytes, ppos);
+	if (cft->read_s64)
+		return cgroup_read_s64(cgrp, cft, file, buf, nbytes, ppos);
 	return -EINVAL;
 }
 

--

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/2] CGroups _s64 files: Use read_s64/write_s64 in CFS cgroup for rt_runtime file
  2008-03-05 10:20 [PATCH 0/2] CGroups _s64 files: Intro menage
  2008-03-05 10:20 ` [PATCH 1/2] CGroups _s64 files: Add cgroups read_s64/write_s64 file methods menage
@ 2008-03-05 10:20 ` menage
  2008-03-05 10:29 ` [PATCH 0/2] CGroups _s64 files: Intro Peter Zijlstra
  2 siblings, 0 replies; 4+ messages in thread
From: menage @ 2008-03-05 10:20 UTC (permalink / raw)
  To: Peter Zijlstra, akpm; +Cc: linux-kernel, containers

[-- Attachment #1: cfs_use_readwrite_s64.patch --]
[-- Type: text/plain, Size: 2159 bytes --]

This removes some filesystem boilerplate from the CFS cgroup subsystem.

Signed-off-by: Paul Menage <menage@google.com>

---
 kernel/sched.c |   52 +++++++++-------------------------------------------
 1 file changed, 9 insertions(+), 43 deletions(-)

Index: read_s64-2.6.25-rc3-mm1/kernel/sched.c
===================================================================
--- read_s64-2.6.25-rc3-mm1.orig/kernel/sched.c
+++ read_s64-2.6.25-rc3-mm1/kernel/sched.c
@@ -8081,48 +8081,14 @@ static u64 cpu_shares_read_u64(struct cg
 
 #ifdef CONFIG_RT_GROUP_SCHED
 static int cpu_rt_runtime_write(struct cgroup *cgrp, struct cftype *cft,
-				struct file *file,
-				const char __user *userbuf,
-				size_t nbytes, loff_t *unused_ppos)
-{
-	char buffer[64];
-	int retval = 0;
-	s64 val;
-	char *end;
-
-	if (!nbytes)
-		return -EINVAL;
-	if (nbytes >= sizeof(buffer))
-		return -E2BIG;
-	if (copy_from_user(buffer, userbuf, nbytes))
-		return -EFAULT;
-
-	buffer[nbytes] = 0;     /* nul-terminate */
-
-	/* strip newline if necessary */
-	if (nbytes && (buffer[nbytes-1] == '\n'))
-		buffer[nbytes-1] = 0;
-	val = simple_strtoll(buffer, &end, 0);
-	if (*end)
-		return -EINVAL;
-
-	/* Pass to subsystem */
-	retval = sched_group_set_rt_runtime(cgroup_tg(cgrp), val);
-	if (!retval)
-		retval = nbytes;
-	return retval;
-}
-
-static ssize_t cpu_rt_runtime_read(struct cgroup *cgrp, struct cftype *cft,
-				   struct file *file,
-				   char __user *buf, size_t nbytes,
-				   loff_t *ppos)
-{
-	char tmp[64];
-	long val = sched_group_rt_runtime(cgroup_tg(cgrp));
-	int len = sprintf(tmp, "%ld\n", val);
+				s64 val)
+{
+	return sched_group_set_rt_runtime(cgroup_tg(cgrp), val);
+}
 
-	return simple_read_from_buffer(buf, nbytes, ppos, tmp, len);
+static s64 cpu_rt_runtime_read(struct cgroup *cgrp, struct cftype *cft)
+{
+	return sched_group_rt_runtime(cgroup_tg(cgrp));
 }
 #endif
 
@@ -8137,8 +8103,8 @@ static struct cftype cpu_files[] = {
 #ifdef CONFIG_RT_GROUP_SCHED
 	{
 		.name = "rt_runtime_us",
-		.read = cpu_rt_runtime_read,
-		.write = cpu_rt_runtime_write,
+		.read_s64 = cpu_rt_runtime_read,
+		.write_s64 = cpu_rt_runtime_write,
 	},
 #endif
 };

--

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] CGroups _s64 files: Intro
  2008-03-05 10:20 [PATCH 0/2] CGroups _s64 files: Intro menage
  2008-03-05 10:20 ` [PATCH 1/2] CGroups _s64 files: Add cgroups read_s64/write_s64 file methods menage
  2008-03-05 10:20 ` [PATCH 2/2] CGroups _s64 files: Use read_s64/write_s64 in CFS cgroup for rt_runtime file menage
@ 2008-03-05 10:29 ` Peter Zijlstra
  2 siblings, 0 replies; 4+ messages in thread
From: Peter Zijlstra @ 2008-03-05 10:29 UTC (permalink / raw)
  To: menage; +Cc: akpm, linux-kernel, containers

On Wed, 2008-03-05 at 02:20 -0800, menage@google.com wrote:
> These patches add cgroups read_s64 and write_s64 control file methods
> (the signed equivalent of read_u64/write_u64) and use them to
> implement the cpu.rt_runtime_us control file in the CFS cgroup
> subsystem.
> 
> Signed-off-by: Paul Menage <menage@google.com>

Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-03-05 10:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-05 10:20 [PATCH 0/2] CGroups _s64 files: Intro menage
2008-03-05 10:20 ` [PATCH 1/2] CGroups _s64 files: Add cgroups read_s64/write_s64 file methods menage
2008-03-05 10:20 ` [PATCH 2/2] CGroups _s64 files: Use read_s64/write_s64 in CFS cgroup for rt_runtime file menage
2008-03-05 10:29 ` [PATCH 0/2] CGroups _s64 files: Intro Peter Zijlstra

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).