Skip to contentSkip to conversation

Xenomai-forge thread_obj: unset __THREAD_S_SAFE when not needed

PATCH Superseded Kim De Mey 1 participant 4 messages Oct 21, 2013

lore
Share & tools
lore

Kim De Mey

author
#0 lore raw

PATCH v2 1/1 Xenomai-forge thread_obj: unset __THREAD_S_SAFE when not needed

Adjusted patches after feedback & suggestions:

PATCH 1: Setting the __THREAD_S_SAFE for thobj->status is done later only when necessary.

PATCH 2: Add warning when pipe() system call fails + assert on return value of notifier_init().

PATCH 3: Extends task-9 with 3 more test loops (of which two make the error that PATCH 1 solves occur).

 lib/copperplate/notifier.c  |   5 ++++-
 lib/copperplate/threadobj.c |   6 ++++--
 lib/psos/testsuite/task-9.c |  38 ++++++++++++++++++++++++++++++++++++--
 3 files changed, 44 insertions(+), 5 deletions(-)
author
#1 lore raw

PATCH v2 1/1 Xenomai-forge thread_obj: Do not set __THREAD_S_SAFE when not needed

Do not set __THREAD_S_SAFE for thobj->status when the priority of the task is lower than the priority of the current task.

---

 lib/copperplate/threadobj.c |  3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
lib/copperplate/threadobj.c +2 -1
@@ -926,7 +926,7 @@ int threadobj_start(struct threadobj *th
 	if (thobj->status & __THREAD_S_STARTED)
 		return 0;
 
-	thobj->status |= __THREAD_S_STARTED|__THREAD_S_SAFE;
+	thobj->status |= __THREAD_S_STARTED;
 	__RT(pthread_cond_signal(&thobj->barrier));
 
 	if (current && thobj->priority <= current->priority)
@@ -943,6 +943,7 @@ int threadobj_start(struct threadobj *th
 	 */
 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate);
 
+	thobj->status |= __THREAD_S_SAFE;
 	wait_on_barrier(thobj, __THREAD_S_ACTIVE);
 	thobj->status &= ~__THREAD_S_SAFE;
 
author
#2 lore raw

PATCH v2 1/1 Xenomai-forge notifier_init: warning on failed pipe

In reply to Kim De Mey

Give a warning if one of the pipe() system calls fails. To indicate that there is an underlying problem. Also add an assert on the notifier_init return value in threadobj_setup_coresp.

---

 lib/copperplate/notifier.c  |  5 ++++-
 lib/copperplate/threadobj.c |  3 ++-
 2 files changed, 6 insertions(+), 2 deletions(-)
lib/copperplate/notifier.c +4 -1
@@ -143,10 +143,13 @@ int notifier_init(struct notifier *nf,
 	sigset_t oset;
 	int fd;
 
-	if (pipe(nf->psfd) < 0)
+	if (pipe(nf->psfd) < 0) {
+		warning("failed to create file descriptors");
 		return __bt(-errno);
+	}
 
 	if (pipe(nf->pwfd) < 0) {
+		warning("failed to create file descriptors");
 		__STD(close(nf->psfd[0]));
 		__STD(close(nf->psfd[1]));
 		return __bt(-errno);
lib/copperplate/threadobj.c +2 -1
@@ -449,7 +449,8 @@ static inline int threadobj_setup_coresp
 	int ret;
 
 	prctl(PR_SET_NAME, (unsigned long)thobj->name, 0, 0, 0);
-	notifier_init(&thobj->core.notifier, notifier_callback, 1);
+	ret = notifier_init(&thobj->core.notifier, notifier_callback, 1);
+	assert(ret == 0);
 	thobj->core.period = 0;
 
 	/*
author
#3 lore raw

PATCH v2 1/1 Xenomai-forge extend psos testsuite task-9

In reply to Kim De Mey

Extend the task-9 test with different root task priorities and with both incrementing and decrementing priorities for the test tasks.

---

 lib/psos/testsuite/task-9.c |  38 ++++++++++++++++++++++++++++++++++++--
 1 files changed, 36 insertions(+), 2 deletions(-)
lib/psos/testsuite/task-9.c +36 -2
@@ -14,7 +14,7 @@ static void test_task(u_long a0, u_long 
 	traceobj_exit(&trobj);
 }
 
-static void root_task(u_long a0, u_long a1, u_long a2, u_long a3)
+static void root_task(u_long increment, u_long a1, u_long a2, u_long a3)
 {
 	u_long args[] = { 1, 2, 3, 4 }, ret, tid;
 	int n;
@@ -22,7 +22,10 @@ static void root_task(u_long a0, u_long 
 	traceobj_enter(&trobj);
 
 	for (n = 0; n < 512; n++) {
-		ret = t_create ("TEST", (n % MAX_PRIO) + 2,100000, 0, 0, &tid);
+		if(increment)
+			ret = t_create ("TEST", (n % MAX_PRIO) + 2,100000, 0, 0, &tid);
+		else
+			ret = t_create ("TEST", MAX_PRIO - (n % MAX_PRIO) + 1,100000, 0, 0, &tid);
 		traceobj_assert(&trobj, ret == SUCCESS);
 		ret = t_start(tid, T_PREEMPT, test_task, args);
 		traceobj_assert(&trobj, ret == SUCCESS);
@@ -39,6 +42,7 @@ int main(int argc, char *const argv[])
 
 	traceobj_init(&trobj, argv[0], 0);
 
+	// Low priority root task, loop incr. priority test tasks
 	ret = t_create("root", 3, 0, 0, 0, &tid);
 	traceobj_assert(&trobj, ret == SUCCESS);
 
@@ -47,5 +51,35 @@ int main(int argc, char *const argv[])
 
 	traceobj_join(&trobj);
 
+	// Low priority root task, loop decr. priority test tasks
+	args[0] = 0;
+	ret = t_create("root", 3, 0, 0, 0, &tid);
+	traceobj_assert(&trobj, ret == SUCCESS);
+
+	ret = t_start(tid, 0, root_task, args);
+	traceobj_assert(&trobj, ret == SUCCESS);
+
+	traceobj_join(&trobj);
+
+	// High priority root task, loop incr. priority test tasks
+	args[0] = 1;
+	ret = t_create("root", 90, 0, 0, 0, &tid);
+	traceobj_assert(&trobj, ret == SUCCESS);
+
+	ret = t_start(tid, 0, root_task, args);
+	traceobj_assert(&trobj, ret == SUCCESS);
+
+	traceobj_join(&trobj);
+
+	// High priority root task, loop decr. priority test tasks 
+	args[0] = 0;
+	ret = t_create("root", 90, 0, 0, 0, &tid);
+	traceobj_assert(&trobj, ret == SUCCESS);
+
+	ret = t_start(tid, 0, root_task, args);
+	traceobj_assert(&trobj, ret == SUCCESS);
+	
+	traceobj_join(&trobj);
+
 	exit(0);
 }