Commit bd40cbb0 authored by Ulf Hansson's avatar Ulf Hansson Committed by Rafael J. Wysocki

PM: domains: Move genpd's time-accounting to ktime_get_mono_fast_ns()

To move towards a more consistent behaviour between genpd and the runtime
PM core, let's start by converting genpd's time-accounting from ktime_get()
into ktime_get_mono_fast_ns().
Signed-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent eefa8618
...@@ -225,24 +225,23 @@ static void genpd_debug_remove(struct generic_pm_domain *genpd) ...@@ -225,24 +225,23 @@ static void genpd_debug_remove(struct generic_pm_domain *genpd)
static void genpd_update_accounting(struct generic_pm_domain *genpd) static void genpd_update_accounting(struct generic_pm_domain *genpd)
{ {
ktime_t delta, now; u64 delta, now;
now = ktime_get(); now = ktime_get_mono_fast_ns();
delta = ktime_sub(now, genpd->accounting_time); if (now <= genpd->accounting_time)
return;
delta = now - genpd->accounting_time;
/* /*
* If genpd->status is active, it means we are just * If genpd->status is active, it means we are just
* out of off and so update the idle time and vice * out of off and so update the idle time and vice
* versa. * versa.
*/ */
if (genpd->status == GENPD_STATE_ON) { if (genpd->status == GENPD_STATE_ON)
int state_idx = genpd->state_idx; genpd->states[genpd->state_idx].idle_time += delta;
else
genpd->states[state_idx].idle_time = genpd->on_time += delta;
ktime_add(genpd->states[state_idx].idle_time, delta);
} else {
genpd->on_time = ktime_add(genpd->on_time, delta);
}
genpd->accounting_time = now; genpd->accounting_time = now;
} }
...@@ -1999,7 +1998,7 @@ int pm_genpd_init(struct generic_pm_domain *genpd, ...@@ -1999,7 +1998,7 @@ int pm_genpd_init(struct generic_pm_domain *genpd,
genpd->max_off_time_changed = true; genpd->max_off_time_changed = true;
genpd->provider = NULL; genpd->provider = NULL;
genpd->has_provider = false; genpd->has_provider = false;
genpd->accounting_time = ktime_get(); genpd->accounting_time = ktime_get_mono_fast_ns();
genpd->domain.ops.runtime_suspend = genpd_runtime_suspend; genpd->domain.ops.runtime_suspend = genpd_runtime_suspend;
genpd->domain.ops.runtime_resume = genpd_runtime_resume; genpd->domain.ops.runtime_resume = genpd_runtime_resume;
genpd->domain.ops.prepare = genpd_prepare; genpd->domain.ops.prepare = genpd_prepare;
...@@ -3163,6 +3162,7 @@ static int sub_domains_show(struct seq_file *s, void *data) ...@@ -3163,6 +3162,7 @@ static int sub_domains_show(struct seq_file *s, void *data)
static int idle_states_show(struct seq_file *s, void *data) static int idle_states_show(struct seq_file *s, void *data)
{ {
struct generic_pm_domain *genpd = s->private; struct generic_pm_domain *genpd = s->private;
u64 now, delta, idle_time = 0;
unsigned int i; unsigned int i;
int ret = 0; int ret = 0;
...@@ -3173,17 +3173,19 @@ static int idle_states_show(struct seq_file *s, void *data) ...@@ -3173,17 +3173,19 @@ static int idle_states_show(struct seq_file *s, void *data)
seq_puts(s, "State Time Spent(ms) Usage Rejected\n"); seq_puts(s, "State Time Spent(ms) Usage Rejected\n");
for (i = 0; i < genpd->state_count; i++) { for (i = 0; i < genpd->state_count; i++) {
ktime_t delta = 0; idle_time += genpd->states[i].idle_time;
s64 msecs;
if ((genpd->status == GENPD_STATE_OFF) && if (genpd->status == GENPD_STATE_OFF && genpd->state_idx == i) {
(genpd->state_idx == i)) now = ktime_get_mono_fast_ns();
delta = ktime_sub(ktime_get(), genpd->accounting_time); if (now > genpd->accounting_time) {
delta = now - genpd->accounting_time;
idle_time += delta;
}
}
msecs = ktime_to_ms( do_div(idle_time, NSEC_PER_MSEC);
ktime_add(genpd->states[i].idle_time, delta)); seq_printf(s, "S%-13i %-14llu %-14llu %llu\n", i, idle_time,
seq_printf(s, "S%-13i %-14lld %-14llu %llu\n", i, msecs, genpd->states[i].usage, genpd->states[i].rejected);
genpd->states[i].usage, genpd->states[i].rejected);
} }
genpd_unlock(genpd); genpd_unlock(genpd);
...@@ -3193,18 +3195,22 @@ static int idle_states_show(struct seq_file *s, void *data) ...@@ -3193,18 +3195,22 @@ static int idle_states_show(struct seq_file *s, void *data)
static int active_time_show(struct seq_file *s, void *data) static int active_time_show(struct seq_file *s, void *data)
{ {
struct generic_pm_domain *genpd = s->private; struct generic_pm_domain *genpd = s->private;
ktime_t delta = 0; u64 now, on_time, delta = 0;
int ret = 0; int ret = 0;
ret = genpd_lock_interruptible(genpd); ret = genpd_lock_interruptible(genpd);
if (ret) if (ret)
return -ERESTARTSYS; return -ERESTARTSYS;
if (genpd->status == GENPD_STATE_ON) if (genpd->status == GENPD_STATE_ON) {
delta = ktime_sub(ktime_get(), genpd->accounting_time); now = ktime_get_mono_fast_ns();
if (now > genpd->accounting_time)
delta = now - genpd->accounting_time;
}
seq_printf(s, "%lld ms\n", ktime_to_ms( on_time = genpd->on_time + delta;
ktime_add(genpd->on_time, delta))); do_div(on_time, NSEC_PER_MSEC);
seq_printf(s, "%llu ms\n", on_time);
genpd_unlock(genpd); genpd_unlock(genpd);
return ret; return ret;
...@@ -3213,7 +3219,7 @@ static int active_time_show(struct seq_file *s, void *data) ...@@ -3213,7 +3219,7 @@ static int active_time_show(struct seq_file *s, void *data)
static int total_idle_time_show(struct seq_file *s, void *data) static int total_idle_time_show(struct seq_file *s, void *data)
{ {
struct generic_pm_domain *genpd = s->private; struct generic_pm_domain *genpd = s->private;
ktime_t delta = 0, total = 0; u64 now, delta, total = 0;
unsigned int i; unsigned int i;
int ret = 0; int ret = 0;
...@@ -3222,16 +3228,19 @@ static int total_idle_time_show(struct seq_file *s, void *data) ...@@ -3222,16 +3228,19 @@ static int total_idle_time_show(struct seq_file *s, void *data)
return -ERESTARTSYS; return -ERESTARTSYS;
for (i = 0; i < genpd->state_count; i++) { for (i = 0; i < genpd->state_count; i++) {
total += genpd->states[i].idle_time;
if ((genpd->status == GENPD_STATE_OFF) && if (genpd->status == GENPD_STATE_OFF && genpd->state_idx == i) {
(genpd->state_idx == i)) now = ktime_get_mono_fast_ns();
delta = ktime_sub(ktime_get(), genpd->accounting_time); if (now > genpd->accounting_time) {
delta = now - genpd->accounting_time;
total = ktime_add(total, genpd->states[i].idle_time); total += delta;
}
}
} }
total = ktime_add(total, delta);
seq_printf(s, "%lld ms\n", ktime_to_ms(total)); do_div(total, NSEC_PER_MSEC);
seq_printf(s, "%llu ms\n", total);
genpd_unlock(genpd); genpd_unlock(genpd);
return ret; return ret;
......
...@@ -98,7 +98,7 @@ struct genpd_power_state { ...@@ -98,7 +98,7 @@ struct genpd_power_state {
u64 usage; u64 usage;
u64 rejected; u64 rejected;
struct fwnode_handle *fwnode; struct fwnode_handle *fwnode;
ktime_t idle_time; u64 idle_time;
void *data; void *data;
}; };
...@@ -149,8 +149,8 @@ struct generic_pm_domain { ...@@ -149,8 +149,8 @@ struct generic_pm_domain {
unsigned int state_count); unsigned int state_count);
unsigned int state_count; /* number of states */ unsigned int state_count; /* number of states */
unsigned int state_idx; /* state that genpd will go to when off */ unsigned int state_idx; /* state that genpd will go to when off */
ktime_t on_time; u64 on_time;
ktime_t accounting_time; u64 accounting_time;
const struct genpd_lock_ops *lock_ops; const struct genpd_lock_ops *lock_ops;
union { union {
struct mutex mlock; struct mutex mlock;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment