blob: cb5093c26d16b6e9e535e1366b692bd5e1cb84e8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Virtual cpu timer based timer functions.
3 *
Martin Schwidefsky27f6b412012-07-20 11:15:08 +02004 * Copyright IBM Corp. 2004, 2012
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Author(s): Jan Glauber <jan.glauber@de.ibm.com>
6 */
7
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <linux/kernel_stat.h>
Martin Schwidefsky27f6b412012-07-20 11:15:08 +02009#include <linux/notifier.h>
Martin Schwidefsky860dba42011-01-05 12:47:25 +010010#include <linux/kprobes.h>
Martin Schwidefsky27f6b412012-07-20 11:15:08 +020011#include <linux/export.h>
12#include <linux/kernel.h>
13#include <linux/timex.h>
14#include <linux/types.h>
15#include <linux/time.h>
16#include <linux/cpu.h>
17#include <linux/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
Heiko Carstens5a489b92006-10-06 16:38:35 +020019#include <asm/irq_regs.h>
Martin Schwidefsky76d4e002009-06-12 10:26:21 +020020#include <asm/cputime.h>
Martin Schwidefsky27f6b412012-07-20 11:15:08 +020021#include <asm/vtimer.h>
Heiko Carstensd7b250e2011-05-26 09:48:24 +020022#include <asm/irq.h>
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -040023#include "entry.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
Martin Schwidefsky27f6b412012-07-20 11:15:08 +020025static void virt_timer_expire(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
Martin Schwidefskye98bbaa2009-06-22 12:08:20 +020027DEFINE_PER_CPU(struct s390_idle_data, s390_idle);
Martin Schwidefsky9cfb9b32008-12-31 15:11:41 +010028
Martin Schwidefsky27f6b412012-07-20 11:15:08 +020029static LIST_HEAD(virt_timer_list);
30static DEFINE_SPINLOCK(virt_timer_lock);
31static atomic64_t virt_timer_current;
32static atomic64_t virt_timer_elapsed;
Martin Schwidefsky9cfb9b32008-12-31 15:11:41 +010033
Martin Schwidefsky27f6b412012-07-20 11:15:08 +020034static inline u64 get_vtimer(void)
35{
36 u64 timer;
37
38 asm volatile("stpt %0" : "=m" (timer));
Martin Schwidefsky9cfb9b32008-12-31 15:11:41 +010039 return timer;
40}
41
Martin Schwidefsky27f6b412012-07-20 11:15:08 +020042static inline void set_vtimer(u64 expires)
Martin Schwidefsky9cfb9b32008-12-31 15:11:41 +010043{
Martin Schwidefsky27f6b412012-07-20 11:15:08 +020044 u64 timer;
Martin Schwidefsky9cfb9b32008-12-31 15:11:41 +010045
Martin Schwidefsky27f6b412012-07-20 11:15:08 +020046 asm volatile(
47 " stpt %0\n" /* Store current cpu timer value */
48 " spt %1" /* Set new value imm. afterwards */
49 : "=m" (timer) : "m" (expires));
Martin Schwidefsky9cfb9b32008-12-31 15:11:41 +010050 S390_lowcore.system_timer += S390_lowcore.last_update_timer - timer;
51 S390_lowcore.last_update_timer = expires;
52}
53
Martin Schwidefsky27f6b412012-07-20 11:15:08 +020054static inline int virt_timer_forward(u64 elapsed)
55{
56 BUG_ON(!irqs_disabled());
57
58 if (list_empty(&virt_timer_list))
59 return 0;
60 elapsed = atomic64_add_return(elapsed, &virt_timer_elapsed);
61 return elapsed >= atomic64_read(&virt_timer_current);
62}
63
Linus Torvalds1da177e2005-04-16 15:20:36 -070064/*
65 * Update process times based on virtual cpu times stored by entry.S
66 * to the lowcore fields user_timer, system_timer & steal_clock.
67 */
Martin Schwidefsky27f6b412012-07-20 11:15:08 +020068static int do_account_vtime(struct task_struct *tsk, int hardirq_offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069{
Martin Schwidefskyaa5e97c2008-12-31 15:11:39 +010070 struct thread_info *ti = task_thread_info(tsk);
Martin Schwidefsky27f6b412012-07-20 11:15:08 +020071 u64 timer, clock, user, system, steal;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
73 timer = S390_lowcore.last_update_timer;
74 clock = S390_lowcore.last_update_clock;
Martin Schwidefsky27f6b412012-07-20 11:15:08 +020075 asm volatile(
76 " stpt %0\n" /* Store current cpu timer value */
77 " stck %1" /* Store current tod clock value */
78 : "=m" (S390_lowcore.last_update_timer),
79 "=m" (S390_lowcore.last_update_clock));
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 S390_lowcore.system_timer += timer - S390_lowcore.last_update_timer;
Martin Schwidefskyaa5e97c2008-12-31 15:11:39 +010081 S390_lowcore.steal_timer += S390_lowcore.last_update_clock - clock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Martin Schwidefskyaa5e97c2008-12-31 15:11:39 +010083 user = S390_lowcore.user_timer - ti->user_timer;
84 S390_lowcore.steal_timer -= user;
85 ti->user_timer = S390_lowcore.user_timer;
86 account_user_time(tsk, user, user);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
Martin Schwidefskyaa5e97c2008-12-31 15:11:39 +010088 system = S390_lowcore.system_timer - ti->system_timer;
89 S390_lowcore.steal_timer -= system;
90 ti->system_timer = S390_lowcore.system_timer;
Martin Schwidefsky9cfb9b32008-12-31 15:11:41 +010091 account_system_time(tsk, hardirq_offset, system, system);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
Martin Schwidefskyaa5e97c2008-12-31 15:11:39 +010093 steal = S390_lowcore.steal_timer;
94 if ((s64) steal > 0) {
95 S390_lowcore.steal_timer = 0;
Martin Schwidefsky9cfb9b32008-12-31 15:11:41 +010096 account_steal_time(steal);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 }
Martin Schwidefsky27f6b412012-07-20 11:15:08 +020098
99 return virt_timer_forward(user + system);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100}
101
Frederic Weisbeckerbf9fae92012-09-08 15:23:11 +0200102void vtime_task_switch(struct task_struct *prev)
Martin Schwidefsky1f1c12a2006-01-14 13:21:03 -0800103{
Martin Schwidefskyaa5e97c2008-12-31 15:11:39 +0100104 struct thread_info *ti;
Martin Schwidefsky1f1c12a2006-01-14 13:21:03 -0800105
Martin Schwidefskyaa5e97c2008-12-31 15:11:39 +0100106 do_account_vtime(prev, 0);
107 ti = task_thread_info(prev);
108 ti->user_timer = S390_lowcore.user_timer;
109 ti->system_timer = S390_lowcore.system_timer;
Frederic Weisbeckerbaa36042012-06-18 17:54:14 +0200110 ti = task_thread_info(current);
Martin Schwidefskyaa5e97c2008-12-31 15:11:39 +0100111 S390_lowcore.user_timer = ti->user_timer;
112 S390_lowcore.system_timer = ti->system_timer;
113}
Martin Schwidefsky1f1c12a2006-01-14 13:21:03 -0800114
Martin Schwidefskyaa5e97c2008-12-31 15:11:39 +0100115void account_process_tick(struct task_struct *tsk, int user_tick)
116{
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200117 if (do_account_vtime(tsk, HARDIRQ_OFFSET))
118 virt_timer_expire();
Martin Schwidefsky1f1c12a2006-01-14 13:21:03 -0800119}
120
121/*
122 * Update process times based on virtual cpu times stored by entry.S
123 * to the lowcore fields user_timer, system_timer & steal_clock.
124 */
Frederic Weisbeckerbf9fae92012-09-08 15:23:11 +0200125void vtime_account(struct task_struct *tsk)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126{
Martin Schwidefskyaa5e97c2008-12-31 15:11:39 +0100127 struct thread_info *ti = task_thread_info(tsk);
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200128 u64 timer, system;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
130 timer = S390_lowcore.last_update_timer;
Martin Schwidefsky9cfb9b32008-12-31 15:11:41 +0100131 S390_lowcore.last_update_timer = get_vtimer();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 S390_lowcore.system_timer += timer - S390_lowcore.last_update_timer;
133
Martin Schwidefskyaa5e97c2008-12-31 15:11:39 +0100134 system = S390_lowcore.system_timer - ti->system_timer;
135 S390_lowcore.steal_timer -= system;
136 ti->system_timer = S390_lowcore.system_timer;
Martin Schwidefsky9cfb9b32008-12-31 15:11:41 +0100137 account_system_time(tsk, 0, system, system);
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200138
139 virt_timer_forward(system);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140}
Frederic Weisbeckerbf9fae92012-09-08 15:23:11 +0200141EXPORT_SYMBOL_GPL(vtime_account);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
Martin Schwidefsky860dba42011-01-05 12:47:25 +0100143void __kprobes vtime_stop_cpu(void)
Martin Schwidefsky9cfb9b32008-12-31 15:11:41 +0100144{
145 struct s390_idle_data *idle = &__get_cpu_var(s390_idle);
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400146 unsigned long long idle_time;
147 unsigned long psw_mask;
148
149 trace_hardirqs_on();
150 /* Don't trace preempt off for idle. */
151 stop_critical_timings();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
Martin Schwidefsky9cfb9b32008-12-31 15:11:41 +0100153 /* Wait for external, I/O or machine check interrupt. */
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400154 psw_mask = psw_kernel_bits | PSW_MASK_WAIT | PSW_MASK_DAT |
155 PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK;
Martin Schwidefsky3c5d92a2009-09-29 14:25:16 +0200156 idle->nohz_delay = 0;
157
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400158 /* Call the assembler magic in entry.S */
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200159 psw_idle(idle, psw_mask);
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400160
161 /* Reenable preemption tracer. */
162 start_critical_timings();
163
164 /* Account time spent with enabled wait psw loaded as idle time. */
165 idle->sequence++;
166 smp_wmb();
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200167 idle_time = idle->clock_idle_exit - idle->clock_idle_enter;
168 idle->clock_idle_enter = idle->clock_idle_exit = 0ULL;
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400169 idle->idle_time += idle_time;
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400170 idle->idle_count++;
171 account_idle_time(idle_time);
172 smp_wmb();
173 idle->sequence++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174}
175
Martin Schwidefskye1c80532009-04-23 13:58:08 +0200176cputime64_t s390_get_idle_time(int cpu)
177{
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400178 struct s390_idle_data *idle = &per_cpu(s390_idle, cpu);
179 unsigned long long now, idle_enter, idle_exit;
Martin Schwidefskye98bbaa2009-06-22 12:08:20 +0200180 unsigned int sequence;
Martin Schwidefskye1c80532009-04-23 13:58:08 +0200181
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400182 do {
183 now = get_clock();
184 sequence = ACCESS_ONCE(idle->sequence);
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200185 idle_enter = ACCESS_ONCE(idle->clock_idle_enter);
186 idle_exit = ACCESS_ONCE(idle->clock_idle_exit);
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400187 } while ((sequence & 1) || (idle->sequence != sequence));
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200188 return idle_enter ? ((idle_exit ?: now) - idle_enter) : 0;
Martin Schwidefskye1c80532009-04-23 13:58:08 +0200189}
190
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191/*
192 * Sorted add to a list. List is linear searched until first bigger
193 * element is found.
194 */
195static void list_add_sorted(struct vtimer_list *timer, struct list_head *head)
196{
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200197 struct vtimer_list *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200199 list_for_each_entry(tmp, head, entry) {
200 if (tmp->expires > timer->expires) {
201 list_add_tail(&timer->entry, &tmp->entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 return;
203 }
204 }
205 list_add_tail(&timer->entry, head);
206}
207
208/*
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200209 * Handler for expired virtual CPU timer.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 */
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200211static void virt_timer_expire(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212{
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200213 struct vtimer_list *timer, *tmp;
214 unsigned long elapsed;
215 LIST_HEAD(cb_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200217 /* walk timer list, fire all expired timers */
218 spin_lock(&virt_timer_lock);
219 elapsed = atomic64_read(&virt_timer_elapsed);
220 list_for_each_entry_safe(timer, tmp, &virt_timer_list, entry) {
221 if (timer->expires < elapsed)
222 /* move expired timer to the callback queue */
223 list_move_tail(&timer->entry, &cb_list);
224 else
225 timer->expires -= elapsed;
226 }
227 if (!list_empty(&virt_timer_list)) {
228 timer = list_first_entry(&virt_timer_list,
229 struct vtimer_list, entry);
230 atomic64_set(&virt_timer_current, timer->expires);
231 }
232 atomic64_sub(elapsed, &virt_timer_elapsed);
233 spin_unlock(&virt_timer_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200235 /* Do callbacks and recharge periodic timers */
236 list_for_each_entry_safe(timer, tmp, &cb_list, entry) {
237 list_del_init(&timer->entry);
238 timer->function(timer->data);
239 if (timer->interval) {
Martin Schwidefsky9cfb9b32008-12-31 15:11:41 +0100240 /* Recharge interval timer */
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200241 timer->expires = timer->interval +
242 atomic64_read(&virt_timer_elapsed);
243 spin_lock(&virt_timer_lock);
244 list_add_sorted(timer, &virt_timer_list);
245 spin_unlock(&virt_timer_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 }
247 }
248}
249
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250void init_virt_timer(struct vtimer_list *timer)
251{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 timer->function = NULL;
253 INIT_LIST_HEAD(&timer->entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254}
255EXPORT_SYMBOL(init_virt_timer);
256
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257static inline int vtimer_pending(struct vtimer_list *timer)
258{
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200259 return !list_empty(&timer->entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260}
261
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262static void internal_add_vtimer(struct vtimer_list *timer)
263{
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200264 if (list_empty(&virt_timer_list)) {
265 /* First timer, just program it. */
266 atomic64_set(&virt_timer_current, timer->expires);
267 atomic64_set(&virt_timer_elapsed, 0);
268 list_add(&timer->entry, &virt_timer_list);
Martin Schwidefsky9cfb9b32008-12-31 15:11:41 +0100269 } else {
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200270 /* Update timer against current base. */
271 timer->expires += atomic64_read(&virt_timer_elapsed);
272 if (likely((s64) timer->expires <
273 (s64) atomic64_read(&virt_timer_current)))
Martin Schwidefsky9cfb9b32008-12-31 15:11:41 +0100274 /* The new timer expires before the current timer. */
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200275 atomic64_set(&virt_timer_current, timer->expires);
276 /* Insert new timer into the list. */
277 list_add_sorted(timer, &virt_timer_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279}
280
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200281static void __add_vtimer(struct vtimer_list *timer, int periodic)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282{
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200283 unsigned long flags;
284
285 timer->interval = periodic ? timer->expires : 0;
286 spin_lock_irqsave(&virt_timer_lock, flags);
287 internal_add_vtimer(timer);
288 spin_unlock_irqrestore(&virt_timer_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289}
290
291/*
292 * add_virt_timer - add an oneshot virtual CPU timer
293 */
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200294void add_virt_timer(struct vtimer_list *timer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295{
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200296 __add_vtimer(timer, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297}
298EXPORT_SYMBOL(add_virt_timer);
299
300/*
301 * add_virt_timer_int - add an interval virtual CPU timer
302 */
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200303void add_virt_timer_periodic(struct vtimer_list *timer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304{
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200305 __add_vtimer(timer, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306}
307EXPORT_SYMBOL(add_virt_timer_periodic);
308
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200309static int __mod_vtimer(struct vtimer_list *timer, u64 expires, int periodic)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 unsigned long flags;
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200312 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
Martin Schwidefskyca366a32008-07-14 09:59:23 +0200314 BUG_ON(!timer->function);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 if (timer->expires == expires && vtimer_pending(timer))
317 return 1;
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200318 spin_lock_irqsave(&virt_timer_lock, flags);
319 rc = vtimer_pending(timer);
320 if (rc)
321 list_del_init(&timer->entry);
322 timer->interval = periodic ? expires : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 timer->expires = expires;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 internal_add_vtimer(timer);
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200325 spin_unlock_irqrestore(&virt_timer_lock, flags);
326 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327}
Jan Glauberb6ecfa92009-04-14 15:36:20 +0200328
329/*
Jan Glauberb6ecfa92009-04-14 15:36:20 +0200330 * returns whether it has modified a pending timer (1) or not (0)
331 */
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200332int mod_virt_timer(struct vtimer_list *timer, u64 expires)
Jan Glauberb6ecfa92009-04-14 15:36:20 +0200333{
334 return __mod_vtimer(timer, expires, 0);
335}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336EXPORT_SYMBOL(mod_virt_timer);
337
338/*
Jan Glauberb6ecfa92009-04-14 15:36:20 +0200339 * returns whether it has modified a pending timer (1) or not (0)
340 */
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200341int mod_virt_timer_periodic(struct vtimer_list *timer, u64 expires)
Jan Glauberb6ecfa92009-04-14 15:36:20 +0200342{
343 return __mod_vtimer(timer, expires, 1);
344}
345EXPORT_SYMBOL(mod_virt_timer_periodic);
346
347/*
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200348 * Delete a virtual timer.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 *
350 * returns whether the deleted timer was pending (1) or not (0)
351 */
352int del_virt_timer(struct vtimer_list *timer)
353{
354 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 if (!vtimer_pending(timer))
357 return 0;
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200358 spin_lock_irqsave(&virt_timer_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 list_del_init(&timer->entry);
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200360 spin_unlock_irqrestore(&virt_timer_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 return 1;
362}
363EXPORT_SYMBOL(del_virt_timer);
364
365/*
366 * Start the virtual CPU timer on the current CPU.
367 */
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200368void __cpuinit init_cpu_vtimer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369{
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400370 /* set initial cpu timer */
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200371 set_vtimer(VTIMER_MAX_SLICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372}
373
Heiko Carstens39881212010-12-01 10:08:01 +0100374static int __cpuinit s390_nohz_notify(struct notifier_block *self,
375 unsigned long action, void *hcpu)
376{
377 struct s390_idle_data *idle;
378 long cpu = (long) hcpu;
379
380 idle = &per_cpu(s390_idle, cpu);
381 switch (action) {
382 case CPU_DYING:
383 case CPU_DYING_FROZEN:
384 idle->nohz_delay = 0;
385 default:
386 break;
387 }
388 return NOTIFY_OK;
389}
390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391void __init vtime_init(void)
392{
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100393 /* Enable cpu timer interrupts on the boot cpu. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 init_cpu_vtimer();
Heiko Carstens39881212010-12-01 10:08:01 +0100395 cpu_notifier(s390_nohz_notify, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396}