Skip to content

Commit 8f1073e

Browse files
committed
Merge branch 'pm-qos'
* pm-qos: (30 commits) PM: QoS: annotate data races in pm_qos_*_value() Documentation: power: fix pm_qos_interface.rst format warning PM: QoS: Make CPU latency QoS depend on CONFIG_CPU_IDLE Documentation: PM: QoS: Update to reflect previous code changes PM: QoS: Update file information comments PM: QoS: Drop PM_QOS_CPU_DMA_LATENCY and rename related functions sound: Call cpu_latency_qos_*() instead of pm_qos_*() drivers: usb: Call cpu_latency_qos_*() instead of pm_qos_*() drivers: tty: Call cpu_latency_qos_*() instead of pm_qos_*() drivers: spi: Call cpu_latency_qos_*() instead of pm_qos_*() drivers: net: Call cpu_latency_qos_*() instead of pm_qos_*() drivers: mmc: Call cpu_latency_qos_*() instead of pm_qos_*() drivers: media: Call cpu_latency_qos_*() instead of pm_qos_*() drivers: hsi: Call cpu_latency_qos_*() instead of pm_qos_*() drm: i915: Call cpu_latency_qos_*() instead of pm_qos_*() x86: platform: iosf_mbi: Call cpu_latency_qos_*() instead of pm_qos_*() cpuidle: Call cpu_latency_qos_limit() instead of pm_qos_request() PM: QoS: Add CPU latency QoS API wrappers PM: QoS: Adjust pm_qos_request() signature and reorder pm_qos.h PM: QoS: Simplify definitions of CPU latency QoS trace events ...
2 parents 2f6bdb0 + a534e92 commit 8f1073e

File tree

29 files changed

+407
-715
lines changed

29 files changed

+407
-715
lines changed

Documentation/admin-guide/pm/cpuidle.rst

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -583,20 +583,17 @@ Power Management Quality of Service for CPUs
583583
The power management quality of service (PM QoS) framework in the Linux kernel
584584
allows kernel code and user space processes to set constraints on various
585585
energy-efficiency features of the kernel to prevent performance from dropping
586-
below a required level. The PM QoS constraints can be set globally, in
587-
predefined categories referred to as PM QoS classes, or against individual
588-
devices.
586+
below a required level.
589587

590588
CPU idle time management can be affected by PM QoS in two ways, through the
591-
global constraint in the ``PM_QOS_CPU_DMA_LATENCY`` class and through the
592-
resume latency constraints for individual CPUs. Kernel code (e.g. device
593-
drivers) can set both of them with the help of special internal interfaces
594-
provided by the PM QoS framework. User space can modify the former by opening
595-
the :file:`cpu_dma_latency` special device file under :file:`/dev/` and writing
596-
a binary value (interpreted as a signed 32-bit integer) to it. In turn, the
597-
resume latency constraint for a CPU can be modified by user space by writing a
598-
string (representing a signed 32-bit integer) to the
599-
:file:`power/pm_qos_resume_latency_us` file under
589+
global CPU latency limit and through the resume latency constraints for
590+
individual CPUs. Kernel code (e.g. device drivers) can set both of them with
591+
the help of special internal interfaces provided by the PM QoS framework. User
592+
space can modify the former by opening the :file:`cpu_dma_latency` special
593+
device file under :file:`/dev/` and writing a binary value (interpreted as a
594+
signed 32-bit integer) to it. In turn, the resume latency constraint for a CPU
595+
can be modified from user space by writing a string (representing a signed
596+
32-bit integer) to the :file:`power/pm_qos_resume_latency_us` file under
600597
:file:`/sys/devices/system/cpu/cpu<N>/` in ``sysfs``, where the CPU number
601598
``<N>`` is allocated at the system initialization time. Negative values
602599
will be rejected in both cases and, also in both cases, the written integer
@@ -605,32 +602,34 @@ number will be interpreted as a requested PM QoS constraint in microseconds.
605602
The requested value is not automatically applied as a new constraint, however,
606603
as it may be less restrictive (greater in this particular case) than another
607604
constraint previously requested by someone else. For this reason, the PM QoS
608-
framework maintains a list of requests that have been made so far in each
609-
global class and for each device, aggregates them and applies the effective
610-
(minimum in this particular case) value as the new constraint.
605+
framework maintains a list of requests that have been made so far for the
606+
global CPU latency limit and for each individual CPU, aggregates them and
607+
applies the effective (minimum in this particular case) value as the new
608+
constraint.
611609

