plan 9 kernel history: overview | file list | diff list

1991/0823/pc/clock.c (diff list | history)

1991/0823/sys/src/9/pc/clock.c:1,951991/1112/sys/src/9/pc/clock.c:1,93 (short | long | prev | next)
1991/0704    
#include	"u.h" 
#include	"lib.h" 
#include	"mem.h" 
#include	"dat.h" 
#include	"fns.h" 
#include	"io.h" 
1991/0706    
#include	"ureg.h" 
1991/0704    
 
1991/0705    
/* 
 *  8253 timer 
 */ 
enum 
{ 
1991/0709    
	T0cntr=	0x40,		/* counter ports */ 
	T1cntr=	0x41,		/* ... */ 
	T2cntr=	0x42,		/* ... */ 
	Tmode=	0x43,		/* mode port */ 
1991/0705    
 
1991/0709    
	Load0square=	0x36,		/*  load counter 0 with 2 bytes, 
					 *  output a square wave whose 
					 *  period is the counter period 
					 */ 
	Freq=		1193182,	/* Real clock frequency */ 
1991/0808    
	FHZ=		1000,		/* hertz for fast clock */ 
1991/0705    
}; 
 
1991/0719    
/* 
 *  delay for l milliseconds 
 */ 
void 
delay(int l) 
{ 
	int i; 
 
	while(--l){ 
		for(i=0; i < 404; i++) 
			; 
	} 
} 
 
1991/0704    
void 
clockinit(void) 
{ 
1991/0709    
	/* 
	 *  set vector for clock interrupts 
	 */ 
1991/0716    
	setvec(Clockvec, clock); 
1991/0709    
 
	/* 
	 *  make clock output a square wave with a 1/HZ period 
	 */ 
	outb(Tmode, Load0square); 
	outb(T0cntr, (Freq/HZ));	/* low byte */ 
	outb(T0cntr, (Freq/HZ)>>8);	/* high byte */ 
1991/0704    
} 
 
1991/0705    
void 
1991/0706    
clock(Ureg *ur) 
1991/0705    
{ 
1991/0706    
	Proc *p; 
 
1991/0705    
	m->ticks++; 
1991/0711    
 
	checkalarms(); 
 
1991/0808    
	/* 
	 *  process time accounting 
	 */ 
1991/0706    
	p = m->proc; 
	if(p){ 
1991/0711    
		p->pc = ur->pc; 
1991/0706    
		if (p->state==Running) 
			p->time[p->insyscall]++; 
	} 
1991/0801    
 
1991/0802    
	if(u && p && p->state==Running){ 
1991/0808    
		/* 
		 *  preemption 
		 */ 
1991/0730    
		if(anyready()){ 
			if(p->hasspin) 
				p->hasspin = 0; 
			else 
				sched(); 
		} 
1991/0808    
		/* 
		 *  notes for processes that might be spinning 
		 *  in user mode. 
		 */ 
		if((ur->cs&0xffff) == UESEL){ 
1991/0802    
			if(u->nnote) 
				notify(ur); 
		} 
1991/1112    
		if((ur->cs&0xffff) == UESEL) 
			notify(ur); 
1991/0802    
	} 
1991/0808    
} 


source code copyright © 1990-2005 Lucent Technologies; see license
Plan 9 distribution
comments to russ cox (rsc@swtch.com)