resched.c,v

来自「TCP-IP红宝书源代码」· C,V 代码 · 共 228 行

C,V
228
字号
head	1.3;
access;
symbols;
locks
	dls:1.3; strict;
comment	@ * @;


1.3
date	97.09.21.19.29.30;	author dls;	state Dist;
branches;
next	1.2;

1.2
date	94.05.07.19.26.36;	author dls;	state Works;
branches;
next	1.1;

1.1
date	94.05.06.03.12.23;	author dls;	state Works;
branches;
next	;


desc
@@


1.3
log
@pre-3e code
@
text
@/* resched.c  -  resched */

#include <conf.h>
#include <kernel.h>
#include <proc.h>
#include <q.h>

unsigned long currSP;	/* REAL sp of current process */

/*------------------------------------------------------------------------
 * resched  --  reschedule processor to highest priority ready process
 *
 * Notes:	Upon entry, currpid gives current process id.
 *		Proctab[currpid].pstate gives correct NEXT state for
 *			current process if other than PRREADY.
 *------------------------------------------------------------------------
 */
int	resched()
{
	STATWORD		PS;
	register struct	pentry	*optr;	/* pointer to old process entry */
	register struct	pentry	*nptr;	/* pointer to new process entry */

	disable(PS);
	/* no switch needed if current process priority higher than next*/

	if ( ( (optr= &proctab[currpid])->pstate == PRCURR) &&
	   (lastkey(rdytail)<optr->pprio)) {
		restore(PS);
		return(OK);
	}
	
#ifdef STKCHK
	/* make sure current stack has room for ctsw */
	asm("movl	%esp,_currSP");
	if (currSP - optr->plimit < 48) {
		kprintf("Bad SP current process, pid=%d (%s), lim=0x%lx, currently 0x%lx\n",
			currpid, optr->pname,
			(unsigned long) optr->plimit,
			(unsigned long) currSP);
		panic("current process stack overflow");
	}
#endif	

	/* force context switch */

	if (optr->pstate == PRCURR) {
		optr->pstate = PRREADY;
		insert(currpid,rdyhead,optr->pprio);
	}

	/* remove highest priority process at end of ready list */

	lastpid = currpid;
	nptr = &proctab[ (currpid = getlast(rdytail)) ];
	nptr->pstate = PRCURR;		/* mark it currently running	*/
#ifdef notdef
#ifdef	STKCHK
	if ( *( (int *)nptr->pbase  ) != MAGIC ) {
		kprintf("Bad magic pid=%d value=0x%lx, at 0x%lx\n",
			currpid,
			(unsigned long) *( (int *)nptr->pbase ),
			(unsigned long) nptr->pbase);
		panic("stack corrupted");
	}
	/*
	 * need ~16 longs of stack space below, so include that in check
	 *	below.
	 */
	if (nptr->pesp - nptr->plimit < 48) {
		kprintf("Bad SP pid=%d (%s), lim=0x%lx will be 0x%lx\n",
			currpid, nptr->pname,
			(unsigned long) nptr->plimit,
			(unsigned long) nptr->pesp);
		panic("stack overflow");
	}
#endif	/* STKCHK */
#endif	/* notdef */
#ifdef	RTCLOCK
	preempt = QUANTUM;		/* reset preemption counter	*/
#endif
#ifdef	DEBUG
	PrintSaved(nptr);
#endif
	
	ctxsw(&optr->pesp, optr->pirmask, &nptr->pesp, nptr->pirmask);

#ifdef	DEBUG
	PrintSaved(nptr);
#endif
	
	/* The OLD process returns here when resumed. */
	restore(PS);
	return OK;
}



#ifdef DEBUG
/* passed the pointer to the regs in the process entry */
PrintSaved(ptr)
    struct pentry *ptr;
{
    unsigned int i;

    if (ptr->pname[0] != 'm') return;
    
    kprintf("\nSaved context listing for process '%s'\n",ptr->pname);
    for (i=0; i<8; ++i) {
	kprintf("     D%d: 0x%08lx	",i,(unsigned long) ptr->pregs[i]);
	kprintf("A%d: 0x%08lx\n",i,(unsigned long) ptr->pregs[i+8]);
    }
    kprintf("         PC: 0x%lx",(unsigned long) ptr->pregs[PC]);
    kprintf("  SP: 0x%lx",(unsigned long) ptr->pregs[SSP]);
    kprintf("  PS: 0x%lx\n",(unsigned long) ptr->pregs[PS]);
}
#endif


@


1.2
log
@*** empty log message ***
@
text
@d20 1
d24 1
a24 1
kprintf("in resched\n");
a26 2
kprintf("curpid %d prio %d lastkey(%X) %d\n", currpid,
proctab[currpid].pprio, rdytail, lastkey(rdytail));
d29 1
d34 1
a34 1
	/* make sure CURRENT process is within it's stack (sdo) */
d36 1
a36 1
	if ( currSP < ((unsigned)optr->plimit) ) {
d54 1
d57 1
a57 1
kprintf("resched: new pid %d\n", currpid);
d66 5
a70 1
	if ( ((unsigned)nptr->pesp) < ((unsigned)nptr->plimit) ) {
d77 2
a78 1
#endif
a85 3
kprintf("calling ctxsw((%X) %X (%X) %X (%X) %X (%X) %X)\n",
&optr->pesp,optr->pesp, optr->pirmask, optr->pirmask[0], &nptr->pesp,
nptr->pesp, nptr->pirmask, nptr->pirmask[0]);
a87 3
kprintf("after ctxsw pid %d pesp %X irmask %X\n", currpid,
optr->pesp, optr->pirmask[0]);

d93 2
a94 1
	return(OK);
@


1.1
log
@Initial revision
@
text
@a35 1
kprintf("stkchk currSP %X plimit %X\n", currSP, optr->plimit);
d56 1
a56 1
kprintf("new pid %d\n", currpid);
a64 1
kprintf("new SP %X new limit %X\n", nptr->pesp, nptr->plimit);
d70 1
a70 1
/*		panic("stack overflow"); */
a82 9
{
int *saddr, i;
kprintf("new stack\n");
saddr = nptr->pesp;
kprintf("pbase %X pesp %X len %d\n", nptr->pbase, nptr->pesp,
(nptr->pbase - nptr->pesp)/4);
for (i=0; i<(nptr->pbase - nptr->pesp)/4; ++i, ++saddr)
kprintf("%X) %X\n", saddr, *saddr);
}
a87 2
while(1);
	
@

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?