This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix mutex pretty printer test and pretty printer output.


This fixes the test for the mutex pretty printers in that it does not
assume that the owner field is set even though the mutex is acquired;
this is not guaranteed under the current lock elision implementation.
Also, it improves the wording of some of the pretty printer output (eg,
changing 'Locked' to 'Acquired').

Tested on x86_64 with --enable-lock-elision. 
commit 661a8a8d766747367314f848733804f22cef825e
Author: Torvald Riegel <triegel@redhat.com>
Date:   Mon Jan 9 20:40:57 2017 +0100

    Fix mutex pretty printer test and pretty printer output.
    
    This fixes the test for the mutex pretty printers in that it does not
    assume that the owner field is set even though the mutex is acquired;
    this is not guaranteed under the current lock elision implementation.
    Also, it improves the wording of some of the pretty printer output (eg,
    changing 'Locked' to 'Acquired').
    
    	* nptl/nptl-printers.py (MutexPrinter): Change output.
    	* nptl/test-mutex-printers.py: Fix test and adapt to changed output.

diff --git a/nptl/nptl-printers.py b/nptl/nptl-printers.py
index 9d67865..54d4c84 100644
--- a/nptl/nptl-printers.py
+++ b/nptl/nptl-printers.py
@@ -124,18 +124,21 @@ class MutexPrinter(object):
         """
 
         if self.lock == PTHREAD_MUTEX_UNLOCKED:
-            self.values.append(('Status', 'Unlocked'))
+            self.values.append(('Status', 'Not acquired'))
         else:
             if self.lock & FUTEX_WAITERS:
-                self.values.append(('Status', 'Locked, possibly with waiters'))
+                self.values.append(('Status',
+                                    'Acquired, possibly with waiters'))
             else:
                 self.values.append(('Status',
-                                    'Locked, possibly with no waiters'))
+                                    'Acquired, possibly with no waiters'))
 
             if self.lock & FUTEX_OWNER_DIED:
-                self.values.append(('Owner ID', '%d (dead)' % self.owner))
+                self.values.append(('Owner ID (if known)',
+                                    '%d (dead)' % self.owner))
             else:
-                self.values.append(('Owner ID', self.lock & FUTEX_TID_MASK))
+                self.values.append(('Owner ID (if known)',
+                                    self.lock & FUTEX_TID_MASK))
 
         if self.owner == PTHREAD_MUTEX_INCONSISTENT:
             self.values.append(('State protected by this mutex',
@@ -157,7 +160,7 @@ class MutexPrinter(object):
             lock_value &= ~(PTHREAD_MUTEX_PRIO_CEILING_MASK)
 
         if lock_value == PTHREAD_MUTEX_UNLOCKED:
-            self.values.append(('Status', 'Unlocked'))
+            self.values.append(('Status', 'Not acquired'))
         else:
             if self.kind & PTHREAD_MUTEX_PRIO_INHERIT_NP:
                 waiters = self.lock & FUTEX_WAITERS
@@ -168,12 +171,13 @@ class MutexPrinter(object):
                 owner = self.owner
 
             if waiters:
-                self.values.append(('Status', 'Locked, possibly with waiters'))
+                self.values.append(('Status',
+                                    'Acquired, possibly with waiters'))
             else:
                 self.values.append(('Status',
-                                    'Locked, possibly with no waiters'))
+                                    'Acquired, possibly with no waiters'))
 
-            self.values.append(('Owner ID', owner))
+            self.values.append(('Owner ID (if known)', owner))
 
     def read_attributes(self):
         """Read the mutex's attributes."""
@@ -215,7 +219,7 @@ class MutexPrinter(object):
         mutex_type = self.kind & PTHREAD_MUTEX_KIND_MASK
 
         if mutex_type == PTHREAD_MUTEX_RECURSIVE and self.count > 1:
-            self.values.append(('Times locked recursively', self.count))
+            self.values.append(('Times acquired by the owner', self.count))
 
 class MutexAttributesPrinter(object):
     """Pretty printer for pthread_mutexattr_t.
diff --git a/nptl/test-mutex-printers.py b/nptl/test-mutex-printers.py
index 23f16b0..d0600b7 100644
--- a/nptl/test-mutex-printers.py
+++ b/nptl/test-mutex-printers.py
@@ -39,15 +39,17 @@ try:
 
     break_at(test_source, 'Test status (non-robust)')
     continue_cmd() # Go to test_status_no_robust
-    test_printer(var, to_string, {'Status': 'Unlocked'})
+    test_printer(var, to_string, {'Status': 'Not acquired'})
     next_cmd()
     thread_id = get_current_thread_lwpid()
-    test_printer(var, to_string, {'Status': 'Locked, possibly with no waiters',
-                                  'Owner ID': thread_id})
+    # Don't check Owner ID here because the owner may not always be set
+    # (e.g., if using lock elision).
+    test_printer(var, to_string,
+                 {'Status': 'Acquired, possibly with no waiters'})
 
     break_at(test_source, 'Test status (robust)')
     continue_cmd() # Go to test_status_robust
-    test_printer(var, to_string, {'Status': 'Unlocked'})
+    test_printer(var, to_string, {'Status': 'Not acquired'})
 
     # We'll now test the robust mutex locking states.  We'll create a new
     # thread that will lock a robust mutex and exit without unlocking it.
@@ -69,21 +71,22 @@ try:
     # The new thread should be dead by now.
     break_at(test_source, 'Test locking (robust)')
     continue_cmd()
-    test_printer(var, to_string, {'Owner ID': r'{0} \(dead\)'.format(child_id)})
+    test_printer(var, to_string,
+                 {'Owner ID \(if known\)': r'{0} \(dead\)'.format(child_id)})
     # Try to lock and unlock the mutex.
     next_cmd()
-    test_printer(var, to_string, {'Owner ID': thread_id,
+    test_printer(var, to_string, {'Owner ID \(if known\)': thread_id,
                            'State protected by this mutex': 'Inconsistent'})
     next_cmd()
-    test_printer(var, to_string, {'Status': 'Unlocked',
+    test_printer(var, to_string, {'Status': 'Not acquired',
                         'State protected by this mutex': 'Not recoverable'})
     set_scheduler_locking(False)
 
     break_at(test_source, 'Test recursive locks')
     continue_cmd() # Go to test_recursive_locks
-    test_printer(var, to_string, {'Times locked recursively': '2'})
+    test_printer(var, to_string, {'Times acquired by the owner': '2'})
     next_cmd()
-    test_printer(var, to_string, {'Times locked recursively': '3'})
+    test_printer(var, to_string, {'Times acquired by the owner': '3'})
     continue_cmd() # Exit
 
 except (NoLineError, pexpect.TIMEOUT) as exception:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]