[RTAPP] add delay param in thread parameters

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

Commit Message

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

---

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              | 9 ++++++++-
 src/rt-app_parse_config.c | 5 ++++-
 src/rt-app_types.h        | 2 +-
 3 files changed, 13 insertions(+), 3 deletions(-)

Patch

diff --git a/src/rt-app.c b/src/rt-app.c
index fdde1bd..de5fe7b 100644
--- a/src/rt-app.c
+++ b/src/rt-app.c
@@ -250,7 +250,13 @@  void *thread_body(void *arg)
 		}
 	}
 
-	if (data->wait_before_start > 0) {
+	/* thread start delay */
+	if (data->delay) {
+		log_notice("[%d] delaying thread for %d usec\n",data->ind,
+				data->delay);
+		usleep(data->delay);
+	}
+	else if (data->wait_before_start > 0) {
 		log_notice("[%d] Waiting %ld usecs... ", data->ind, 
 			 data->wait_before_start);
 		clock_gettime(CLOCK_MONOTONIC, &t);
@@ -262,6 +268,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.
 	 */
diff --git a/src/rt-app_parse_config.c b/src/rt-app_parse_config.c
index f7f8056..bc8ca94 100644
--- a/src/rt-app_parse_config.c
+++ b/src/rt-app_parse_config.c
@@ -326,7 +326,7 @@  static void
 parse_thread_data(char *name, struct json_object *obj, int idx, 
 		  thread_data_t *data, const rtapp_options_t *opts)
 {
-	long exec, period, dline;
+	long exec, period, dline, delay;
 	char *policy;
 	char def_policy[RTAPP_POLICY_DESCR_LENGTH];
 	struct array_list *cpuset;
@@ -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->delay = get_int_value_from(obj, "delay", TRUE, 0);
 	
 	/* cpu set */
 	cpuset_obj = get_in_object(obj, "cpus", TRUE);
diff --git a/src/rt-app_types.h b/src/rt-app_types.h
index 30f2020..adf0b3c 100644
--- a/src/rt-app_types.h
+++ b/src/rt-app_types.h
@@ -81,7 +81,7 @@  typedef struct _thread_data_t {
 	int duration;
 	cpu_set_t *cpuset;
 	char *cpuset_str;
-	unsigned long wait_before_start;
+	unsigned long wait_before_start, delay;
 	struct timespec min_et, max_et;
 	struct timespec period, deadline;
 	struct timespec main_app_start;