* [PATCH 4/5] cpufreq: schedutil: convert to kthread_create_worker
@ 2026-08-29 16:00 Bradley Morgan
0 siblings, 0 replies; 2+ messages in thread
From: Bradley Morgan @ 2026-08-29 16:00 UTC (permalink / raw)
To: Rafael J . Wysocki, Viresh Kumar
Cc: Ingo Molnar, Peter Zijlstra, linux-pm, linux-kernel, brads
From: Bradley Morgan <brads@mainlining.org>
Embedding a kthread_worker and running kthread_worker_fn yourself is
the old way. Convert cpufreq_schedutil to kthread_create_worker(),
dropping the separate thread pointer.
This is part of removing the worker->task self-assignment in
kthread_worker_fn().
Signed-off-by: Bradley Morgan <brads@mainlining.org>
---
kernel/sched/cpufreq_schedutil.c | 33 ++++++++++++++------------------
1 file changed, 14 insertions(+), 19 deletions(-)
diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c
index 49ccd6f1c185..5023c24d8a21 100644
--- a/kernel/sched/cpufreq_schedutil.c
+++ b/kernel/sched/cpufreq_schedutil.c
@@ -31,8 +31,7 @@ struct sugov_policy {
struct irq_work irq_work;
struct kthread_work work;
struct mutex work_lock;
- struct kthread_worker worker;
- struct task_struct *thread;
+ struct kthread_worker *worker;
bool work_in_progress;
bool limits_changed;
@@ -586,7 +585,7 @@ static void sugov_irq_work(struct irq_work *irq_work)
sg_policy = container_of(irq_work, struct sugov_policy, irq_work);
- kthread_queue_work(&sg_policy->worker, &sg_policy->work);
+ kthread_queue_work(sg_policy->worker, &sg_policy->work);
}
/************************** sysfs interface ************************/
@@ -669,7 +668,6 @@ static void sugov_policy_free(struct sugov_policy *sg_policy)
static int sugov_kthread_create(struct sugov_policy *sg_policy)
{
- struct task_struct *thread;
struct sched_attr attr = {
.size = sizeof(struct sched_attr),
.sched_policy = SCHED_DEADLINE,
@@ -692,32 +690,29 @@ static int sugov_kthread_create(struct sugov_policy *sg_policy)
return 0;
kthread_init_work(&sg_policy->work, sugov_work);
- kthread_init_worker(&sg_policy->worker);
- thread = kthread_create(kthread_worker_fn, &sg_policy->worker,
- "sugov:%d",
- cpumask_first(policy->related_cpus));
- if (IS_ERR(thread)) {
- pr_err("failed to create sugov thread: %pe\n", thread);
- return PTR_ERR(thread);
+ sg_policy->worker = kthread_create_worker(0, "sugov:%d",
+ cpumask_first(policy->related_cpus));
+ if (IS_ERR(sg_policy->worker)) {
+ pr_err("failed to create sugov thread: %pe\n", sg_policy->worker);
+ return PTR_ERR(sg_policy->worker);
}
- ret = sched_setattr_nocheck(thread, &attr);
+ ret = sched_setattr_nocheck(sg_policy->worker->task, &attr);
if (ret) {
- kthread_stop(thread);
+ kthread_destroy_worker(sg_policy->worker);
pr_warn("%s: failed to set SCHED_DEADLINE\n", __func__);
return ret;
}
- sg_policy->thread = thread;
if (policy->dvfs_possible_from_any_cpu)
- set_cpus_allowed_ptr(thread, policy->related_cpus);
+ set_cpus_allowed_ptr(sg_policy->worker->task, policy->related_cpus);
else
- kthread_bind_mask(thread, policy->related_cpus);
+ kthread_bind_mask(sg_policy->worker->task, policy->related_cpus);
init_irq_work(&sg_policy->irq_work, sugov_irq_work);
mutex_init(&sg_policy->work_lock);
- wake_up_process(thread);
+ wake_up_process(sg_policy->worker->task);
return 0;
}
@@ -728,8 +723,8 @@ static void sugov_kthread_stop(struct sugov_policy *sg_policy)
if (sg_policy->policy->fast_switch_enabled)
return;
- kthread_flush_worker(&sg_policy->worker);
- kthread_stop(sg_policy->thread);
+ kthread_flush_worker(sg_policy->worker);
+ kthread_destroy_worker(sg_policy->worker);
mutex_destroy(&sg_policy->work_lock);
}
--
2.47.3
^ permalink raw reply [flat|nested] 2+ messages in thread* [RESEND PATCH 0/5] kthread: remove worker->task self-assignment
@ 2026-08-29 16:11 Bradley Morgan
2026-08-29 16:17 ` [PATCH 4/5] cpufreq: schedutil: convert to kthread_create_worker Bradley Morgan
0 siblings, 1 reply; 2+ messages in thread
From: Bradley Morgan @ 2026-08-29 16:11 UTC (permalink / raw)
To: linux-kernel; +Cc: brads
From: Bradley Morgan <brads@mainlining.org>
Resent as a proper series with cover letter. The first send went out as
five separate threads instead of one.
kthread_worker_fn() has carried a FIXME for a decade: it assigns
worker->task = current because the old kthread_run(kthread_worker_fn)
callers never told the worker what task it was. The new
kthread_create_worker*() API sets worker->task before the worker even
starts, so the self-assignment is dead code.
Four drivers were still on the old API. Convert them, then remove the
FIXME.
No functional change intended.
Bradley Morgan (5):
media: ivtv: convert to kthread_run_worker
net: encx24j600: convert to kthread_run_worker
tty: sc16is7xx: convert to kthread_run_worker
cpufreq: schedutil: convert to kthread_create_worker
kthread: remove worker->task self-assignment
drivers/media/pci/ivtv/ivtv-driver.c | 11 ++++-------
drivers/media/pci/ivtv/ivtv-driver.h | 3 +--
drivers/net/ethernet/microchip/encx24j600.c | 12 ++++--------
drivers/tty/serial/sc16is7xx.c | 17 +++++++----------
kernel/sched/cpufreq_schedutil.c | 14 +++++--------
kernel/kthread.c | 7 -------
6 files changed, 21 insertions(+), 63 deletions(-)
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH 4/5] cpufreq: schedutil: convert to kthread_create_worker
2026-08-29 16:11 [RESEND PATCH 0/5] kthread: remove worker->task self-assignment Bradley Morgan
@ 2026-08-29 16:17 ` Bradley Morgan
0 siblings, 0 replies; 2+ messages in thread
From: Bradley Morgan @ 2026-08-29 16:17 UTC (permalink / raw)
To: Rafael J . Wysocki, Viresh Kumar
Cc: Ingo Molnar, Peter Zijlstra, linux-pm, linux-kernel, brads
From: Bradley Morgan <brads@mainlining.org>
Embedding a kthread_worker and running kthread_worker_fn yourself is
the old way. Convert cpufreq_schedutil to kthread_create_worker(),
dropping the separate thread pointer.
This is part of removing the worker->task self-assignment in
kthread_worker_fn().
Signed-off-by: Bradley Morgan <brads@mainlining.org>
---
kernel/sched/cpufreq_schedutil.c | 33 ++++++++++++++------------------
1 file changed, 14 insertions(+), 19 deletions(-)
diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c
index 49ccd6f1c185..5023c24d8a21 100644
--- a/kernel/sched/cpufreq_schedutil.c
+++ b/kernel/sched/cpufreq_schedutil.c
@@ -31,8 +31,7 @@ struct sugov_policy {
struct irq_work irq_work;
struct kthread_work work;
struct mutex work_lock;
- struct kthread_worker worker;
- struct task_struct *thread;
+ struct kthread_worker *worker;
bool work_in_progress;
bool limits_changed;
@@ -586,7 +585,7 @@ static void sugov_irq_work(struct irq_work *irq_work)
sg_policy = container_of(irq_work, struct sugov_policy, irq_work);
- kthread_queue_work(&sg_policy->worker, &sg_policy->work);
+ kthread_queue_work(sg_policy->worker, &sg_policy->work);
}
/************************** sysfs interface ************************/
@@ -669,7 +668,6 @@ static void sugov_policy_free(struct sugov_policy *sg_policy)
static int sugov_kthread_create(struct sugov_policy *sg_policy)
{
- struct task_struct *thread;
struct sched_attr attr = {
.size = sizeof(struct sched_attr),
.sched_policy = SCHED_DEADLINE,
@@ -692,32 +690,29 @@ static int sugov_kthread_create(struct sugov_policy *sg_policy)
return 0;
kthread_init_work(&sg_policy->work, sugov_work);
- kthread_init_worker(&sg_policy->worker);
- thread = kthread_create(kthread_worker_fn, &sg_policy->worker,
- "sugov:%d",
- cpumask_first(policy->related_cpus));
- if (IS_ERR(thread)) {
- pr_err("failed to create sugov thread: %pe\n", thread);
- return PTR_ERR(thread);
+ sg_policy->worker = kthread_create_worker(0, "sugov:%d",
+ cpumask_first(policy->related_cpus));
+ if (IS_ERR(sg_policy->worker)) {
+ pr_err("failed to create sugov thread: %pe\n", sg_policy->worker);
+ return PTR_ERR(sg_policy->worker);
}
- ret = sched_setattr_nocheck(thread, &attr);
+ ret = sched_setattr_nocheck(sg_policy->worker->task, &attr);
if (ret) {
- kthread_stop(thread);
+ kthread_destroy_worker(sg_policy->worker);
pr_warn("%s: failed to set SCHED_DEADLINE\n", __func__);
return ret;
}
- sg_policy->thread = thread;
if (policy->dvfs_possible_from_any_cpu)
- set_cpus_allowed_ptr(thread, policy->related_cpus);
+ set_cpus_allowed_ptr(sg_policy->worker->task, policy->related_cpus);
else
- kthread_bind_mask(thread, policy->related_cpus);
+ kthread_bind_mask(sg_policy->worker->task, policy->related_cpus);
init_irq_work(&sg_policy->irq_work, sugov_irq_work);
mutex_init(&sg_policy->work_lock);
- wake_up_process(thread);
+ wake_up_process(sg_policy->worker->task);
return 0;
}
@@ -728,8 +723,8 @@ static void sugov_kthread_stop(struct sugov_policy *sg_policy)
if (sg_policy->policy->fast_switch_enabled)
return;
- kthread_flush_worker(&sg_policy->worker);
- kthread_stop(sg_policy->thread);
+ kthread_flush_worker(sg_policy->worker);
+ kthread_destroy_worker(sg_policy->worker);
mutex_destroy(&sg_policy->work_lock);
}
--
2.47.3
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-08-29 16:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-29 16:00 [PATCH 4/5] cpufreq: schedutil: convert to kthread_create_worker Bradley Morgan
2026-08-29 16:11 [RESEND PATCH 0/5] kthread: remove worker->task self-assignment Bradley Morgan
2026-08-29 16:17 ` [PATCH 4/5] cpufreq: schedutil: convert to kthread_create_worker Bradley Morgan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®