612610
In fact, opening the :file:`cpu_dma_latency` special device file causes a new
613-
PM QoS request to be created and added to the priority list of requests in the
614-
``PM_QOS_CPU_DMA_LATENCY`` class and the file descriptor coming from the
615-
"open" operation represents that request. If that file descriptor is then
616-
used for writing, the number written to it will be associated with the PM QoS
617-
request represented by it as a new requested constraint value. Next, the
618-
priority list mechanism will be used to determine the new effective value of
619-
the entire list of requests and that effective value will be set as a new
620-
constraint. Thus setting a new requested constraint value will only change the
621-
real constraint if the effective "list" value is affected by it. In particular,
622-
for the ``PM_QOS_CPU_DMA_LATENCY`` class it only affects the real constraint if
623-
it is the minimum of the requested constraints in the list. The process holding
624-
a file descriptor obtained by opening the :file:`cpu_dma_latency` special device
625-
file controls the PM QoS request associated with that file descriptor, but it
626-
controls this particular PM QoS request only.
611+
PM QoS request to be created and added to a global priority list of CPU latency
612+
limit requests and the file descriptor coming from the "open" operation
613+
represents that request. If that file descriptor is then used for writing, the
614+
number written to it will be associated with the PM QoS request represented by
615+
it as a new requested limit value. Next, the priority list mechanism will be
616+
used to determine the new effective value of the entire list of requests and
617+
that effective value will be set as a new CPU latency limit. Thus requesting a
618+
new limit value will only change the real limit if the effective "list" value is
619+
affected by it, which is the case if it is the minimum of the requested values
620+
in the list.
621+
622+
The process holding a file descriptor obtained by opening the
623+
:file:`cpu_dma_latency` special device file controls the PM QoS request
624+
associated with that file descriptor, but it controls this particular PM QoS
625+
request only.
627626

628627
Closing the :file:`cpu_dma_latency` special device file or, more precisely, the
629628
file descriptor obtained while opening it, causes the PM QoS request associated
630-
with that file descriptor to be removed from the ``PM_QOS_CPU_DMA_LATENCY``
631-
class priority list and destroyed. If that happens, the priority list mechanism
632-
will be used, again, to determine the new effective value for the whole list
633-
and that value will become the new real constraint.
629+
with that file descriptor to be removed from the global priority list of CPU
630+
latency limit requests and destroyed. If that happens, the priority list
631+
mechanism will be used again, to determine the new effective value for the whole
632+
list and that value will become the new limit.
634633

635634
In turn, for each CPU there is one resume latency PM QoS request associated with
636635
the :file:`power/pm_qos_resume_latency_us` file under
@@ -647,10 +646,10 @@ CPU in question every time the list of requests is updated this way or another
647646
(there may be other requests coming from kernel code in that list).
648647

649648
CPU idle time governors are expected to regard the minimum of the global
650-
effective ``PM_QOS_CPU_DMA_LATENCY`` class constraint and the effective
651-
resume latency constraint for the given CPU as the upper limit for the exit
652-
latency of the idle states they can select for that CPU. They should never
653-
select any idle states with exit latency beyond that limit.
649+
(effective) CPU latency limit and the effective resume latency constraint for
650+
the given CPU as the upper limit for the exit latency of the idle states that
651+
they are allowed to select for that CPU. They should never select any idle
652+
states with exit latency beyond that limit.
654653

655654

656655
Idle States Control Via Kernel Command Line

Documentation/power/pm_qos_interface.rst

Lines changed: 40 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -7,86 +7,78 @@ performance expectations by drivers, subsystems and user space applications on
77
one of the parameters.
88

99
Two different PM QoS frameworks are available:
10-
1. PM QoS classes for cpu_dma_latency
11-
2. The per-device PM QoS framework provides the API to manage the
10+
* CPU latency QoS.
11+
* The per-device PM QoS framework provides the API to manage the
1212
per-device latency constraints and PM QoS flags.
1313

14-
Each parameters have defined units:
15-
16-
* latency: usec
17-
* timeout: usec
18-
* throughput: kbs (kilo bit / sec)
19-
* memory bandwidth: mbs (mega bit / sec)
14+
The latency unit used in the PM QoS framework is the microsecond (usec).
2015

2116

