CVS commit: [netbsd-7-0] src/sys/arch/sparc/sparc
Module Name:src Committed By: martin Date: Tue Jan 15 18:45:24 UTC 2019 Modified Files: src/sys/arch/sparc/sparc [netbsd-7-0]: pmap.c Log Message: Pull up following revision(s) (requested by mrg in ticket #1672): sys/arch/sparc/sparc/pmap.c: revision 1.366 switch sparc pmap lock to the scheme sparc64 uses: - - local IPL_NONE mutex for general pmap locking operations, not kernel lock. - - for pmap_activate()/pmap_deactivate(), switch to using the existing ctx_lock, and push handling of it into ctx_alloc() the ctx_free() callers. fixes easy to trigger deadlocks on systems with >2 cpus. without this patch i usually hang during boot. with it, i was able to push the machine hard for over 12 hours. XXX: pullup-8, and maybe -7. To generate a diff of this commit: cvs rdiff -u -r1.358 -r1.358.6.1 src/sys/arch/sparc/sparc/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/sparc/sparc/pmap.c diff -u src/sys/arch/sparc/sparc/pmap.c:1.358 src/sys/arch/sparc/sparc/pmap.c:1.358.6.1 --- src/sys/arch/sparc/sparc/pmap.c:1.358 Sat May 3 11:17:06 2014 +++ src/sys/arch/sparc/sparc/pmap.c Tue Jan 15 18:45:24 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: pmap.c,v 1.358 2014/05/03 11:17:06 nakayama Exp $ */ +/* $NetBSD: pmap.c,v 1.358.6.1 2019/01/15 18:45:24 martin Exp $ */ /* * Copyright (c) 1996 @@ -56,7 +56,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.358 2014/05/03 11:17:06 nakayama Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.358.6.1 2019/01/15 18:45:24 martin Exp $"); #include "opt_ddb.h" #include "opt_kgdb.h" @@ -176,8 +176,8 @@ paddr_t vm_first_phys = (paddr_t)-1; paddr_t vm_last_phys = 0; psize_t vm_num_phys; -#define PMAP_LOCK() KERNEL_LOCK(1, NULL) -#define PMAP_UNLOCK() KERNEL_UNLOCK_ONE(NULL) +#define PMAP_LOCK() mutex_enter(&pmap_lock) +#define PMAP_UNLOCK() mutex_exit(&pmap_lock) /* * Flags in pvlist.pv_flags. Note that PV_MOD must be 1 and PV_REF must be 2 @@ -347,6 +347,7 @@ mmuq_insert_tail(struct mmuentry *head, int seginval; /* [4/4c] the invalid segment number */ int reginval; /* [4/3mmu] the invalid region number */ +static kmutex_t pmap_lock; static kmutex_t demap_lock; static bool lock_available = false; /* demap_lock has been initialized */ @@ -372,15 +373,15 @@ union ctxinfo { struct pmap *c_pmap; /* pmap (if busy) */ }; -static kmutex_t ctx_lock; /* lock for below */ +static kmutex_t ctx_lock; /* lock for below, and {,de}activate */ union ctxinfo *ctxinfo; /* allocated at in pmap_bootstrap */ union ctxinfo *ctx_freelist; /* context free list */ int ctx_kick; /* allocation rover when none free */ int ctx_kickdir; /* ctx_kick roves both directions */ int ncontext; /* sizeof ctx_freelist */ -void ctx_alloc(struct pmap *); -void ctx_free(struct pmap *); +static void ctx_alloc(struct pmap *); +static void ctx_free(struct pmap *); /*void * vdumppages; -* 32KB worth of reserved dump pages */ @@ -2121,7 +2122,7 @@ mmu_pagein(struct pmap *pm, vaddr_t va, * This routine is only ever called from locore.s just after it has * saved away the previous process, so there are no active user windows. */ -void +static void ctx_alloc(struct pmap *pm) { union ctxinfo *c; @@ -2133,6 +2134,8 @@ ctx_alloc(struct pmap *pm) struct cpu_info *cpi; #endif + KASSERT(mutex_owned(&ctx_lock)); + /*XXX-GCC!*/gap_start=gap_end=0; #ifdef DEBUG if (pm->pm_ctx) @@ -2145,7 +2148,6 @@ ctx_alloc(struct pmap *pm) gap_end = pm->pm_gap_end; } - mutex_spin_enter(&ctx_lock); if ((c = ctx_freelist) != NULL) { ctx_freelist = c->c_nextfree; cnum = c - ctxinfo; @@ -2288,13 +2290,12 @@ ctx_alloc(struct pmap *pm) setcontext4m(cnum); #endif /* SUN4M || SUN4D */ } - mutex_spin_exit(&ctx_lock); } /* * Give away a context. */ -void +static void ctx_free(struct pmap *pm) { union ctxinfo *c; @@ -2303,6 +2304,8 @@ ctx_free(struct pmap *pm) struct cpu_info *cpi; #endif + KASSERT(mutex_owned(&ctx_lock)); + c = pm->pm_ctx; ctx = pm->pm_ctxnum; pm->pm_ctx = NULL; @@ -2316,8 +2319,6 @@ ctx_free(struct pmap *pm) } #endif /* SUN4 || SUN4C */ - mutex_spin_enter(&ctx_lock); - #if defined(SUN4M) || defined(SUN4D) if (CPU_HAS_SRMMU) { CPU_INFO_ITERATOR i; @@ -2334,7 +2335,6 @@ ctx_free(struct pmap *pm) c->c_nextfree = ctx_freelist; ctx_freelist = c; - mutex_spin_exit(&ctx_lock); } @@ -3070,6 +3070,7 @@ pmap_bootstrap(int nctx, int nregion, in } pmap_page_upload(); + mutex_init(&pmap_lock, MUTEX_DEFAULT, IPL_NONE); mutex_init(&demap_lock, MUTEX_DEFAULT, IPL_VM); mutex_init(&ctx_lock, MUTEX_DEFAULT, IPL_SCHED); lock_available = true; @@ -4386,7 +4387,9 @@ pmap_pmap_pool_dtor(void *arg, void *obj #endif if ((c = pm->pm_ctx) != NULL) { + mutex_spin_enter(&ctx_lock); ctx_free(pm); + mutex_spin_exit(&ctx_lock); } #if defined(SUN4M) || defined(SUN4D)
CVS commit: [netbsd-7-0] src/sys/arch/sparc/sparc
Module Name:src Committed By: snj Date: Wed Jan 3 20:06:02 UTC 2018 Modified Files: src/sys/arch/sparc/sparc [netbsd-7-0]: locore.s Log Message: Pull up following revision(s) (requested by maya in ticket #1530): sys/arch/sparc/sparc/locore.s: revision 1.269 Avoid an instruction requiring a higher alignment than we are guaranteed Fixes PR port-sparc/52721: ddb errors on ps command Thanks to mlelstv. To generate a diff of this commit: cvs rdiff -u -r1.268 -r1.268.16.1 src/sys/arch/sparc/sparc/locore.s 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/sparc/sparc/locore.s diff -u src/sys/arch/sparc/sparc/locore.s:1.268 src/sys/arch/sparc/sparc/locore.s:1.268.16.1 --- src/sys/arch/sparc/sparc/locore.s:1.268 Sun Nov 4 00:32:47 2012 +++ src/sys/arch/sparc/sparc/locore.s Wed Jan 3 20:06:02 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: locore.s,v 1.268 2012/11/04 00:32:47 chs Exp $ */ +/* $NetBSD: locore.s,v 1.268.16.1 2018/01/03 20:06:02 snj Exp $ */ /* * Copyright (c) 1996 Paul Kranenburg @@ -6288,8 +6288,9 @@ ENTRY(longjmp) cmp %fp, %g7 ! compare against desired frame bl,a 1b ! if below, restore !pop frame and loop - be,a 2f ! if there, - ldd [%g1+0], %o2 !fetch return %sp and pc, and get out + ld [%g1+0], %o2 ! fetch return %sp + be,a 2f ! we're there, get out + ld [%g1+4], %o3 ! fetch return pc Llongjmpbotch: ! otherwise, went too far; bomb out
CVS commit: [netbsd-7-0] src/sys/arch/sparc/sparc
Module Name:src Committed By: snj Date: Mon Feb 12 18:42:16 UTC 2018 Modified Files: src/sys/arch/sparc/sparc [netbsd-7-0]: timer.c timer_sun4m.c timerreg.h Log Message: Pull up following revision(s) (requested by mrg in ticket #1552): sys/arch/sparc/sparc/timer.c: 1.33-1.34 sys/arch/sparc/sparc/timer_sun4m.c: 1.31 sys/arch/sparc/sparc/timerreg.h: 1.10 fix time goes backwards problems on sparc. there are a few things here: - there's a race between reading the limit register (which clears the interrupt and the limit bit) and increasing the latest offset. this can happen easily if an interrupt comes between the read and the call to tickle_tc() that increases the offset (i obverved this actually happening.) - in early boot, sometimes the counter can cycle twice before the tickle happens. to handle these issues, add two workarounds: - if the limit bit isn't set, but the counter value is less than the previous value, and the offset hasn't changed, use the same fixup as if the limit bit was set. this handles the first case above. - add a hard-workaround for never allowing returning a smaller value (except during 32 bit overflow): if the result is less than the last result, add fixups until it does (or until it would overflow.) the first workaround fixes general run-time issues, and the second fixes issues only seen during boot. also expand some comments in timer_sun4m.c and re-enable the sun4m sub-microsecond tmr_ustolim4m() support (but it's always called with at least 'tick' microseconds, so the end result is the same.) -- fix hang at 4B microseconds (1h12 or so), and simplify part of the previous To generate a diff of this commit: cvs rdiff -u -r1.32 -r1.32.8.1 src/sys/arch/sparc/sparc/timer.c cvs rdiff -u -r1.30 -r1.30.8.1 src/sys/arch/sparc/sparc/timer_sun4m.c cvs rdiff -u -r1.9 -r1.9.144.1 src/sys/arch/sparc/sparc/timerreg.h 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/sparc/sparc/timer.c diff -u src/sys/arch/sparc/sparc/timer.c:1.32 src/sys/arch/sparc/sparc/timer.c:1.32.8.1 --- src/sys/arch/sparc/sparc/timer.c:1.32 Sun Jan 19 00:22:33 2014 +++ src/sys/arch/sparc/sparc/timer.c Mon Feb 12 18:42:16 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: timer.c,v 1.32 2014/01/19 00:22:33 mrg Exp $ */ +/* $NetBSD: timer.c,v 1.32.8.1 2018/02/12 18:42:16 snj Exp $ */ /* * Copyright (c) 1992, 1993 @@ -60,7 +60,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: timer.c,v 1.32 2014/01/19 00:22:33 mrg Exp $"); +__KERNEL_RCSID(0, "$NetBSD: timer.c,v 1.32.8.1 2018/02/12 18:42:16 snj Exp $"); #include #include @@ -85,55 +85,92 @@ void *sched_cookie; * timecounter local state */ static struct counter { - volatile u_int *cntreg; /* counter register */ + __cpu_simple_lock_t lock; /* protects access to offset, reg, last* */ + volatile u_int *cntreg; /* counter register to read */ u_int limit; /* limit we count up to */ u_int offset; /* accumulated offset due to wraps */ u_int shift; /* scaling for valid bits */ u_int mask; /* valid bit mask */ -} cntr; + u_int lastcnt; /* the last* values are used to notice */ + u_int lastres; /* and fix up cases where it would appear */ + u_int lastoffset; /* time went backwards. */ +} cntr __aligned(CACHE_LINE_SIZE); /* * define timecounter */ static struct timecounter counter_timecounter = { - timer_get_timecount, /* get_timecount */ - 0, /* no poll_pps */ - ~0u, /* counter_mask */ - 0, /* frequency - set at initialisation */ - "timer-counter", /* name */ - 100, /* quality */ - &cntr /* private reference */ + .tc_get_timecount = timer_get_timecount, + .tc_poll_pps = NULL, + .tc_counter_mask = ~0u, + .tc_frequency = 0, + .tc_name = "timer-counter", + .tc_quality = 100, + .tc_priv = &cntr, }; /* * timer_get_timecount provide current counter value */ +__attribute__((__optimize__("Os"))) static u_int timer_get_timecount(struct timecounter *tc) { - struct counter *ctr = (struct counter *)tc->tc_priv; - - u_int c, res, r; + u_int cnt, res, fixup, offset; int s; + /* + * We use splhigh/__cpu_simple_lock here as we don't want + * any mutex or lockdebug overhead. The lock protects a + * bunch of the members of cntr that are written here to + * deal with the various minor races to be observed and + * worked around. + */ s = splhigh(); - - res = c = *ctr->cntreg; + __cpu_simple_lock(&cntr.lock); + res = cnt = *cntr.cntreg; res &= ~TMR_LIMIT; + offset = cntr.offset; - if (c != res) { - r = ctr->limit; + /* + * There are 3 cases here: + * - limit reached, interrupt not yet processed. + * - count reset but offset the same, race between handling + * the interrupt and tickle_tc() updating the offset. + * - normal case. + * + * For the first two cases, add the limit so that we avoid + * time going backwards. + */ + if (cnt != res) {