socsvn commit: r236922 - in soc2012/gmiller/locking-head: include lib/libthr/thread

gmiller at FreeBSD.org gmiller at FreeBSD.org
Sat Jun 2 09:38:01 UTC 2012


Author: gmiller
Date: Sat Jun  2 09:37:59 2012
New Revision: 236922
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=236922

Log:
  Instrument rwlocks.
  

Modified:
  soc2012/gmiller/locking-head/include/pthread.h
  soc2012/gmiller/locking-head/lib/libthr/thread/thr_cond.c
  soc2012/gmiller/locking-head/lib/libthr/thread/thr_mutex.c
  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_rwlock.c

Modified: soc2012/gmiller/locking-head/include/pthread.h
==============================================================================
--- soc2012/gmiller/locking-head/include/pthread.h	Sat Jun  2 08:47:26 2012	(r236921)
+++ soc2012/gmiller/locking-head/include/pthread.h	Sat Jun  2 09:37:59 2012	(r236922)
@@ -315,21 +315,66 @@
 						  const struct timespec *,
 						  const char *,
 						  int);
+int		pthread_rwlock_rdlock_profiled(pthread_rwlock_t *,
+					       const char *,
+					       int);
+int		pthread_rwlock_timedrdlock_profiled(pthread_rwlock_t *,
+						    const struct timespec *,
+						    const char *,
+						    int);
+int		pthread_rwlock_timedwrlock_profiled(pthread_rwlock_t *,
+						    const struct timespec *,
+						    const char *,
+						    int);
+int		pthread_rwlock_tryrdlock_profiled(pthread_rwlock_t *,
+						  const char *,
+						  int);
+int		pthread_rwlock_trywrlock_profiled(pthread_rwlock_t *,
+						  const char *,
+						  int);
+int		pthread_rwlock_wrlock_profiled(pthread_rwlock_t *,
+					       const char *,
+					       int);
 
 #ifdef pthread_mutex_lock
 
 #undef pthread_mutex_lock
 #undef pthread_mutex_trylock
 #undef pthread_mutex_timedlock
+#undef pthread_cond_wait
+#undef pthread_cond_timedwait
+#undef pthread_rwlock_rdlock
+#undef pthread_rwlock_wrlock
+#undef pthread_rwlock_timedrdlock
+#undef pthread_rwlock_timedwrlock
+#undef pthread_rwlock_tryrdlock
+#undef pthread_rwlock_trywrlock
 
 #endif
 
 #define		pthread_mutex_lock(m)                                         \
-		_pthread_mutex_lock(m, __FILE__, __LINE__)
+		_pthread_mutex_lock_profiled(m, __FILE__, __LINE__)
 #define		pthread_mutex_trylock(m)                                      \
-		_pthread_mutex_trylock(m, __FILE__, __LINE__)
+		_pthread_mutex_trylock_profiled(m, __FILE__, __LINE__)
 #define		pthread_mutex_timedlock(m, t)			\
