From: Vincent Guittot vincent.guittot@linaro.org
add new sleep and run type of resources
Signed-off-by: Vincent Guittot vincent.guittot@linaro.org --- src/rt-app.c | 47 +++++++++++++++++++++++++++-------------------- src/rt-app_parse_config.c | 7 ++++--- src/rt-app_types.h | 2 ++ src/rt-app_utils.c | 10 ++++++++++ 4 files changed, 43 insertions(+), 23 deletions(-)
diff --git a/src/rt-app.c b/src/rt-app.c index bf893d3..90afe7f 100644 --- a/src/rt-app.c +++ b/src/rt-app.c @@ -113,11 +113,15 @@ static inline busywait(struct timespec *to) } }
-void lock_resource(rtapp_resource_access_list_t *lock) +int get_resource(rtapp_resource_access_list_t *lock, struct timespec *usage) { + int busywait = 1; rtapp_resource_access_list_t *prev;
switch(lock->res->type) { + case rtapp_mutex: + pthread_mutex_lock(&(lock->res->res.mtx.obj)); + break; case rtapp_wait: prev = lock->prev; pthread_cond_wait(&(lock->res->res.cond.obj), &(prev->res->res.mtx.obj)); @@ -128,24 +132,25 @@ void lock_resource(rtapp_resource_access_list_t *lock) case rtapp_broadcast: pthread_cond_broadcast(lock->res->res.signal.target); break; - default: - pthread_mutex_lock(&(lock->res->res.mtx.obj)); + case rtapp_sleep: + nanosleep(usage, NULL); + busywait = 0; + break; } + + return busywait; }
-void unlock_resource(rtapp_resource_access_list_t *lock) +void put_resource(rtapp_resource_access_list_t *lock) { - switch(lock->res->type) { - case rtapp_mutex: + if (lock->res->type == rtapp_mutex) pthread_mutex_unlock(&(lock->res->res.mtx.obj)); - break; - } }
void run(int ind, struct timespec *min, struct timespec *max, rtapp_tasks_resource_list_t *blockages, int nblockages) { - int i; + int i, busywait = 1; struct timespec t_exec; rtapp_resource_access_list_t *lock, *last;
@@ -153,7 +158,7 @@ void run(int ind, struct timespec *min, struct timespec *max,
for (i = 0; i < nblockages; i++) { - /* Lock resources */ + /* Lock resources sequence including the busy wait */ lock = blockages[i].acl; while (lock != NULL) { log_debug("[%d] locking %d", ind, lock->res->index); @@ -161,19 +166,21 @@ void run(int ind, struct timespec *min, struct timespec *max, log_ftrace(ft_data.marker_fd, "[%d] locking %d", ind, lock->res->index); - lock_resource(lock); + busywait = get_resource(lock, &blockages[i].usage); last = lock; lock = lock->next; }
- /* Busy wait */ - log_debug("[%d] busywait for %lu", ind, timespec_to_usec(&blockages[i].usage)); - if (opts.ftrace) - log_ftrace(ft_data.marker_fd, - "[%d] busywait for %d", - ind, timespec_to_usec(&blockages[i].usage)); - loadwait(&blockages[i].usage); - t_exec = timespec_sub(&t_exec, &blockages[i].usage); + if (busywait) { + /* Busy wait */ + log_debug("[%d] busywait for %lu", ind, timespec_to_usec(&blockages[i].usage)); + if (opts.ftrace) + log_ftrace(ft_data.marker_fd, + "[%d] busywait for %d", + ind, timespec_to_usec(&blockages[i].usage)); + loadwait(&blockages[i].usage); + t_exec = timespec_sub(&t_exec, &blockages[i].usage); + }
/* Unlock resources */ lock = last; @@ -183,7 +190,7 @@ void run(int ind, struct timespec *min, struct timespec *max, log_ftrace(ft_data.marker_fd, "[%d] unlocking %d", ind, lock->res->index); - unlock_resource(lock); + put_resource(lock); lock = lock->prev; } } diff --git a/src/rt-app_parse_config.c b/src/rt-app_parse_config.c index 003e99b..30a331c 100644 --- a/src/rt-app_parse_config.c +++ b/src/rt-app_parse_config.c @@ -205,6 +205,7 @@ parse_resource_data(char *name, struct json_object *obj, int idx, { char *type, *target; char def_type[RTAPP_RESOURCE_DESCR_LENGTH]; + int duration;
log_info(PFX "Parsing resources %s [%d]", name, idx);
@@ -223,6 +224,9 @@ parse_resource_data(char *name, struct json_object *obj, int idx, }
switch (data->type) { + case rtapp_mutex: + init_mutex_resource(data, opts); + break; case rtapp_wait: init_cond_resource(data, opts); break; @@ -231,9 +235,6 @@ parse_resource_data(char *name, struct json_object *obj, int idx, target = get_string_value_from(obj, "target", FALSE, NULL); init_signal_resource(data, opts, target); break; - default: - init_mutex_resource(data, opts); - } }
diff --git a/src/rt-app_types.h b/src/rt-app_types.h index 3ce58ee..dbec836 100644 --- a/src/rt-app_types.h +++ b/src/rt-app_types.h @@ -63,6 +63,8 @@ typedef enum resource_t rtapp_wait, rtapp_signal, rtapp_broadcast, + rtapp_sleep, + rtapp_run } resource_t;
struct _rtapp_mutex { diff --git a/src/rt-app_utils.c b/src/rt-app_utils.c index 72bca7a..c2dc60c 100644 --- a/src/rt-app_utils.c +++ b/src/rt-app_utils.c @@ -230,6 +230,10 @@ string_to_resource(const char *name, resource_t *resource) *resource = rtapp_wait; else if (strcmp(name, "broadcast") == 0) *resource = rtapp_broadcast; + else if (strcmp(name, "sleep") == 0) + *resource = rtapp_sleep; + else if (strcmp(name, "run") == 0) + *resource = rtapp_run; else return 1; return 0; @@ -251,6 +255,12 @@ resource_to_string(resource_t resource, char *resource_name) case rtapp_broadcast: strcpy(resource_name, "broadcast"); break; + case rtapp_sleep: + strcpy(resource_name, "sleep"); + break; + case rtapp_run: + strcpy(resource_name, "run"); + break; default: return 1; }