diff options
author | jake <jake@FreeBSD.org> | 2001-01-10 04:43:51 +0000 |
---|---|---|
committer | jake <jake@FreeBSD.org> | 2001-01-10 04:43:51 +0000 |
commit | 4f5d8ed82579a945555b585b43ab2d09eae30c77 (patch) | |
tree | 512839f19fc02786cc9904c4406357f3573a8b09 /sys/i386 | |
parent | 776ef1f43089579877329277af83423976a699d2 (diff) | |
download | FreeBSD-src-4f5d8ed82579a945555b585b43ab2d09eae30c77.zip FreeBSD-src-4f5d8ed82579a945555b585b43ab2d09eae30c77.tar.gz |
Use PCPU_GET, PCPU_PTR and PCPU_SET to access all per-cpu variables
other then curproc.
Diffstat (limited to 'sys/i386')
-rw-r--r-- | sys/i386/i386/bios.c | 2 | ||||
-rw-r--r-- | sys/i386/i386/db_interface.c | 12 | ||||
-rw-r--r-- | sys/i386/i386/machdep.c | 15 | ||||
-rw-r--r-- | sys/i386/i386/mp_machdep.c | 38 | ||||
-rw-r--r-- | sys/i386/i386/mpapic.c | 6 | ||||
-rw-r--r-- | sys/i386/i386/mptable.c | 38 | ||||
-rw-r--r-- | sys/i386/i386/pmap.c | 71 | ||||
-rw-r--r-- | sys/i386/i386/sys_machdep.c | 6 | ||||
-rw-r--r-- | sys/i386/i386/trap.c | 39 | ||||
-rw-r--r-- | sys/i386/i386/vm86.c | 6 | ||||
-rw-r--r-- | sys/i386/i386/vm_machdep.c | 10 | ||||
-rw-r--r-- | sys/i386/include/cpu.h | 6 | ||||
-rw-r--r-- | sys/i386/include/mptable.h | 38 | ||||
-rw-r--r-- | sys/i386/isa/npx.c | 34 |
14 files changed, 166 insertions, 155 deletions
diff --git a/sys/i386/i386/bios.c b/sys/i386/i386/bios.c index a22f1549..e90de29 100644 --- a/sys/i386/i386/bios.c +++ b/sys/i386/i386/bios.c @@ -258,7 +258,7 @@ set_bios_selectors(struct bios_segments *seg, int flags) union descriptor *p_gdt; #ifdef SMP - p_gdt = &gdt[cpuid * NGDT]; + p_gdt = &gdt[PCPU_GET(cpuid) * NGDT]; #else p_gdt = gdt; #endif diff --git a/sys/i386/i386/db_interface.c b/sys/i386/i386/db_interface.c index fe94264..ee4ab19 100644 --- a/sys/i386/i386/db_interface.c +++ b/sys/i386/i386/db_interface.c @@ -142,11 +142,12 @@ kdb_trap(type, code, regs) #ifdef CPUSTOP_ON_DDBBREAK #if defined(VERBOSE_CPUSTOP_ON_DDBBREAK) - db_printf("\nCPU%d stopping CPUs: 0x%08x...", cpuid, other_cpus); + db_printf("\nCPU%d stopping CPUs: 0x%08x...", PCPU_GET(cpuid), + PCPU_GET(other_cpus)); #endif /* VERBOSE_CPUSTOP_ON_DDBBREAK */ /* We stop all CPUs except ourselves (obviously) */ - stop_cpus(other_cpus); + stop_cpus(PCPU_GET(other_cpus)); #if defined(VERBOSE_CPUSTOP_ON_DDBBREAK) db_printf(" stopped.\n"); @@ -171,13 +172,14 @@ kdb_trap(type, code, regs) #ifdef CPUSTOP_ON_DDBBREAK #if defined(VERBOSE_CPUSTOP_ON_DDBBREAK) - db_printf("\nCPU%d restarting CPUs: 0x%08x...", cpuid, stopped_cpus); + db_printf("\nCPU%d restarting CPUs: 0x%08x...", PCPU_GET(cpuid), + stopped_cpus); #endif /* VERBOSE_CPUSTOP_ON_DDBBREAK */ /* Restart all the CPUs we previously stopped */ - if (stopped_cpus != other_cpus && smp_started != 0) { + if (stopped_cpus != PCPU_GET(other_cpus) && smp_started != 0) { db_printf("whoa, other_cpus: 0x%08x, stopped_cpus: 0x%08x\n", - other_cpus, stopped_cpus); + PCPU_GET(other_cpus), stopped_cpus); panic("stop_cpus() failed"); } restart_cpus(stopped_cpus); diff --git a/sys/i386/i386/machdep.c b/sys/i386/i386/machdep.c index c1c6f29..5abdc05 100644 --- a/sys/i386/i386/machdep.c +++ b/sys/i386/i386/machdep.c @@ -1051,7 +1051,7 @@ setregs(p, entry, stack, ps_strings) regs->tf_ebx = ps_strings; /* reset %gs as well */ - if (pcb == curpcb) + if (pcb == PCPU_GET(curpcb)) load_gs(_udatasel); else pcb->pcb_gs = _udatasel; @@ -1067,7 +1067,7 @@ setregs(p, entry, stack, ps_strings) pcb->pcb_dr3 = 0; pcb->pcb_dr6 = 0; pcb->pcb_dr7 = 0; - if (pcb == curpcb) { + if (pcb == PCPU_GET(curpcb)) { /* * Clear the debug registers on the running * CPU, otherwise they will end up affecting @@ -1970,13 +1970,14 @@ init386(first) initializecpu(); /* Initialize CPU registers */ /* make an initial tss so cpu can get interrupt stack on syscall! */ - common_tss.tss_esp0 = (int) proc0.p_addr + UPAGES*PAGE_SIZE - 16; - common_tss.tss_ss0 = GSEL(GDATA_SEL, SEL_KPL); + PCPU_SET(common_tss.tss_esp0, + (int) proc0.p_addr + UPAGES*PAGE_SIZE - 16); + PCPU_SET(common_tss.tss_ss0, GSEL(GDATA_SEL, SEL_KPL)); gsel_tss = GSEL(GPROC0_SEL, SEL_KPL); private_tss = 0; - tss_gdt = &gdt[GPROC0_SEL].sd; - common_tssd = *tss_gdt; - common_tss.tss_ioopt = (sizeof common_tss) << 16; + PCPU_SET(tss_gdt, &gdt[GPROC0_SEL].sd); + PCPU_SET(common_tssd, *PCPU_GET(tss_gdt)); + PCPU_SET(common_tss.tss_ioopt, (sizeof (struct i386tss)) << 16); ltr(gsel_tss); dblfault_tss.tss_esp = dblfault_tss.tss_esp0 = dblfault_tss.tss_esp1 = diff --git a/sys/i386/i386/mp_machdep.c b/sys/i386/i386/mp_machdep.c index 6c3abeb..79fc383 100644 --- a/sys/i386/i386/mp_machdep.c +++ b/sys/i386/i386/mp_machdep.c @@ -484,11 +484,11 @@ init_secondary(void) gsel_tss = GSEL(GPROC0_SEL, SEL_KPL); gdt[myid * NGDT + GPROC0_SEL].sd.sd_type = SDT_SYS386TSS; - common_tss.tss_esp0 = 0; /* not used until after switch */ - common_tss.tss_ss0 = GSEL(GDATA_SEL, SEL_KPL); - common_tss.tss_ioopt = (sizeof common_tss) << 16; - tss_gdt = &gdt[myid * NGDT + GPROC0_SEL].sd; - common_tssd = *tss_gdt; + PCPU_SET(common_tss.tss_esp0, 0); /* not used until after switch */ + PCPU_SET(common_tss.tss_ss0, GSEL(GDATA_SEL, SEL_KPL)); + PCPU_SET(common_tss.tss_ioopt, (sizeof (struct i386tss)) << 16); + PCPU_SET(tss_gdt, &gdt[myid * NGDT + GPROC0_SEL].sd); + PCPU_SET(common_tssd, *PCPU_GET(tss_gdt)); ltr(gsel_tss); pmap_set_opt(); @@ -2045,7 +2045,7 @@ start_all_aps(u_int boot_addr) } /* build our map of 'other' CPUs */ - other_cpus = all_cpus & ~(1 << cpuid); + PCPU_SET(other_cpus, all_cpus & ~(1 << PCPU_GET(cpuid))); /* fill in our (BSP) APIC version */ cpu_apic_versions[0] = lapic.version; @@ -2398,9 +2398,9 @@ ap_init(void) #endif /* Build our map of 'other' CPUs. */ - other_cpus = all_cpus & ~(1 << cpuid); + PCPU_SET(other_cpus, all_cpus & ~(1 << PCPU_GET(cpuid))); - printf("SMP: AP CPU #%d Launched!\n", cpuid); + printf("SMP: AP CPU #%d Launched!\n", PCPU_GET(cpuid)); /* set up CPU registers and state */ cpu_setregs(); @@ -2410,8 +2410,8 @@ ap_init(void) /* A quick check from sanity claus */ apic_id = (apic_id_to_logical[(lapic.id & 0x0f000000) >> 24]); - if (cpuid != apic_id) { - printf("SMP: cpuid = %d\n", cpuid); + if (PCPU_GET(cpuid) != apic_id) { + printf("SMP: cpuid = %d\n", PCPU_GET(cpuid)); printf("SMP: apic_id = %d\n", apic_id); printf("PTD[MPPTDI] = %p\n", (void *)PTD[MPPTDI]); panic("cpuid mismatch! boom!!"); @@ -2445,10 +2445,10 @@ ap_init(void) * Set curproc to our per-cpu idleproc so that mutexes have * something unique to lock with. */ - PCPU_SET(curproc,idleproc); + PCPU_SET(curproc, PCPU_GET(idleproc)); - microuptime(&switchtime); - switchticks = ticks; + microuptime(PCPU_PTR(switchtime)); + PCPU_SET(switchticks, ticks); /* ok, now grab sched_lock and enter the scheduler */ enable_intr(); @@ -2610,7 +2610,7 @@ forward_statclock(int pscnt) /* Step 1: Probe state (user, cpu, interrupt, spinlock, idle ) */ - map = other_cpus & ~stopped_cpus ; + map = PCPU_GET(other_cpus) & ~stopped_cpus ; checkstate_probed_cpus = 0; if (map != 0) selected_apic_ipi(map, @@ -2636,7 +2636,7 @@ forward_statclock(int pscnt) map = 0; for (id = 0; id < mp_ncpus; id++) { - if (id == cpuid) + if (id == PCPU_GET(cpuid)) continue; if (((1 << id) & checkstate_probed_cpus) == 0) continue; @@ -2685,7 +2685,7 @@ forward_hardclock(int pscnt) /* Step 1: Probe state (user, cpu, interrupt, spinlock, idle) */ - map = other_cpus & ~stopped_cpus ; + map = PCPU_GET(other_cpus) & ~stopped_cpus ; checkstate_probed_cpus = 0; if (map != 0) selected_apic_ipi(map, @@ -2712,7 +2712,7 @@ forward_hardclock(int pscnt) map = 0; for (id = 0; id < mp_ncpus; id++) { - if (id == cpuid) + if (id == PCPU_GET(cpuid)) continue; if (((1 << id) & checkstate_probed_cpus) == 0) continue; @@ -2813,8 +2813,8 @@ forward_roundrobin(void) return; if (!forward_roundrobin_enabled) return; - resched_cpus |= other_cpus; - map = other_cpus & ~stopped_cpus ; + resched_cpus |= PCPU_GET(other_cpus); + map = PCPU_GET(other_cpus) & ~stopped_cpus ; #if 1 selected_apic_ipi(map, XCPUAST_OFFSET, APIC_DELMODE_FIXED); #else diff --git a/sys/i386/i386/mpapic.c b/sys/i386/i386/mpapic.c index 8b706c0..33aab28 100644 --- a/sys/i386/i386/mpapic.c +++ b/sys/i386/i386/mpapic.c @@ -62,7 +62,7 @@ apic_initialize(void) /* setup LVT1 as ExtINT */ temp = lapic.lvt_lint0; temp &= ~(APIC_LVT_M | APIC_LVT_TM | APIC_LVT_IIPP | APIC_LVT_DM); - if (cpuid == 0) + if (PCPU_GET(cpuid) == 0) temp |= 0x00000700; /* process ExtInts */ else temp |= 0x00010700; /* mask ExtInts */ @@ -94,7 +94,7 @@ apic_initialize(void) temp |= (XSPURIOUSINT_OFFSET & APIC_SVR_VEC_PROG); #if defined(TEST_TEST1) - if (cpuid == GUARD_CPU) { + if (PCPU_GET(cpuid) == GUARD_CPU) { temp &= ~APIC_SVR_SWEN; /* software DISABLE APIC */ } #endif /** TEST_TEST1 */ @@ -112,7 +112,7 @@ apic_initialize(void) void apic_dump(char* str) { - printf("SMP: CPU%d %s:\n", cpuid, str); + printf("SMP: CPU%d %s:\n", PCPU_GET(cpuid), str); printf(" lint0: 0x%08x lint1: 0x%08x TPR: 0x%08x SVR: 0x%08x\n", lapic.lvt_lint0, lapic.lvt_lint1, lapic.tpr, lapic.svr); } diff --git a/sys/i386/i386/mptable.c b/sys/i386/i386/mptable.c index 6c3abeb..79fc383 100644 --- a/sys/i386/i386/mptable.c +++ b/sys/i386/i386/mptable.c @@ -484,11 +484,11 @@ init_secondary(void) gsel_tss = GSEL(GPROC0_SEL, SEL_KPL); gdt[myid * NGDT + GPROC0_SEL].sd.sd_type = SDT_SYS386TSS; - common_tss.tss_esp0 = 0; /* not used until after switch */ - common_tss.tss_ss0 = GSEL(GDATA_SEL, SEL_KPL); - common_tss.tss_ioopt = (sizeof common_tss) << 16; - tss_gdt = &gdt[myid * NGDT + GPROC0_SEL].sd; - common_tssd = *tss_gdt; + PCPU_SET(common_tss.tss_esp0, 0); /* not used until after switch */ + PCPU_SET(common_tss.tss_ss0, GSEL(GDATA_SEL, SEL_KPL)); + PCPU_SET(common_tss.tss_ioopt, (sizeof (struct i386tss)) << 16); + PCPU_SET(tss_gdt, &gdt[myid * NGDT + GPROC0_SEL].sd); + PCPU_SET(common_tssd, *PCPU_GET(tss_gdt)); ltr(gsel_tss); pmap_set_opt(); @@ -2045,7 +2045,7 @@ start_all_aps(u_int boot_addr) } /* build our map of 'other' CPUs */ - other_cpus = all_cpus & ~(1 << cpuid); + PCPU_SET(other_cpus, all_cpus & ~(1 << PCPU_GET(cpuid))); /* fill in our (BSP) APIC version */ cpu_apic_versions[0] = lapic.version; @@ -2398,9 +2398,9 @@ ap_init(void) #endif /* Build our map of 'other' CPUs. */ - other_cpus = all_cpus & ~(1 << cpuid); + PCPU_SET(other_cpus, all_cpus & ~(1 << PCPU_GET(cpuid))); - printf("SMP: AP CPU #%d Launched!\n", cpuid); + printf("SMP: AP CPU #%d Launched!\n", PCPU_GET(cpuid)); /* set up CPU registers and state */ cpu_setregs(); @@ -2410,8 +2410,8 @@ ap_init(void) /* A quick check from sanity claus */ apic_id = (apic_id_to_logical[(lapic.id & 0x0f000000) >> 24]); - if (cpuid != apic_id) { - printf("SMP: cpuid = %d\n", cpuid); + if (PCPU_GET(cpuid) != apic_id) { + printf("SMP: cpuid = %d\n", PCPU_GET(cpuid)); printf("SMP: apic_id = %d\n", apic_id); printf("PTD[MPPTDI] = %p\n", (void *)PTD[MPPTDI]); panic("cpuid mismatch! boom!!"); @@ -2445,10 +2445,10 @@ ap_init(void) * Set curproc to our per-cpu idleproc so that mutexes have * something unique to lock with. */ - PCPU_SET(curproc,idleproc); + PCPU_SET(curproc, PCPU_GET(idleproc)); - microuptime(&switchtime); - switchticks = ticks; + microuptime(PCPU_PTR(switchtime)); + PCPU_SET(switchticks, ticks); /* ok, now grab sched_lock and enter the scheduler */ enable_intr(); @@ -2610,7 +2610,7 @@ forward_statclock(int pscnt) /* Step 1: Probe state (user, cpu, interrupt, spinlock, idle ) */ - map = other_cpus & ~stopped_cpus ; + map = PCPU_GET(other_cpus) & ~stopped_cpus ; checkstate_probed_cpus = 0; if (map != 0) selected_apic_ipi(map, @@ -2636,7 +2636,7 @@ forward_statclock(int pscnt) map = 0; for (id = 0; id < mp_ncpus; id++) { - if (id == cpuid) + if (id == PCPU_GET(cpuid)) continue; if (((1 << id) & checkstate_probed_cpus) == 0) continue; @@ -2685,7 +2685,7 @@ forward_hardclock(int pscnt) /* Step 1: Probe state (user, cpu, interrupt, spinlock, idle) */ - map = other_cpus & ~stopped_cpus ; + map = PCPU_GET(other_cpus) & ~stopped_cpus ; checkstate_probed_cpus = 0; if (map != 0) selected_apic_ipi(map, @@ -2712,7 +2712,7 @@ forward_hardclock(int pscnt) map = 0; for (id = 0; id < mp_ncpus; id++) { - if (id == cpuid) + if (id == PCPU_GET(cpuid)) continue; if (((1 << id) & checkstate_probed_cpus) == 0) continue; @@ -2813,8 +2813,8 @@ forward_roundrobin(void) return; if (!forward_roundrobin_enabled) return; - resched_cpus |= other_cpus; - map = other_cpus & ~stopped_cpus ; + resched_cpus |= PCPU_GET(other_cpus); + map = PCPU_GET(other_cpus) & ~stopped_cpus ; #if 1 selected_apic_ipi(map, XCPUAST_OFFSET, APIC_DELMODE_FIXED); #else diff --git a/sys/i386/i386/pmap.c b/sys/i386/i386/pmap.c index ef4d3f0..aa5f94e 100644 --- a/sys/i386/i386/pmap.c +++ b/sys/i386/i386/pmap.c @@ -453,7 +453,7 @@ pmap_set_opt(void) { if (pseflag && (cpu_feature & CPUID_PSE)) { load_cr4(rcr4() | CR4_PSE); - if (pdir4mb && cpuid == 0) { /* only on BSP */ + if (pdir4mb && PCPU_GET(cpuid) == 0) { /* only on BSP */ kernel_pmap->pm_pdir[KPTDI] = PTD[KPTDI] = (pd_entry_t)pdir4mb; cpu_invltlb(); @@ -581,9 +581,9 @@ static __inline void pmap_TLB_invalidate(pmap_t pmap, vm_offset_t va) { #if defined(SMP) - if (pmap->pm_active & (1 << cpuid)) + if (pmap->pm_active & (1 << PCPU_GET(cpuid))) cpu_invlpg((void *)va); - if (pmap->pm_active & other_cpus) + if (pmap->pm_active & PCPU_GET(other_cpus)) smp_invltlb(); #else if (pmap->pm_active) @@ -595,9 +595,9 @@ static __inline void pmap_TLB_invalidate_all(pmap_t pmap) { #if defined(SMP) - if (pmap->pm_active & (1 << cpuid)) + if (pmap->pm_active & (1 << PCPU_GET(cpuid))) cpu_invltlb(); - if (pmap->pm_active & other_cpus) + if (pmap->pm_active & PCPU_GET(other_cpus)) smp_invltlb(); #else if (pmap->pm_active) @@ -652,11 +652,11 @@ pmap_pte_quick(pmap, va) } newpf = pde & PG_FRAME; #ifdef SMP - if ( ((* (unsigned *) prv_PMAP1) & PG_FRAME) != newpf) { - * (unsigned *) prv_PMAP1 = newpf | PG_RW | PG_V; - cpu_invlpg(prv_PADDR1); + if ( ((* (unsigned *) PCPU_GET(prv_PMAP1)) & PG_FRAME) != newpf) { + * (unsigned *) PCPU_GET(prv_PMAP1) = newpf | PG_RW | PG_V; + cpu_invlpg(PCPU_GET(prv_PADDR1)); } - return (unsigned *)(prv_PADDR1 + (index & (NPTEPG - 1))); + return (unsigned *)(PCPU_GET(prv_PADDR1) + (index & (NPTEPG - 1))); #else if ( ((* (unsigned *) PMAP1) & PG_FRAME) != newpf) { * (unsigned *) PMAP1 = newpf | PG_RW | PG_V; @@ -1985,11 +1985,11 @@ pmap_enter(pmap_t pmap, vm_offset_t va, vm_page_t m, vm_prot_t prot, pmap->pm_pdir[PTDPTDI], origpte, va); } if (smp_active) { - pdeaddr = (vm_offset_t *) IdlePTDS[cpuid]; + pdeaddr = (vm_offset_t *) IdlePTDS[PCPU_GET(cpuid)]; if (((newpte = pdeaddr[va >> PDRSHIFT]) & PG_V) == 0) { if ((vm_offset_t) my_idlePTD != (vm_offset_t) vtophys(pdeaddr)) printf("pde mismatch: %x, %x\n", my_idlePTD, pdeaddr); - printf("cpuid: %d, pdeaddr: 0x%x\n", cpuid, pdeaddr); + printf("cpuid: %d, pdeaddr: 0x%x\n", PCPU_GET(cpuid), pdeaddr); panic("pmap_enter: invalid kernel page table page(1), pdir=%p, npde=%p, pde=%p, va=%p\n", pmap->pm_pdir[PTDPTDI], newpte, origpte, va); } @@ -2048,7 +2048,7 @@ pmap_enter(pmap_t pmap, vm_offset_t va, vm_page_t m, vm_prot_t prot, *pte |= PG_RW; #ifdef SMP cpu_invlpg((void *)va); - if (pmap->pm_active & other_cpus) + if (pmap->pm_active & PCPU_GET(other_cpus)) smp_invltlb(); #else invltlb_1pg(va); @@ -2122,7 +2122,7 @@ validate: /*if (origpte)*/ { #ifdef SMP cpu_invlpg((void *)va); - if (pmap->pm_active & other_cpus) + if (pmap->pm_active & PCPU_GET(other_cpus)) smp_invltlb(); #else invltlb_1pg(va); @@ -2666,20 +2666,20 @@ pmap_zero_page(phys) vm_offset_t phys; { #ifdef SMP - if (*(int *) prv_CMAP3) + if (*(int *) PCPU_GET(prv_CMAP3)) panic("pmap_zero_page: prv_CMAP3 busy"); - *(int *) prv_CMAP3 = PG_V | PG_RW | (phys & PG_FRAME) | PG_A | PG_M; - cpu_invlpg(prv_CADDR3); + *(int *) PCPU_GET(prv_CMAP3) = PG_V | PG_RW | (phys & PG_FRAME) | PG_A | PG_M; + cpu_invlpg(PCPU_GET(prv_CADDR3)); #if defined(I686_CPU) if (cpu_class == CPUCLASS_686) - i686_pagezero(prv_CADDR3); + i686_pagezero(PCPU_GET(prv_CADDR3)); else #endif - bzero(prv_CADDR3, PAGE_SIZE); + bzero(PCPU_GET(prv_CADDR3), PAGE_SIZE); - *(int *) prv_CMAP3 = 0; + *(int *) PCPU_GET(prv_CMAP3) = 0; #else if (*(int *) CMAP2) panic("pmap_zero_page: CMAP2 busy"); @@ -2710,20 +2710,20 @@ pmap_zero_page_area(phys, off, size) int size; { #ifdef SMP - if (*(int *) prv_CMAP3) + if (*(int *) PCPU_GET(prv_CMAP3)) panic("pmap_zero_page: prv_CMAP3 busy"); - *(int *) prv_CMAP3 = PG_V | PG_RW | (phys & PG_FRAME) | PG_A | PG_M; - cpu_invlpg(prv_CADDR3); + *(int *) PCPU_GET(prv_CMAP3) = PG_V | PG_RW | (phys & PG_FRAME) | PG_A | PG_M; + cpu_invlpg(PCPU_GET(prv_CADDR3)); #if defined(I686_CPU) if (cpu_class == CPUCLASS_686 && off == 0 && size == PAGE_SIZE) - i686_pagezero(prv_CADDR3); + i686_pagezero(PCPU_GET(prv_CADDR3)); else #endif - bzero((char *)prv_CADDR3 + off, size); + bzero((char *)PCPU_GET(prv_CADDR3) + off, size); - *(int *) prv_CMAP3 = 0; + *(int *) PCPU_GET(prv_CMAP3) = 0; #else if (*(int *) CMAP2) panic("pmap_zero_page: CMAP2 busy"); @@ -2753,21 +2753,22 @@ pmap_copy_page(src, dst) vm_offset_t dst; { #ifdef SMP - if (*(int *) prv_CMAP1) + if (*(int *) PCPU_GET(prv_CMAP1)) panic("pmap_copy_page: prv_CMAP1 busy"); - if (*(int *) prv_CMAP2) + if (*(int *) PCPU_GET(prv_CMAP2)) panic("pmap_copy_page: prv_CMAP2 busy"); - *(int *) prv_CMAP1 = PG_V | (src & PG_FRAME) | PG_A; - *(int *) prv_CMAP2 = PG_V | PG_RW | (dst & PG_FRAME) | PG_A | PG_M; + *(int *) PCPU_GET(prv_CMAP1) = PG_V | (src & PG_FRAME) | PG_A; + *(int *) PCPU_GET(prv_CMAP2) = PG_V | PG_RW | (dst & PG_FRAME) | PG_A | PG_M; - cpu_invlpg(prv_CADDR1); - cpu_invlpg(prv_CADDR2); + cpu_invlpg(PCPU_GET(prv_CADDR1)); + cpu_invlpg(PCPU_GET(prv_CADDR2)); - bcopy(prv_CADDR1, prv_CADDR2, PAGE_SIZE); + bcopy(PCPU_GET(prv_CADDR1), PCPU_GET(prv_CADDR2), PAGE_SIZE); + + *(int *) PCPU_GET(prv_CMAP1) = 0; + *(int *) PCPU_GET(prv_CMAP2) = 0; - *(int *) prv_CMAP1 = 0; - *(int *) prv_CMAP2 = 0; #else if (*(int *) CMAP1 || *(int *) CMAP2) panic("pmap_copy_page: CMAP busy"); @@ -3294,7 +3295,7 @@ pmap_activate(struct proc *p) pmap = vmspace_pmap(p->p_vmspace); #if defined(SMP) - pmap->pm_active |= 1 << cpuid; + pmap->pm_active |= 1 << PCPU_GET(cpuid); #else pmap->pm_active |= 1; #endif diff --git a/sys/i386/i386/sys_machdep.c b/sys/i386/i386/sys_machdep.c index d09d882..e242b73 100644 --- a/sys/i386/i386/sys_machdep.c +++ b/sys/i386/i386/sys_machdep.c @@ -252,12 +252,12 @@ set_user_ldt(struct pcb *pcb) { struct pcb_ldt *pcb_ldt; - if (pcb != curpcb) + if (pcb != PCPU_GET(curpcb)) return; pcb_ldt = pcb->pcb_ldt; #ifdef SMP - gdt[cpuid * NGDT + GUSERLDT_SEL].sd = pcb_ldt->ldt_sd; + gdt[PCPU_GET(cpuid) * NGDT + GUSERLDT_SEL].sd = pcb_ldt->ldt_sd; #else gdt[GUSERLDT_SEL].sd = pcb_ldt->ldt_sd; #endif @@ -308,7 +308,7 @@ user_ldt_free(struct pcb *pcb) if (pcb_ldt == NULL) return; - if (pcb == curpcb) { + if (pcb == PCPU_GET(curpcb)) { lldt(_default_ldt); PCPU_SET(currentldt, _default_ldt); } diff --git a/sys/i386/i386/trap.c b/sys/i386/i386/trap.c index db02d51..959c64f 100644 --- a/sys/i386/i386/trap.c +++ b/sys/i386/i386/trap.c @@ -480,7 +480,7 @@ restart: if (in_vm86call) break; - if (intr_nesting_level != 0) + if (PCPU_GET(intr_nesting_level) != 0) break; /* @@ -493,7 +493,7 @@ restart: * a signal. */ if (frame.tf_eip == (int)cpu_switch_load_gs) { - curpcb->pcb_gs = 0; + PCPU_GET(curpcb)->pcb_gs = 0; psignal(p, SIGBUS); goto out; } @@ -519,13 +519,15 @@ restart: if (frame.tf_eip == (int)doreti_popl_es) { frame.tf_eip = (int)doreti_popl_es_fault; goto out; - } + } if (frame.tf_eip == (int)doreti_popl_fs) { frame.tf_eip = (int)doreti_popl_fs_fault; goto out; } - if (curpcb && curpcb->pcb_onfault) { - frame.tf_eip = (int)curpcb->pcb_onfault; + if (PCPU_GET(curpcb) != NULL && + PCPU_GET(curpcb)->pcb_onfault != NULL) { + frame.tf_eip = + (int)PCPU_GET(curpcb)->pcb_onfault; goto out; } break; @@ -685,8 +687,9 @@ trap_pfault(frame, usermode, eva) if (p == NULL || (!usermode && va < VM_MAXUSER_ADDRESS && - (intr_nesting_level != 0 || curpcb == NULL || - curpcb->pcb_onfault == NULL))) { + (PCPU_GET(intr_nesting_level) != 0 || + PCPU_GET(curpcb) == NULL || + PCPU_GET(curpcb)->pcb_onfault == NULL))) { trap_fatal(frame, eva); return (-1); } @@ -748,8 +751,10 @@ trap_pfault(frame, usermode, eva) return (0); nogo: if (!usermode) { - if (intr_nesting_level == 0 && curpcb && curpcb->pcb_onfault) { - frame->tf_eip = (int)curpcb->pcb_onfault; + if (PCPU_GET(intr_nesting_level) == 0 && + PCPU_GET(curpcb) != NULL && + PCPU_GET(curpcb)->pcb_onfault != NULL) { + frame->tf_eip = (int)PCPU_GET(curpcb)->pcb_onfault; return (0); } trap_fatal(frame, eva); @@ -853,8 +858,10 @@ trap_pfault(frame, usermode, eva) return (0); nogo: if (!usermode) { - if (intr_nesting_level == 0 && curpcb && curpcb->pcb_onfault) { - frame->tf_eip = (int)curpcb->pcb_onfault; + if (PCPU_GET(intr_nesting_level) == 0 && + PCPU_GET(curpcb) != NULL && + PCPU_GET(curpcb)->pcb_onfault != NULL) { + frame->tf_eip = (int)PCPU_GET(curpcb)->pcb_onfault; return (0); } trap_fatal(frame, eva); @@ -886,7 +893,7 @@ trap_fatal(frame, eva) ISPL(frame->tf_cs) == SEL_UPL ? "user" : "kernel"); #ifdef SMP /* two seperate prints in case of a trap on an unmapped page */ - printf("cpuid = %d; ", cpuid); + printf("cpuid = %d; ", PCPU_GET(cpuid)); printf("lapic.id = %08x\n", lapic.id); #endif if (type == T_PAGEFLT) { @@ -964,12 +971,12 @@ void dblfault_handler() { printf("\nFatal double fault:\n"); - printf("eip = 0x%x\n", common_tss.tss_eip); - printf("esp = 0x%x\n", common_tss.tss_esp); - printf("ebp = 0x%x\n", common_tss.tss_ebp); + printf("eip = 0x%x\n", PCPU_GET(common_tss.tss_eip)); + printf("esp = 0x%x\n", PCPU_GET(common_tss.tss_esp)); + printf("ebp = 0x%x\n", PCPU_GET(common_tss.tss_ebp)); #ifdef SMP /* two seperate prints in case of a trap on an unmapped page */ - printf("cpuid = %d; ", cpuid); + printf("cpuid = %d; ", PCPU_GET(cpuid)); printf("lapic.id = %08x\n", lapic.id); #endif panic("double fault"); diff --git a/sys/i386/i386/vm86.c b/sys/i386/i386/vm86.c index 08555b6..b081eef 100644 --- a/sys/i386/i386/vm86.c +++ b/sys/i386/i386/vm86.c @@ -143,9 +143,9 @@ vm86_emulate(vmf) * the extension is not present. (This check should not be needed, * as we can't enter vm86 mode until we set up an extension area) */ - if (curpcb->pcb_ext == 0) + if (PCPU_GET(curpcb)->pcb_ext == 0) return (SIGBUS); - vm86 = &curpcb->pcb_ext->ext_vm86; + vm86 = &PCPU_GET(curpcb)->pcb_ext->ext_vm86; if (vmf->vmf_eflags & PSL_T) retcode = SIGTRAP; @@ -507,7 +507,7 @@ static void vm86_initflags(struct vm86frame *vmf) { int eflags = vmf->vmf_eflags; - struct vm86_kernel *vm86 = &curpcb->pcb_ext->ext_vm86; + struct vm86_kernel *vm86 = &PCPU_GET(curpcb)->pcb_ext->ext_vm86; if (vm86->vm86_has_vme) { eflags = (vmf->vmf_eflags & ~VME_USERCHANGE) | diff --git a/sys/i386/i386/vm_machdep.c b/sys/i386/i386/vm_machdep.c index 0a3bc51..552967c 100644 --- a/sys/i386/i386/vm_machdep.c +++ b/sys/i386/i386/vm_machdep.c @@ -143,7 +143,7 @@ cpu_fork(p1, p2, flags) #if NNPX > 0 /* Ensure that p1's pcb is up to date. */ - if (npxproc == p1) + if (PCPU_GET(npxproc) == p1) npxsave(&p1->p_addr->u_pcb.pcb_savefpu); #endif @@ -442,23 +442,23 @@ cpu_reset() u_int map; int cnt; - printf("cpu_reset called on cpu#%d\n",cpuid); + printf("cpu_reset called on cpu#%d\n", PCPU_GET(cpuid)); - map = other_cpus & ~ stopped_cpus; + map = PCPU_GET(other_cpus) & ~ stopped_cpus; if (map != 0) { printf("cpu_reset: Stopping other CPUs\n"); stop_cpus(map); /* Stop all other CPUs */ } - if (cpuid == 0) { + if (PCPU_GET(cpuid) == 0) { DELAY(1000000); cpu_reset_real(); /* NOTREACHED */ } else { /* We are not BSP (CPU #0) */ - cpu_reset_proxyid = cpuid; + cpu_reset_proxyid = PCPU_GET(cpuid); cpustop_restartfunc = cpu_reset_proxy; cpu_reset_proxy_active = 0; printf("cpu_reset: Restarting BSP\n"); diff --git a/sys/i386/include/cpu.h b/sys/i386/include/cpu.h index 4c6cb43..6c4162b 100644 --- a/sys/i386/include/cpu.h +++ b/sys/i386/include/cpu.h @@ -62,7 +62,7 @@ #define CLKF_USERMODE(framep) \ ((ISPL((framep)->cf_cs) == SEL_UPL) || (framep->cf_eflags & PSL_VM)) -#define CLKF_INTR(framep) (intr_nesting_level >= 2) +#define CLKF_INTR(framep) (PCPU_GET(intr_nesting_level) >= 2) #define CLKF_PC(framep) ((framep)->cf_eip) /* @@ -82,7 +82,7 @@ #define need_resched() do { \ PCPU_SET(astpending, AST_RESCHED|AST_PENDING); \ } while (0) -#define resched_wanted() (astpending & AST_RESCHED) +#define resched_wanted() (PCPU_GET(astpending) & AST_RESCHED) /* * Arrange to handle pending profiling ticks before returning to user mode. @@ -105,7 +105,7 @@ */ #define signotify(p) aston() #define aston() do { \ - PCPU_SET(astpending, astpending | AST_PENDING); \ + PCPU_SET(astpending, PCPU_GET(astpending) | AST_PENDING); \ } while (0) #define astoff() diff --git a/sys/i386/include/mptable.h b/sys/i386/include/mptable.h index 6c3abeb..79fc383 100644 --- a/sys/i386/include/mptable.h +++ b/sys/i386/include/mptable.h @@ -484,11 +484,11 @@ init_secondary(void) gsel_tss = GSEL(GPROC0_SEL, SEL_KPL); gdt[myid * NGDT + GPROC0_SEL].sd.sd_type = SDT_SYS386TSS; - common_tss.tss_esp0 = 0; /* not used until after switch */ - common_tss.tss_ss0 = GSEL(GDATA_SEL, SEL_KPL); - common_tss.tss_ioopt = (sizeof common_tss) << 16; - tss_gdt = &gdt[myid * NGDT + GPROC0_SEL].sd; - common_tssd = *tss_gdt; + PCPU_SET(common_tss.tss_esp0, 0); /* not used until after switch */ + PCPU_SET(common_tss.tss_ss0, GSEL(GDATA_SEL, SEL_KPL)); + PCPU_SET(common_tss.tss_ioopt, (sizeof (struct i386tss)) << 16); + PCPU_SET(tss_gdt, &gdt[myid * NGDT + GPROC0_SEL].sd); + PCPU_SET(common_tssd, *PCPU_GET(tss_gdt)); ltr(gsel_tss); pmap_set_opt(); @@ -2045,7 +2045,7 @@ start_all_aps(u_int boot_addr) } /* build our map of 'other' CPUs */ - other_cpus = all_cpus & ~(1 << cpuid); + PCPU_SET(other_cpus, all_cpus & ~(1 << PCPU_GET(cpuid))); /* fill in our (BSP) APIC version */ cpu_apic_versions[0] = lapic.version; @@ -2398,9 +2398,9 @@ ap_init(void) #endif /* Build our map of 'other' CPUs. */ - other_cpus = all_cpus & ~(1 << cpuid); + PCPU_SET(other_cpus, all_cpus & ~(1 << PCPU_GET(cpuid))); - printf("SMP: AP CPU #%d Launched!\n", cpuid); + printf("SMP: AP CPU #%d Launched!\n", PCPU_GET(cpuid)); /* set up CPU registers and state */ cpu_setregs(); @@ -2410,8 +2410,8 @@ ap_init(void) /* A quick check from sanity claus */ apic_id = (apic_id_to_logical[(lapic.id & 0x0f000000) >> 24]); - if (cpuid != apic_id) { - printf("SMP: cpuid = %d\n", cpuid); + if (PCPU_GET(cpuid) != apic_id) { + printf("SMP: cpuid = %d\n", PCPU_GET(cpuid)); printf("SMP: apic_id = %d\n", apic_id); printf("PTD[MPPTDI] = %p\n", (void *)PTD[MPPTDI]); panic("cpuid mismatch! boom!!"); @@ -2445,10 +2445,10 @@ ap_init(void) * Set curproc to our per-cpu idleproc so that mutexes have * something unique to lock with. */ - PCPU_SET(curproc,idleproc); + PCPU_SET(curproc, PCPU_GET(idleproc)); - microuptime(&switchtime); - switchticks = ticks; + microuptime(PCPU_PTR(switchtime)); + PCPU_SET(switchticks, ticks); /* ok, now grab sched_lock and enter the scheduler */ enable_intr(); @@ -2610,7 +2610,7 @@ forward_statclock(int pscnt) /* Step 1: Probe state (user, cpu, interrupt, spinlock, idle ) */ - map = other_cpus & ~stopped_cpus ; + map = PCPU_GET(other_cpus) & ~stopped_cpus ; checkstate_probed_cpus = 0; if (map != 0) selected_apic_ipi(map, @@ -2636,7 +2636,7 @@ forward_statclock(int pscnt) map = 0; for (id = 0; id < mp_ncpus; id++) { - if (id == cpuid) + if (id == PCPU_GET(cpuid)) continue; if (((1 << id) & checkstate_probed_cpus) == 0) continue; @@ -2685,7 +2685,7 @@ forward_hardclock(int pscnt) /* Step 1: Probe state (user, cpu, interrupt, spinlock, idle) */ - map = other_cpus & ~stopped_cpus ; + map = PCPU_GET(other_cpus) & ~stopped_cpus ; checkstate_probed_cpus = 0; if (map != 0) selected_apic_ipi(map, @@ -2712,7 +2712,7 @@ forward_hardclock(int pscnt) map = 0; for (id = 0; id < mp_ncpus; id++) { - if (id == cpuid) + if (id == PCPU_GET(cpuid)) continue; if (((1 << id) & checkstate_probed_cpus) == 0) continue; @@ -2813,8 +2813,8 @@ forward_roundrobin(void) return; if (!forward_roundrobin_enabled) return; - resched_cpus |= other_cpus; - map = other_cpus & ~stopped_cpus ; + resched_cpus |= PCPU_GET(other_cpus); + map = PCPU_GET(other_cpus) & ~stopped_cpus ; #if 1 selected_apic_ipi(map, XCPUAST_OFFSET, APIC_DELMODE_FIXED); #else diff --git a/sys/i386/isa/npx.c b/sys/i386/isa/npx.c index 2672a63..b79d511 100644 --- a/sys/i386/isa/npx.c +++ b/sys/i386/isa/npx.c @@ -493,8 +493,8 @@ npxinit(control) npxsave(&dummy); stop_emulating(); fldcw(&control); - if (curpcb != NULL) - fnsave(&curpcb->pcb_savefpu); + if (PCPU_GET(curpcb) != NULL) + fnsave(&PCPU_GET(curpcb)->pcb_savefpu); start_emulating(); } @@ -506,14 +506,14 @@ npxexit(p) struct proc *p; { - if (p == npxproc) - npxsave(&curpcb->pcb_savefpu); + if (p == PCPU_GET(npxproc)) + npxsave(&PCPU_GET(curpcb)->pcb_savefpu); #ifdef NPX_DEBUG if (npx_exists) { u_int masked_exceptions; - masked_exceptions = curpcb->pcb_savefpu.sv_env.en_cw - & curpcb->pcb_savefpu.sv_env.en_sw & 0x7f; + masked_exceptions = PCPU_GET(curpcb)->pcb_savefpu.sv_env.en_cw + &PCPU_GET(curpcb)->pcb_savefpu.sv_env.en_sw & 0x7f; /* * Log exceptions that would have trapped with the old * control word (overflow, divide by 0, and invalid operand). @@ -722,19 +722,19 @@ npx_intr(dummy) u_short control; struct intrframe *frame; - if (npxproc == NULL || !npx_exists) { + if (PCPU_GET(npxproc) == NULL || !npx_exists) { printf("npxintr: npxproc = %p, curproc = %p, npx_exists = %d\n", - npxproc, curproc, npx_exists); + PCPU_GET(npxproc), curproc, npx_exists); panic("npxintr from nowhere"); } - if (npxproc != curproc) { + if (PCPU_GET(npxproc) != curproc) { printf("npxintr: npxproc = %p, curproc = %p, npx_exists = %d\n", - npxproc, curproc, npx_exists); + PCPU_GET(npxproc), curproc, npx_exists); panic("npxintr from non-current process"); } outb(0xf0, 0); - fnstsw(&curpcb->pcb_savefpu.sv_ex_sw); + fnstsw(&PCPU_GET(curpcb)->pcb_savefpu.sv_ex_sw); fnstcw(&control); fnclex(); @@ -760,8 +760,8 @@ npx_intr(dummy) * this exception. */ code = - fpetable[(curpcb->pcb_savefpu.sv_ex_sw & ~control & 0x3f) | - (curpcb->pcb_savefpu.sv_ex_sw & 0x40)]; + fpetable[(PCPU_GET(curpcb)->pcb_savefpu.sv_ex_sw & ~control & 0x3f) | + (PCPU_GET(curpcb)->pcb_savefpu.sv_ex_sw & 0x40)]; trapsignal(curproc, SIGFPE, code); } else { /* @@ -794,9 +794,9 @@ npxdna() { if (!npx_exists) return (0); - if (npxproc != NULL) { + if (PCPU_GET(npxproc) != NULL) { printf("npxdna: npxproc = %p, curproc = %p\n", - npxproc, curproc); + PCPU_GET(npxproc), curproc); panic("npxdna"); } stop_emulating(); @@ -804,7 +804,7 @@ npxdna() * Record new context early in case frstor causes an IRQ13. */ PCPU_SET(npxproc, CURPROC); - curpcb->pcb_savefpu.sv_ex_sw = 0; + PCPU_GET(curpcb)->pcb_savefpu.sv_ex_sw = 0; /* * The following frstor may cause an IRQ13 when the state being * restored has a pending error. The error will appear to have been @@ -817,7 +817,7 @@ npxdna() * fnsave are broken, so our treatment breaks fnclex if it is the * first FPU instruction after a context switch. */ - frstor(&curpcb->pcb_savefpu); + frstor(&PCPU_GET(curpcb)->pcb_savefpu); return (1); } |