Module: xenomai-forge
Branch: master
Commit: 7f78bb0bf2b8474546acb6958fb5c06b782404dd
URL:    
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=7f78bb0bf2b8474546acb6958fb5c06b782404dd

Author: Philippe Gerum <r...@xenomai.org>
Date:   Wed Jul 31 14:29:34 2013 +0200

cobalt/thread: move non-critical cleanup code out of critical section

Since the thread cleanup code can only run on behalf of the root
domain, and only from the exiting context, we may do a lot of
housekeeping locklessly.

Remove those fully private cleanups from the nklocked section, which
should help reducing the overall latency upon thread exit.

---

 include/cobalt/kernel/thread.h |    2 +-
 kernel/cobalt/pod.c            |   31 ++++++++++++++++---------------
 kernel/cobalt/shadow.c         |    2 +-
 kernel/cobalt/thread.c         |    4 +---
 4 files changed, 19 insertions(+), 20 deletions(-)

diff --git a/include/cobalt/kernel/thread.h b/include/cobalt/kernel/thread.h
index 28b4296..191c24e 100644
--- a/include/cobalt/kernel/thread.h
+++ b/include/cobalt/kernel/thread.h
@@ -324,7 +324,7 @@ void xnthread_init_shadow_tcb(struct xnthread *thread,
 
 void xnthread_init_root_tcb(struct xnthread *thread);
 
-void xnthread_cleanup(struct xnthread *thread);
+void xnthread_deregister(struct xnthread *thread);
 
 char *xnthread_format_status(unsigned long status, char *buf, int size);
 
diff --git a/kernel/cobalt/pod.c b/kernel/cobalt/pod.c
index 3fd270d..5d911af 100644
--- a/kernel/cobalt/pod.c
+++ b/kernel/cobalt/pod.c
@@ -654,9 +654,6 @@ static inline void cleanup_thread(struct xnthread *thread) 
/* nklock held, irqs
 {
        struct xnsched *sched = thread->sched;
 
-       trace_mark(xn_nucleus, thread_cleanup, "thread %p thread_name %s",
-                  thread, xnthread_name(thread));
-
        list_del(&thread->glink);
        nkpod->nrthreads--;
        xnvfile_touch_tag(&nkpod->threadlist_tag);
@@ -667,16 +664,8 @@ static inline void cleanup_thread(struct xnthread *thread) 
/* nklock held, irqs
                xnthread_clear_state(thread, XNREADY);
        }
 
-       xntimer_destroy(&thread->rtimer);
-       xntimer_destroy(&thread->ptimer);
-       xntimer_destroy(&thread->rrbtimer);
        thread->idtag = 0;
 
-       if (thread->selector) {
-               xnselector_destroy(thread->selector);
-               thread->selector = NULL;
-       }
-
        if (xnthread_test_state(thread, XNPEND))
                xnsynch_forget_sleeper(thread);
 
@@ -695,12 +684,9 @@ static inline void cleanup_thread(struct xnthread *thread) 
/* nklock held, irqs
                return;
 
        xnsched_forget(thread);
-       xnthread_cleanup(thread);
+       xnthread_deregister(thread);
        /* Finalize last since this incurs releasing the TCB. */
        xnshadow_finalize(thread);
-
-       if (xnthread_test_state(sched->curr, XNROOT))
-               xnfreesync();
 }
 
 void __xnpod_cleanup_thread(struct xnthread *thread)
@@ -708,9 +694,24 @@ void __xnpod_cleanup_thread(struct xnthread *thread)
        spl_t s;
 
        XENO_BUGON(NUCLEUS, !ipipe_root_p);
+
+       trace_mark(xn_nucleus, thread_cleanup, "thread %p thread_name %s",
+                  thread, xnthread_name(thread));
+
+       xntimer_destroy(&thread->rtimer);
+       xntimer_destroy(&thread->ptimer);
+       xntimer_destroy(&thread->rrbtimer);
+
+       if (thread->selector) {
+               xnselector_destroy(thread->selector);
+               thread->selector = NULL;
+       }
+
        xnlock_get_irqsave(&nklock, s);
        cleanup_thread(thread);
+       xnfreesync();
        xnlock_put_irqrestore(&nklock, s);
+
        wake_up(&nkjoinq);
 }
 
diff --git a/kernel/cobalt/shadow.c b/kernel/cobalt/shadow.c
index 11776ec..4d0b761 100644
--- a/kernel/cobalt/shadow.c
+++ b/kernel/cobalt/shadow.c
@@ -1025,7 +1025,7 @@ void xnshadow_finalize(struct xnthread *thread)
 {
        struct xnsys_ppd *sys_ppd;
 
-       trace_mark(xn_nucleus, shadow_unmap,
+       trace_mark(xn_nucleus, shadow_finalize,
                   "thread %p thread_name %s pid %d",
                   thread, xnthread_name(thread), xnthread_host_pid(thread));
 
diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c
index 5d268a2..4e0ae56 100644
--- a/kernel/cobalt/thread.c
+++ b/kernel/cobalt/thread.c
@@ -229,10 +229,8 @@ void xnthread_init_root_tcb(struct xnthread *thread)
        xnarch_init_root_tcb(tcb);
 }
 
-void xnthread_cleanup(struct xnthread *thread)
+void xnthread_deregister(struct xnthread *thread)
 {
-       /* Does not wreck the TCB, only releases the held resources. */
-
        if (thread->registry.handle != XN_NO_HANDLE)
                xnregistry_remove(thread->registry.handle);
 


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to