osmo-gsm-tester: Convert event_loop.wait to support passive polling
Right now, all polling in osmo-gsm-tester is done by sleeping small amounts of times (like 0.1 seconds), then calling poll function everywhere. Some of those poll functions are actually event-based (like glib main loop, or any fd/socket being used) and can be monitored with select() instead of using active polling. This way we avoid wasting resources and we avoid delaying signal-driven events.
For objects not supporting passive polling, we should provide an API to create a timer object (man timerd_create ?) and just call select() on those.
#2 Updated by pespin over 2 years ago
As far as I could see now, it seems the best idea will be to re-use some of the code in modem.py and move it to event_loop.py to have an EventLoop class and public global functions which use a global instance of that object.
This EventLoop will contain a glib main loop inside. It will call glib_main_loop.iterate() every time we want to poll. New methods will be added to be able to register fds for passive polling instead of only having active polling functions. Also we will add methods to add/remove timer callbacks. We can then fire active polling every 0.1 seconds by using the timer registered function, and we can use the same to implement the wait() API we already have.
The idea is to slowly move required active polling users (python-smpp fd, wait(), sleep(), etc.) to use passive polling/timers.
Also interesting to look at GSource to implement management of all the fds/poll functions:
#3 Updated by pespin over 2 years ago
- Status changed from New to Feedback
- % Done changed from 0 to 60
Patches re-implementing event_loop wait() and sleep() using glib loop have been usbmited to gerrit:
remote: https://gerrit.osmocom.org/7559 event_loop: Use glib as mainloop impl and move modem to use event_loop remote: https://gerrit.osmocom.org/7560 Drop event_loop global functions and import MainLoop
With this code, we remove part of busy polling and from here we can easily add a register_fd() and unregister_fd() APIs to event_loop to be able to use passive polling with any source using an FD. We can even implement GSource subclasses.