-		_pthread_mutex_timedlock(m, t, __FILE__, __LINE__)
+		_pthread_mutex_timedlock_profiled(m, t, __FILE__, __LINE__)
+#define		pthread_cond_wait(c, m)                                       \
+		_pthread_cond_wait_profiled(c, m, __FILE__, __LINE__)
+#define		pthread_cond_timedwait(c, m, t)                               \
+		_pthread_cond_timedwait_profiled(c, m, t, __FILE__, __LINE__)
+#define		pthread_rwlock_rdlock(l)                                      \
+		_pthread_rwlock_rdlock_profiled(l, __FILE__, __LINE__)
+#define		pthread_rwlock_wrlock(l)                                      \
+		_pthread_rwlock_wrlock_profiled(l, __FILE__, __LINE__)
+#define		pthread_rwlock_timedrdlock(l, t)                              \
+		_pthread_rwlock_timedrdlock_profiled(l, t, __FILE__, __LINE__)
+#define		pthread_rwlock_timedwrlock(l, t)                              \
+		_pthread_rwlock(timedwrlock_profiled(l, t, __FILE__, __LINE__)
+#define		pthread_rwlock_tryrdlock(l, t)                                \
+		_pthread_rwlock_tryrdlock_profiled(l, t, __FILE__, __LINE__)
+#define		pthread_rwlock_trywrlock(l, t)                                \
+		_pthread_rwlock_trywrlock_profiled(l, t, __FILE__, __LINE__)
+
 #endif
 
 #endif

Modified: soc2012/gmiller/locking-head/lib/libthr/thread/thr_cond.c
==============================================================================
--- soc2012/gmiller/locking-head/lib/libthr/thread/thr_cond.c	Sat Jun  2 08:47:26 2012	(r236921)
+++ soc2012/gmiller/locking-head/lib/libthr/thread/thr_cond.c	Sat Jun  2 09:37:59 2012	(r236922)
@@ -49,18 +49,6 @@
 static int cond_signal_common(pthread_cond_t *cond);
 static int cond_broadcast_common(pthread_cond_t *cond);
 
-#ifdef LOCK_PROFILING
-int	__pthread_cond_wait_profiled(pthread_cond_t *cond,
-				     pthread_mutex_t *mutex,
-				     const char *file,
-				     int line);
-int	__pthread_cond_timedwait_profiled(pthread_cond_t *cond,
-					  pthread_mutex_t *mutex,
-					  const struct timespec * abstime,
-					  const char *file,
-					  int line);
-#endif
-
 /*
  * Double underscore versions are cancellation points.  Single underscore
  * versions are not and are provided for libc internal usage (which
@@ -74,6 +62,20 @@
 __weak_reference(_pthread_cond_signal, pthread_cond_signal);
 __weak_reference(_pthread_cond_broadcast, pthread_cond_broadcast);
 
+#ifdef LOCK_PROFILING
+
+int	__pthread_cond_wait_profiled(pthread_cond_t *cond,
+				     pthread_mutex_t *mutex,
+				     const char *file,
+				     int line);
+int	__pthread_cond_timedwait_profiled(pthread_cond_t *cond,
+					  pthread_mutex_t *mutex,
+					  const struct timespec * abstime,
+					  const char *file,
+					  int line);
+
+#endif
+
 #define CV_PSHARED(cvp)	(((cvp)->__flags & USYNC_PROCESS_SHARED) != 0)
 
 static int

Modified: soc2012/gmiller/locking-head/lib/libthr/thread/thr_mutex.c
==============================================================================
--- soc2012/gmiller/locking-head/lib/libthr/thread/thr_mutex.c	Sat Jun  2 08:47:26 2012	(r236921)
+++ soc2012/gmiller/locking-head/lib/libthr/thread/thr_mutex.c	Sat Jun  2 09:37:59 2012	(r236922)
@@ -96,19 +96,6 @@
 static int	mutex_lock_sleep(struct pthread *, pthread_mutex_t,
 				const struct timespec * _PROFILE_PARMS);
 
-#ifdef LOCK_PROFILING
-int	__pthread_mutex_trylock_profiled(pthread_mutex_t *mutex,
-					 const char *file,
-					 int line);
-int	__pthread_mutex_lock_profiled(pthread_mutex_t *mutex,
-				      const char *file,
-				      int line);
-int	__pthread_mutex_timedlock_profiled(pthread_mutex_t *mutex,
-					   const struct timespec *abstime,
-					   const char *file,
-					   int line);
-#endif
-
 __weak_reference(__pthread_mutex_init, pthread_mutex_init);
 __strong_reference(__pthread_mutex_init, _pthread_mutex_init);
 __weak_reference(__pthread_mutex_lock, pthread_mutex_lock);
@@ -135,6 +122,27 @@
 __weak_reference(_pthread_mutex_getyieldloops_np, pthread_mutex_getyieldloops_np);
 __weak_reference(_pthread_mutex_isowned_np, pthread_mutex_isowned_np);
 
+#ifdef LOCK_PROFILING
+int	__pthread_mutex_trylock_profiled(pthread_mutex_t *mutex,
+					 const char *file,
+					 int line);
+int	__pthread_mutex_lock_profiled(pthread_mutex_t *mutex,
+				      const char *file,
+				      int line);
+int	__pthread_mutex_timedlock_profiled(pthread_mutex_t *mutex,
+					   const struct timespec *abstime,
+					   const char *file,
+					   int line);
+
+__strong_reference(__pthread_mutex_lock_profiled,
+		   _pthread_mutex_lock_profiled);
+__strong_reference(__pthread_mutex_trylock_profiled,
+		   _pthread_mutex_trylock_profiled);
+__strong_reference(__pthread_mutex_timedlock_profiled,
+		   _pthread_mutex_timedlock_profiled);
+
+#endif
+
 static int
 mutex_init(pthread_mutex_t *mutex,
     const struct pthread_mutex_attr *mutex_attr,

Modified: soc2012/gmiller/locking-head/lib/libthr/thread/thr_private.h
==============================================================================
--- soc2012/gmiller/locking-head/lib/libthr/thread/thr_private.h	Sat Jun  2 08:47:26 2012	(r236921)
+++ soc2012/gmiller/locking-head/lib/libthr/thread/thr_private.h	Sat Jun  2 09:37:59 2012	(r236922)
@@ -748,6 +748,16 @@
 void	_mutex_obtain_success(struct pthread_mutex *, const char *, int)
 	    __hidden;
 void	_lock_profile_exit_thread(struct pthread *curthread) __hidden;
+void	_rwlock_obtain_read_success(struct pthread_rwlock *, const char *file,
+				    int line) __hidden;
+void	_rwlock_obtain_read_failed(struct pthread_rwlock *, const char *file,
+				   int line) __hidden;
+void	_rwlock_obtain_write_success(struct pthread_rwlock *, const char *file,
+				     int line) __hidden;
+void	_rwlock_obtain_write_failed(struct pthread_rwlock *, const char *file,
+				    int line) __hidden;
+void	_rwlock_release_read(struct pthread_rwlock *) __hidden;
+void	_rwlock_release_write(struct pthread_rwlock *) __hidden;
 void	_mutex_release(struct pthread_mutex *) __hidden;
 void	_libpthread_init(struct pthread *) __hidden;
 struct pthread *_thr_alloc(struct pthread *) __hidden;
@@ -816,13 +826,29 @@
 #define		MUTEX_OBTAIN_FAILED(m)                                       \
 		_mutex_obtain_failed(m, file, line)
 #define		MUTEX_RELEASE(m)	_mutex_release(m)
+#define		RWLOCK_OBTAIN_READ_SUCCESS(l)                                \
+		_rwlock_obtain_read_success(l, file, line)
+#define		RWLOCK_OBTAIN_READ_FAILED(l)                                 \
+		_rwlock_obtain_read_failed(l, file, line)
+#define		RWLOCK_OBTAIN_WRITE_SUCCESS(l)                               \
+		_rwlock_obtain_write_success(l, file, line)
+#define		RWLOCK_OBTAIN_WRITE_FAILED(l)                                \
+		_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)
 
 #else
 
-#define		LOCK_PROFILE_EXIT_THREAD(t) do { } while (0)
-#define		MUTEX_OBTAIN_SUCCESS(m)	do { } while (0)
-#define		MUTEX_OBTAIN_FAILED(m)	do { } while (0)
-#define		MUTEX_RELEASE(m)	do { } while (0)
+#define		LOCK_PROFILE_EXIT_THREAD(t)	do { } while (0)
+#define		MUTEX_OBTAIN_SUCCESS(m)		do { } while (0)
+#define		MUTEX_OBTAIN_FAILED(m)		do { } while (0)
+#define		MUTEX_RELEASE(m)		do { } while (0)
+#define		RWLOCK_OBTAIN_READ_SUCCESS(l)	do { } while (0)
+#define		RWLOCK_OBTAIN_READ_FAILED(l)	do { } while (0)
+#define		RWLOCK_OBTAIN_WRITE_SUCCESS(l)	do { } while (0)
+#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)
 
 #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 08:47:26 2012	(r236921)
+++ soc2012/gmiller/locking-head/lib/libthr/thread/thr_profile.c	Sat Jun  2 09:37:59 2012	(r236922)
@@ -25,6 +25,8 @@
  *
  */
 
+#ifdef LOCK_PROFILING
+
 #include "thr_private.h"
 
 void
@@ -46,3 +48,39 @@
 _lock_profile_exit_thread(struct pthread *t)
 {
 }
+
+void
+_rwlock_obtain_read_success(struct pthread_rwlock *l, const char *file,
+			    int line)
+{
+}
+
+void
+_rwlock_obtain_read_failed(struct pthread_rwlock *l, const char *file,
+			   int line)
+{
+}
+
+void
+_rwlock_obtain_write_success(struct pthread_rwlock *l, const char *file,
+			     int line)
+{
+}
+
+void
+_rwlock_obtain_write_failed(struct pthread_rwlock *l, const char *file,
+			    int line)
+{
+}
+
+void
+_rwlock_release_read(struct pthread_rwlock *l)
+{
+}
+
+void
+_rwlock_release_write(struct pthread_rwlock *l)
+{
+}
+
+#endif

Modified: soc2012/gmiller/locking-head/lib/libthr/thread/thr_rwlock.c
==============================================================================
--- soc2012/gmiller/locking-head/lib/libthr/thread/thr_rwlock.c	Sat Jun  2 08:47:26 2012	(r236921)
+++ soc2012/gmiller/locking-head/lib/libthr/thread/thr_rwlock.c	Sat Jun  2 09:37:59 2012	(r236922)
@@ -61,6 +61,30 @@
 /*
  * Prototypes
  */
+#ifdef LOCK_PROFILING
+
+int	_pthread_rwlock_rdlock_profiled(pthread_rwlock_t *rwlock,
+					const char *file,
+					int line);
+int	_pthread_rwlock_wrlock_profiled(pthread_rwlock_t *rwlock,
+					const char *file,
+					int line);
+int	_pthread_rwlock_timedrdlock_profiled(pthread_rwlock_t *rwlock,
+					     const struct timespec *abstime,
+					     const char *file,
+					     int line);
+int	_pthread_rwlock_timedwrlock_profiled(pthread_rwlock_t *rwlock,
+					     const struct timespec *abstime,
+					     const char *file,
+					     int line);
+int	_pthread_rwlock_tryrdlock_profiled(pthread_rwlock_t *rwlock,
+					   const char *file,
+					   int line);
+int	_pthread_rwlock_trywrlock_profiled(pthread_rwlock_t *rwlock,
+					   const char *file,
+					   int line);
+
+#endif
 
 static int
 rwlock_init(pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr __unused)
@@ -119,7 +143,8 @@
 }
 
 static int
