mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Lukasz Luba <lukasz.luba@arm.com>
To: Zhongqiu Han <zhongqiu.han@oss.qualcomm.com>,
	Zhongqiu Han <quic_zhonhan@quicinc.com>
Cc: linux-pm@vger.kernel.org, lenb@kernel.org,
	christian.loehle@arm.com, amit.kucheria@linaro.org,
	ulf.hansson@linaro.org, james.morse@arm.com, Dave.Martin@arm.com,
	reinette.chatre@intel.com, tony.luck@intel.com, pavel@kernel.org,
	linux-kernel@vger.kernel.org, rafael@kernel.org
Subject: Re: [PATCH v2 0/5] PM QoS: Add CPU affinity latency QoS support and resctrl integration
Date: Tue, 28 Oct 2025 13:12:21 +0000	[thread overview]
Message-ID: <b4386726-9c50-47cb-b521-cd6f871d64de@arm.com> (raw)
In-Reply-To: <f1195632-d973-4339-a89d-e1e62b98015d@oss.qualcomm.com>



On 10/24/25 09:25, Zhongqiu Han wrote:
> On 10/23/2025 9:09 PM, Lukasz Luba wrote:
>> Hi Zhongqui,
>>
>> My apologies for being a bit late with my comments...
>>
>> On 7/21/25 13:40, Zhongqiu Han wrote:
>>> Hi all,
>>>
>>> This patch series introduces support for CPU affinity-based latency
>>> constraints in the PM QoS framework. The motivation is to allow
>>> finer-grained power management by enabling latency QoS requests to 
>>> target
>>> specific CPUs, rather than applying system-wide constraints.
>>>
>>> The current PM QoS framework supports global and per-device CPU latency
>>> constraints. However, in many real-world scenarios, such as IRQ affinity
>>> or CPU-bound kernel threads, only a subset of CPUs are
>>> performance-critical. Applying global constraints in such cases
>>> unnecessarily prevents other CPUs from entering deeper C-states, leading
>>> to increased power consumption.
>>>
>>> This series addresses that limitation by introducing a new interface 
>>> that
>>> allows latency constraints to be applied to a CPU mask. This is
>>> particularly useful on heterogeneous platforms (e.g., big.LITTLE) and
>>> embedded systems where power efficiency is critical for example:
>>>
>>>                          driver A       rt kthread B      module C
>>>    CPU IDs (mask):         0-3              2-5              6-7
>>>    target latency(us):     20               30               100
>>>                            |                |                |
>>>                            v                v                v
>>>                            +---------------------------------+
>>>                            |        PM  QoS  Framework       |
>>>                            +---------------------------------+
>>>                            |                |                |
>>>                            v                v                v
>>>    CPU IDs (mask):        0-3            2-3,4-5            6-7
>>>    runtime latency(us):   20             20, 30             100
>>>
>>> The current implementation includes only cpu_affinity_latency_qos_add()
>>> and cpu_affinity_latency_qos_remove() interfaces. An update interface is
>>> planned for future submission, along with PM QoS optimizations in the 
>>> UFS
>>> subsystem.
>>>
>>> Patch1 introduces the core support for CPU affinity latency QoS in 
>>> the PM
>>> QoS framework.
>>>
>>> Patch2 removes redundant KERN_ERR prefixes in WARN() calls in the global
>>> CPU PM QoS interface. This change addresses issues in existing code 
>>> and is
>>> not related to the new interface introduced in this patch series.
>>>
>>> Patch3 adds documentation for the new interface.
>>>
>>> Patch4 fixes a minor documentation issue related to the return type of
>>> cpu_latency_qos_request_active(). This change addresses issues in 
>>> existing
>>> doc and is not related to the new interface introduced in this patch
>>> series.
>>>
>>> Patch5 updates the resctrl pseudo-locking logic to use the new CPU
>>> affinity latency QoS helpers, improving clarity and consistency. The 
>>> only
>>> functional and beneficial change is that the new interface actively 
>>> wakes
>>> up CPUs whose latency QoS values have changed, ensuring the latency 
>>> limit
>>> takes effect immediately.
>>
>> Could you describe a bit more the big picture of this proposed design,
>> please?
>>
>> Ideally with some graph of connected frameworks & drivers and how they
>> are going to work together.
> 
> Hi Lukasz,
> Thank you very much for your review and discussion~
> 
> I will describe you one big picture if needed, please allow me
> illustrate a simple scenario using pseudo code first:
> 
> Suppose there is a USB driver. This driver uses the kernel existing
> cpu_latency_qos_* interfaces to boost its IRQ execution efficiency. Its
> IRQ affinity is set to core0 and core1 according to DTS config, and the
> affinity of its threaded IRQ (bottom half) is also set to CPU0 and CPU1.
> 
> 
> =================================================================
> Using the kernel existing cpu_latency_qos_* interfaces:
> =================================================================
> static int dwc3_sample_probe(struct platform_device *pdev)
> {
>    cpu_latency_qos_add_request(&foo->pm_qos_req,DEFAULT_VALUE);
>    xxxx;
>    ret = devm_request_threaded_irq(xxx,xxx,foo_dwc3_pwr_irq, ....)
>    xxxx;
> }
> 
> static irqreturn_t foo_dwc3_pwr_irq(int irq, void *dev)
> {
>    xxxx;
>    cpu_latency_qos_update_request(&foo->pm_qos_req, 0);
> 
>    /*.... process interrupt ....*/
> 
>    cpu_latency_qos_update_request(&foo->pm_qos_req, DEFAULT_VALUE);
> 
>    return IRQ_HANDLED;
> 
> }
> 
> 
> The number of IRQ executions on each CPU:
> ==================================================================
> IRQ  HWIRQ   affinity CPU0    CPU1   CPU2 CPU3 CPU4 CPU5 CPU6 CPU7
> 320  0xb0    0x3      9782468 415472  0    0    0    0    0    0
> ==================================================================
> 
> ==================================================================
> Process: irq/320-dwc3, [affinity: 0x3]  cpu:1    pid:5250   ppid:2
> ==================================================================
> 
> 
>  From the code, we can see that the USB module using the kernel existing
> cpu_latency_qos_* interfaces sets the CPU latency to 0,\v which prevents
> all CPUs from entering idle states—even C1. During\v operation, the USB
> IRQs is triggered 9,782,468 times on CPU0, and each time it runs,\v all
> CPUs are blocked from entering deeper C-states. However, only CPU0,\v CPU1
> are actually involved in handling the IRQ and its threaded bottom half.
> It will cause unnecessary power consumption on other CPUs.
> (Please note, due to the simplicity of the pseudocode, I did not show
> how the IRQ bottom-half thread is synchronized to restrict CPU idle
> states via PM QoS. In reality, it's clear that we can also apply a CPU
> latency limit to the bottom-half thread.)
> 
> 
> If we use current patch series API cpu_affinity_latency_qos_xxx, such
> as:
> 
> =================================================================
> Using current patch series cpu_affinity_latency_qos_* interfaces:
> =================================================================
> static int dwc3_sample_probe(struct platform_device *pdev)
> {
>    cpu_affinity_latency_qos_add(&foo->pm_qos_req,DEFAULT_VALUE, mask);
>    xxxx;
>    ret = devm_request_threaded_irq(xxx,xxx,foo_dwc3_pwr_irq, ....)
>    xxxx;
> }
> 
> We can only constrain the CPU latency PM QoS on CPU0 and CPU1 in order
> to save power.

