Lines Matching +full:domain +full:- +full:idle +full:- +full:states
1 // SPDX-License-Identifier: GPL-2.0
3 * drivers/base/power/domain_governor.c - Governors for device PM domains.
20 if (dev->power.subsys_data && dev->power.subsys_data->domain_data) { in dev_update_qos_constraint()
21 struct gpd_timing_data *td = dev_gpd_data(dev)->td; in dev_update_qos_constraint()
24 * Only take suspend-time QoS constraints of devices into in dev_update_qos_constraint()
30 constraint_ns = td ? td->effective_constraint_ns : in dev_update_qos_constraint()
34 * The child is not in a domain and there's no info on its in dev_update_qos_constraint()
50 * default_suspend_ok - Default PM domain governor routine to suspend devices.
55 struct gpd_timing_data *td = dev_gpd_data(dev)->td; in default_suspend_ok()
61 spin_lock_irqsave(&dev->power.lock, flags); in default_suspend_ok()
63 if (!td->constraint_changed) { in default_suspend_ok()
64 bool ret = td->cached_suspend_ok; in default_suspend_ok()
66 spin_unlock_irqrestore(&dev->power.lock, flags); in default_suspend_ok()
69 td->constraint_changed = false; in default_suspend_ok()
70 td->cached_suspend_ok = false; in default_suspend_ok()
71 td->effective_constraint_ns = 0; in default_suspend_ok()
74 spin_unlock_irqrestore(&dev->power.lock, flags); in default_suspend_ok()
85 if (!dev->power.ignore_children) in default_suspend_ok()
91 td->effective_constraint_ns = PM_QOS_RESUME_LATENCY_NO_CONSTRAINT_NS; in default_suspend_ok()
92 td->cached_suspend_ok = true; in default_suspend_ok()
96 * domain has a zero PM QoS constraint and it's better not to in default_suspend_ok()
102 constraint_ns -= td->suspend_latency_ns + in default_suspend_ok()
103 td->resume_latency_ns; in default_suspend_ok()
112 td->effective_constraint_ns = constraint_ns; in default_suspend_ok()
113 td->cached_suspend_ok = true; in default_suspend_ok()
120 return td->cached_suspend_ok; in default_suspend_ok()
130 if (!(genpd->flags & GENPD_FLAG_MIN_RESIDENCY)) in update_domain_next_wakeup()
136 * devices attached to this domain and from all the sub-domains. in update_domain_next_wakeup()
138 * stale when we read that here. We will ignore to ensure the domain in update_domain_next_wakeup()
139 * is able to enter its optimal idle state. in update_domain_next_wakeup()
141 list_for_each_entry(pdd, &genpd->dev_list, list_node) { in update_domain_next_wakeup()
142 next_wakeup = to_gpd_data(pdd)->td->next_wakeup; in update_domain_next_wakeup()
148 list_for_each_entry(link, &genpd->parent_links, parent_node) { in update_domain_next_wakeup()
149 struct genpd_governor_data *cgd = link->child->gd; in update_domain_next_wakeup()
151 next_wakeup = cgd ? cgd->next_wakeup : KTIME_MAX; in update_domain_next_wakeup()
157 genpd->gd->next_wakeup = domain_wakeup; in update_domain_next_wakeup()
163 ktime_t domain_wakeup = genpd->gd->next_wakeup; in next_wakeup_allows_state()
166 min_sleep_ns = genpd->states[state].power_off_latency_ns + in next_wakeup_allows_state()
167 genpd->states[state].residency_ns; in next_wakeup_allows_state()
183 off_on_time_ns = genpd->states[state].power_off_latency_ns + in __default_power_down_ok()
184 genpd->states[state].power_on_latency_ns; in __default_power_down_ok()
186 min_off_time_ns = -1; in __default_power_down_ok()
192 list_for_each_entry(link, &genpd->parent_links, parent_node) { in __default_power_down_ok()
193 struct genpd_governor_data *cgd = link->child->gd; in __default_power_down_ok()
195 s64 sd_max_off_ns = cgd ? cgd->max_off_time_ns : -1; in __default_power_down_ok()
202 * the current domain to turn off and on (that's how much time in __default_power_down_ok()
213 * Check if the devices in the domain can be off enough time. in __default_power_down_ok()
215 list_for_each_entry(pdd, &genpd->dev_list, list_node) { in __default_power_down_ok()
221 * domain to turn off and on (that's how much time it will in __default_power_down_ok()
224 td = to_gpd_data(pdd)->td; in __default_power_down_ok()
225 constraint_ns = td->effective_constraint_ns; in __default_power_down_ok()
228 * devices in the domain are suspended, so it must be positive. in __default_power_down_ok()
242 * latency constraints, so the domain can spend arbitrary time in the in __default_power_down_ok()
250 * time and the time needed to turn the domain on is the maximum in __default_power_down_ok()
251 * theoretical time this domain can spend in the "off" state. in __default_power_down_ok()
253 genpd->gd->max_off_time_ns = min_off_time_ns - in __default_power_down_ok()
254 genpd->states[state].power_on_latency_ns; in __default_power_down_ok()
259 * _default_power_down_ok - Default generic PM domain power off governor routine.
260 * @pd: PM domain to check.
263 * This routine must be executed under the PM domain's lock.
268 struct genpd_governor_data *gd = genpd->gd; in _default_power_down_ok()
269 int state_idx = genpd->state_count - 1; in _default_power_down_ok()
274 * to find when the domain would wakeup and do it for every device down in _default_power_down_ok()
279 if ((genpd->flags & GENPD_FLAG_MIN_RESIDENCY) && (gd->next_wakeup != KTIME_MAX)) { in _default_power_down_ok()
280 /* Let's find out the deepest domain idle state, the devices prefer */ in _default_power_down_ok()
283 gd->max_off_time_changed = true; in _default_power_down_ok()
286 state_idx--; in _default_power_down_ok()
291 gd->cached_power_down_ok = false; in _default_power_down_ok()
296 if (!gd->max_off_time_changed) { in _default_power_down_ok()
297 genpd->state_idx = gd->cached_power_down_state_idx; in _default_power_down_ok()
298 return gd->cached_power_down_ok; in _default_power_down_ok()
307 list_for_each_entry(link, &genpd->child_links, child_node) { in _default_power_down_ok()
308 struct genpd_governor_data *pgd = link->parent->gd; in _default_power_down_ok()
311 pgd->max_off_time_changed = true; in _default_power_down_ok()
314 gd->max_off_time_ns = -1; in _default_power_down_ok()
315 gd->max_off_time_changed = false; in _default_power_down_ok()
316 gd->cached_power_down_ok = true; in _default_power_down_ok()
324 gd->cached_power_down_ok = false; in _default_power_down_ok()
327 state_idx--; in _default_power_down_ok()
331 genpd->state_idx = state_idx; in _default_power_down_ok()
332 gd->cached_power_down_state_idx = genpd->state_idx; in _default_power_down_ok()
333 return gd->cached_power_down_ok; in _default_power_down_ok()
355 if (!(genpd->flags & GENPD_FLAG_CPU_DOMAIN)) in cpu_power_down_ok()
359 * Find the next wakeup for any of the online CPUs within the PM domain in cpu_power_down_ok()
360 * and its subdomains. Note, we only need the genpd->cpus, as it already in cpu_power_down_ok()
364 for_each_cpu_and(cpu, genpd->cpus, cpu_online_mask) { in cpu_power_down_ok()
367 next_hrtimer = READ_ONCE(dev->next_hrtimer); in cpu_power_down_ok()
373 /* The minimum idle duration is from now - until the next wakeup. */ in cpu_power_down_ok()
379 genpd->gd->next_hrtimer = domain_wakeup; in cpu_power_down_ok()
382 * Find the deepest idle state that has its residency value satisfied in cpu_power_down_ok()
386 i = genpd->state_idx; in cpu_power_down_ok()
388 if (idle_duration_ns >= (genpd->states[i].residency_ns + in cpu_power_down_ok()
389 genpd->states[i].power_off_latency_ns)) { in cpu_power_down_ok()
390 genpd->state_idx = i; in cpu_power_down_ok()
393 } while (--i >= 0); in cpu_power_down_ok()
410 * pm_genpd_gov_always_on - A governor implementing an always-on policy