Use the cpu_info struct to store cpu-specific data in the same way in

both uniprocessor and multiprocessor environments. Use the otherwise
unused internal CPU register SSP to store the cpu_info pointer.
The macros curcpu(), curproc, cpu_number() and need_resched() are now the
same in both uniprocessor and multiprocessor environments.
This commit is contained in:
ragge 2000-05-29 20:00:55 +00:00
parent 628bc101f2
commit 992002c2be
6 changed files with 54 additions and 107 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: cpu.h,v 1.47 2000/05/27 16:33:04 ragge Exp $ */
/* $NetBSD: cpu.h,v 1.48 2000/05/29 20:00:56 ragge Exp $ */
/*
* Copyright (c) 1994 Ludd, University of Lule}, Sweden
@ -94,52 +94,26 @@ struct cpu_info {
u_long ci_simple_locks; /* # of simple locks held */
#endif
#if defined(MULTIPROCESSOR)
struct proc *ci_curproc; /* current owner of the processor */
#endif
/*
* Private members.
*/
#if defined(MULTIPROCESSOR)
int ci_want_resched; /* Should change process */
#endif
int ci_want_resched; /* Should change process */
int ci_cpunumber; /* Some numeric identifier */
long ci_exit; /* Page to use while exiting */
};
#if defined(MULTIPROCESSOR)
/*
* VAX internal CPU numbering is not sequential; therefore have a separate
* function call that returns the cpu_info struct for this CPU.
*
* For the master CPU (or only) this struct is allocated early in startup;
* for other CPUs it is allocated when the CPU is found.
*/
extern int (*vax_cpu_number)(void);
extern struct cpu_info *(*vax_curcpu)(void);
#define cpu_number() (*vax_cpu_number)()
#define curcpu() (*vax_curcpu)()
#define curcpu() ((struct cpu_info *)mfpr(PR_SSP))
#define curproc (curcpu()->ci_curproc)
#define cpu_number() (curcpu()->ci_cpunumber)
#define need_resched() {curcpu()->ci_want_resched++; mtpr(AST_OK,PR_ASTLVL); }
#define cpu_boot_secondary_processors()
#else /* MULTIPROCESSOR */
extern int want_resched; /* resched() was called */
extern struct cpu_info cpu_info_store;
#define curcpu() (&cpu_info_store)
#define cpu_number() 0
#define need_resched() { want_resched++; mtpr(AST_OK,PR_ASTLVL); }
#endif /* MULTIPROCESSOR */
extern struct device *booted_from;
extern int mastercpu;
#define setsoftnet() mtpr(12,PR_SIRR)
#define setsoftclock() mtpr(8,PR_SIRR)
#define todr() mfpr(PR_TODR)
/*
* Notify the current process (p) that it has a signal pending,

View File

@ -1,4 +1,4 @@
# $NetBSD: genassym.cf,v 1.16 2000/05/27 20:02:58 ragge Exp $
# $NetBSD: genassym.cf,v 1.17 2000/05/29 20:00:55 ragge Exp $
#
# Copyright (c) 1997 Ludd, University of Lule}, Sweden.
# All rights reserved.
@ -68,15 +68,14 @@ define KERNBASE KERNBASE
define UVM_PAGE_IDLE_ZERO offsetof(struct uvm, page_idle_zero)
ifdef MULTIPROCESSOR
# Multiprocessor struct members
define CI_CURPROC offsetof(struct cpu_info, ci_curproc)
define CI_WANT_RESCHED offsetof(struct cpu_info, ci_want_resched)
endif
define CI_EXIT offsetof(struct cpu_info, ci_exit)
# mtpr register numbers
define PR_KSP PR_KSP
define PR_ESP PR_ESP
define PR_SSP PR_SSP
define PR_USP PR_USP
define PR_ICCS PR_ICCS
define PR_PCBB PR_PCBB

View File

@ -1,4 +1,4 @@
/* $NetBSD: machdep.c,v 1.99 2000/05/26 21:20:26 thorpej Exp $ */
/* $NetBSD: machdep.c,v 1.100 2000/05/29 20:00:55 ragge Exp $ */
/*
* Copyright (c) 1994, 1998 Ludd, University of Lule}, Sweden.
@ -121,16 +121,6 @@ extern int virtual_avail, virtual_end;
* We do these external declarations here, maybe they should be done
* somewhere else...
*/
#if defined(MULTIPROCESSOR)
static int dummy_cpu_number(void);
static struct cpu_info *dummy_curcpu(void);
int (*vax_cpu_number)(void) = dummy_cpu_number;
struct cpu_info *(*vax_curcpu)(void) = dummy_curcpu;
#else
int want_resched;
struct cpu_info cpu_info_store;
#endif
char machine[] = MACHINE; /* from <machine/param.h> */
char machine_arch[] = MACHINE_ARCH; /* from <machine/param.h> */
char cpu_model[100];
@ -760,23 +750,3 @@ vax_unmap_physmem(addr, size)
else
rmfree(iomap, size, pageno);
}
#if defined(MULTIPROCESSOR)
/*
* Default functions that returns CPU numbers etc on non-MP systems
* and for just the master CPU.
*/
int
dummy_cpu_number()
{
return 0;
}
struct cpu_info *
dummy_curcpu()
{
extern char *scratch;
return (struct cpu_info *)(scratch + VAX_NBPG);
}
#endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: pmap.c,v 1.79 2000/05/20 13:38:58 ragge Exp $ */
/* $NetBSD: pmap.c,v 1.80 2000/05/29 20:00:55 ragge Exp $ */
/*
* Copyright (c) 1994, 1998, 1999 Ludd, University of Lule}, Sweden.
* All rights reserved.
@ -76,12 +76,23 @@ vaddr_t istack;
#define PROT_RO (PG_RO >> PROTSHIFT)
#define PROT_URKW (PG_URKW >> PROTSHIFT)
/*
* Scratch pages usage:
* Page 1: initial frame pointer during autoconfig. Stack and pcb for
* processes during exit on boot cpu only.
* Page 2: cpu_info struct for master (or only) cpu.
* Page 3: unused
* Page 4: unused
*/
long scratch;
#define SCRATCHPAGES 4
struct pmap kernel_pmap_store;
struct pte *Sysmap; /* System page table */
struct pv_entry *pv_table; /* array of entries, one per LOGICAL page */
int pventries;
void *scratch;
vaddr_t iospace;
vaddr_t ptemapstart, ptemapend;
@ -197,10 +208,10 @@ pmap_bootstrap()
kvtopte(istack)->pg_v = 0;
/* Some scratch pages */
scratch = (void *)((u_int)istack + ISTACK_SIZE);
scratch = ((u_int)istack + ISTACK_SIZE);
/* Physical-to-virtual translation table */
(unsigned)pv_table = (u_int)scratch + 4 * VAX_NBPG;
(unsigned)pv_table = scratch + 4 * VAX_NBPG;
avail_start = (unsigned)pv_table + (ROUND_PAGE(avail_end >> PGSHIFT)) *
sizeof(struct pv_entry) - KERNBASE;
@ -241,7 +252,7 @@ pmap_bootstrap()
#if 0 /* Breaks cninit() on some machines */
cninit();
printf("Sysmap %p, istack %lx, scratch %p\n",Sysmap,istack,scratch);
printf("Sysmap %p, istack %lx, scratch %\n",Sysmap,istack,scratch);
printf("etext %p\n", &etext);
printf("SYSPTSIZE %x\n",sysptsize);
printf("pv_table %p, ptemapstart %lx ptemapend %lx\n",
@ -269,6 +280,12 @@ pmap_bootstrap()
mtpr(pcb->P1LR = pmap->pm_p1lr, PR_P1LR);
mtpr(pcb->P0LR = pmap->pm_p0lr, PR_P0LR);
/* cpu_info struct */
pcb->SSP = scratch + VAX_NBPG;
mtpr(pcb->SSP, PR_SSP);
bzero((caddr_t)pcb->SSP, sizeof(struct cpu_info));
curcpu()->ci_exit = scratch;
/*
* Now everything should be complete, start virtual memory.
*/

View File

@ -1,4 +1,4 @@
/* $NetBSD: subr.s,v 1.41 2000/05/27 20:02:58 ragge Exp $ */
/* $NetBSD: subr.s,v 1.42 2000/05/29 20:00:55 ragge Exp $ */
/*
* Copyright (c) 1994 Ludd, University of Lule}, Sweden.
@ -65,6 +65,8 @@ to: movw $0xfff,_panic # Save all regs in panic
addl3 $USPACE,_proc0paddr,r0 # Get kernel stack top
mtpr r0,$PR_KSP # put in IPR KSP
movl r0,_Sysmap # SPT start addr after KSP
movab IFTRAP(r0),4(r0) # Save trap address in ESP
mtpr 4(r0),$PR_ESP # Put it in ESP also
# Set some registers in known state
movl _proc0paddr,r0
@ -260,14 +262,8 @@ idle: mtpr $0,$PR_IPL # Enable all types of interrupts
#
JSBENTRY(Swtch)
#if defined(MULTIPROCESSOR)
pushl r0
calls $0,*_vax_curcpu # Get ptr to this cpu_info struct
clrl CI_CURPROC(r0) # Stop process accounting
movl (sp)+,r0
#else
clrl _curproc # Stop process accounting
#endif
mfpr $PR_SSP,r1 # Get ptr to this cpu_info struct
clrl CI_CURPROC(r1) # Stop process accounting
mtpr $0x1f,$PR_IPL # block all interrupts
ffs $0,$32,_sched_whichqs,r3 # Search for bit set
beql idle # no bit set, go to idle loop
@ -284,16 +280,9 @@ noque: .asciz "swtch"
bbsc r3,_sched_whichqs,2f # no, clear bit in whichqs
2: clrl 4(r2) # clear proc backpointer
movb $SONPROC,P_STAT(r2) # p->p_stat = SONPROC;
#if defined(MULTIPROCESSOR)
pushl r0
calls $0,*_vax_curcpu # Get ptr to this cpu_info struct
movl r2,CI_CURPROC(r0) # set new process running
clrl CI_WANT_RESCHED(r0) # we are now changing process
movl (sp)+,r0
#else
movl r2,_curproc # set new process running
clrl _want_resched # we are now changing process
#endif
mfpr $PR_SSP,r1 # Get ptr to this cpu_info struct
movl r2,CI_CURPROC(r1) # set new process running
clrl CI_WANT_RESCHED(r1) # we are now changing process
cmpl r0,r2 # Same process?
bneq 1f # No, continue
rsb
@ -301,6 +290,8 @@ noque: .asciz "swtch"
addl3 r0,$IFTRAP,r1 # Save for copy* functions.
mtpr r1,$PR_ESP # Use ESP as CPU-specific pointer
movl r1,4(r0) # Must save in PCB also.
mfpr $PR_SSP,r1 # New process must inherit cpu_info
movl r1,8(r0) # Put it in new PCB
#
# Nice routine to get physical from virtual adresses.
@ -324,17 +315,17 @@ noque: .asciz "swtch"
ENTRY(cpu_exit,0)
movl 4(ap),r6 # Process pointer in r6
mtpr $0x18,$PR_IPL # Block almost everything
addl3 $512,_scratch,sp # Change stack, and schedule it to be freed
pushl r6 # exit2(p)
calls $1,_exit2
clrl r0 # No process to switch from
bicl3 $0xc0000000,_scratch,r1
mtpr r1,$PR_PCBB
mfpr $PR_SSP,r7 # get cpu_info ptr
movl CI_EXIT(r7),r8 # scratch page address
movab 512(r8),sp # change stack
bicl2 $0xc0000000,r8 # get physical address
mtpr r8,$PR_PCBB # new PCB
mtpr r7,$PR_SSP # In case...
pushl r6
calls $1,_exit2 # release last resources.
clrl r0
brw Swtch
#
# copy/fetch/store routines.
#

View File

@ -1,4 +1,4 @@
/* $NetBSD: trap.c,v 1.53 2000/05/27 16:33:04 ragge Exp $ */
/* $NetBSD: trap.c,v 1.54 2000/05/29 20:00:55 ragge Exp $ */
/*
* Copyright (c) 1994 Ludd, University of Lule}, Sweden.
@ -123,18 +123,14 @@ userret(p, frame, oticks)
while ((sig = CURSIG(p)) != 0)
postsig(sig);
p->p_priority = p->p_usrpri;
#if defined(MULTIPROCESSOR)
if (curcpu()->ci_want_resched) {
#else
if (want_resched) {
#endif
/*
* We are being preempted.
*/
preempt(NULL);
while ((sig = CURSIG(p)) != 0)
postsig(sig);
} /* } */
}
/*
* If profiling, charge system time to the trapped pc.