-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
core/tasklet: add initial support #12420
Conversation
I removed the receive thread from the It works OK on iotlab-m3 and the ROM and RAM consumption went from:
to
EDIT: Please ignore current results in RAM consumption, since the tasklet thread was initialized with THREAD_STACKSIZE_DEFAULT |
I think this could be easily modeled using event_callback and a thread running the event loop. |
@haukepetersen has a PoC here: https://github.com/haukepetersen/RIOT/tree/add_eventhandlerthread Looking at the code, the struct used for tasklet is basically identical to event_callback. The tasklet list handling is also very similar. The main difference would be that event allows multiple queues, whereas tasklet as is would only allow one. |
It seems to be exactly the same as we realized with the interrupt handler thread in PR #10555. The only difference is that the interrupt handler thread is realized on top of event queues. Although the name suggests that it is only suitable for interrupts, it could be used for other functions as well. I suggest that we only implement one mechanism for the same problem. Otherwise, an application might have different threads that do the same thing. For example, a driver for an I2C device processes interrupts by using the interrupt handler thread while the application is using with the tasklets thread. We could give the interrupt event handler a more general name, and if neded extend it with additional functions. |
@kaspar At the moment, we have the same problem with the interrupt handler thread. |
I'm aware this whole concept can be implemented with event queues. The only reason why I didn't do it was to not mix sys dependencies with core, but maybe it's better to stick to event_loops :)
That was exactly the purpose I was aiming for. I couldn't find the original references for the IRQ handler proposal and I was not aware of this feature. I totally agree that we should only aim to have one solution for this.
Well, the ISR handler thread is basically a tasklet mechanism. Any opinions on closing this PR and renaming the ISR thread handler concept to "tasklet"? I think it will be easier to find in the documentation. |
@jia200x At the moment, the interrupt handler thread is realized as singleton. This has two advantages. First, there is no need to create the thread explicitly. It's done when it's used the first time. Second, as long as the What are the options?
|
I would be fine if we would expand and rename the |
hi @gschorcht
I'm a little bit confused with this statement that leads to the first proposal. Isn't the stack already allocated in RAM even before creating the thread? I get that if the function is never called, then the stack won't be allocated because of compiler optimizations, but in any other case the RAM usage would be the same. Or am I missing something?
I think this is a good solution!
Ok, I can do it, no problem. Then, I can close this PR |
Yes, I expressed myself wrong, my fault. That is exactly what I meant. If you don't use the function the stack is optimized out. For example, the sizes for an Cortex-M with
and without calling the function.
The difference in
Great. |
@kaspar030 Any feedback from your side to the proposed approach? |
@maribu It might be interesting for you. |
Yes, indeed. Especially the possibility of sharing one thread to handling the ISR callback between different network devices is nice for our testbed nodes with plenty of netdevs. To me it appeared that the conclusion that |
Basically the irq_handler is a tasklets implementation. So, yes. |
#12459 is there |
since #12474 got merged, I will just close this one |
Contribution description
This PR adds kernel support of tasklets, similar to the ones in Linux
Tasklets are snippets of code that are ran as soon as the OS finds a safe time. They can be scheduled several time but will only run once (they can be re-scheduled again after ran).
Scheduling tasklets is a thread safe operation and can be done from ISR context.
They are extremely useful for doing ISR offloading. E.g handling radios from the OS instead of the network stack. It's possible to change:
into
Since the device drivers registers the tasklet, it might not be necessary to have a
dev->driver->isr
netdev function with this method. And also, it ensures packet reception is preemptive since the tasklet run in the highest priority (see #11256).Also, drivers or components that need to offload ISR wouldn't require to register a thread (e.g recv thread in some applications)
I think there was a comment somewhere from @gschorcht with a similar idea for offloading ISRs. It's also inspired in the work of @gebart in #9326.
The current implementation doesn't support priorities nor deadlines (for real-time constraints), but they could be added in follow ups.
Testing procedure
make doc
make -C tests/unittests tests-tasklet
Issues/PRs references
None so far, but it's would benefit the PHY & MAC rework