Sometimes we need a create load that can run in any CPU of the system for a given period of time, regardless of their compute capacity. Add a runtime event to be able to generate such a load.
Changes since v1:
- Change runtime granularity to 10usec - Reorder run and runtime in run_event() and in the tutorial.txt
Javi Merino (2): rt-parse: avoid repetition in obj_is_event() rt-app: add a runtime event
doc/tutorial.txt | 5 +++++ src/rt-app.c | 20 +++++++++++++++++ src/rt-app_parse_config.c | 57 ++++++++++++++++++++++++----------------------- src/rt-app_types.h | 1 + 4 files changed, 55 insertions(+), 28 deletions(-)
obj_is_event() is a boolean function that returns true if the name is an event. The two users of the function use it as a boolean function. The function has a lot of unnecessary copy&paste and duplication. Avoid repeating ourselves and just loop through all the events in an array. --- src/rt-app_parse_config.c | 54 +++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 28 deletions(-)
diff --git a/src/rt-app_parse_config.c b/src/rt-app_parse_config.c index af18910..99b0e5e 100644 --- a/src/rt-app_parse_config.c +++ b/src/rt-app_parse_config.c @@ -550,37 +550,35 @@ unknown_event:
}
+static char *events[] = { + "lock", + "unlock", + "wait", + "signal", + "broad", + "sync", + "sleep", + "run", + "timer", + "suspend", + "resume", + "mem", + "iorun", + NULL +}; + static int obj_is_event(char *name) { - if (!strncmp(name, "lock", strlen("lock"))) - return rtapp_mutex; - if (!strncmp(name, "unlock", strlen("unlock"))) - return rtapp_lock; - if (!strncmp(name, "wait", strlen("wait"))) - return rtapp_unlock; - if (!strncmp(name, "signal", strlen("signal"))) - return rtapp_signal; - if (!strncmp(name, "broad", strlen("broad"))) - return rtapp_broadcast; - if (!strncmp(name, "sync", strlen("sync"))) - return rtapp_sig_and_wait; - if (!strncmp(name, "sleep", strlen("sleep"))) - return rtapp_sleep; - if (!strncmp(name, "run", strlen("run"))) - return rtapp_run; - if (!strncmp(name, "timer", strlen("timer"))) - return rtapp_timer; - if (!strncmp(name, "suspend", strlen("suspend"))) - return rtapp_suspend; - if (!strncmp(name, "resume", strlen("resume"))) - return rtapp_resume; - if (!strncmp(name, "mem", strlen("mem"))) - return rtapp_mem; - if (!strncmp(name, "iorun", strlen("iorun"))) - return rtapp_iorun; - - return 0; + char **pos; + + for (pos = events; *pos; pos++) { + char *event = *pos; + if (!strncmp(name, event, strlen(event))) + return 1; + } + + return 0; }
static void
The runtime event emulates the execution of a load for a specific amount of time irrespective of the compute capacity of the CPU it is run on or the frequency. ---
Changes since v1:
- Change runtime granularity to 10usec - Reorder run and runtime in run_event() and in the tutorial.txt
doc/tutorial.txt | 5 +++++ src/rt-app.c | 20 ++++++++++++++++++++ src/rt-app_parse_config.c | 3 +++ src/rt-app_types.h | 1 + 4 files changed, 29 insertions(+)
diff --git a/doc/tutorial.txt b/doc/tutorial.txt index 6dc9a44..4435dad 100644 --- a/doc/tutorial.txt +++ b/doc/tutorial.txt @@ -210,6 +210,11 @@ complete "phases" object will be executed. The default value is -1. events are simple action that will be performed by the thread or on the thread. They have to be listed by execution order.
+* runtime : Integer. The duration is define in usec. Similar to the +run event, it emulates the execution of a load. Unlike run, runtime +runs for a specific amount of time irrespective of the compute +capacity of the CPU or the frequency. + * run : Integer. Emulate the execution of a load. The duration is defined in usec but the run event will effectively run a number of time a loop that waste cpu cycles. When the run event is executed, the duration is transformed in a diff --git a/src/rt-app.c b/src/rt-app.c index 679d39a..5a6f4f3 100644 --- a/src/rt-app.c +++ b/src/rt-app.c @@ -263,6 +263,26 @@ static int run_event(event_data_t *event, int dry_run, nanosleep(&sleep, NULL); } break; + case rtapp_runtime: + { + struct timespec t_start, t_end; + int64_t diff_ns; + + log_debug("runtime %d ", event->duration); + clock_gettime(CLOCK_MONOTONIC, &t_start); + + do { + /* Do work for 10usec */ + *perf += loadwait(10); + + clock_gettime(CLOCK_MONOTONIC, &t_end); + diff_ns = timespec_sub_to_ns(&t_end, &t_start); + } while ((diff_ns / 1000) < event->duration); + + t_end = timespec_sub(&t_end, &t_start); + *duration += timespec_to_usec(&t_end); + } + break; case rtapp_run: { struct timespec t_start, t_end; diff --git a/src/rt-app_parse_config.c b/src/rt-app_parse_config.c index 99b0e5e..c59b562 100644 --- a/src/rt-app_parse_config.c +++ b/src/rt-app_parse_config.c @@ -348,6 +348,8 @@ parse_thread_event_data(char *name, struct json_object *obj,
if (!strncmp(name, "sleep", strlen("sleep"))) data->type = rtapp_sleep; + else if (!strncmp(name, "runtime", strlen("runtime"))) + data->type = rtapp_runtime; else data->type = rtapp_run;
@@ -558,6 +560,7 @@ static char *events[] = { "broad", "sync", "sleep", + "runtime", "run", "timer", "suspend", diff --git a/src/rt-app_types.h b/src/rt-app_types.h index 2ce9c9d..57fb80d 100644 --- a/src/rt-app_types.h +++ b/src/rt-app_types.h @@ -67,6 +67,7 @@ typedef enum resource_t rtapp_resume, rtapp_mem, rtapp_iorun, + rtapp_runtime, } resource_t;
struct _rtapp_mutex {