This is the mail archive of the 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]

Re: [PATCH] Speedup nptl/tst-rwlock19.

On 9/12/19 4:14 PM, Carlos O'Donell wrote:
On 9/12/19 8:16 AM, Stefan Liebler wrote:

the test creates 15 threads which are trying 5000x to pthread_rwlock_rdlock
a modified lock where the number of readers is set to max - 5.  If locked
successfully, it sleeps for 1ms.

The test succeeds if the lock was rdlock'ed successfully for at least
one time and it has failed at least once with EAGAIN and the
number of readers needs to be max - 5 again after all threads have joined.

The test is currently running for 5 seconds.  Thus this patch reduces
the READTRIES from 5000 to 100 and is increasing the DELAY from 1ms to 5ms.
Then the test runs for roughly 0.5 seconds.

Why do we need to limit the retries?

The point of the test is to run until we see a successful lock, and a failed
lock with EAGAIN.

It should be possible to make this test robust and so that when we run it
on slower i686 it should jus run until it sees the events it needs to see,
or fail from timeout (indicating a problem).

I'm worried that by limiting the retires we'll see failures on slower or
loaded hardware in the lab, and then we'll have to go back and bump up the
retries again.

The optimal test in my mind is:

- Run forever.
- Look for events of interest.
- Exit success when those events are seen.
- Fail if we timeout.

This sounds great.
I've adjusted the patch and READTRIES is now removed.

commit a2f7492f5ef5faaf038df49f4f8d4b5a5b0395a3
Author: Stefan Liebler <>
Date:   Thu Sep 12 09:19:01 2019 +0200

    Speedup nptl/tst-rwlock19.
    The test creates 15 threads which are trying 5000x to pthread_rwlock_rdlock
    a modified lock where the number of readers is set to max - 5.  If locked
    successfully, it sleeps for 1ms.
    The test succeeds if the lock was rdlock'ed successfully for at least
    one time and it has failed at least once with EAGAIN and the
    number of readers needs to be max - 5 again after all threads have joined.
    The test is currently running for 5 seconds.  Thus this patch is now running
    as long as both rdlock contitions are met or the test times out.
    This saves nearly 5 seconds of "make check".
            * nptl/tst-rwlock19.c (READTRIES): Remove macro.
            (do_test) Move checks to reader_thread.
            (reader_thread): Replace for loop by while loop with checks.

diff --git a/nptl/tst-rwlock19.c b/nptl/tst-rwlock19.c
index 19d40c11ca..91ee89a7ae 100644
--- a/nptl/tst-rwlock19.c
+++ b/nptl/tst-rwlock19.c
@@ -26,7 +26,6 @@
 #define NREADERS 15
-#define READTRIES 5000
 #define DELAY   1000000
@@ -38,12 +37,12 @@ static void *
 reader_thread (void *nr)
   struct timespec delay;
-  int n;
   delay.tv_sec = 0;
   delay.tv_nsec = DELAY;
-  for (n = 0; n < READTRIES; ++n)
+  while (atomic_load_relaxed (&eagain_returned) == 0
+	 || atomic_load_relaxed (&success_returned) == 0)
       int err = pthread_rwlock_rdlock (&lock);
       if (err == EAGAIN)
@@ -101,18 +100,6 @@ do_test (void)
 	exit (1);
-  if (atomic_load_relaxed (&eagain_returned) == 0)
-    {
-      puts ("EAGAIN has never been returned");
-      exit (1);
-    }
-  if (atomic_load_relaxed (&success_returned) == 0)
-    {
-      puts ("rdlock was never successfully acquired");
-      exit (1);
-    }
   if (lock.__data.__readers != readers)
       puts ("__readers in rwlock differs from initial value");

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