socsvn commit: r236931 - in soc2012/gmiller/locking-head: include
lib/libthr/thread
gmiller at FreeBSD.org
gmiller at FreeBSD.org
Sat Jun 2 12:00:58 UTC 2012
Author: gmiller
Date: Sat Jun 2 12:00:56 2012
New Revision: 236931
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=236931
Log:
Instrument POSIX spinlocks for lock profiling.
Modified:
soc2012/gmiller/locking-head/include/pthread.h
soc2012/gmiller/locking-head/lib/libthr/thread/thr_private.h
soc2012/gmiller/locking-head/lib/libthr/thread/thr_profile.c
soc2012/gmiller/locking-head/lib/libthr/thread/thr_pspinlock.c
Modified: soc2012/gmiller/locking-head/include/pthread.h
==============================================================================
--- soc2012/gmiller/locking-head/include/pthread.h Sat Jun 2 11:44:50 2012 (r236930)
+++ soc2012/gmiller/locking-head/include/pthread.h Sat Jun 2 12:00:56 2012 (r236931)
@@ -335,6 +335,12 @@
int pthread_rwlock_wrlock_profiled(pthread_rwlock_t *,
const char *,
int);
+int pthread_spin_lock_profiled(pthread_spinlock_t *,
+ const char *,
+ int);
+int pthread_spin_trylock_profiled(pthread_spinlock_t *,
+ const char *,
+ int);
#ifdef pthread_mutex_lock
@@ -349,6 +355,8 @@
#undef pthread_rwlock_timedwrlock
#undef pthread_rwlock_tryrdlock
#undef pthread_rwlock_trywrlock
+#undef pthread_spin_lock
+#undef pthread_spin_trylock
#endif
@@ -374,6 +382,10 @@
_pthread_rwlock_tryrdlock_profiled(l, t, __FILE__, __LINE__)
#define pthread_rwlock_trywrlock(l, t) \
_pthread_rwlock_trywrlock_profiled(l, t, __FILE__, __LINE__)
+#define pthread_spin_lock(s) \
+ _pthread_spin_lock(s, __FILE__, __LINE__)
+#define pthread_spin_trylock(s) \
+ _pthread_spin_trylock(s, __FILE__, __LINE__)
#endif
Modified: soc2012/gmiller/locking-head/lib/libthr/thread/thr_private.h
==============================================================================
--- soc2012/gmiller/locking-head/lib/libthr/thread/thr_private.h Sat Jun 2 11:44:50 2012 (r236930)
+++ soc2012/gmiller/locking-head/lib/libthr/thread/thr_private.h Sat Jun 2 12:00:56 2012 (r236931)
@@ -759,6 +759,11 @@
void _rwlock_release_read(struct pthread_rwlock *) __hidden;
void _rwlock_release_write(struct pthread_rwlock *) __hidden;
void _mutex_release(struct pthread_mutex *) __hidden;
+void _spin_obtain_success(struct pthread_spinlock *, const char *file,
+ int line) __hidden;
+void _spin_obtain_failed(struct pthread_spinlock *, const char *file,
+ int line) __hidden;
+void _spin_release(struct pthread_spinlock *) __hidden;
void _libpthread_init(struct pthread *) __hidden;
struct pthread *_thr_alloc(struct pthread *) __hidden;
void _thread_exit(const char *, int, const char *) __hidden __dead2;
@@ -836,6 +841,12 @@
_rwlock_obtain_write_failed(l, file, line)
#define RWLOCK_RELEASE_READ(l) _rwlock_release_read(l)
#define RWLOCK_RELEASE_WRITE(l) _rwlock_release_write(l)
+#define SPIN_OBTAIN_SUCCESS(s) \
+ _spin_obtain_success(s, file, line)
+#define SPIN_OBTAIN_FAILED(s) \
+ _spin_obtain_failed(s, file, line)
+#define SPIN_RELEASE(s) \
+ _spin_release(s)
#else
@@ -849,6 +860,9 @@
#define RWLOCK_OBTAIN_WRITE_FAILED(l) do { } while (0)
#define RWLOCK_RELEASE_READ(l) do { } while (0)
#define RWLOCK_RELEASE_WRITE(l) do { } while (0)
+#define SPIN_OBTAIN_SUCCESS(s) do { } while (0)
+#define SPIN_OBTAIN_FAILED(s) do { } while (0)
+#define SPIN_RELEASE(s) do { } while (0)
#endif
Modified: soc2012/gmiller/locking-head/lib/libthr/thread/thr_profile.c
==============================================================================
--- soc2012/gmiller/locking-head/lib/libthr/thread/thr_profile.c Sat Jun 2 11:44:50 2012 (r236930)
+++ soc2012/gmiller/locking-head/lib/libthr/thread/thr_profile.c Sat Jun 2 12:00:56 2012 (r236931)
@@ -83,4 +83,19 @@
{
}
+void
+_spin_obtain_success(struct pthread_spinlock *s, const char *file, int line)
+{
+}
+
+void
+_spin_obtain_failed(struct pthread_spinlock *s, const char *file, int line)
+{
+}
+
+void
+_spin_release(struct pthread_spinlock *s)
+{
+}
+
#endif
Modified: soc2012/gmiller/locking-head/lib/libthr/thread/thr_pspinlock.c
==============================================================================
--- soc2012/gmiller/locking-head/lib/libthr/thread/thr_pspinlock.c Sat Jun 2 11:44:50 2012 (r236930)
+++ soc2012/gmiller/locking-head/lib/libthr/thread/thr_pspinlock.c Sat Jun 2 12:00:56 2012 (r236931)
@@ -42,6 +42,15 @@
__weak_reference(_pthread_spin_lock, pthread_spin_lock);
__weak_reference(_pthread_spin_unlock, pthread_spin_unlock);
+#ifdef LOCK_PROFILING
+
+int _pthread_spin_trylock_profiled(pthread_spinlock_t *lock,
+ const char *file, int line);
+int _pthread_spin_lock_profiled(pthread_spinlock_t *lock,
+ const char *file, int line);
+
+#endif
+
int
_pthread_spin_init(pthread_spinlock_t *lock, int pshared)
{
@@ -79,6 +88,15 @@
int
_pthread_spin_trylock(pthread_spinlock_t *lock)
+#ifdef LOCK_PROFILING
+{
+ return (_pthread_spin_trylock_profiled(lock, __FILE__, __LINE__));
+}
+
+int
+_pthread_spin_trylock_profiled(pthread_spinlock_t *lock, const char *file,
+ int line)
+#endif
{
struct pthread *curthread = _get_curthread();
struct pthread_spinlock *lck;
@@ -86,23 +104,47 @@
if (lock == NULL || (lck = *lock) == NULL)
ret = EINVAL;
- else
+ else {
ret = THR_UMUTEX_TRYLOCK(curthread, &lck->s_lock);
+ if (ret == 0) {
+ SPIN_OBTAIN_SUCCESS(lck);
+ } else {
+ SPIN_OBTAIN_FAILED(lck);
+ }
+ }
+
return (ret);
}
int
_pthread_spin_lock(pthread_spinlock_t *lock)
+#ifdef LOCK_PROFILING
+{
+ return (_pthread_spin_lock_profiled(lock, __FILE__, __LINE__));
+}
+
+int
+_pthread_spin_lock_profiled(pthread_spinlock_t *lock, const char *file,
+ int line)
+#endif
{
struct pthread *curthread = _get_curthread();
struct pthread_spinlock *lck;
int ret, count;
-
+#ifdef LOCK_PROFILING
+ int spin_needed = 0;
+#endif
if (lock == NULL || (lck = *lock) == NULL)
ret = EINVAL;
else {
count = SPIN_COUNT;
while ((ret = THR_UMUTEX_TRYLOCK(curthread, &lck->s_lock)) != 0) {
+#ifdef LOCK_PROFILING
+ if (!spin_needed) {
+ spin_needed = 1;
+ SPIN_OBTAIN_FAILED(lck);
+ }
+#endif
while (lck->s_lock.m_owner) {
if (!_thr_is_smp) {
_pthread_yield();
@@ -117,6 +159,7 @@
}
}
ret = 0;
+ SPIN_OBTAIN_SUCCESS(lck);
}
return (ret);
@@ -133,6 +176,9 @@
ret = EINVAL;
else {
ret = THR_UMUTEX_UNLOCK(curthread, &lck->s_lock);
+ if (ret == 0) {
+ SPIN_RELEASE(lck);
+ }
}
return (ret);
}
More information about the svn-soc-all
mailing list