Re: [Geekos-devel] timer munging
Status: Pre-Alpha
Brought to you by:
daveho
|
From: David H. <da...@cs...> - 2002-01-14 17:23:33
|
I tried your patch, and it seems to work fine, although the messages
print out more than once per second.
I like the idea of being able to specify the rate of the timer
interrupts. Maybe you could explain how this works in more detail?
-Dave
On Fri, Jan 11, 2002 at 11:15:02PM -0600, Parc wrote:
> I've munged together a couple lines to set the timer to 10ms jiffies,
> and added a sleep(). Could somebody try these out for me? For some
> reason I don't get the correct timing occasionally. This patch should
> cause the kernel to loop saying "tick" once a second.
>
> Thanks
>
> Index: drivers/timer.c
> ===================================================================
> RCS file: /cvsroot/geekos/drivers/timer.c,v
> retrieving revision 1.2
> diff -c -r1.2 timer.c
> *** drivers/timer.c 2001/12/24 15:35:57 1.2
> --- drivers/timer.c 2002/01/12 05:10:29
> ***************
> *** 11,16 ****
> --- 11,20 ----
> #include "sys/geekos/kthread.h"
> #include "sys/geekos/timer.h"
>
> + #define TICKRATE 1193182
> + //#define FIND_RATE(hz) (((TICKRATE + hz) / 2) / hz)
> + #define FIND_RATE(hz) (((TICKRATE + hz) / 2) / hz)
> +
> // global tick counter
> volatile unsigned long g_numTicks;
>
> ***************
> *** 56,61 ****
> --- 60,72 ----
>
> Print( "Initializing timer...\n" );
>
> + //Set the tick rate to 10ms
> + disable_interrupts();
> + out_byte(0x043, 0x34);
> + out_byte(0x040, FIND_RATE(100) & 0xff);
> + out_byte(0x040, FIND_RATE(100) >> 8);
> + enable_interrupts();
> +
> // Install an interrupt handler for the timer IRQ
> install_irq( TIMER_IRQ, &timer_interrupt_handler );
>
> ***************
> *** 63,66 ****
> --- 74,83 ----
> irqMask = get_irq_mask();
> irqMask &= ~(1 << TIMER_IRQ);
> set_irq_mask( irqMask );
> + }
> +
> + void sleep(int time) {
> + long start = g_numTicks + time +1;
> + Print("Sleeping from %x to %x\n",g_numTicks,start);
> + while((g_numTicks - start) > 0) ; //spin
> }
> Index: include/sys/geekos/timer.h
> ===================================================================
> RCS file: /cvsroot/geekos/include/sys/geekos/timer.h,v
> retrieving revision 1.2
> diff -c -r1.2 timer.h
> *** include/sys/geekos/timer.h 2001/12/24 15:35:57 1.2
> --- include/sys/geekos/timer.h 2002/01/12 05:10:29
> ***************
> *** 13,17 ****
> --- 13,18 ----
> extern volatile unsigned long g_numTicks;
>
> void init_timer( void );
> + void sleep( int time );
>
> #endif // TIMER_H
> Index: kern/main.c
> ===================================================================
> RCS file: /cvsroot/geekos/kern/main.c,v
> retrieving revision 1.6
> diff -c -r1.6 main.c
> *** kern/main.c 2001/12/24 15:35:57 1.6
> --- kern/main.c 2002/01/12 05:10:30
> ***************
> *** 51,56 ****
> --- 53,62 ----
> // Test Join() function
> {
> struct kernel_thread* child;
> + for(; ;) {
> + sleep(100);
> + Print("tick.\n");
> + }
> Print( "Starting child...\n" );
> child = start_kernel_thread( &test_join, 0, PRIORITY_NORMAL, FALSE );
> Join( child );
|