[rotorcraft][linux] limit main/event loop to 1kHz

This is a kludge until we can better leverage threads and have real events.
Without this limit the event flags will constantly polled as fast as possible,
resulting on 100% cpu load on boards with an (RT)OS.
On bare metal boards this is not an issue, as you have nothing else running anyway.

Enable this for the bebop and ardrone2 by default.

Alternative to #1239 and should fix #1233
This commit is contained in:
Felix Ruess
2015-07-15 13:59:24 +02:00
parent e8536f8514
commit da0dac74bd
3 changed files with 30 additions and 0 deletions

View File

@@ -42,6 +42,9 @@ $(TARGET).CFLAGS += -DUSE_LINUX_SIGNAL -D_GNU_SOURCE
$(TARGET).CFLAGS += -DLINUX_LINK_STATIC
$(TARGET).LDFLAGS += -static
# limit main loop to 1kHz so ap doesn't need 100% cpu
$(TARGET).CFLAGS += -DLIMIT_EVENT_POLLING
# -----------------------------------------------------------------------
# default LED configuration

View File

@@ -38,6 +38,9 @@ $(TARGET).srcs += $(SRC_BOARD)/video.c
$(TARGET).CFLAGS += -DLINUX_LINK_STATIC
$(TARGET).LDFLAGS += -static
# limit main loop to 1kHz so ap doesn't need 100% cpu
$(TARGET).CFLAGS += -DLIMIT_EVENT_POLLING
# -----------------------------------------------------------------------
# default LED configuration

View File

@@ -120,10 +120,34 @@ int main(void)
{
main_init();
#if LIMIT_EVENT_POLLING
/* Limit main loop frequency to 1kHz.
* This is a kludge until we can better leverage threads and have real events.
* Without this limit the event flags will constantly polled as fast as possible,
* resulting on 100% cpu load on boards with an (RT)OS.
* On bare metal boards this is not an issue, as you have nothing else running anyway.
*/
uint32_t t_begin = 0;
uint32_t t_diff = 0;
while (1) {
t_begin = get_sys_time_usec();
handle_periodic_tasks();
main_event();
/* sleep remaining time to limit to 1kHz */
t_diff = get_sys_time_usec() - t_begin;
if (t_diff < 1000) {
sys_time_usleep(1000 - t_diff);
}
}
#else
while (1) {
handle_periodic_tasks();
main_event();
}
#endif
return 0;
}
#endif /* SITL */