diff options
author | Tim Newsome <tim@sifive.com> | 2021-07-09 12:58:07 -0700 |
---|---|---|
committer | Antonio Borneo <borneo.antonio@gmail.com> | 2021-07-31 10:08:47 +0100 |
commit | db16b3dc5b061c152f2478a5b9b7b3a3b0908911 (patch) | |
tree | 97d7d067da9b1a6b51842c28adbb5404ad86d594 /src/server | |
parent | beff3de2ce7e275bf8c0051641dfc1acb0ecee9a (diff) | |
download | riscv-openocd-db16b3dc5b061c152f2478a5b9b7b3a3b0908911.zip riscv-openocd-db16b3dc5b061c152f2478a5b9b7b3a3b0908911.tar.gz riscv-openocd-db16b3dc5b061c152f2478a5b9b7b3a3b0908911.tar.bz2 |
Call poll at a fixed interval.
The existing implementation blocks in select() for a fixed amount of
time. This change tracks when the next event (likely poll()) wants to be
run, and uses a shorter timeout in select() if necessary.
Also track all these timeouts using milliseconds as returned by
timeval_ms() instead of `struct timeval` to simplify the code.
This feature is helpful if poll() wants to do something like sample PCs
or memory values for basically the entire time that otherwise OpenOCD
would be hung in select(). See
https://github.com/riscv/riscv-openocd/pull/541 for an example of that.
The RISC-V code using this change will be upstreamed some day, too.
Signed-off-by: Tim Newsome <tim@sifive.com>
Change-Id: I67104a7cf69ed07c8399c14aa55963fc5116a67d
Reviewed-on: http://openocd.zylin.com/6363
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Diffstat (limited to 'src/server')
-rw-r--r-- | src/server/server.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/server/server.c b/src/server/server.c index 6f0b23c..64acd36 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -437,6 +437,8 @@ int server_loop(struct command_context *command_context) /* used in accept() */ int retval; + int64_t next_event = timeval_ms() + polling_period; + #ifndef _WIN32 if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) LOG_ERROR("couldn't set SIGPIPE to SIG_IGN"); @@ -478,7 +480,12 @@ int server_loop(struct command_context *command_context) retval = socket_select(fd_max + 1, &read_fds, NULL, NULL, &tv); } else { /* Every 100ms, can be changed with "poll_period" command */ - tv.tv_usec = polling_period * 1000; + int timeout_ms = next_event - timeval_ms(); + if (timeout_ms < 0) + timeout_ms = 0; + else if (timeout_ms > polling_period) + timeout_ms = polling_period; + tv.tv_usec = timeout_ms * 1000; /* Only while we're sleeping we'll let others run */ openocd_sleep_prelude(); kept_alive(); @@ -511,7 +518,8 @@ 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(); + target_call_timer_callbacks_now(); + next_event = target_timer_next_event(); process_jim_events(command_context); FD_ZERO(&read_fds); /* eCos leaves read_fds unchanged in this case! */ |