Skip to content

Commit 1a8823f

Browse files
authored
Merge pull request #1434 from nasa/integration-candidate
osal Integration candidate: Caelum-rc4+dev66
2 parents edede38 + 9efb7c1 commit 1a8823f

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Changelog
22

3-
##Development Build: v6.0.0-rc4+dev243
3+
## Development Build: v6.0.0-rc4+dev247
4+
- adjust pthread stack to account for TCB+TLS
5+
- See <https://github.com/nasa/osal/pull/1430>
6+
7+
## Development Build: v6.0.0-rc4+dev243
48
- Wrong memory alignment calculation
59
- See <https://github.com/nasa/osal/pull/1413>
610

src/os/inc/osapi-version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
/*
3535
* Development Build Macro Definitions
3636
*/
37-
#define OS_BUILD_NUMBER 243
37+
#define OS_BUILD_NUMBER 247
3838
#define OS_BUILD_BASELINE "v6.0.0-rc4"
3939

4040
/*

src/os/posix/src/os-impl-tasks.c

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,26 @@
3737
#include "os-shared-idmap.h"
3838

3939
/*
40-
* Defines
40+
* Extra Stack Space for overhead -
41+
*
42+
* glibc pthreads implicitly puts its TCB/TLS structures at the base of the stack.
43+
* The actual size of these structures is highly system and configuration dependent.
44+
* Experimentation/measurement on an x64-64 system with glibc shows this to consume
45+
* between 9-10kB of stack space off the top.
46+
*
47+
* There does not seem to be a reliable/standardized way of determining how large this
48+
* is going to be, but PTHREAD_STACK_MIN (if defined) should include adequate space for it.
49+
* If this is not defined, then just assume 1 page.
50+
*
51+
* Importantly - when the user passes a stack size to OS_TaskCreate() - the expectation is
52+
* that there will be at least this amount of real _usable_ space for the task. If 10kB
53+
* is used before the entry point is even called, this needs to be accounted for, or else
54+
* the stack might end up being too small.
4155
*/
42-
#ifndef PTHREAD_STACK_MIN
43-
#define PTHREAD_STACK_MIN (8 * 1024)
56+
#ifdef PTHREAD_STACK_MIN
57+
#define OS_IMPL_STACK_EXTRA PTHREAD_STACK_MIN
58+
#else
59+
#define OS_IMPL_STACK_EXTRA POSIX_GlobalVars.PageSize
4460
#endif
4561

4662
/* Tables where the OS object information is stored */
@@ -451,20 +467,9 @@ int32 OS_Posix_InternalTaskCreate_Impl(pthread_t *pthr, osal_priority_t priority
451467
}
452468

453469
/*
454-
* Adjust the stack size parameter.
455-
*
456-
* POSIX has additional restrictions/limitations on the stack size of tasks that
457-
* other RTOS environments may not have. Specifically POSIX says that the stack
458-
* size must be at least PTHREAD_STACK_MIN and may also need to be a multiple of the
459-
* system page size.
460-
*
461-
* Rounding up means the user might get a bigger stack than they requested, but
462-
* that should not break anything aside from consuming extra memory.
470+
* Adjust the stack size parameter, add budget for TCB/TLS overhead.
463471
*/
464-
if (stacksz < PTHREAD_STACK_MIN)
465-
{
466-
stacksz = PTHREAD_STACK_MIN;
467-
}
472+
stacksz += OS_IMPL_STACK_EXTRA;
468473

469474
stacksz += POSIX_GlobalVars.PageSize - 1;
470475
stacksz -= stacksz % POSIX_GlobalVars.PageSize;

0 commit comments

Comments
 (0)