Skip to contentSkip to conversation

Stack size of created task

Xenomai-help Jakub Nowacki 2 participants 4 messages Jul 13, 2011

lore
Share & tools
lore
#0 lore raw

Hi,

I had a slight problem with freezing tasks in RTXI using Xenomai. Namely, task was working normally for some time and then froze, but just RTXI/task not the whole system. I've found that it was caused by the stack size of a task set to 2000B during the creation. Changing it to 0, i.e., automatic stack size fixed the freezing. My question is what is a preferred value there? Before on the list I asked about a problem with the stack size in the kernel being to small for switchtest to run properly on i7 machine. There, one of the answers was that safe bet is 8kB for 64-bit machine. I'm not sure should I leave the stack size in rt_task_create to 0 or to some high value or it should be machine dependent? What is being put on this stack and how to determine it's size depending on the complexity of the task (number of vars?)?

Cheers,

Jakub

#1 lore raw
Quoted 14 lines · Jakub Nowacki

Hi,

I had a slight problem with freezing tasks in RTXI using Xenomai. Namely, task was working normally for some time and then froze, but just RTXI/task not the whole system. I've found that it was caused by the stack size of a task set to 2000B during the creation. Changing it to 0, i.e., automatic stack size fixed the freezing. My question is what is a preferred value there? Before on the list I asked about a problem with the stack size in the kernel being to small for switchtest to run properly on i7 machine. There, one of the answers was that safe bet is 8kB for 64-bit machine. I'm not sure should I leave the stack size in rt_task_create to 0 or to some high value or it should be machine dependent? What is being put on this stack and how to determine it's size depending on the complexity of the task (number of vars?)?

The stack size of a task is highly dependent on what the task does, and a little bit less on the architecture. There is no generic answer.

The problem with switchtest was not the task size, but the number of kernel stacks which were available in the kernel threads stacks pool. That is an entirely different issue.

Signature · 1 line
                                                                Gilles.
#2 lore raw
Quoted 4 lines · Gilles Chanteperdrix

The stack size of a task is highly dependent on what the task does, and a little bit less on the architecture. There is no generic answer.

Yes, that is understandable.

I've found in xenomai/inclues/arm-generic/stack.h that xeno_stack, which is used in rt_task_create have a default value of __WORDSIZE*1024, hence, 64kB on 64-bit system. So using 0 stack size in rt_create_stack means that it'll be 64kB in my case, which seems to be a lot compared to the previous version. Am I correct?

I'm still not sure should I assume that stack size 0, which is (probably) __WORDSIZE*1024, is large enough for the vast majority of practical cases or put it as a variable. Also, is there any way to measure/asses the size of stack that is needed for a particular task or just when it sudden crashes increase the stack size has to be increased? I don't think that in RTXI very complicated RT tasks are used, so default size should be more than enough, but I'm still not sure what might indicate how large stack should be. As I understand it is related to the amounts of memory being used by a task, which is put on the stack during task switching, am I right?

Quoted 4 lines

The problem with switchtest was not the task size, but the number of kernel stacks which were available in the kernel threads stacks pool. That is an entirely different issue.

I understand. I was referring to it because some 'safe' value of 8kB appeared there.

Cheers,

Jakub

#3 lore raw
Quoted 3 lines · Jakub Nowacki

As I understand it is related
to the amounts of memory being used by a task, which is put on the stack during task switching, am I right?

Not really. When a function starts, it reserves some room on stack, mainly for local variables that can not be put in registers (because not enough registers are available, or for other reasons, such as the fact that the address of the variable needs to be passed to another function).

When this function calls another function, this other function reserves room on top of the first stack reserved room, hence the name "stack".

The worst case is the highest level, it may be due to too many functions reserving little space on stack, or to one function reserving too much room on stack. For most functions, you can easily measure how much they reserve on stack by looking at their disassembly. I guess there are perl scripts around to edit a report of the stack usage of each function in a binary.

Signature · 1 line
                                                                Gilles.