-rwlock_rdlock_common(pthread_rwlock_t *rwlock, const struct timespec *abstime)
+rwlock_rdlock_common(pthread_rwlock_t *rwlock, const struct timespec *abstime
+		     _PROFILE_PARMS)
 {
 	struct pthread *curthread = _get_curthread();
 	pthread_rwlock_t prwlock;
@@ -153,9 +178,14 @@
 	ret = _thr_rwlock_tryrdlock(&prwlock->lock, flags);
 	if (ret == 0) {
 		curthread->rdlock_count++;
+
+		RWLOCK_OBTAIN_READ_SUCCESS(*rwlock);
+
 		return (ret);
 	}
 
+	RWLOCK_OBTAIN_READ_FAILED(*rwlock);
+
 	if (__predict_false(abstime && 
 		(abstime->tv_nsec >= 1000000000 || abstime->tv_nsec < 0)))
 		return (EINVAL);
@@ -172,26 +202,59 @@
 			break;
 		}
 	}
-	if (ret == 0)
+	if (ret == 0) {
 		curthread->rdlock_count++;
+		RWLOCK_OBTAIN_READ_SUCCESS(*rwlock);
+	}
+
 	return (ret);
 }
 
 int
-_pthread_rwlock_rdlock (pthread_rwlock_t *rwlock)
+_pthread_rwlock_rdlock(pthread_rwlock_t *rwlock)
+#ifdef LOCK_PROFILING
+{
+	return (_pthread_rwlock_rdlock_profiled(rwlock, __FILE__, __LINE__));
+}
+
+int
+_pthread_rwlock_rdlock_profiled(pthread_rwlock_t *rwlock, const char *file,
+				int line)
+#endif
 {
-	return (rwlock_rdlock_common(rwlock, NULL));
+	return (rwlock_rdlock_common(rwlock, NULL _PROFILE_PASS));
 }
 
 int
