cpufreq: Fix wrong time unit conversion
PATCH 1/1 cpufreq: Fix wrong time unit conversion
The time spent by a CPU under a given frequency is stored in jiffies unit in the cpu var cpufreq_stats_table->time_in_state[i], i being the index of the frequency.
This is what is displayed in the following file on the right column:
cat /sys/devices/system/cpu/cpuX/cpufreq/stats/time_in_state
2301000 19835820
2300000 3172
[...]Now cpufreq converts this jiffies unit delta to clock_t before returning it to the user as in the above file. And that conversion is achieved using the API cputime64_to_clock_t().
Although it accidentally works on traditional tick based cputime accounting, where cputime_t maps directly to jiffies, it doesn't work with other types of cputime accounting such as CONFIG_VIRT_CPU_ACCOUNTING_* where cputime_t can map to nsecs or any granularity preffered by the architecture.
For example we get a buggy zero delta on full dyntick configurations:
cat /sys/devices/system/cpu/cpuX/cpufreq/stats/time_in_state
2301000 0
2300000 0
[...]Fix this with using the proper jiffies_64_t to clock_t conversion.
--- drivers/cpufreq/cpufreq_stats.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/cpufreq/cpufreq_stats.c +1 -1
@@ -81,7 +81,7 @@ static ssize_t show_time_in_state(struct cpufreq_policy *policy, char *buf)for (i =0 ; i < stat->state_num; i++) { len +=sprintf (buf + len,"%u %llu\n" , stat->freq_table[i], (unsigned long long ) -cputime64_to_clock_t (stat->time_in_state[i])); +jiffies_64_to_clock_t (stat->time_in_state[i])); }return len; }
Signature · 1 line
1.7.5.4
Quoted 29 lines · Frederic Weisbecker
The time spent by a CPU under a given frequency is stored in jiffies unit in the cpu var cpufreq_stats_table->time_in_state[i], i being the index of the frequency.
This is what is displayed in the following file on the right column:
cat /sys/devices/system/cpu/cpuX/cpufreq/stats/time_in_state 2301000 19835820 2300000 3172 [...]Now cpufreq converts this jiffies unit delta to
clock_tbefore returning it to the user as in the above file. And that conversion is achieved using the APIcputime64_to_clock_t().Although it accidentally works on traditional tick based cputime accounting, where
cputime_tmaps directly to jiffies, it doesn't work with other types of cputime accounting such as CONFIG_VIRT_CPU_ACCOUNTING_* wherecputime_tcan map to nsecs or any granularity preffered by the architecture.For example we get a buggy zero delta on full dyntick configurations:
cat /sys/devices/system/cpu/cpuX/cpufreq/stats/time_in_state 2301000 0 2300000 0 [...]Fix this with using the proper
jiffies_64_ttoclock_tconversion.
Quoted 8 lines
Reported-by Carsten Emde <[email protected]>Tested-by Carsten Emde <[email protected]>Signed-off-by Frederic Weisbecker <[email protected]>Cc Carsten Emde <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Clark Williams <[email protected]>Cc Sebastian Andrzej Siewior <[email protected]>Cc Paul E. McKenney <[email protected]>
Good catch!
Quoted 20 lines
--- drivers/cpufreq/cpufreq_stats.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)drivers/cpufreq/cpufreq_stats.c +1
-1@@ -81,7 +81,7 @@ static ssize_t show_time_in_state(struct cpufreq_policy *policy, char *buf)for (i =0 ; i < stat->state_num; i++) { len +=sprintf (buf + len,"%u %llu\n" , stat->freq_table[i], (unsigned long long ) -cputime64_to_clock_t (stat->time_in_state[i])); +jiffies_64_to_clock_t (stat->time_in_state[i])); }return len; }Signature · 1 line
1.7.5.4
Rafael J. Wysocki
AppliedQuoted 39 lines · Paul E. McKenney
Quoted 29 lines · Frederic Weisbecker
The time spent by a CPU under a given frequency is stored in jiffies unit in the cpu var cpufreq_stats_table->time_in_state[i], i being the index of the frequency.
This is what is displayed in the following file on the right column:
cat /sys/devices/system/cpu/cpuX/cpufreq/stats/time_in_state 2301000 19835820 2300000 3172 [...]Now cpufreq converts this jiffies unit delta to
clock_tbefore returning it to the user as in the above file. And that conversion is achieved using the APIcputime64_to_clock_t().Although it accidentally works on traditional tick based cputime accounting, where
cputime_tmaps directly to jiffies, it doesn't work with other types of cputime accounting such as CONFIG_VIRT_CPU_ACCOUNTING_* wherecputime_tcan map to nsecs or any granularity preffered by the architecture.For example we get a buggy zero delta on full dyntick configurations:
cat /sys/devices/system/cpu/cpuX/cpufreq/stats/time_in_state 2301000 0 2300000 0 [...]Fix this with using the proper
jiffies_64_ttoclock_tconversion.Quoted 8 lines
Reported-by Carsten Emde <[email protected]>Tested-by Carsten Emde <[email protected]>Signed-off-by Frederic Weisbecker <[email protected]>Cc Carsten Emde <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Clark Williams <[email protected]>Cc Sebastian Andrzej Siewior <[email protected]>Cc Paul E. McKenney <[email protected]>
Quoted 3 lines
Good catch!
Acked-by Paul E. McKenney <[email protected]>
Applied, will push for 3.12-rc1.
Thanks Frederic!
Quoted 19 lines
Quoted 18 lines
--- drivers/cpufreq/cpufreq_stats.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)drivers/cpufreq/cpufreq_stats.c +1
-1@@ -81,7 +81,7 @@ static ssize_t show_time_in_state(struct cpufreq_policy *policy, char *buf)for (i =0 ; i < stat->state_num; i++) { len +=sprintf (buf + len,"%u %llu\n" , stat->freq_table[i], (unsigned long long ) -cputime64_to_clock_t (stat->time_in_state[i])); +jiffies_64_to_clock_t (stat->time_in_state[i])); }return len; }
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
See also <http://permalink.gmane.org/gmane.linux.kernel.cpufreq/11672>.
Andreas.
Signature · 3 lines
Andreas Schwab, [email protected] GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different."
Quoted 1 line · Andreas Schwab
See also <http://permalink.gmane.org/gmane.linux.kernel.cpufreq/11672>.
Does look quite similar, now that you mention it.
Perhaps if Frederic has not already sent his patch he could add your Signed-off-by to his patch?
Thanx, Paul
Quoted 3 lines · Andreas Schwab
See also <http://permalink.gmane.org/gmane.linux.kernel.cpufreq/11672>.
Andreas.
Ah I missed it.
Raphael, if it is not too late, may be you could still set Andreas as the original author?
Thanks.
Quoted 5 lines
Signature · 4 lines
-- Andreas Schwab, [email protected] GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different."
Quoted 8 lines · Frederic Weisbecker
Quoted 3 lines · Andreas Schwab
See also <http://permalink.gmane.org/gmane.linux.kernel.cpufreq/11672>.
Andreas.
Ah I missed it.
Raphael, if it is not too late, may be you could still set Andreas as the original author?
Done.
Thanks,
Rafael
Quoted 11 lines · Rafael J. Wysocki
Quoted 8 lines · Frederic Weisbecker
Quoted 3 lines · Andreas Schwab
See also <http://permalink.gmane.org/gmane.linux.kernel.cpufreq/11672>.
Andreas.
Ah I missed it.
Raphael, if it is not too late, may be you could still set Andreas as the original author?
Done.
BTW, CCing power management patches to [email protected] helps a bit, because I can see them in patchwork then and that makes overlooking them or forgetting about them much less likely.
Thanks,
Rafael
Quoted 9 lines · Rafael J. Wysocki
Quoted 8 lines · Rafael J. Wysocki
Quoted 7 lines · Frederic Weisbecker
Quoted 3 lines · Andreas Schwab
See also <http://permalink.gmane.org/gmane.linux.kernel.cpufreq/11672>.
Andreas.
Ah I missed it.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Raphael, if it is not too late, may be you could still set Andreas as the original author?
Done.
BTW, CCing power management patches to [email protected] helps a bit, because I can see them in patchwork then and that makes overlooking them or forgetting about them much less likely.
Ok, I'll do that next time.
Thanks.