The start time of a timer is currently set to the beg of the use case which generates issue if the timer starts to be used quite late in use case.
Change the init sequence so the start time of the timer is initialized the 1st time it is used
Signed-off-by: Vincent Guittot vincent.guittot@linaro.org --- src/rt-app.c | 12 ++++++------ src/rt-app_parse_config.c | 2 +- src/rt-app_types.h | 1 + 3 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/src/rt-app.c b/src/rt-app.c index 3cd601d..d2945e1 100644 --- a/src/rt-app.c +++ b/src/rt-app.c @@ -174,6 +174,12 @@ static int run_event(event_data_t *event, int dry_run, log_debug("timer %d ", event->duration);
t_period = usec_to_timespec(event->duration); + + if (rdata->res.timer.init == 0) { + rdata->res.timer.init = 1; + clock_gettime(CLOCK_MONOTONIC, &rdata->res.timer.t_next); + } + rdata->res.timer.t_next = timespec_add(&rdata->res.timer.t_next, &t_period); clock_gettime(CLOCK_MONOTONIC, &t_now); if (timespec_lower(&t_now, &rdata->res.timer.t_next)) @@ -678,12 +684,6 @@ int main(int argc, char* argv[]) /* Sync timer resources with start time */ clock_gettime(CLOCK_MONOTONIC, &t_start);
- for (i = 0; i < nresources; i++) { - rdata = &opts.resources[i]; - if (rdata->type == rtapp_timer) - rdata->res.timer.t_next = t_start; - } - /* Start the use case */ for (i = 0; i < nthreads; i++) { tdata = &opts.threads_data[i]; diff --git a/src/rt-app_parse_config.c b/src/rt-app_parse_config.c index 2572afb..3fdf5f5 100644 --- a/src/rt-app_parse_config.c +++ b/src/rt-app_parse_config.c @@ -179,7 +179,7 @@ static int init_mutex_resource(rtapp_resource_t *data, const rtapp_options_t *op static int init_timer_resource(rtapp_resource_t *data, const rtapp_options_t *opts) { log_info(PIN3 "Init: %s timer", data->name); - clock_gettime(CLOCK_MONOTONIC, &data->res.timer.t_next); + data->res.timer.init = 0; }
static int init_cond_resource(rtapp_resource_t *data, const rtapp_options_t *opts) diff --git a/src/rt-app_types.h b/src/rt-app_types.h index cefb3a6..1075f64 100644 --- a/src/rt-app_types.h +++ b/src/rt-app_types.h @@ -83,6 +83,7 @@ struct _rtapp_signal {
struct _rtapp_timer { struct timespec t_next; + int init; };
/* Shared resources */