server/server: fix target timer timing
authorTomas Vanek <vanekt@fbl.cz>
Mon, 15 Aug 2022 17:18:18 +0000 (19:18 +0200)
committerAntonio Borneo <borneo.antonio@gmail.com>
Sat, 27 Aug 2022 16:17:53 +0000 (16:17 +0000)
The change 6363: Call poll at a fixed interval
switched from target_call_timer_callbacks() to target_call_timer_callbacks_now().
It breaks the timing as all timers callbacks are called every time
one timer expires.

Revert this part of change and use target_call_timer_callbacks().

Fixes: db16b3dc5b06 (Call poll at a fixed interval.)
Change-Id: Ib5b7774de9694d40c55d2a4109d0d1582fc5008b
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: https://review.openocd.org/c/openocd/+/7118
Tested-by: jenkins
Reviewed-by: Tim Newsome <tim@sifive.com>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
src/server/server.c

index eeaa3d750ecff316041bafb0dfcb416c02948d36..6542200d2f04e49bbc2319c46216adf8b05d8c11 100644 (file)
@@ -473,7 +473,7 @@ int server_loop(struct command_context *command_context)
                        tv.tv_usec = 0;
                        retval = socket_select(fd_max + 1, &read_fds, NULL, NULL, &tv);
                } else {
-                       /* Every 100ms, can be changed with "poll_period" command */
+                       /* Timeout socket_select() when a target timer expires or every polling_period */
                        int timeout_ms = next_event - timeval_ms();
                        if (timeout_ms < 0)
                                timeout_ms = 0;
@@ -507,9 +507,12 @@ int server_loop(struct command_context *command_context)
                }
 
                if (retval == 0) {
-                       /* We only execute these callbacks when there was nothing to do or we timed
-                        *out */
-                       target_call_timer_callbacks_now();
+                       /* Execute callbacks of expired timers when
+                        * - there was nothing to do if poll_ok was true
+                        * - socket_select() timed out if poll_ok was false, now one or more
+                        *   timers expired or the polling period elapsed
+                        */
+                       target_call_timer_callbacks();
                        next_event = target_timer_next_event();
                        process_jim_events(command_context);