From: Bradley Morgan <include@grrlz.net>
To: "Rafael J . Wysocki" <rafael@kernel.org>,
Viresh Kumar <viresh.kumar@linaro.org>
Cc: Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
brads@mainlining.org
Subject: [PATCH 4/5] cpufreq: schedutil: convert to kthread_create_worker
Date: Sat, 29 Aug 2026 16:17:38 +0000 [thread overview]
Message-ID: <20260829161738.19639-1-include@grrlz.net> (raw)
In-Reply-To: <20260829161150.16301-1-include@grrlz.net>
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
next prev parent reply other threads:[~2026-08-29 16:17 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260829161150.16301-1-include@grrlz.net>
2026-08-29 16:13 ` [PATCH 1/5] media: ivtv: convert to kthread_run_worker Bradley Morgan
2026-08-29 16:15 ` [PATCH 2/5] net: encx24j600: " Bradley Morgan
2026-08-29 16:16 ` [PATCH 3/5] tty: sc16is7xx: " Bradley Morgan
2026-08-29 16:17 ` Bradley Morgan [this message]
2026-08-29 16:00 [PATCH 4/5] cpufreq: schedutil: convert to kthread_create_worker Bradley Morgan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260829161738.19639-1-include@grrlz.net \
--to=include@grrlz.net \
--cc=brads@mainlining.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rafael@kernel.org \
--cc=viresh.kumar@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.