Module: xenomai-rpm Branch: queue/vfile Commit: 5bc6830b08b2484a14539332272ab76cbcfdb634 URL: http://git.xenomai.org/?p=xenomai-rpm.git;a=commit;h=5bc6830b08b2484a14539332272ab76cbcfdb634
Author: Philippe Gerum <[email protected]> Date: Tue Jun 1 16:47:00 2010 +0200 uitron: convert to vfile --- ksrc/skins/uitron/flag.c | 142 +++++++++++++++++++++++++++++++------------- ksrc/skins/uitron/mbx.c | 138 +++++++++++++++++++++++++++++------------- ksrc/skins/uitron/module.c | 9 +--- ksrc/skins/uitron/sem.c | 137 +++++++++++++++++++++++++++++------------- 4 files changed, 291 insertions(+), 135 deletions(-) diff --git a/ksrc/skins/uitron/flag.c b/ksrc/skins/uitron/flag.c index c7f3c0d..5538ec9 100644 --- a/ksrc/skins/uitron/flag.c +++ b/ksrc/skins/uitron/flag.c @@ -25,65 +25,123 @@ static xnmap_t *ui_flag_idmap; #ifdef CONFIG_PROC_FS -static int __flag_read_proc(char *page, - char **start, - off_t off, int count, int *eof, void *data) +struct vfile_priv { + int nrdata; + struct xnpholder *curr; + unsigned long value; +}; + +struct vfile_data { + UINT wfmode; + UINT waiptn; + char name[XNOBJECT_NAME_LEN]; +}; + +static int vfile_rewind(struct xnvfile_snapshot_iterator *it) { - uiflag_t *flag = (uiflag_t *)data; - char *p = page; - int len; - spl_t s; + struct vfile_priv *priv = xnvfile_snapshot_iterator_priv(it); + struct uiflag *flag = xnvfile_priv(it->vfile); - xnlock_get_irqsave(&nklock, s); + priv->nrdata = xnsynch_nsleepers(&flag->synchbase); + priv->curr = getheadpq(xnsynch_wait_queue(&flag->synchbase)); + priv->value = flag->flgvalue; - p += sprintf(p, "=0x%x, attr=%s\n", flag->flgvalue, - flag->flgatr & TA_WMUL ? "TA_WMUL" : "TA_WSGL"); + return 0; +} - if (xnsynch_nsleepers(&flag->synchbase) > 0) { - xnpholder_t *holder; +static void *vfile_begin(struct xnvfile_snapshot_iterator *it) +{ + struct vfile_priv *priv = xnvfile_snapshot_iterator_priv(it); - /* Pended flag -- dump waiters. */ + if (priv->nrdata == 0) + /* No output beside the header. */ + return VFILE_SEQ_EMPTY; - holder = getheadpq(xnsynch_wait_queue(&flag->synchbase)); + return kmalloc(priv->nrdata * sizeof(struct vfile_data), + GFP_KERNEL); +} - while (holder) { - xnthread_t *sleeper = link2thread(holder, plink); - p += sprintf(p, "+%s\n", xnthread_name(sleeper)); - holder = nextpq(xnsynch_wait_queue(&flag->synchbase), holder); - } - } +static void vfile_end(struct xnvfile_snapshot_iterator *it, void *buf) +{ + kfree(buf); +} - xnlock_put_irqrestore(&nklock, s); +static int vfile_next(struct xnvfile_snapshot_iterator *it, void *data) +{ + struct vfile_priv *priv = xnvfile_snapshot_iterator_priv(it); + struct uiflag *flag = xnvfile_priv(it->vfile); + struct vfile_data *p = data; + struct xnthread *thread; + struct uitask *task; + + priv->value = flag->flgvalue; /* Refresh as we collect. */ - len = (p - page) - off; - if (len <= off + count) - *eof = 1; - *start = page + off; - if (len > count) - len = count; - if (len < 0) - len = 0; + if (priv->curr == NULL) + return 0; /* We are done. */ - return len; + /* Fetch current waiter, advance list cursor. */ + thread = link2thread(priv->curr, plink); + priv->curr = nextpq(xnsynch_wait_queue(&flag->synchbase), + priv->curr); + + /* Collect thread name to be output in ->show(). */ + strncpy(p->name, xnthread_name(thread), sizeof(p->name)); + task = thread2uitask(thread); + p->wfmode = task->wargs.flag.wfmode; + p->waiptn = task->wargs.flag.waiptn; + + return 1; } -extern xnptree_t __uitron_ptree; +static int vfile_show(struct xnvfile_snapshot_iterator *it, void *data) +{ + struct vfile_priv *priv = xnvfile_snapshot_iterator_priv(it); + struct vfile_data *p = data; + + if (p == NULL) { /* Dump header. */ + /* Always dump current event mask value. */ + xnvfile_printf(it, "=0x%lx\n", priv->value); + if (priv->nrdata > 0) + xnvfile_printf(it, "\n%10s %4s %s\n", + "WAITPN", "WFMODE", "WAITER"); + } else + xnvfile_printf(it, "0x%-8x %4s %.*s\n", + p->waiptn, + p->wfmode & TWF_ORW ? "OR" : "AND", + (int)sizeof(p->name), p->name); -static xnpnode_t __flag_pnode = { + return 0; +} - .dir = NULL, - .type = "flags", - .entries = 0, - .read_proc = &__flag_read_proc, - .write_proc = NULL, - .root = &__uitron_ptree, +static struct xnvfile_snapshot_ops vfile_ops = { + .rewind = vfile_rewind, + .begin = vfile_begin, + .next = vfile_next, + .end = vfile_end, + .show = vfile_show, }; -#else /* !CONFIG_PROC_FS */ +extern struct xnptree __uitron_ptree; + +static struct xnpnode_file __flag_pnode = { + .node = { + .dirname = "flags", + .root = &__uitron_ptree, + .ops = &xnregistry_vfile_ops, + }, + .vfile = { + .privsz = sizeof(struct vfile_priv), + .datasz = sizeof(struct vfile_data), + .ops = &vfile_ops, + }, +}; -static xnpnode_t __flag_pnode = { +#else /* !CONFIG_PROC_FS */ - .type = "flags" +static struct xnpnode_file __flag_pnode = { + .node = { + .dirname = "flags", + }, }; #endif /* !CONFIG_PROC_FS */ @@ -128,7 +186,7 @@ ER cre_flg(ID flgid, T_CFLG *pk_cflg) flag->flgatr = pk_cflg->flgatr; flag->flgvalue = pk_cflg->iflgptn; sprintf(flag->name, "flg%d", flgid); - xnregistry_enter(flag->name, flag, &flag->handle, &__flag_pnode); + xnregistry_enter(flag->name, flag, &flag->handle, &__flag_pnode.node); xnarch_memory_barrier(); flag->magic = uITRON_FLAG_MAGIC; diff --git a/ksrc/skins/uitron/mbx.c b/ksrc/skins/uitron/mbx.c index 746919c..47ff4a3 100644 --- a/ksrc/skins/uitron/mbx.c +++ b/ksrc/skins/uitron/mbx.c @@ -25,66 +25,118 @@ static xnmap_t *ui_mbx_idmap; #ifdef CONFIG_PROC_FS -static int __mbx_read_proc(char *page, - char **start, - off_t off, int count, int *eof, void *data) +struct vfile_priv { + int nrdata; + struct xnpholder *curr; + int mcount; + int bufcnt; + int mbxatr; +}; + +struct vfile_data { + char name[XNOBJECT_NAME_LEN]; +}; + +static int vfile_rewind(struct xnvfile_snapshot_iterator *it) { - uimbx_t *mbx = (uimbx_t *)data; - char *p = page; - int len; - spl_t s; + struct vfile_priv *priv = xnvfile_snapshot_iterator_priv(it); + struct uimbx *mbx = xnvfile_priv(it->vfile); - xnlock_get_irqsave(&nklock, s); + priv->nrdata = xnsynch_nsleepers(&mbx->synchbase); + priv->curr = getheadpq(xnsynch_wait_queue(&mbx->synchbase)); + priv->mcount = mbx->mcount; + priv->bufcnt = mbx->bufcnt; + priv->mbxatr = mbx->mbxatr; - p += sprintf(p, "%d/%d message(s), attr=%s\n", - mbx->mcount, mbx->bufcnt, - mbx->mbxatr & TA_TPRI ? "TA_TPRI" : "TA_TFIFO"); + return 0; +} - if (xnsynch_pended_p(&mbx->synchbase)) { - xnpholder_t *holder; +static void *vfile_begin(struct xnvfile_snapshot_iterator *it) +{ + struct vfile_priv *priv = xnvfile_snapshot_iterator_priv(it); - /* Pended mbx -- dump waiters. */ + if (priv->nrdata == 0) + /* No output beside the header. */ + return VFILE_SEQ_EMPTY; - holder = getheadpq(xnsynch_wait_queue(&mbx->synchbase)); + return kmalloc(priv->nrdata * sizeof(struct vfile_data), + GFP_KERNEL); +} - while (holder) { - xnthread_t *sleeper = link2thread(holder, plink); - p += sprintf(p, "+%s\n", xnthread_name(sleeper)); - holder = nextpq(xnsynch_wait_queue(&mbx->synchbase), holder); - } - } +static void vfile_end(struct xnvfile_snapshot_iterator *it, void *buf) +{ + kfree(buf); +} - xnlock_put_irqrestore(&nklock, s); +static int vfile_next(struct xnvfile_snapshot_iterator *it, void *data) +{ + struct vfile_priv *priv = xnvfile_snapshot_iterator_priv(it); + struct uimbx *mbx = xnvfile_priv(it->vfile); + struct vfile_data *p = data; + struct xnthread *thread; - len = (p - page) - off; - if (len <= off + count) - *eof = 1; - *start = page + off; - if (len > count) - len = count; - if (len < 0) - len = 0; + if (priv->curr == NULL) + return 0; /* We are done. */ - return len; + /* Fetch current waiter, advance list cursor. */ + thread = link2thread(priv->curr, plink); + priv->curr = nextpq(xnsynch_wait_queue(&mbx->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 __uitron_ptree; +static int vfile_show(struct xnvfile_snapshot_iterator *it, void *data) +{ + struct vfile_priv *priv = xnvfile_snapshot_iterator_priv(it); + struct vfile_data *p = data; + + if (p == NULL) { /* Dump header. */ + /* Always dump current event mask value. */ + xnvfile_printf(it, "%d/%d message(s), attr=%s\n", + priv->mcount, priv->bufcnt, + priv->mbxatr & TA_TPRI ? "TA_TPRI" : "TA_TFIFO"); + if (priv->nrdata > 0) + xnvfile_printf(it, "--------------------\n"); + } else + xnvfile_printf(it, "%.*s\n", + (int)sizeof(p->name), p->name); -static xnpnode_t __mbx_pnode = { + return 0; +} - .dir = NULL, - .type = "mailboxes", - .entries = 0, - .read_proc = &__mbx_read_proc, - .write_proc = NULL, - .root = &__uitron_ptree, +static struct xnvfile_snapshot_ops vfile_ops = { + .rewind = vfile_rewind, + .begin = vfile_begin, + .next = vfile_next, + .end = vfile_end, + .show = vfile_show, }; -#else /* !CONFIG_PROC_FS */ +extern struct xnptree __uitron_ptree; + +static struct xnpnode_file __mbx_pnode = { + .node = { + .dirname = "mailboxes", + .root = &__uitron_ptree, + .ops = &xnregistry_vfile_ops, + }, + .vfile = { + .privsz = sizeof(struct vfile_priv), + .datasz = sizeof(struct vfile_data), + .ops = &vfile_ops, + }, +}; -static xnpnode_t __mbx_pnode = { +#else /* !CONFIG_PROC_FS */ - .type = "mailboxes" +static struct xnpnode_file __mbx_pnode = { + .node = { + .dirname = "mailboxes", + }, }; #endif /* !CONFIG_PROC_FS */ @@ -150,7 +202,7 @@ ER cre_mbx(ID mbxid, T_CMBX *pk_cmbx) mbx->mcount = 0; mbx->ring = ring; sprintf(mbx->name, "mbx%d", mbxid); - xnregistry_enter(mbx->name, mbx, &mbx->handle, &__mbx_pnode); + xnregistry_enter(mbx->name, mbx, &mbx->handle, &__mbx_pnode.node); xnarch_memory_barrier(); mbx->magic = uITRON_MBX_MAGIC; diff --git a/ksrc/skins/uitron/module.c b/ksrc/skins/uitron/module.c index 26b5bf8..259be00 100644 --- a/ksrc/skins/uitron/module.c +++ b/ksrc/skins/uitron/module.c @@ -40,14 +40,7 @@ xntbase_t *ui_tbase; ui_rholder_t __ui_global_rholder; -#ifdef CONFIG_PROC_FS -xnptree_t __uitron_ptree = { - - .dir = NULL, - .name = "uitron", - .entries = 0, -}; -#endif /* CONFIG_PROC_FS */ +DEFINE_XNPTREE(__uitron_ptree, "uitron"); int SKIN_INIT(uitron) { diff --git a/ksrc/skins/uitron/sem.c b/ksrc/skins/uitron/sem.c index aceeaef..4add7fe 100644 --- a/ksrc/skins/uitron/sem.c +++ b/ksrc/skins/uitron/sem.c @@ -25,65 +25,118 @@ static xnmap_t *ui_sem_idmap; #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 { + int nrdata; + struct xnpholder *curr; + int semcnt; + int sematr; +}; + +struct vfile_data { + char name[XNOBJECT_NAME_LEN]; +}; + +static int vfile_rewind(struct xnvfile_snapshot_iterator *it) { - uisem_t *sem = (uisem_t *)data; - char *p = page; - int len; - spl_t s; + struct vfile_priv *priv = xnvfile_snapshot_iterator_priv(it); + struct uisem *sem = xnvfile_priv(it->vfile); - xnlock_get_irqsave(&nklock, s); + priv->nrdata = xnsynch_nsleepers(&sem->synchbase); + priv->curr = getheadpq(xnsynch_wait_queue(&sem->synchbase)); + priv->semcnt = sem->semcnt; + priv->sematr = sem->sematr; - p += sprintf(p, "=%d, attr=%s\n", sem->semcnt, - sem->sematr & TA_TPRI ? "TA_TPRI" : "TA_TFIFO"); + return 0; +} - if (xnsynch_pended_p(&sem->synchbase)) { - xnpholder_t *holder; +static void *vfile_begin(struct xnvfile_snapshot_iterator *it) +{ + struct vfile_priv *priv = xnvfile_snapshot_iterator_priv(it); - /* Pended semaphore -- dump waiters. */ + if (priv->nrdata == 0) + /* No output beside the header. */ + return VFILE_SEQ_EMPTY; - holder = getheadpq(xnsynch_wait_queue(&sem->synchbase)); + return kmalloc(priv->nrdata * sizeof(struct vfile_data), + GFP_KERNEL); +} - while (holder) { - xnthread_t *sleeper = link2thread(holder, plink); - p += sprintf(p, "+%s\n", xnthread_name(sleeper)); - holder = nextpq(xnsynch_wait_queue(&sem->synchbase), holder); - } - } +static void vfile_end(struct xnvfile_snapshot_iterator *it, void *buf) +{ + kfree(buf); +} - xnlock_put_irqrestore(&nklock, s); +static int vfile_next(struct xnvfile_snapshot_iterator *it, void *data) +{ + struct vfile_priv *priv = xnvfile_snapshot_iterator_priv(it); + struct uisem *sem = xnvfile_priv(it->vfile); + struct vfile_data *p = data; + struct xnthread *thread; + + priv->semcnt = sem->semcnt; /* Refresh as we collect. */ + + 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); - len = (p - page) - off; - if (len <= off + count) - *eof = 1; - *start = page + off; - if (len > count) - len = count; - if (len < 0) - len = 0; + /* Collect thread name to be output in ->show(). */ + strncpy(p->name, xnthread_name(thread), sizeof(p->name)); - return len; + return 1; } -extern xnptree_t __uitron_ptree; +static int vfile_show(struct xnvfile_snapshot_iterator *it, void *data) +{ + struct vfile_priv *priv = xnvfile_snapshot_iterator_priv(it); + struct vfile_data *p = data; + + if (p == NULL) { /* Dump header. */ + /* Always dump current event mask value. */ + xnvfile_printf(it, "count=%d, attr=%s\n", + priv->semcnt, + priv->sematr & TA_TPRI ? "TA_TPRI" : "TA_TFIFO"); + if (priv->nrdata > 0) + xnvfile_printf(it, "--------------------\n"); + } else + xnvfile_printf(it, "%.*s\n", + (int)sizeof(p->name), p->name); + + return 0; +} -static xnpnode_t __sem_pnode = { +static struct xnvfile_snapshot_ops vfile_ops = { + .rewind = vfile_rewind, + .begin = vfile_begin, + .next = vfile_next, + .end = vfile_end, + .show = vfile_show, +}; - .dir = NULL, - .type = "semaphores", - .entries = 0, - .read_proc = &__sem_read_proc, - .write_proc = NULL, - .root = &__uitron_ptree, +extern struct xnptree __uitron_ptree; + +static struct xnpnode_file __sem_pnode = { + .node = { + .dirname = "semaphores", + .root = &__uitron_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 __sem_pnode = { - - .type = "semaphores" +static struct xnpnode_file __sem_pnode = { + .node = { + .dirname = "semaphores", + }, }; #endif /* !CONFIG_PROC_FS */ @@ -136,7 +189,7 @@ ER cre_sem(ID semid, T_CSEM *pk_csem) sem->semcnt = pk_csem->isemcnt; sem->maxsem = pk_csem->maxsem; sprintf(sem->name, "sem%d", semid); - xnregistry_enter(sem->name, sem, &sem->handle, &__sem_pnode); + xnregistry_enter(sem->name, sem, &sem->handle, &__sem_pnode.node); xnarch_memory_barrier(); sem->magic = uITRON_SEM_MAGIC; _______________________________________________ Xenomai-git mailing list [email protected] https://mail.gna.org/listinfo/xenomai-git
