Skip to content

Commit afece3a

Browse files
tharagopinathrafaeljw
authored andcommitted
PM / Domains: Add time accounting to various genpd states
This patch adds support to calculate the time spent by the generic power domains in on and various idle states. Signed-off-by: Thara Gopinath <[email protected]> Acked-by: Ulf Hansson <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 520eccd commit afece3a

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

drivers/base/power/domain.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,34 @@ static void genpd_sd_counter_inc(struct generic_pm_domain *genpd)
209209
smp_mb__after_atomic();
210210
}
211211

212+
#ifdef CONFIG_DEBUG_FS
213+
static void genpd_update_accounting(struct generic_pm_domain *genpd)
214+
{
215+
ktime_t delta, now;
216+
217+
now = ktime_get();
218+
delta = ktime_sub(now, genpd->accounting_time);
219+
220+
/*
221+
* If genpd->status is active, it means we are just
222+
* out of off and so update the idle time and vice
223+
* versa.
224+
*/
225+
if (genpd->status == GPD_STATE_ACTIVE) {
226+
int state_idx = genpd->state_idx;
227+
228+
genpd->states[state_idx].idle_time =
229+
ktime_add(genpd->states[state_idx].idle_time, delta);
230+
} else {
231+
genpd->on_time = ktime_add(genpd->on_time, delta);
232+
}
233+
234+
genpd->accounting_time = now;
235+
}
236+
#else
237+
static inline void genpd_update_accounting(struct generic_pm_domain *genpd) {}
238+
#endif
239+
212240
static int _genpd_power_on(struct generic_pm_domain *genpd, bool timed)
213241
{
214242
unsigned int state_idx = genpd->state_idx;
@@ -361,6 +389,7 @@ static int genpd_power_off(struct generic_pm_domain *genpd, bool one_dev_on,
361389
}
362390

363391
genpd->status = GPD_STATE_POWER_OFF;
392+
genpd_update_accounting(genpd);
364393

365394
list_for_each_entry(link, &genpd->slave_links, slave_node) {
366395
genpd_sd_counter_dec(link->master);
@@ -413,6 +442,8 @@ static int genpd_power_on(struct generic_pm_domain *genpd, unsigned int depth)
413442
goto err;
414443

415444
genpd->status = GPD_STATE_ACTIVE;
445+
genpd_update_accounting(genpd);
446+
416447
return 0;
417448

418449
err:
@@ -1540,6 +1571,7 @@ int pm_genpd_init(struct generic_pm_domain *genpd,
15401571
genpd->max_off_time_changed = true;
15411572
genpd->provider = NULL;
15421573
genpd->has_provider = false;
1574+
genpd->accounting_time = ktime_get();
15431575
genpd->domain.ops.runtime_suspend = genpd_runtime_suspend;
15441576
genpd->domain.ops.runtime_resume = genpd_runtime_resume;
15451577
genpd->domain.ops.prepare = pm_genpd_prepare;

include/linux/pm_domain.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ struct genpd_power_state {
4343
s64 power_on_latency_ns;
4444
s64 residency_ns;
4545
struct fwnode_handle *fwnode;
46+
ktime_t idle_time;
4647
};
4748

4849
struct genpd_lock_ops;
@@ -78,6 +79,8 @@ struct generic_pm_domain {
7879
unsigned int state_count; /* number of states */
7980
unsigned int state_idx; /* state that genpd will go to when off */
8081
void *free; /* Free the state that was allocated for default */
82+
ktime_t on_time;
83+
ktime_t accounting_time;
8184
const struct genpd_lock_ops *lock_ops;
8285
union {
8386
struct mutex mlock;

0 commit comments

Comments
 (0)