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-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"
|
2010-09-23 12:49:52 +02:00
|
|
|
#include "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
|
2010-09-15 16:10:03 +02:00
|
|
|
#include "spinlock.h"
|
2009-11-16 22:41:44 +01: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
|
|
|
#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*/
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
tsc_delta = sub64(tsc1, tsc0);
|
|
|
|
|
|
|
|
cpu_freq = mul64(div64u64(tsc_delta, PROBE_TICKS - 1), make64(system_hz, 0));
|
|
|
|
cpu_set_freq(cpuid, cpu_freq);
|
2010-10-26 23:07:27 +02:00
|
|
|
cpu_info[cpuid].freq = div64u(cpu_freq, 1000000);
|
2010-05-25 10:06:14 +02:00
|
|
|
BOOT_VERBOSE(cpu_print_freq(cpuid));
|
|
|
|
}
|
|
|
|
|
2010-09-15 16:11:06 +02:00
|
|
|
PUBLIC 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;
|
|
|
|
tsc_per_ms[cpu] = div64u(cpu_get_freq(cpu), 1000);
|
2010-10-21 19:07:01 +02:00
|
|
|
lapic_set_timer_one_shot(1000000/system_hz);
|
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;
|
|
|
|
}
|
|
|
|
|
2010-09-15 16:11:06 +02:00
|
|
|
PUBLIC 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
|
|
|
}
|
|
|
|
|
2010-09-15 16:11:06 +02:00
|
|
|
PUBLIC 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
|
|
|
}
|
|
|
|
|
2010-09-15 16:11:06 +02:00
|
|
|
PUBLIC 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
|
|
|
|
|
|
|
PUBLIC void cycles_accounting_init(void)
|
|
|
|
{
|
2010-09-19 17:52:12 +02:00
|
|
|
read_tsc_64(get_cpu_var_ptr(cpu, tsc_ctr_switch));
|
|
|
|
|
|
|
|
make_zero64(get_cpu_var(cpu, cpu_last_tsc));
|
|
|
|
make_zero64(get_cpu_var(cpu, cpu_last_idle));
|
2010-02-10 16:36:54 +01:00
|
|
|
}
|
|
|
|
|
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-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;
|
|
|
|
|
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);
|
2010-10-19 19:07:11 +02:00
|
|
|
tmp = sub64(tsc, *__tsc_ctr_switch);
|
|
|
|
kernel_ticks[cpu] = add64(kernel_ticks[cpu], tmp);
|
|
|
|
p->p_cycles = add64(p->p_cycles, tmp);
|
2010-09-15 16:10:03 +02:00
|
|
|
BKL_UNLOCK();
|
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
|
|
|
|
|
|
|
bkl_ticks[cpu] = add64(bkl_ticks[cpu], sub64(tsc, bkl_tsc));
|
|
|
|
bkl_tries[cpu]++;
|
|
|
|
bkl_succ[cpu] += !(!(succ == 0));
|
|
|
|
|
2010-10-19 19:07:11 +02:00
|
|
|
p->p_cycles = add64(p->p_cycles, sub64(tsc, *__tsc_ctr_switch));
|
2010-09-15 16:10:27 +02:00
|
|
|
}
|
2010-09-15 16:11:03 +02:00
|
|
|
#else
|
|
|
|
read_tsc_64(&tsc);
|
|
|
|
p->p_cycles = add64(p->p_cycles, sub64(tsc, *__tsc_ctr_switch));
|
|
|
|
#endif
|
2010-09-15 16:10:27 +02:00
|
|
|
|
2010-09-15 16:11:03 +02:00
|
|
|
tsc_delta = sub64(tsc, *__tsc_ctr_switch);
|
|
|
|
|
2011-02-08 14:58:32 +01:00
|
|
|
if(kbill_ipc) {
|
|
|
|
kbill_ipc->p_kipc_cycles =
|
|
|
|
add64(kbill_ipc->p_kipc_cycles, tsc_delta);
|
|
|
|
kbill_ipc = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(kbill_kcall) {
|
|
|
|
kbill_kcall->p_kcall_cycles =
|
|
|
|
add64(kbill_kcall->p_kcall_cycles, tsc_delta);
|
|
|
|
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
|
|
|
|
make_zero64(p->p_cpu_time_left);
|
|
|
|
#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)))
|
2010-09-15 16:11:03 +02:00
|
|
|
p->p_cpu_time_left = sub64(p->p_cpu_time_left, tsc_delta);
|
|
|
|
else {
|
|
|
|
make_zero64(p->p_cpu_time_left);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-09-15 16:10:27 +02:00
|
|
|
*__tsc_ctr_switch = tsc;
|
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-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
|
|
|
|
|
|
|
PUBLIC u64_t ms_2_cpu_time(unsigned ms)
|
|
|
|
{
|
|
|
|
return mul64u(tsc_per_ms[cpuid], ms);
|
|
|
|
}
|
2010-09-19 17:52:12 +02:00
|
|
|
|
|
|
|
PUBLIC unsigned cpu_time_2_ms(u64_t cpu_time)
|
|
|
|
{
|
|
|
|
return div64u(cpu_time, tsc_per_ms[cpuid]);
|
|
|
|
}
|
|
|
|
|
|
|
|
PUBLIC short cpu_load(void)
|
|
|
|
{
|
|
|
|
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 */
|
|
|
|
if (!is_zero64(*last_tsc)) {
|
|
|
|
tsc_delta = sub64(current_tsc, *last_tsc);
|
|
|
|
idle_delta = sub64(*current_idle, *last_idle);
|
|
|
|
|
|
|
|
busy = sub64(tsc_delta, idle_delta);
|
|
|
|
busy = mul64(busy, make64(100, 0));
|
2010-11-08 00:35:29 +01:00
|
|
|
load = ex64lo(div64(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;
|
|
|
|
}
|