CGroups _s64 files: Intro
cover CGroups _s64 files: Intro
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.
--
PATCH 1/2 CGroups _s64 files: Add cgroups read_s64/write_s64 file methods
These are the signed equivalents of the read_u64/write_u64 methods
--- include/linux/cgroup.h | 8 ++++++++ kernel/cgroup.c | 38 ++++++++++++++++++++++++++++---------- 2 files changed, 36 insertions(+), 10 deletions(-)
include/linux/cgroup.h +8 -0
@@ -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); };
kernel/cgroup.c +28 -10
@@ -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(structreturn -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 cgreturn 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 freturn 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 ; }
--
PATCH 2/2 CGroups _s64 files: Use read_s64/write_s64 in CFS cgroup for rt_runtime file
In reply to [email protected]This removes some filesystem boilerplate from the CFS cgroup subsystem.
--- kernel/sched.c | 52 +++++++++------------------------------------------- 1 file changed, 9 insertions(+), 43 deletions(-)
kernel/sched.c +9 -43
@@ -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 };
--
PATCH 1/2 CGroups _s64 files: Add cgroups read_s64/write_s64 file methods
In reply to [email protected]These are the signed equivalents of the read_u64/write_u64 methods
--- include/linux/cgroup.h | 8 ++++++++ kernel/cgroup.c | 38 ++++++++++++++++++++++++++++---------- 2 files changed, 36 insertions(+), 10 deletions(-)
include/linux/cgroup.h +8 -0
@@ -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); };
kernel/cgroup.c +28 -10
@@ -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(structreturn -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 cgreturn 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 freturn 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 ; }
--
Peter Zijlstra
Acked-byQuoted 6 lines · On Wed, 2008-03-05 at 02:20 -0800, [email protected]…
These patches add cgroups
read_s64andwrite_s64control 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 <[email protected]>
Quoted 6 lines · On Wed, 2008-03-05 at 02:20 -0800, [email protected] wrote:
These patches add cgroups
read_s64andwrite_s64control 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 <[email protected]>