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 v2] Use default_attr to store default pthread attributes


Hi,

This patch is another attempt at moving __default_stacksize into
default_attr (calling it __default_attr now).  This is needed for my
future patch (first attempt here[1]), where I introduce an API to set
the process-level default attributes for threads.  With this move,
I've also removed the initializer for guardsize and instead added it
to the libpthread.so constructor.

I've tested to verify that none of this causes regressions in the
testsuite on x86_64.  OK to commit?

Siddhesh
   
        * allocatestack.c (allocate_stack): Use __default_attr instead
        of __default_stacksize.
        * nptl-init.c (__pthread_initialize_minimal_internal):
        Likewise.  Initialize guardsize.
        * pthreadP.h (__default_attr): Declare.
        * pthread_attr_getstacksize.c (__pthread_attr_getstacksize):
        Use __default_attr instead of __default_stacksize.
        * pthread_create.c (default_attr): Remove.
        (__pthread_create_2_1): Use __default_attr instead of
        default_attr.
        * vars.c (__default_stacksize): Remove.
        (__default_attr): New static variable to store
        default thread attributes.


diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c
index 31c8829..eee74e4 100644
--- a/nptl/allocatestack.c
+++ b/nptl/allocatestack.c
@@ -358,7 +358,7 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
 
   /* Get the stack size from the attribute if it is set.  Otherwise we
      use the default we determined at start time.  */
-  size = attr->stacksize ?: __default_stacksize;
+  size = attr->stacksize ?: __default_attr.stacksize;
 
   /* Get memory for the stack.  */
   if (__builtin_expect (attr->flags & ATTR_FLAG_STACKADDR, 0))
diff --git a/nptl/nptl-init.c b/nptl/nptl-init.c
index 19e6616..ca2cd59 100644
--- a/nptl/nptl-init.c
+++ b/nptl/nptl-init.c
@@ -423,7 +423,8 @@ __pthread_initialize_minimal_internal (void)
 
   /* Round the resource limit up to page size.  */
   limit.rlim_cur = (limit.rlim_cur + pagesz - 1) & -pagesz;
-  __default_stacksize = limit.rlim_cur;
+  __default_attr.stacksize = limit.rlim_cur;
+  __default_attr.guardsize = GLRO (dl_pagesize);
 
 #ifdef SHARED
   /* Transfer the old value from the dynamic linker's internal location.  */
diff --git a/nptl/pthreadP.h b/nptl/pthreadP.h
index d08b219..9d37361 100644
--- a/nptl/pthreadP.h
+++ b/nptl/pthreadP.h
@@ -147,8 +147,8 @@ enum
 /* Internal variables.  */
 
 
-/* Default stack size.  */
-extern size_t __default_stacksize attribute_hidden;
+/* Default pthread attributes.  */
+extern struct pthread_attr __default_attr attribute_hidden;
 
 /* Size and alignment of static TLS block.  */
 extern size_t __static_tls_size attribute_hidden;
diff --git a/nptl/pthread_attr_getstacksize.c b/nptl/pthread_attr_getstacksize.c
index 6df7062..6e3a408 100644
--- a/nptl/pthread_attr_getstacksize.c
+++ b/nptl/pthread_attr_getstacksize.c
@@ -32,7 +32,7 @@ __pthread_attr_getstacksize (attr, stacksize)
 
   /* If the user has not set a stack size we return what the system
      will use as the default.  */
-  *stacksize = iattr->stacksize ?: __default_stacksize;
+  *stacksize = iattr->stacksize ?: __default_attr.stacksize;
 
   return 0;
 }
diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c
index c6f2fdd..831c8a2 100644
--- a/nptl/pthread_create.c
+++ b/nptl/pthread_create.c
@@ -435,15 +435,6 @@ start_thread (void *arg)
 }
 
 
-/* Default thread attributes for the case when the user does not
-   provide any.  */
-static const struct pthread_attr default_attr =
-  {
-    /* Just some value > 0 which gets rounded to the nearest page size.  */
-    .guardsize = 1,
-  };
-
-
 int
 __pthread_create_2_1 (newthread, attr, start_routine, arg)
      pthread_t *newthread;
@@ -457,7 +448,7 @@ __pthread_create_2_1 (newthread, attr, start_routine, arg)
   if (iattr == NULL)
     /* Is this the best idea?  On NUMA machines this could mean
        accessing far-away memory.  */
-    iattr = &default_attr;
+    iattr = &__default_attr;
 
   struct pthread *pd = NULL;
   int err = ALLOCATE_STACK (iattr, &pd);
diff --git a/nptl/vars.c b/nptl/vars.c
index 2bcd1f8..2b0798a 100644
--- a/nptl/vars.c
+++ b/nptl/vars.c
@@ -20,13 +20,9 @@
 #include <tls.h>
 #include <unistd.h>
 
-/* Default stack size.  */
-size_t __default_stacksize attribute_hidden
-#ifdef SHARED
-;
-#else
-  = PTHREAD_STACK_MIN;
-#endif
+/* Default thread attributes for the case when the user does not
+   provide any.  */
+struct pthread_attr __default_attr attribute_hidden;
 
 /* Flag whether the machine is SMP or not.  */
 int __is_smp attribute_hidden;


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