2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* linux/arch/ia64/kernel/time.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 1998-2003 Hewlett-Packard Co
|
|
|
|
* Stephane Eranian <eranian@hpl.hp.com>
|
|
|
|
* David Mosberger <davidm@hpl.hp.com>
|
|
|
|
* Copyright (C) 1999 Don Dugger <don.dugger@intel.com>
|
|
|
|
* Copyright (C) 1999-2000 VA Linux Systems
|
|
|
|
* Copyright (C) 1999-2000 Walt Drummond <drummond@valinux.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/cpu.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/profile.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/time.h>
|
2017-02-09 01:51:31 +08:00
|
|
|
#include <linux/nmi.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/efi.h>
|
|
|
|
#include <linux/timex.h>
|
2012-09-05 03:27:48 +08:00
|
|
|
#include <linux/timekeeper_internal.h>
|
2009-04-01 06:24:48 +08:00
|
|
|
#include <linux/platform_device.h>
|
2017-02-05 18:48:36 +08:00
|
|
|
#include <linux/sched/cputime.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include <asm/machvec.h>
|
|
|
|
#include <asm/delay.h>
|
|
|
|
#include <asm/hw_irq.h>
|
|
|
|
#include <asm/ptrace.h>
|
|
|
|
#include <asm/sal.h>
|
|
|
|
#include <asm/sections.h>
|
|
|
|
|
2007-07-21 02:22:30 +08:00
|
|
|
#include "fsyscall_gtod_data.h"
|
|
|
|
|
2016-12-22 03:32:01 +08:00
|
|
|
static u64 itc_get_cycles(struct clocksource *cs);
|
2007-07-21 02:22:30 +08:00
|
|
|
|
2012-02-29 03:46:05 +08:00
|
|
|
struct fsyscall_gtod_data_t fsyscall_gtod_data;
|
2007-07-21 02:22:30 +08:00
|
|
|
|
|
|
|
struct itc_jitter_data_t itc_jitter_data;
|
|
|
|
|
2005-11-12 06:32:40 +08:00
|
|
|
volatile int time_keeper_id = 0; /* smp_processor_id() of time-keeper */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_IA64_DEBUG_IRQ
|
|
|
|
|
|
|
|
unsigned long last_cli_ip;
|
|
|
|
EXPORT_SYMBOL(last_cli_ip);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2007-07-21 02:22:30 +08:00
|
|
|
static struct clocksource clocksource_itc = {
|
2008-02-08 20:19:25 +08:00
|
|
|
.name = "itc",
|
|
|
|
.rating = 350,
|
|
|
|
.read = itc_get_cycles,
|
|
|
|
.mask = CLOCKSOURCE_MASK(64),
|
|
|
|
.flags = CLOCK_SOURCE_IS_CONTINUOUS,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
2007-07-21 02:22:30 +08:00
|
|
|
static struct clocksource *itc_clocksource;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-07-25 13:56:04 +08:00
|
|
|
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
|
2008-01-29 13:27:30 +08:00
|
|
|
|
|
|
|
#include <linux/kernel_stat.h>
|
|
|
|
|
2017-01-31 11:09:45 +08:00
|
|
|
extern u64 cycle_to_nsec(u64 cyc);
|
2008-01-29 13:27:30 +08:00
|
|
|
|
2017-01-06 01:11:50 +08:00
|
|
|
void vtime_flush(struct task_struct *tsk)
|
2012-09-09 00:00:02 +08:00
|
|
|
{
|
|
|
|
struct thread_info *ti = task_thread_info(tsk);
|
2017-01-31 11:09:40 +08:00
|
|
|
u64 delta;
|
2012-09-09 00:00:02 +08:00
|
|
|
|
2017-01-06 01:11:48 +08:00
|
|
|
if (ti->utime)
|
2017-01-31 11:09:45 +08:00
|
|
|
account_user_time(tsk, cycle_to_nsec(ti->utime));
|
2017-01-06 01:11:48 +08:00
|
|
|
|
|
|
|
if (ti->gtime)
|
2017-01-31 11:09:45 +08:00
|
|
|
account_guest_time(tsk, cycle_to_nsec(ti->gtime));
|
2017-01-06 01:11:48 +08:00
|
|
|
|
|
|
|
if (ti->idle_time)
|
2017-01-31 11:09:45 +08:00
|
|
|
account_idle_time(cycle_to_nsec(ti->idle_time));
|
2017-01-06 01:11:48 +08:00
|
|
|
|
|
|
|
if (ti->stime) {
|
2017-01-31 11:09:45 +08:00
|
|
|
delta = cycle_to_nsec(ti->stime);
|
2017-01-06 01:11:48 +08:00
|
|
|
account_system_index_time(tsk, delta, CPUTIME_SYSTEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ti->hardirq_time) {
|
2017-01-31 11:09:45 +08:00
|
|
|
delta = cycle_to_nsec(ti->hardirq_time);
|
2017-01-06 01:11:48 +08:00
|
|
|
account_system_index_time(tsk, delta, CPUTIME_IRQ);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ti->softirq_time) {
|
2017-01-31 11:09:45 +08:00
|
|
|
delta = cycle_to_nsec(ti->softirq_time));
|
2017-01-06 01:11:48 +08:00
|
|
|
account_system_index_time(tsk, delta, CPUTIME_SOFTIRQ);
|
2012-09-09 00:00:02 +08:00
|
|
|
}
|
2017-01-06 01:11:48 +08:00
|
|
|
|
|
|
|
ti->utime = 0;
|
|
|
|
ti->gtime = 0;
|
|
|
|
ti->idle_time = 0;
|
|
|
|
ti->stime = 0;
|
|
|
|
ti->hardirq_time = 0;
|
|
|
|
ti->softirq_time = 0;
|
2012-09-09 00:00:02 +08:00
|
|
|
}
|
|
|
|
|
2008-01-29 13:27:30 +08:00
|
|
|
/*
|
|
|
|
* Called from the context switch with interrupts disabled, to charge all
|
|
|
|
* accumulated times to the current process, and to prepare accounting on
|
|
|
|
* the next process.
|
|
|
|
*/
|
2012-11-14 07:24:25 +08:00
|
|
|
void arch_vtime_task_switch(struct task_struct *prev)
|
2008-01-29 13:27:30 +08:00
|
|
|
{
|
|
|
|
struct thread_info *pi = task_thread_info(prev);
|
2012-06-18 23:54:14 +08:00
|
|
|
struct thread_info *ni = task_thread_info(current);
|
2008-01-29 13:27:30 +08:00
|
|
|
|
2017-01-06 01:11:42 +08:00
|
|
|
ni->ac_stamp = pi->ac_stamp;
|
2008-01-29 13:27:30 +08:00
|
|
|
ni->ac_stime = ni->ac_utime = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Account time for a transition between system, hard irq or soft irq state.
|
|
|
|
* Note that this function is called with interrupts enabled.
|
|
|
|
*/
|
2017-01-06 01:11:48 +08:00
|
|
|
static __u64 vtime_delta(struct task_struct *tsk)
|
2008-01-29 13:27:30 +08:00
|
|
|
{
|
|
|
|
struct thread_info *ti = task_thread_info(tsk);
|
2017-01-06 01:11:48 +08:00
|
|
|
__u64 now, delta_stime;
|
2008-01-29 13:27:30 +08:00
|
|
|
|
2012-11-20 00:00:24 +08:00
|
|
|
WARN_ON_ONCE(!irqs_disabled());
|
|
|
|
|
2008-01-29 13:27:30 +08:00
|
|
|
now = ia64_get_itc();
|
2017-01-06 01:11:48 +08:00
|
|
|
delta_stime = now - ti->ac_stamp;
|
2008-01-29 13:27:30 +08:00
|
|
|
ti->ac_stamp = now;
|
|
|
|
|
2012-09-08 22:14:02 +08:00
|
|
|
return delta_stime;
|
|
|
|
}
|
|
|
|
|
2012-11-14 01:21:22 +08:00
|
|
|
void vtime_account_system(struct task_struct *tsk)
|
2012-09-08 22:14:02 +08:00
|
|
|
{
|
2017-01-06 01:11:48 +08:00
|
|
|
struct thread_info *ti = task_thread_info(tsk);
|
|
|
|
__u64 stime = vtime_delta(tsk);
|
|
|
|
|
|
|
|
if ((tsk->flags & PF_VCPU) && !irq_count())
|
|
|
|
ti->gtime += stime;
|
|
|
|
else if (hardirq_count())
|
|
|
|
ti->hardirq_time += stime;
|
|
|
|
else if (in_serving_softirq())
|
|
|
|
ti->softirq_time += stime;
|
|
|
|
else
|
|
|
|
ti->stime += stime;
|
2012-09-08 22:14:02 +08:00
|
|
|
}
|
2013-01-21 07:50:22 +08:00
|
|
|
EXPORT_SYMBOL_GPL(vtime_account_system);
|
2012-09-08 22:14:02 +08:00
|
|
|
|
2012-11-14 01:21:22 +08:00
|
|
|
void vtime_account_idle(struct task_struct *tsk)
|
2012-09-08 22:14:02 +08:00
|
|
|
{
|
2017-01-06 01:11:48 +08:00
|
|
|
struct thread_info *ti = task_thread_info(tsk);
|
|
|
|
|
|
|
|
ti->idle_time += vtime_delta(tsk);
|
2008-01-29 13:27:30 +08:00
|
|
|
}
|
|
|
|
|
2012-07-25 13:56:04 +08:00
|
|
|
#endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
|
2008-01-29 13:27:30 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static irqreturn_t
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 21:55:46 +08:00
|
|
|
timer_interrupt (int irq, void *dev_id)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned long new_itm;
|
|
|
|
|
2010-12-10 15:16:55 +08:00
|
|
|
if (cpu_is_offline(smp_processor_id())) {
|
2005-04-17 06:20:36 +08:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 21:55:46 +08:00
|
|
|
platform_timer_interrupt(irq, dev_id);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
new_itm = local_cpu_data->itm_next;
|
|
|
|
|
|
|
|
if (!time_after(ia64_get_itc(), new_itm))
|
|
|
|
printk(KERN_ERR "Oops: timer tick before it's due (itc=%lx,itm=%lx)\n",
|
|
|
|
ia64_get_itc(), new_itm);
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 21:55:46 +08:00
|
|
|
profile_tick(CPU_PROFILING);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
while (1) {
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 21:55:46 +08:00
|
|
|
update_process_times(user_mode(get_irq_regs()));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
new_itm += local_cpu_data->itm_delta;
|
|
|
|
|
2011-01-27 22:59:56 +08:00
|
|
|
if (smp_processor_id() == time_keeper_id)
|
|
|
|
xtime_update(1);
|
|
|
|
|
|
|
|
local_cpu_data->itm_next = new_itm;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (time_after(new_itm, ia64_get_itc()))
|
|
|
|
break;
|
2006-10-17 01:56:54 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Allow IPIs to interrupt the timer loop.
|
|
|
|
*/
|
|
|
|
local_irq_enable();
|
|
|
|
local_irq_disable();
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
/*
|
|
|
|
* If we're too close to the next clock tick for
|
|
|
|
* comfort, we increase the safety margin by
|
|
|
|
* intentionally dropping the next tick(s). We do NOT
|
|
|
|
* update itm.next because that would force us to call
|
2011-01-27 22:59:56 +08:00
|
|
|
* xtime_update() which in turn would let our clock run
|
2005-04-17 06:20:36 +08:00
|
|
|
* too fast (with the potentially devastating effect
|
|
|
|
* of losing monotony of time).
|
|
|
|
*/
|
|
|
|
while (!time_after(new_itm, ia64_get_itc() + local_cpu_data->itm_delta/2))
|
|
|
|
new_itm += local_cpu_data->itm_delta;
|
|
|
|
ia64_set_itm(new_itm);
|
|
|
|
/* double check, in case we got hit by a (slow) PMI: */
|
|
|
|
} while (time_after_eq(ia64_get_itc(), new_itm));
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Encapsulate access to the itm structure for SMP.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ia64_cpu_local_tick (void)
|
|
|
|
{
|
|
|
|
int cpu = smp_processor_id();
|
|
|
|
unsigned long shift = 0, delta;
|
|
|
|
|
|
|
|
/* arrange for the cycle counter to generate a timer interrupt: */
|
|
|
|
ia64_set_itv(IA64_TIMER_VECTOR);
|
|
|
|
|
|
|
|
delta = local_cpu_data->itm_delta;
|
|
|
|
/*
|
|
|
|
* Stagger the timer tick for each CPU so they don't occur all at (almost) the
|
|
|
|
* same time:
|
|
|
|
*/
|
|
|
|
if (cpu) {
|
|
|
|
unsigned long hi = 1UL << ia64_fls(cpu);
|
|
|
|
shift = (2*(cpu - hi) + 1) * delta/hi/2;
|
|
|
|
}
|
|
|
|
local_cpu_data->itm_next = ia64_get_itc() + delta + shift;
|
|
|
|
ia64_set_itm(local_cpu_data->itm_next);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int nojitter;
|
|
|
|
|
|
|
|
static int __init nojitter_setup(char *str)
|
|
|
|
{
|
|
|
|
nojitter = 1;
|
|
|
|
printk("Jitter checking for ITC timers disabled\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
__setup("nojitter", nojitter_setup);
|
|
|
|
|
|
|
|
|
2012-12-22 06:05:13 +08:00
|
|
|
void ia64_init_itm(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned long platform_base_freq, itc_freq;
|
|
|
|
struct pal_freq_ratio itc_ratio, proc_ratio;
|
|
|
|
long status, platform_base_drift, itc_drift;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* According to SAL v2.6, we need to use a SAL call to determine the platform base
|
|
|
|
* frequency and then a PAL call to determine the frequency ratio between the ITC
|
|
|
|
* and the base frequency.
|
|
|
|
*/
|
|
|
|
status = ia64_sal_freq_base(SAL_FREQ_BASE_PLATFORM,
|
|
|
|
&platform_base_freq, &platform_base_drift);
|
|
|
|
if (status != 0) {
|
|
|
|
printk(KERN_ERR "SAL_FREQ_BASE_PLATFORM failed: %s\n", ia64_sal_strerror(status));
|
|
|
|
} else {
|
|
|
|
status = ia64_pal_freq_ratios(&proc_ratio, NULL, &itc_ratio);
|
|
|
|
if (status != 0)
|
|
|
|
printk(KERN_ERR "PAL_FREQ_RATIOS failed with status=%ld\n", status);
|
|
|
|
}
|
|
|
|
if (status != 0) {
|
|
|
|
/* invent "random" values */
|
|
|
|
printk(KERN_ERR
|
|
|
|
"SAL/PAL failed to obtain frequency info---inventing reasonable values\n");
|
|
|
|
platform_base_freq = 100000000;
|
|
|
|
platform_base_drift = -1; /* no drift info */
|
|
|
|
itc_ratio.num = 3;
|
|
|
|
itc_ratio.den = 1;
|
|
|
|
}
|
|
|
|
if (platform_base_freq < 40000000) {
|
|
|
|
printk(KERN_ERR "Platform base frequency %lu bogus---resetting to 75MHz!\n",
|
|
|
|
platform_base_freq);
|
|
|
|
platform_base_freq = 75000000;
|
|
|
|
platform_base_drift = -1;
|
|
|
|
}
|
|
|
|
if (!proc_ratio.den)
|
|
|
|
proc_ratio.den = 1; /* avoid division by zero */
|
|
|
|
if (!itc_ratio.den)
|
|
|
|
itc_ratio.den = 1; /* avoid division by zero */
|
|
|
|
|
|
|
|
itc_freq = (platform_base_freq*itc_ratio.num)/itc_ratio.den;
|
|
|
|
|
|
|
|
local_cpu_data->itm_delta = (itc_freq + HZ/2) / HZ;
|
2006-04-01 02:28:29 +08:00
|
|
|
printk(KERN_DEBUG "CPU %d: base freq=%lu.%03luMHz, ITC ratio=%u/%u, "
|
2005-04-17 06:20:36 +08:00
|
|
|
"ITC freq=%lu.%03luMHz", smp_processor_id(),
|
|
|
|
platform_base_freq / 1000000, (platform_base_freq / 1000) % 1000,
|
|
|
|
itc_ratio.num, itc_ratio.den, itc_freq / 1000000, (itc_freq / 1000) % 1000);
|
|
|
|
|
|
|
|
if (platform_base_drift != -1) {
|
|
|
|
itc_drift = platform_base_drift*itc_ratio.num/itc_ratio.den;
|
|
|
|
printk("+/-%ldppm\n", itc_drift);
|
|
|
|
} else {
|
|
|
|
itc_drift = -1;
|
|
|
|
printk("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
local_cpu_data->proc_freq = (platform_base_freq*proc_ratio.num)/proc_ratio.den;
|
|
|
|
local_cpu_data->itc_freq = itc_freq;
|
|
|
|
local_cpu_data->cyc_per_usec = (itc_freq + USEC_PER_SEC/2) / USEC_PER_SEC;
|
|
|
|
local_cpu_data->nsec_per_cyc = ((NSEC_PER_SEC<<IA64_NSEC_PER_CYC_SHIFT)
|
|
|
|
+ itc_freq/2)/itc_freq;
|
|
|
|
|
|
|
|
if (!(sal_platform_features & IA64_SAL_PLATFORM_FEATURE_ITC_DRIFT)) {
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/* On IA64 in an SMP configuration ITCs are never accurately synchronized.
|
|
|
|
* Jitter compensation requires a cmpxchg which may limit
|
|
|
|
* the scalability of the syscalls for retrieving time.
|
|
|
|
* The ITC synchronization is usually successful to within a few
|
|
|
|
* ITC ticks but this is not a sure thing. If you need to improve
|
|
|
|
* timer performance in SMP situations then boot the kernel with the
|
|
|
|
* "nojitter" option. However, doing so may result in time fluctuating (maybe
|
|
|
|
* even going backward) if the ITC offsets between the individual CPUs
|
|
|
|
* are too large.
|
|
|
|
*/
|
2007-07-21 02:22:30 +08:00
|
|
|
if (!nojitter)
|
|
|
|
itc_jitter_data.itc_jitter = 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
2007-08-02 04:49:45 +08:00
|
|
|
} else
|
|
|
|
/*
|
|
|
|
* ITC is drifty and we have not synchronized the ITCs in smpboot.c.
|
|
|
|
* ITC values may fluctuate significantly between processors.
|
|
|
|
* Clock should not be used for hrtimers. Mark itc as only
|
|
|
|
* useful for boot and testing.
|
|
|
|
*
|
|
|
|
* Note that jitter compensation is off! There is no point of
|
|
|
|
* synchronizing ITCs since they may be large differentials
|
|
|
|
* that change over time.
|
|
|
|
*
|
|
|
|
* The only way to fix this would be to repeatedly sync the
|
|
|
|
* ITCs. Until that time we have to avoid ITC.
|
|
|
|
*/
|
|
|
|
clocksource_itc.rating = 50;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-05-19 21:13:44 +08:00
|
|
|
/* avoid softlock up message when cpu is unplug and plugged again. */
|
|
|
|
touch_softlockup_watchdog();
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Setup the CPU local timer tick */
|
|
|
|
ia64_cpu_local_tick();
|
2007-07-21 02:22:30 +08:00
|
|
|
|
|
|
|
if (!itc_clocksource) {
|
2010-04-27 11:20:47 +08:00
|
|
|
clocksource_register_hz(&clocksource_itc,
|
|
|
|
local_cpu_data->itc_freq);
|
2007-07-21 02:22:30 +08:00
|
|
|
itc_clocksource = &clocksource_itc;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2016-12-22 03:32:01 +08:00
|
|
|
static u64 itc_get_cycles(struct clocksource *cs)
|
2007-07-21 02:22:30 +08:00
|
|
|
{
|
2009-05-23 04:49:49 +08:00
|
|
|
unsigned long lcycle, now, ret;
|
2007-07-21 02:22:30 +08:00
|
|
|
|
|
|
|
if (!itc_jitter_data.itc_jitter)
|
|
|
|
return get_cycles();
|
|
|
|
|
|
|
|
lcycle = itc_jitter_data.itc_lastcycle;
|
|
|
|
now = get_cycles();
|
|
|
|
if (lcycle && time_after(lcycle, now))
|
|
|
|
return lcycle;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Keep track of the last timer value returned.
|
|
|
|
* In an SMP environment, you could lose out in contention of
|
|
|
|
* cmpxchg. If so, your cmpxchg returns new value which the
|
|
|
|
* winner of contention updated to. Use the new value instead.
|
|
|
|
*/
|
|
|
|
ret = cmpxchg(&itc_jitter_data.itc_lastcycle, lcycle, now);
|
|
|
|
if (unlikely(ret != lcycle))
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return now;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static struct irqaction timer_irqaction = {
|
|
|
|
.handler = timer_interrupt,
|
2014-03-05 04:29:13 +08:00
|
|
|
.flags = IRQF_IRQPOLL,
|
2005-04-17 06:20:36 +08:00
|
|
|
.name = "timer"
|
|
|
|
};
|
|
|
|
|
2016-06-17 22:48:17 +08:00
|
|
|
void read_persistent_clock64(struct timespec64 *ts)
|
2010-03-04 11:57:22 +08:00
|
|
|
{
|
|
|
|
efi_gettimeofday(ts);
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
void __init
|
|
|
|
time_init (void)
|
|
|
|
{
|
|
|
|
register_percpu_irq(IA64_TIMER_VECTOR, &timer_irqaction);
|
|
|
|
ia64_init_itm();
|
|
|
|
}
|
2005-12-17 02:00:24 +08:00
|
|
|
|
2006-02-15 02:40:17 +08:00
|
|
|
/*
|
|
|
|
* Generic udelay assumes that if preemption is allowed and the thread
|
|
|
|
* migrates to another CPU, that the ITC values are synchronized across
|
|
|
|
* all CPUs.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ia64_itc_udelay (unsigned long usecs)
|
2005-12-17 02:00:24 +08:00
|
|
|
{
|
2006-02-15 02:40:17 +08:00
|
|
|
unsigned long start = ia64_get_itc();
|
|
|
|
unsigned long end = start + usecs*local_cpu_data->cyc_per_usec;
|
2005-12-17 02:00:24 +08:00
|
|
|
|
2006-02-15 02:40:17 +08:00
|
|
|
while (time_before(ia64_get_itc(), end))
|
|
|
|
cpu_relax();
|
|
|
|
}
|
2005-12-17 02:00:24 +08:00
|
|
|
|
2006-02-15 02:40:17 +08:00
|
|
|
void (*ia64_udelay)(unsigned long usecs) = &ia64_itc_udelay;
|
2005-12-17 02:00:24 +08:00
|
|
|
|
2006-02-15 02:40:17 +08:00
|
|
|
void
|
|
|
|
udelay (unsigned long usecs)
|
|
|
|
{
|
|
|
|
(*ia64_udelay)(usecs);
|
2005-12-17 02:00:24 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(udelay);
|
2006-02-08 07:25:57 +08:00
|
|
|
|
2007-10-18 18:04:57 +08:00
|
|
|
/* IA64 doesn't cache the timezone */
|
|
|
|
void update_vsyscall_tz(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-09-05 03:34:21 +08:00
|
|
|
void update_vsyscall_old(struct timespec *wall, struct timespec *wtm,
|
2016-12-22 03:32:01 +08:00
|
|
|
struct clocksource *c, u32 mult, u64 cycle_last)
|
2007-07-21 02:22:30 +08:00
|
|
|
{
|
2012-02-29 03:46:05 +08:00
|
|
|
write_seqcount_begin(&fsyscall_gtod_data.seq);
|
2007-07-21 02:22:30 +08:00
|
|
|
|
|
|
|
/* copy fsyscall clock data */
|
|
|
|
fsyscall_gtod_data.clk_mask = c->mask;
|
2009-11-17 13:49:50 +08:00
|
|
|
fsyscall_gtod_data.clk_mult = mult;
|
2007-07-21 02:22:30 +08:00
|
|
|
fsyscall_gtod_data.clk_shift = c->shift;
|
2011-07-13 21:24:15 +08:00
|
|
|
fsyscall_gtod_data.clk_fsys_mmio = c->archdata.fsys_mmio;
|
2014-07-17 05:05:13 +08:00
|
|
|
fsyscall_gtod_data.clk_cycle_last = cycle_last;
|
2007-07-21 02:22:30 +08:00
|
|
|
|
|
|
|
/* copy kernel time structures */
|
|
|
|
fsyscall_gtod_data.wall_time.tv_sec = wall->tv_sec;
|
|
|
|
fsyscall_gtod_data.wall_time.tv_nsec = wall->tv_nsec;
|
2010-07-14 08:56:23 +08:00
|
|
|
fsyscall_gtod_data.monotonic_time.tv_sec = wtm->tv_sec
|
2007-07-21 02:22:30 +08:00
|
|
|
+ wall->tv_sec;
|
2010-07-14 08:56:23 +08:00
|
|
|
fsyscall_gtod_data.monotonic_time.tv_nsec = wtm->tv_nsec
|
2007-07-21 02:22:30 +08:00
|
|
|
+ wall->tv_nsec;
|
|
|
|
|
|
|
|
/* normalize */
|
|
|
|
while (fsyscall_gtod_data.monotonic_time.tv_nsec >= NSEC_PER_SEC) {
|
|
|
|
fsyscall_gtod_data.monotonic_time.tv_nsec -= NSEC_PER_SEC;
|
|
|
|
fsyscall_gtod_data.monotonic_time.tv_sec++;
|
|
|
|
}
|
|
|
|
|
2012-02-29 03:46:05 +08:00
|
|
|
write_seqcount_end(&fsyscall_gtod_data.seq);
|
2007-07-21 02:22:30 +08:00
|
|
|
}
|
|
|
|
|