aboutsummaryrefslogtreecommitdiffstats
path: root/libc/bionic/pthread_mutex.cpp
diff options
context:
space:
mode:
authorBrigid Smith <brigidsmith@google.com>2014-07-21 15:38:06 -0700
committerBrigid Smith <brigidsmith@google.com>2014-07-28 19:38:08 -0700
commita406ee6d5f616192e9a13afad6ac6a9969814fc1 (patch)
treebc9d1575ddacb246d49109367b6151732fbfe19e /libc/bionic/pthread_mutex.cpp
parent337c0cefdc4667143a1f4f2c30113b452c5d188f (diff)
downloadandroid_bionic-a406ee6d5f616192e9a13afad6ac6a9969814fc1.tar.gz
android_bionic-a406ee6d5f616192e9a13afad6ac6a9969814fc1.tar.bz2
android_bionic-a406ee6d5f616192e9a13afad6ac6a9969814fc1.zip
Added a bionic systrace class and tracing to pthread_mutex.cpp.
bionic_systrace.h contains an implementation of tracing that can be used with systrace.py and its associated viewer. pthread_mutex now uses this tracing to track pthread_mutex contention, which can be enabled by using the "bionic" command line option to systrace. Bug: 15116468 Change-Id: I30ed5b377c91ca4c36568a0e647ddf95d4e4a61a
Diffstat (limited to 'libc/bionic/pthread_mutex.cpp')
-rw-r--r--libc/bionic/pthread_mutex.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/libc/bionic/pthread_mutex.cpp b/libc/bionic/pthread_mutex.cpp
index 546166166..e00ffb437 100644
--- a/libc/bionic/pthread_mutex.cpp
+++ b/libc/bionic/pthread_mutex.cpp
@@ -39,6 +39,8 @@
#include "private/bionic_futex.h"
#include "private/bionic_tls.h"
+#include "private/bionic_systrace.h"
+
extern void pthread_debug_mutex_lock_check(pthread_mutex_t *mutex);
extern void pthread_debug_mutex_unlock_check(pthread_mutex_t *mutex);
@@ -333,6 +335,10 @@ static inline void _normal_lock(pthread_mutex_t* mutex, int shared) {
* that the mutex is in state 2 when we go to sleep on it, which
* guarantees a wake-up call.
*/
+
+ ScopedTrace trace("Contending for pthread mutex");
+
+
while (__bionic_swap(locked_contended, &mutex->value) != unlocked) {
__futex_wait_ex(&mutex->value, shared, locked_contended, NULL);
}
@@ -473,6 +479,8 @@ int pthread_mutex_lock(pthread_mutex_t* mutex) {
mvalue = mutex->value;
}
+ ScopedTrace trace("Contending for pthread mutex");
+
for (;;) {
int newval;
@@ -626,6 +634,8 @@ static int __pthread_mutex_timedlock(pthread_mutex_t* mutex, const timespec* abs
return 0;
}
+ ScopedTrace trace("Contending for timed pthread mutex");
+
// Loop while needed.
while (__bionic_swap(locked_contended, &mutex->value) != unlocked) {
if (__timespec_from_absolute(&ts, abs_timeout, clock) < 0) {
@@ -658,6 +668,8 @@ static int __pthread_mutex_timedlock(pthread_mutex_t* mutex, const timespec* abs
mvalue = mutex->value;
}
+ ScopedTrace trace("Contending for timed pthread mutex");
+
while (true) {
// If the value is 'unlocked', try to acquire it directly.
// NOTE: put state to 2 since we know there is contention.