2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* arch/s390/kernel/vtime.c
|
|
|
|
* Virtual cpu timer based timer functions.
|
|
|
|
*
|
|
|
|
* S390 version
|
|
|
|
* Copyright (C) 2004 IBM Deutschland Entwicklung GmbH, IBM Corporation
|
|
|
|
* Author(s): Jan Glauber <jan.glauber@de.ibm.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/time.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/smp.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/timex.h>
|
|
|
|
#include <linux/notifier.h>
|
|
|
|
#include <linux/kernel_stat.h>
|
|
|
|
#include <linux/rcupdate.h>
|
|
|
|
#include <linux/posix-timers.h>
|
2010-12-01 10:08:01 +01:00
|
|
|
#include <linux/cpu.h>
|
2011-01-05 12:47:25 +01:00
|
|
|
#include <linux/kprobes.h>
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
#include <asm/timer.h>
|
2006-10-06 16:38:35 +02:00
|
|
|
#include <asm/irq_regs.h>
|
2009-06-12 10:26:21 +02:00
|
|
|
#include <asm/cputime.h>
|
2011-05-26 09:48:24 +02:00
|
|
|
#include <asm/irq.h>
|
2012-03-11 16:59:27 +01:00
|
|
|
#include "entry.h"
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2007-02-05 21:16:47 +01:00
|
|
|
static DEFINE_PER_CPU(struct vtimer_queue, virt_cpu_timer);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2009-06-22 12:08:20 +02:00
|
|
|
DEFINE_PER_CPU(struct s390_idle_data, s390_idle);
|
2008-12-31 15:11:41 +01:00
|
|
|
|
|
|
|
static inline __u64 get_vtimer(void)
|
|
|
|
{
|
|
|
|
__u64 timer;
|
|
|
|
|
|
|
|
asm volatile("STPT %0" : "=m" (timer));
|
|
|
|
return timer;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void set_vtimer(__u64 expires)
|
|
|
|
{
|
|
|
|
__u64 timer;
|
|
|
|
|
|
|
|
asm volatile (" STPT %0\n" /* Store current cpu timer value */
|
2011-03-31 03:57:33 +02:00
|
|
|
" SPT %1" /* Set new value immediately afterwards */
|
2008-12-31 15:11:41 +01:00
|
|
|
: "=m" (timer) : "m" (expires) );
|
|
|
|
S390_lowcore.system_timer += S390_lowcore.last_update_timer - timer;
|
|
|
|
S390_lowcore.last_update_timer = expires;
|
|
|
|
}
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Update process times based on virtual cpu times stored by entry.S
|
|
|
|
* to the lowcore fields user_timer, system_timer & steal_clock.
|
|
|
|
*/
|
2008-12-31 15:11:39 +01:00
|
|
|
static void do_account_vtime(struct task_struct *tsk, int hardirq_offset)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-12-31 15:11:39 +01:00
|
|
|
struct thread_info *ti = task_thread_info(tsk);
|
|
|
|
__u64 timer, clock, user, system, steal;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
timer = S390_lowcore.last_update_timer;
|
|
|
|
clock = S390_lowcore.last_update_clock;
|
|
|
|
asm volatile (" STPT %0\n" /* Store current cpu timer value */
|
|
|
|
" STCK %1" /* Store current tod clock value */
|
|
|
|
: "=m" (S390_lowcore.last_update_timer),
|
|
|
|
"=m" (S390_lowcore.last_update_clock) );
|
|
|
|
S390_lowcore.system_timer += timer - S390_lowcore.last_update_timer;
|
2008-12-31 15:11:39 +01:00
|
|
|
S390_lowcore.steal_timer += S390_lowcore.last_update_clock - clock;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2008-12-31 15:11:39 +01:00
|
|
|
user = S390_lowcore.user_timer - ti->user_timer;
|
|
|
|
S390_lowcore.steal_timer -= user;
|
|
|
|
ti->user_timer = S390_lowcore.user_timer;
|
|
|
|
account_user_time(tsk, user, user);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2008-12-31 15:11:39 +01:00
|
|
|
system = S390_lowcore.system_timer - ti->system_timer;
|
|
|
|
S390_lowcore.steal_timer -= system;
|
|
|
|
ti->system_timer = S390_lowcore.system_timer;
|
2008-12-31 15:11:41 +01:00
|
|
|
account_system_time(tsk, hardirq_offset, system, system);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2008-12-31 15:11:39 +01:00
|
|
|
steal = S390_lowcore.steal_timer;
|
|
|
|
if ((s64) steal > 0) {
|
|
|
|
S390_lowcore.steal_timer = 0;
|
2008-12-31 15:11:41 +01:00
|
|
|
account_steal_time(steal);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-31 15:11:39 +01:00
|
|
|
void account_vtime(struct task_struct *prev, struct task_struct *next)
|
2006-01-14 22:21:03 +01:00
|
|
|
{
|
2008-12-31 15:11:39 +01:00
|
|
|
struct thread_info *ti;
|
|
|
|
|
|
|
|
do_account_vtime(prev, 0);
|
|
|
|
ti = task_thread_info(prev);
|
|
|
|
ti->user_timer = S390_lowcore.user_timer;
|
|
|
|
ti->system_timer = S390_lowcore.system_timer;
|
|
|
|
ti = task_thread_info(next);
|
|
|
|
S390_lowcore.user_timer = ti->user_timer;
|
|
|
|
S390_lowcore.system_timer = ti->system_timer;
|
|
|
|
}
|
2006-01-14 22:21:03 +01:00
|
|
|
|
2008-12-31 15:11:39 +01:00
|
|
|
void account_process_tick(struct task_struct *tsk, int user_tick)
|
|
|
|
{
|
|
|
|
do_account_vtime(tsk, HARDIRQ_OFFSET);
|
2006-01-14 22:21:03 +01:00
|
|
|
}
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Update process times based on virtual cpu times stored by entry.S
|
|
|
|
* to the lowcore fields user_timer, system_timer & steal_clock.
|
|
|
|
*/
|
|
|
|
void account_system_vtime(struct task_struct *tsk)
|
|
|
|
{
|
2008-12-31 15:11:39 +01:00
|
|
|
struct thread_info *ti = task_thread_info(tsk);
|
|
|
|
__u64 timer, system;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
timer = S390_lowcore.last_update_timer;
|
2008-12-31 15:11:41 +01:00
|
|
|
S390_lowcore.last_update_timer = get_vtimer();
|
2005-04-17 00:20:36 +02:00
|
|
|
S390_lowcore.system_timer += timer - S390_lowcore.last_update_timer;
|
|
|
|
|
2008-12-31 15:11:39 +01:00
|
|
|
system = S390_lowcore.system_timer - ti->system_timer;
|
|
|
|
S390_lowcore.steal_timer -= system;
|
|
|
|
ti->system_timer = S390_lowcore.system_timer;
|
2008-12-31 15:11:41 +01:00
|
|
|
account_system_time(tsk, 0, system, system);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
2008-03-25 18:47:20 +01:00
|
|
|
EXPORT_SYMBOL_GPL(account_system_vtime);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2012-03-11 16:59:27 +01:00
|
|
|
void __kprobes vtime_stop_cpu(void)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-12-31 15:11:41 +01:00
|
|
|
struct s390_idle_data *idle = &__get_cpu_var(s390_idle);
|
2008-12-31 15:11:40 +01:00
|
|
|
struct vtimer_queue *vq = &__get_cpu_var(virt_cpu_timer);
|
2012-03-11 16:59:27 +01:00
|
|
|
unsigned long long idle_time;
|
|
|
|
unsigned long psw_mask;
|
2008-12-31 15:11:41 +01:00
|
|
|
|
2012-03-11 16:59:27 +01:00
|
|
|
trace_hardirqs_on();
|
|
|
|
/* Don't trace preempt off for idle. */
|
|
|
|
stop_critical_timings();
|
2010-05-17 10:00:03 +02:00
|
|
|
|
2012-03-11 16:59:27 +01:00
|
|
|
/* Wait for external, I/O or machine check interrupt. */
|
|
|
|
psw_mask = psw_kernel_bits | PSW_MASK_WAIT | PSW_MASK_DAT |
|
|
|
|
PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK;
|
|
|
|
idle->nohz_delay = 0;
|
|
|
|
|
|
|
|
/* Call the assembler magic in entry.S */
|
|
|
|
psw_idle(idle, vq, psw_mask, !list_empty(&vq->list));
|
|
|
|
|
|
|
|
/* Reenable preemption tracer. */
|
|
|
|
start_critical_timings();
|
2005-05-01 17:58:57 +02:00
|
|
|
|
2012-03-11 16:59:27 +01:00
|
|
|
/* Account time spent with enabled wait psw loaded as idle time. */
|
2009-06-22 12:08:20 +02:00
|
|
|
idle->sequence++;
|
|
|
|
smp_wmb();
|
2012-03-11 16:59:27 +01:00
|
|
|
idle_time = idle->idle_exit - idle->idle_enter;
|
2008-12-31 15:11:41 +01:00
|
|
|
idle->idle_time += idle_time;
|
2012-03-11 16:59:27 +01:00
|
|
|
idle->idle_enter = idle->idle_exit = 0ULL;
|
2008-12-31 15:11:41 +01:00
|
|
|
idle->idle_count++;
|
2012-03-11 16:59:27 +01:00
|
|
|
account_idle_time(idle_time);
|
2009-06-22 12:08:20 +02:00
|
|
|
smp_wmb();
|
|
|
|
idle->sequence++;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
2009-04-23 13:58:08 +02:00
|
|
|
cputime64_t s390_get_idle_time(int cpu)
|
|
|
|
{
|
2012-03-11 16:59:27 +01:00
|
|
|
struct s390_idle_data *idle = &per_cpu(s390_idle, cpu);
|
|
|
|
unsigned long long now, idle_enter, idle_exit;
|
2009-06-22 12:08:20 +02:00
|
|
|
unsigned int sequence;
|
2009-04-23 13:58:08 +02:00
|
|
|
|
2012-03-11 16:59:27 +01:00
|
|
|
do {
|
|
|
|
now = get_clock();
|
|
|
|
sequence = ACCESS_ONCE(idle->sequence);
|
|
|
|
idle_enter = ACCESS_ONCE(idle->idle_enter);
|
|
|
|
idle_exit = ACCESS_ONCE(idle->idle_exit);
|
|
|
|
} while ((sequence & 1) || (idle->sequence != sequence));
|
|
|
|
return idle_enter ? ((idle_exit ? : now) - idle_enter) : 0;
|
2009-04-23 13:58:08 +02:00
|
|
|
}
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Sorted add to a list. List is linear searched until first bigger
|
|
|
|
* element is found.
|
|
|
|
*/
|
|
|
|
static void list_add_sorted(struct vtimer_list *timer, struct list_head *head)
|
|
|
|
{
|
|
|
|
struct vtimer_list *event;
|
|
|
|
|
|
|
|
list_for_each_entry(event, head, entry) {
|
|
|
|
if (event->expires > timer->expires) {
|
|
|
|
list_add_tail(&timer->entry, &event->entry);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
list_add_tail(&timer->entry, head);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do the callback functions of expired vtimer events.
|
|
|
|
* Called from within the interrupt handler.
|
|
|
|
*/
|
2006-10-11 15:31:26 +02:00
|
|
|
static void do_callbacks(struct list_head *cb_list)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-12-31 15:11:41 +01:00
|
|
|
struct vtimer_queue *vq;
|
2005-04-17 00:20:36 +02:00
|
|
|
struct vtimer_list *event, *tmp;
|
|
|
|
|
|
|
|
if (list_empty(cb_list))
|
|
|
|
return;
|
|
|
|
|
2008-12-31 15:11:41 +01:00
|
|
|
vq = &__get_cpu_var(virt_cpu_timer);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
list_for_each_entry_safe(event, tmp, cb_list, entry) {
|
2008-12-31 15:11:41 +01:00
|
|
|
list_del_init(&event->entry);
|
|
|
|
(event->function)(event->data);
|
|
|
|
if (event->interval) {
|
|
|
|
/* Recharge interval timer */
|
|
|
|
event->expires = event->interval + vq->elapsed;
|
|
|
|
spin_lock(&vq->lock);
|
|
|
|
list_add_sorted(event, &vq->list);
|
|
|
|
spin_unlock(&vq->lock);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handler for the virtual CPU timer.
|
|
|
|
*/
|
2010-10-25 16:10:38 +02:00
|
|
|
static void do_cpu_timer_interrupt(unsigned int ext_int_code,
|
|
|
|
unsigned int param32, unsigned long param64)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-12-31 15:11:41 +01:00
|
|
|
struct vtimer_queue *vq;
|
2005-04-17 00:20:36 +02:00
|
|
|
struct vtimer_list *event, *tmp;
|
2008-12-31 15:11:41 +01:00
|
|
|
struct list_head cb_list; /* the callback queue */
|
|
|
|
__u64 elapsed, next;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2011-01-05 12:47:28 +01:00
|
|
|
kstat_cpu(smp_processor_id()).irqs[EXTINT_TMR]++;
|
2005-04-17 00:20:36 +02:00
|
|
|
INIT_LIST_HEAD(&cb_list);
|
2008-12-31 15:11:41 +01:00
|
|
|
vq = &__get_cpu_var(virt_cpu_timer);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/* walk timer list, fire all expired events */
|
2008-12-31 15:11:41 +01:00
|
|
|
spin_lock(&vq->lock);
|
|
|
|
|
|
|
|
elapsed = vq->elapsed + (vq->timer - S390_lowcore.async_enter_timer);
|
|
|
|
BUG_ON((s64) elapsed < 0);
|
|
|
|
vq->elapsed = 0;
|
|
|
|
list_for_each_entry_safe(event, tmp, &vq->list, entry) {
|
|
|
|
if (event->expires < elapsed)
|
|
|
|
/* move expired timer to the callback queue */
|
|
|
|
list_move_tail(&event->entry, &cb_list);
|
|
|
|
else
|
|
|
|
event->expires -= elapsed;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
2008-12-31 15:11:41 +01:00
|
|
|
spin_unlock(&vq->lock);
|
|
|
|
|
2006-10-11 15:31:26 +02:00
|
|
|
do_callbacks(&cb_list);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/* next event is first in list */
|
2008-12-31 15:11:41 +01:00
|
|
|
next = VTIMER_MAX_SLICE;
|
|
|
|
spin_lock(&vq->lock);
|
|
|
|
if (!list_empty(&vq->list)) {
|
|
|
|
event = list_first_entry(&vq->list, struct vtimer_list, entry);
|
|
|
|
next = event->expires;
|
2012-03-11 16:59:27 +01:00
|
|
|
}
|
2008-12-31 15:11:41 +01:00
|
|
|
spin_unlock(&vq->lock);
|
|
|
|
/*
|
|
|
|
* To improve precision add the time spent by the
|
|
|
|
* interrupt handler to the elapsed time.
|
|
|
|
* Note: CPU timer counts down and we got an interrupt,
|
|
|
|
* the current content is negative
|
|
|
|
*/
|
|
|
|
elapsed = S390_lowcore.async_enter_timer - get_vtimer();
|
|
|
|
set_vtimer(next - elapsed);
|
|
|
|
vq->timer = next - elapsed;
|
|
|
|
vq->elapsed = elapsed;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void init_virt_timer(struct vtimer_list *timer)
|
|
|
|
{
|
|
|
|
timer->function = NULL;
|
|
|
|
INIT_LIST_HEAD(&timer->entry);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(init_virt_timer);
|
|
|
|
|
|
|
|
static inline int vtimer_pending(struct vtimer_list *timer)
|
|
|
|
{
|
|
|
|
return (!list_empty(&timer->entry));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* this function should only run on the specified CPU
|
|
|
|
*/
|
|
|
|
static void internal_add_vtimer(struct vtimer_list *timer)
|
|
|
|
{
|
2008-12-31 15:11:41 +01:00
|
|
|
struct vtimer_queue *vq;
|
2005-04-17 00:20:36 +02:00
|
|
|
unsigned long flags;
|
2008-12-31 15:11:41 +01:00
|
|
|
__u64 left, expires;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2008-12-31 15:11:41 +01:00
|
|
|
vq = &per_cpu(virt_cpu_timer, timer->cpu);
|
|
|
|
spin_lock_irqsave(&vq->lock, flags);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2008-07-14 09:59:23 +02:00
|
|
|
BUG_ON(timer->cpu != smp_processor_id());
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2008-12-31 15:11:41 +01:00
|
|
|
if (list_empty(&vq->list)) {
|
|
|
|
/* First timer on this cpu, just program it. */
|
|
|
|
list_add(&timer->entry, &vq->list);
|
|
|
|
set_vtimer(timer->expires);
|
|
|
|
vq->timer = timer->expires;
|
|
|
|
vq->elapsed = 0;
|
|
|
|
} else {
|
|
|
|
/* Check progress of old timers. */
|
|
|
|
expires = timer->expires;
|
|
|
|
left = get_vtimer();
|
|
|
|
if (likely((s64) expires < (s64) left)) {
|
|
|
|
/* The new timer expires before the current timer. */
|
|
|
|
set_vtimer(expires);
|
|
|
|
vq->elapsed += vq->timer - left;
|
|
|
|
vq->timer = expires;
|
|
|
|
} else {
|
|
|
|
vq->elapsed += vq->timer - left;
|
|
|
|
vq->timer = left;
|
|
|
|
}
|
|
|
|
/* Insert new timer into per cpu list. */
|
|
|
|
timer->expires += vq->elapsed;
|
|
|
|
list_add_sorted(timer, &vq->list);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
2008-12-31 15:11:41 +01:00
|
|
|
spin_unlock_irqrestore(&vq->lock, flags);
|
2006-06-26 18:35:02 +02:00
|
|
|
/* release CPU acquired in prepare_vtimer or mod_virt_timer() */
|
2005-04-17 00:20:36 +02:00
|
|
|
put_cpu();
|
|
|
|
}
|
|
|
|
|
2008-07-14 09:59:23 +02:00
|
|
|
static inline void prepare_vtimer(struct vtimer_list *timer)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-07-14 09:59:23 +02:00
|
|
|
BUG_ON(!timer->function);
|
|
|
|
BUG_ON(!timer->expires || timer->expires > VTIMER_MAX_SLICE);
|
|
|
|
BUG_ON(vtimer_pending(timer));
|
2005-04-17 00:20:36 +02:00
|
|
|
timer->cpu = get_cpu();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* add_virt_timer - add an oneshot virtual CPU timer
|
|
|
|
*/
|
|
|
|
void add_virt_timer(void *new)
|
|
|
|
{
|
|
|
|
struct vtimer_list *timer;
|
|
|
|
|
|
|
|
timer = (struct vtimer_list *)new;
|
2008-07-14 09:59:23 +02:00
|
|
|
prepare_vtimer(timer);
|
2005-04-17 00:20:36 +02:00
|
|
|
timer->interval = 0;
|
|
|
|
internal_add_vtimer(timer);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(add_virt_timer);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* add_virt_timer_int - add an interval virtual CPU timer
|
|
|
|
*/
|
|
|
|
void add_virt_timer_periodic(void *new)
|
|
|
|
{
|
|
|
|
struct vtimer_list *timer;
|
|
|
|
|
|
|
|
timer = (struct vtimer_list *)new;
|
2008-07-14 09:59:23 +02:00
|
|
|
prepare_vtimer(timer);
|
2005-04-17 00:20:36 +02:00
|
|
|
timer->interval = timer->expires;
|
|
|
|
internal_add_vtimer(timer);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(add_virt_timer_periodic);
|
|
|
|
|
2011-10-30 15:17:11 +01:00
|
|
|
static int __mod_vtimer(struct vtimer_list *timer, __u64 expires, int periodic)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-12-31 15:11:41 +01:00
|
|
|
struct vtimer_queue *vq;
|
2005-04-17 00:20:36 +02:00
|
|
|
unsigned long flags;
|
|
|
|
int cpu;
|
|
|
|
|
2008-07-14 09:59:23 +02:00
|
|
|
BUG_ON(!timer->function);
|
|
|
|
BUG_ON(!expires || expires > VTIMER_MAX_SLICE);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
if (timer->expires == expires && vtimer_pending(timer))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
cpu = get_cpu();
|
2008-12-31 15:11:41 +01:00
|
|
|
vq = &per_cpu(virt_cpu_timer, cpu);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/* disable interrupts before test if timer is pending */
|
2008-12-31 15:11:41 +01:00
|
|
|
spin_lock_irqsave(&vq->lock, flags);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/* if timer isn't pending add it on the current CPU */
|
|
|
|
if (!vtimer_pending(timer)) {
|
2008-12-31 15:11:41 +01:00
|
|
|
spin_unlock_irqrestore(&vq->lock, flags);
|
2009-04-14 15:36:20 +02:00
|
|
|
|
|
|
|
if (periodic)
|
|
|
|
timer->interval = expires;
|
|
|
|
else
|
|
|
|
timer->interval = 0;
|
2005-04-17 00:20:36 +02:00
|
|
|
timer->expires = expires;
|
|
|
|
timer->cpu = cpu;
|
|
|
|
internal_add_vtimer(timer);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-04-14 15:36:20 +02:00
|
|
|
/* check if we run on the right CPU */
|
|
|
|
BUG_ON(timer->cpu != cpu);
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
list_del_init(&timer->entry);
|
|
|
|
timer->expires = expires;
|
2009-04-14 15:36:20 +02:00
|
|
|
if (periodic)
|
2005-04-17 00:20:36 +02:00
|
|
|
timer->interval = expires;
|
|
|
|
|
|
|
|
/* the timer can't expire anymore so we can release the lock */
|
2008-12-31 15:11:41 +01:00
|
|
|
spin_unlock_irqrestore(&vq->lock, flags);
|
2005-04-17 00:20:36 +02:00
|
|
|
internal_add_vtimer(timer);
|
|
|
|
return 1;
|
|
|
|
}
|
2009-04-14 15:36:20 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we change a pending timer the function must be called on the CPU
|
|
|
|
* where the timer is running on.
|
|
|
|
*
|
|
|
|
* returns whether it has modified a pending timer (1) or not (0)
|
|
|
|
*/
|
|
|
|
int mod_virt_timer(struct vtimer_list *timer, __u64 expires)
|
|
|
|
{
|
|
|
|
return __mod_vtimer(timer, expires, 0);
|
|
|
|
}
|
2005-04-17 00:20:36 +02:00
|
|
|
EXPORT_SYMBOL(mod_virt_timer);
|
|
|
|
|
2009-04-14 15:36:20 +02:00
|
|
|
/*
|
|
|
|
* If we change a pending timer the function must be called on the CPU
|
|
|
|
* where the timer is running on.
|
|
|
|
*
|
|
|
|
* returns whether it has modified a pending timer (1) or not (0)
|
|
|
|
*/
|
|
|
|
int mod_virt_timer_periodic(struct vtimer_list *timer, __u64 expires)
|
|
|
|
{
|
|
|
|
return __mod_vtimer(timer, expires, 1);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(mod_virt_timer_periodic);
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* delete a virtual timer
|
|
|
|
*
|
|
|
|
* returns whether the deleted timer was pending (1) or not (0)
|
|
|
|
*/
|
|
|
|
int del_virt_timer(struct vtimer_list *timer)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
2008-12-31 15:11:41 +01:00
|
|
|
struct vtimer_queue *vq;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/* check if timer is pending */
|
|
|
|
if (!vtimer_pending(timer))
|
|
|
|
return 0;
|
|
|
|
|
2008-12-31 15:11:41 +01:00
|
|
|
vq = &per_cpu(virt_cpu_timer, timer->cpu);
|
|
|
|
spin_lock_irqsave(&vq->lock, flags);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/* we don't interrupt a running timer, just let it expire! */
|
|
|
|
list_del_init(&timer->entry);
|
|
|
|
|
2008-12-31 15:11:41 +01:00
|
|
|
spin_unlock_irqrestore(&vq->lock, flags);
|
2005-04-17 00:20:36 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(del_virt_timer);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start the virtual CPU timer on the current CPU.
|
|
|
|
*/
|
|
|
|
void init_cpu_vtimer(void)
|
|
|
|
{
|
2008-12-31 15:11:41 +01:00
|
|
|
struct vtimer_queue *vq;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2008-12-31 15:11:41 +01:00
|
|
|
/* initialize per cpu vtimer structure */
|
|
|
|
vq = &__get_cpu_var(virt_cpu_timer);
|
|
|
|
INIT_LIST_HEAD(&vq->list);
|
|
|
|
spin_lock_init(&vq->lock);
|
2007-02-05 21:18:19 +01:00
|
|
|
|
|
|
|
/* enable cpu timer interrupts */
|
|
|
|
__ctl_set_bit(0,10);
|
2012-03-11 16:59:26 +01:00
|
|
|
|
|
|
|
/* set initial cpu timer */
|
|
|
|
set_vtimer(0x7fffffffffffffffULL);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
2010-12-01 10:08:01 +01:00
|
|
|
static int __cpuinit s390_nohz_notify(struct notifier_block *self,
|
|
|
|
unsigned long action, void *hcpu)
|
|
|
|
{
|
|
|
|
struct s390_idle_data *idle;
|
|
|
|
long cpu = (long) hcpu;
|
|
|
|
|
|
|
|
idle = &per_cpu(s390_idle, cpu);
|
|
|
|
switch (action) {
|
|
|
|
case CPU_DYING:
|
|
|
|
case CPU_DYING_FROZEN:
|
|
|
|
idle->nohz_delay = 0;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return NOTIFY_OK;
|
|
|
|
}
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
void __init vtime_init(void)
|
|
|
|
{
|
|
|
|
/* request the cpu timer external interrupt */
|
2009-06-22 12:08:03 +02:00
|
|
|
if (register_external_interrupt(0x1005, do_cpu_timer_interrupt))
|
2005-04-17 00:20:36 +02:00
|
|
|
panic("Couldn't request external interrupt 0x1005");
|
|
|
|
|
2007-02-05 21:18:19 +01:00
|
|
|
/* Enable cpu timer interrupts on the boot cpu. */
|
2005-04-17 00:20:36 +02:00
|
|
|
init_cpu_vtimer();
|
2010-12-01 10:08:01 +01:00
|
|
|
cpu_notifier(s390_nohz_notify, 0);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|