ibm-s390-linux / s390-tools

Tools for use with the s390 Linux kernel and device drivers
MIT License
63 stars 60 forks source link

RFE: make cpuplugd arch-agnostic #24

Open sharkcz opened 6 years ago

sharkcz commented 6 years ago

I think the idea behind cpuplugd is useful in general, dynamically add resources when needed and remove them when not needed. And it shouldn't be difficult to use cpuplugd on platform other than s390x, with

diff --git a/cpuplugd/cpu.c b/cpuplugd/cpu.c
index a4456cf..e603137 100644
--- a/cpuplugd/cpu.c
+++ b/cpuplugd/cpu.c
@@ -24,7 +24,7 @@ int get_numcpus()

        for (i = 0; ; i++) {
                /* check whether file exists and is readable */
-               sprintf(path, "/sys/devices/system/cpu/cpu%d/online", i);
+               sprintf(path, "/sys/devices/system/cpu/cpu%d", i);
                if (access(path, R_OK) == 0)
                        number++;
                else

it worked on my x86 machine (for the CPU part). Although more changes will be needed for a proper non-s390x support. I believe it would save power when used with modern multi-core CPUs like Power9 or some AArch64 ones.

Then cpuplugd might be another candidate for moving into util-linux package.

michael-holzheu commented 6 years ago

@gerald-schaefer could you have a look please?

gerald-schaefer commented 6 years ago

I am a little surprised that Intel doesn't seem to have an online attribute for CPU 0, and the concept of "(de)configured" CPUs also seems to be missing, but it shouldn't be too difficult to adjust the cpuplugd code for this (at least get_numcpus(), get_num_online_cpus() and cpu_is_configured(), from a quick glance). The memory hotplug part using the s390-specific cmm memory balloon would also need to be disabled for other archs, or maybe rewritten to use the generic sysfs memory hotplug interface.

I currently don't have resources for this, and I also wonder if there really would be demand for this on other architectures, so that it would be worth the effort. If you want to spend the effort, feel free to send a pull request with the complete changes, or maybe even move it to util-linux.

sharkcz commented 6 years ago

I'm planning to play with it more seriously when I get my Power9-based based workstation to save some power/electricity :-) Will let you know about the results.