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.
57 struct gpd_timing_data *td = dev_gpd_data(dev)->td; in default_suspend_ok()
63 spin_lock_irqsave(&dev->power.lock, flags); in default_suspend_ok()
65 if (!td->constraint_changed) { in default_suspend_ok()
66 bool ret = td->cached_suspend_ok; in default_suspend_ok()
68 spin_unlock_irqrestore(&dev->power.lock, flags); in default_suspend_ok()
71 td->constraint_changed = false; in default_suspend_ok()
72 td->cached_suspend_ok = false; in default_suspend_ok()
73 td->effective_constraint_ns = 0; in default_suspend_ok()
76 spin_unlock_irqrestore(&dev->power.lock, flags); in default_suspend_ok()
87 if (!dev->power.ignore_children) in default_suspend_ok()
93 td->effective_constraint_ns = PM_QOS_RESUME_LATENCY_NO_CONSTRAINT_NS; in default_suspend_ok()
94 td->cached_suspend_ok = true; in default_suspend_ok()
98 * domain has a zero PM QoS constraint and it's better not to in default_suspend_ok()
104 constraint_ns -= td->suspend_latency_ns + in default_suspend_ok()
105 td->resume_latency_ns; in default_suspend_ok()
114 td->effective_constraint_ns = constraint_ns; in default_suspend_ok()
115 td->cached_suspend_ok = true; in default_suspend_ok()
122 return td->cached_suspend_ok; in default_suspend_ok()
132 if (!(genpd->flags & GENPD_FLAG_MIN_RESIDENCY)) in update_domain_next_wakeup()
138 * devices attached to this domain and from all the sub-domains. in update_domain_next_wakeup()
140 * stale when we read that here. We will ignore to ensure the domain in update_domain_next_wakeup()
141 * is able to enter its optimal idle state. in update_domain_next_wakeup()
143 list_for_each_entry(pdd, &genpd->dev_list, list_node) { in update_domain_next_wakeup()
144 next_wakeup = to_gpd_data(pdd)->td->next_wakeup; in update_domain_next_wakeup()
150 list_for_each_entry(link, &genpd->parent_links, parent_node) { in update_domain_next_wakeup()
151 struct genpd_governor_data *cgd = link->child->gd; in update_domain_next_wakeup()
153 next_wakeup = cgd ? cgd->next_wakeup : KTIME_MAX; in update_domain_next_wakeup()
159 genpd->gd->next_wakeup = domain_wakeup; in update_domain_next_wakeup()
165 ktime_t domain_wakeup = genpd->gd->next_wakeup; in next_wakeup_allows_state()
168 min_sleep_ns = genpd->states[state].power_off_latency_ns + in next_wakeup_allows_state()
169 genpd->states[state].residency_ns; in next_wakeup_allows_state()
185 off_on_time_ns = genpd->states[state].power_off_latency_ns + in __default_power_down_ok()
186 genpd->states[state].power_on_latency_ns; in __default_power_down_ok()
188 min_off_time_ns = -1; in __default_power_down_ok()
194 list_for_each_entry(link, &genpd->parent_links, parent_node) { in __default_power_down_ok()
195 struct genpd_governor_data *cgd = link->child->gd; in __default_power_down_ok()
197 s64 sd_max_off_ns = cgd ? cgd->max_off_time_ns : -1; in __default_power_down_ok()
204 * the current domain to turn off and on (that's how much time in __default_power_down_ok()
215 * Check if the devices in the domain can be off enough time. in __default_power_down_ok()
217 list_for_each_entry(pdd, &genpd->dev_list, list_node) { in __default_power_down_ok()
223 * domain to turn off and on (that's how much time it will in __default_power_down_ok()
226 td = to_gpd_data(pdd)->td; in __default_power_down_ok()
227 constraint_ns = td->effective_constraint_ns; in __default_power_down_ok()
230 * devices in the domain are suspended, so it must be positive. in __default_power_down_ok()
244 * latency constraints, so the domain can spend arbitrary time in the in __default_power_down_ok()
252 * time and the time needed to turn the domain on is the maximum in __default_power_down_ok()
253 * theoretical time this domain can spend in the "off" state. in __default_power_down_ok()
255 genpd->gd->max_off_time_ns = min_off_time_ns - in __default_power_down_ok()
256 genpd->states[state].power_on_latency_ns; in __default_power_down_ok()
261 * _default_power_down_ok - Default generic PM domain power off governor routine.
262 * @pd: PM domain to check.
265 * This routine must be executed under the PM domain's lock.
272 struct genpd_governor_data *gd = genpd->gd; in _default_power_down_ok()
273 int state_idx = genpd->state_count - 1; in _default_power_down_ok()
278 * to find when the domain would wakeup and do it for every device down in _default_power_down_ok()
283 if ((genpd->flags & GENPD_FLAG_MIN_RESIDENCY) && (gd->next_wakeup != KTIME_MAX)) { in _default_power_down_ok()
284 /* Let's find out the deepest domain idle state, the devices prefer */ in _default_power_down_ok()
287 gd->max_off_time_changed = true; in _default_power_down_ok()
290 state_idx--; in _default_power_down_ok()
295 gd->cached_power_down_ok = false; in _default_power_down_ok()
300 if (!gd->max_off_time_changed) { in _default_power_down_ok()
301 genpd->state_idx = gd->cached_power_down_state_idx; in _default_power_down_ok()
302 return gd->cached_power_down_ok; in _default_power_down_ok()
311 list_for_each_entry(link, &genpd->child_links, child_node) { in _default_power_down_ok()
312 struct genpd_governor_data *pgd = link->parent->gd; in _default_power_down_ok()
315 pgd->max_off_time_changed = true; in _default_power_down_ok()
318 gd->max_off_time_ns = -1; in _default_power_down_ok()
319 gd->max_off_time_changed = false; in _default_power_down_ok()
320 gd->cached_power_down_ok = true; in _default_power_down_ok()
328 gd->cached_power_down_ok = false; in _default_power_down_ok()
331 state_idx--; in _default_power_down_ok()
335 genpd->state_idx = state_idx; in _default_power_down_ok()
336 gd->cached_power_down_state_idx = genpd->state_idx; in _default_power_down_ok()
337 return gd->cached_power_down_ok; in _default_power_down_ok()
359 if (!(genpd->flags & GENPD_FLAG_CPU_DOMAIN)) in cpu_power_down_ok()
363 * Find the next wakeup for any of the online CPUs within the PM domain in cpu_power_down_ok()
364 * and its subdomains. Note, we only need the genpd->cpus, as it already in cpu_power_down_ok()
368 for_each_cpu_and(cpu, genpd->cpus, cpu_online_mask) { in cpu_power_down_ok()
371 next_hrtimer = READ_ONCE(dev->next_hrtimer); in cpu_power_down_ok()
377 /* The minimum idle duration is from now - until the next wakeup. */ in cpu_power_down_ok()
383 genpd->gd->next_hrtimer = domain_wakeup; in cpu_power_down_ok()
386 * Find the deepest idle state that has its residency value satisfied in cpu_power_down_ok()
390 i = genpd->state_idx; in cpu_power_down_ok()
392 if (idle_duration_ns >= (genpd->states[i].residency_ns + in cpu_power_down_ok()
393 genpd->states[i].power_off_latency_ns)) { in cpu_power_down_ok()
394 genpd->state_idx = i; in cpu_power_down_ok()
397 } while (--i >= 0); in cpu_power_down_ok()
414 * pm_domain_always_on_gov - A governor implementing an always-on policy