patacongo commented on a change in pull request #3517:
URL: https://github.com/apache/incubator-nuttx/pull/3517#discussion_r612749139



##########
File path: arch/arm/src/common/arm_usestack.c
##########
@@ -127,37 +117,17 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t 
stack_size)
   /* Save the new stack allocation */
 
   tcb->stack_alloc_ptr = stack;
-
-  /* Align stack top */
-
-  tcb->adj_stack_ptr =
-      (FAR void *)STACK_ALIGN_DOWN((uintptr_t)stack + stack_size);
-
-  /* Offset by tls_size */
-
-  stack = (FAR void *)((uintptr_t)stack + tls_size);
-
-  /* Is there enough room for at least TLS ? */
-
-  if ((uintptr_t)stack > (uintptr_t)tcb->adj_stack_ptr)
-    {
-      return -ENOMEM;
-    }
-
-  tcb->adj_stack_size = (uintptr_t)tcb->adj_stack_ptr - (uintptr_t)stack;
-
-  /* Initialize the TLS data structure */
-
-  memset(tcb->stack_alloc_ptr, 0, tls_size);
+  tcb->adj_stack_ptr   = tcb->stack_alloc_ptr;
+  tcb->adj_stack_size  =
+      STACK_ALIGN_DOWN((uintptr_t)stack + stack_size) - (uintptr_t)stack;

Review comment:
       > 
   > 
   
   > Before this change it looked (CONFIG_TLS_ALIGNED not lit) like 
300+sizeof(tls) which I got what I asked for and the OS got what it needed. Is 
that still the case?
   
   I believe you will get 300-sizeof(tls).  That could be dangerous for finely 
tuned, minimal stack sizes.
   
   > Also is it correct that if I ask for an 11K stack it may get truncated by 
3K without warning if the TLS_MAXSTACK (log and friends) ends up at 8K?
   
   And CONFIG_TLS_ALIGNED=y.  In normal usage, that option is only used with an 
MMU.  In that case, there is no penalty for the alignment because a virtual 
stack address space is allocated (and backed up by real RAM only on demand).  
Normally the alignment is around 1Mb.  I seem to recall the Linux pthread 
stacks are aligned to a 2Mb virtual address (but I don't remember for certain).
   
   If you can use CONFIG_TLS_ALIGNED=y, then you get a good performance benefit 
in the you can avoid a system call.  Without CONFIG_TLS_ALIGNED, a system call 
is required.  But with CONFIG_TLS_ALIGNED=y, no system call is needed.  The 
stack base is found simply by:
   
       stack_base = ((builtin_stack_pointer()) & ~(TLS_MAXSTACK - 1)
   
   There is not much motivation to use CONFIG_TLS_ALIGNED=y in a FLAT build  
since the cost of a system call is very low.  There are usually no system calls 
in the FLAT build (although they can be set up for some improved ELF module 
support).  The PROTECTED build with the MPU might benefit with 8Kb aligned 
stacks although stack alignment might result in some additional memory 
fragmentation.
   
   
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to