Thank you for this explanation. IMO this could be part of the
documentation patch.

> 
>>
>> E.g.:
>> 1. what are the other components in the kernel which would use this
>> feature?
> 
> 1.Drivers such as Audio, USB, and UFS, which currently rely on the
> kernel's global CPU Latency PM QoS interface, but only require latency
> constraints on a subset of CPUs, can leverage this new interface to
> achieve improved power efficiency.
> 
> 2.I’m considering supporting this feature in userspace.
> Once implemented, userspace threads—such as mobile gaming threads that
> aim to constrain CPU latency and are already bound to big cores—will be
> able to use the API to help save power.
> 
>> 2. is there also a user-space interface planned for it so a HAL in
>> the middle-ware would configure these "short-wake-up-CPU"?
> 
> Yes, I am considering to support userspace on patch V3.
> 
>> 3. Is it possible to view/debug from the user-space which component
>> requested this setting for some subsets of cpus?
> 
> I'm uncertain whether we should provide the ability to inspect
> which components are applying constraints on CPU latency. However,
> what I do want to ensure is that—similar to the existing /dev
> cpu_dma_latency interface in the current kernel—I can offer per-CPU
> level latency value setting and querying.
> 
>

OK, I think this is a good approach to not tackle all in single
step, but in some phases. The user-space would need more thinking.

Regards,
Lukasz

  reply	other threads:[~2025-10-28 13:11 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-21 12:40 Zhongqiu Han
2025-07-21 12:41 ` [PATCH v2 1/5] PM: QoS: Add support for CPU affinity latency PM QoS Zhongqiu Han
2025-08-21 10:37   ` Rafael J. Wysocki
2025-08-22 10:31     ` Zhongqiu Han
2025-07-21 12:41 ` [PATCH v2 2/5] PM: QOS: Remove unnecessary KERN_ERR on WARN() calls Zhongqiu Han
2025-07-21 12:41 ` [PATCH v2 3/5] Documentation: PM: QoS: Add CPU affinity latency PM QoS Interface documentation Zhongqiu Han
2025-07-21 12:41 ` [PATCH v2 4/5] Documentation: PM: QoS: Fix return type and return value description Zhongqiu Han
2025-08-01 11:27   ` Christian Loehle
2025-08-04 11:58     ` Zhongqiu Han
2025-07-21 12:41 ` [PATCH v2 5/5] resctrl: Replace PM QoS logic with cpu_affinity_latency_qos_* helpers Zhongqiu Han
2025-07-28 10:09 ` [PATCH v2 0/5] PM QoS: Add CPU affinity latency QoS support and resctrl integration Christian Loehle
2025-07-28 10:40   ` Zhongqiu Han
2025-08-02 14:38     ` Christian Loehle
2025-08-04 13:47       ` Zhongqiu Han
2025-08-15 12:48 ` Zhongqiu Han
2025-10-23 11:03 ` Ulf Hansson
2025-10-24  8:40   ` Zhongqiu Han
2025-10-24 10:44     ` Ulf Hansson
2025-10-27 12:38       ` Zhongqiu Han
2025-10-23 13:09 ` Lukasz Luba
2025-10-24  8:25   ` Zhongqiu Han
2025-10-28 13:12     ` Lukasz Luba [this message]
2025-10-30 13:25       ` Zhongqiu Han

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=b4386726-9c50-47cb-b521-cd6f871d64de@arm.com \
    --to=lukasz.luba@arm.com \
    --cc=Dave.Martin@arm.com \
    --cc=amit.kucheria@linaro.org \
    --cc=christian.loehle@arm.com \
    --cc=james.morse@arm.com \
    --cc=lenb@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=pavel@kernel.org \
    --cc=quic_zhonhan@quicinc.com \
    --cc=rafael@kernel.org \
    --cc=reinette.chatre@intel.com \
    --cc=tony.luck@intel.com \
    --cc=ulf.hansson@linaro.org \
    --cc=zhongqiu.han@oss.qualcomm.com \
    /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 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®