[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <386d99d3-aa97-4069-8d63-d197262832bf@kylinos.cn>
Date: Thu, 10 Jul 2025 08:47:12 +0800
From: Zihuan Zhang <zhangzihuan@...inos.cn>
To: Christian Loehle <christian.loehle@....com>, xuewen.yan@...soc.com,
vincent.guittot@...aro.org, mingo@...hat.com, peterz@...radead.org,
juri.lelli@...hat.com
Cc: rostedt@...dmis.org, bsegall@...gle.com, mgorman@...e.de,
vschneid@...hat.com, hongyan.xia2@....com, linux-kernel@...r.kernel.org,
ke.wang@...soc.com, di.shen@...soc.com, xuewen.yan94@...il.com,
kprateek.nayak@....com, kuyo.chang@...iatek.com, juju.sung@...iatek.com,
qyousef@...alina.io
Subject: Re: [PATCH v1] sched/uclamp: Exclude kernel threads from uclamp logic
Hi Christian,
Apologies for the late reply, and thanks for raising the concerns.
在 2025/7/3 18:17, Christian Loehle 写道:
> On 7/3/25 11:07, Zihuan Zhang wrote:
>> Hi Christian,
>>
>> Thanks for the question!
>>
>> 在 2025/7/3 17:22, Christian Loehle 写道:
>>> On 7/3/25 10:14, Zihuan Zhang wrote:
>>>> Kernel threads (PF_KTHREAD) are not subject to user-defined utilization
>>>> clamping. They do not represent user workloads and should not participate
>>>> in any uclamp logic, including:
>>> Why not?
>>>
>> As Xuewen mentioned, some kernel threads may intentionally set scheduling attributes for performance. So instead of unconditionally excluding all kernel threads, I’m now considering a more conservative approach:
>> skip only those kthreads that haven’t explicitly set any clamp values.
>>
>> This should help avoid unintended clamp aggregation while still supporting performance-tuned kthreads.
> I'm skeptical, fundamentally you cannot exclude some fair tasks from uclamp logic.
> At least the cpufreq part they will be affected by, so if you 'exclude' some
> kthread that doesn't have clamps set (i.e. has min=0, max=1024) its
> utilization may not contribute to sugov frequency selection by being
> clamped by other task(s) (let's say you only have one other task with
> max=0, excluding the unclamped kthread now leads to sugov requesting
> the lowest OPP? Is that always correct/desired?)
>
> Is there a specific issue you're trying to solve?
> FYI there has been discussion around reworking the uclamp mechanism to solve
> some issues you may have been facing, but so far they haven't lead anywhere:
> https://lore.kernel.org/lkml/cover.1741091349.git.hongyan.xia2@arm.com/
Our original motivation stems from the observation that uclamp is
primarily designed to manage frequency selection based on user-space
task behavior. Kernel threads typically do not represent user workloads
and are often not considered meaningful participants in uclamp-driven
decisions.
To be clear, we are not aiming to exclude all kthreads from affecting
frequency, but rather to explore ways to avoid unnecessary uclamp
aggregation overhead from kernel threads that have no explicit clamp
values set (i.e. uclamp.min=0, max=1024).
As you pointed out, fully excluding these tasks might interfere with
sugov behavior in certain edge cases. So a more balanced approach might be:
- For kernel threads that do not set any clamp values, skip the clamp
aggregation step
- If a kernel thread explicitly sets clamp attributes, it should of
course remain fully visible to uclamp logic.
This would preserve correctness while reducing unnecessary overhead in
the hot path, especially on systems with many runnable tasks.
That said, we're open to alternative suggestions if there's a better way
to achieve this optimization. We'll also review the earlier rework
discussion you linked, thank you for pointing that out.
Best regards,
Zihuan Zhang
Powered by blists - more mailing lists