Skip to contentSkip to conversation

cpufreq/schedutil: Only bind threads if needed

PATCH Applied Christian Loehle 2 participants 2 messages Jan 20, 2025 – Jan 23, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpufreq/schedutil: Only bind threads if needed

Remove the unconditional binding of sugov kthreads to the affected CPUs if the cpufreq driver indicates that updates can happen from any CPU. This allows userspace to set affinities to either save power (waking up bigger CPUs on HMP can be expensive) or increasing performance (by letting the utilized CPUs run without preemption of the sugov kthread).

---
- RESEND: pick up tags
- v2: Add comment for the dl_task_check_affinity return (Juri)
v2: https://lore.kernel.org/lkml/[email protected]/
v1: https://lore.kernel.org/lkml/[email protected]/

 kernel/sched/cpufreq_schedutil.c | 6 +++++-
 kernel/sched/syscalls.c          | 7 +++++++
 2 files changed, 12 insertions(+), 1 deletion(-)
kernel/sched/cpufreq_schedutil.c +5 -1
index 28c77904ea74..a81444501158 100644
@@ -691,7 +691,11 @@ static int sugov_kthread_create(struct sugov_policy *sg_policy)
 	}
 
 	sg_policy->thread = thread;
-	kthread_bind_mask(thread, policy->related_cpus);
+	if (policy->dvfs_possible_from_any_cpu)
+		set_cpus_allowed_ptr(thread, policy->related_cpus);
+	else
+		kthread_bind_mask(thread, policy->related_cpus);
+
 	init_irq_work(&sg_policy->irq_work, sugov_irq_work);
 	mutex_init(&sg_policy->work_lock);
 
kernel/sched/syscalls.c +7 -0
index ff0e5ab4e37c..8230358d2b90 100644
@@ -1139,6 +1139,13 @@ int dl_task_check_affinity(struct task_struct *p, const struct cpumask *mask)
 	if (!task_has_dl_policy(p) || !dl_bandwidth_enabled())
 		return 0;
 
+	/*
+	 * The special/sugov task isn't part of regular bandwidth/admission
+	 * control so let userspace change affinities.
+	 */
+	if (dl_entity_is_special(&p->dl))
+		return 0;
+
 	/*
 	 * Since bandwidth control happens on root_domain basis,
 	 * if admission test is enabled, we only admit -deadline
Signature · 1 line
2.34.1
maintainer Applied
#1 lore raw
Quoted 48 lines · Christian Loehle

Remove the unconditional binding of sugov kthreads to the affected CPUs if the cpufreq driver indicates that updates can happen from any CPU. This allows userspace to set affinities to either save power (waking up bigger CPUs on HMP can be expensive) or increasing performance (by letting the utilized CPUs run without preemption of the sugov kthread).

---
- RESEND: pick up tags
- v2: Add comment for the dl_task_check_affinity return (Juri)
v2: https://lore.kernel.org/lkml/[email protected]/
v1: https://lore.kernel.org/lkml/[email protected]/

 kernel/sched/cpufreq_schedutil.c | 6 +++++-
 kernel/sched/syscalls.c          | 7 +++++++
 2 files changed, 12 insertions(+), 1 deletion(-)
kernel/sched/cpufreq_schedutil.c +5 -1
index 28c77904ea74..a81444501158 100644
@@ -691,7 +691,11 @@ static int sugov_kthread_create(struct sugov_policy *sg_policy)
        }
 
        sg_policy->thread = thread;
-       kthread_bind_mask(thread, policy->related_cpus);
+       if (policy->dvfs_possible_from_any_cpu)
+               set_cpus_allowed_ptr(thread, policy->related_cpus);
+       else
+               kthread_bind_mask(thread, policy->related_cpus);
+
        init_irq_work(&sg_policy->irq_work, sugov_irq_work);
        mutex_init(&sg_policy->work_lock);
 
kernel/sched/syscalls.c +1 -0
index ff0e5ab4e37c..8230358d2b90 100644
@@ -1139,6 +1139,13 @@ int dl_task_check_affinity(struct task_struct *p, const struct cpumask *mask)
        if (!task_has_dl_policy(p) || !dl_bandwidth_enabled())
                return 0;
 
+       /*

kernel/sched/syscalls.c int dl_task_check_affinity(struct task_struct *p, const struct cpumask *mask)

Quoted 10 lines
kernel/sched/syscalls.c +6 -1
+        * The special/sugov task isn't part of regular bandwidth/admission
+        * control so let userspace change affinities.
+        */
+       if (dl_entity_is_special(&p->dl))
+               return 0;
+
        /*
         * Since bandwidth control happens on root_domain basis,
         * if admission test is enabled, we only admit -deadline
--

Applied as 6.14-rc material, thanks!