Module: xenomai-3
Branch: next
Commit: 4e5fcf5d02c663d967e0aec9a2dde917da4c65bf
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=4e5fcf5d02c663d967e0aec9a2dde917da4c65bf

Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org>
Date:   Sun Nov 16 00:00:54 2014 +0100

cobalt/rtdm: rebase rtdm_nrtsig on ipipe_post_work_root

As a consequence of this change, the RTDM API changes:
- rtdm_nrtsig_t becomes a structure
- rtdm_nrtsig_init now returns void, as we can no longer run out of virq
- the first argument of the nrtsig handler is a pointer to the rtdm_nrtsig_t
structure.

In-tree updated to reflect the change:
kernel/drivers/analogy/rtdm_helpers.c
kernel/drivers/testing/switchtest.c

---

 include/cobalt/kernel/rtdm/driver.h   |   43 +++++++++++++++------------------
 kernel/cobalt/rtdm/drvlib.c           |   38 ++++++++++++++++++++++++-----
 kernel/drivers/analogy/rtdm_helpers.c |    4 +--
 kernel/drivers/testing/switchtest.c   |    7 ++----
 4 files changed, 56 insertions(+), 36 deletions(-)

diff --git a/include/cobalt/kernel/rtdm/driver.h 
b/include/cobalt/kernel/rtdm/driver.h
index f705af2..703b6ec 100644
--- a/include/cobalt/kernel/rtdm/driver.h
+++ b/include/cobalt/kernel/rtdm/driver.h
@@ -221,7 +221,7 @@ struct rtdm_profile_info {
        /** Reserved */
        unsigned int magic;
        struct module *owner;
-};     
+};
 
 /**
  * @brief RTDM driver
@@ -288,7 +288,7 @@ struct rtdm_driver {
  */
 #define RTDM_PROFILE_INFO(__name, __id, __subid, __version)    \
 {                                                              \
-       .name = ( # __name ),                                   \
+       .name = ( # __name ),                                   \
        .class_id = (__id),                                     \
        .subclass_id = (__subid),                               \
        .version = (__version),                                 \
@@ -829,44 +829,41 @@ static inline int rtdm_irq_disable(rtdm_irq_t *irq_handle)
  * @{
  */
 
-typedef unsigned rtdm_nrtsig_t;
-
+typedef struct rtdm_nrtsig rtdm_nrtsig_t;
 /**
  * Non-real-time signal handler
  *
- * @param[in] nrt_sig Signal handle as returned by rtdm_nrtsig_init()
+ * @param[in] nrt_sig Signal handle pointer as passed to rtdm_nrtsig_init()
  * @param[in] arg Argument as passed to rtdm_nrtsig_init()
  *
  * @note The signal handler will run in soft-IRQ context of the non-real-time
  * subsystem. Note the implications of this context, e.g. no invocation of
  * blocking operations.
  */
-typedef void (*rtdm_nrtsig_handler_t)(rtdm_nrtsig_t nrt_sig, void *arg);
+typedef void (*rtdm_nrtsig_handler_t)(rtdm_nrtsig_t *nrt_sig, void *arg);
+
+struct rtdm_nrtsig {
+       rtdm_nrtsig_handler_t handler;
+       void *arg;
+};
+
 /** @} rtdm_nrtsignal */
 
 #ifndef DOXYGEN_CPP /* Avoid static inline tags for RTDM in doxygen */
-static inline int rtdm_nrtsig_init(rtdm_nrtsig_t *nrt_sig,
-                                  rtdm_nrtsig_handler_t handler, void *arg)
+static inline void rtdm_nrtsig_init(rtdm_nrtsig_t *nrt_sig,
+                               rtdm_nrtsig_handler_t handler, void *arg)
 {
-       *nrt_sig = ipipe_alloc_virq();
-       if (*nrt_sig == 0)
-               return -EAGAIN;
-
-       ipipe_request_irq(ipipe_root_domain, *nrt_sig, handler, arg, NULL);
-
-       return 0;
+       nrt_sig->handler = handler;
+       nrt_sig->arg = arg;
 }
 
 static inline void rtdm_nrtsig_destroy(rtdm_nrtsig_t *nrt_sig)
 {
-       ipipe_free_irq(ipipe_root_domain, *nrt_sig);
-       ipipe_free_virq(*nrt_sig);
+       nrt_sig->handler = NULL;
+       nrt_sig->arg = NULL;
 }
 
-static inline void rtdm_nrtsig_pend(rtdm_nrtsig_t *nrt_sig)
-{
-       ipipe_raise_irq(*nrt_sig);
-}
+void rtdm_nrtsig_pend(rtdm_nrtsig_t *nrt_sig);
 #endif /* !DOXYGEN_CPP */
 
 /* --- timer services --- */
@@ -1059,10 +1056,10 @@ static inline int __deprecated 
rtdm_task_sleep_until(nanosecs_abs_t wakeup_time)
                int __ret = 0;                                                  
\
                for (;;) {                                                      
\
                        __end = rtdm_clock_read_monotonic() + __spin_ns;        
\
-                       for (;;) {                                              
\
+                       for (;;) {                                              
\
                                if (__condition)                                
\
                                        goto done;                              
\
-                               if (rtdm_clock_read_monotonic() >= __end)       
\
+                               if (rtdm_clock_read_monotonic() >= __end)       
\
                                        break;                                  
\
                        }                                                       
\
                        __ret = rtdm_task_sleep(__sleep_ns);                    
\
diff --git a/kernel/cobalt/rtdm/drvlib.c b/kernel/cobalt/rtdm/drvlib.c
index 414e262..165768a 100644
--- a/kernel/cobalt/rtdm/drvlib.c
+++ b/kernel/cobalt/rtdm/drvlib.c
@@ -328,7 +328,7 @@ int rtdm_task_sleep_abs(nanosecs_abs_t wakeup_time, enum 
rtdm_timer_mode mode);
  * @coretags{primary-only, might-switch}
  */
 int rtdm_task_busy_wait(bool condition, nanosecs_rel_t spin_ns,
-                       nanosecs_rel_t sleep_ns);
+                       nanosecs_rel_t sleep_ns);
 
 #endif /* DOXYGEN_CPP */
 
@@ -1410,8 +1410,6 @@ int rtdm_irq_disable(rtdm_irq_t *irq_handle);
 
 /** @} Interrupt Management Services */
 
-#ifdef DOXYGEN_CPP /* Only used for doxygen doc generation */
-
 /**
  * @ingroup rtdm_driver_interface
  * @defgroup rtdm_nrtsignal Non-Real-Time Signalling Services
@@ -1424,6 +1422,8 @@ int rtdm_irq_disable(rtdm_irq_t *irq_handle);
  * @{
  */
 
+#ifdef DOXYGEN_CPP /* Only used for doxygen doc generation */
+
 /**
  * @brief Register a non-real-time signal handler
  *
@@ -1448,6 +1448,22 @@ int rtdm_nrtsig_init(rtdm_nrtsig_t *nrt_sig, 
rtdm_nrtsig_handler_t handler,
  * @coretags{task-unrestricted}
  */
 void rtdm_nrtsig_destroy(rtdm_nrtsig_t *nrt_sig);
+#endif /* DOXYGEN_CPP */
+
+struct nrtsig_work {
+       struct ipipe_work_header work;
+       struct rtdm_nrtsig *nrtsig;
+};
+
+static void nrtsig_execute(struct ipipe_work_header *work)
+{
+       struct rtdm_nrtsig *nrtsig;
+       struct nrtsig_work *w;
+
+       w = container_of(work, typeof(*w), work);
+       nrtsig = w->nrtsig;
+       nrtsig->handler(nrtsig, nrtsig->arg);
+}
 
 /**
  * Trigger non-real-time signal
@@ -1456,10 +1472,20 @@ void rtdm_nrtsig_destroy(rtdm_nrtsig_t *nrt_sig);
  *
  * @coretags{unrestricted}
  */
-void rtdm_nrtsig_pend(rtdm_nrtsig_t *nrt_sig);
+void rtdm_nrtsig_pend(rtdm_nrtsig_t *nrt_sig)
+{
+       struct nrtsig_work nrtsig_work = {
+               .work = {
+                       .size = sizeof(nrtsig_work),
+                       .handler = nrtsig_execute,
+               },
+               .nrtsig = nrt_sig,
+       };
+       ipipe_post_work_root(&nrtsig_work, work);
+}
+EXPORT_SYMBOL_GPL(rtdm_nrtsig_pend);
 /** @} Non-Real-Time Signalling Services */
 
-#endif /* DOXYGEN_CPP */
 
 /**
  * @ingroup rtdm_driver_interface
@@ -1486,7 +1512,7 @@ static int mmap_kmem_helper(struct vm_area_struct *vma, 
void *va)
 {
        unsigned long addr, len, pfn, to;
        int ret = 0;
-       
+
        to = (unsigned long)va;
        addr = vma->vm_start;
        len = vma->vm_end - vma->vm_start;
diff --git a/kernel/drivers/analogy/rtdm_helpers.c 
b/kernel/drivers/analogy/rtdm_helpers.c
index 9e1af43..8330d06 100644
--- a/kernel/drivers/analogy/rtdm_helpers.c
+++ b/kernel/drivers/analogy/rtdm_helpers.c
@@ -81,7 +81,7 @@ int __a4l_free_irq(struct a4l_irq_descriptor * dsc)
 
 /* --- Synchronization section --- */
 
-static void a4l_nrt_sync_handler(rtdm_nrtsig_t nrt_sig, void *arg)
+static void a4l_nrt_sync_handler(rtdm_nrtsig_t *nrt_sig, void *arg)
 {
        struct a4l_sync *snc = (struct a4l_sync *) arg;
        wake_up_interruptible(&snc->wq);
@@ -101,7 +101,7 @@ int a4l_init_sync(struct a4l_sync *snc)
        rtdm_event_init(&snc->rtdm_evt, 0);
 
        /* Initializes the gateway to NRT context */
-       ret = rtdm_nrtsig_init(&snc->nrt_sig, a4l_nrt_sync_handler, snc);
+       rtdm_nrtsig_init(&snc->nrt_sig, a4l_nrt_sync_handler, snc);
 
        return ret;
 }
diff --git a/kernel/drivers/testing/switchtest.c 
b/kernel/drivers/testing/switchtest.c
index f9cb78e..a93a53a 100644
--- a/kernel/drivers/testing/switchtest.c
+++ b/kernel/drivers/testing/switchtest.c
@@ -520,7 +520,7 @@ static int rtswitch_create_ktask(struct rtswitch_context 
*ctx,
        return err;
 }
 
-static void rtswitch_utask_waker(rtdm_nrtsig_t sig, void *arg)
+static void rtswitch_utask_waker(rtdm_nrtsig_t *sig, void *arg)
 {
        struct rtswitch_context *ctx = (struct rtswitch_context *)arg;
        up(&ctx->utask->nrt_synch);
@@ -529,7 +529,6 @@ static void rtswitch_utask_waker(rtdm_nrtsig_t sig, void 
*arg)
 static int rtswitch_open(struct rtdm_fd *fd, int oflags)
 {
        struct rtswitch_context *ctx = rtdm_fd_to_private(fd);
-       int err;
 
        ctx->tasks = NULL;
        ctx->tasks_count = ctx->next_index = ctx->cpu = ctx->switches_count = 0;
@@ -538,9 +537,7 @@ static int rtswitch_open(struct rtdm_fd *fd, int oflags)
        ctx->error.last_switch.from = ctx->error.last_switch.to = -1;
        ctx->pause_us = 0;
 
-       err = rtdm_nrtsig_init(&ctx->wake_utask, rtswitch_utask_waker, ctx);
-       if (err)
-               return err;
+       rtdm_nrtsig_init(&ctx->wake_utask, rtswitch_utask_waker, ctx);
 
        rtdm_timer_init(&ctx->wake_up_delay, timed_wake_up, "switchtest timer");
 


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

Reply via email to