Module: xenomai-forge
Branch: next
Commit: 734b2473d5ab45afddb052dc995b416bbce8afa4
URL:    
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=734b2473d5ab45afddb052dc995b416bbce8afa4

Author: Philippe Gerum <r...@xenomai.org>
Date:   Wed Jul  3 16:09:33 2013 +0200

include/asm-generic/stack.h: stack-related helpers belong to userland

---

 include/cobalt/asm-generic/Makefile.am |    1 -
 include/cobalt/asm-generic/Makefile.in |    1 -
 include/cobalt/asm-generic/stack.h     |   34 --------------------------------
 lib/cobalt/init.c                      |   15 ++-----------
 lib/cobalt/internal.c                  |   18 ++++++++++++++++
 lib/cobalt/internal.h                  |    5 +++-
 lib/cobalt/printf.c                    |    1 -
 lib/cobalt/thread.c                    |   13 +++++++++--
 testsuite/switchtest/Makefile.am       |    6 ++--
 testsuite/switchtest/Makefile.in       |    4 +-
 testsuite/switchtest/switchtest.c      |   13 ++---------
 testsuite/unit/cond-torture.c          |    2 -
 testsuite/unit/mutex-torture.c         |    6 +----
 13 files changed, 44 insertions(+), 75 deletions(-)

diff --git a/include/cobalt/asm-generic/Makefile.am 
b/include/cobalt/asm-generic/Makefile.am
index cff1c94..4a57452 100644
--- a/include/cobalt/asm-generic/Makefile.am
+++ b/include/cobalt/asm-generic/Makefile.am
@@ -6,7 +6,6 @@ includesub_HEADERS =    \
        machine.h       \
        mayday.h        \
        pci_ids.h       \
-       stack.h         \
        syscall.h       \
        thread.h        \
        wrappers.h
diff --git a/include/cobalt/asm-generic/Makefile.in 
b/include/cobalt/asm-generic/Makefile.in
index 7655bb6..2fdc584 100644
--- a/include/cobalt/asm-generic/Makefile.in
+++ b/include/cobalt/asm-generic/Makefile.in
@@ -317,7 +317,6 @@ includesub_HEADERS = \
        machine.h       \
        mayday.h        \
        pci_ids.h       \
-       stack.h         \
        syscall.h       \
        thread.h        \
        wrappers.h
diff --git a/include/cobalt/asm-generic/stack.h 
b/include/cobalt/asm-generic/stack.h
deleted file mode 100644
index f863df6..0000000
--- a/include/cobalt/asm-generic/stack.h
+++ /dev/null
@@ -1,34 +0,0 @@
-#ifndef STACKSIZE_H
-#define STACKSIZE_H
-
-#include <stdint.h>
-#include <limits.h>
-#include <unistd.h>
-#include <pthread.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-
-static inline unsigned cobalt_get_stacksize(unsigned size)
-{
-       static const unsigned default_size = __WORDSIZE * 1024;
-       static unsigned min_size;
-       if (!min_size)
-               min_size = PTHREAD_STACK_MIN + getpagesize();
-
-       if (!size)
-               size = default_size;
-       if (size < min_size)
-               size = min_size;
-
-       return size;
-}
-
-void cobalt_prefault_stack(void);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
-#endif /* STACKSIZE_H */
diff --git a/lib/cobalt/init.c b/lib/cobalt/init.c
index 66c075d..f13f7e7 100644
--- a/lib/cobalt/init.c
+++ b/lib/cobalt/init.c
@@ -25,7 +25,6 @@
 #include <signal.h>
 #include <limits.h>
 #include <unistd.h>
-#include <asm-generic/xenomai/stack.h>
 #include <cobalt/uapi/sys/heap.h>
 #include <cobalt/uapi/rtdm/syscall.h>
 #include <cobalt/ticks.h>
