From: Vincent Guittot vincent.guittot@linaro.org
The large ressources object is now optional, the reosources are declaring the 1st time they are used in a thread.
Signed-off-by: Vincent Guittot vincent.guittot@linaro.org Signed-off-by: Pi-Cheng Chen pi-cheng.chen@linaro.org --- src/rt-app.c | 19 ++++---- src/rt-app_parse_config.c | 110 ++++++++++++++++++++++++++++++++++------------ src/rt-app_types.h | 7 ++- 3 files changed, 98 insertions(+), 38 deletions(-)
diff --git a/src/rt-app.c b/src/rt-app.c index e7bade0..575dea6 100644 --- a/src/rt-app.c +++ b/src/rt-app.c @@ -176,19 +176,20 @@ static inline int loadwait(unsigned long exec) }
static int run_event(event_data_t *event, int dry_run, - unsigned long *perf, unsigned long *duration) + unsigned long *perf, unsigned long *duration, rtapp_resource_t *resources) { + rtapp_resource_t *rdata = &(resources[event->res]); unsigned long lock = 0;
switch(event->type) { case rtapp_lock: - log_debug("lock %s ", event->res->name); - pthread_mutex_lock(&(event->res->res.mtx.obj)); + log_debug("lock %s ", rdata->name); + pthread_mutex_lock(&(rdata->res.mtx.obj)); lock = 1; break; case rtapp_unlock: - log_debug("unlock %s ", event->res->name); - pthread_mutex_unlock(&(event->res->res.mtx.obj)); + log_debug("unlock %s ", rdata->name); + pthread_mutex_unlock(&(rdata->res.mtx.obj)); lock = -1; break; } @@ -222,7 +223,8 @@ static int run_event(event_data_t *event, int dry_run, }
int run(int ind, event_data_t *events, - int nbevents, unsigned long *duration) + int nbevents, unsigned long *duration, + rtapp_resource_t *resources) { int i, lock = 0; unsigned long perf = 0; @@ -237,7 +239,7 @@ int run(int ind, event_data_t *events, log_ftrace(ft_data.marker_fd, "[%d] locking %d", ind, events[i].type); - lock += run_event(&events[i], !continue_running, &perf, duration); + lock += run_event(&events[i], !continue_running, &perf, duration, resources); }
return perf; @@ -249,6 +251,7 @@ shutdown(int sig) int i; // notify threads, join them, then exit continue_running = 0; + for (i = 0; i < nthreads; i++) { pthread_join(threads[i], NULL); @@ -435,7 +438,7 @@ void *thread_body(void *arg) log_debug("[%d] begins loop %d phase %d step %d", data->ind, i, j, loop);;
clock_gettime(CLOCK_MONOTONIC, &t_start); - perf = run(data->ind, pdata->events, pdata->nbevents, &duration); + perf = run(data->ind, pdata->events, pdata->nbevents, &duration, *(data->resources)); clock_gettime(CLOCK_MONOTONIC, &t_end);
if (timings) diff --git a/src/rt-app_parse_config.c b/src/rt-app_parse_config.c index 1f4c2db..6834b65 100644 --- a/src/rt-app_parse_config.c +++ b/src/rt-app_parse_config.c @@ -24,6 +24,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #define PFL " "PFX #define PIN PFX" " #define PIN2 PIN" " +#define PIN3 PIN2" " #define JSON_FILE_BUF_SIZE 4096
/* redefine foreach as in <json/json_object.h> but to be ANSI @@ -162,7 +163,7 @@ get_string_value_from(struct json_object *where,
static int init_mutex_resource(rtapp_resource_t *data, const rtapp_options_t *opts) { - log_info(PIN "Init: %s mutex", data->name); + log_info(PIN3 "Init: %s mutex", data->name);
pthread_mutexattr_init(&data->res.mtx.attr); if (opts->pi_enabled) { @@ -175,6 +176,24 @@ static int init_mutex_resource(rtapp_resource_t *data, const rtapp_options_t *op }
static void +init_resource_data(const char *name, int type, int idx, const rtapp_options_t *opts) +{ + rtapp_resource_t *data = &(opts->resources[idx]); + char *target; + + /* common and defaults */ + data->index = idx; + data->name = strdup(name); + data->type = type; + + switch (data->type) { + case rtapp_mutex: + init_mutex_resource(data, opts); + break; + } +} + +static void parse_resource_data(char *name, struct json_object *obj, int idx, rtapp_resource_t *data, const rtapp_options_t *opts) { @@ -183,10 +202,6 @@ parse_resource_data(char *name, struct json_object *obj, int idx,
log_info(PFX "Parsing resources %s [%d]", name, idx);
- /* common and defaults */ - data->index = idx; - data->name = strdup(name); - /* resource type */ resource_to_string(0, def_type); type = get_string_value_from(obj, "type", TRUE, def_type); @@ -197,8 +212,24 @@ parse_resource_data(char *name, struct json_object *obj, int idx, } }
- if (data->type == rtapp_mutex) - init_mutex_resource(data, opts); + init_resource_data(name, data->type, idx, opts); +} + +static int +add_resource_data(const char *name, int type, rtapp_options_t *opts) +{ + int idx; + + idx = opts->nresources; + + log_info(PIN2 "Add new resource %s [%d] type %d", name, idx, type); + + opts->nresources++; + opts->resources = realloc(opts->resources, sizeof(rtapp_resource_t) * opts->nresources); + + init_resource_data(name, type, idx, opts); + + return idx; }
static void @@ -209,6 +240,11 @@ parse_resources(struct json_object *resources, rtapp_options_t *opts)
log_info(PFX "Parsing resource section");
+ if (!resources) { + log_info(PFX "No resource section Found"); + return; + } + if (json_object_is_type(resources, json_type_object)) { opts->nresources = 0; foreach(resources, entry, key, val, idx) { @@ -224,24 +260,32 @@ parse_resources(struct json_object *resources, rtapp_options_t *opts) } }
-static int get_resource_index(const char *name, rtapp_resource_t *resources) +static int get_resource_index(const char *name, int type, rtapp_options_t *opts) { - int i=0; + rtapp_resource_t *resources = opts->resources; + int nresources = opts->nresources; + int i = 0;
- while (strcmp(resources[i].name, name) != 0) + while ((i < nresources) && ((strcmp(resources[i].name, name) != 0) || (resources[i].type != type))) i++;
+ if (i >= nresources) + i = add_resource_data(name, type, opts); + return i; }
static void parse_thread_event_data(char *name, struct json_object *obj, - event_data_t *data, const rtapp_options_t *opts) + event_data_t *data, rtapp_options_t *opts) { + rtapp_resource_t *rdata, *ddata; + const char *ref; int i;
if (!strncmp(name, "run", strlen("run")) || !strncmp(name, "sleep", strlen("sleep"))) { + if (!json_object_is_type(obj, json_type_int)) goto unknown_event;
@@ -258,50 +302,55 @@ parse_thread_event_data(char *name, struct json_object *obj,
if (!strncmp(name, "lock", strlen("lock")) || !strncmp(name, "unlock", strlen("unlock"))) { + if (!json_object_is_type(obj, json_type_string)) goto unknown_event;
- i = get_resource_index(json_object_get_string(obj), - opts->resources); + ref = json_object_get_string(obj); + i = get_resource_index(ref, rtapp_mutex, opts);
- if (i >= opts->nresources) - goto unknown_event; - - data->res = &opts->resources[i]; + data->res = i;
if (!strncmp(name, "lock", strlen("lock"))) data->type = rtapp_lock; else data->type = rtapp_unlock;
- log_info(PIN2 "type %d target %s", data->type, data->res->name); + rdata = &(opts->resources[data->res]); + ddata = &(opts->resources[data->dep]); + + log_info(PIN2 "type %d target %s [%d]", data->type, rdata->name, rdata->index); return; }
+unknown_resource: + log_error(PIN2 "Resource %s not found in the resource section !!!", ref); + log_error(PIN2 "Please check the resource name or the resource section"); + unknown_event: data->duration = 0; data->type = rtapp_run; - log_info(PIN2 "unknown type %d duration %d", data->type, data->duration); + log_error(PIN2 "Unknown or mismatch %s event type !!!", name); }
static int obj_is_event(char *name) { if (!strncmp(name, "lock", strlen("lock"))) - return 1; + return rtapp_mutex; if (!strncmp(name, "unlock", strlen("unlock"))) - return 1; + return rtapp_lock; if (!strncmp(name, "sleep", strlen("sleep"))) - return 1; + return rtapp_sleep; if (!strncmp(name, "run", strlen("run"))) - return 1; + return rtapp_run;
return 0; }
static void parse_thread_phase_data(struct json_object *obj, phase_data_t *data, - const rtapp_options_t *opts) + rtapp_options_t *opts) { /* used in the foreach macro */ struct lh_entry *entry; char *key; struct json_object *val; int idx; @@ -336,7 +385,7 @@ parse_thread_phase_data(struct json_object *obj, phase_data_t *data,
static void parse_thread_data(char *name, struct json_object *obj, int index, - thread_data_t *data, const rtapp_options_t *opts) + thread_data_t *data, rtapp_options_t *opts) { long exec, period, dline; char *policy; @@ -348,6 +397,7 @@ parse_thread_data(char *name, struct json_object *obj, int index, log_info(PFX "Parsing thread %s [%d]", name, index);
/* common and defaults */ + data->resources = &opts->resources; data->ind = index; data->name = strdup(name); data->lock_pages = opts->lock_pages; @@ -449,6 +499,7 @@ parse_global(struct json_object *global, rtapp_options_t *opts) log_info(PFX "Parsing global section");
if (!global) { + log_info(PFX " No global section Found: Use default value"); opts->duration = -1; opts->gnuplot = 0; opts->policy = other; @@ -520,16 +571,19 @@ get_opts_from_json_object(struct json_object *root, rtapp_options_t *opts) log_info(PFX "root : %s", json_object_to_json_string(root));
global = get_in_object(root, "global", TRUE); - log_info(PFX "global : %s", json_object_to_json_string(global)); + if (global) + log_info(PFX "global : %s", json_object_to_json_string(global));
tasks = get_in_object(root, "tasks", FALSE); log_info(PFX "tasks : %s", json_object_to_json_string(tasks));
- resources = get_in_object(root, "resources", FALSE); - log_info(PFX "resources: %s", json_object_to_json_string(resources)); + resources = get_in_object(root, "resources", TRUE); + if (resources) + log_info(PFX "resources: %s", json_object_to_json_string(resources));
parse_global(global, opts); json_object_put(global); + log_info(PFX "Parsing resources"); parse_resources(resources, opts); json_object_put(resources); parse_tasks(tasks, opts); diff --git a/src/rt-app_types.h b/src/rt-app_types.h index aeea37d..3ddd7fd 100644 --- a/src/rt-app_types.h +++ b/src/rt-app_types.h @@ -59,7 +59,8 @@ typedef enum policy_t
typedef enum resource_t { - rtapp_mutex = 0, + rtapp_unknown = 0, + rtapp_mutex, rtapp_sleep, rtapp_run, rtapp_lock, @@ -83,7 +84,8 @@ typedef struct _rtapp_resource_t {
typedef struct _event_data_t { resource_t type; - rtapp_resource_t *res; + int res; + int dep; int duration; int count; } event_data_t; @@ -99,6 +101,7 @@ typedef struct _thread_data_t { char *name; int lock_pages; int duration; + rtapp_resource_t **resources; cpu_set_t *cpuset; char *cpuset_str; struct timespec main_app_start;