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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Thu Jun 20 12:34:49 2013 +0200

cobalt/kernel/pod: turn threadq into regular kernel list

---

 include/cobalt/kernel/pod.h    |    6 +---
 include/cobalt/kernel/ppd.h    |    1 -
 include/cobalt/kernel/thread.h |    5 +--
 kernel/cobalt/pod.c            |   41 ++++++++++++++++++---------------------
 kernel/cobalt/sched-rt.c       |   11 ++++++---
 kernel/cobalt/sched-sporadic.c |   11 ++++++---
 kernel/cobalt/sched-tp.c       |   14 +++++++++---
 kernel/cobalt/sched-weak.c     |   11 ++++++---
 kernel/cobalt/sched.c          |   27 ++++++++++++++++---------
 kernel/cobalt/thread.c         |    1 -
 10 files changed, 71 insertions(+), 57 deletions(-)

diff --git a/include/cobalt/kernel/pod.h b/include/cobalt/kernel/pod.h
index 3d6b983..f554e73 100644
--- a/include/cobalt/kernel/pod.h
+++ b/include/cobalt/kernel/pod.h
@@ -66,12 +66,10 @@ struct xnsynch;
  */
 
 struct xnpod {
-
        xnflags_t status;       /*!< Status bitmask. */
-
        xnsched_t sched[NR_CPUS];       /*!< Per-cpu scheduler slots. */
-
-       xnqueue_t threadq;      /*!< All existing threads. */
+       struct list_head threadq;       /*!< All existing threads. */
+       int nrthreads;
 #ifdef CONFIG_XENO_OPT_VFILE
        struct xnvfile_rev_tag threadlist_tag;
 #endif
diff --git a/include/cobalt/kernel/ppd.h b/include/cobalt/kernel/ppd.h
index e418bc8..98efa27 100644
--- a/include/cobalt/kernel/ppd.h
+++ b/include/cobalt/kernel/ppd.h
@@ -1,7 +1,6 @@
 #ifndef _COBALT_KERNEL_PPD_H
 #define _COBALT_KERNEL_PPD_H
 
-#include <cobalt/kernel/queue.h>
 #include <cobalt/kernel/shadow.h>
 #include <cobalt/kernel/heap.h>
 
diff --git a/include/cobalt/kernel/thread.h b/include/cobalt/kernel/thread.h
index 1adb32e..7028263 100644
--- a/include/cobalt/kernel/thread.h
+++ b/include/cobalt/kernel/thread.h
@@ -233,9 +233,8 @@ typedef struct xnthread {
         */
        struct list_head plink;
 
-       xnholder_t glink;               /* Thread holder in global queue */
-
-#define link2thread(ln, fld)   container_of(ln, struct xnthread, fld)
+       /** Thread holder in global queue. */
+       struct list_head glink;
 
        /**
         * List of xnsynch owned by this thread _and_ claimed by
diff --git a/kernel/cobalt/pod.c b/kernel/cobalt/pod.c
index f987013..f83f3ce 100644
--- a/kernel/cobalt/pod.c
+++ b/kernel/cobalt/pod.c
@@ -146,8 +146,7 @@ void xnpod_fatal(const char *format, ...)
 {
        static char msg_buf[1024];
        struct xnthread *thread;
-       xnholder_t *holder;
-       xnsched_t *sched;
+       struct xnsched *sched;
        char pbuf[16];
        xnticks_t now;
        unsigned cpu;
@@ -174,19 +173,17 @@ void xnpod_fatal(const char *format, ...)
        printk(KERN_ERR "\n %-3s  %-6s %-8s %-8s %-8s  %s\n",
               "CPU", "PID", "PRI", "TIMEOUT", "STAT", "NAME");
 
+       /*
+        * NOTE: &nkpod->threadq can't be empty, we have the root
+        * thread(s) linked there at least.
+        */
        for_each_online_cpu(cpu) {
                sched = xnpod_sched_slot(cpu);
-
-               holder = getheadq(&nkpod->threadq);
-               while (holder) {
-                       thread = link2thread(holder, glink);
-                       holder = nextq(&nkpod->threadq, holder);
+               list_for_each_entry(thread, &nkpod->threadq, glink) {
                        if (thread->sched != sched)
                                continue;
-
                        cprio = xnthread_current_priority(thread);
                        snprintf(pbuf, sizeof(pbuf), "%3d", cprio);
-
                        printk(KERN_ERR "%c%3u  %-6d %-8s %-8Lu %.8lx  %s\n",
                               thread == sched->curr ? '>' : ' ',
                               cpu,
@@ -263,7 +260,8 @@ int xnpod_init(void)
 
        pod = &nkpod_struct;
        pod->status = 0;
-       initq(&pod->threadq);
+       INIT_LIST_HEAD(&pod->threadq);
+       pod->nrthreads = 0;
        atomic_set(&pod->timerlck, 0);
 
        xnlock_put_irqrestore(&nklock, s);
@@ -279,8 +277,10 @@ int xnpod_init(void)
        for_each_online_cpu(cpu) {
                sched = &pod->sched[cpu];
                xnsched_init(sched, cpu);
-               if (xnarch_cpu_supported(cpu))
-                       appendq(&pod->threadq, &sched->rootcb.glink);
+               if (xnarch_cpu_supported(cpu)) {
+                       list_add_tail(&sched->rootcb.glink, &pod->threadq);
+                       pod->nrthreads++;
+               }
        }
 
 #ifdef CONFIG_SMP
@@ -331,8 +331,7 @@ EXPORT_SYMBOL_GPL(xnpod_init);
 
 void xnpod_shutdown(int xtype)
 {
-       struct xnholder *h, *nh;
-       struct xnthread *thread;
+       struct xnthread *thread, *tmp;
        struct xnsched *sched;
        int cpu;
        spl_t s;
@@ -354,12 +353,8 @@ void xnpod_shutdown(int xtype)
 
        xnlock_get_irqsave(&nklock, s);
 
-       nh = getheadq(&nkpod->threadq);
-       while ((h = nh) != NULL) {
-               nh = nextq(&nkpod->threadq, h);
-
-               thread = link2thread(h, glink);
-
+       /* NOTE: &nkpod->threadq can't be empty (root thread(s)). */
+       list_for_each_entry_safe(thread, tmp, &nkpod->threadq, glink) {
                if (!xnthread_test_state(thread, XNROOT))
                        xnpod_cancel_thread(thread);
        }
@@ -469,7 +464,8 @@ int xnpod_init_thread(struct xnthread *thread,
                   sched_class->name, thread->cprio);
 
        xnlock_get_irqsave(&nklock, s);
-       appendq(&nkpod->threadq, &thread->glink);
+       list_add_tail(&thread->glink, &nkpod->threadq);
+       nkpod->nrthreads++;
        xnvfile_touch_tag(&nkpod->threadlist_tag);
        xnlock_put_irqrestore(&nklock, s);
 
@@ -773,7 +769,8 @@ static void cleanup_thread(struct xnthread *thread) /* 
nklock held, irqs off */
        trace_mark(xn_nucleus, thread_cleanup, "thread %p thread_name %s",
                   thread, xnthread_name(thread));
 
-       removeq(&nkpod->threadq, &thread->glink);
+       list_del(&thread->glink);
+       nkpod->nrthreads--;
        xnvfile_touch_tag(&nkpod->threadlist_tag);
 
        if (xnthread_test_state(thread, XNREADY)) {
diff --git a/kernel/cobalt/sched-rt.c b/kernel/cobalt/sched-rt.c
index 91a4b41..f403710 100644
--- a/kernel/cobalt/sched-rt.c
+++ b/kernel/cobalt/sched-rt.c
@@ -127,7 +127,7 @@ void xnsched_rt_trackprio(struct xnthread *thread,
 struct xnvfile_directory sched_rt_vfroot;
 
 struct vfile_sched_rt_priv {
-       struct xnholder *curr;
+       struct xnthread *curr;
 };
 
 struct vfile_sched_rt_data {
@@ -155,7 +155,7 @@ static int vfile_sched_rt_rewind(struct 
xnvfile_snapshot_iterator *it)
        if (nrthreads == 0)
                return -ESRCH;
 
-       priv->curr = getheadq(&nkpod->threadq);
+       priv->curr = list_first_entry(&nkpod->threadq, struct xnthread, glink);
 
        return nrthreads;
 }
@@ -170,8 +170,11 @@ static int vfile_sched_rt_next(struct 
xnvfile_snapshot_iterator *it,
        if (priv->curr == NULL)
                return 0;       /* All done. */
 
-       thread = link2thread(priv->curr, glink);
-       priv->curr = nextq(&nkpod->threadq, priv->curr);
+       thread = priv->curr;
+       if (list_is_last(&thread->glink, &nkpod->threadq))
+               priv->curr = NULL;
+       else
+               priv->curr = list_next_entry(thread, glink);
 
        if (thread->base_class != &xnsched_class_rt)
                return VFILE_SEQ_SKIP;
diff --git a/kernel/cobalt/sched-sporadic.c b/kernel/cobalt/sched-sporadic.c
index cc56c9f..3dce3e1 100644
--- a/kernel/cobalt/sched-sporadic.c
+++ b/kernel/cobalt/sched-sporadic.c
@@ -387,7 +387,7 @@ struct xnvfile_directory sched_sporadic_vfroot;
 
 struct vfile_sched_sporadic_priv {
        int nrthreads;
-       struct xnholder *curr;
+       struct xnthread *curr;
 };
 
 struct vfile_sched_sporadic_data {
@@ -419,7 +419,7 @@ static int vfile_sched_sporadic_rewind(struct 
xnvfile_snapshot_iterator *it)
        if (nrthreads == 0)
                return -ESRCH;
 
-       priv->curr = getheadq(&nkpod->threadq);
+       priv->curr = list_first_entry(&nkpod->threadq, struct xnthread, glink);
 
        return nrthreads;
 }
@@ -434,8 +434,11 @@ static int vfile_sched_sporadic_next(struct 
xnvfile_snapshot_iterator *it,
        if (priv->curr == NULL)
                return 0;       /* All done. */
 
-       thread = link2thread(priv->curr, glink);
-       priv->curr = nextq(&nkpod->threadq, priv->curr);
+       thread = priv->curr;
+       if (list_is_last(&thread->glink, &nkpod->threadq))
+               priv->curr = NULL;
+       else
+               priv->curr = list_next_entry(thread, glink);
 
        if (thread->base_class != &xnsched_class_sporadic)
                return VFILE_SEQ_SKIP;
diff --git a/kernel/cobalt/sched-tp.c b/kernel/cobalt/sched-tp.c
index 8186c0a..119d6c0 100644
--- a/kernel/cobalt/sched-tp.c
+++ b/kernel/cobalt/sched-tp.c
@@ -283,7 +283,7 @@ EXPORT_SYMBOL_GPL(xnsched_tp_get_partition);
 struct xnvfile_directory sched_tp_vfroot;
 
 struct vfile_sched_tp_priv {
-       struct xnholder *curr;
+       struct xnthread *curr;
 };
 
 struct vfile_sched_tp_data {
@@ -308,7 +308,10 @@ static int vfile_sched_tp_rewind(struct 
xnvfile_snapshot_iterator *it)
        struct vfile_sched_tp_priv *priv = xnvfile_iterator_priv(it);
        int nrthreads = xnsched_class_tp.nthreads;
 
-       priv->curr = getheadq(&nkpod->threadq);
+       if (nrthreads == 0)
+               return -ESRCH;
+
+       priv->curr = list_first_entry(&nkpod->threadq, struct xnthread, glink);
 
        return nrthreads;
 }
@@ -323,8 +326,11 @@ static int vfile_sched_tp_next(struct 
xnvfile_snapshot_iterator *it,
        if (priv->curr == NULL)
                return 0;       /* All done. */
 
-       thread = link2thread(priv->curr, glink);
-       priv->curr = nextq(&nkpod->threadq, priv->curr);
+       thread = priv->curr;
+       if (list_is_last(&thread->glink, &nkpod->threadq))
+               priv->curr = NULL;
+       else
+               priv->curr = list_next_entry(thread, glink);
 
        if (thread->base_class != &xnsched_class_tp)
                return VFILE_SEQ_SKIP;
diff --git a/kernel/cobalt/sched-weak.c b/kernel/cobalt/sched-weak.c
index 21b1b0f..133fa6e 100644
--- a/kernel/cobalt/sched-weak.c
+++ b/kernel/cobalt/sched-weak.c
@@ -78,7 +78,7 @@ void xnsched_weak_trackprio(struct xnthread *thread,
 struct xnvfile_directory sched_weak_vfroot;
 
 struct vfile_sched_weak_priv {
-       struct xnholder *curr;
+       struct xnthread *curr;
 };
 
 struct vfile_sched_weak_data {
@@ -105,7 +105,7 @@ static int vfile_sched_weak_rewind(struct 
xnvfile_snapshot_iterator *it)
        if (nrthreads == 0)
                return -ESRCH;
 
-       priv->curr = getheadq(&nkpod->threadq);
+       priv->curr = list_first_entry(&nkpod->threadq, struct xnthread, glink);
 
        return nrthreads;
 }
@@ -120,8 +120,11 @@ static int vfile_sched_weak_next(struct 
xnvfile_snapshot_iterator *it,
        if (priv->curr == NULL)
                return 0;       /* All done. */
 
-       thread = link2thread(priv->curr, glink);
-       priv->curr = nextq(&nkpod->threadq, priv->curr);
+       thread = priv->curr;
+       if (list_is_last(&thread->glink, &nkpod->threadq))
+               priv->curr = NULL;
+       else
+               priv->curr = list_next_entry(thread, glink);
 
        if (thread->base_class != &xnsched_class_weak)
                return VFILE_SEQ_SKIP;
diff --git a/kernel/cobalt/sched.c b/kernel/cobalt/sched.c
index 808d461..2f2cd1a 100644
--- a/kernel/cobalt/sched.c
+++ b/kernel/cobalt/sched.c
@@ -618,7 +618,7 @@ struct xnthread *sched_findq(struct list_head *q, int prio)
 static struct xnvfile_directory sched_vfroot;
 
 struct vfile_schedlist_priv {
-       struct xnholder *curr;
+       struct xnthread *curr;
        xnticks_t start_time;
 };
 
@@ -645,10 +645,11 @@ static int vfile_schedlist_rewind(struct 
xnvfile_snapshot_iterator *it)
 {
        struct vfile_schedlist_priv *priv = xnvfile_iterator_priv(it);
 
-       priv->curr = getheadq(&nkpod->threadq);
+       /* &nkpod->threadq cannot be empty (root thread(s)). */
+       priv->curr = list_first_entry(&nkpod->threadq, struct xnthread, glink);
        priv->start_time = xnclock_read_monotonic();
 
-       return countq(&nkpod->threadq);
+       return nkpod->nrthreads;
 }
 
 static int vfile_schedlist_next(struct xnvfile_snapshot_iterator *it,
@@ -662,8 +663,11 @@ static int vfile_schedlist_next(struct 
xnvfile_snapshot_iterator *it,
        if (priv->curr == NULL)
                return 0;       /* All done. */
 
-       thread = link2thread(priv->curr, glink);
-       priv->curr = nextq(&nkpod->threadq, priv->curr);
+       thread = priv->curr;
+       if (list_is_last(&thread->glink, &nkpod->threadq))
+               priv->curr = NULL;
+       else
+               priv->curr = list_next_entry(thread, glink);
 
        p->cpu = xnsched_cpu(thread->sched);
        p->pid = xnthread_host_pid(thread);
@@ -733,7 +737,7 @@ static struct xnvfile_snapshot_ops vfile_schedlist_ops = {
 
 struct vfile_schedstat_priv {
        int irq;
-       struct xnholder *curr;
+       struct xnthread *curr;
        struct xnintr_iterator intr_it;
 };
 
@@ -772,11 +776,11 @@ static int vfile_schedstat_rewind(struct 
xnvfile_snapshot_iterator *it)
         * The activity numbers on each valid interrupt descriptor are
         * grouped under a pseudo-thread.
         */
-       priv->curr = getheadq(&nkpod->threadq);
+       priv->curr = list_first_entry(&nkpod->threadq, struct xnthread, glink);
        priv->irq = 0;
        irqnr = xnintr_query_init(&priv->intr_it) * NR_CPUS;
 
-       return irqnr + countq(&nkpod->threadq);
+       return irqnr + nkpod->nrthreads;
 }
 
 static int vfile_schedstat_next(struct xnvfile_snapshot_iterator *it,
@@ -796,8 +800,11 @@ static int vfile_schedstat_next(struct 
xnvfile_snapshot_iterator *it,
                 */
                goto scan_irqs;
 
-       thread = link2thread(priv->curr, glink);
-       priv->curr = nextq(&nkpod->threadq, priv->curr);
+       thread = priv->curr;
+       if (list_is_last(&thread->glink, &nkpod->threadq))
+               priv->curr = NULL;
+       else
+               priv->curr = list_next_entry(thread, glink);
 
        sched = thread->sched;
        p->cpu = xnsched_cpu(sched);
diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c
index 48d0734..71921e0 100644
--- a/kernel/cobalt/thread.c
+++ b/kernel/cobalt/thread.c
@@ -180,7 +180,6 @@ int xnthread_init(struct xnthread *thread,
        thread->entry = NULL;
        thread->cookie = NULL;
 
-       inith(&thread->glink);
        thread->selector = NULL;
        INIT_LIST_HEAD(&thread->claimq);
 


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

Reply via email to