@@ -38,14 +37,14 @@ int __cobalt_muxid = -1;
 
 struct sigaction __cobalt_orig_sigdebug;
 
+pthread_t __cobalt_main_tid;
+
 int __rtdm_muxid = -1;
 
 int __rtdm_fd_start = INT_MAX;
 
 static int fork_handler_registered;
 
-static pthread_t main_tid;
-
 static void sigill_handler(int sig)
 {
        const char m[] = "Xenomai disabled in kernel?\n";
@@ -53,14 +52,6 @@ static void sigill_handler(int sig)
        exit(EXIT_FAILURE);
 }
 
-void cobalt_prefault_stack(void)
-{
-       if (pthread_self() == main_tid) {
-               char stk[cobalt_get_stacksize(1)];
-               stk[0] = stk[sizeof(stk) - 1] = 0xA5;
-       }
-}
-
 static int bind_interface(void)
 {
        sighandler_t old_sigill_handler;
@@ -124,7 +115,7 @@ static int bind_interface(void)
 
        cobalt_init_current_keys();
 
-       main_tid = pthread_self();
+       __cobalt_main_tid = pthread_self();
 
        cobalt_ticks_init(sysinfo.clockfreq);
 
diff --git a/lib/cobalt/internal.c b/lib/cobalt/internal.c
index c9b1bdd..feacab2 100644
--- a/lib/cobalt/internal.c
+++ b/lib/cobalt/internal.c
@@ -23,6 +23,7 @@
 #include <sys/types.h>
 #include <stddef.h>
 #include <stdlib.h>
+#include <limits.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <signal.h>
@@ -59,6 +60,23 @@ void ___cobalt_prefault(void *p, size_t len)
        } while (_p < end);
 }
 
+size_t cobalt_get_stacksize(size_t size)
+{
+       static const size_t default_size = __WORDSIZE * 1024;
+       static size_t min_size;
+
+       if (min_size == 0)
+               min_size = PTHREAD_STACK_MIN + getpagesize();
+
+       if (size == 0)
+               size = default_size;
+
+       if (size < min_size)
+               size = min_size;
+
+       return size;
+}
+
 static inline
 struct cobalt_monitor_data *get_monitor_data(cobalt_monitor_t *mon)
 {
diff --git a/lib/cobalt/internal.h b/lib/cobalt/internal.h
index eec4f91..b7534ad 100644
--- a/lib/cobalt/internal.h
+++ b/lib/cobalt/internal.h
@@ -38,8 +38,9 @@ static inline atomic_long_t *mutex_get_ownerp(struct 
__shadow_mutex *shadow)
        return &mutex_get_datp(shadow)->owner;
 }
 
-void ___cobalt_prefault(void *p, size_t len);
+size_t cobalt_get_stacksize(size_t size);
 
+void ___cobalt_prefault(void *p, size_t len);
 #define __cobalt_prefault(p) ___cobalt_prefault(p, sizeof(*p))
 
 void __cobalt_thread_harden(void);
@@ -109,6 +110,8 @@ struct xnfeatinfo;
 
 void cobalt_check_features(struct xnfeatinfo *finfo);
 
+extern pthread_t __cobalt_main_tid;
+
 extern struct sigaction __cobalt_orig_sigdebug;
 
 extern int __cobalt_muxid;
diff --git a/lib/cobalt/printf.c b/lib/cobalt/printf.c
index 25f9ba6..d48ec6a 100644
--- a/lib/cobalt/printf.c
+++ b/lib/cobalt/printf.c
@@ -28,7 +28,6 @@
 #include <syslog.h>
 #include <rtdk.h>
 #include <nocore/atomic.h>
-#include <asm-generic/stack.h>
 #include "current.h"
 #include "internal.h"
 
diff --git a/lib/cobalt/thread.c b/lib/cobalt/thread.c
index f92b439..f44eb3a 100644
--- a/lib/cobalt/thread.c
+++ b/lib/cobalt/thread.c
@@ -25,7 +25,6 @@
 #include <pthread.h>
 #include <sys/types.h>
 #include <semaphore.h>
