Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

cpufreq: stats: Use local_clock() instead of jiffies

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>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

authored by

Viresh Kumar and committed by
Rafael J. Wysocki
7854c752 90ac908a

+8 -8
+8 -8
drivers/cpufreq/cpufreq_stats.c
··· 9 9 #include <linux/cpu.h> 10 10 #include <linux/cpufreq.h> 11 11 #include <linux/module.h> 12 + #include <linux/sched/clock.h> 12 13 #include <linux/slab.h> 13 - 14 14 15 15 struct cpufreq_stats { 16 16 unsigned int total_trans; ··· 30 30 static void cpufreq_stats_update(struct cpufreq_stats *stats, 31 31 unsigned long long time) 32 32 { 33 - unsigned long long cur_time = get_jiffies_64(); 33 + unsigned long long cur_time = local_clock(); 34 34 35 35 stats->time_in_state[stats->last_index] += cur_time - time; 36 36 stats->last_time = cur_time; ··· 42 42 43 43 memset(stats->time_in_state, 0, count * sizeof(u64)); 44 44 memset(stats->trans_table, 0, count * count * sizeof(int)); 45 - stats->last_time = get_jiffies_64(); 45 + stats->last_time = local_clock(); 46 46 stats->total_trans = 0; 47 47 48 48 /* Adjust for the time elapsed since reset was requested */ ··· 82 82 * before the reset_pending read above. 83 83 */ 84 84 smp_rmb(); 85 - time = get_jiffies_64() - READ_ONCE(stats->reset_time); 85 + time = local_clock() - READ_ONCE(stats->reset_time); 86 86 } else { 87 87 time = 0; 88 88 } 89 89 } else { 90 90 time = stats->time_in_state[i]; 91 91 if (i == stats->last_index) 92 - time += get_jiffies_64() - stats->last_time; 92 + time += local_clock() - stats->last_time; 93 93 } 94 94 95 95 len += sprintf(buf + len, "%u %llu\n", stats->freq_table[i], 96 - jiffies_64_to_clock_t(time)); 96 + nsec_to_clock_t(time)); 97 97 } 98 98 return len; 99 99 } ··· 109 109 * Defer resetting of stats to cpufreq_stats_record_transition() to 110 110 * avoid races. 111 111 */ 112 - WRITE_ONCE(stats->reset_time, get_jiffies_64()); 112 + WRITE_ONCE(stats->reset_time, local_clock()); 113 113 /* 114 114 * The memory barrier below is to prevent the readers of reset_time from 115 115 * seeing a stale or partially updated value. ··· 249 249 stats->freq_table[i++] = pos->frequency; 250 250 251 251 stats->state_num = i; 252 - stats->last_time = get_jiffies_64(); 252 + stats->last_time = local_clock(); 253 253 stats->last_index = freq_table_get_index(stats, policy->cur); 254 254 255 255 policy->stats = stats;