2217
1. PM QoS framework
2318
===================
2419

25-
The infrastructure exposes multiple misc device nodes one per implemented
26-
parameter. The set of parameters implement is defined by pm_qos_power_init()
27-
and pm_qos_params.h. This is done because having the available parameters
28-
being runtime configurable or changeable from a driver was seen as too easy to
29-
abuse.
30-
31-
For each parameter a list of performance requests is maintained along with
32-
an aggregated target value. The aggregated target value is updated with
33-
changes to the request list or elements of the list. Typically the
34-
aggregated target value is simply the max or min of the request values held
35-
in the parameter list elements.
20+
A global list of CPU latency QoS requests is maintained along with an aggregated
21+
(effective) target value. The aggregated target value is updated with changes
22+
to the request list or elements of the list. For CPU latency QoS, the
23+
aggregated target value is simply the min of the request values held in the list
24+
elements.
25+
3626
Note: the aggregated target value is implemented as an atomic variable so that
3727
reading the aggregated value does not require any locking mechanism.
3828

29+
From kernel space the use of this interface is simple:
3930

40-
From kernel mode the use of this interface is simple:
41-
42-
void pm_qos_add_request(handle, param_class, target_value):
43-
Will insert an element into the list for that identified PM QoS class with the
44-
target value. Upon change to this list the new target is recomputed and any
45-
registered notifiers are called only if the target value is now different.
46-
Clients of pm_qos need to save the returned handle for future use in other
47-
pm_qos API functions.
31+
void cpu_latency_qos_add_request(handle, target_value):
32+
Will insert an element into the CPU latency QoS list with the target value.
33+
Upon change to this list the new target is recomputed and any registered
34+
notifiers are called only if the target value is now different.
35+
Clients of PM QoS need to save the returned handle for future use in other
36+
PM QoS API functions.
4837

49-
void pm_qos_update_request(handle, new_target_value):
38+
void cpu_latency_qos_update_request(handle, new_target_value):
5039
Will update the list element pointed to by the handle with the new target
5140
value and recompute the new aggregated target, calling the notification tree
5241
if the target is changed.
5342

54-
void pm_qos_remove_request(handle):
43+
void cpu_latency_qos_remove_request(handle):
5544
Will remove the element. After removal it will update the aggregate target
5645
and call the notification tree if the target was changed as a result of
5746
removing the request.
5847

59-
int pm_qos_request(param_class):
60-
Returns the aggregated value for a given PM QoS class.
48+
int cpu_latency_qos_limit():
49+
Returns the aggregated value for the CPU latency QoS.
50+
51+
int cpu_latency_qos_request_active(handle):
52+
Returns if the request is still active, i.e. it has not been removed from the
53+
CPU latency QoS list.
6154

62-
int pm_qos_request_active(handle):
63-
Returns if the request is still active, i.e. it has not been removed from a
64-
PM QoS class constraints list.
55+
int cpu_latency_qos_add_notifier(notifier):
56+
Adds a notification callback function to the CPU latency QoS. The callback is
57+
called when the aggregated value for the CPU latency QoS is changed.
6558

66-
int pm_qos_add_notifier(param_class, notifier):
67-
Adds a notification callback function to the PM QoS class. The callback is
68-
called when the aggregated value for the PM QoS class is changed.
59+
int cpu_latency_qos_remove_notifier(notifier):
60+
Removes the notification callback function from the CPU latency QoS.
6961

70-
int pm_qos_remove_notifier(int param_class, notifier):
71-
Removes the notification callback function for the PM QoS class.
7262

63+
From user space:
7364

74-
From user mode:
65+
The infrastructure exposes one device node, /dev/cpu_dma_latency, for the CPU
66+
latency QoS.
7567

76-
Only processes can register a pm_qos request. To provide for automatic
68+
Only processes can register a PM QoS request. To provide for automatic
7769
cleanup of a process, the interface requires the process to register its
78-
parameter requests in the following way:
70+
parameter requests as follows.
7971

80-
To register the default pm_qos target for the specific parameter, the process
81-
must open /dev/cpu_dma_latency
72+
To register the default PM QoS target for the CPU latency QoS, the process must
73+
open /dev/cpu_dma_latency.
8274

8375
As long as the device node is held open that process has a registered
8476
request on the parameter.
8577

