diff mbox series

[V2] cpufreq: stats: Use local_clock() instead of jiffies

Message ID d6d9193249832c54fdd29656558f48914a4015dd.1605612661.git.viresh.kumar@linaro.org
State Accepted
Commit 7854c7520b86f0c14f7fcfea6fd1785617844341
Headers show
Series [V2] cpufreq: stats: Use local_clock() instead of jiffies | expand

Commit Message

Viresh Kumar Nov. 17, 2020, 11:32 a.m. UTC
local_clock() has better precision and accuracy as compared to jiffies,
lets use it for time management in cpufreq stats.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>

---
V2:
- Doesn't change the units to msec and use local_clock() instead of
  ktime.

 drivers/cpufreq/cpufreq_stats.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

-- 
2.25.0.rc1.19.g042ed3e048af

Comments

Rafael J. Wysocki Nov. 17, 2020, 4:59 p.m. UTC | #1
On Tue, Nov 17, 2020 at 12:32 PM Viresh Kumar <viresh.kumar@linaro.org> wrote:
>

> local_clock() has better precision and accuracy as compared to jiffies,

> lets use it for time management in cpufreq stats.

>

> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>

> ---

> V2:

> - Doesn't change the units to msec and use local_clock() instead of

>   ktime.

>

>  drivers/cpufreq/cpufreq_stats.c | 16 ++++++++--------

>  1 file changed, 8 insertions(+), 8 deletions(-)

>

> diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c

> index 6cd5c8ab5d49..da717f7cd9a9 100644

> --- a/drivers/cpufreq/cpufreq_stats.c

> +++ b/drivers/cpufreq/cpufreq_stats.c

> @@ -9,9 +9,9 @@

>  #include <linux/cpu.h>

>  #include <linux/cpufreq.h>

>  #include <linux/module.h>

> +#include <linux/sched/clock.h>

>  #include <linux/slab.h>

>

> -

>  struct cpufreq_stats {

>         unsigned int total_trans;

>         unsigned long long last_time;

> @@ -30,7 +30,7 @@ struct cpufreq_stats {

>  static void cpufreq_stats_update(struct cpufreq_stats *stats,

>                                  unsigned long long time)

>  {

> -       unsigned long long cur_time = get_jiffies_64();

> +       unsigned long long cur_time = local_clock();

>

>         stats->time_in_state[stats->last_index] += cur_time - time;

>         stats->last_time = cur_time;

> @@ -42,7 +42,7 @@ static void cpufreq_stats_reset_table(struct cpufreq_stats *stats)

>

>         memset(stats->time_in_state, 0, count * sizeof(u64));

>         memset(stats->trans_table, 0, count * count * sizeof(int));

> -       stats->last_time = get_jiffies_64();

> +       stats->last_time = local_clock();

>         stats->total_trans = 0;

>

>         /* Adjust for the time elapsed since reset was requested */

> @@ -82,18 +82,18 @@ static ssize_t show_time_in_state(struct cpufreq_policy *policy, char *buf)

>                                  * before the reset_pending read above.

>                                  */

>                                 smp_rmb();

> -                               time = get_jiffies_64() - READ_ONCE(stats->reset_time);

> +                               time = local_clock() - READ_ONCE(stats->reset_time);

>                         } else {

>                                 time = 0;

>                         }

>                 } else {

>                         time = stats->time_in_state[i];

>                         if (i == stats->last_index)

> -                               time += get_jiffies_64() - stats->last_time;

> +                               time += local_clock() - stats->last_time;

>                 }

>

>                 len += sprintf(buf + len, "%u %llu\n", stats->freq_table[i],

> -                              jiffies_64_to_clock_t(time));

> +                              nsec_to_clock_t(time));

>         }

>         return len;

>  }

