summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Guittot <vincent.guittot@linaro.org>2015-03-06 13:08:52 +0100
committerVincent Guittot <vincent.guittot@linaro.org>2015-03-24 11:42:40 +0100
commit715dd333d0f9602a755cdf8fbe1ac52f42477b0d (patch)
treea3d0bf505d5125ec4252706a7b837d20a06f89bd
parentd34808fa17a956bd10581992c37bbccc8002a348 (diff)
rt-app: fix timer init
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>
-rw-r--r--src/rt-app.c12
-rw-r--r--src/rt-app_parse_config.c2
-rw-r--r--src/rt-app_types.h1
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 */