Split of architecture-dependent and -independent functions for i386,
mainly in the kernel and headers. This split based on work by
Ingmar Alting <iaalting@cs.vu.nl> done for his Minix PowerPC architecture
port.
. kernel does not program the interrupt controller directly, do any
other architecture-dependent operations, or contain assembly any more,
but uses architecture-dependent functions in arch/$(ARCH)/.
. architecture-dependent constants and types defined in arch/$(ARCH)/include.
. <ibm/portio.h> moved to <minix/portio.h>, as they have become, for now,
architecture-independent functions.
. int86, sdevio, readbios, and iopenable are now i386-specific kernel calls
and live in arch/i386/do_* now.
. i386 arch now supports even less 86 code; e.g. mpx86.s and klib86.s have
gone, and 'machine.protected' is gone (and always taken to be 1 in i386).
If 86 support is to return, it should be a new architecture.
. prototypes for the architecture-dependent functions defined in
kernel/arch/$(ARCH)/*.c but used in kernel/ are in kernel/proto.h
. /etc/make.conf included in makefiles and shell scripts that need to
know the building architecture; it defines ARCH=<arch>, currently only
i386.
. some basic per-architecture build support outside of the kernel (lib)
. in clock.c, only dequeue a process if it was ready
. fixes for new include files
files deleted:
. mpx/klib.s - only for choosing between mpx/klib86 and -386
. klib86.s - only for 86
i386-specific files files moved (or arch-dependent stuff moved) to arch/i386/:
. mpx386.s (entry point)
. klib386.s
. sconst.h
. exception.c
. protect.c
. protect.h
. i8269.c
2006-12-22 16:22:27 +01:00
|
|
|
|
|
|
|
/* i386-specific clock functions. */
|
|
|
|
|
2010-03-08 12:04:59 +01:00
|
|
|
#include <machine/ports.h>
|
Split of architecture-dependent and -independent functions for i386,
mainly in the kernel and headers. This split based on work by
Ingmar Alting <iaalting@cs.vu.nl> done for his Minix PowerPC architecture
port.
. kernel does not program the interrupt controller directly, do any
other architecture-dependent operations, or contain assembly any more,
but uses architecture-dependent functions in arch/$(ARCH)/.
. architecture-dependent constants and types defined in arch/$(ARCH)/include.
. <ibm/portio.h> moved to <minix/portio.h>, as they have become, for now,
architecture-independent functions.
. int86, sdevio, readbios, and iopenable are now i386-specific kernel calls
and live in arch/i386/do_* now.
. i386 arch now supports even less 86 code; e.g. mpx86.s and klib86.s have
gone, and 'machine.protected' is gone (and always taken to be 1 in i386).
If 86 support is to return, it should be a new architecture.
. prototypes for the architecture-dependent functions defined in
kernel/arch/$(ARCH)/*.c but used in kernel/ are in kernel/proto.h
. /etc/make.conf included in makefiles and shell scripts that need to
know the building architecture; it defines ARCH=<arch>, currently only
i386.
. some basic per-architecture build support outside of the kernel (lib)
. in clock.c, only dequeue a process if it was ready
. fixes for new include files
files deleted:
. mpx/klib.s - only for choosing between mpx/klib86 and -386
. klib86.s - only for 86
i386-specific files files moved (or arch-dependent stuff moved) to arch/i386/:
. mpx386.s (entry point)
. klib386.s
. sconst.h
. exception.c
. protect.c
. protect.h
. i8269.c
2006-12-22 16:22:27 +01:00
|
|
|
#include <minix/portio.h>
|
|
|
|
|
2010-04-02 00:22:33 +02:00
|
|
|
#include "kernel/kernel.h"
|
Split of architecture-dependent and -independent functions for i386,
mainly in the kernel and headers. This split based on work by
Ingmar Alting <iaalting@cs.vu.nl> done for his Minix PowerPC architecture
port.
. kernel does not program the interrupt controller directly, do any
other architecture-dependent operations, or contain assembly any more,
but uses architecture-dependent functions in arch/$(ARCH)/.
. architecture-dependent constants and types defined in arch/$(ARCH)/include.
. <ibm/portio.h> moved to <minix/portio.h>, as they have become, for now,
architecture-independent functions.
. int86, sdevio, readbios, and iopenable are now i386-specific kernel calls
and live in arch/i386/do_* now.
. i386 arch now supports even less 86 code; e.g. mpx86.s and klib86.s have
gone, and 'machine.protected' is gone (and always taken to be 1 in i386).
If 86 support is to return, it should be a new architecture.
. prototypes for the architecture-dependent functions defined in
kernel/arch/$(ARCH)/*.c but used in kernel/ are in kernel/proto.h
. /etc/make.conf included in makefiles and shell scripts that need to
know the building architecture; it defines ARCH=<arch>, currently only
i386.
. some basic per-architecture build support outside of the kernel (lib)
. in clock.c, only dequeue a process if it was ready
. fixes for new include files
files deleted:
. mpx/klib.s - only for choosing between mpx/klib86 and -386
. klib86.s - only for 86
i386-specific files files moved (or arch-dependent stuff moved) to arch/i386/:
. mpx386.s (entry point)
. klib386.s
. sconst.h
. exception.c
. protect.c
. protect.h
. i8269.c
2006-12-22 16:22:27 +01:00
|
|
|
|
2010-04-02 00:22:33 +02:00
|
|
|
#include "kernel/clock.h"
|
|
|
|
#include "kernel/proc.h"
|
2010-02-10 16:36:54 +01:00
|
|
|
#include <minix/u64.h>
|
2010-09-15 16:09:52 +02:00
|
|
|
#include "glo.h"
|
2010-02-10 16:36:54 +01:00
|
|
|
|
2009-11-06 10:04:15 +01:00
|
|
|
|
2009-11-16 22:41:44 +01:00
|
|
|
#ifdef CONFIG_APIC
|
|
|
|
#include "apic.h"
|
|
|
|
#endif
|
|
|
|
|
Split of architecture-dependent and -independent functions for i386,
mainly in the kernel and headers. This split based on work by
Ingmar Alting <iaalting@cs.vu.nl> done for his Minix PowerPC architecture
port.
. kernel does not program the interrupt controller directly, do any
other architecture-dependent operations, or contain assembly any more,
but uses architecture-dependent functions in arch/$(ARCH)/.
. architecture-dependent constants and types defined in arch/$(ARCH)/include.
. <ibm/portio.h> moved to <minix/portio.h>, as they have become, for now,
architecture-independent functions.
. int86, sdevio, readbios, and iopenable are now i386-specific kernel calls
and live in arch/i386/do_* now.
. i386 arch now supports even less 86 code; e.g. mpx86.s and klib86.s have
gone, and 'machine.protected' is gone (and always taken to be 1 in i386).
If 86 support is to return, it should be a new architecture.
. prototypes for the architecture-dependent functions defined in
kernel/arch/$(ARCH)/*.c but used in kernel/ are in kernel/proto.h
. /etc/make.conf included in makefiles and shell scripts that need to
know the building architecture; it defines ARCH=<arch>, currently only
i386.
. some basic per-architecture build support outside of the kernel (lib)
. in clock.c, only dequeue a process if it was ready
. fixes for new include files
files deleted:
. mpx/klib.s - only for choosing between mpx/klib86 and -386
. klib86.s - only for 86
i386-specific files files moved (or arch-dependent stuff moved) to arch/i386/:
. mpx386.s (entry point)
. klib386.s
. sconst.h
. exception.c
. protect.c
. protect.h
. i8269.c
2006-12-22 16:22:27 +01:00
|
|
|
#define CLOCK_ACK_BIT 0x80 /* PS/2 clock interrupt acknowledge bit */
|
|
|
|
|
|
|
|
/* Clock parameters. */
|
|
|
|
#define COUNTER_FREQ (2*TIMER_FREQ) /* counter frequency using square wave */
|
|
|
|
#define LATCH_COUNT 0x00 /* cc00xxxx, c = channel, x = any */
|
|
|
|
#define SQUARE_WAVE 0x36 /* ccaammmb, a = access, m = mode, b = BCD */
|
|
|
|
/* 11x11, 11 = LSB then MSB, x11 = sq wave */
|
|
|
|
#define TIMER_FREQ 1193182 /* clock frequency for timer in PC and AT */
|
2009-11-06 10:04:15 +01:00
|
|
|
#define TIMER_COUNT(freq) (TIMER_FREQ/(freq)) /* initial value for counter*/
|
|
|
|
|
2010-02-10 16:36:54 +01:00
|
|
|
/* FIXME make it cpu local! */
|
|
|
|
PRIVATE u64_t tsc_ctr_switch; /* when did we switched time accounting */
|
|
|
|
|
2009-11-06 10:04:15 +01:00
|
|
|
PRIVATE irq_hook_t pic_timer_hook; /* interrupt handler hook */
|
Split of architecture-dependent and -independent functions for i386,
mainly in the kernel and headers. This split based on work by
Ingmar Alting <iaalting@cs.vu.nl> done for his Minix PowerPC architecture
port.
. kernel does not program the interrupt controller directly, do any
other architecture-dependent operations, or contain assembly any more,
but uses architecture-dependent functions in arch/$(ARCH)/.
. architecture-dependent constants and types defined in arch/$(ARCH)/include.
. <ibm/portio.h> moved to <minix/portio.h>, as they have become, for now,
architecture-independent functions.
. int86, sdevio, readbios, and iopenable are now i386-specific kernel calls
and live in arch/i386/do_* now.
. i386 arch now supports even less 86 code; e.g. mpx86.s and klib86.s have
gone, and 'machine.protected' is gone (and always taken to be 1 in i386).
If 86 support is to return, it should be a new architecture.
. prototypes for the architecture-dependent functions defined in
kernel/arch/$(ARCH)/*.c but used in kernel/ are in kernel/proto.h
. /etc/make.conf included in makefiles and shell scripts that need to
know the building architecture; it defines ARCH=<arch>, currently only
i386.
. some basic per-architecture build support outside of the kernel (lib)
. in clock.c, only dequeue a process if it was ready
. fixes for new include files
files deleted:
. mpx/klib.s - only for choosing between mpx/klib86 and -386
. klib86.s - only for 86
i386-specific files files moved (or arch-dependent stuff moved) to arch/i386/:
. mpx386.s (entry point)
. klib386.s
. sconst.h
. exception.c
. protect.c
. protect.h
. i8269.c
2006-12-22 16:22:27 +01:00
|
|
|
|
2010-05-25 10:06:14 +02:00
|
|
|
PRIVATE unsigned probe_ticks;
|
|
|
|
PRIVATE u64_t tsc0, tsc1;
|
|
|
|
#define PROBE_TICKS (system_hz / 10)
|
|
|
|
|
|
|
|
PRIVATE unsigned tsc_per_ms[CONFIG_MAX_CPUS];
|
|
|
|
|
Split of architecture-dependent and -independent functions for i386,
mainly in the kernel and headers. This split based on work by
Ingmar Alting <iaalting@cs.vu.nl> done for his Minix PowerPC architecture
port.
. kernel does not program the interrupt controller directly, do any
other architecture-dependent operations, or contain assembly any more,
but uses architecture-dependent functions in arch/$(ARCH)/.
. architecture-dependent constants and types defined in arch/$(ARCH)/include.
. <ibm/portio.h> moved to <minix/portio.h>, as they have become, for now,
architecture-independent functions.
. int86, sdevio, readbios, and iopenable are now i386-specific kernel calls
and live in arch/i386/do_* now.
. i386 arch now supports even less 86 code; e.g. mpx86.s and klib86.s have
gone, and 'machine.protected' is gone (and always taken to be 1 in i386).
If 86 support is to return, it should be a new architecture.
. prototypes for the architecture-dependent functions defined in
kernel/arch/$(ARCH)/*.c but used in kernel/ are in kernel/proto.h
. /etc/make.conf included in makefiles and shell scripts that need to
know the building architecture; it defines ARCH=<arch>, currently only
i386.
. some basic per-architecture build support outside of the kernel (lib)
. in clock.c, only dequeue a process if it was ready
. fixes for new include files
files deleted:
. mpx/klib.s - only for choosing between mpx/klib86 and -386
. klib86.s - only for 86
i386-specific files files moved (or arch-dependent stuff moved) to arch/i386/:
. mpx386.s (entry point)
. klib386.s
. sconst.h
. exception.c
. protect.c
. protect.h
. i8269.c
2006-12-22 16:22:27 +01:00
|
|
|
/*===========================================================================*
|
2009-11-06 10:04:15 +01:00
|
|
|
* init_8235A_timer *
|
Split of architecture-dependent and -independent functions for i386,
mainly in the kernel and headers. This split based on work by
Ingmar Alting <iaalting@cs.vu.nl> done for his Minix PowerPC architecture
port.
. kernel does not program the interrupt controller directly, do any
other architecture-dependent operations, or contain assembly any more,
but uses architecture-dependent functions in arch/$(ARCH)/.
. architecture-dependent constants and types defined in arch/$(ARCH)/include.
. <ibm/portio.h> moved to <minix/portio.h>, as they have become, for now,
architecture-independent functions.
. int86, sdevio, readbios, and iopenable are now i386-specific kernel calls
and live in arch/i386/do_* now.
. i386 arch now supports even less 86 code; e.g. mpx86.s and klib86.s have
gone, and 'machine.protected' is gone (and always taken to be 1 in i386).
If 86 support is to return, it should be a new architecture.
. prototypes for the architecture-dependent functions defined in
kernel/arch/$(ARCH)/*.c but used in kernel/ are in kernel/proto.h
. /etc/make.conf included in makefiles and shell scripts that need to
know the building architecture; it defines ARCH=<arch>, currently only
i386.
. some basic per-architecture build support outside of the kernel (lib)
. in clock.c, only dequeue a process if it was ready
. fixes for new include files
files deleted:
. mpx/klib.s - only for choosing between mpx/klib86 and -386
. klib86.s - only for 86
i386-specific files files moved (or arch-dependent stuff moved) to arch/i386/:
. mpx386.s (entry point)
. klib386.s
. sconst.h
. exception.c
. protect.c
. protect.h
. i8269.c
2006-12-22 16:22:27 +01:00
|
|
|
*===========================================================================*/
|
2010-03-27 15:31:00 +01:00
|
|
|
PUBLIC int init_8253A_timer(const unsigned freq)
|
Split of architecture-dependent and -independent functions for i386,
mainly in the kernel and headers. This split based on work by
Ingmar Alting <iaalting@cs.vu.nl> done for his Minix PowerPC architecture
port.
. kernel does not program the interrupt controller directly, do any
other architecture-dependent operations, or contain assembly any more,
but uses architecture-dependent functions in arch/$(ARCH)/.
. architecture-dependent constants and types defined in arch/$(ARCH)/include.
. <ibm/portio.h> moved to <minix/portio.h>, as they have become, for now,
architecture-independent functions.
. int86, sdevio, readbios, and iopenable are now i386-specific kernel calls
and live in arch/i386/do_* now.
. i386 arch now supports even less 86 code; e.g. mpx86.s and klib86.s have
gone, and 'machine.protected' is gone (and always taken to be 1 in i386).
If 86 support is to return, it should be a new architecture.
. prototypes for the architecture-dependent functions defined in
kernel/arch/$(ARCH)/*.c but used in kernel/ are in kernel/proto.h
. /etc/make.conf included in makefiles and shell scripts that need to
know the building architecture; it defines ARCH=<arch>, currently only
i386.
. some basic per-architecture build support outside of the kernel (lib)
. in clock.c, only dequeue a process if it was ready
. fixes for new include files
files deleted:
. mpx/klib.s - only for choosing between mpx/klib86 and -386
. klib86.s - only for 86
i386-specific files files moved (or arch-dependent stuff moved) to arch/i386/:
. mpx386.s (entry point)
. klib386.s
. sconst.h
. exception.c
. protect.c
. protect.h
. i8269.c
2006-12-22 16:22:27 +01:00
|
|
|
{
|
|
|
|
/* Initialize channel 0 of the 8253A timer to, e.g., 60 Hz,
|
|
|
|
* and register the CLOCK task's interrupt handler to be run
|
|
|
|
* on every clock tick.
|
|
|
|
*/
|
|
|
|
outb(TIMER_MODE, SQUARE_WAVE); /* run continuously */
|
2009-11-06 10:04:15 +01:00
|
|
|
outb(TIMER0, (TIMER_COUNT(freq) & 0xff)); /* timer low byte */
|
|
|
|
outb(TIMER0, TIMER_COUNT(freq) >> 8); /* timer high byte */
|
Split of architecture-dependent and -independent functions for i386,
mainly in the kernel and headers. This split based on work by
Ingmar Alting <iaalting@cs.vu.nl> done for his Minix PowerPC architecture
port.
. kernel does not program the interrupt controller directly, do any
other architecture-dependent operations, or contain assembly any more,
but uses architecture-dependent functions in arch/$(ARCH)/.
. architecture-dependent constants and types defined in arch/$(ARCH)/include.
. <ibm/portio.h> moved to <minix/portio.h>, as they have become, for now,
architecture-independent functions.
. int86, sdevio, readbios, and iopenable are now i386-specific kernel calls
and live in arch/i386/do_* now.
. i386 arch now supports even less 86 code; e.g. mpx86.s and klib86.s have
gone, and 'machine.protected' is gone (and always taken to be 1 in i386).
If 86 support is to return, it should be a new architecture.
. prototypes for the architecture-dependent functions defined in
kernel/arch/$(ARCH)/*.c but used in kernel/ are in kernel/proto.h
. /etc/make.conf included in makefiles and shell scripts that need to
know the building architecture; it defines ARCH=<arch>, currently only
i386.
. some basic per-architecture build support outside of the kernel (lib)
. in clock.c, only dequeue a process if it was ready
. fixes for new include files
files deleted:
. mpx/klib.s - only for choosing between mpx/klib86 and -386
. klib86.s - only for 86
i386-specific files files moved (or arch-dependent stuff moved) to arch/i386/:
. mpx386.s (entry point)
. klib386.s
. sconst.h
. exception.c
. protect.c
. protect.h
. i8269.c
2006-12-22 16:22:27 +01:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
2009-11-06 10:04:15 +01:00
|
|
|
* stop_8235A_timer *
|
Split of architecture-dependent and -independent functions for i386,
mainly in the kernel and headers. This split based on work by
Ingmar Alting <iaalting@cs.vu.nl> done for his Minix PowerPC architecture
port.
. kernel does not program the interrupt controller directly, do any
other architecture-dependent operations, or contain assembly any more,
but uses architecture-dependent functions in arch/$(ARCH)/.
. architecture-dependent constants and types defined in arch/$(ARCH)/include.
. <ibm/portio.h> moved to <minix/portio.h>, as they have become, for now,
architecture-independent functions.
. int86, sdevio, readbios, and iopenable are now i386-specific kernel calls
and live in arch/i386/do_* now.
. i386 arch now supports even less 86 code; e.g. mpx86.s and klib86.s have
gone, and 'machine.protected' is gone (and always taken to be 1 in i386).
If 86 support is to return, it should be a new architecture.
. prototypes for the architecture-dependent functions defined in
kernel/arch/$(ARCH)/*.c but used in kernel/ are in kernel/proto.h
. /etc/make.conf included in makefiles and shell scripts that need to
know the building architecture; it defines ARCH=<arch>, currently only
i386.
. some basic per-architecture build support outside of the kernel (lib)
. in clock.c, only dequeue a process if it was ready
. fixes for new include files
files deleted:
. mpx/klib.s - only for choosing between mpx/klib86 and -386
. klib86.s - only for 86
i386-specific files files moved (or arch-dependent stuff moved) to arch/i386/:
. mpx386.s (entry point)
. klib386.s
. sconst.h
. exception.c
. protect.c
. protect.h
. i8269.c
2006-12-22 16:22:27 +01:00
|
|
|
*===========================================================================*/
|
2009-11-06 10:04:15 +01:00
|
|
|
PUBLIC void stop_8253A_timer(void)
|
Split of architecture-dependent and -independent functions for i386,
mainly in the kernel and headers. This split based on work by
Ingmar Alting <iaalting@cs.vu.nl> done for his Minix PowerPC architecture
port.
. kernel does not program the interrupt controller directly, do any
other architecture-dependent operations, or contain assembly any more,
but uses architecture-dependent functions in arch/$(ARCH)/.
. architecture-dependent constants and types defined in arch/$(ARCH)/include.
. <ibm/portio.h> moved to <minix/portio.h>, as they have become, for now,
architecture-independent functions.
. int86, sdevio, readbios, and iopenable are now i386-specific kernel calls
and live in arch/i386/do_* now.
. i386 arch now supports even less 86 code; e.g. mpx86.s and klib86.s have
gone, and 'machine.protected' is gone (and always taken to be 1 in i386).
If 86 support is to return, it should be a new architecture.
. prototypes for the architecture-dependent functions defined in
kernel/arch/$(ARCH)/*.c but used in kernel/ are in kernel/proto.h
. /etc/make.conf included in makefiles and shell scripts that need to
know the building architecture; it defines ARCH=<arch>, currently only
i386.
. some basic per-architecture build support outside of the kernel (lib)
. in clock.c, only dequeue a process if it was ready
. fixes for new include files
files deleted:
. mpx/klib.s - only for choosing between mpx/klib86 and -386
. klib86.s - only for 86
i386-specific files files moved (or arch-dependent stuff moved) to arch/i386/:
. mpx386.s (entry point)
. klib386.s
. sconst.h
. exception.c
. protect.c
. protect.h
. i8269.c
2006-12-22 16:22:27 +01:00
|
|
|
{
|
|
|
|
/* Reset the clock to the BIOS rate. (For rebooting.) */
|
|
|
|
outb(TIMER_MODE, 0x36);
|
|
|
|
outb(TIMER0, 0);
|
|
|
|
outb(TIMER0, 0);
|
|
|
|
}
|
|
|
|
|
2010-05-25 10:06:14 +02:00
|
|
|
PRIVATE int calib_cpu_handler(irq_hook_t * UNUSED(hook))
|
|
|
|
{
|
|
|
|
u64_t tsc;
|
|
|
|
|
|
|
|
probe_ticks++;
|
|
|
|
read_tsc_64(&tsc);
|
|
|
|
|
|
|
|
|
|
|
|
if (probe_ticks == 1) {
|
|
|
|
tsc0 = tsc;
|
|
|
|
}
|
|
|
|
else if (probe_ticks == PROBE_TICKS) {
|
|
|
|
tsc1 = tsc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRIVATE void estimate_cpu_freq(void)
|
|
|
|
{
|
|
|
|
u64_t tsc_delta;
|
|
|
|
u64_t cpu_freq;
|
|
|
|
|
|
|
|
irq_hook_t calib_cpu;
|
|
|
|
|
|
|
|
/* set the probe, we use the legacy timer, IRQ 0 */
|
|
|
|
put_irq_handler(&calib_cpu, CLOCK_IRQ, calib_cpu_handler);
|
|
|
|
|
|
|
|
/* set the PIC timer to get some time */
|
|
|
|
intr_enable();
|
|
|
|
|
|
|
|
/* loop for some time to get a sample */
|
|
|
|
while(probe_ticks < PROBE_TICKS) {
|
|
|
|
intr_enable();
|
|
|
|
}
|
|
|
|
|
|
|
|
intr_disable();
|
|
|
|
|
|
|
|
/* remove the probe */
|
|
|
|
rm_irq_handler(&calib_cpu);
|
|
|
|
|
|
|
|
tsc_delta = sub64(tsc1, tsc0);
|
|
|
|
|
|
|
|
cpu_freq = mul64(div64u64(tsc_delta, PROBE_TICKS - 1), make64(system_hz, 0));
|
|
|
|
cpu_set_freq(cpuid, cpu_freq);
|
|
|
|
BOOT_VERBOSE(cpu_print_freq(cpuid));
|
|
|
|
}
|
|
|
|
|
2009-11-06 10:04:15 +01:00
|
|
|
PUBLIC int arch_init_local_timer(unsigned freq)
|
|
|
|
{
|
2009-11-16 22:41:44 +01:00
|
|
|
#ifdef CONFIG_APIC
|
|
|
|
/* if we know the address, lapic is enabled and we should use it */
|
|
|
|
if (lapic_addr) {
|
2010-05-25 10:06:14 +02:00
|
|
|
unsigned cpu = cpuid;
|
2009-11-16 22:41:44 +01:00
|
|
|
lapic_set_timer_periodic(freq);
|
2010-05-25 10:06:14 +02:00
|
|
|
tsc_per_ms[cpu] = div64u(cpu_get_freq(cpu), 1000);
|
2009-11-16 22:41:44 +01:00
|
|
|
} else
|
|
|
|
{
|
2010-03-03 16:45:01 +01:00
|
|
|
BOOT_VERBOSE(printf("Initiating legacy i8253 timer\n"));
|
2009-11-16 22:41:44 +01:00
|
|
|
#else
|
|
|
|
{
|
|
|
|
#endif
|
|
|
|
init_8253A_timer(freq);
|
2010-05-25 10:06:14 +02:00
|
|
|
estimate_cpu_freq();
|
|
|
|
/* always only 1 cpu in the system */
|
|
|
|
tsc_per_ms[0] = div64u(cpu_get_freq(0), 1000);
|
2009-11-16 22:41:44 +01:00
|
|
|
}
|
2009-11-06 10:04:15 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
PUBLIC void arch_stop_local_timer(void)
|
|
|
|
{
|
2009-11-16 22:41:44 +01:00
|
|
|
#ifdef CONFIG_APIC
|
|
|
|
if (lapic_addr) {
|
|
|
|
lapic_stop_timer();
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
stop_8253A_timer();
|
|
|
|
}
|
2009-11-06 10:04:15 +01:00
|
|
|
}
|
|
|
|
|
2010-03-27 15:31:00 +01:00
|
|
|
PUBLIC int arch_register_local_timer_handler(const irq_handler_t handler)
|
2009-11-06 10:04:15 +01:00
|
|
|
{
|
2009-11-16 22:41:44 +01:00
|
|
|
#ifdef CONFIG_APIC
|
|
|
|
if (lapic_addr) {
|
|
|
|
/* Using APIC, it is configured in apic_idt_init() */
|
2010-03-03 16:45:01 +01:00
|
|
|
BOOT_VERBOSE(printf("Using LAPIC timer as tick source\n"));
|
2009-11-16 22:41:44 +01:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
/* Using PIC, Initialize the CLOCK's interrupt hook. */
|
|
|
|
pic_timer_hook.proc_nr_e = NONE;
|
|
|
|
pic_timer_hook.irq = CLOCK_IRQ;
|
|
|
|
|
|
|
|
put_irq_handler(&pic_timer_hook, CLOCK_IRQ, handler);
|
|
|
|
}
|
2009-11-06 10:04:15 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2010-02-10 16:36:54 +01:00
|
|
|
|
|
|
|
PUBLIC void cycles_accounting_init(void)
|
|
|
|
{
|
|
|
|
read_tsc_64(&tsc_ctr_switch);
|
|
|
|
}
|
|
|
|
|
2010-05-18 15:00:39 +02:00
|
|
|
PUBLIC void context_stop(struct proc * p)
|
2010-02-10 16:36:54 +01:00
|
|
|
{
|
2010-05-25 10:06:14 +02:00
|
|
|
u64_t tsc, tsc_delta;
|
2010-02-10 16:36:54 +01:00
|
|
|
|
|
|
|
read_tsc_64(&tsc);
|
2010-05-25 10:06:14 +02:00
|
|
|
tsc_delta = sub64(tsc, tsc_ctr_switch);
|
|
|
|
p->p_cycles = add64(p->p_cycles, tsc_delta);
|
2010-02-10 16:36:54 +01:00
|
|
|
tsc_ctr_switch = tsc;
|
2010-05-25 10:06:14 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* deduct the just consumed cpu cycles from the cpu time left for this
|
|
|
|
* process during its current quantum. Skip IDLE and other pseudo kernel
|
|
|
|
* tasks
|
|
|
|
*/
|
|
|
|
if (p->p_endpoint >= 0) {
|
|
|
|
#if DEBUG_RACE
|
|
|
|
make_zero64(p->p_cpu_time_left);
|
|
|
|
#else
|
|
|
|
/* if (tsc_delta < p->p_cpu_time_left) in 64bit */
|
|
|
|
if (tsc_delta.hi < p->p_cpu_time_left.hi ||
|
|
|
|
(tsc_delta.hi == p->p_cpu_time_left.hi &&
|
|
|
|
tsc_delta.lo < p->p_cpu_time_left.lo))
|
|
|
|
p->p_cpu_time_left = sub64(p->p_cpu_time_left, tsc_delta);
|
|
|
|
else {
|
|
|
|
make_zero64(p->p_cpu_time_left);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2010-02-10 16:36:54 +01:00
|
|
|
}
|
|
|
|
|
2010-05-18 15:00:39 +02:00
|
|
|
PUBLIC void context_stop_idle(void)
|
2010-02-10 16:36:54 +01:00
|
|
|
{
|
2010-05-18 15:00:39 +02:00
|
|
|
context_stop(proc_addr(IDLE));
|
2010-02-10 16:36:54 +01:00
|
|
|
}
|
2010-05-25 10:06:14 +02:00
|
|
|
|
|
|
|
PUBLIC u64_t ms_2_cpu_time(unsigned ms)
|
|
|
|
{
|
|
|
|
return mul64u(tsc_per_ms[cpuid], ms);
|
|
|
|
}
|