drivers/base/base.h | 4 ++++ drivers/base/cpu.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-)
This is helper patch which could be used to set the range of CPUs as
paravirt. One could make use of this for quick testing of this infra
instead of writing arch specific code.
This is currently not meant be merged, since paravirt sysfs file is meant
to be Read-Only.
echo 100-200,600-700 > /sys/devices/system/cpu/paravirt
cat /sys/devices/system/cpu/paravirt
100-200,600-700
echo > /sys/devices/system/cpu/paravirt
cat /sys/devices/system/cpu/paravirt
Signed-off-by: Shrikanth Hegde <sshegde@linux.ibm.com>
---
Idea was borrowed from Ilya's patch shared to me internally.
It is up for debate to have something like this or like powerpc patch.
drivers/base/base.h | 4 ++++
drivers/base/cpu.c | 43 ++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 46 insertions(+), 1 deletion(-)
diff --git a/drivers/base/base.h b/drivers/base/base.h
index 123031a757d9..bd93b2895b24 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -264,3 +264,7 @@ static inline int devtmpfs_delete_node(struct device *dev) { return 0; }
void software_node_notify(struct device *dev);
void software_node_notify_remove(struct device *dev);
+
+#ifdef CONFIG_PARAVIRT
+DECLARE_STATIC_KEY_FALSE(cpu_paravirt_push_tasks);
+#endif
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index 902747ff4988..d66cbd0c3060 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -375,12 +375,53 @@ static int cpu_uevent(const struct device *dev, struct kobj_uevent_env *env)
#endif
#ifdef CONFIG_PARAVIRT
+static ssize_t store_paravirt_cpus(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ cpumask_var_t temp_mask;
+ int retval = 0;
+
+ if (!alloc_cpumask_var(&temp_mask, GFP_KERNEL))
+ return -ENOMEM;
+
+ retval = cpulist_parse(buf, temp_mask);
+ if (retval)
+ goto free_mask;
+
+ /* ALL cpus can't be marked as paravirt */
+ if (cpumask_equal(temp_mask, cpu_online_mask)) {
+ retval = -EINVAL;
+ goto free_mask;
+ }
+ if (cpumask_weight(temp_mask) > num_online_cpus()) {
+ retval = -EINVAL;
+ goto free_mask;
+ }
+
+ /* No more paravirt cpus */
+ if (cpumask_empty(temp_mask)) {
+ static_branch_disable(&cpu_paravirt_push_tasks);
+ cpumask_copy((struct cpumask *)&__cpu_paravirt_mask, temp_mask);
+
+ } else {
+ static_branch_enable(&cpu_paravirt_push_tasks);
+ cpumask_copy((struct cpumask *)&__cpu_paravirt_mask, temp_mask);
+ }
+
+ retval = count;
+
+free_mask:
+ free_cpumask_var(temp_mask);
+ return retval;
+}
+
static ssize_t print_paravirt_cpus(struct device *dev,
struct device_attribute *attr, char *buf)
{
return sysfs_emit(buf, "%*pbl\n", cpumask_pr_args(cpu_paravirt_mask));
}
-static DEVICE_ATTR(paravirt, 0444, print_paravirt_cpus, NULL);
+static DEVICE_ATTR(paravirt, 0644, print_paravirt_cpus, store_paravirt_cpus);
#endif
const struct bus_type cpu_subsys = {
--
2.47.3
© 2016 - 2025 Red Hat, Inc.