-#include <asm-generic/stack.h>
 #include <asm/sysdeps/syscall.h>
 #include "current.h"
 #include "internal.h"
@@ -34,6 +33,14 @@ static pthread_attr_ex_t default_attr_ex;
 
 static int linuxthreads;
 
+static void prefault_stack(void)
+{
+       if (pthread_self() == __cobalt_main_tid) {
+               char stk[cobalt_get_stacksize(1)];
+               __cobalt_prefault(stk);
+       }
+}
+
 static int libc_setschedparam(pthread_t thread,
                              int policy_ex, const struct sched_param_ex 
*param_ex)
 {
@@ -98,7 +105,7 @@ int pthread_setschedparam_ex(pthread_t thread,
                                 &u_winoff, &promoted);
 
        if (ret == 0 && promoted) {
-               cobalt_prefault_stack();
+               prefault_stack();
                cobalt_sigshadow_install_once();
                cobalt_set_current();
                cobalt_set_current_window(u_winoff);
@@ -215,7 +222,7 @@ static void *__pthread_trampoline(void *p)
        long ret;
 
        cobalt_sigshadow_install_once();
-       cobalt_prefault_stack();
+       prefault_stack();
 
        param_ex = iargs->param_ex;
        policy = iargs->policy;
diff --git a/testsuite/switchtest/Makefile.am b/testsuite/switchtest/Makefile.am
index 9507176..9992ba5 100644
--- a/testsuite/switchtest/Makefile.am
+++ b/testsuite/switchtest/Makefile.am
@@ -6,9 +6,9 @@ test_PROGRAMS = switchtest
 
 switchtest_SOURCES = switchtest.c
 
-switchtest_CPPFLAGS =                  \
-       $(XENO_USER_CFLAGS)             \
-       -I$(top_srcdir)/include         \
+switchtest_CPPFLAGS =          \
+       $(XENO_USER_CFLAGS)     \
+       -I$(top_srcdir)/include \
        -Wno-missing-prototypes 
 
 switchtest_LDFLAGS =  $(XENO_POSIX_WRAPPERS)
diff --git a/testsuite/switchtest/Makefile.in b/testsuite/switchtest/Makefile.in
index d42ba03..9fa6753 100644
--- a/testsuite/switchtest/Makefile.in
+++ b/testsuite/switchtest/Makefile.in
@@ -268,8 +268,8 @@ testdir = @XENO_TEST_DIR@
 CCLD = $(top_srcdir)/scripts/wrap-link.sh $(CC)
 switchtest_SOURCES = switchtest.c
 switchtest_CPPFLAGS = \
-       $(XENO_USER_CFLAGS)             \
-       -I$(top_srcdir)/include         \
+       $(XENO_USER_CFLAGS)     \
+       -I$(top_srcdir)/include \
        -Wno-missing-prototypes 
 
 switchtest_LDFLAGS = $(XENO_POSIX_WRAPPERS)
diff --git a/testsuite/switchtest/switchtest.c 
b/testsuite/switchtest/switchtest.c
index 2d1485f..3604dfb 100644
--- a/testsuite/switchtest/switchtest.c
+++ b/testsuite/switchtest/switchtest.c
@@ -4,7 +4,6 @@
 #include <stdlib.h>
 #include <string.h>
 #include <limits.h>
-
 #include <sched.h>
 #include <signal.h>
 #include <unistd.h>
@@ -12,12 +11,9 @@
 #include <sys/mman.h>
 #include <semaphore.h>
 #include <setjmp.h>
-
 #include <getopt.h>
-
 #include <xeno_config.h>
 #include <asm/xenomai/fptest.h>
-#include <asm-generic/stack.h>
 #include <cobalt/trace.h>
 #include <rtdm/rttesting.h>
 
@@ -44,9 +40,6 @@ typedef unsigned long cpu_set_t;
 #define smp_sched_setaffinity(pid,len,mask) 0
 #endif /* !CONFIG_SMP */
 
-#define SMALL_STACK_MIN cobalt_get_stacksize(32 * 1024)
-#define LARGE_STACK_MIN cobalt_get_stacksize(64 * 1024)
-
 /* Thread type. */
 typedef enum {
        SLEEPER = 0,
@@ -839,7 +832,7 @@ static int task_create(struct cpu_tasks *cpu,
                pthread_attr_t attr;
 
                pthread_attr_init(&attr);
-               pthread_attr_setstacksize(&attr, SMALL_STACK_MIN);
+               pthread_attr_setstacksize(&attr, 32 * 1024);
 
                err = __STD(pthread_create(&param->thread,
                                           &attr,
@@ -859,7 +852,7 @@ static int task_create(struct cpu_tasks *cpu,
                pthread_attr_t attr;
 
                pthread_attr_init(&attr);
-               pthread_attr_setstacksize(&attr, LARGE_STACK_MIN);
+               pthread_attr_setstacksize(&attr, 64 * 1024);
 
                err = __STD(pthread_create(&param->thread,
                                           &attr,
@@ -1373,7 +1366,7 @@ int main(int argc, const char *argv[])
        pthread_attr_setschedpolicy(&rt_attr, SCHED_FIFO);
        sp.sched_priority = 1;
        pthread_attr_setschedparam(&rt_attr, &sp);
-       pthread_attr_setstacksize(&rt_attr, SMALL_STACK_MIN);
+       pthread_attr_setstacksize(&rt_attr, 32 * 1024);
 
        printf("== Threads:");
        /* Create and register all tasks. */
diff --git a/testsuite/unit/cond-torture.c b/testsuite/unit/cond-torture.c
index 1c2dfa6..99574aa 100644
--- a/testsuite/unit/cond-torture.c
+++ b/testsuite/unit/cond-torture.c
@@ -16,7 +16,6 @@
 #include <sys/mman.h>
 #include <pthread.h>
 #include <alchemy/timer.h>
-#include <asm-generic/xenomai/stack.h>
 
 #define NS_PER_MS (1000000)
 #define NS_PER_S (1000000000)
@@ -129,7 +128,6 @@ int thread_spawn(pthread_t *thread, int prio,
        param.sched_priority = prio;
        pthread_attr_setschedparam(&tattr, &param);
        pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_JOINABLE);
-       pthread_attr_setstacksize(&tattr, cobalt_get_stacksize(0));
 
        err = pthread_create(thread, &tattr, handler, cookie);
 
diff --git a/testsuite/unit/mutex-torture.c b/testsuite/unit/mutex-torture.c
index d7591d6..c534b3b 100644
--- a/testsuite/unit/mutex-torture.c
+++ b/testsuite/unit/mutex-torture.c
@@ -7,19 +7,16 @@
  *
  * Released under the terms of GPLv2.
  */
-
+#include <sys/mman.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 #include <errno.h>
 #include <stdarg.h>
-
 #include <unistd.h>
 #include <signal.h>
-#include <sys/mman.h>
 #include <pthread.h>
 #include <alchemy/timer.h>
-#include <asm-generic/xenomai/stack.h>
 #include <cobalt/uapi/syscall.h>
 #include "lib/cobalt/current.h"
 
@@ -207,7 +204,6 @@ int dispatch(const char *service_name,
                pthread_attr_setschedparam(&threadattr, &param);
                pthread_attr_setinheritsched(&threadattr,
                                             PTHREAD_EXPLICIT_SCHED);
-               pthread_attr_setstacksize(&threadattr, cobalt_get_stacksize(0));
                handler = va_arg(ap, void *);
                status = pthread_create(thread, &threadattr, handler,
                                        va_arg(ap, void *));


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

Reply via email to