Module: xenomai-gch
Branch: for-head
Commit: dd97d5ef89be95bb26fa86ad19b014eff3444fc1
URL:    
http://git.xenomai.org/?p=xenomai-gch.git;a=commit;h=dd97d5ef89be95bb26fa86ad19b014eff3444fc1

Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org>
Date:   Wed Dec  2 17:12:21 2009 +0100

signals: reduce signals handling memory footprint

---

 include/asm-generic/syscall.h |   18 +++++++++---------
 include/asm-x86/syscall.h     |   35 ++++++++++-------------------------
 src/skins/common/bind.c       |   40 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 59 insertions(+), 34 deletions(-)

diff --git a/include/asm-generic/syscall.h b/include/asm-generic/syscall.h
index 926498b..483b99f 100644
--- a/include/asm-generic/syscall.h
+++ b/include/asm-generic/syscall.h
@@ -158,10 +158,15 @@ static inline int __xn_safe_strncpy_from_user(char *dst,
 #else /* !__KERNEL__ */
 
 #ifdef __cplusplus
-extern "C"
+extern "C" {
 #endif /* __cplusplus */
 int __xnsig_dispatch(struct xnsig *sigs, int cumulated_error, int last_error);
 
+int __xnsig_dispatch_safe(struct xnsig *sigs, int cumulated_error, int 
last_error);
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
 /* Called to dispatch signals which interrupted a system call. */
 static inline int xnsig_dispatch(struct xnsig *sigs, int cumul, int last)
 {
@@ -170,16 +175,11 @@ static inline int xnsig_dispatch(struct xnsig *sigs, int 
cumul, int last)
        return last;
 }
 
-/* Called to dispatch additional signals (received with the special
-   system call __xn_sys_get_next_sigs), it may happen that this
-   syscall was in fact called whereas no additional signal was
-   pending, in this case, ignore the syscall return value (last) and
-   preserve the cumulated error. */
-static inline int xnsig_dispatch_next(struct xnsig *sigs, int cumul, int last)
+static inline int xnsig_dispatch_safe(struct xnsig *sigs, int cumul, int last)
 {
        if (sigs->nsigs)
-               return __xnsig_dispatch(sigs, cumul, last);
-       return cumul;
+               return __xnsig_dispatch_safe(sigs, cumul, last);
+       return last;
 }
 
 #endif /* !__KERNEL__ */
diff --git a/include/asm-x86/syscall.h b/include/asm-x86/syscall.h
index 7b6aa20..26ea33f 100644
--- a/include/asm-x86/syscall.h
+++ b/include/asm-x86/syscall.h
@@ -166,15 +166,19 @@ static inline void __xn_get_ebp(void **dest)
         asm volatile("movl %%ebp, %0": "=m"(*dest));
 }
 
+#define XENOMAI_SIGS_TO_SYSARG(sigs) \
+       (&((struct frame *)sigs)->last_fp)
+
 #define XENOMAI_SYS_MUX_INNER(nr, op, args...)                 \
 ({                                                             \
        unsigned __resultvar;                                   \
        asm volatile (                                          \
                LOADARGS_##nr                                   \
                "movl %1, %%eax\n\t"                            \
+               "pushl %%ebp\n\t"                               \
                "movl %2, %%ebp\n\t"                            \
                DOSYSCALL                                       \
-               "movl (%%ebp), %%ebp\n\t"                       \
+               "popl %%ebp\n\t"                                \
                RESTOREARGS_##nr                                \
                : "=a" (__resultvar)                            \
                : "i" (__xn_mux_code(0, op)) ASMFMT_##nr(args)  \
@@ -195,13 +199,6 @@ static inline void __xn_get_ebp(void **dest)
                f.sigs.nsigs = 0;                                       \
                err = XENOMAI_SYS_MUX_INNER(nr, op, fp, args);          \
                res = xnsig_dispatch(&f.sigs, res, err);                \
-                                                                       \
-               while (f.sigs.nsigs && f.sigs.remaining) {              \
-                       f.sigs.nsigs = 0;                               \
-                       err = XENOMAI_SYS_MUX_INNER                     \
-                               (0, __xn_sys_get_next_sigs, fp);        \
-                       res = xnsig_dispatch_next(&f.sigs, res, err);   \
-               }                                                       \
        } while (res == -ERESTART);                                     \
        res;                                                            \
 })
@@ -212,9 +209,10 @@ static inline void __xn_get_ebp(void **dest)
        asm volatile (                                          \
                LOADARGS_##nr                                   \
                "movl %1, %%eax\n\t"                            \
+               "pushl %%ebp\n\t"                               \
                "movl %2, %%ebp\n\t"                            \
                DOSYSCALLSAFE                                   \
-               "movl (%%ebp), %%ebp\n\t"                       \
+               "popl %%ebp\n\t"                                \
                RESTOREARGS_##nr                                \
                : "=a" (__resultvar)                            \
                : "i" (__xn_mux_code(0, op)) ASMFMT_##nr(args)  \
@@ -234,14 +232,7 @@ static inline void __xn_get_ebp(void **dest)
        do {                                                            \
                f.sigs.nsigs = 0;                                       \
                err = XENOMAI_SYS_MUX_SAFE_INNER(nr, op, fp, args);     \
-               res = xnsig_dispatch(&f.sigs, res, err);                \
-                                                                       \
-               while (f.sigs.nsigs && f.sigs.remaining) {              \
-                       f.sigs.nsigs = 0;                               \
-                       err = XENOMAI_SYS_MUX_SAFE_INNER                \
-                               (0, __xn_sys_get_next_sigs, fp);        \
-                       res = xnsig_dispatch_next(&f.sigs, res, err);   \
-               }                                                       \
+               res = xnsig_dispatch_safe(&f.sigs, res, err);           \
        } while (res == -ERESTART);                                     \
        res;                                                            \
 })