> @@ -109,7 +109,7 @@ static ssize_t store_reset(struct cpufreq_policy *policy, const char *buf,

>          * Defer resetting of stats to cpufreq_stats_record_transition() to

>          * avoid races.

>          */

> -       WRITE_ONCE(stats->reset_time, get_jiffies_64());

> +       WRITE_ONCE(stats->reset_time, local_clock());

>         /*

>          * The memory barrier below is to prevent the readers of reset_time from

>          * seeing a stale or partially updated value.

> @@ -249,7 +249,7 @@ void cpufreq_stats_create_table(struct cpufreq_policy *policy)

>                         stats->freq_table[i++] = pos->frequency;

>

>         stats->state_num = i;

> -       stats->last_time = get_jiffies_64();

> +       stats->last_time = local_clock();

>         stats->last_index = freq_table_get_index(stats, policy->cur);

>

>         policy->stats = stats;

> --


Applied as 5.11 material, thanks!
diff mbox series

Patch

diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
index 6cd5c8ab5d49..da717f7cd9a9 100644
--- a/drivers/cpufreq/cpufreq_stats.c
+++ b/drivers/cpufreq/cpufreq_stats.c
@@ -9,9 +9,9 @@ 
 #include <linux/cpu.h>
 #include <linux/cpufreq.h>
 #include <linux/module.h>
+#include <linux/sched/clock.h>
 #include <linux/slab.h>
 
-
 struct cpufreq_stats {
 	unsigned int total_trans;
 	unsigned long long last_time;
@@ -30,7 +30,7 @@  struct cpufreq_stats {
 static void cpufreq_stats_update(struct cpufreq_stats *stats,
 				 unsigned long long time)
 {
-	unsigned long long cur_time = get_jiffies_64();
+	unsigned long long cur_time = local_clock();
 
 	stats->time_in_state[stats->last_index] += cur_time - time;
 	stats->last_time = cur_time;
@@ -42,7 +42,7 @@  static void cpufreq_stats_reset_table(struct cpufreq_stats *stats)
 
 	memset(stats->time_in_state, 0, count * sizeof(u64));
 	memset(stats->trans_table, 0, count * count * sizeof(int));
-	stats->last_time = get_jiffies_64();
+	stats->last_time = local_clock();
 	stats->total_trans = 0;
 
 	/* Adjust for the time elapsed since reset was requested */
@@ -82,18 +82,18 @@  static ssize_t show_time_in_state(struct cpufreq_policy *policy, char *buf)
 				 * before the reset_pending read above.
 				 */
 				smp_rmb();
-				time = get_jiffies_64() - READ_ONCE(stats->reset_time);
+				time = local_clock() - READ_ONCE(stats->reset_time);
 			} else {
 				time = 0;
 			}
 		} else {
 			time = stats->time_in_state[i];
 			if (i == stats->last_index)
-				time += get_jiffies_64() - stats->last_time;
+				time += local_clock() - stats->last_time;
 		}
 
 		len += sprintf(buf + len, "%u %llu\n", stats->freq_table[i],
-			       jiffies_64_to_clock_t(time));
+			       nsec_to_clock_t(time));
 	}
 	return len;
 }
@@ -109,7 +109,7 @@  static ssize_t store_reset(struct cpufreq_policy *policy, const char *buf,
 	 * Defer resetting of stats to cpufreq_stats_record_transition() to
 	 * avoid races.
 	 */
-	WRITE_ONCE(stats->reset_time, get_jiffies_64());
+	WRITE_ONCE(stats->reset_time, local_clock());
 	/*
 	 * The memory barrier below is to prevent the readers of reset_time from
 	 * seeing a stale or partially updated value.
@@ -249,7 +249,7 @@  void cpufreq_stats_create_table(struct cpufreq_policy *policy)
 			stats->freq_table[i++] = pos->frequency;
 
 	stats->state_num = i;
-	stats->last_time = get_jiffies_64();
+	stats->last_time = local_clock();
 	stats->last_index = freq_table_get_index(stats, policy->cur);
 
 	policy->stats = stats;