2005-04-16 16:20:36 -06:00
|
|
|
/* time.c: FRV arch-specific time handling
|
|
|
|
*
|
|
|
|
* Copyright (C) 2003-5 Red Hat, Inc. All Rights Reserved.
|
|
|
|
* Written by David Howells (dhowells@redhat.com)
|
|
|
|
* - Derived from arch/m68k/kernel/time.c
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version
|
|
|
|
* 2 of the License, or (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/param.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/profile.h>
|
|
|
|
#include <linux/irq.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/timer-regs.h>
|
|
|
|
#include <asm/mb-regs.h>
|
|
|
|
#include <asm/mb86943a.h>
|
|
|
|
|
|
|
|
#include <linux/timex.h>
|
|
|
|
|
|
|
|
#define TICK_SIZE (tick_nsec / 1000)
|
|
|
|
|
|
|
|
unsigned long __nongprelbss __clkin_clock_speed_HZ;
|
|
|
|
unsigned long __nongprelbss __ext_bus_clock_speed_HZ;
|
|
|
|
unsigned long __nongprelbss __res_bus_clock_speed_HZ;
|
|
|
|
unsigned long __nongprelbss __sdram_clock_speed_HZ;
|
|
|
|
unsigned long __nongprelbss __core_bus_clock_speed_HZ;
|
|
|
|
unsigned long __nongprelbss __core_clock_speed_HZ;
|
|
|
|
unsigned long __nongprelbss __dsu_clock_speed_HZ;
|
|
|
|
unsigned long __nongprelbss __serial_clock_speed_HZ;
|
|
|
|
unsigned long __delay_loops_MHz;
|
|
|
|
|
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 07:55:46 -06:00
|
|
|
static irqreturn_t timer_interrupt(int irq, void *dummy);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
static struct irqaction timer_irq = {
|
2007-10-16 02:26:29 -06:00
|
|
|
.handler = timer_interrupt,
|
|
|
|
.flags = IRQF_DISABLED,
|
|
|
|
.mask = CPU_MASK_NONE,
|
|
|
|
.name = "timer",
|
2005-04-16 16:20:36 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
static inline int set_rtc_mmss(unsigned long nowtime)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* timer_interrupt() needs to keep up the real-time clock,
|
|
|
|
* as well as call the "do_timer()" routine every clocktick
|
|
|
|
*/
|
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 07:55:46 -06:00
|
|
|
static irqreturn_t timer_interrupt(int irq, void *dummy)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
/* last time the cmos clock got updated */
|
|
|
|
static long last_rtc_update = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Here we are in the timer irq handler. We just have irqs locally
|
|
|
|
* disabled but we don't know if the timer_bh is running on the other
|
2007-10-19 17:09:42 -06:00
|
|
|
* CPU. We need to avoid to SMP race with it. NOTE: we don't need
|
2005-04-16 16:20:36 -06:00
|
|
|
* the irq version of write_lock because as just said we have irq
|
|
|
|
* locally disabled. -arca
|
|
|
|
*/
|
|
|
|
write_seqlock(&xtime_lock);
|
|
|
|
|
2006-09-29 03:00:32 -06:00
|
|
|
do_timer(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 07:55:46 -06:00
|
|
|
update_process_times(user_mode(get_irq_regs()));
|
|
|
|
profile_tick(CPU_PROFILING);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we have an externally synchronized Linux clock, then update
|
|
|
|
* CMOS clock accordingly every ~11 minutes. Set_rtc_mmss() has to be
|
|
|
|
* called as close as possible to 500 ms before the new second starts.
|
|
|
|
*/
|
2005-09-06 16:17:46 -06:00
|
|
|
if (ntp_synced() &&
|
2005-04-16 16:20:36 -06:00
|
|
|
xtime.tv_sec > last_rtc_update + 660 &&
|
|
|
|
(xtime.tv_nsec / 1000) >= 500000 - ((unsigned) TICK_SIZE) / 2 &&
|
|
|
|
(xtime.tv_nsec / 1000) <= 500000 + ((unsigned) TICK_SIZE) / 2
|
|
|
|
) {
|
|
|
|
if (set_rtc_mmss(xtime.tv_sec) == 0)
|
|
|
|
last_rtc_update = xtime.tv_sec;
|
|
|
|
else
|
|
|
|
last_rtc_update = xtime.tv_sec - 600; /* do it again in 60 s */
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_HEARTBEAT
|
|
|
|
static unsigned short n;
|
|
|
|
n++;
|
|
|
|
__set_LEDS(n);
|
|
|
|
#endif /* CONFIG_HEARTBEAT */
|
|
|
|
|
|
|
|
write_sequnlock(&xtime_lock);
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void time_divisor_init(void)
|
|
|
|
{
|
|
|
|
unsigned short base, pre, prediv;
|
|
|
|
|
|
|
|
/* set the scheduling timer going */
|
|
|
|
pre = 1;
|
|
|
|
prediv = 4;
|
|
|
|
base = __res_bus_clock_speed_HZ / pre / HZ / (1 << prediv);
|
|
|
|
|
|
|
|
__set_TPRV(pre);
|
|
|
|
__set_TxCKSL_DATA(0, prediv);
|
|
|
|
__set_TCTR(TCTR_SC_CTR0 | TCTR_RL_RW_LH8 | TCTR_MODE_2);
|
|
|
|
__set_TCSR_DATA(0, base & 0xff);
|
|
|
|
__set_TCSR_DATA(0, base >> 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
void time_init(void)
|
|
|
|
{
|
|
|
|
unsigned int year, mon, day, hour, min, sec;
|
|
|
|
|
|
|
|
extern void arch_gettod(int *year, int *mon, int *day, int *hour, int *min, int *sec);
|
|
|
|
|
|
|
|
/* FIX by dqg : Set to zero for platforms that don't have tod */
|
|
|
|
/* without this time is undefined and can overflow time_t, causing */
|
2007-10-19 17:09:42 -06:00
|
|
|
/* very strange errors */
|
2005-04-16 16:20:36 -06:00
|
|
|
year = 1980;
|
|
|
|
mon = day = 1;
|
|
|
|
hour = min = sec = 0;
|
|
|
|
arch_gettod (&year, &mon, &day, &hour, &min, &sec);
|
|
|
|
|
|
|
|
if ((year += 1900) < 1970)
|
|
|
|
year += 100;
|
|
|
|
xtime.tv_sec = mktime(year, mon, day, hour, min, sec);
|
|
|
|
xtime.tv_nsec = 0;
|
|
|
|
|
|
|
|
/* install scheduling interrupt handler */
|
|
|
|
setup_irq(IRQ_CPU_TIMER0, &timer_irq);
|
|
|
|
|
|
|
|
time_divisor_init();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Scheduler clock - returns current time in nanosec units.
|
|
|
|
*/
|
|
|
|
unsigned long long sched_clock(void)
|
|
|
|
{
|
|
|
|
return jiffies_64 * (1000000000 / HZ);
|
|
|
|
}
|