Module: xenomai-rpm Branch: queue/vfile Commit: b719997903a57e3d996646acdbe4692012e11fd3 URL: http://git.xenomai.org/?p=xenomai-rpm.git;a=commit;h=b719997903a57e3d996646acdbe4692012e11fd3
Author: Philippe Gerum <r...@xenomai.org> Date: Sun Jun 6 19:06:33 2010 +0200 vxworks: convert to vfile --- ksrc/skins/vxworks/module.c | 9 +-- ksrc/skins/vxworks/msgQLib.c | 133 ++++++++++++++++++++++++-------------- ksrc/skins/vxworks/semLib.c | 147 +++++++++++++++++++++++++++--------------- ksrc/skins/vxworks/wdLib.c | 121 ++++++++++++++++++++++------------- 4 files changed, 256 insertions(+), 154 deletions(-) diff --git a/ksrc/skins/vxworks/module.c b/ksrc/skins/vxworks/module.c index 830df76..632f5d2 100644 --- a/ksrc/skins/vxworks/module.c +++ b/ksrc/skins/vxworks/module.c @@ -39,14 +39,7 @@ xntbase_t *wind_tbase; wind_rholder_t __wind_global_rholder; -#ifdef CONFIG_PROC_FS -xnptree_t __vxworks_ptree = { - - .dir = NULL, - .name = "vxworks", - .entries = 0, -}; -#endif /* CONFIG_PROC_FS */ +DEFINE_XNPTREE(__vxworks_ptree, "vxworks"); int SKIN_INIT(vxworks) { diff --git a/ksrc/skins/vxworks/msgQLib.c b/ksrc/skins/vxworks/msgQLib.c index 0acb574..f762635 100644 --- a/ksrc/skins/vxworks/msgQLib.c +++ b/ksrc/skins/vxworks/msgQLib.c @@ -24,69 +24,102 @@ static int msgq_destroy_internal(wind_msgq_t *queue); #ifdef CONFIG_PROC_FS -static int msgq_read_proc(char *page, - char **start, - off_t off, int count, int *eof, void *data) -{ - wind_msgq_t *queue = (wind_msgq_t *)data; - char *p = page; - int len; - spl_t s; - - p += sprintf(p, "porder=%s:mlength=%u:mcount=%d\n", - xnsynch_test_flags(&queue->synchbase, - XNSYNCH_PRIO) ? "prio" : "fifo", - queue->msg_length, countq(&queue->msgq)); - - xnlock_get_irqsave(&nklock, s); - - if (xnsynch_nsleepers(&queue->synchbase) > 0) { - xnpholder_t *holder; +struct vfile_priv { + struct xnpholder *curr; + int flags; + unsigned int mlength; + int mcount; +}; - /* Pended queue -- dump waiters. */ +struct vfile_data { + char name[XNOBJECT_NAME_LEN]; +}; - holder = getheadpq(xnsynch_wait_queue(&queue->synchbase)); +static int vfile_rewind(struct xnvfile_snapshot_iterator *it) +{ + struct vfile_priv *priv = xnvfile_iterator_priv(it); + wind_msgq_t *q = xnvfile_priv(it->vfile); - while (holder) { - xnthread_t *sleeper = link2thread(holder, plink); - p += sprintf(p, "+%s\n", xnthread_name(sleeper)); - holder = - nextpq(xnsynch_wait_queue(&queue->synchbase), - holder); - } - } + q = wind_h2obj_active((MSG_Q_ID)q, WIND_MSGQ_MAGIC, wind_msgq_t); + if (q == NULL) + return -EIDRM; - xnlock_put_irqrestore(&nklock, s); + priv->curr = getheadpq(xnsynch_wait_queue(&q->synchbase)); + priv->flags = xnsynch_test_flags(&q->synchbase, XNSYNCH_PRIO); + priv->mlength = q->msg_length; + priv->mcount = countq(&q->msgq); - len = (p - page) - off; - if (len <= off + count) - *eof = 1; - *start = page + off; - if (len > count) - len = count; - if (len < 0) - len = 0; + return xnsynch_nsleepers(&q->synchbase); +} - return len; +static int vfile_next(struct xnvfile_snapshot_iterator *it, void *data) +{ + struct vfile_priv *priv = xnvfile_iterator_priv(it); + wind_msgq_t *q = xnvfile_priv(it->vfile); + struct vfile_data *p = data; + struct xnthread *thread; + + if (priv->curr == NULL) + return 0; /* We are done. */ + + /* Fetch current waiter, advance list cursor. */ + thread = link2thread(priv->curr, plink); + priv->curr = nextpq(xnsynch_wait_queue(&q->synchbase), + priv->curr); + /* Collect thread name to be output in ->show(). */ + strncpy(p->name, xnthread_name(thread), sizeof(p->name)); + + return 1; } -extern xnptree_t __vxworks_ptree; +static int vfile_show(struct xnvfile_snapshot_iterator *it, void *data) +{ + struct vfile_priv *priv = xnvfile_iterator_priv(it); + struct vfile_data *p = data; + + if (p == NULL) { /* Dump header. */ + xnvfile_printf(it, + "porder=%s:mlength=%u:mcount=%d\n", + priv->flags ? "prio" : "fifo", + priv->mlength, + priv->mcount); + if (it->nrdata > 0) + /* Queue is pended -- dump waiters */ + xnvfile_printf(it, "-------------------------------------------\n"); + } else + xnvfile_printf(it, "%.*s\n", + (int)sizeof(p->name), p->name); + + return 0; +} -static xnpnode_t msgq_pnode = { +static struct xnvfile_snapshot_ops vfile_ops = { + .rewind = vfile_rewind, + .next = vfile_next, + .show = vfile_show, +}; - .dir = NULL, - .type = "msgq", - .entries = 0, - .read_proc = &msgq_read_proc, - .write_proc = NULL, - .root = &__vxworks_ptree, +extern struct xnptree __vxworks_ptree; + +static struct xnpnode_file __msgq_pnode = { + .node = { + .dirname = "msgq", + .root = &__vxworks_ptree, + .ops = &xnregistry_vfile_ops, + }, + .vfile = { + .privsz = sizeof(struct vfile_priv), + .datasz = sizeof(struct vfile_data), + .ops = &vfile_ops, + }, }; #else /* !CONFIG_PROC_FS */ -static xnpnode_t msgq_pnode = { - - .type = "msgq" +static struct xnpnode_file __msgq_pnode = { + .node = { + .dirname = "msgq", + }, }; #endif /* !CONFIG_PROC_FS */ @@ -189,7 +222,7 @@ MSG_Q_ID msgQCreate(int nb_msgs, int length, int flags) sprintf(queue->name, "mq%lu", msgq_ids++); if (xnregistry_enter(queue->name, queue, - &queue->handle, &msgq_pnode)) { + &queue->handle, &__msgq_pnode.node)) { wind_errnoset(S_objLib_OBJ_ID_ERROR); msgQDelete((MSG_Q_ID)queue); return 0; diff --git a/ksrc/skins/vxworks/semLib.c b/ksrc/skins/vxworks/semLib.c index cb27706..f5a57d6 100644 --- a/ksrc/skins/vxworks/semLib.c +++ b/ksrc/skins/vxworks/semLib.c @@ -35,74 +35,117 @@ static SEM_ID sem_create_internal(int flags, const sem_vtbl_t *vtbl, int count); #ifdef CONFIG_PROC_FS -static int sem_read_proc(char *page, - char **start, - off_t off, int count, int *eof, void *data) +struct vfile_priv { + struct xnpholder *curr; + const char *type; + char owner[XNOBJECT_NAME_LEN]; + unsigned int count; +}; + +struct vfile_data { + char name[XNOBJECT_NAME_LEN]; +}; + +static int vfile_rewind(struct xnvfile_snapshot_iterator *it) { - wind_sem_t *sem = (wind_sem_t *)data; - xnpholder_t *holder; - xnthread_t *sleeper; - char *p = page; - xnpqueue_t *q; - int len; - spl_t s; + struct vfile_priv *priv = xnvfile_iterator_priv(it); + wind_sem_t *sem = xnvfile_priv(it->vfile); + struct xnthread *owner; - xnlock_get_irqsave(&nklock, s); + sem = wind_h2obj_active((SEM_ID)sem, WIND_SEM_MAGIC, wind_sem_t); + if (sem == NULL) + return -EIDRM; - p += sprintf(p, "type=%s:", sem->vtbl->type); + priv->curr = getheadpq(xnsynch_wait_queue(&sem->synchbase)); + priv->type = sem->vtbl->type; if (sem->vtbl == &semm_vtbl) { - p += sprintf(p, "state=%s", xnsynch_owner(&sem->synchbase) ? "locked" : "unlocked"); - if (xnsynch_owner(&sem->synchbase) != NULL) - p += sprintf(p, " (%s)\n", - xnthread_name(xnsynch_owner(&sem->synchbase))); + owner = xnsynch_owner(&sem->synchbase); + if (owner) + strncpy(priv->owner, xnthread_name(owner), + sizeof(priv->owner)); else - p += sprintf(p, "\n"); + *priv->owner = 0; + priv->count = -1U; } else - p += sprintf(p, "value=%u\n", sem->count); - - q = xnsynch_wait_queue(&sem->synchbase); - if (xnsynch_nsleepers(&sem->synchbase) > 0) { - /* Pended semaphore -- dump waiters. */ - holder = getheadpq(q); - while (holder) { - sleeper = link2thread(holder, plink); - p += sprintf(p, "+%s\n", xnthread_name(sleeper)); - holder = nextpq(q, holder); - } - } - - xnlock_put_irqrestore(&nklock, s); + priv->count = sem->count; - len = (p - page) - off; - if (len <= off + count) - *eof = 1; - *start = page + off; - if (len > count) - len = count; - if (len < 0) - len = 0; + return xnsynch_nsleepers(&sem->synchbase); +} - return len; +static int vfile_next(struct xnvfile_snapshot_iterator *it, void *data) +{ + struct vfile_priv *priv = xnvfile_iterator_priv(it); + wind_sem_t *sem = xnvfile_priv(it->vfile); + struct vfile_data *p = data; + struct xnthread *thread; + + if (priv->curr == NULL) + return 0; /* We are done. */ + + /* Fetch current waiter, advance list cursor. */ + thread = link2thread(priv->curr, plink); + priv->curr = nextpq(xnsynch_wait_queue(&sem->synchbase), + priv->curr); + /* Collect thread name to be output in ->show(). */ + strncpy(p->name, xnthread_name(thread), sizeof(p->name)); + + return 1; } -extern xnptree_t __vxworks_ptree; +static int vfile_show(struct xnvfile_snapshot_iterator *it, void *data) +{ + struct vfile_priv *priv = xnvfile_iterator_priv(it); + struct vfile_data *p = data; + + if (p == NULL) { /* Dump header. */ + if (priv->count == -1U) { + xnvfile_printf(it, + "state=%s", *priv->owner ? + "locked" : "unlocked"); + if (*priv->owner) + xnvfile_printf(it, " (%s)\n", priv->owner); + else + xnvfile_printf(it, "\n"); + } else + xnvfile_printf(it, "value=%u\n", priv->count); + if (it->nrdata > 0) + /* Semaphore is pended -- dump waiters */ + xnvfile_printf(it, "-------------------------------------------\n"); + } else + xnvfile_printf(it, "%.*s\n", + (int)sizeof(p->name), p->name); -static xnpnode_t sem_pnode = { + return 0; +} - .dir = NULL, - .type = "semaphores", - .entries = 0, - .read_proc = &sem_read_proc, - .write_proc = NULL, - .root = &__vxworks_ptree, +static struct xnvfile_snapshot_ops vfile_ops = { + .rewind = vfile_rewind, + .next = vfile_next, + .show = vfile_show, }; -#else /* !CONFIG_PROC_FS */ +extern struct xnptree __vxworks_ptree; + +static struct xnpnode_file __sem_pnode = { + .node = { + .dirname = "semaphores", + .root = &__vxworks_ptree, + .ops = &xnregistry_vfile_ops, + }, + .vfile = { + .privsz = sizeof(struct vfile_priv), + .datasz = sizeof(struct vfile_data), + .ops = &vfile_ops, + }, +}; -static xnpnode_t sem_pnode = { +#else /* !CONFIG_PROC_FS */ - .type = "semaphores" +static struct xnpnode_file __sem_pnode = { + .node = { + .dirname = "semaphores", + }, }; #endif /* !CONFIG_PROC_FS */ @@ -446,7 +489,7 @@ static SEM_ID sem_create_internal(int flags, const sem_vtbl_t *vtbl, int count) sprintf(sem->name, "sem%lu", sem_ids++); - if (xnregistry_enter(sem->name, sem, &sem->handle, &sem_pnode)) { + if (xnregistry_enter(sem->name, sem, &sem->handle, &__sem_pnode.node)) { wind_errnoset(S_objLib_OBJ_ID_ERROR); semDelete((SEM_ID)sem); return 0; diff --git a/ksrc/skins/vxworks/wdLib.c b/ksrc/skins/vxworks/wdLib.c index 0e3fb2c..b1b80c5 100644 --- a/ksrc/skins/vxworks/wdLib.c +++ b/ksrc/skins/vxworks/wdLib.c @@ -26,64 +26,97 @@ static void wd_destroy_internal(wind_wd_t *wd); #ifdef CONFIG_PROC_FS -static int wd_read_proc(char *page, - char **start, - off_t off, int count, int *eof, void *data) +struct vfile_priv { + struct xnpholder *curr; + xnticks_t timeout; +}; + +struct vfile_data { + char name[XNOBJECT_NAME_LEN]; +}; + +static int vfile_rewind(struct xnvfile_snapshot_iterator *it) { - wind_wd_t *wd = (wind_wd_t *)data; - char *p = page; - int len; - spl_t s; + struct vfile_priv *priv = xnvfile_iterator_priv(it); + wind_wd_t *wd = xnvfile_priv(it->vfile); - xnlock_get_irqsave(&nklock, s); + wd = wind_h2obj_active((WDOG_ID)wd, WIND_WD_MAGIC, wind_wd_t); + if (wd == NULL) + return -EIDRM; - p += sprintf(p, "timeout=%lld\n", xntimer_get_timeout(&wd->timerbase)); + priv->curr = getheadpq(xnsynch_wait_queue(&wd->rh->wdsynch)); + priv->timeout = xntimer_get_timeout(&wd->timerbase); -#ifdef CONFIG_XENO_OPT_PERVASIVE - { - xnpholder_t *holder = - getheadpq(xnsynch_wait_queue(&wd->rh->wdsynch)); - - while (holder) { - xnthread_t *sleeper = link2thread(holder, plink); - p += sprintf(p, "+%s\n", xnthread_name(sleeper)); - holder = - nextpq(xnsynch_wait_queue(&wd->rh->wdsynch), holder); - } - } -#endif /* CONFIG_XENO_OPT_PERVASIVE */ + return xnsynch_nsleepers(&wd->rh->wdsynch); +} - xnlock_put_irqrestore(&nklock, s); +static int vfile_next(struct xnvfile_snapshot_iterator *it, void *data) +{ + struct vfile_priv *priv = xnvfile_iterator_priv(it); + wind_wd_t *wd = xnvfile_priv(it->vfile); + struct vfile_data *p = data; + struct xnthread *thread; + + /* Refresh as we collect. */ + priv->timeout = xntimer_get_timeout(&wd->timerbase); + + if (priv->curr == NULL) + return 0; /* We are done. */ - len = (p - page) - off; - if (len <= off + count) - *eof = 1; - *start = page + off; - if (len > count) - len = count; - if (len < 0) - len = 0; + /* Fetch current waiter, advance list cursor. */ + thread = link2thread(priv->curr, plink); + priv->curr = nextpq(xnsynch_wait_queue(&wd->rh->wdsynch), + priv->curr); + /* Collect thread name to be output in ->show(). */ + strncpy(p->name, xnthread_name(thread), sizeof(p->name)); - return len; + return 1; } -extern xnptree_t __vxworks_ptree; +static int vfile_show(struct xnvfile_snapshot_iterator *it, void *data) +{ + struct vfile_priv *priv = xnvfile_iterator_priv(it); + struct vfile_data *p = data; + + if (p == NULL) { /* Dump header. */ + xnvfile_printf(it, "timeout=%Lu\n", priv->timeout); + if (it->nrdata > 0) + /* Watchdog is pended -- dump waiters */ + xnvfile_printf(it, "-------------------------------------------\n"); + } else + xnvfile_printf(it, "%.*s\n", + (int)sizeof(p->name), p->name); + + return 0; +} -static xnpnode_t wd_pnode = { +static struct xnvfile_snapshot_ops vfile_ops = { + .rewind = vfile_rewind, + .next = vfile_next, + .show = vfile_show, +}; - .dir = NULL, - .type = "watchdogs", - .entries = 0, - .read_proc = &wd_read_proc, - .write_proc = NULL, - .root = &__vxworks_ptree, +extern struct xnptree __vxworks_ptree; + +static struct xnpnode_file __wd_pnode = { + .node = { + .dirname = "watchdogs", + .root = &__vxworks_ptree, + .ops = &xnregistry_vfile_ops, + }, + .vfile = { + .privsz = sizeof(struct vfile_priv), + .datasz = sizeof(struct vfile_data), + .ops = &vfile_ops, + }, }; #else /* !CONFIG_PROC_FS */ -static xnpnode_t wd_pnode = { - - .type = "watchdogs" +static struct xnpnode_file __wd_pnode = { + .node = { + .dirname = "watchdogs", + }, }; #endif /* !CONFIG_PROC_FS */ @@ -129,7 +162,7 @@ WDOG_ID wdCreate(void) sprintf(wd->name, "wd%lu", wd_ids++); - if (xnregistry_enter(wd->name, wd, &wd->handle, &wd_pnode)) { + if (xnregistry_enter(wd->name, wd, &wd->handle, &__wd_pnode.node)) { wind_errnoset(S_objLib_OBJ_ID_ERROR); wdDelete((WDOG_ID)wd); return 0; _______________________________________________ Xenomai-git mailing list Xenomai-git@gna.org https://mail.gna.org/listinfo/xenomai-git