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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Tue Mar 20 22:42:27 2012 +0100

cobalt: introduce pre-faulting of shared areas

---

 lib/cobalt/cond.c     |   11 ++++++++---
 lib/cobalt/current.c  |    9 +++++++--
 lib/cobalt/internal.c |   26 +++++++++++++++++++++-----
 lib/cobalt/internal.h |    4 ++++
 lib/cobalt/mutex.c    |   10 ++++++++--
 5 files changed, 48 insertions(+), 12 deletions(-)

diff --git a/lib/cobalt/cond.c b/lib/cobalt/cond.c
index 9a6d2d6..0f9e050 100644
--- a/lib/cobalt/cond.c
+++ b/lib/cobalt/cond.c
@@ -89,13 +89,18 @@ int __wrap_pthread_cond_init(pthread_cond_t *cond,
                             const pthread_condattr_t * attr)
 {
        struct __shadow_cond *_cnd = &((union __xeno_cond *)cond)->shadow_cond;
+       unsigned long *pending_signalsp;
        int err;
 
        err = XENOMAI_SKINCALL2(__cobalt_muxid, sc_cobalt_cond_init, _cnd, 
attr);
        if (!err && !_cnd->attr.pshared) {
-               _cnd->pending_signals = (unsigned long *)
+               pending_signalsp = (unsigned long *)
                        (xeno_sem_heap[0] + _cnd->pending_signals_offset);
-       }
+               _cnd->pending_signals = pending_signalsp;
+       } else
+               pending_signalsp = cond_get_signalsp(_cnd);
+
+       __cobalt_prefault(pending_signalsp);
 
        return -err;
 }
@@ -243,7 +248,7 @@ int __wrap_pthread_cond_signal(pthread_cond_t *cond)
 
        mutex_datp = cond_get_mutex_datp(_cnd);
        if (mutex_datp) {
-               unsigned long flags = mutex_datp->flags ;
+               unsigned long flags = mutex_datp->flags;
 
                if (unlikely(flags & COBALT_MUTEX_ERRORCHECK)) {
                        xnhandle_t cur = xeno_get_current();
diff --git a/lib/cobalt/current.c b/lib/cobalt/current.c
index 6ea49f4..dde38a3 100644
--- a/lib/cobalt/current.c
+++ b/lib/cobalt/current.c
@@ -8,6 +8,7 @@
 #include <nucleus/vdso.h>
 #include <asm/xenomai/syscall.h>
 #include <asm-generic/bits/current.h>
+#include "internal.h"
 
 extern unsigned long xeno_sem_heap[2];
 
@@ -30,6 +31,7 @@ void xeno_set_current_window(unsigned long offset)
 {
        xeno_current_window = (struct xnthread_user_window *)
                (xeno_sem_heap[0] + offset);
+       __cobalt_prefault(xeno_current_window);
 }
 #else /* !HAVE_TLS */
 
@@ -73,8 +75,11 @@ void xeno_init_current_keys(void)
 
 void xeno_set_current_window(unsigned long offset)
 {
-       pthread_setspecific(xeno_current_window_key,
-                           (void *)(xeno_sem_heap[0] + offset));
+       struct xnthread_user_window *window;
+
+       window = (void *)(xeno_sem_heap[0] + offset);
+       pthread_setspecific(xeno_current_window_key, window);
+       __cobalt_prefault(window);
 }
 #endif /* !HAVE_TLS */
 
diff --git a/lib/cobalt/internal.c b/lib/cobalt/internal.c
index c20935e..12e31fb 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 <unistd.h>
 #include <signal.h>
 #include <errno.h>
 #include <pthread.h>
@@ -51,6 +52,18 @@ int __cobalt_thread_stat(pthread_t tid, struct 
cobalt_threadstat *stat)
                                 sc_cobalt_thread_getstat, tid, stat);
 }
 
+void ___cobalt_prefault(void *p, size_t len)
+{
+       volatile char *_p = (volatile char *)p, *end;
+       long pagesz = sysconf(_SC_PAGESIZE);
+
+       end = _p + len;
+       do {
+               *_p = *_p;
+               _p += pagesz;
+       } while (_p < end);
+}
+
 static inline
 struct cobalt_monitor_data *get_monitor_data(cobalt_monitor_t *mon)
 {
@@ -73,7 +86,10 @@ int cobalt_monitor_init(cobalt_monitor_t *mon, int flags)
        if ((flags & COBALT_MONITOR_SHARED) == 0) {
                datp = (void *)xeno_sem_heap[0] + mon->u.data_offset;
                mon->u.data = datp;
-       }
+       } else
+               datp = get_monitor_data(mon);
+
+       __cobalt_prefault(datp);
 
        return 0;
 }
@@ -130,7 +146,7 @@ int cobalt_monitor_exit(cobalt_monitor_t *mon)
        unsigned long status;
        xnhandle_t cur;
 
-       xnarch_memory_barrier();
+       __sync_synchronize();
 
        datp = get_monitor_data(mon);
        if ((datp->flags & COBALT_MONITOR_PENDED) &&
@@ -347,10 +363,10 @@ int cobalt_event_init(cobalt_event_t *event, unsigned 
long value,
        if ((flags & COBALT_EVENT_SHARED) == 0) {
                datp = (void *)xeno_sem_heap[0] + event->u.data_offset;
                event->u.data = datp;
-       }
+       } else
+               datp = get_event_data(event);
 
-       datp = get_event_data(event);
-       memset(datp, 0, sizeof(*datp));
+       __cobalt_prefault(datp);
 
        return 0;
 }
diff --git a/lib/cobalt/internal.h b/lib/cobalt/internal.h
index da8586b..539f8e1 100644
--- a/lib/cobalt/internal.h
+++ b/lib/cobalt/internal.h
@@ -12,6 +12,10 @@ struct xnthread_user_window;
 struct cobalt_threadstat;
 struct cobalt_monitor_shadow;
 
+void ___cobalt_prefault(void *p, size_t len);
+
+#define __cobalt_prefault(p) ___cobalt_prefault(p, sizeof(*p))
+
 void __cobalt_thread_harden(void);
 
 int __cobalt_thread_stat(pthread_t tid,
diff --git a/lib/cobalt/mutex.c b/lib/cobalt/mutex.c
index f4c5a03..018147d 100644
--- a/lib/cobalt/mutex.c
+++ b/lib/cobalt/mutex.c
@@ -81,6 +81,7 @@ int __wrap_pthread_mutex_init(pthread_mutex_t *mutex,
 {
        struct __shadow_mutex *_mutex =
                &((union __xeno_mutex *)mutex)->shadow_mutex;
+       struct mutex_dat *datp;
        int err;
 
        if (_mutex->magic == COBALT_MUTEX_MAGIC) {
@@ -93,9 +94,14 @@ int __wrap_pthread_mutex_init(pthread_mutex_t *mutex,
 
        err = 
-XENOMAI_SKINCALL2(__cobalt_muxid,sc_cobalt_mutex_init,_mutex,attr);
 
-       if (!_mutex->attr.pshared)
-               _mutex->dat = (struct mutex_dat *)
+       if (!_mutex->attr.pshared) {
+               datp = (struct mutex_dat *)
                        (xeno_sem_heap[0] + _mutex->dat_offset);
+               _mutex->dat = datp;
+       } else
+               datp = mutex_get_datp(_mutex);
+
+       __cobalt_prefault(datp);
 
        return err;
 }


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

Reply via email to