socsvn commit: r237648 - in soc2012/gmiller/locking-head: include
lib/libthr/thread
gmiller at FreeBSD.org
gmiller at FreeBSD.org
Wed Jun 13 23:37:38 UTC 2012
Author: gmiller
Date: Wed Jun 13 23:37:35 2012
New Revision: 237648
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=237648
Log:
Bug fixes for mutex profiling code. Works now, except for wait times and
contest counts.
Modified:
soc2012/gmiller/locking-head/include/pthread.h
soc2012/gmiller/locking-head/include/pthread_np.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_pspinlock.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 Wed Jun 13 22:53:56 2012 (r237647)
+++ soc2012/gmiller/locking-head/include/pthread.h Wed Jun 13 23:37:35 2012 (r237648)
@@ -313,40 +313,42 @@
int);
int _pthread_mutex_timedlock_profiled(pthread_mutex_t *,
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);
+int _pthread_mutex_unlock_profiled(pthread_mutex_t *,
+ 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);
+int _pthread_spin_lock_profiled(pthread_spinlock_t *,
+ const char *,
+ int);
+int _pthread_spin_trylock_profiled(pthread_spinlock_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
#undef pthread_mutex_lock
#undef pthread_mutex_trylock
#undef pthread_mutex_timedlock
+#undef pthread_mutex_unlock
#undef pthread_cond_wait
#undef pthread_cond_timedwait
#undef pthread_rwlock_rdlock
@@ -366,6 +368,8 @@
_pthread_mutex_trylock_profiled(m, __FILE__, __LINE__)
#define pthread_mutex_timedlock(m, t) \
_pthread_mutex_timedlock_profiled(m, t, __FILE__, __LINE__)
+#define pthread_mutex_unlock(m) \
+ _pthread_mutex_unlock_profiled(m, __FILE__, __LINE__)
#define pthread_cond_wait(c, m) \
_pthread_cond_wait_profiled(c, m, __FILE__, __LINE__)
#define pthread_cond_timedwait(c, m, t) \
Modified: soc2012/gmiller/locking-head/include/pthread_np.h
==============================================================================
--- soc2012/gmiller/locking-head/include/pthread_np.h Wed Jun 13 22:53:56 2012 (r237647)
+++ soc2012/gmiller/locking-head/include/pthread_np.h Wed Jun 13 23:37:35 2012 (r237648)
@@ -88,7 +88,7 @@
};
void pthread_getstatistics_begin_np(struct pthread_statistics_np *);
-void pthread_getstatistics_next_np(struct pthread_statistics_np *);
+int pthread_getstatistics_next_np(struct pthread_statistics_np *);
void pthread_getstatistics_end_np(struct pthread_statistics_np *);
#endif
Modified: soc2012/gmiller/locking-head/lib/libthr/thread/thr_cond.c
==============================================================================
--- soc2012/gmiller/locking-head/lib/libthr/thread/thr_cond.c Wed Jun 13 22:53:56 2012 (r237647)
+++ soc2012/gmiller/locking-head/lib/libthr/thread/thr_cond.c Wed Jun 13 23:37:35 2012 (r237648)
@@ -246,7 +246,7 @@
*/
cvp->__has_user_waiters = 1;
curthread->will_sleep = 1;
- (void)_mutex_cv_unlock(mp, &recurse);
+ (void)_mutex_cv_unlock(mp, &recurse _PROFILE_PASS);
curthread->mutex_obj = mp;
_sleepq_add(cvp, curthread);
for(;;) {
@@ -318,7 +318,7 @@
_pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
#ifdef LOCK_PROFILING
{
- return (_pthread_cond_wait_profiled(cond, mutex, __FILE__, __LINE__));
+ return (_pthread_cond_wait_profiled(cond, mutex, NULL, 0));
}
int
@@ -336,7 +336,7 @@
__pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
#ifdef LOCK_PROFILING
{
- return (__pthread_cond_wait_profiled(cond, mutex, __FILE__, __LINE__));
+ return (__pthread_cond_wait_profiled(cond, mutex, NULL, 0));
}
int
@@ -355,8 +355,7 @@
const struct timespec *abstime)
#ifdef LOCK_PROFILING
{
- return (_pthread_cond_timedwait_profiled(cond, mutex, abstime,
- __FILE__, __LINE__));
+ return (_pthread_cond_timedwait_profiled(cond, mutex, abstime, NULL, 0));
}
int
@@ -379,8 +378,7 @@
const struct timespec *abstime)
#ifdef LOCK_PROFILING
{
- return (__pthread_cond_timedwait_profiled(cond, mutex, abstime,
- __FILE__, __LINE__));
+ return (__pthread_cond_timedwait_profiled(cond, mutex, abstime, NULL, 0));
}
int
Modified: soc2012/gmiller/locking-head/lib/libthr/thread/thr_mutex.c
==============================================================================
--- soc2012/gmiller/locking-head/lib/libthr/thread/thr_mutex.c Wed Jun 13 22:53:56 2012 (r237647)
+++ soc2012/gmiller/locking-head/lib/libthr/thread/thr_mutex.c Wed Jun 13 23:37:35 2012 (r237648)
@@ -80,6 +80,7 @@
int __pthread_mutex_lock(pthread_mutex_t *mutex);
int __pthread_mutex_timedlock(pthread_mutex_t *mutex,
const struct timespec *abstime);
+int __pthread_mutex_unlock(pthread_mutex_t *);
int _pthread_mutex_init_calloc_cb(pthread_mutex_t *mutex,
void *(calloc_cb)(size_t, size_t));
int _pthread_mutex_getspinloops_np(pthread_mutex_t *mutex, int *count);
@@ -92,7 +93,8 @@
static int mutex_self_trylock(pthread_mutex_t _PROFILE_PARMS);
static int mutex_self_lock(pthread_mutex_t,
const struct timespec *abstime _PROFILE_PARMS);
-static int mutex_unlock_common(struct pthread_mutex *, int);
+static int mutex_unlock_common(struct pthread_mutex *,
+ int _PROFILE_PARMS);
static int mutex_lock_sleep(struct pthread *, pthread_mutex_t,
const struct timespec * _PROFILE_PARMS);
@@ -133,6 +135,9 @@
const struct timespec *abstime,
const char *file,
int line);
+int __pthread_mutex_unlock_profiled(pthread_mutex_t *mutex,
+ const char *file,
+ int line);
__strong_reference(__pthread_mutex_lock_profiled,
_pthread_mutex_lock_profiled);
@@ -140,6 +145,8 @@
_pthread_mutex_trylock_profiled);
__strong_reference(__pthread_mutex_timedlock_profiled,
_pthread_mutex_timedlock_profiled);
+__strong_reference(__pthread_mutex_unlock_profiled,
+ _pthread_mutex_unlock_profiled);
#endif
@@ -353,7 +360,6 @@
MUTEX_OBTAIN_SUCCESS(m, &waittime);
} else if (m->m_owner == curthread) {
ret = mutex_self_trylock(m _PROFILE_PASS);
- MUTEX_OBTAIN_FAILED(m, &waittime);
} else {
MUTEX_OBTAIN_FAILED(m, &waittime);
}
@@ -368,7 +374,7 @@
__pthread_mutex_trylock(pthread_mutex_t *mutex)
#ifdef LOCK_PROFILING
{
- return (__pthread_mutex_trylock_profiled(mutex, __FILE__, __LINE__));
+ return (__pthread_mutex_trylock_profiled(mutex, NULL, 0));
}
int
@@ -490,7 +496,7 @@
__pthread_mutex_lock(pthread_mutex_t *mutex)
#ifdef LOCK_PROFILING
{
- return (__pthread_mutex_lock_profiled(mutex, __FILE__, __LINE__));
+ return (__pthread_mutex_lock_profiled(mutex, NULL, 0));
}
int
@@ -513,8 +519,7 @@
const struct timespec *abstime)
#ifdef LOCK_PROFILING
{
- return (__pthread_mutex_timedlock_profiled(mutex, abstime,
- __FILE__, __LINE__));
+ return (__pthread_mutex_timedlock_profiled(mutex, abstime, NULL, 0));
}
int
@@ -535,11 +540,21 @@
int
_pthread_mutex_unlock(pthread_mutex_t *mutex)
+#ifdef LOCK_PROFILING
+{
+ return (__pthread_mutex_unlock_profiled(mutex, NULL, 0));
+}
+
+int
+__pthread_mutex_unlock_profiled(pthread_mutex_t *mutex,
+ const char *file,
+ int line)
+#endif
{
struct pthread_mutex *mp;
mp = *mutex;
- return (mutex_unlock_common(mp, 0));
+ return (mutex_unlock_common(mp, 0 _PROFILE_PASS));
}
int
@@ -554,7 +569,7 @@
}
int
-_mutex_cv_unlock(struct pthread_mutex *m, int *count)
+_mutex_cv_unlock(struct pthread_mutex *m, int *count _PROFILE_PARMS)
{
/*
@@ -562,7 +577,7 @@
*/
*count = m->m_count;
m->m_count = 0;
- (void)mutex_unlock_common(m, 1);
+ (void)mutex_unlock_common(m, 1 _PROFILE_PASS);
return (0);
}
@@ -731,7 +746,7 @@
}
static int
-mutex_unlock_common(struct pthread_mutex *m, int cv)
+mutex_unlock_common(struct pthread_mutex *m, int cv _PROFILE_PARMS)
{
struct pthread *curthread = _get_curthread();
uint32_t id;
Modified: soc2012/gmiller/locking-head/lib/libthr/thread/thr_private.h
==============================================================================
--- soc2012/gmiller/locking-head/lib/libthr/thread/thr_private.h Wed Jun 13 22:53:56 2012 (r237647)
+++ soc2012/gmiller/locking-head/lib/libthr/thread/thr_private.h Wed Jun 13 23:37:35 2012 (r237648)
@@ -742,14 +742,15 @@
int _thr_setthreaded(int) __hidden;
int _mutex_cv_lock(struct pthread_mutex *, int count _PROFILE_PARMS)
__hidden;
-int _mutex_cv_unlock(struct pthread_mutex *, int *count) __hidden;
+int _mutex_cv_unlock(struct pthread_mutex *, int *count _PROFILE_PARMS)
+ __hidden;
int _mutex_cv_attach(struct pthread_mutex *, int count) __hidden;
int _mutex_cv_detach(struct pthread_mutex *, int *count) __hidden;
int _mutex_owned(struct pthread *, const struct pthread_mutex *) __hidden;
int _mutex_reinit(pthread_mutex_t *) __hidden;
void _mutex_fork(struct pthread *curthread) __hidden;
-void _mutex_obtain_failed(struct pthread_mutex *, struct timespec *)
- __hidden;
+void _mutex_obtain_failed(struct pthread_mutex *, struct timespec *,
+ const char *) __hidden;
void _mutex_obtain_success(struct pthread_mutex *, struct timespec *,
const char *, int) __hidden;
void _lock_profile_init(void) __hidden;
@@ -766,7 +767,8 @@
__hidden;
void _rwlock_release_write(struct pthread_rwlock *, struct timespec *)
__hidden;
-void _mutex_release(struct pthread_mutex *, struct timespec *) __hidden;
+void _mutex_release(struct pthread_mutex *, struct timespec *,
+ const char *file) __hidden;
void _spin_obtain_success(struct pthread_spinlock *,
struct timespec *wait_time, const char *file, int line) __hidden;
void _spin_obtain_failed(struct pthread_spinlock *,
@@ -839,8 +841,8 @@
#define MUTEX_OBTAIN_SUCCESS(m, ts) \
_mutex_obtain_success(m, ts, file, line)
#define MUTEX_OBTAIN_FAILED(m, ts) \
- _mutex_obtain_failed(m, ts)
-#define MUTEX_RELEASE(m, ts) _mutex_release(m, ts)
+ _mutex_obtain_failed(m, ts, file)
+#define MUTEX_RELEASE(m, ts) _mutex_release(m, ts, file)
#define RWLOCK_OBTAIN_READ_SUCCESS(l, ts) \
_rwlock_obtain_read_success(l, ts, file, line)
#define RWLOCK_OBTAIN_READ_FAILED(l, ts) \
Modified: soc2012/gmiller/locking-head/lib/libthr/thread/thr_profile.c
==============================================================================
--- soc2012/gmiller/locking-head/lib/libthr/thread/thr_profile.c Wed Jun 13 22:53:56 2012 (r237647)
+++ soc2012/gmiller/locking-head/lib/libthr/thread/thr_profile.c Wed Jun 13 23:37:35 2012 (r237648)
@@ -67,13 +67,13 @@
struct acq_point_head mutex_hash[LOCK_PROF_HASH_SIZE];
struct _pthread_statistics_private {
- int hash;
+ u_int hash;
struct acquisition_point *last_record;
};
void
_lock_profile_init()
-{
+{
int i;
for (i = 0; i < LOCK_PROF_HASH_SIZE; i++) {
@@ -92,8 +92,7 @@
}
}
- acq = malloc(sizeof(struct acquisition));
- bzero(acq, sizeof(*acq));
+ acq = calloc(1, sizeof(*acq));
acq->lock = m;
acq->file = file;
acq->line = line;
@@ -117,8 +116,7 @@
}
}
- acq_point = malloc(sizeof(struct acquisition_point));
- bzero(acq_point, sizeof(*acq_point));
+ acq_point = calloc(1, sizeof(*acq_point));
acq_point->file = file;
acq_point->line = line;
@@ -134,6 +132,10 @@
struct pthread *curthread = _get_curthread();
struct acquisition *acq;
+ if (file == NULL) {
+ return;
+ }
+
THR_CRITICAL_ENTER(curthread);
acq = mutex_lookup_acq(m, file, line);
@@ -146,7 +148,7 @@
wait_time->tv_nsec != 0) {
if (TIMESPEC_GT(&acq->acq_time, wait_time)) {
TIMESPEC_SUB(&acq->wait_time,
- &acq->acq_time, &acq->acq_time);
+ &acq->acq_time, wait_time);
}
} else {
bzero(&acq->wait_time, sizeof(acq->wait_time));
@@ -158,15 +160,21 @@
}
void
-_mutex_obtain_failed(struct pthread_mutex *m, struct timespec *wait_time)
+_mutex_obtain_failed(struct pthread_mutex *m, struct timespec *wait_time,
+ const char *file)
{
+ if (file == NULL) {
+ return;
+ }
+
if (wait_time->tv_sec == 0 && wait_time->tv_nsec == 0) {
clock_gettime(CLOCK_REALTIME, wait_time);
}
}
void
-_mutex_release(struct pthread_mutex *m, struct timespec *wait_time)
+_mutex_release(struct pthread_mutex *m, struct timespec *wait_time,
+ const char *file)
{
struct pthread *curthread = _get_curthread();
struct acquisition *acq;
@@ -174,6 +182,10 @@
struct timespec current_time;
struct timespec hold_time;
+ if (file == NULL) {
+ return;
+ }
+
THR_CRITICAL_ENTER(curthread);
LIST_FOREACH(acq, &acq_head, acq_next) {
@@ -188,10 +200,13 @@
acq_point = mutex_lookup_acq_point(m, acq->file,
acq->line);
clock_gettime(CLOCK_REALTIME, ¤t_time);
- if (acq_point != NULL &&
- TIMESPEC_GT(&acq->acq_time, ¤t_time)) {
- TIMESPEC_SUB(&hold_time, ¤t_time,
- &acq->acq_time);
+ if (acq_point != NULL) {
+ bzero(&hold_time, sizeof(hold_time));
+ if (TIMESPEC_GT(¤t_time,
+ &acq->acq_time)) {
+ TIMESPEC_SUB(&hold_time, ¤t_time,
+ &acq->acq_time);
+ }
if (TIMESPEC_GT(&hold_time,
&acq_point->hold_max)) {
memcpy(&acq_point->hold_max,
@@ -237,7 +252,7 @@
void
_rwlock_obtain_read_failed(struct pthread_rwlock *l,
- struct timespec *wait_time)
+ struct timespec *wait_time)
{
}
@@ -292,9 +307,9 @@
if (stats->_pvt->hash >= LOCK_PROF_HASH_SIZE) {
break;
} else {
- stats->_pvt->hash++;
stats->_pvt->last_record =
SLIST_FIRST(&mutex_hash[stats->_pvt->hash]);
+ stats->_pvt->hash++;
}
} else {
stats->_pvt->last_record = SLIST_NEXT(stats->_pvt->
@@ -329,14 +344,12 @@
stats->_pvt = malloc(sizeof(struct _pthread_statistics_private));
stats->_pvt->hash = 0;
stats->_pvt->last_record = NULL;
-
- find_next_record(stats);
}
-void
+int
pthread_getstatistics_next_np(struct pthread_statistics_np *stats)
{
- find_next_record(stats);
+ return (find_next_record(stats));
}
void
Modified: soc2012/gmiller/locking-head/lib/libthr/thread/thr_pspinlock.c
==============================================================================
--- soc2012/gmiller/locking-head/lib/libthr/thread/thr_pspinlock.c Wed Jun 13 22:53:56 2012 (r237647)
+++ soc2012/gmiller/locking-head/lib/libthr/thread/thr_pspinlock.c Wed Jun 13 23:37:35 2012 (r237648)
@@ -90,7 +90,7 @@
_pthread_spin_trylock(pthread_spinlock_t *lock)
#ifdef LOCK_PROFILING
{
- return (_pthread_spin_trylock_profiled(lock, __FILE__, __LINE__));
+ return (_pthread_spin_trylock_profiled(lock, NULL, 0));
}
int
@@ -124,7 +124,7 @@
_pthread_spin_lock(pthread_spinlock_t *lock)
#ifdef LOCK_PROFILING
{
- return (_pthread_spin_lock_profiled(lock, __FILE__, __LINE__));
+ return (_pthread_spin_lock_profiled(lock, NULL, 0));
}
int
Modified: soc2012/gmiller/locking-head/lib/libthr/thread/thr_rwlock.c
==============================================================================
--- soc2012/gmiller/locking-head/lib/libthr/thread/thr_rwlock.c Wed Jun 13 22:53:56 2012 (r237647)
+++ soc2012/gmiller/locking-head/lib/libthr/thread/thr_rwlock.c Wed Jun 13 23:37:35 2012 (r237648)
@@ -218,7 +218,7 @@
_pthread_rwlock_rdlock(pthread_rwlock_t *rwlock)
#ifdef LOCK_PROFILING
{
- return (_pthread_rwlock_rdlock_profiled(rwlock, __FILE__, __LINE__));
+ return (_pthread_rwlock_rdlock_profiled(rwlock, NULL, 0));
}
int
@@ -234,8 +234,7 @@
const struct timespec *abstime)
#ifdef LOCK_PROFILING
{
- return (_pthread_rwlock_timedrdlock_profiled(rwlock, abstime, __FILE__,
- __LINE__));
+ return (_pthread_rwlock_timedrdlock_profiled(rwlock, abstime, NULL, 0));
}
int
@@ -251,8 +250,7 @@
_pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock)
#ifdef LOCK_PROFILING
{
- return (_pthread_rwlock_tryrdlock_profiled(rwlock, __FILE__,
- __LINE__));
+ return (_pthread_rwlock_tryrdlock_profiled(rwlock, NULL, 0));
}
int
@@ -304,7 +302,7 @@
_pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock)
#ifdef LOCK_PROFILING
{
- return (_pthread_rwlock_trywrlock_profiled(rwlock, __FILE__, __LINE__));
+ return (_pthread_rwlock_trywrlock_profiled(rwlock, NULL, 0));
}
int
@@ -399,7 +397,7 @@
_pthread_rwlock_wrlock(pthread_rwlock_t *rwlock)
#ifdef LOCK_PROFILING
{
- return (_pthread_rwlock_wrlock_profiled(rwlock, __FILE__, __LINE__));
+ return (_pthread_rwlock_wrlock_profiled(rwlock, NULL, 0));
}
int
@@ -415,8 +413,8 @@
const struct timespec *abstime)
#ifdef LOCK_PROFILING
{
- return (_pthread_rwlock_timedwrlock_profiled(rwlock, abstime, __FILE__,
- __LINE__));
+ return (_pthread_rwlock_timedwrlock_profiled(rwlock, abstime, NULL,
+ 0));
}
int
More information about the svn-soc-all
mailing list