cpufreq: stats: Defer stats update to cpufreq_stats_record_transition()
authorViresh Kumar <viresh.kumar@linaro.org>
Mon, 5 Oct 2020 07:56:01 +0000 (13:26 +0530)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Mon, 5 Oct 2020 13:13:42 +0000 (15:13 +0200)
commit40c3bd4cfa6fe5756344709b98611a1ddd15bf9d
tree7d305f553fa8340a32e691338a63fda41b3ccffe
parentfccd2f0e629b357437bebc015810f7f1957a4643
cpufreq: stats: Defer stats update to cpufreq_stats_record_transition()

In order to prepare for lock-less stats update, add support to defer any
updates to it until cpufreq_stats_record_transition() is called.

The stats were updated from two places earlier:

- show_time_in_state(): This can be easily deferred, all we need is to
  calculate the delta duration again in this routine to show the current
  state's time-in-state.

- store_reset(): This is a bit tricky as we need to clear the stats
  here and avoid races with simultaneous call to
  cpufreq_stats_record_transition().

Fix that by deferring the reset of the stats (within the code) to the
next call to cpufreq_stats_record_transition(), but since we need to
keep showing the right stats until that time, we capture the reset
time and account for the time since last time reset was called until
the time cpufreq_stats_record_transition() update the stats.

User space will continue seeing the stats correctly, everything will
be 0 after the stats are reset, apart from the time-in-state of the
current state, until the time a frequency switch happens.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
[ rjw: Minor changelog edits ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/cpufreq/cpufreq_stats.c