]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
s390/topology: Add sysctl handler for polarization
authorTobias Huschle <huschle@linux.ibm.com>
Mon, 12 Aug 2024 11:39:31 +0000 (13:39 +0200)
committerVasily Gorbik <gor@linux.ibm.com>
Thu, 29 Aug 2024 20:56:35 +0000 (22:56 +0200)
Provide an additional path to set the polarization of the system, such
that a user no longer relies on the sysfs interface only and is able
configure the polarization for every reboot via sysctl control files.

The new sysctl can be set as follows:
 - s390.polarization=0 for horizontal polarization
 - s390.polarization=1 for vertical polarization

Acked-by: Heiko Carstens <hca@linux.ibm.com>
Tested-by: Mete Durlu <meted@linux.ibm.com>
Signed-off-by: Tobias Huschle <huschle@linux.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
arch/s390/kernel/topology.c

index 22029ecae1c554a9a7aa8bbd8e68fbc7b33d7e11..4bd0ee8eb1ab5d507b2529f1bbbe9e77fa55aafe 100644 (file)
@@ -376,6 +376,25 @@ void topology_expect_change(void)
 
 static int cpu_management;
 
+static int set_polarization(int polarization)
+{
+       int rc = 0;
+
+       cpus_read_lock();
+       mutex_lock(&smp_cpu_state_mutex);
+       if (cpu_management == polarization)
+               goto out;
+       rc = topology_set_cpu_management(polarization);
+       if (rc)
+               goto out;
+       cpu_management = polarization;
+       topology_expect_change();
+out:
+       mutex_unlock(&smp_cpu_state_mutex);
+       cpus_read_unlock();
+       return rc;
+}
+
 static ssize_t dispatching_show(struct device *dev,
                                struct device_attribute *attr,
                                char *buf)
@@ -400,19 +419,7 @@ static ssize_t dispatching_store(struct device *dev,
                return -EINVAL;
        if (val != 0 && val != 1)
                return -EINVAL;
-       rc = 0;
-       cpus_read_lock();
-       mutex_lock(&smp_cpu_state_mutex);
-       if (cpu_management == val)
-               goto out;
-       rc = topology_set_cpu_management(val);
-       if (rc)
-               goto out;
-       cpu_management = val;
-       topology_expect_change();
-out:
-       mutex_unlock(&smp_cpu_state_mutex);
-       cpus_read_unlock();
+       rc = set_polarization(val);
        return rc ? rc : count;
 }
 static DEVICE_ATTR_RW(dispatching);
@@ -624,12 +631,37 @@ static int topology_ctl_handler(const struct ctl_table *ctl, int write,
        return rc;
 }
 
+static int polarization_ctl_handler(const struct ctl_table *ctl, int write,
+                                   void *buffer, size_t *lenp, loff_t *ppos)
+{
+       int polarization;
+       int rc;
+       struct ctl_table ctl_entry = {
+               .procname       = ctl->procname,
+               .data           = &polarization,
+               .maxlen         = sizeof(int),
+               .extra1         = SYSCTL_ZERO,
+               .extra2         = SYSCTL_ONE,
+       };
+
+       polarization = cpu_management;
+       rc = proc_douintvec_minmax(&ctl_entry, write, buffer, lenp, ppos);
+       if (rc < 0 || !write)
+               return rc;
+       return set_polarization(polarization);
+}
+
 static struct ctl_table topology_ctl_table[] = {
        {
                .procname       = "topology",
                .mode           = 0644,
                .proc_handler   = topology_ctl_handler,
        },
+       {
+               .procname       = "polarization",
+               .mode           = 0644,
+               .proc_handler   = polarization_ctl_handler,
+       },
 };
 
 static int __init topology_init(void)