new chcpu tool
Subsystems (2)
cover new chcpu tool
This patch set introduces a new chcpu tool to util-linux. chcpu lets a user configure CPUs. In this first version all that is possible is to enable or disable CPUs (set them online of offline).
This is quite useful if you work a lot with virtual servers, since enabling and disabling cpus manually via sysfs becomes tiring.
This first version is kept very simple so that I can easily change things based on feedback/criticism before I add more functionality. More features that I would like to add are
- rescan cpus: trigger the kernel to trigger a rescan of cpus. Necessary because not all hypervisors on s390 generate a guest event if a new cpu becomes visible to a guest.
- configure/deconfigure cpus: if cpus are offline the resources taken by the hypervisor can be freed if the cpus are deconfigured. Makes sense if a cpus are given dedicated to a logical partition. Deconfigured cpus can be given to other logical partitions.
- set dispatch mode: if the underlying hypervisor is PR/SM (LPAR hypervisor) it is possible to configure it's scheduling algorithm for the virtual cpus of the own logical partition.
Other architectures might add own features...
Any feedback and/or criticism would be welcome.
A usage example with a logical partition with 20 virtual cpus:
[root@r35lp37]# chcpu --help
Usage:
chcpu [options] [cpu-list]
Options:
-h, --help print this help -e, --enable enable cpus -d, --disable disable cpus -v, --verbose explain what is being done -V, --version output version information and exit
[root@r35lp37]# cat /proc/cpuinfo vendor_id : IBM/S390 # processors : 4 bogomips per cpu: 14367.00 features : esan3 zarch stfle msa ldisp eimm dfp etf3eh highgprs processor 1: version = 00, identification = 279F25, machine = 2817 processor 10: version = 00, identification = 279F25, machine = 2817 processor 11: version = 00, identification = 279F25, machine = 2817 processor 12: version = 00, identification = 279F25, machine = 2817
[root@r35lp37]# ./chcpu -v -e 0-20 CPU 0 enabled CPU 1 already enabled CPU 2 enabled CPU 3 enabled CPU 4 enabled CPU 5 enabled CPU 6 enabled CPU 7 enabled CPU 8 enabled CPU 9 enabled CPU 10 already enabled CPU 11 already enabled CPU 12 already enabled CPU 13 enabled CPU 14 enabled CPU 15 enabled CPU 16 enabled CPU 17 enabled CPU 18 enabled CPU 19 enabled CPU 20 does not exist
[root@r35lp37]# cat /proc/cpuinfo vendor_id : IBM/S390 # processors : 20 bogomips per cpu: 14367.00 features : esan3 zarch stfle msa ldisp eimm dfp etf3eh highgprs processor 0: version = 00, identification = 279F25, machine = 2817 processor 1: version = 00, identification = 279F25, machine = 2817 processor 2: version = 00, identification = 279F25, machine = 2817 processor 3: version = 00, identification = 279F25, machine = 2817 processor 4: version = 00, identification = 279F25, machine = 2817 processor 5: version = 00, identification = 279F25, machine = 2817 processor 6: version = 00, identification = 279F25, machine = 2817 processor 7: version = 00, identification = 279F25, machine = 2817 processor 8: version = 00, identification = 279F25, machine = 2817 processor 9: version = 00, identification = 279F25, machine = 2817 processor 10: version = 00, identification = 279F25, machine = 2817 processor 11: version = 00, identification = 279F25, machine = 2817 processor 12: version = 00, identification = 279F25, machine = 2817 processor 13: version = 00, identification = 279F25, machine = 2817 processor 14: version = 00, identification = 279F25, machine = 2817 processor 15: version = 00, identification = 279F25, machine = 2817 processor 16: version = 00, identification = 279F25, machine = 2817 processor 17: version = 00, identification = 279F25, machine = 2817 processor 18: version = 00, identification = 279F25, machine = 2817 processor 19: version = 00, identification = 279F25, machine = 2817
Thanks,
Heiko
PATCH 1/2 cpuset: add option to allow cpulist_parse() to fail
From: Heiko Carstens <[email protected]>
This is a preparation patch for chcpu. If a cpu should be added to a cpu_set where the cpu doesn't fit into the cpu_set this got silently ignored.
Since the cpu-list is user space provided it should be checked if cpus are specified that are completely out of range of the system. In order to do that add a parameter which specifies if cpulist_parse() should fail if it parses a cpu-list with "impossible" cpus. The current callers have been converted so they behave like before.
--- include/cpuset.h | 2 +- lib/cpuset.c | 7 +++++-- schedutils/taskset.c | 2 +- sys-utils/lscpu.c | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-)
include/cpuset.h +1 -1
@@ -67,7 +67,7 @@ extern cpu_set_t *cpuset_alloc(int ncpus, size_t *setsize, size_t *nbits);extern void cpuset_free (cpu_set_t *set);extern char *cpulist_create (char *str,size_t len,cpu_set_t *set,size_t setsize); -extern int cpulist_parse (const char *str,cpu_set_t *set,size_t setsize); +extern int cpulist_parse (const char *str,cpu_set_t *set,size_t setsize,int fail);extern char *cpumask_create (char *str,size_t len,cpu_set_t *set,size_t setsize);extern int cpumask_parse (const char *str,cpu_set_t *set,size_t setsize);
lib/cpuset.c +5 -2
@@ -264,8 +264,9 @@ int cpumask_parse(const char *str, cpu_set_t *set, size_t setsize)/* * Parses string with CPUs mask. */ -int cpulist_parse (const char *str,cpu_set_t *set,size_t setsize) +int cpulist_parse (const char *str,cpu_set_t *set,size_t setsize,int fail) { +size_t max =cpuset_nbits (setsize);const char *p, *q; q = str;
@@ -297,6 +298,8 @@ int cpulist_parse(const char *str, cpu_set_t *set, size_t setsize)if (!(a <= b))return 1 ;while (a <= b) { +if (fail && (a >= max)) +return 1 ;CPU_SET_S (a, setsize, set); a += s; }
@@ -359,7 +362,7 @@ int main(int argc, char *argv[])if (mask) rc =cpumask_parse (mask, set, setsize);else - rc =cpulist_parse (range, set, setsize); + rc =cpulist_parse (range, set, setsize,0 );if (rc)errx (EXIT_FAILURE ,"failed to parse string: %s" , mask ? : range);
schedutils/taskset.c +1 -1
@@ -208,7 +208,7 @@ int main(int argc, char **argv) ts.get_only =1 ; else if (ts.use_list) { -if (cpulist_parse (argv[optind], new_set, new_setsize)) +if (cpulist_parse (argv[optind], new_set, new_setsize,0 ))errx (EXIT_FAILURE ,_ ("failed to parse CPU list: %s" ), argv[optind]); } else if (cpumask_parse(argv[optind], new_set, new_setsize)) {
sys-utils/lscpu.c +1 -1
@@ -304,7 +304,7 @@ path_cpuparse(int islist, const char *path, va_list ap)err (EXIT_FAILURE ,_ ("failed to callocate cpu set" ));if (islist) { -if (cpulist_parse (buf, set, setsize)) +if (cpulist_parse (buf, set, setsize,0 ))errx (EXIT_FAILURE ,_ ("failed to parse CPU list %s" ), buf); }else {if (cpumask_parse (buf, set, setsize))
Signature · 1 line
1.7.5.4
PATCH 2/2 chcpu: new tool
In reply to Heiko CarstensFrom: Heiko Carstens <[email protected]>
The chcpu lets a user configure CPUs. In this first version all that is possible is to enable or disable CPUs (set them online of offline). This is quite useful if you work a lot with virtual servers, since enabling and disabling cpus via sysfs becomes tiring.
--- sys-utils/.gitignore | 1 + sys-utils/Makefile.am | 3 + sys-utils/chcpu.1 | 56 ++++++++++++ sys-utils/chcpu.c | 222 +++++++++++++++++++++++++++++++++++++++++++++++++ sys-utils/lscpu.1 | 2 + 5 files changed, 284 insertions(+), 0 deletions(-) create mode 100644 sys-utils/chcpu.1 create mode 100644 sys-utils/chcpu.c
sys-utils/.gitignore +1 -0
@@ -41,3 +41,4 @@ switch_root tunelp unshare x86_64.8 +chcpu
sys-utils/Makefile.am +3 -0
@@ -21,6 +21,9 @@ if HAVE_CPU_SET_T usrbin_exec_PROGRAMS += lscpu lscpu_SOURCES = lscpu.c $(top_srcdir)/lib/cpuset.c $(top_srcdir)/lib/strutils.c dist_man_MANS += lscpu.1 +sbin_PROGRAMS += chcpu +chcpu_SOURCES = chcpu.c $(top_srcdir)/lib/cpuset.c +dist_man_MANS += chcpu.1 endif endif
sys-utils/chcpu.1 new file +56 -0
56 lines not on this page · raw message
sys-utils/chcpu.c new file +222 -0
222 lines not on this page · raw message
sys-utils/lscpu.1 +2 -0
@@ -56,6 +56,8 @@ Sometimes in Xen Dom0 the kernel reports wrong data. Cai Qian <[email protected]> Karel Zak <[email protected]> .fi +.SH "SEE ALSO" +.BR chcpu (1) .SH AVAILABILITY The lscpu command is part of the util-linux package and is available from ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
Signature · 1 line
1.7.5.4
PATCH 1/1 new chcpu tool
In reply to Heiko CarstensHi Karel,
here is an updated version of the chcpu tool that includes all the features I described in my previous mail.
Do you think it would be ok to have it in util-linux? Or should it live somewhere else?
The rationale why I think it should be within util-linux is simply that lscpu is already there. Parts of the tool are architecture/hypervisor dependent, but some things are useful for most architectures, I think. At least for those architectures that support virtualization quite a few features are (or will be) common.
Another reason for trying to add it to util-linux is that we want to avoid doing the same mistake we did already with the "lsmem" and "chmem" tools which can configure hotplug memory. These tools are completely architecture independent, but we put them into our "s390-tools" package.
I think both of them should live in util-linux instead... But that's something we could address later anyway :)
Anyway, what do you think?
Thanks,
Heiko
----
Subject: [PATCH] chcpu: new tool
From: Heiko Carstens <[email protected]>
chcpu can modify the logical state of CPUs. It can enable and disable CPUs, scan for new CPUs, change the CPU dispatching mode of the underlying hypervisor and request (configure) or give logical CPUs back (deconfigure) to the the underlying hypervisor.
This is quite useful if you work a lot with virtual servers, since doing all the configuration stuff directly via sysfs becomes a pain.
---
sys-utils/.gitignore | 1 sys-utils/Makefile.am | 3 sys-utils/chcpu.1 | 94 +++++++++++++ sys-utils/chcpu.c | 337 ++++++++++++++++++++++++++++++++++++++++++++++++++ sys-utils/lscpu.1 | 2 5 files changed, 437 insertions(+)
sys-utils/.gitignore +1 -0
@@ -41,3 +41,4 @@ switch_root tunelp unshare x86_64.8 +chcpu
sys-utils/Makefile.am +3 -0
@@ -21,6 +21,9 @@ if HAVE_CPU_SET_T usrbin_exec_PROGRAMS += lscpu lscpu_SOURCES = lscpu.c $(top_srcdir)/lib/cpuset.c $(top_srcdir)/lib/strutils.c dist_man_MANS += lscpu.1 +sbin_PROGRAMS += chcpu +chcpu_SOURCES = chcpu.c $(top_srcdir)/lib/cpuset.c +dist_man_MANS += chcpu.1 endif endif
sys-utils/chcpu.1 new file +94 -0
94 lines not on this page · raw message
sys-utils/chcpu.c new file +337 -0
337 lines not on this page · raw message
sys-utils/lscpu.1 +2 -0
@@ -56,6 +56,8 @@ Sometimes in Xen Dom0 the kernel reports wrong data. Cai Qian <[email protected]> Karel Zak <[email protected]> .fi +.SH "SEE ALSO" +.BR chcpu (1) .SH AVAILABILITY The lscpu command is part of the util-linux package and is available from ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
Karel Zak
maintainerQuoted 2 lines · Heiko Carstens
Do you think it would be ok to have it in util-linux? Or should it live somewhere else?
It makes sense to have it in util-linux. I'm going to merge it after v2.20 release.
Quoted 6 lines
Another reason for trying to add it to util-linux is that we want to avoid doing the same mistake we did already with the "lsmem" and "chmem" tools which can configure hotplug memory. These tools are completely architecture independent, but we put them into our "s390-tools" package.
I think both of them should live in util-linux instead... But that's something we could address later anyway :)
OK :-)
Quoted 1 line
+static int
path_exist(const char *path, ...)
It seems that we need to move the path_*() functions from lscpu(1) to lib/ and hare the stuff.
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Quoted 6 lines · Karel Zak
Quoted 2 lines · Heiko Carstens
Do you think it would be ok to have it in util-linux? Or should it live somewhere else?
It makes sense to have it in util-linux. I'm going to merge it after v2.20 release.
Ok, great!
I set up a chcpu git branch where you could pull the chcpu stuff easily:
git://git.kernel.org/pub/scm/linux/kernel/git/heiko/util-linux.git chcpu
It contains just the two patches posted here and doesn't interfer with the lscpu branch that is also there.
Heiko Carstens (2):
cpuset: add option to allow cpulist_parse() to fail
chcpu: new tool
include/cpuset.h | 2 +- lib/cpuset.c | 7 +- schedutils/taskset.c | 2 +- sys-utils/.gitignore | 1 + sys-utils/Makefile.am | 3 + sys-utils/chcpu.1 | 94 ++++++++++++++ sys-utils/chcpu.c | 337 +++++++++++++++++++++++++++++++++++++++++++++++++ sys-utils/lscpu.1 | 2 + sys-utils/lscpu.c | 2 +- 9 files changed, 445 insertions(+), 5 deletions(-) create mode 100644 sys-utils/chcpu.1 create mode 100644 sys-utils/chcpu.c
Quoted 4 lines
Quoted 1 line
+static int
path_exist(const char *path, ...)It seems that we need to move the path_*() functions from lscpu(1) to
lib/and hare the stuff.
Yes, I thought so as well. But laziness won ;)
Thanks,
Heiko
Karel Zak
maintainerRe: [PATCH/RFC 2/2] chcpu: new tool
In reply to Heiko Carstenssys-utils/chcpu.c line 220
Quoted 9 lines · Heiko Carstens
sys-utils/chcpu.c new file +9
-0+if ((argc ==1 ) || (argc != optind)) +usage (stderr); + +switch (cmd) { +case CMD_CPU_ENABLE : +return cpu_enable (cpu_set, ncpus,1 ); +case CMD_CPU_DISABLE : +return cpu_enable (cpu_set, ncpus,0 ); + }
What about to add CMD_CPU_SHOW and use it as a default if --enable/disable is not specified?
I know that you can use lscpu, but it's not intuitive... see for example ionice, nice or so. You can see the current status and then change it.
It's trivial change to the cpu_enable() function.
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Karel Zak
maintainerRe: [PATCH/RFC 2/2] chcpu: new tool
Quoted 13 lines · Karel Zak
sys-utils/chcpu.c line 220
Quoted 9 lines · Heiko Carstens
sys-utils/chcpu.c new file +9
-0+if ((argc ==1 ) || (argc != optind)) +usage (stderr); + +switch (cmd) { +case CMD_CPU_ENABLE : +return cpu_enable (cpu_set, ncpus,1 ); +case CMD_CPU_DISABLE : +return cpu_enable (cpu_set, ncpus,0 ); + }What about to add
CMD_CPU_SHOWand use it as a default if --enable/disable is not specified?
Ah... I see your updated version now. Sorry. Ignore my note about CMD_CPU_SHOW :-) It will be better to use lscpu.
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Quoted 3 lines · Heiko Carstens
I set up a chcpu git branch where you could pull the chcpu stuff easily:
git://git.kernel.org/pub/scm/linux/kernel/git/heiko/util-linux.gitchcpu
Merged to my private repository. The hera server at kernel.org is still off-line so I'll push it later. Thanks!
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com