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"
|
2010-09-15 16:10:57 +02:00
|
|
|
#include "kernel/interrupt.h"
|
2010-02-10 16:36:54 +01:00
|
|
|
#include <minix/u64.h>
|
2010-09-15 16:09:52 +02:00
|
|
|
#include "glo.h"
|
2012-11-15 12:06:41 +01:00
|
|
|
#include "kernel/profile.h"
|
2010-02-10 16:36:54 +01:00
|
|
|
|
2009-11-06 10:04:15 +01:00
|
|
|
|
2011-07-31 16:20:34 +02:00
|
|
|
#ifdef USE_APIC
|
2009-11-16 22:41:44 +01:00
|
|
|
#include "apic.h"
|
|
|
|
#endif
|
2011-10-26 17:43:36 +02:00
|
|
|
|
2012-11-15 12:06:41 +01:00
|
|
|
#include "kernel/spinlock.h"
|
2009-11-16 22:41:44 +01:00
|
|
|
|
2011-10-26 17:43:36 +02:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
#include "kernel/smp.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*/
|
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
static 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
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
static unsigned probe_ticks;
|
|
|
|
static u64_t tsc0, tsc1;
|
2010-05-25 10:06:14 +02:00
|
|
|
#define PROBE_TICKS (system_hz / 10)
|
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
static unsigned tsc_per_ms[CONFIG_MAX_CPUS];
|
2010-05-25 10:06:14 +02:00
|
|
|
|
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
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
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
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-10-08 03:38:03 +02:00
|
|
|
void arch_timer_int_handler(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
static int calib_cpu_handler(irq_hook_t * UNUSED(hook))
|
2010-05-25 10:06:14 +02:00
|
|
|
{
|
|
|
|
u64_t tsc;
|
|
|
|
|
|
|
|
probe_ticks++;
|
|
|
|
read_tsc_64(&tsc);
|
|
|
|
|
|
|
|
|
|
|
|
if (probe_ticks == 1) {
|
|
|
|
tsc0 = tsc;
|
|
|
|
}
|
|
|
|
else if (probe_ticks == PROBE_TICKS) {
|
|
|
|
tsc1 = tsc;
|
|
|
|
}
|
|
|
|
|
2010-09-15 16:10:03 +02:00
|
|
|
/* just in case we are in an SMP single cpu fallback mode */
|
|
|
|
BKL_UNLOCK();
|
2010-05-25 10:06:14 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
static void estimate_cpu_freq(void)
|
2010-05-25 10:06:14 +02:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
2010-09-15 16:10:03 +02:00
|
|
|
/* just in case we are in an SMP single cpu fallback mode */
|
|
|
|
BKL_UNLOCK();
|
2010-05-25 10:06:14 +02:00
|
|
|
/* 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();
|
2010-09-15 16:10:03 +02:00
|
|
|
/* just in case we are in an SMP single cpu fallback mode */
|
|
|
|
BKL_LOCK();
|
2010-05-25 10:06:14 +02:00
|
|
|
|
|
|
|
/* remove the probe */
|
|
|
|
rm_irq_handler(&calib_cpu);
|
|
|
|
|
2013-08-07 12:17:09 +02:00
|
|
|
tsc_delta = tsc1 - tsc0;
|
2010-05-25 10:06:14 +02:00
|
|
|
|
2013-08-07 12:17:09 +02:00
|
|
|
cpu_freq = (tsc_delta / (PROBE_TICKS - 1)) * system_hz;
|
2010-05-25 10:06:14 +02:00
|
|
|
cpu_set_freq(cpuid, cpu_freq);
|
2013-08-07 12:17:09 +02:00
|
|
|
cpu_info[cpuid].freq = (unsigned long)(cpu_freq / 1000000);
|
2010-05-25 10:06:14 +02:00
|
|
|
BOOT_VERBOSE(cpu_print_freq(cpuid));
|
|
|
|
}
|
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
int init_local_timer(unsigned freq)
|
2009-11-06 10:04:15 +01:00
|
|
|
{
|
2011-07-31 16:20:34 +02:00
|
|
|
#ifdef USE_APIC
|
2009-11-16 22:41:44 +01:00
|
|
|
/* 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;
|
2013-08-07 12:17:09 +02:00
|
|
|
tsc_per_ms[cpu] = (unsigned long)(cpu_get_freq(cpu) / 1000);
|
|
|
|
lapic_set_timer_one_shot(1000000 / system_hz);
|
|
|
|
} 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 */
|
2013-08-07 12:17:09 +02:00
|
|
|
tsc_per_ms[0] = (unsigned long)(cpu_get_freq(0) / 1000);
|
2009-11-16 22:41:44 +01:00
|
|
|
}
|
2009-11-06 10:04:15 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
void stop_local_timer(void)
|
2009-11-06 10:04:15 +01:00
|
|
|
{
|
2011-07-31 16:20:34 +02:00
|
|
|
#ifdef USE_APIC
|
2009-11-16 22:41:44 +01:00
|
|
|
if (lapic_addr) {
|
|
|
|
lapic_stop_timer();
|
2010-09-15 16:10:57 +02:00
|
|
|
apic_eoi();
|
2009-11-16 22:41:44 +01:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
stop_8253A_timer();
|
|
|
|
}
|
2009-11-06 10:04:15 +01:00
|
|
|
}
|
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
void restart_local_timer(void)
|
2010-09-15 16:10:57 +02:00
|
|
|
{
|
2011-07-31 16:20:34 +02:00
|
|
|
#ifdef USE_APIC
|
2010-09-15 16:10:57 +02:00
|
|
|
if (lapic_addr) {
|
|
|
|
lapic_restart_timer();
|
|
|
|
}
|
2010-09-15 16:11:06 +02:00
|
|
|
#endif
|
2010-09-15 16:10:57 +02:00
|
|
|
}
|
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
int register_local_timer_handler(const irq_handler_t handler)
|
2009-11-06 10:04:15 +01:00
|
|
|
{
|
2011-07-31 16:20:34 +02:00
|
|
|
#ifdef USE_APIC
|
2009-11-16 22:41:44 +01:00
|
|
|
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
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
void cycles_accounting_init(void)
|
2010-02-10 16:36:54 +01:00
|
|
|
{
|
2011-12-15 10:56:08 +01:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
unsigned cpu = cpuid;
|
|
|
|
#endif
|
|
|
|
|
2010-09-19 17:52:12 +02:00
|
|
|
read_tsc_64(get_cpu_var_ptr(cpu, tsc_ctr_switch));
|
|
|
|
|
2013-08-07 12:17:09 +02:00
|
|
|
get_cpu_var(cpu, cpu_last_tsc) = 0;
|
|
|
|
get_cpu_var(cpu, cpu_last_idle) = 0;
|
2010-02-10 16:36:54 +01:00
|
|
|
}
|
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
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-09-15 16:10:27 +02:00
|
|
|
u64_t * __tsc_ctr_switch = get_cpulocal_var_ptr(tsc_ctr_switch);
|
2010-09-15 16:11:03 +02:00
|
|
|
#ifdef CONFIG_SMP
|
2011-06-09 16:09:13 +02:00
|
|
|
unsigned cpu = cpuid;
|
2012-07-13 00:54:27 +02:00
|
|
|
int must_bkl_unlock = 0;
|
2011-06-09 16:09:13 +02:00
|
|
|
|
2010-09-15 16:10:03 +02:00
|
|
|
/*
|
|
|
|
* This function is called only if we switch from kernel to user or idle
|
|
|
|
* or back. Therefore this is a perfect location to place the big kernel
|
|
|
|
* lock which will hopefully disappear soon.
|
|
|
|
*
|
|
|
|
* If we stop accounting for KERNEL we must unlock the BKL. If account
|
|
|
|
* for IDLE we must not hold the lock
|
|
|
|
*/
|
2010-09-15 16:10:27 +02:00
|
|
|
if (p == proc_addr(KERNEL)) {
|
2010-10-19 19:07:11 +02:00
|
|
|
u64_t tmp;
|
|
|
|
|
2010-09-15 16:10:27 +02:00
|
|
|
read_tsc_64(&tsc);
|
2013-08-07 12:17:09 +02:00
|
|
|
tmp = tsc - *__tsc_ctr_switch;
|
|
|
|
kernel_ticks[cpu] = kernel_ticks[cpu] + tmp;
|
|
|
|
p->p_cycles = p->p_cycles + tmp;
|
2012-07-13 00:54:27 +02:00
|
|
|
must_bkl_unlock = 1;
|
2010-09-15 16:10:27 +02:00
|
|
|
} else {
|
2010-10-19 19:07:11 +02:00
|
|
|
u64_t bkl_tsc;
|
2010-09-15 16:10:37 +02:00
|
|
|
atomic_t succ;
|
|
|
|
|
|
|
|
read_tsc_64(&bkl_tsc);
|
|
|
|
/* this only gives a good estimate */
|
|
|
|
succ = big_kernel_lock.val;
|
|
|
|
|
2010-09-15 16:10:03 +02:00
|
|
|
BKL_LOCK();
|
2010-09-15 16:10:37 +02:00
|
|
|
|
2010-09-15 16:10:27 +02:00
|
|
|
read_tsc_64(&tsc);
|
2010-09-15 16:10:37 +02:00
|
|
|
|
2013-08-07 12:17:09 +02:00
|
|
|
bkl_ticks[cpu] = bkl_ticks[cpu] + tsc - bkl_tsc;
|
2010-09-15 16:10:37 +02:00
|
|
|
bkl_tries[cpu]++;
|
|
|
|
bkl_succ[cpu] += !(!(succ == 0));
|
|
|
|
|
2013-08-07 12:17:09 +02:00
|
|
|
p->p_cycles = p->p_cycles + tsc - *__tsc_ctr_switch;
|
2011-10-26 17:43:36 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/*
|
|
|
|
* Since at the time we got a scheduling IPI we might have been
|
|
|
|
* waiting for BKL already, we may miss it due to a similar IPI to
|
|
|
|
* the cpu which is already waiting for us to handle its. This
|
|
|
|
* results in a live-lock of these two cpus.
|
|
|
|
*
|
|
|
|
* Therefore we always check if there is one pending and if so,
|
|
|
|
* we handle it straight away so the other cpu can continue and
|
|
|
|
* we do not deadlock.
|
|
|
|
*/
|
|
|
|
smp_sched_handler();
|
|
|
|
#endif
|
2010-09-15 16:10:27 +02:00
|
|
|
}
|
2010-09-15 16:11:03 +02:00
|
|
|
#else
|
|
|
|
read_tsc_64(&tsc);
|
2013-08-07 12:17:09 +02:00
|
|
|
p->p_cycles = p->p_cycles + tsc - *__tsc_ctr_switch;
|
2010-09-15 16:11:03 +02:00
|
|
|
#endif
|
2010-09-15 16:10:27 +02:00
|
|
|
|
2013-08-07 12:17:09 +02:00
|
|
|
tsc_delta = tsc - *__tsc_ctr_switch;
|
2010-09-15 16:11:03 +02:00
|
|
|
|
2013-08-07 12:17:09 +02:00
|
|
|
if (kbill_ipc) {
|
2011-02-08 14:58:32 +01:00
|
|
|
kbill_ipc->p_kipc_cycles =
|
2013-08-07 12:17:09 +02:00
|
|
|
kbill_ipc->p_kipc_cycles + tsc_delta;
|
2011-02-08 14:58:32 +01:00
|
|
|
kbill_ipc = NULL;
|
|
|
|
}
|
|
|
|
|
2013-08-07 12:17:09 +02:00
|
|
|
if (kbill_kcall) {
|
2011-02-08 14:58:32 +01:00
|
|
|
kbill_kcall->p_kcall_cycles =
|
2013-08-07 12:17:09 +02:00
|
|
|
kbill_kcall->p_kcall_cycles + tsc_delta;
|
2011-02-08 14:58:32 +01:00
|
|
|
kbill_kcall = NULL;
|
|
|
|
}
|
|
|
|
|
2010-09-15 16:11:03 +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
|
2013-08-07 12:17:09 +02:00
|
|
|
p->p_cpu_time_left = 0;
|
2010-09-15 16:11:03 +02:00
|
|
|
#else
|
|
|
|
/* if (tsc_delta < p->p_cpu_time_left) in 64bit */
|
2010-11-08 00:35:29 +01:00
|
|
|
if (ex64hi(tsc_delta) < ex64hi(p->p_cpu_time_left) ||
|
|
|
|
(ex64hi(tsc_delta) == ex64hi(p->p_cpu_time_left) &&
|
|
|
|
ex64lo(tsc_delta) < ex64lo(p->p_cpu_time_left)))
|
2013-08-07 12:17:09 +02:00
|
|
|
p->p_cpu_time_left = p->p_cpu_time_left - tsc_delta;
|
2010-09-15 16:11:03 +02:00
|
|
|
else {
|
2013-08-07 12:17:09 +02:00
|
|
|
p->p_cpu_time_left = 0;
|
2010-09-15 16:11:03 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-09-15 16:10:27 +02:00
|
|
|
*__tsc_ctr_switch = tsc;
|
2012-07-13 00:54:27 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
if(must_bkl_unlock) {
|
|
|
|
BKL_UNLOCK();
|
|
|
|
}
|
|
|
|
#endif
|
2010-02-10 16:36:54 +01:00
|
|
|
}
|
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
void context_stop_idle(void)
|
2010-02-10 16:36:54 +01:00
|
|
|
{
|
2010-09-15 16:10:57 +02:00
|
|
|
int is_idle;
|
2011-06-09 16:09:13 +02:00
|
|
|
#ifdef CONFIG_SMP
|
2010-09-15 16:10:57 +02:00
|
|
|
unsigned cpu = cpuid;
|
2011-06-09 16:09:13 +02:00
|
|
|
#endif
|
2010-09-15 16:10:57 +02:00
|
|
|
|
|
|
|
is_idle = get_cpu_var(cpu, cpu_is_idle);
|
|
|
|
get_cpu_var(cpu, cpu_is_idle) = 0;
|
|
|
|
|
|
|
|
context_stop(get_cpulocal_var_ptr(idle_proc));
|
|
|
|
|
|
|
|
if (is_idle)
|
2010-09-15 16:11:06 +02:00
|
|
|
restart_local_timer();
|
2011-05-25 09:42:11 +02:00
|
|
|
#if SPROFILE
|
2010-09-23 12:49:52 +02:00
|
|
|
if (sprofiling)
|
|
|
|
get_cpulocal_var(idle_interrupted) = 1;
|
2011-05-25 09:42:11 +02:00
|
|
|
#endif
|
2010-02-10 16:36:54 +01:00
|
|
|
}
|
2010-05-25 10:06:14 +02:00
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
u64_t ms_2_cpu_time(unsigned ms)
|
2010-05-25 10:06:14 +02:00
|
|
|
{
|
2013-08-07 12:17:09 +02:00
|
|
|
return (u64_t)tsc_per_ms[cpuid] * ms;
|
2010-05-25 10:06:14 +02:00
|
|
|
}
|
2010-09-19 17:52:12 +02:00
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
unsigned cpu_time_2_ms(u64_t cpu_time)
|
2010-09-19 17:52:12 +02:00
|
|
|
{
|
2013-08-07 12:17:09 +02:00
|
|
|
return (unsigned long)(cpu_time / tsc_per_ms[cpuid]);
|
2010-09-19 17:52:12 +02:00
|
|
|
}
|
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
short cpu_load(void)
|
2010-09-19 17:52:12 +02:00
|
|
|
{
|
|
|
|
u64_t current_tsc, *current_idle;
|
|
|
|
u64_t tsc_delta, idle_delta, busy;
|
|
|
|
struct proc *idle;
|
|
|
|
short load;
|
2011-06-09 16:09:13 +02:00
|
|
|
#ifdef CONFIG_SMP
|
2010-09-19 17:52:12 +02:00
|
|
|
unsigned cpu = cpuid;
|
2011-06-09 16:09:13 +02:00
|
|
|
#endif
|
2010-09-19 17:52:12 +02:00
|
|
|
|
|
|
|
u64_t *last_tsc, *last_idle;
|
|
|
|
|
|
|
|
last_tsc = get_cpu_var_ptr(cpu, cpu_last_tsc);
|
|
|
|
last_idle = get_cpu_var_ptr(cpu, cpu_last_idle);
|
|
|
|
|
|
|
|
idle = get_cpu_var_ptr(cpu, idle_proc);;
|
|
|
|
read_tsc_64(¤t_tsc);
|
|
|
|
current_idle = &idle->p_cycles; /* ptr to idle proc */
|
|
|
|
|
|
|
|
/* calculate load since last cpu_load invocation */
|
2013-08-07 12:17:09 +02:00
|
|
|
if (*last_tsc) {
|
|
|
|
tsc_delta = current_tsc - *last_tsc;
|
|
|
|
idle_delta = *current_idle - *last_idle;
|
2010-09-19 17:52:12 +02:00
|
|
|
|
2013-08-07 12:17:09 +02:00
|
|
|
busy = tsc_delta - idle_delta;
|
|
|
|
busy = busy * 100;
|
|
|
|
load = ex64lo(busy / tsc_delta);
|
2010-09-19 17:52:12 +02:00
|
|
|
|
|
|
|
if (load > 100)
|
|
|
|
load = 100;
|
|
|
|
} else
|
|
|
|
load = 0;
|
|
|
|
|
|
|
|
*last_tsc = current_tsc;
|
|
|
|
*last_idle = *current_idle;
|
|
|
|
return load;
|
|
|
|
}
|
2012-02-20 18:58:17 +01:00
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
void busy_delay_ms(int ms)
|
2012-02-20 18:58:17 +01:00
|
|
|
{
|
|
|
|
u64_t cycles = ms_2_cpu_time(ms), tsc0, tsc, tsc1;
|
|
|
|
read_tsc_64(&tsc0);
|
|
|
|
tsc1 = tsc0 + cycles;
|
|
|
|
do { read_tsc_64(&tsc); } while(tsc < tsc1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|