-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Allow running mbed_highprio_event_queue() in main thread #10256
Comments
If it needs to be high priority, and you're using the normal event queue for things with standard timing characteristics, then combining them won't work. The high-priority user won't be getting the latency requirement they apparently need - they'll be stuck behind all the people taking tens of milliseconds per event. If it does work, then it would seem that particular user doesn't need to be high priority at all, and should be changed to use the normal. Or it should have a flag to configure it to use normal optionally with documentation on whatever performance provisos there are. Just doing it globally feels dangerous, but maybe in an emergency? Now, there is an alternative in the opposite direction that can work - telling a driver to use interrupts directly instead of the high priority queue. The Nanostack/Pelion client HAL has that option, called (obscurely) The high priority queue and normal priority queue pair are an analogue to the two "interrupt" and "foreground" contexts you'd get in a bare-metal build, but pushing the high-priority down to thread to be a bit nicer to latency - avoiding that serial loss when you a high-priority SPI transfer. So you always have the option to push it back up to interrupt, but it's a tad marginal. Unfortunately we don't have a way of transparently making "high priority" be thread or interrupt at the in the main code, although @c1728p9 has got something along those lines in USB, I believe. |
Internal Jira reference: https://jira.arm.com/browse/MBOCUSTRIA-1091 |
In your application where you're experimenting with this option - who's using the high-priority queue and who's using the normal one? |
@kjbracey-arm I'm not sure. I'm using Pelion Client with Mbed OS 5.12 on DISCO-L475VG-IOT01A1 board and nothing seems to break when disabling highprio queue. |
Low memory client configurations are @TeroJaasko's speciality. Maybe he has input. The high priority queue is probably just being initialised for the Nanostack HAL's "platform timer". I guess if that timer is only being used to schedule "normal priority" work in this system, and it's not being used for any driver-type purposes, it can be shoved down to the normal queue. I think our assumption was though that in a system the high priority event queue would be in use by drivers, so would not cost extra for that purpose - it's only the transition from "no users" to "1 user" which costs you something. But a lot of drivers are still creating their own high-priority threads rather than sharing the high-priority one. A better line of attack might be to find any such driver in your system, and make it share high priority with Nanostack's platform timer. You may also want to turn on |
@kjbracey-arm Yes, already doing that. An overview of changes I made is in: https://github.com/janjongboom/pelion-ready-plus-azure. |
Another line of attack here would be to improve At the minute it's kind of a minimal integration because it doesn't let the Mbed OS event loop also take over scheduling - it's just done minimally in the "bare-metal-like" Nanostack porting layer, rather than having a complete higher-level reimplementation of the API like for MINAR. If we did that, then the Nanostack HAL platform timer wouldn't be needed. And there would be other power/latency benefits from hooking into the standard system. Running your own |
@kjbracey-arm I agree wholeheartedly. IMHO too it is the user of those queues which should decide if and how they can tolerate the latencies if there are no separate message queues. The mbed_highprio_event_queue() call likely comes from arm_hal_timer.cpp, arm_hal_fhss_timer.cpp or on a Pelion application, the pal_plat_network.cpp. The last one is using the high priority queue by default just because the high-priority thread already always exists and the code did not want to waste memory. All these call sites have alternative paths for If the system works with the attached hack, it should work also with "nanostack-hal.critical-section-usable-from-interrupt: true", which effectively also remove calls to mbed_highprio_event_queue(), some parts of RTOS and as a bonus, makes code a bit closer to compile without MBED_CONF_RTOS_PRESENT -define. |
@TeroJaasko @kjbracey-arm But right now I don't get this choice. The high prio queue is always started up. What if none of my libraries / drivers use the queue? The thread is still started and still steals a bunch of RAM. |
It's only started if it's used. It is being used by the Nanostack event loop, which is being used by Pelion Client. First call to (Exception being |
@kjbracey-arm Ah, ok. Thanks for specifying. |
@janjongboom I'm not clear if further enhancement is till needed. Please reopen if so. |
Description
I can disable the normal event queue thread by setting
MBED_CONF_EVENTS_SHARED_DISPATCH_FROM_APPLICATION=1
, but the high prio queue is always running from a separate thread. But what if my application does not require this, or is very low on memory? I want to be able to disable it. I think a good way would be to introduceMBED_CONF_EVENTS_ENABLE_HIGHPRIO_QUEUE
and if set to0
it returnsmbed_event_queue()
.E.g.:
Issue request type
The text was updated successfully, but these errors were encountered: