Closed antoinealb closed 9 years ago
How are the stack for each task allocated ? Are they all of the same size ? Personally I suggest a variable stack size, allocated on the heap using malloc(), although there may be problem on the ARM targets I am not aware of.
Allocating the task's stack shouldn't be a problem on ARM Cortex-M. (You would probably just have to ensure alignment) However, I wouldn't pack the stack into the heap, but rather statically allocate all the stacks in a separate memory section. (a stackoverflow corrupting malloc's data structures or data allocated next to it) Why allocate them dynamically? I assume most threads will be running all the time anyway.
Why allocate them dynamically? I assume most threads will be running all the time anyway.
That's not sure : consider the case of a debug TCP shell : you want to spawn one thread per incoming connection to handle multiple clients.
That's not sure : consider the case of a debug TCP shell : you want to spawn one thread per incoming connection to handle multiple clients.
ok, in this case it makes sense, but I wouldn't do it with all the stacks.
I would prefer if the stack could be allocated wherever we wanted them, heap or special section.
We will probably need some wrapper around the task stack type too, to use the stack overflow detection function and such.
With regard to point 3, how much effort is entailed by the development of a very thin wrapper around the uC/OS-III priority system? Comparatively, how much of the code base should we change if the underlying priority system changes?
uc/OS-III priority system will not change for another 5+ year probably. The ony "real" case would be if we change our RTOS but it still will be very easy to change priorities in the application.
I am actually working on the threading API and would like to know if there is a real use case for variable stack sizes for optimization purpose or if we will always use the same stack size (easier implementation).
The required stack sizes greatly will vary between threads. Therefore we definitely want to have different stack sizes.
We don't have an external RAM like on the FPGA board, so space is very limited. I think we need variable stack sizes. Also we should allocate stacks in a separate memory on the master (STM32F4) board for performance.
Separate memory
What do you mean, like second adress bus or ?
Space is limited
Fuu, no more Lua/Python.
But ok, I will be working on an implementation allowing static variable-sized stacks.
Yes, there is a "core coupled memory" that is separate. If the stacks are in that memory, DMA transfers shouldn't affect performance.
You can do it with a linker section ?
yes, you just have to add __attribute__ ((section (".ccm")))
to your variable declaration and define the .ccm
section start & end in the linker script. (this works for uninitialized data. if we need to initialize it at boot we have do it manually, by defining a lma&vma and copying the data before we call main)
Mmmm, I see. Then we should probably have some kind of macro / defines to statically allocate a stack of a given stack, put it in correct memory, etc.
This might be a good idea.
I'm useless here, not enough experience with embedded systems. I'll go with whatever you judge appropriate :)
So, now that mutex and semaphores are more or less sorted out, let's talk about threading. For me the threading API involves quite a few design decisions :
malloc()
, although there may be problem on the ARM targets I am not aware of.OSTaskDelete(OS_PRIO_SELF);
before returning. Do we want a wrapper around tasks to do this for us ? I would say yes.