From d3033cf52711d2cd7c2581a26a99112be572eb07 Mon Sep 17 00:00:00 2001 From: Michal Sojka Date: Tue, 23 Jul 2013 13:51:52 +0200 Subject: [PATCH] Postpone next sampling time on overruns If the overrun is longer than a period, we may end up executing next steps without any delay. Most of the time this is not a good think to do so on overruns, we simply print a message and postpone the next step to now + period. --- ert_linux/ert_linux_multitasking_main.tlc | 28 +++++++++++++---------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/ert_linux/ert_linux_multitasking_main.tlc b/ert_linux/ert_linux_multitasking_main.tlc index 96ca6ea..3308b96 100644 --- a/ert_linux/ert_linux_multitasking_main.tlc +++ b/ert_linux/ert_linux_multitasking_main.tlc @@ -181,18 +181,22 @@ rtExtModeCheckEndTrigger(); %endif - next.tv_sec += period.tv_sec; - next.tv_nsec += period.tv_nsec; - if (next.tv_nsec >= 1000000000) { - next.tv_sec++; - next.tv_nsec -= 1000000000; - } - clock_gettime(CLOCK_MONOTONIC, &now); - if (now.tv_sec > next.tv_sec || - (now.tv_sec == next.tv_sec && now.tv_nsec > next.tv_nsec)) { - uint64_T nsec = (now.tv_sec - next.tv_sec) * 1000000000 + now.tv_nsec - next.tv_nsec; - fprintf(stderr, "Base rate (%s) overrun by %d us\n", (int)(nsec/1000)); - } + do { + next.tv_sec += period.tv_sec; + next.tv_nsec += period.tv_nsec; + if (next.tv_nsec >= 1000000000) { + next.tv_sec++; + next.tv_nsec -= 1000000000; + } + clock_gettime(CLOCK_MONOTONIC, &now); + if (now.tv_sec > next.tv_sec || + (now.tv_sec == next.tv_sec && now.tv_nsec > next.tv_nsec)) { + uint64_T nsec = (now.tv_sec - next.tv_sec) * 1000000000 + now.tv_nsec - next.tv_nsec; + fprintf(stderr, "Base rate (%s) overrun by %d us\n", (int)(nsec/1000)); + next = now; + continue; + } + } while (0); clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &next, NULL); } -- 2.39.2