public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix mutex pretty printer test and pretty printer output.
@ 2017-01-10 16:11 Torvald Riegel
  2017-01-10 16:39 ` Martin Galvan
  0 siblings, 1 reply; 8+ messages in thread
From: Torvald Riegel @ 2017-01-10 16:11 UTC (permalink / raw)
  To: GLIBC Devel; +Cc: Martin Galvan

[-- Attachment #1: Type: text/plain, Size: 363 bytes --]

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. 

[-- Attachment #2: mutex-pp-fix.patch --]
[-- Type: text/x-patch, Size: 6201 bytes --]

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:

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2017-01-11 14:23 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-10 16:11 [PATCH] Fix mutex pretty printer test and pretty printer output Torvald Riegel
2017-01-10 16:39 ` Martin Galvan
2017-01-11 10:32   ` Torvald Riegel
2017-01-11 12:45     ` Martin Galvan
2017-01-11 12:49       ` Martin Galvan
2017-01-11 14:01       ` Torvald Riegel
2017-01-11 14:08         ` Martin Galvan
2017-01-11 14:23           ` Torvald Riegel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).