[PATCH] Fix nptl/tst-cond1{6,7} on 32-bit with many cpus

David Miller davem@davemloft.net
Mon Mar 26 21:35:00 GMT 2012


From: "Carlos O'Donell" <carlos@systemhalted.org>
Date: Mon, 26 Mar 2012 10:44:21 -0400

> On Sun, Mar 25, 2012 at 9:47 PM, David Miller <davem@davemloft.net> wrote:
>> @@ -76,9 +76,15 @@ do_test (void)
>>   count *= 4;
>>
>>   pthread_t th[count];
>> -  int i, ret;
>> +  pthread_attr_t attr;
>> +  int i, ret, sz;
>> +  pthread_attr_init (&attr);
>> +  sz = __getpagesize ();
>> +  if (sz < 64 * 1024)
>> +         sz = 64 * 1024;
> 
> Should this be PTHREAD_STACK_MIN instead to allow for per-machine
> variations? Is it sufficient to use PTHREAD_STACK_MIN?

We still need to take __getpagesize() into account, because some
PTHREAD_STACK_MIN definitions are smaller than the largest possible
page size on the respective architecture.

And it also turns out that tst-cond18 has the same problem as
tst-cond16 and tst-cond17

Here is an updated patch:

nptl/

2012-03-26  David S. Miller  <davem@davemloft.net>

	* tst-cond16.c (do_test): Use a thread stack size which is either
	PTHREAD_STACK_MIN or the page size, whichever is larger.
	* tst-cond18.c (do_test): Likewise.

diff --git a/nptl/tst-cond16.c b/nptl/tst-cond16.c
index 44b9863..8a35d95 100644
--- a/nptl/tst-cond16.c
+++ b/nptl/tst-cond16.c
@@ -76,9 +76,15 @@ do_test (void)
   count *= 4;
 
   pthread_t th[count];
-  int i, ret;
+  pthread_attr_t attr;
+  int i, ret, sz;
+  pthread_attr_init (&attr);
+  sz = __getpagesize ();
+  if (sz < PTHREAD_STACK_MIN)
+	  sz = PTHREAD_STACK_MIN;
+  pthread_attr_setstacksize (&attr, sz);
   for (i = 0; i < count; ++i)
-    if ((ret = pthread_create (&th[i], NULL, tf, NULL)) != 0)
+    if ((ret = pthread_create (&th[i], &attr, tf, NULL)) != 0)
       {
 	errno = ret;
 	printf ("pthread_create %d failed: %m\n", i);
diff --git a/nptl/tst-cond18.c b/nptl/tst-cond18.c
index a1bb947..264c932 100644
--- a/nptl/tst-cond18.c
+++ b/nptl/tst-cond18.c
@@ -87,10 +87,16 @@ do_test (void)
   count *= 8;
 
   pthread_t th[count + 1];
-  int i, ret;
+  pthread_attr_t attr;
+  int i, ret, sz;
+  pthread_attr_init (&attr);
+  sz = __getpagesize ();
+  if (sz < PTHREAD_STACK_MIN)
+	  sz = PTHREAD_STACK_MIN;
+  pthread_attr_setstacksize (&attr, sz);
 
   for (i = 0; i <= count; ++i)
-    if ((ret = pthread_create (&th[i], NULL, tf, (void *) (long) i)) != 0)
+    if ((ret = pthread_create (&th[i], &attr, tf, (void *) (long) i)) != 0)
       {
 	errno = ret;
 	printf ("pthread_create %d failed: %m\n", i);



More information about the Libc-alpha mailing list