-_pthread_rwlock_timedrdlock (pthread_rwlock_t *rwlock,
-	 const struct timespec *abstime)
+_pthread_rwlock_timedrdlock(pthread_rwlock_t *rwlock,
+			    const struct timespec *abstime)
+#ifdef LOCK_PROFILING
 {
-	return (rwlock_rdlock_common(rwlock, abstime));
+  return (_pthread_rwlock_timedrdlock_profiled(rwlock, abstime, __FILE__,
+					       __LINE__));
 }
 
 int
-_pthread_rwlock_tryrdlock (pthread_rwlock_t *rwlock)
+_pthread_rwlock_timedrdlock_profiled(pthread_rwlock_t *rwlock,
+				     const struct timespec *abstime,
+				     const char *file, int line)
+#endif
+{
+	return (rwlock_rdlock_common(rwlock, abstime _PROFILE_PASS));
+}
+
+int
+_pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock)
+#ifdef LOCK_PROFILING
+{
+	return (_pthread_rwlock_tryrdlock_profiled(rwlock, __FILE__,
+						   __LINE__));
+}
+
+int
+_pthread_rwlock_tryrdlock_profiled(pthread_rwlock_t *rwlock,
+				   const char *file, int line)
+#endif
 {
 	struct pthread *curthread = _get_curthread();
 	pthread_rwlock_t prwlock;
@@ -219,13 +282,26 @@
 	}
 
 	ret = _thr_rwlock_tryrdlock(&prwlock->lock, flags);