86-
To change the requested target value the process needs to write an s32 value to
87-
the open device node. Alternatively the user mode program could write a hex
88-
string for the value using 10 char long format e.g. "0x12345678". This
89-
translates to a pm_qos_update_request call.
78+
To change the requested target value, the process needs to write an s32 value to
79+
the open device node. Alternatively, it can write a hex string for the value
80+
using the 10 char long format e.g. "0x12345678". This translates to a
81+
cpu_latency_qos_update_request() call.
9082

9183
To remove the user mode request for a target value simply close the device
9284
node.

Documentation/trace/events-power.rst

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,6 @@ The second parameter is the power domain target state.
7373
================
7474
The PM QoS events are used for QoS add/update/remove request and for
7575
target/flags update.
76-
::
77-
78-
pm_qos_add_request "pm_qos_class=%s value=%d"
79-
pm_qos_update_request "pm_qos_class=%s value=%d"
80-
pm_qos_remove_request "pm_qos_class=%s value=%d"
81-
pm_qos_update_request_timeout "pm_qos_class=%s value=%d, timeout_us=%ld"
82-
83-
The first parameter gives the QoS class name (e.g. "CPU_DMA_LATENCY").
84-
The second parameter is value to be added/updated/removed.
85-
The third parameter is timeout value in usec.
8676
::
8777

8878
pm_qos_update_target "action=%s prev_value=%d curr_value=%d"
@@ -92,7 +82,7 @@ The first parameter gives the QoS action name (e.g. "ADD_REQ").
9282
The second parameter is the previous QoS value.
9383
The third parameter is the current QoS value to update.
9484

95-
And, there are also events used for device PM QoS add/update/remove request.
85+
There are also events used for device PM QoS add/update/remove request.
9686
::
9787

9888
dev_pm_qos_add_request "device=%s type=%s new_value=%d"
@@ -103,3 +93,12 @@ The first parameter gives the device name which tries to add/update/remove
10393
QoS requests.
10494
The second parameter gives the request type (e.g. "DEV_PM_QOS_RESUME_LATENCY").
10595
The third parameter is value to be added/updated/removed.
96+
97+
And, there are events used for CPU latency QoS add/update/remove request.
98+
::
99+
100+
pm_qos_add_request "value=%d"
101+
pm_qos_update_request "value=%d"
102+
pm_qos_remove_request "value=%d"
103+
104+
The parameter is the value to be added/updated/removed.

arch/x86/platform/intel/iosf_mbi.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ static void iosf_mbi_reset_semaphore(void)
265265
iosf_mbi_sem_address, 0, PUNIT_SEMAPHORE_BIT))
266266
dev_err(&mbi_pdev->dev, "Error P-Unit semaphore reset failed\n");
267267

268-
pm_qos_update_request(&iosf_mbi_pm_qos, PM_QOS_DEFAULT_VALUE);
268+
cpu_latency_qos_update_request(&iosf_mbi_pm_qos, PM_QOS_DEFAULT_VALUE);
269269

270270
blocking_notifier_call_chain(&iosf_mbi_pmic_bus_access_notifier,
271271
MBI_PMIC_BUS_ACCESS_END, NULL);
@@ -301,8 +301,8 @@ static void iosf_mbi_reset_semaphore(void)
301301
* 4) When CPU cores enter C6 or C7 the P-Unit needs to talk to the PMIC
302302
* if this happens while the kernel itself is accessing the PMIC I2C bus
303303
* the SoC hangs.
304-
* As the third step we call pm_qos_update_request() to disallow the CPU
305-
* to enter C6 or C7.
304+
* As the third step we call cpu_latency_qos_update_request() to disallow the
305+
* CPU to enter C6 or C7.
306306
*
307307
* 5) The P-Unit has a PMIC bus semaphore which we can request to stop
308308
* autonomous P-Unit tasks from accessing the PMIC I2C bus while we hold it.
@@ -338,7 +338,7 @@ int iosf_mbi_block_punit_i2c_access(void)
338338
* requires the P-Unit to talk to the PMIC and if this happens while
339339
* we're holding the semaphore, the SoC hangs.
340340
*/
341-
pm_qos_update_request(&iosf_mbi_pm_qos, 0);
341+
cpu_latency_qos_update_request(&iosf_mbi_pm_qos, 0);
342342

