Module Name: src Committed By: mrg Date: Sat Mar 6 08:08:30 UTC 2010
Modified Files: src/sys/arch/sparc64/include: cpu.h intr.h pmap.h src/sys/arch/sparc64/sparc64: autoconf.c cache.h cpu.c db_interface.c pmap.c Log Message: clean up a bunch of MULTIPROCESSOR: - always include ci_ipi_evcnt[] in cpuinfo - #define sparc_ncpus 1 for !MULTIPROCESSOR - make struct pmap::pm_list an pm_ctx always be an array, and simplify several functions and lookups to always be the same tested on U60 and SB2500 before and after with one and two cpus in an MP kernel, and UP kernels, and i can't find anything besides noise for benchmark issues. (infact, i can't really tell the difference between GENERIC and GENERIC.MP on these systems...) To generate a diff of this commit: cvs rdiff -u -r1.88 -r1.89 src/sys/arch/sparc64/include/cpu.h cvs rdiff -u -r1.27 -r1.28 src/sys/arch/sparc64/include/intr.h cvs rdiff -u -r1.51 -r1.52 src/sys/arch/sparc64/include/pmap.h cvs rdiff -u -r1.171 -r1.172 src/sys/arch/sparc64/sparc64/autoconf.c cvs rdiff -u -r1.15 -r1.16 src/sys/arch/sparc64/sparc64/cache.h cvs rdiff -u -r1.89 -r1.90 src/sys/arch/sparc64/sparc64/cpu.c cvs rdiff -u -r1.122 -r1.123 src/sys/arch/sparc64/sparc64/db_interface.c cvs rdiff -u -r1.256 -r1.257 src/sys/arch/sparc64/sparc64/pmap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/sparc64/include/cpu.h diff -u src/sys/arch/sparc64/include/cpu.h:1.88 src/sys/arch/sparc64/include/cpu.h:1.89 --- src/sys/arch/sparc64/include/cpu.h:1.88 Tue Feb 2 04:28:55 2010 +++ src/sys/arch/sparc64/include/cpu.h Sat Mar 6 08:08:29 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: cpu.h,v 1.88 2010/02/02 04:28:55 mrg Exp $ */ +/* $NetBSD: cpu.h,v 1.89 2010/03/06 08:08:29 mrg Exp $ */ /* * Copyright (c) 1992, 1993 @@ -131,9 +131,9 @@ /* Event counters */ struct evcnt ci_tick_evcnt; -#ifdef MULTIPROCESSOR + + /* This could be under MULTIPROCESSOR, but there's no good reason */ struct evcnt ci_ipi_evcnt[IPI_EVCNT_NUM]; -#endif int ci_flags; int ci_want_ast; @@ -191,7 +191,12 @@ extern struct cpu_bootargs *cpu_args; +#if defined(MULTIPROCESSOR) extern int sparc_ncpus; +#else +#define sparc_ncpus 1 +#endif + extern struct cpu_info *cpus; extern struct pool_cache *fpstate_cache; Index: src/sys/arch/sparc64/include/intr.h diff -u src/sys/arch/sparc64/include/intr.h:1.27 src/sys/arch/sparc64/include/intr.h:1.28 --- src/sys/arch/sparc64/include/intr.h:1.27 Mon Feb 1 02:42:33 2010 +++ src/sys/arch/sparc64/include/intr.h Sat Mar 6 08:08:29 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: intr.h,v 1.27 2010/02/01 02:42:33 mrg Exp $ */ +/* $NetBSD: intr.h,v 1.28 2010/03/06 08:08:29 mrg Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -73,12 +73,12 @@ int mp_cpu_is_paused (sparc64_cpuset_t); void mp_resume_cpu(int); #endif /* _LOCORE */ +#endif #define IPI_EVCNT_TLB_PTE 0 #define IPI_EVCNT_FPU_SYNCH 1 #define IPI_EVCNT_FPU_FLUSH 2 #define IPI_EVCNT_NUM 3 #define IPI_EVCNT_NAMES { "TLB pte IPI", "FPU synch IPI", "FPU flush IPI" } -#endif #endif /* _SPARC64_INTR_H_ */ Index: src/sys/arch/sparc64/include/pmap.h diff -u src/sys/arch/sparc64/include/pmap.h:1.51 src/sys/arch/sparc64/include/pmap.h:1.52 --- src/sys/arch/sparc64/include/pmap.h:1.51 Thu Mar 4 08:01:35 2010 +++ src/sys/arch/sparc64/include/pmap.h Sat Mar 6 08:08:29 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: pmap.h,v 1.51 2010/03/04 08:01:35 mrg Exp $ */ +/* $NetBSD: pmap.h,v 1.52 2010/03/06 08:08:29 mrg Exp $ */ /*- * Copyright (C) 1995, 1996 Wolfgang Solfrank. @@ -111,19 +111,20 @@ #define va_to_dir(v) (int)((((paddr_t)(v))>>PDSHIFT)&PDMASK) #define va_to_pte(v) (int)((((paddr_t)(v))>>PTSHIFT)&PTMASK) +#ifdef MULTIPROCESSOR +#define PMAP_LIST_MAXNUMCPU CPUSET_MAXNUMCPU +#else +#define PMAP_LIST_MAXNUMCPU 1 +#endif + struct pmap { struct uvm_object pm_obj; #define pm_lock pm_obj.vmobjlock #define pm_refs pm_obj.uo_refs -#ifdef MULTIPROCESSOR - LIST_ENTRY(pmap) pm_list[CPUSET_MAXNUMCPU]; /* per cpu ctx used list */ -#else - LIST_ENTRY(pmap) pm_list; /* single ctx used list */ -#endif + LIST_ENTRY(pmap) pm_list[PMAP_LIST_MAXNUMCPU]; /* per cpu ctx used list */ struct pmap_statistics pm_stats; -#ifdef MULTIPROCESSOR /* * We record the context used on any cpu here. If the context * is actually present in the TLB, it will be the plain context @@ -132,10 +133,7 @@ * If this pmap has no context allocated on that cpu, the entry * will be 0. */ - int pm_ctx[CPUSET_MAXNUMCPU]; /* Current context per cpu */ -#else - int pm_ctx; /* Current context */ -#endif + int pm_ctx[PMAP_LIST_MAXNUMCPU]; /* Current context per cpu */ /* * This contains 64-bit pointers to pages that contain Index: src/sys/arch/sparc64/sparc64/autoconf.c diff -u src/sys/arch/sparc64/sparc64/autoconf.c:1.171 src/sys/arch/sparc64/sparc64/autoconf.c:1.172 --- src/sys/arch/sparc64/sparc64/autoconf.c:1.171 Mon Mar 1 01:14:58 2010 +++ src/sys/arch/sparc64/sparc64/autoconf.c Sat Mar 6 08:08:29 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: autoconf.c,v 1.171 2010/03/01 01:14:58 macallan Exp $ */ +/* $NetBSD: autoconf.c,v 1.172 2010/03/06 08:08:29 mrg Exp $ */ /* * Copyright (c) 1996 @@ -48,7 +48,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.171 2010/03/01 01:14:58 macallan Exp $"); +__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.172 2010/03/06 08:08:29 mrg Exp $"); #include "opt_ddb.h" #include "opt_kgdb.h" @@ -207,7 +207,7 @@ sparc_ncpus++; } #else - sparc_ncpus = 1; + /* #define sparc_ncpus 1 */ #endif } Index: src/sys/arch/sparc64/sparc64/cache.h diff -u src/sys/arch/sparc64/sparc64/cache.h:1.15 src/sys/arch/sparc64/sparc64/cache.h:1.16 --- src/sys/arch/sparc64/sparc64/cache.h:1.15 Wed Feb 24 09:49:36 2010 +++ src/sys/arch/sparc64/sparc64/cache.h Sat Mar 6 08:08:29 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: cache.h,v 1.15 2010/02/24 09:49:36 mrg Exp $ */ +/* $NetBSD: cache.h,v 1.16 2010/03/06 08:08:29 mrg Exp $ */ /* * Copyright (c) 1996 @@ -141,7 +141,7 @@ void smp_dcache_flush_page_all(paddr_t pa); #define dcache_flush_page_all(pa) smp_dcache_flush_page_all(pa) #else -#define tlb_flush_pte(va,pm) sp_tlb_flush_pte(va, (pm)->pm_ctx) +#define tlb_flush_pte(va,pm) sp_tlb_flush_pte(va, (pm)->pm_ctx[0]) #define dcache_flush_page_all(pa) dcache_flush_page(pa) #endif Index: src/sys/arch/sparc64/sparc64/cpu.c diff -u src/sys/arch/sparc64/sparc64/cpu.c:1.89 src/sys/arch/sparc64/sparc64/cpu.c:1.90 --- src/sys/arch/sparc64/sparc64/cpu.c:1.89 Mon Feb 22 00:16:31 2010 +++ src/sys/arch/sparc64/sparc64/cpu.c Sat Mar 6 08:08:29 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: cpu.c,v 1.89 2010/02/22 00:16:31 mrg Exp $ */ +/* $NetBSD: cpu.c,v 1.90 2010/03/06 08:08:29 mrg Exp $ */ /* * Copyright (c) 1996 @@ -52,7 +52,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.89 2010/02/22 00:16:31 mrg Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.90 2010/03/06 08:08:29 mrg Exp $"); #include "opt_multiprocessor.h" @@ -77,7 +77,9 @@ int ecache_min_line_size; /* Linked list of all CPUs in system. */ +#if defined(MULTIPROCESSOR) int sparc_ncpus = 0; +#endif struct cpu_info *cpus = NULL; volatile sparc64_cpuset_t cpus_active;/* set of active cpus */ Index: src/sys/arch/sparc64/sparc64/db_interface.c diff -u src/sys/arch/sparc64/sparc64/db_interface.c:1.122 src/sys/arch/sparc64/sparc64/db_interface.c:1.123 --- src/sys/arch/sparc64/sparc64/db_interface.c:1.122 Tue Feb 23 05:32:08 2010 +++ src/sys/arch/sparc64/sparc64/db_interface.c Sat Mar 6 08:08:29 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: db_interface.c,v 1.122 2010/02/23 05:32:08 mrg Exp $ */ +/* $NetBSD: db_interface.c,v 1.123 2010/03/06 08:08:29 mrg Exp $ */ /* * Copyright (c) 1996-2002 Eduardo Horvath. All rights reserved. @@ -34,7 +34,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.122 2010/02/23 05:32:08 mrg Exp $"); +__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.123 2010/03/06 08:08:29 mrg Exp $"); #include "opt_ddb.h" #include "opt_multiprocessor.h" @@ -87,7 +87,7 @@ #ifdef MULTIPROCESSOR #define pmap_ctx(PM) ((PM)->pm_ctx[cpu_number()]) #else -#define pmap_ctx(PM) ((PM)->pm_ctx) +#define pmap_ctx(PM) ((PM)->pm_ctx[0]) #endif void fill_ddb_regs_from_tf(struct trapframe64 *tf); Index: src/sys/arch/sparc64/sparc64/pmap.c diff -u src/sys/arch/sparc64/sparc64/pmap.c:1.256 src/sys/arch/sparc64/sparc64/pmap.c:1.257 --- src/sys/arch/sparc64/sparc64/pmap.c:1.256 Thu Mar 4 08:11:42 2010 +++ src/sys/arch/sparc64/sparc64/pmap.c Sat Mar 6 08:08:30 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: pmap.c,v 1.256 2010/03/04 08:11:42 mrg Exp $ */ +/* $NetBSD: pmap.c,v 1.257 2010/03/06 08:08:30 mrg Exp $ */ /* * * Copyright (C) 1996-1999 Eduardo Horvath. @@ -26,7 +26,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.256 2010/03/04 08:11:42 mrg Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.257 2010/03/06 08:08:30 mrg Exp $"); #undef NO_VCACHE /* Don't forget the locked TLB in dostart */ #define HWREF @@ -151,9 +151,7 @@ static int ctx_alloc(struct pmap *); static bool pmap_is_referenced_locked(struct vm_page *); -#ifdef MULTIPROCESSOR static void ctx_free(struct pmap *, struct cpu_info *); -#define pmap_ctx(PM) ((PM)->pm_ctx[cpu_number()]) /* * Check if any MMU has a non-zero context @@ -171,6 +169,12 @@ return false; } +#ifdef MULTIPROCESSOR +#define pmap_ctx(PM) ((PM)->pm_ctx[cpu_number()]) +#else +#define pmap_ctx(PM) ((PM)->pm_ctx[0]) +#endif + /* * Check if this pmap has a live mapping on some MMU. */ @@ -183,22 +187,6 @@ return pmap_has_ctx(p); } -#else -static void ctx_free(struct pmap *); -#define pmap_ctx(PM) ((PM)->pm_ctx) - -static inline bool -pmap_has_ctx(struct pmap *p) -{ - return pmap_ctx(p) > 0; -} - -static inline bool -pmap_is_on_mmu(struct pmap *p) -{ - return p == pmap_kernel() || pmap_ctx(p) > 0; -} -#endif /* * Virtual and physical addresses of the start and end of kernel text @@ -236,7 +224,6 @@ __asm volatile("clrx [%0]" : : "r" (addr) : "memory"); } -#ifdef MULTIPROCESSOR static void tsb_invalidate(vaddr_t va, pmap_t pm) { @@ -247,9 +234,13 @@ int64_t tag; i = ptelookup_va(va); +#ifdef MULTIPROCESSOR for (ci = cpus; ci != NULL; ci = ci->ci_next) { if (!CPUSET_HAS(cpus_active, ci->ci_index)) continue; +#else + ci = curcpu(); +#endif ctx = pm->pm_ctx[ci->ci_index]; if (kpm || ctx > 0) { tag = TSB_TAG(0, ctx, va); @@ -260,25 +251,10 @@ clrx(&ci->ci_tsb_immu[i].data); } } +#ifdef MULTIPROCESSOR } -} -#else -static inline void -tsb_invalidate(vaddr_t va, pmap_t pm) -{ - int i; - int64_t tag; - - i = ptelookup_va(va); - tag = TSB_TAG(0, pmap_ctx(pm), va); - if (curcpu()->ci_tsb_dmmu[i].tag == tag) { - clrx(&curcpu()->ci_tsb_dmmu[i].data); - } - if (curcpu()->ci_tsb_immu[i].tag == tag) { - clrx(&curcpu()->ci_tsb_immu[i].data); - } -} #endif +} struct prom_map *prom_map; int prom_map_size; @@ -1397,7 +1373,7 @@ } mutex_exit(&pmap_lock); #else - ctx_free(pm); + ctx_free(pm, curcpu()); #endif /* we could be a little smarter and leave pages zeroed */ @@ -1902,7 +1878,7 @@ } mutex_exit(&pmap_lock); #else - ctx_free(pm); + ctx_free(pm, curcpu()); #endif REMOVE_STAT(flushes); blast_dcache(); @@ -3054,11 +3030,9 @@ while (!LIST_EMPTY(&curcpu()->ci_pmap_ctxlist)) { #ifdef MULTIPROCESSOR KASSERT(pmap_ctx(LIST_FIRST(&curcpu()->ci_pmap_ctxlist)) != 0); +#endif ctx_free(LIST_FIRST(&curcpu()->ci_pmap_ctxlist), curcpu()); -#else - ctx_free(LIST_FIRST(&curcpu()->ci_pmap_ctxlist)); -#endif } for (i = TSBENTS - 1; i >= 0; i--) { if (TSB_TAG_CTX(curcpu()->ci_tsb_dmmu[i].tag) != 0) { @@ -3073,13 +3047,7 @@ curcpu()->ci_pmap_next_ctx = 2; } curcpu()->ci_ctxbusy[ctx] = pm->pm_physaddr; - LIST_INSERT_HEAD(&curcpu()->ci_pmap_ctxlist, pm, -#ifdef MULTIPROCESSOR - pm_list[cpu_number()] -#else - pm_list -#endif - ); + LIST_INSERT_HEAD(&curcpu()->ci_pmap_ctxlist, pm, pm_list[cpu_number()]); pmap_ctx(pm) = ctx; mutex_exit(&pmap_lock); DPRINTF(PDB_CTX_ALLOC, ("ctx_alloc: cpu%d allocated ctx %d\n", @@ -3090,14 +3058,22 @@ /* * Give away a context. */ -#ifdef MULTIPROCESSOR static void ctx_free(struct pmap *pm, struct cpu_info *ci) { int oldctx; + int cpunum; KASSERT(mutex_owned(&pmap_lock)); - oldctx = pm->pm_ctx[ci->ci_index]; + +#ifdef MULTIPROCESSOR + cpunum = ci->ci_index; +#else + /* Give the compiler a hint.. */ + cpunum = 0; +#endif + + oldctx = pm->pm_ctx[cpunum]; if (oldctx == 0) return; @@ -3118,40 +3094,9 @@ DPRINTF(PDB_CTX_ALLOC, ("ctx_free: cpu%d freeing ctx %d\n", cpu_number(), oldctx)); ci->ci_ctxbusy[oldctx] = 0UL; - pm->pm_ctx[ci->ci_index] = 0; - LIST_REMOVE(pm, pm_list[ci->ci_index]); -} -#else -static void -ctx_free(struct pmap *pm) -{ - int oldctx; - - oldctx = pmap_ctx(pm); - if (oldctx == 0) - return; - -#ifdef DIAGNOSTIC - if (pm == pmap_kernel()) - panic("ctx_free: freeing kernel context"); - if (curcpu()->ci_ctxbusy[oldctx] == 0) - printf("ctx_free: freeing free context %d\n", oldctx); - if (curcpu()->ci_ctxbusy[oldctx] != pm->pm_physaddr) { - printf("ctx_free: freeing someone else's context\n " - "ctxbusy[%d] = %p, pm(%p)->pm_ctx = %p\n", - oldctx, (void *)(u_long)curcpu()->ci_ctxbusy[oldctx], pm, - (void *)(u_long)pm->pm_physaddr); - Debugger(); - } -#endif - /* We should verify it has not been stolen and reallocated... */ - DPRINTF(PDB_CTX_ALLOC, ("ctx_free: cpu%d freeing ctx %d\n", - cpu_number(), oldctx)); - curcpu()->ci_ctxbusy[oldctx] = 0UL; - pmap_ctx(pm) = 0; - LIST_REMOVE(pm, pm_list); + pm->pm_ctx[cpunum] = 0; + LIST_REMOVE(pm, pm_list[cpunum]); } -#endif /* * Enter the pmap and virtual address into the