]>
Commit | Line | Data |
---|---|---|
5a784215 GKH |
1 | From 7fb1327ee9b92fca27662f9b9d60c7c3376d6c69 Mon Sep 17 00:00:00 2001 |
2 | From: Frederic Weisbecker <fweisbec@gmail.com> | |
3 | Date: Tue, 31 Jan 2017 04:09:19 +0100 | |
4 | Subject: sched/cputime: Convert kcpustat to nsecs | |
5 | ||
6 | From: Frederic Weisbecker <fweisbec@gmail.com> | |
7 | ||
8 | commit 7fb1327ee9b92fca27662f9b9d60c7c3376d6c69 upstream. | |
9 | ||
10 | Kernel CPU stats are stored in cputime_t which is an architecture | |
11 | defined type, and hence a bit opaque and requiring accessors and mutators | |
12 | for any operation. | |
13 | ||
14 | Converting them to nsecs simplifies the code and is one step toward | |
15 | the removal of cputime_t in the core code. | |
16 | ||
17 | Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com> | |
18 | Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> | |
19 | Cc: Paul Mackerras <paulus@samba.org> | |
20 | Cc: Michael Ellerman <mpe@ellerman.id.au> | |
21 | Cc: Heiko Carstens <heiko.carstens@de.ibm.com> | |
22 | Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> | |
23 | Cc: Tony Luck <tony.luck@intel.com> | |
24 | Cc: Fenghua Yu <fenghua.yu@intel.com> | |
25 | Cc: Peter Zijlstra <peterz@infradead.org> | |
26 | Cc: Rik van Riel <riel@redhat.com> | |
27 | Cc: Stanislaw Gruszka <sgruszka@redhat.com> | |
28 | Cc: Wanpeng Li <wanpeng.li@hotmail.com> | |
29 | Link: http://lkml.kernel.org/r/1485832191-26889-4-git-send-email-fweisbec@gmail.com | |
30 | Signed-off-by: Ingo Molnar <mingo@kernel.org> | |
31 | [colona: minor conflict as 527b0a76f41d ("sched/cpuacct: Avoid %lld seq_printf | |
32 | warning") is missing from v4.9] | |
33 | Signed-off-by: Ivan Delalande <colona@arista.com> | |
34 | Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> | |
35 | --- | |
36 | arch/s390/appldata/appldata_os.c | 16 ++++---- | |
37 | drivers/cpufreq/cpufreq.c | 6 +-- | |
38 | drivers/cpufreq/cpufreq_governor.c | 2 - | |
39 | drivers/cpufreq/cpufreq_stats.c | 1 | |
40 | drivers/macintosh/rack-meter.c | 2 - | |
41 | fs/proc/stat.c | 68 ++++++++++++++++++------------------- | |
42 | fs/proc/uptime.c | 7 +-- | |
43 | kernel/sched/cpuacct.c | 2 - | |
44 | kernel/sched/cputime.c | 22 +++++------ | |
45 | 9 files changed, 61 insertions(+), 65 deletions(-) | |
46 | ||
47 | --- a/arch/s390/appldata/appldata_os.c | |
48 | +++ b/arch/s390/appldata/appldata_os.c | |
49 | @@ -113,21 +113,21 @@ static void appldata_get_os_data(void *d | |
50 | j = 0; | |
51 | for_each_online_cpu(i) { | |
52 | os_data->os_cpu[j].per_cpu_user = | |
53 | - cputime_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_USER]); | |
54 | + nsecs_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_USER]); | |
55 | os_data->os_cpu[j].per_cpu_nice = | |
56 | - cputime_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_NICE]); | |
57 | + nsecs_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_NICE]); | |
58 | os_data->os_cpu[j].per_cpu_system = | |
59 | - cputime_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM]); | |
60 | + nsecs_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM]); | |
61 | os_data->os_cpu[j].per_cpu_idle = | |
62 | - cputime_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_IDLE]); | |
63 | + nsecs_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_IDLE]); | |
64 | os_data->os_cpu[j].per_cpu_irq = | |
65 | - cputime_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_IRQ]); | |
66 | + nsecs_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_IRQ]); | |
67 | os_data->os_cpu[j].per_cpu_softirq = | |
68 | - cputime_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ]); | |
69 | + nsecs_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ]); | |
70 | os_data->os_cpu[j].per_cpu_iowait = | |
71 | - cputime_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_IOWAIT]); | |
72 | + nsecs_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_IOWAIT]); | |
73 | os_data->os_cpu[j].per_cpu_steal = | |
74 | - cputime_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_STEAL]); | |
75 | + nsecs_to_jiffies(kcpustat_cpu(i).cpustat[CPUTIME_STEAL]); | |
76 | os_data->os_cpu[j].cpu_id = i; | |
77 | j++; | |
78 | } | |
79 | --- a/drivers/cpufreq/cpufreq.c | |
80 | +++ b/drivers/cpufreq/cpufreq.c | |
81 | @@ -132,7 +132,7 @@ static inline u64 get_cpu_idle_time_jiff | |
82 | u64 cur_wall_time; | |
83 | u64 busy_time; | |
84 | ||
85 | - cur_wall_time = jiffies64_to_cputime64(get_jiffies_64()); | |
86 | + cur_wall_time = jiffies64_to_nsecs(get_jiffies_64()); | |
87 | ||
88 | busy_time = kcpustat_cpu(cpu).cpustat[CPUTIME_USER]; | |
89 | busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_SYSTEM]; | |
90 | @@ -143,9 +143,9 @@ static inline u64 get_cpu_idle_time_jiff | |
91 | ||
92 | idle_time = cur_wall_time - busy_time; | |
93 | if (wall) | |
94 | - *wall = cputime_to_usecs(cur_wall_time); | |
95 | + *wall = div_u64(cur_wall_time, NSEC_PER_USEC); | |
96 | ||
97 | - return cputime_to_usecs(idle_time); | |
98 | + return div_u64(idle_time, NSEC_PER_USEC); | |
99 | } | |
100 | ||
101 | u64 get_cpu_idle_time(unsigned int cpu, u64 *wall, int io_busy) | |
102 | --- a/drivers/cpufreq/cpufreq_governor.c | |
103 | +++ b/drivers/cpufreq/cpufreq_governor.c | |
104 | @@ -152,7 +152,7 @@ unsigned int dbs_update(struct cpufreq_p | |
105 | if (ignore_nice) { | |
106 | u64 cur_nice = kcpustat_cpu(j).cpustat[CPUTIME_NICE]; | |
107 | ||
108 | - idle_time += cputime_to_usecs(cur_nice - j_cdbs->prev_cpu_nice); | |
109 | + idle_time += div_u64(cur_nice - j_cdbs->prev_cpu_nice, NSEC_PER_USEC); | |
110 | j_cdbs->prev_cpu_nice = cur_nice; | |
111 | } | |
112 | ||
113 | --- a/drivers/cpufreq/cpufreq_stats.c | |
114 | +++ b/drivers/cpufreq/cpufreq_stats.c | |
115 | @@ -13,7 +13,6 @@ | |
116 | #include <linux/cpufreq.h> | |
117 | #include <linux/module.h> | |
118 | #include <linux/slab.h> | |
119 | -#include <linux/cputime.h> | |
120 | ||
121 | static DEFINE_SPINLOCK(cpufreq_stats_lock); | |
122 | ||
123 | --- a/drivers/macintosh/rack-meter.c | |
124 | +++ b/drivers/macintosh/rack-meter.c | |
125 | @@ -91,7 +91,7 @@ static inline cputime64_t get_cpu_idle_t | |
126 | if (rackmeter_ignore_nice) | |
127 | retval += kcpustat_cpu(cpu).cpustat[CPUTIME_NICE]; | |
128 | ||
129 | - return retval; | |
130 | + return nsecs_to_cputime64(retval); | |
131 | } | |
132 | ||
133 | static void rackmeter_setup_i2s(struct rackmeter *rm) | |
134 | --- a/fs/proc/stat.c | |
135 | +++ b/fs/proc/stat.c | |
136 | @@ -21,23 +21,23 @@ | |
137 | ||
138 | #ifdef arch_idle_time | |
139 | ||
140 | -static cputime64_t get_idle_time(int cpu) | |
141 | +static u64 get_idle_time(int cpu) | |
142 | { | |
143 | - cputime64_t idle; | |
144 | + u64 idle; | |
145 | ||
146 | idle = kcpustat_cpu(cpu).cpustat[CPUTIME_IDLE]; | |
147 | if (cpu_online(cpu) && !nr_iowait_cpu(cpu)) | |
148 | - idle += arch_idle_time(cpu); | |
149 | + idle += cputime_to_nsecs(arch_idle_time(cpu)); | |
150 | return idle; | |
151 | } | |
152 | ||
153 | -static cputime64_t get_iowait_time(int cpu) | |
154 | +static u64 get_iowait_time(int cpu) | |
155 | { | |
156 | - cputime64_t iowait; | |
157 | + u64 iowait; | |
158 | ||
159 | iowait = kcpustat_cpu(cpu).cpustat[CPUTIME_IOWAIT]; | |
160 | if (cpu_online(cpu) && nr_iowait_cpu(cpu)) | |
161 | - iowait += arch_idle_time(cpu); | |
162 | + iowait += cputime_to_nsecs(arch_idle_time(cpu)); | |
163 | return iowait; | |
164 | } | |
165 | ||
166 | @@ -45,32 +45,32 @@ static cputime64_t get_iowait_time(int c | |
167 | ||
168 | static u64 get_idle_time(int cpu) | |
169 | { | |
170 | - u64 idle, idle_time = -1ULL; | |
171 | + u64 idle, idle_usecs = -1ULL; | |
172 | ||
173 | if (cpu_online(cpu)) | |
174 | - idle_time = get_cpu_idle_time_us(cpu, NULL); | |
175 | + idle_usecs = get_cpu_idle_time_us(cpu, NULL); | |
176 | ||
177 | - if (idle_time == -1ULL) | |
178 | + if (idle_usecs == -1ULL) | |
179 | /* !NO_HZ or cpu offline so we can rely on cpustat.idle */ | |
180 | idle = kcpustat_cpu(cpu).cpustat[CPUTIME_IDLE]; | |
181 | else | |
182 | - idle = usecs_to_cputime64(idle_time); | |
183 | + idle = idle_usecs * NSEC_PER_USEC; | |
184 | ||
185 | return idle; | |
186 | } | |
187 | ||
188 | static u64 get_iowait_time(int cpu) | |
189 | { | |
190 | - u64 iowait, iowait_time = -1ULL; | |
191 | + u64 iowait, iowait_usecs = -1ULL; | |
192 | ||
193 | if (cpu_online(cpu)) | |
194 | - iowait_time = get_cpu_iowait_time_us(cpu, NULL); | |
195 | + iowait_usecs = get_cpu_iowait_time_us(cpu, NULL); | |
196 | ||
197 | - if (iowait_time == -1ULL) | |
198 | + if (iowait_usecs == -1ULL) | |
199 | /* !NO_HZ or cpu offline so we can rely on cpustat.iowait */ | |
200 | iowait = kcpustat_cpu(cpu).cpustat[CPUTIME_IOWAIT]; | |
201 | else | |
202 | - iowait = usecs_to_cputime64(iowait_time); | |
203 | + iowait = iowait_usecs * NSEC_PER_USEC; | |
204 | ||
205 | return iowait; | |
206 | } | |
207 | @@ -115,16 +115,16 @@ static int show_stat(struct seq_file *p, | |
208 | } | |
209 | sum += arch_irq_stat(); | |
210 | ||
211 | - seq_put_decimal_ull(p, "cpu ", cputime64_to_clock_t(user)); | |
212 | - seq_put_decimal_ull(p, " ", cputime64_to_clock_t(nice)); | |
213 | - seq_put_decimal_ull(p, " ", cputime64_to_clock_t(system)); | |
214 | - seq_put_decimal_ull(p, " ", cputime64_to_clock_t(idle)); | |
215 | - seq_put_decimal_ull(p, " ", cputime64_to_clock_t(iowait)); | |
216 | - seq_put_decimal_ull(p, " ", cputime64_to_clock_t(irq)); | |
217 | - seq_put_decimal_ull(p, " ", cputime64_to_clock_t(softirq)); | |
218 | - seq_put_decimal_ull(p, " ", cputime64_to_clock_t(steal)); | |
219 | - seq_put_decimal_ull(p, " ", cputime64_to_clock_t(guest)); | |
220 | - seq_put_decimal_ull(p, " ", cputime64_to_clock_t(guest_nice)); | |
221 | + seq_put_decimal_ull(p, "cpu ", nsec_to_clock_t(user)); | |
222 | + seq_put_decimal_ull(p, " ", nsec_to_clock_t(nice)); | |
223 | + seq_put_decimal_ull(p, " ", nsec_to_clock_t(system)); | |
224 | + seq_put_decimal_ull(p, " ", nsec_to_clock_t(idle)); | |
225 | + seq_put_decimal_ull(p, " ", nsec_to_clock_t(iowait)); | |
226 | + seq_put_decimal_ull(p, " ", nsec_to_clock_t(irq)); | |
227 | + seq_put_decimal_ull(p, " ", nsec_to_clock_t(softirq)); | |
228 | + seq_put_decimal_ull(p, " ", nsec_to_clock_t(steal)); | |
229 | + seq_put_decimal_ull(p, " ", nsec_to_clock_t(guest)); | |
230 | + seq_put_decimal_ull(p, " ", nsec_to_clock_t(guest_nice)); | |
231 | seq_putc(p, '\n'); | |
232 | ||
233 | for_each_online_cpu(i) { | |
234 | @@ -140,16 +140,16 @@ static int show_stat(struct seq_file *p, | |
235 | guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST]; | |
236 | guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE]; | |
237 | seq_printf(p, "cpu%d", i); | |
238 | - seq_put_decimal_ull(p, " ", cputime64_to_clock_t(user)); | |
239 | - seq_put_decimal_ull(p, " ", cputime64_to_clock_t(nice)); | |
240 | - seq_put_decimal_ull(p, " ", cputime64_to_clock_t(system)); | |
241 | - seq_put_decimal_ull(p, " ", cputime64_to_clock_t(idle)); | |
242 | - seq_put_decimal_ull(p, " ", cputime64_to_clock_t(iowait)); | |
243 | - seq_put_decimal_ull(p, " ", cputime64_to_clock_t(irq)); | |
244 | - seq_put_decimal_ull(p, " ", cputime64_to_clock_t(softirq)); | |
245 | - seq_put_decimal_ull(p, " ", cputime64_to_clock_t(steal)); | |
246 | - seq_put_decimal_ull(p, " ", cputime64_to_clock_t(guest)); | |
247 | - seq_put_decimal_ull(p, " ", cputime64_to_clock_t(guest_nice)); | |
248 | + seq_put_decimal_ull(p, " ", nsec_to_clock_t(user)); | |
249 | + seq_put_decimal_ull(p, " ", nsec_to_clock_t(nice)); | |
250 | + seq_put_decimal_ull(p, " ", nsec_to_clock_t(system)); | |
251 | + seq_put_decimal_ull(p, " ", nsec_to_clock_t(idle)); | |
252 | + seq_put_decimal_ull(p, " ", nsec_to_clock_t(iowait)); | |
253 | + seq_put_decimal_ull(p, " ", nsec_to_clock_t(irq)); | |
254 | + seq_put_decimal_ull(p, " ", nsec_to_clock_t(softirq)); | |
255 | + seq_put_decimal_ull(p, " ", nsec_to_clock_t(steal)); | |
256 | + seq_put_decimal_ull(p, " ", nsec_to_clock_t(guest)); | |
257 | + seq_put_decimal_ull(p, " ", nsec_to_clock_t(guest_nice)); | |
258 | seq_putc(p, '\n'); | |
259 | } | |
260 | seq_put_decimal_ull(p, "intr ", (unsigned long long)sum); | |
261 | --- a/fs/proc/uptime.c | |
262 | +++ b/fs/proc/uptime.c | |
263 | @@ -5,23 +5,20 @@ | |
264 | #include <linux/seq_file.h> | |
265 | #include <linux/time.h> | |
266 | #include <linux/kernel_stat.h> | |
267 | -#include <linux/cputime.h> | |
268 | ||
269 | static int uptime_proc_show(struct seq_file *m, void *v) | |
270 | { | |
271 | struct timespec uptime; | |
272 | struct timespec idle; | |
273 | - u64 idletime; | |
274 | u64 nsec; | |
275 | u32 rem; | |
276 | int i; | |
277 | ||
278 | - idletime = 0; | |
279 | + nsec = 0; | |
280 | for_each_possible_cpu(i) | |
281 | - idletime += (__force u64) kcpustat_cpu(i).cpustat[CPUTIME_IDLE]; | |
282 | + nsec += (__force u64) kcpustat_cpu(i).cpustat[CPUTIME_IDLE]; | |
283 | ||
284 | get_monotonic_boottime(&uptime); | |
285 | - nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC; | |
286 | idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem); | |
287 | idle.tv_nsec = rem; | |
288 | seq_printf(m, "%lu.%02lu %lu.%02lu\n", | |
289 | --- a/kernel/sched/cpuacct.c | |
290 | +++ b/kernel/sched/cpuacct.c | |
291 | @@ -297,7 +297,7 @@ static int cpuacct_stats_show(struct seq | |
292 | for (stat = 0; stat < CPUACCT_STAT_NSTATS; stat++) { | |
293 | seq_printf(sf, "%s %lld\n", | |
294 | cpuacct_stat_desc[stat], | |
295 | - cputime64_to_clock_t(val[stat])); | |
296 | + nsec_to_clock_t(val[stat])); | |
297 | } | |
298 | ||
299 | return 0; | |
300 | --- a/kernel/sched/cputime.c | |
301 | +++ b/kernel/sched/cputime.c | |
302 | @@ -75,9 +75,9 @@ static cputime_t irqtime_account_update( | |
303 | u64 *cpustat = kcpustat_this_cpu->cpustat; | |
304 | cputime_t irq_cputime; | |
305 | ||
306 | - irq_cputime = nsecs_to_cputime64(irqtime) - cpustat[idx]; | |
307 | + irq_cputime = nsecs_to_cputime64(irqtime - cpustat[idx]); | |
308 | irq_cputime = min(irq_cputime, maxtime); | |
309 | - cpustat[idx] += irq_cputime; | |
310 | + cpustat[idx] += cputime_to_nsecs(irq_cputime); | |
311 | ||
312 | return irq_cputime; | |
313 | } | |
314 | @@ -143,7 +143,7 @@ void account_user_time(struct task_struc | |
315 | index = (task_nice(p) > 0) ? CPUTIME_NICE : CPUTIME_USER; | |
316 | ||
317 | /* Add user time to cpustat. */ | |
318 | - task_group_account_field(p, index, (__force u64) cputime); | |
319 | + task_group_account_field(p, index, cputime_to_nsecs(cputime)); | |
320 | ||
321 | /* Account for user time used */ | |
322 | acct_account_cputime(p); | |
323 | @@ -168,11 +168,11 @@ static void account_guest_time(struct ta | |
324 | ||
325 | /* Add guest time to cpustat. */ | |
326 | if (task_nice(p) > 0) { | |
327 | - cpustat[CPUTIME_NICE] += (__force u64) cputime; | |
328 | - cpustat[CPUTIME_GUEST_NICE] += (__force u64) cputime; | |
329 | + cpustat[CPUTIME_NICE] += cputime_to_nsecs(cputime); | |
330 | + cpustat[CPUTIME_GUEST_NICE] += cputime_to_nsecs(cputime); | |
331 | } else { | |
332 | - cpustat[CPUTIME_USER] += (__force u64) cputime; | |
333 | - cpustat[CPUTIME_GUEST] += (__force u64) cputime; | |
334 | + cpustat[CPUTIME_USER] += cputime_to_nsecs(cputime); | |
335 | + cpustat[CPUTIME_GUEST] += cputime_to_nsecs(cputime); | |
336 | } | |
337 | } | |
338 | ||
339 | @@ -193,7 +193,7 @@ void __account_system_time(struct task_s | |
340 | account_group_system_time(p, cputime); | |
341 | ||
342 | /* Add system time to cpustat. */ | |
343 | - task_group_account_field(p, index, (__force u64) cputime); | |
344 | + task_group_account_field(p, index, cputime_to_nsecs(cputime)); | |
345 | ||
346 | /* Account for system time used */ | |
347 | acct_account_cputime(p); | |
348 | @@ -234,7 +234,7 @@ void account_steal_time(cputime_t cputim | |
349 | { | |
350 | u64 *cpustat = kcpustat_this_cpu->cpustat; | |
351 | ||
352 | - cpustat[CPUTIME_STEAL] += (__force u64) cputime; | |
353 | + cpustat[CPUTIME_STEAL] += cputime_to_nsecs(cputime); | |
354 | } | |
355 | ||
356 | /* | |
357 | @@ -247,9 +247,9 @@ void account_idle_time(cputime_t cputime | |
358 | struct rq *rq = this_rq(); | |
359 | ||
360 | if (atomic_read(&rq->nr_iowait) > 0) | |
361 | - cpustat[CPUTIME_IOWAIT] += (__force u64) cputime; | |
362 | + cpustat[CPUTIME_IOWAIT] += cputime_to_nsecs(cputime); | |
363 | else | |
364 | - cpustat[CPUTIME_IDLE] += (__force u64) cputime; | |
365 | + cpustat[CPUTIME_IDLE] += cputime_to_nsecs(cputime); | |
366 | } | |
367 | ||
368 | /* |