343343
/* host driver writes to side band semaphore register */
344344
ret = iosf_mbi_write(BT_MBI_UNIT_PMC, MBI_REG_WRITE,
@@ -547,8 +547,7 @@ static int __init iosf_mbi_init(void)
547547
{
548548
iosf_debugfs_init();
549549

550-
pm_qos_add_request(&iosf_mbi_pm_qos, PM_QOS_CPU_DMA_LATENCY,
551-
PM_QOS_DEFAULT_VALUE);
550+
cpu_latency_qos_add_request(&iosf_mbi_pm_qos, PM_QOS_DEFAULT_VALUE);
552551

553552
return pci_register_driver(&iosf_mbi_pci_driver);
554553
}
@@ -561,7 +560,7 @@ static void __exit iosf_mbi_exit(void)
561560
pci_dev_put(mbi_pdev);
562561
mbi_pdev = NULL;
563562

564-
pm_qos_remove_request(&iosf_mbi_pm_qos);
563+
cpu_latency_qos_remove_request(&iosf_mbi_pm_qos);
565564
}
566565

567566
module_init(iosf_mbi_init);

drivers/cpuidle/cpuidle.c

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -736,53 +736,15 @@ int cpuidle_register(struct cpuidle_driver *drv,
736736
}
737737
EXPORT_SYMBOL_GPL(cpuidle_register);
738738

739-
#ifdef CONFIG_SMP
740-
741-
/*
742-
* This function gets called when a part of the kernel has a new latency
743-
* requirement. This means we need to get all processors out of their C-state,
744-
* and then recalculate a new suitable C-state. Just do a cross-cpu IPI; that
745-
* wakes them all right up.
746-
*/
747-
static int cpuidle_latency_notify(struct notifier_block *b,
748-
unsigned long l, void *v)
749-
{
750-
wake_up_all_idle_cpus();
751-
return NOTIFY_OK;
752-
}
753-
754-
static struct notifier_block cpuidle_latency_notifier = {
755-
.notifier_call = cpuidle_latency_notify,
756-
};
757-
758-
static inline void latency_notifier_init(struct notifier_block *n)
759-
{
760-
pm_qos_add_notifier(PM_QOS_CPU_DMA_LATENCY, n);
761-
}
762-
763-
#else /* CONFIG_SMP */
764-
765-
#define latency_notifier_init(x) do { } while (0)
766-
767-
#endif /* CONFIG_SMP */
768-
769739
/**
770740
* cpuidle_init - core initializer
771741
*/
772742
static int __init cpuidle_init(void)
773743
{
774-
int ret;
775-
776744
if (cpuidle_disabled())
777745
return -ENODEV;
778746

779-
ret = cpuidle_add_interface(cpu_subsys.dev_root);
780-
if (ret)
781-
return ret;
782-
783-
latency_notifier_init(&cpuidle_latency_notifier);
784-
785-
return 0;
747+
return cpuidle_add_interface(cpu_subsys.dev_root);
786748
}
787749

788750
module_param(off, int, 0444);

drivers/cpuidle/governor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
109109
*/
110110
s64 cpuidle_governor_latency_req(unsigned int cpu)
111111
{
112-
int global_req = pm_qos_request(PM_QOS_CPU_DMA_LATENCY);
113112
struct device *device = get_cpu_device(cpu);
114113
int device_req = dev_pm_qos_raw_resume_latency(device);
114+
int global_req = cpu_latency_qos_limit();
115115

116116
if (device_req > global_req)
117117
device_req = global_req;

drivers/gpu/drm/i915/display/intel_dp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,7 +1360,7 @@ intel_dp_aux_xfer(struct intel_dp *intel_dp,
13601360
* lowest possible wakeup latency and so prevent the cpu from going into
13611361
* deep sleep states.
13621362
*/
1363-
pm_qos_update_request(&i915->pm_qos, 0);
1363+
cpu_latency_qos_update_request(&i915->pm_qos, 0);
13641364

13651365
intel_dp_check_edp(intel_dp);
13661366

@@ -1488,7 +1488,7 @@ intel_dp_aux_xfer(struct intel_dp *intel_dp,
14881488

14891489
ret = recv_bytes;
14901490
out:
1491-
pm_qos_update_request(&i915->pm_qos, PM_QOS_DEFAULT_VALUE);
1491+
cpu_latency_qos_update_request(&i915->pm_qos, PM_QOS_DEFAULT_VALUE);
14921492

14931493
if (vdd)
14941494
edp_panel_vdd_off(intel_dp, false);

0 commit comments

Comments
 (0)