@@ -253,9 +244,10 @@ static inline void __xn_get_ebp(void **dest)
        asm volatile (                                          \
                LOADARGS_##nr                                   \
                "movl %1, %%eax\n\t"                            \
+               "pushl %%ebp\n\t"                               \
                "movl %2, %%ebp\n\t"                            \
                DOSYSCALL                                       \
-               "movl (%%ebp), %%ebp\n\t"                       \
+               "popl %%ebp\n\t"                                \
                RESTOREARGS_##nr                                \
                : "=a" (__resultvar)                            \
                : "m" (__muxcode) ASMFMT_##nr(args)             \
@@ -276,13 +268,6 @@ static inline void __xn_get_ebp(void **dest)
                f.sigs.nsigs = 0;                                       \
                err = XENOMAI_SKIN_MUX_INNER(nr, shifted_id, op, fp, args); \
                res = xnsig_dispatch(&f.sigs, res, err);                \
-                                                                       \
-               while (f.sigs.nsigs && f.sigs.remaining) {              \
-                       f.sigs.nsigs = 0;                               \
-                       err = XENOMAI_SYS_MUX_INNER                     \
-                               (0, __xn_sys_get_next_sigs, fp);        \
-                       res = xnsig_dispatch_next(&f.sigs, res, err);   \
-               }                                                       \
        } while (res == -ERESTART);                                     \
        res;                                                            \
 })
diff --git a/src/skins/common/bind.c b/src/skins/common/bind.c
index e4a4c3c..8a54568 100644
--- a/src/skins/common/bind.c
+++ b/src/skins/common/bind.c
@@ -22,8 +22,10 @@ struct xnfeatinfo xeno_featinfo;
 
 int __xnsig_dispatch(struct xnsig *sigs, int cumulated_error, int last_error)
 {
+       void *sysarg = XENOMAI_SIGS_TO_SYSARG(sigs);
        unsigned i;
 
+  dispatch:
        for (i = 0; i < sigs->nsigs; i++) {
                xnsighandler *handler;
                
@@ -31,8 +33,46 @@ int __xnsig_dispatch(struct xnsig *sigs, int 
cumulated_error, int last_error)
                if (handler)
                        handler(&sigs->pending[i].si);
        }
+
        if (cumulated_error == -ERESTART)
                cumulated_error = last_error;
+
+       if (sigs->remaining) {
+               sigs->nsigs = 0;
+               last_error = XENOMAI_SYS_MUX_INNER
+                       (0, __xn_sys_get_next_sigs, sysarg);
+               if (sigs->nsigs)
+                       goto dispatch;
+       }
+
+       return cumulated_error;
+}
+
+int __xnsig_dispatch_safe(struct xnsig *sigs, int cumulated_error, int 
last_error)
+{
+       void *sysarg = XENOMAI_SIGS_TO_SYSARG(sigs);
+       unsigned i;
+
+  dispatch:
+       for (i = 0; i < sigs->nsigs; i++) {
+               xnsighandler *handler;
+               
+               handler = xnsig_handlers[sigs->pending[i].muxid];
+               if (handler)
+                       handler(&sigs->pending[i].si);
+       }
+
+       if (cumulated_error == -ERESTART)
+               cumulated_error = last_error;
+
+       if (sigs->remaining) {
+               sigs->nsigs = 0;
+               last_error = XENOMAI_SYS_MUX_SAFE_INNER
+                       (0, __xn_sys_get_next_sigs, sysarg);
+               if (sigs->nsigs)
+                       goto dispatch;
+       }
+
        return cumulated_error;
 }
 


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

Reply via email to