]> rtime.felk.cvut.cz Git - ert_linux.git/commitdiff
Postpone next sampling time on overruns
authorMichal Sojka <sojkam1@fel.cvut.cz>
Tue, 23 Jul 2013 11:51:52 +0000 (13:51 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Tue, 23 Jul 2013 11:51:52 +0000 (13:51 +0200)
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

index 96ca6eaf239c8490e82a5456a8a9c46ecdf8888d..3308b960a906052d17427b6792664017397655f7 100644 (file)
        rtExtModeCheckEndTrigger();\r
       %endif\r
 \r
-      next.tv_sec += period.tv_sec;\r
-      next.tv_nsec += period.tv_nsec;\r
-      if (next.tv_nsec >= 1000000000) {\r
-       next.tv_sec++;\r
-       next.tv_nsec -= 1000000000;\r
-      }\r
-      clock_gettime(CLOCK_MONOTONIC, &now);\r
-      if (now.tv_sec > next.tv_sec ||\r
-          (now.tv_sec == next.tv_sec && now.tv_nsec > next.tv_nsec)) {\r
-           uint64_T nsec = (now.tv_sec - next.tv_sec) * 1000000000 + now.tv_nsec - next.tv_nsec;\r
-           fprintf(stderr, "Base rate (%<fundamentalStepSize>s) overrun by %d us\n", (int)(nsec/1000));\r
-      }\r
+      do {\r
+       next.tv_sec += period.tv_sec;\r
+       next.tv_nsec += period.tv_nsec;\r
+       if (next.tv_nsec >= 1000000000) {\r
+         next.tv_sec++;\r
+         next.tv_nsec -= 1000000000;\r
+       }\r
+       clock_gettime(CLOCK_MONOTONIC, &now);\r
+       if (now.tv_sec > next.tv_sec ||\r
+           (now.tv_sec == next.tv_sec && now.tv_nsec > next.tv_nsec)) {\r
+         uint64_T nsec = (now.tv_sec - next.tv_sec) * 1000000000 + now.tv_nsec - next.tv_nsec;\r
+         fprintf(stderr, "Base rate (%<fundamentalStepSize>s) overrun by %d us\n", (int)(nsec/1000));\r
+         next = now;\r
+         continue;\r
+       }\r
+      }        while (0);\r
       clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &next, NULL);\r
 \r
     }\r