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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Sun Jun  9 18:30:32 2013 +0200

nucleus: drop START/SWITCH/DELETE hook mechanism

This legacy did not allow to differentiate handlers based on the
Xenomai personality threads belong to. This shortcoming made them
sub-optimal for handling interface resource cleanups efficiently,
which is basically what we need.

Since we don't have any in-tree clients for these anymore, let's drop
them happily.

---

 include/cobalt/nucleus/pod.h    |   22 ----
 include/cobalt/nucleus/thread.h |   10 --
 kernel/cobalt/nucleus/pod.c     |  208 +--------------------------------------
 kernel/cobalt/nucleus/sched.c   |   10 +-
 4 files changed, 6 insertions(+), 244 deletions(-)

diff --git a/include/cobalt/nucleus/pod.h b/include/cobalt/nucleus/pod.h
index 25ab126..941747f 100644
--- a/include/cobalt/nucleus/pod.h
+++ b/include/cobalt/nucleus/pod.h
@@ -75,10 +75,6 @@ struct xnpod {
 #ifdef CONFIG_XENO_OPT_VFILE
        struct xnvfile_rev_tag threadlist_tag;
 #endif
-       xnqueue_t tstartq,      /*!< Thread start hook queue. */
-        tswitchq,              /*!< Thread switch hook queue. */
-        tdeleteq;              /*!< Thread delete hook queue. */
-
        atomic_counter_t timerlck; /*!< Timer lock depth.  */
 
        int refcnt;             /*!< Reference count.  */
@@ -327,20 +323,6 @@ static inline void xnpod_testcancel_thread(void)
 
 int xnpod_handle_exception(struct ipipe_trap_data *d);
 
-void xnpod_fire_callouts(xnqueue_t *hookq,
-                        xnthread_t *thread);
-
-static inline void xnpod_run_hooks(struct xnqueue *q,
-                                  struct xnthread *thread, const char *type)
-{
-       if (!emptyq_p(q)) {
-               trace_mark(xn_nucleus, thread_callout,
-                          "thread %p thread_name %s hook %s",
-                          thread, xnthread_name(thread), type);
-               xnpod_fire_callouts(q, thread);
-       }
-}
-
 int xnpod_set_thread_periodic(xnthread_t *thread,
                              xnticks_t idate,
                              xntmode_t timeout_mode,
@@ -351,10 +333,6 @@ int xnpod_wait_thread_period(unsigned long *overruns_r);
 int xnpod_set_thread_tslice(struct xnthread *thread,
                            xnticks_t quantum);
 
-int xnpod_add_hook(int type, void (*routine) (xnthread_t *));
-
-int xnpod_remove_hook(int type, void (*routine) (xnthread_t *));
-
 static inline void xnpod_yield(void)
 {
        xnpod_resume_thread(xnpod_current_thread(), 0);
diff --git a/include/cobalt/nucleus/thread.h b/include/cobalt/nucleus/thread.h
index 32119cc..293377e 100644
--- a/include/cobalt/nucleus/thread.h
+++ b/include/cobalt/nucleus/thread.h
@@ -300,16 +300,6 @@ typedef struct xnthread {
 #endif
 } xnthread_t;
 
-#define XNHOOK_THREAD_START  1
-#define XNHOOK_THREAD_SWITCH 2
-#define XNHOOK_THREAD_DELETE 3
-
-typedef struct xnhook {
-       xnholder_t link;
-#define link2hook(ln)          container_of(ln, xnhook_t, link)
-       void (*routine)(struct xnthread *thread);
-} xnhook_t;
-
 #define xnthread_name(thread)               ((thread)->name)
 #define xnthread_clear_name(thread)        do { *(thread)->name = 0; } while(0)
 #define xnthread_sched(thread)             ((thread)->sched)
diff --git a/kernel/cobalt/nucleus/pod.c b/kernel/cobalt/nucleus/pod.c
index 117091d..39fade8 100644
--- a/kernel/cobalt/nucleus/pod.c
+++ b/kernel/cobalt/nucleus/pod.c
@@ -279,9 +279,6 @@ int xnpod_init(void)
        pod->status = 0;
        pod->refcnt = 1;
        initq(&pod->threadq);
-       initq(&pod->tstartq);
-       initq(&pod->tswitchq);
-       initq(&pod->tdeleteq);
        xnarch_atomic_set(&pod->timerlck, 0);
 
        xnlock_put_irqrestore(&nklock, s);
@@ -398,27 +395,6 @@ void xnpod_shutdown(int xtype)
 }
 EXPORT_SYMBOL_GPL(xnpod_shutdown);
 
-void xnpod_fire_callouts(xnqueue_t *hookq, xnthread_t *thread)
-{
-       /* Must be called with nklock locked, interrupts off. */
-       xnsched_t *sched = xnpod_current_sched();
-       xnholder_t *holder, *nholder;
-
-       __setbits(sched->status, XNKCOUT);
-
-       /* The callee is allowed to alter the hook queue when running */
-
-       nholder = getheadq(hookq);
-
-       while ((holder = nholder) != NULL) {
-               xnhook_t *hook = link2hook(holder);
-               nholder = nextq(hookq, holder);
-               hook->routine(thread);
-       }
-
-       __clrbits(sched->status, XNKCOUT);
-}
-
 /*!
  * \fn void xnpod_init_thread(struct xnthread *thread,const struct 
xnthread_init_attr *attr,struct xnsched_class *sched_class,const union 
xnsched_policy_param *sched_param)
  * \brief Initialize a new thread.
@@ -559,9 +535,6 @@ EXPORT_SYMBOL_GPL(xnpod_init_thread);
  * - cookie: A user-defined opaque cookie the nucleus will pass to the
  * emerging thread as the sole argument of its entry point.
  *
- * The START hooks are called on behalf of the calling context (if
- * any).
- *
  * @retval 0 if @a thread could be started ;
  *
  * @retval -EBUSY if @a thread was not dormant or stopped ;
@@ -627,8 +600,6 @@ int xnpod_start_thread(struct xnthread *thread,
                   thread, xnthread_name(thread));
 
        xnpod_resume_thread(thread, XNDORMANT);
-
-       xnpod_run_hooks(&nkpod->tstartq, thread, "START");
 schedule:
        xnpod_schedule();
 unlock_and_exit:
@@ -847,11 +818,10 @@ static void cleanup_thread(struct xnthread *thread) /* 
nklock held, irqs off */
 
        if (!moving_target(sched, thread)) {
                xnshadow_unmap(thread);
-               xnpod_run_hooks(&nkpod->tdeleteq, thread, "DELETE");
                xnsched_forget(thread);
                /*
-                * Note: the thread control block must remain
-                * available until the user hooks have been called.
+                * We may wipe the TCB out now that the unmap_thread()
+                * handler has run (in xnshadow_unmap()).
                 */
                xnthread_cleanup(thread);
 
@@ -1791,8 +1761,6 @@ static inline void xnpod_switch_to(xnsched_t *sched,
  * - Interrupt service routine, although this leads to a no-op.
  * - Kernel-based task
  * - User-space task
- *
- * @note The switch hooks are called on behalf of the resuming thread.
  */
 
 static inline int test_resched(struct xnsched *sched)
@@ -1944,8 +1912,6 @@ reschedule:
 
        __xnpod_switch_fpu(sched);
 
-       xnpod_run_hooks(&nkpod->tswitchq, curr, "SWITCH");
-
  signal_unlock_and_exit:
        if (xnthread_signaled_p(curr))
                xnpod_dispatch_signals();
@@ -2014,176 +1980,6 @@ void ___xnpod_unlock_sched(xnsched_t *sched)
 EXPORT_SYMBOL_GPL(___xnpod_unlock_sched);
 
 /*!
- * \fn int xnpod_add_hook(int type,void (*routine)(xnthread_t *))
- * \brief Install a nucleus hook.
- *
- * The nucleus allows to register user-defined routines which get
- * called whenever a specific scheduling event occurs. Multiple hooks
- * can be chained for a single event type, and get called on a FIFO
- * basis.
- *
- * The scheduling is locked while a hook is executing.
- *
- * @param type Defines the kind of hook to install:
- *
- *        - XNHOOK_THREAD_START: The user-defined routine will be
- *        called on behalf of the starter thread whenever a new thread
- *        starts. The descriptor address of the started thread is
- *        passed to the routine.
- *
- *        - XNHOOK_THREAD_DELETE: The user-defined routine will be
- *        called on behalf of the deletor thread whenever a thread is
- *        deleted. The descriptor address of the deleted thread is
- *        passed to the routine.
- *
- *        - XNHOOK_THREAD_SWITCH: The user-defined routine will be
- *        called on behalf of the resuming thread whenever a context
- *        switch takes place. The descriptor address of the thread
- *        which has been switched out is passed to the routine.
- *
- * @param routine The address of the user-supplied routine to call.
- *
- * @return 0 is returned on success. Otherwise, one of the following
- * error codes indicates the cause of the failure:
- *
- *         - -EINVAL is returned if type is incorrect.
- *
- *         - -ENOMEM is returned if not enough memory is available
- *         from the system heap to add the new hook.
- *
- * Environments:
- *
- * This service can be called from:
- *
- * - Kernel module initialization/cleanup code
- * - Kernel-based task
- * - User-space task
- *
- * Rescheduling: never.
- */
-
-int xnpod_add_hook(int type, void (*routine) (xnthread_t *))
-{
-       xnqueue_t *hookq;
-       xnhook_t *hook;
-       int err = 0;
-       spl_t s;
-
-       xnlock_get_irqsave(&nklock, s);
-
-       trace_mark(xn_nucleus, sched_addhook, "type %d routine %p",
-                  type, routine);
-
-       switch (type) {
-       case XNHOOK_THREAD_START:
-               hookq = &nkpod->tstartq;
-               break;
-       case XNHOOK_THREAD_SWITCH:
-               hookq = &nkpod->tswitchq;
-               break;
-       case XNHOOK_THREAD_DELETE:
-               hookq = &nkpod->tdeleteq;
-               break;
-       default:
-               err = -EINVAL;
-               goto unlock_and_exit;
-       }
-
-       hook = xnmalloc(sizeof(*hook));
-
-       if (hook) {
-               inith(&hook->link);
-               hook->routine = routine;
-               prependq(hookq, &hook->link);
-       } else
-               err = -ENOMEM;
-
-      unlock_and_exit:
-
-       xnlock_put_irqrestore(&nklock, s);
-
-       return err;
-}
-EXPORT_SYMBOL_GPL(xnpod_add_hook);
-
-/*!
- * \fn int xnpod_remove_hook(int type,void (*routine)(xnthread_t *))
- * \brief Remove a nucleus hook.
- *
- * This service removes a nucleus hook previously registered using
- * xnpod_add_hook().
- *
- * @param type Defines the kind of hook to remove among
- * XNHOOK_THREAD_START, XNHOOK_THREAD_DELETE and XNHOOK_THREAD_SWITCH.
- *
- * @param routine The address of the user-supplied routine to remove.
- *
- * @return 0 is returned on success. Otherwise, -EINVAL is returned if
- * type is incorrect or if the routine has never been registered
- * before.
- *
- * Environments:
- *
- * This service can be called from:
- *
- * - Kernel module initialization/cleanup code
- * - Kernel-based task
- * - User-space task
- *
- * Rescheduling: never.
- */
-
-int xnpod_remove_hook(int type, void (*routine) (xnthread_t *))
-{
-       xnhook_t *hook = NULL;
-       xnholder_t *holder;
-       xnqueue_t *hookq;
-       int err = 0;
-       spl_t s;
-
-       xnlock_get_irqsave(&nklock, s);
-
-       trace_mark(xn_nucleus, sched_removehook, "type %d routine %p",
-                  type, routine);
-
-       switch (type) {
-       case XNHOOK_THREAD_START:
-               hookq = &nkpod->tstartq;
-               break;
-       case XNHOOK_THREAD_SWITCH:
-               hookq = &nkpod->tswitchq;
-               break;
-       case XNHOOK_THREAD_DELETE:
-               hookq = &nkpod->tdeleteq;
-               break;
-       default:
-               goto bad_hook;
-       }
-
-       for (holder = getheadq(hookq);
-            holder != NULL; holder = nextq(hookq, holder)) {
-               hook = link2hook(holder);
-
-               if (hook->routine == routine) {
-                       removeq(hookq, holder);
-                       xnfree(hook);
-                       goto unlock_and_exit;
-               }
-       }
-
-      bad_hook:
-
-       err = -EINVAL;
-
-      unlock_and_exit:
-
-       xnlock_put_irqrestore(&nklock, s);
-
-       return err;
-}
-EXPORT_SYMBOL_GPL(xnpod_remove_hook);
-
-/*!
  * \fn void xnpod_handle_exception(struct ipipe_trap_data *d);
  * \brief Exception handler.
  *
diff --git a/kernel/cobalt/nucleus/sched.c b/kernel/cobalt/nucleus/sched.c
index db21bfa..9319080 100644
--- a/kernel/cobalt/nucleus/sched.c
+++ b/kernel/cobalt/nucleus/sched.c
@@ -247,6 +247,7 @@ struct xnthread *xnsched_pick_next(struct xnsched *sched)
 void xnsched_zombie_hooks(struct xnthread *thread)
 {
        XENO_BUGON(NUCLEUS, thread->sched->zombie != NULL);
+
        thread->sched->zombie = thread;
 
        trace_mark(xn_nucleus, sched_finalize,
@@ -254,9 +255,6 @@ void xnsched_zombie_hooks(struct xnthread *thread)
                   thread, xnthread_name(thread));
 
        xnshadow_unmap(thread);
-
-       xnpod_run_hooks(&nkpod->tdeleteq, thread, "DELETE");
-
        xnsched_forget(thread);
 }
 
@@ -299,11 +297,11 @@ struct xnsched *xnsched_finish_unlocked_switch(struct 
xnsched *sched)
                /*
                 * There are two cases where sched->last has the zombie
                 * bit:
-                * - either it had it before the context switch, the hooks
-                * have been executed and sched->zombie is last;
+                * - either it had it before the context switch, the
+                * cleanup has be done and sched->zombie is last;
                 * - or it has been killed while the nklocked was unlocked
                 * during the context switch, in which case we must run the
-                * hooks, and we do it now.
+                * cleanup code, and we do it now.
                 */
                if (sched->zombie != last)
                        xnsched_zombie_hooks(last);


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

Reply via email to