From a9803ae643b070b8c805cf94b4ac3205ba8668b1 Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Sun, 15 Jan 2012 11:43:40 -0500 Subject: [PATCH] Windows: make lock reader history debug only The lock reader history on osi_rwlock is proving to be too expensive. Only use it for DEBUG builds. Leave the data structures the same so that DEBUG builds can be mixed with a RELEASE build of afsd_service.exe. Change-Id: If0eeddb63c8f9919cdb5e119f31cde77974447b6 Reviewed-on: http://gerrit.openafs.org/6559 Tested-by: BuildBot Reviewed-by: Jeffrey Altman Tested-by: Jeffrey Altman --- src/WINNT/client_osi/osibasel.c | 40 +++++++++++++++++++++++++++++----------- src/WINNT/client_osi/osisleep.c | 2 ++ 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/WINNT/client_osi/osibasel.c b/src/WINNT/client_osi/osibasel.c index 192a22c..8939324 100644 --- a/src/WINNT/client_osi/osibasel.c +++ b/src/WINNT/client_osi/osibasel.c @@ -176,11 +176,14 @@ void lock_ObtainWrite(osi_rwlock_t *lockp) if (lockp->flags & OSI_LOCKFLAG_EXCL) { osi_assertx(lockp->tid[0] != tid, "OSI_RWLOCK_WRITEHELD"); - } else { + } +#ifdef DEBUG + else { for ( i=0; i < lockp->readers && i < OSI_RWLOCK_THREADS; i++ ) { osi_assertx(lockp->tid[i] != tid, "OSI_RWLOCK_READHELD"); } } +#endif /* here we have the fast lock, so see if we can obtain the real lock */ if (lockp->waiters > 0 || (lockp->flags & OSI_LOCKFLAG_EXCL) || @@ -235,11 +238,14 @@ void lock_ObtainRead(osi_rwlock_t *lockp) if (lockp->flags & OSI_LOCKFLAG_EXCL) { osi_assertx(lockp->tid[0] != tid, "OSI_RWLOCK_WRITEHELD"); - } else { + } +#ifdef DEBUG + else { for ( i=0; i < lockp->readers && i < OSI_RWLOCK_THREADS; i++ ) { osi_assertx(lockp->tid[i] != tid, "OSI_RWLOCK_READHELD"); } } +#endif /* here we have the fast lock, so see if we can obtain the real lock */ if (lockp->waiters > 0 || (lockp->flags & OSI_LOCKFLAG_EXCL)) { @@ -250,8 +256,11 @@ void lock_ObtainRead(osi_rwlock_t *lockp) osi_assert(!(lockp->flags & OSI_LOCKFLAG_EXCL) && lockp->readers > 0); } else { /* if we're here, all clear to set the lock */ - if (++lockp->readers <= OSI_RWLOCK_THREADS) + lockp->readers++; +#ifdef DEBUG + if (lockp->readers <= OSI_RWLOCK_THREADS) lockp->tid[lockp->readers-1] = tid; +#endif } LeaveCriticalSection(csp); @@ -302,14 +311,16 @@ void lock_ReleaseRead(osi_rwlock_t *lockp) osi_assertx(lockp->readers > 0, "read lock not held"); - for ( i=0; i < lockp->readers; i++) { +#ifdef DEBUG + for ( i=0; i < lockp->readers && i < OSI_RWLOCK_THREADS; i++) { if ( lockp->tid[i] == tid ) { - for ( ; i < lockp->readers - 1; i++) + for ( ; i < (lockp->readers - 1) && i < (OSI_RWLOCK_THREADS - 1); i++) lockp->tid[i] = lockp->tid[i+1]; lockp->tid[i] = 0; break; } } +#endif lockp->readers--; @@ -363,7 +374,6 @@ void lock_ReleaseWrite(osi_rwlock_t *lockp) osi_assertx(lockp->flags & OSI_LOCKFLAG_EXCL, "write lock not held"); osi_assertx(lockp->tid[0] == thrd_Current(), "write lock not held by current thread"); - lockp->tid[0] = 0; lockp->flags &= ~OSI_LOCKFLAG_EXCL; @@ -396,6 +406,7 @@ void lock_ConvertWToR(osi_rwlock_t *lockp) /* convert write lock to read lock */ lockp->flags &= ~OSI_LOCKFLAG_EXCL; + lockp->tid[0] = 0; lockp->readers++; osi_assertx(lockp->readers == 1, "read lock not one"); @@ -428,14 +439,16 @@ void lock_ConvertRToW(osi_rwlock_t *lockp) osi_assertx(!(lockp->flags & OSI_LOCKFLAG_EXCL), "write lock held"); osi_assertx(lockp->readers > 0, "read lock not held"); - for ( i=0; i < lockp->readers; i++) { +#ifdef DEBUG + for ( i=0; i < lockp->readers && i < OSI_RWLOCK_THREADS; i++) { if ( lockp->tid[i] == tid ) { - for ( ; i < lockp->readers - 1; i++) + for ( ; i < (lockp->readers - 1) && i < (OSI_RWLOCK_THREADS - 1); i++) lockp->tid[i] = lockp->tid[i+1]; lockp->tid[i] = 0; break; } } +#endif if (--(lockp->readers) == 0) { /* convert read lock to write lock */ @@ -586,8 +599,11 @@ int lock_TryRead(struct osi_rwlock *lockp) } else { /* if we're here, all clear to set the lock */ - if (++(lockp->readers) < OSI_RWLOCK_THREADS) + lockp->readers++; +#ifdef DEBUG + if (lockp->readers < OSI_RWLOCK_THREADS) lockp->tid[lockp->readers-1] = thrd_Current(); +#endif i = 1; } @@ -743,14 +759,16 @@ void osi_SleepR(LONG_PTR sleepVal, struct osi_rwlock *lockp) osi_assertx(lockp->readers > 0, "osi_SleepR: not held"); - for ( i=0; i < lockp->readers; i++) { +#ifdef DEBUG + for ( i=0; i < lockp->readers && i < OSI_RWLOCK_THREADS; i++) { if ( lockp->tid[i] == tid ) { - for ( ; i < lockp->readers - 1; i++) + for ( ; i < (lockp->readers - 1) && i < (OSI_RWLOCK_THREADS - 1); i++) lockp->tid[i] = lockp->tid[i+1]; lockp->tid[i] = 0; break; } } +#endif /* XXX better to get the list of things to wakeup from TSignalForMLs, and * then do the wakeup after SleepSpin releases the low-level mutex. diff --git a/src/WINNT/client_osi/osisleep.c b/src/WINNT/client_osi/osisleep.c index 7081d84..5d6c4a2 100644 --- a/src/WINNT/client_osi/osisleep.c +++ b/src/WINNT/client_osi/osisleep.c @@ -392,8 +392,10 @@ void osi_TSignalForMLs(osi_turnstile_t *turnp, int stillHaveReaders, CRITICAL_SE } else if (tsp->waitFor & OSI_SLEEPINFO_W4READ) { sp = (void *) tsp->value; +#ifdef DEBUG if ((*sp) < OSI_RWLOCK_THREADS) tsp->tidp[*sp] = tsp->tid; +#endif (*sp)++; } -- 1.9.4