[RTAPP,V4] add delay param in thread parameters

Message ID 1403530098-18333-1-git-send-email-sanjay.rawat@linaro.org
State New
Headers show

Commit Message

Sanjay Singh Rawat June 23, 2014, 1:28 p.m.
to start thread after a certain amount of time, add delay option
in the json file in microseconds

---
V4: remove multiple setting of wait_before_start

V3: make use of wait_before_start to store the delay param specified
    in task property

V2: this is an update on the previous patch, handling the comments

- make delay as usec instead of using the nano sec structure
- make thread delay & spacing mutually exclusive

this patch is based on 17be4548
---
 src/rt-app.c              | 6 +++---
 src/rt-app_parse_config.c | 3 +++
 2 files changed, 6 insertions(+), 3 deletions(-)

Patch

diff --git a/src/rt-app.c b/src/rt-app.c
index fdde1bd..6682fe2 100644
--- a/src/rt-app.c
+++ b/src/rt-app.c
@@ -262,6 +262,7 @@  void *thread_body(void *arg)
 				NULL);
 		log_notice("[%d] Starting...", data->ind);
 	}
+
 	/* if we know the duration we can calculate how many periods we will
 	 * do at most, and the log to memory, instead of logging to file.
 	 */
@@ -457,15 +458,14 @@  int main(int argc, char* argv[])
 	for (i = 0; i < nthreads; i++)
 	{
 		tdata = &opts.threads_data[i];
-		if (opts.spacing > 0 ) {
+		if (!tdata->wait_before_start && (opts.spacing > 0)) {
 			/* start the thread, then it will sleep accordingly
 			 * to its position. We don't sleep here anymore as 
 			 * this would mean that 
 			 * duration = spacing * nthreads + duration */
 			tdata->wait_before_start = opts.spacing * (i+1);
-		} else {
-			tdata->wait_before_start = 0;
 		}
+
 		tdata->duration = opts.duration;
 		tdata->main_app_start = t_start;
 		tdata->lock_pages = opts.lock_pages;
diff --git a/src/rt-app_parse_config.c b/src/rt-app_parse_config.c
index f7f8056..2e9e121 100644
--- a/src/rt-app_parse_config.c
+++ b/src/rt-app_parse_config.c
@@ -389,6 +389,9 @@  parse_thread_data(char *name, struct json_object *obj, int idx,
 		exit(EXIT_INV_CONFIG);
 	}
 	data->deadline = usec_to_timespec(dline);
+
+	/* delay */
+	data->wait_before_start = get_int_value_from(obj, "delay", TRUE, 0);
 	
 	/* cpu set */
 	cpuset_obj = get_in_object(obj, "cpus", TRUE);