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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Wed Oct 27 17:42:05 2010 +0200

nucleus: clear kthread stack while setting its TCB

Zero the stack space allocated for a kthread while initializing its
control block, so that xnarch_init_thread() may assume it gets clean
memory.

Zeroing such memory in xnthread_init() is better for latency, since it
runs with hw interrupts enabled, unlike xnarch_init_thread().

---

 include/asm-powerpc/bits/pod.h |    6 +++++-
 ksrc/nucleus/thread.c          |   10 +++++++---
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/include/asm-powerpc/bits/pod.h b/include/asm-powerpc/bits/pod.h
index fffa91f..f800391 100644
--- a/include/asm-powerpc/bits/pod.h
+++ b/include/asm-powerpc/bits/pod.h
@@ -180,10 +180,14 @@ static inline void xnarch_init_thread(xnarchtcb_t * tcb,
        struct pt_regs *childregs;
        unsigned long sp;
 
+       /*
+        * Stack space is guaranteed to have been fully zeroed. We do
+        * this earlier in xnthread_init() which runs with interrupts
+        * on, to reduce latency.
+        */
        sp = (unsigned long)tcb->stackbase + tcb->stacksize;
        sp -= sizeof(struct pt_regs);
        childregs = (struct pt_regs *)sp;
-       memset(childregs, 0, sizeof(*childregs));
        sp -= STACK_FRAME_OVERHEAD;
 
        tcb->ts.ksp = sp;
diff --git a/ksrc/nucleus/thread.c b/ksrc/nucleus/thread.c
index ac38144..54b0796 100644
--- a/ksrc/nucleus/thread.c
+++ b/ksrc/nucleus/thread.c
@@ -52,10 +52,12 @@ int xnthread_init(struct xnthread *thread,
 {
        unsigned int stacksize = attr->stacksize;
        xnflags_t flags = attr->flags;
+       struct xnarchtcb *tcb;
        int ret;
 
        /* Setup the TCB. */
-       xnarch_init_tcb(xnthread_archtcb(thread));
+       tcb = xnthread_archtcb(thread);
+       xnarch_init_tcb(tcb);
 
        flags &= ~XNSUSP;
 #ifndef CONFIG_XENO_HW_FPU
@@ -87,13 +89,15 @@ int xnthread_init(struct xnthread *thread,
        }
 #endif
 #else
-       ret = xnarch_alloc_stack(xnthread_archtcb(thread), stacksize);
+       ret = xnarch_alloc_stack(tcb, stacksize);
        if (ret) {
                xnlogerr("%s: no stack for kernel thread '%s' (raise 
CONFIG_XENO_OPT_SYS_STACKPOOLSZ)\n",
                         __FUNCTION__, attr->name);
                return ret;
        }
 #endif
+       if (stacksize)
+               memset(xnarch_stack_base(tcb), 0, stacksize);
 
        if (attr->name)
                xnobject_copy_name(thread->name, attr->name);
@@ -172,7 +176,7 @@ int xnthread_init(struct xnthread *thread,
 
 fail:
 #if CONFIG_XENO_OPT_SYS_STACKPOOLSZ > 0
-       xnarch_free_stack(xnthread_archtcb(thread));
+       xnarch_free_stack(tcb);
 #endif
        return ret;
 }


_______________________________________________
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git

Reply via email to