-	if (ret == 0)
+	if (ret == 0) {
 		curthread->rdlock_count++;
+		RWLOCK_OBTAIN_READ_SUCCESS(*rwlock);
+	} else {
+		RWLOCK_OBTAIN_READ_FAILED(*rwlock);
+	}
 	return (ret);
 }
 
 int
-_pthread_rwlock_trywrlock (pthread_rwlock_t *rwlock)
+_pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock)
+#ifdef LOCK_PROFILING
+{
+  return (_pthread_rwlock_trywrlock_profiled(rwlock, __FILE__, __LINE__));
+}
+
+int
+_pthread_rwlock_trywrlock_profiled(pthread_rwlock_t *rwlock, const char *file,
+				   int line)
+#endif
 {
 	struct pthread *curthread = _get_curthread();
 	pthread_rwlock_t prwlock;
@@ -234,13 +310,18 @@
 	CHECK_AND_INIT_RWLOCK
 
 	ret = _thr_rwlock_trywrlock(&prwlock->lock);
-	if (ret == 0)
+	if (ret == 0) {
 		prwlock->owner = curthread;
+		RWLOCK_OBTAIN_WRITE_SUCCESS(*rwlock);
+	} else {
+		RWLOCK_OBTAIN_WRITE_FAILED(*rwlock);
+	}
 	return (ret);
 }
 
 static int
-rwlock_wrlock_common (pthread_rwlock_t *rwlock, const struct timespec *abstime)
+rwlock_wrlock_common(pthread_rwlock_t *rwlock, const struct timespec *abstime
+		     _PROFILE_PARMS)
 {
 	struct pthread *curthread = _get_curthread();
 	pthread_rwlock_t prwlock;
@@ -255,9 +336,14 @@
 	ret = _thr_rwlock_trywrlock(&prwlock->lock);
 	if (ret == 0) {
 		prwlock->owner = curthread;
+
+		RWLOCK_OBTAIN_WRITE_SUCCESS(*rwlock);
+
 		return (ret);
 	}
 
+	RWLOCK_OBTAIN_WRITE_FAILED(*rwlock);
+
 	if (__predict_false(abstime && 
 		(abstime->tv_nsec >= 1000000000 || abstime->tv_nsec < 0)))
 		return (EINVAL);
@@ -280,20 +366,47 @@
 			break;
 		}
 	}
+
+	if (ret == 0) {
+		RWLOCK_OBTAIN_WRITE_SUCCESS(*rwlock);
+	} else {
+		RWLOCK_OBTAIN_WRITE_FAILED(*rwlock);
+	}
+
 	return (ret);
 }
 
 int
-_pthread_rwlock_wrlock (pthread_rwlock_t *rwlock)
+_pthread_rwlock_wrlock(pthread_rwlock_t *rwlock)
+#ifdef LOCK_PROFILING
+{
+	return (_pthread_rwlock_wrlock_profiled(rwlock, __FILE__, __LINE__));
+}
+
+int
+_pthread_rwlock_wrlock_profiled(pthread_rwlock_t *rwlock, const char *file,
+				int line)
+#endif
 {
-	return (rwlock_wrlock_common (rwlock, NULL));
+	return (rwlock_wrlock_common(rwlock, NULL _PROFILE_PASS));
 }
 
 int
-_pthread_rwlock_timedwrlock (pthread_rwlock_t *rwlock,
-    const struct timespec *abstime)
+_pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock,
+			    const struct timespec *abstime)
+#ifdef LOCK_PROFILING
 {
-	return (rwlock_wrlock_common (rwlock, abstime));
+	return (_pthread_rwlock_timedwrlock_profiled(rwlock, abstime, __FILE__,
+					       __LINE__));
+}
+
+int
+_pthread_rwlock_timedwrlock_profiled(pthread_rwlock_t *rwlock,
+				     const struct timespec *abstime,
+				     const char *file, int line)
+#endif
+{
+	return (rwlock_wrlock_common(rwlock, abstime _PROFILE_PASS));
 }
 
 int
@@ -317,8 +430,12 @@
 	}
 
 	ret = _thr_rwlock_unlock(&prwlock->lock);
-	if (ret == 0 && (state & URWLOCK_WRITE_OWNER) == 0)
+	if (ret == 0 && (state & URWLOCK_WRITE_OWNER) == 0) {
 		curthread->rdlock_count--;
+		RWLOCK_RELEASE_READ(*rwlock);
+	} else if (ret == 0) {
+		RWLOCK_RELEASE_WRITE(*rwlock);
+	}
 
 	return (ret);
 }


More information about the svn-soc-all mailing list