Provide macros and extensions to the task spawn command to set the stack sizes right

This commit is contained in:
Lorenz Meier 2016-09-07 22:05:20 +02:00
parent efd64e2cd2
commit 5b69e58925
3 changed files with 12 additions and 6 deletions

View File

@ -185,11 +185,7 @@ px4_task_t px4_task_spawn_cmd(const char *name, int scheduler, int priority, int
stack_size = PTHREAD_STACK_MIN;
}
// The stack size is intended for 32-bit architectures; therefore
// we often run out of stack space when pointers are larger than 4 bytes.
// Double the stack size on posix when we're on a 64-bit architecture.
stack_size *= __SIZEOF_POINTER__ >> 2;
rv = pthread_attr_setstacksize(&attr, stack_size);
rv = pthread_attr_setstacksize(&attr, PX4_STACK_ADJUSTED(stack_size));
if (rv != 0) {
PX4_ERR("pthread_attr_setstacksize to %d returned error (%d)", stack_size, rv);

View File

@ -77,11 +77,14 @@ typedef struct pollfd px4_pollfd_struct_t;
#define px4_access _GLOBAL access
#define px4_getpid _GLOBAL getpid
#define PX4_STACK_OVERHEAD 0
#elif defined(__PX4_POSIX)
#define PX4_F_RDONLY O_RDONLY
#define PX4_F_WRONLY O_WRONLY
#define PX4_F_CREAT O_CREAT
#define PX4_STACK_OVERHEAD 8192
typedef short pollevent_t;
@ -118,6 +121,13 @@ __END_DECLS
#error "No TARGET OS Provided"
#endif
// The stack size is intended for 32-bit architectures; therefore
// we often run out of stack space when pointers are larger than 4 bytes.
// Double the stack size on posix when we're on a 64-bit architecture.
// Most full-scale OS use 1-4K of memory from the stack themselves
#define PX4_STACK_ADJUSTED(_s) (_s * (__SIZEOF_POINTER__ >> 2) + PX4_STACK_OVERHEAD)
__BEGIN_DECLS
extern int px4_errno;

View File

@ -202,7 +202,7 @@ px4_task_t px4_task_spawn_cmd(const char *name, int scheduler, int priority, int
fixed_stacksize = (fixed_stacksize < (size_t)stack_size) ? (size_t)stack_size : fixed_stacksize;
PX4_DEBUG("setting the thread[%s] stack size to[%d]", name, fixed_stacksize);
pthread_attr_setstacksize(&attr, fixed_stacksize);
pthread_attr_setstacksize(&attr, PX4_STACK_ADJUSTED(fixed_stacksize));
PX4_DEBUG("stack address after pthread_attr_setstacksize: 0x%X", attr.stackaddr);
param.sched_priority = priority;