Module: xenomai-rpm
Branch: queue/vfile
Commit: b0b29d848ed8eae6ab98db71b88e07d65ef07091
URL:    
http://git.xenomai.org/?p=xenomai-rpm.git;a=commit;h=b0b29d848ed8eae6ab98db71b88e07d65ef07091

Author: Philippe Gerum <r...@xenomai.org>
Date:   Wed Jun  9 18:36:17 2010 +0200

nucleus/pod: convert to vfile

---

 ksrc/nucleus/pod.c |  135 ++++++++++++++++++++-------------------------------
 1 files changed, 53 insertions(+), 82 deletions(-)

diff --git a/ksrc/nucleus/pod.c b/ksrc/nucleus/pod.c
index 7e8a3b7..4f6060d 100644
--- a/ksrc/nucleus/pod.c
+++ b/ksrc/nucleus/pod.c
@@ -3094,16 +3094,13 @@ EXPORT_SYMBOL_GPL(xnpod_set_thread_tslice);
 
 #if XENO_DEBUG(XNLOCK)
 
-xnlockinfo_t xnlock_stats[RTHAL_NR_CPUS];
+xnlockinfo_t xnlock_stats[XNARCH_NR_CPUS];
+EXPORT_SYMBOL_GPL(xnlock_stats);
 
-static int lock_read_proc(char *page,
-                         char **start,
-                         off_t off, int count, int *eof, void *data)
+static int lock_vfile_show(struct xnvfile_regular_iterator *it, void *data)
 {
        xnlockinfo_t lockinfo;
-       int cpu, len = 0;
-       char *p = page;
-       spl_t s;
+       int cpu;
 
        for_each_online_cpu(cpu) {
 
@@ -3112,11 +3109,11 @@ static int lock_read_proc(char *page,
                xnlock_put_irqrestore(&nklock, s);
 
                if (cpu > 0)
-                       p += sprintf(p, "\n");
+                       xnvfile_printf(it, "\n");
 
-               p += sprintf(p, "CPU%d:\n", cpu);
+               xnvfile_printf(it, "CPU%d:\n", cpu);
 
-               p += sprintf(p,
+               xnvfile_printf(it,
                             "  longest locked section: %llu ns\n"
                             "  spinning time: %llu ns\n"
                             "  section entry: %s:%d (%s)\n",
@@ -3125,84 +3122,64 @@ static int lock_read_proc(char *page,
                             lockinfo.file, lockinfo.line, lockinfo.function);
        }
 
-       len = p - page - off;
+       return 0;
+}
 
-       if (len <= off + count)
-               *eof = 1;
-       *start = page + off;
-       if (len > count)
-               len = count;
-       if (len < 0)
-               len = 0;
+static struct xnvfile_regular_ops lock_vfile_ops = {
+       .show = lock_vfile_show,
+};
 
-       return len;
-}
-EXPORT_SYMBOL_GPL(xnlock_stats);
+static struct xnvfile_regular lock_vfile = {
+       .ops = &lock_vfile_ops,
+};
 
 #endif /* XENO_DEBUG(XNLOCK) */
 
-static int latency_read_proc(char *page,
-                            char **start,
-                            off_t off, int count, int *eof, void *data)
+static int latency_vfile_show(struct xnvfile_regular_iterator *it, void *data)
 {
-       int len;
-
-       len = sprintf(page, "%Lu\n", xnarch_tsc_to_ns(nklatency));
-       len -= off;
-       if (len <= off + count)
-               *eof = 1;
-       *start = page + off;
-       if (len > count)
-               len = count;
-       if (len < 0)
-               len = 0;
-
-       return len;
+       xnvfile_printf(it, "%Lu\n", xnarch_tsc_to_ns(nklatency));
+
+       return 0;
 }
 
-static int latency_write_proc(struct file *file,
-                             const char __user * buffer,
-                             unsigned long count, void *data)
+static ssize_t latency_vfile_store(struct xnvfile_input *input)
 {
-       char *end, buf[16];
-       long ns;
-       int n;
-
-       n = count > sizeof(buf) - 1 ? sizeof(buf) - 1 : count;
+       long val;
+       int ret;
 
-       if (copy_from_user(buf, buffer, n))
-               return -EFAULT;
+       ret = xnvfile_get_integer(input, &val);
+       if (ret)
+               return ret;
 
-       buf[n] = '\0';
-       ns = simple_strtol(buf, &end, 0);
+       nklatency = xnarch_ns_to_tsc(val);
 
-       if ((*end != '\0' && !isspace(*end)) || ns < 0)
-               return -EINVAL;
+       return 0;
+}
 
-       nklatency = xnarch_ns_to_tsc(ns);
+static struct xnvfile_regular_ops latency_vfile_ops = {
+       .show = latency_vfile_show,
+       .store = latency_vfile_store,
+};
 
-       return count;
-}
+static struct xnvfile_regular latency_vfile = {
+       .ops = &latency_vfile_ops,
+};
 
-static int version_read_proc(char *page,
-                            char **start,
-                            off_t off, int count, int *eof, void *data)
+static int version_vfile_show(struct xnvfile_regular_iterator *it, void *data)
 {
-       int len;
-
-       len = sprintf(page, "%s\n", XENO_VERSION_STRING);
-       len -= off;
-       if (len <= off + count)
-               *eof = 1;
-       *start = page + off;
-       if (len > count)
-               len = count;
-       if (len < 0)
-               len = 0;
-
-       return len;
+       xnvfile_printf(it, "%s\n", XENO_VERSION_STRING);
+
+       return 0;
 }
 
+static struct xnvfile_regular_ops version_vfile_ops = {
+       .show = version_vfile_show,
+};
+
+static struct xnvfile_regular version_vfile = {
+       .ops = &version_vfile_ops,
+};
+
 int xnpod_init_proc(void)
 {
        int ret;
@@ -3220,16 +3197,10 @@ int xnpod_init_proc(void)
        xnintr_init_proc();
        xnshadow_init_proc();
 
-       rthal_add_proc_leaf("latency",
-                           &latency_read_proc,
-                           &latency_write_proc, NULL, rthal_proc_root);
-
-       rthal_add_proc_leaf("version", &version_read_proc, NULL, NULL,
-                           rthal_proc_root);
-
+       xnvfile_init_regular("latency", &latency_vfile, NULL);
+       xnvfile_init_regular("version", &version_vfile, NULL);
 #if XENO_DEBUG(XNLOCK)
-       rthal_add_proc_leaf("lock", &lock_read_proc, NULL, NULL,
-                           rthal_proc_root);
+       xnvfile_init_regular("lock", &lock_vfile, NULL);
 #endif /* XENO_DEBUG(XNLOCK) */
        return 0;
 }
@@ -3237,10 +3208,10 @@ int xnpod_init_proc(void)
 void xnpod_cleanup_proc(void)
 {
 #if XENO_DEBUG(XNLOCK)
-       remove_proc_entry("lock", rthal_proc_root);
+       xnvfile_destroy_regular(&lock_vfile);
 #endif /* XENO_DEBUG(XNLOCK) */
-       remove_proc_entry("version", rthal_proc_root);
-       remove_proc_entry("latency", rthal_proc_root);
+       xnvfile_destroy_regular(&version_vfile);
+       xnvfile_destroy_regular(&latency_vfile);
 
        xnshadow_cleanup_proc();
        xnintr_cleanup_proc();


_______________________________________________
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git

Reply via email to