Skip to content

Commit 500ba33

Browse files
maulik-k-shahstorulf
authored andcommitted
pmdomain: governor: Consider CPU latency tolerance from pm_domain_cpu_gov
pm_domain_cpu_gov is selecting a cluster idle state but does not consider latency tolerance of child CPUs. This results in deeper cluster idle state whose latency does not meet latency tolerance requirement. Select deeper idle state only if global and device latency tolerance of all child CPUs meet. Test results on SM8750 with 300 usec PM-QoS on CPU0 which is less than domain idle state entry (2150) + exit (1983) usec latency mentioned in devicetree, demonstrate the issue. # echo 300 > /sys/devices/system/cpu/cpu0/power/pm_qos_resume_latency_us Before: (Usage is incrementing) ====== # cat /sys/kernel/debug/pm_genpd/power-domain-cluster0/idle_states State Time Spent(ms) Usage Rejected Above Below S0 29817 537 8 270 0 # cat /sys/kernel/debug/pm_genpd/power-domain-cluster0/idle_states State Time Spent(ms) Usage Rejected Above Below S0 30348 542 8 271 0 After: (Usage is not incrementing due to latency tolerance) ====== # cat /sys/kernel/debug/pm_genpd/power-domain-cluster0/idle_states State Time Spent(ms) Usage Rejected Above Below S0 39319 626 14 307 0 # cat /sys/kernel/debug/pm_genpd/power-domain-cluster0/idle_states State Time Spent(ms) Usage Rejected Above Below S0 39319 626 14 307 0 Signed-off-by: Maulik Shah <[email protected]> Fixes: e949996 ("PM / Domains: Add genpd governor for CPUs") Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ulf Hansson <[email protected]>
1 parent e04c78d commit 500ba33

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

drivers/pmdomain/governor.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/pm_domain.h>
99
#include <linux/pm_qos.h>
1010
#include <linux/hrtimer.h>
11+
#include <linux/cpu.h>
1112
#include <linux/cpuidle.h>
1213
#include <linux/cpumask.h>
1314
#include <linux/ktime.h>
@@ -349,6 +350,8 @@ static bool cpu_power_down_ok(struct dev_pm_domain *pd)
349350
struct cpuidle_device *dev;
350351
ktime_t domain_wakeup, next_hrtimer;
351352
ktime_t now = ktime_get();
353+
struct device *cpu_dev;
354+
s64 cpu_constraint, global_constraint;
352355
s64 idle_duration_ns;
353356
int cpu, i;
354357

@@ -359,6 +362,7 @@ static bool cpu_power_down_ok(struct dev_pm_domain *pd)
359362
if (!(genpd->flags & GENPD_FLAG_CPU_DOMAIN))
360363
return true;
361364

365+
global_constraint = cpu_latency_qos_limit();
362366
/*
363367
* Find the next wakeup for any of the online CPUs within the PM domain
364368
* and its subdomains. Note, we only need the genpd->cpus, as it already
@@ -372,8 +376,16 @@ static bool cpu_power_down_ok(struct dev_pm_domain *pd)
372376
if (ktime_before(next_hrtimer, domain_wakeup))
373377
domain_wakeup = next_hrtimer;
374378
}
379+
380+
cpu_dev = get_cpu_device(cpu);
381+
if (cpu_dev) {
382+
cpu_constraint = dev_pm_qos_raw_resume_latency(cpu_dev);
383+
if (cpu_constraint < global_constraint)
384+
global_constraint = cpu_constraint;
385+
}
375386
}
376387

388+
global_constraint *= NSEC_PER_USEC;
377389
/* The minimum idle duration is from now - until the next wakeup. */
378390
idle_duration_ns = ktime_to_ns(ktime_sub(domain_wakeup, now));
379391
if (idle_duration_ns <= 0)
@@ -389,8 +401,10 @@ static bool cpu_power_down_ok(struct dev_pm_domain *pd)
389401
*/
390402
i = genpd->state_idx;
391403
do {
392-
if (idle_duration_ns >= (genpd->states[i].residency_ns +
393-
genpd->states[i].power_off_latency_ns)) {
404+
if ((idle_duration_ns >= (genpd->states[i].residency_ns +
405+
genpd->states[i].power_off_latency_ns)) &&
406+
(global_constraint >= (genpd->states[i].power_on_latency_ns +
407+
genpd->states[i].power_off_latency_ns))) {
394408
genpd->state_idx = i;
395409
genpd->gd->last_enter = now;
396410
genpd->gd->reflect_residency = true;

0 commit comments

Comments
 (0)