Module: xenomai-head
Branch: master
Commit: 28198e321c45ff2e42fb4f6a41727a68dfbd2405
URL:    
http://git.xenomai.org/?p=xenomai-head.git;a=commit;h=28198e321c45ff2e42fb4f6a41727a68dfbd2405

Author: Philippe Gerum <r...@xenomai.org>
Date:   Wed Apr 28 17:01:42 2010 +0200

nucleus/heap: convert to vfile

---

 ksrc/nucleus/heap.c |  171 ++++++++++++++++++++++++++++-----------------------
 1 files changed, 95 insertions(+), 76 deletions(-)

diff --git a/ksrc/nucleus/heap.c b/ksrc/nucleus/heap.c
index f1d2c7b..0d60678 100644
--- a/ksrc/nucleus/heap.c
+++ b/ksrc/nucleus/heap.c
@@ -66,18 +66,106 @@ HEAP {
 #include <nucleus/pod.h>
 #include <nucleus/thread.h>
 #include <nucleus/heap.h>
+#include <nucleus/vfile.h>
 #include <nucleus/assert.h>
 #include <asm/xenomai/bits/heap.h>
 
-xnheap_t kheap;                /* System heap */
+struct xnheap kheap;           /* System heap */
 EXPORT_SYMBOL_GPL(kheap);
 
 #if CONFIG_XENO_OPT_SYS_STACKPOOLSZ > 0
-xnheap_t kstacks;      /* Private stack pool */
+struct xnheap kstacks;         /* Private stack pool */
 #endif
 
-static DEFINE_XNQUEUE(heapq);  /* Heap list for /proc reporting */
-static unsigned long heapq_rev;
+static DEFINE_XNQUEUE(heapq);  /* Heap list for v-file dump */
+
+#ifdef CONFIG_PROC_FS
+
+static struct xnvfile_rev_tag vfile_tag;
+
+static struct xnvfile_snapshot_ops vfile_ops;
+
+struct vfile_priv {
+       struct xnholder *curr;
+};
+
+struct vfile_data {
+       size_t usable_mem;
+       size_t used_mem;
+       size_t page_size;
+       char label[XNOBJECT_NAME_LEN+16];
+};
+
+static struct xnvfile_snapshot vfile = {
+       .privsz = sizeof(struct vfile_priv),
+       .datasz = sizeof(struct vfile_data),
+       .tag = &vfile_tag,
+       .ops = &vfile_ops,
+};
+
+static int vfile_rewind(struct xnvfile_snapshot_iterator *it)
+{
+       struct vfile_priv *priv = xnvfile_iterator_priv(it);
+
+       priv->curr = getheadq(&heapq);
+
+       return countq(&heapq);
+}
+
+static int vfile_next(struct xnvfile_snapshot_iterator *it, void *data)
+{
+       struct vfile_priv *priv = xnvfile_iterator_priv(it);
+       struct vfile_data *p = data;
+       struct xnheap *heap;
+
+       if (priv->curr == NULL)
+               return 0;       /* We are done. */
+
+       heap = container_of(priv->curr, struct xnheap, stat_link);
+       priv->curr = nextq(&heapq, priv->curr);
+
+       p->usable_mem = xnheap_usable_mem(heap);
+       p->used_mem = xnheap_used_mem(heap);
+       p->page_size = xnheap_page_size(heap);
+       strncpy(p->label, heap->label, sizeof(p->label));
+
+       return 1;
+}
+
+static int vfile_show(struct xnvfile_snapshot_iterator *it, void *data)
+{
+       struct vfile_data *p = data;
+
+       if (p == NULL)
+               xnvfile_printf(it, "%9s %9s  %6s  %s\n",
+                              "TOTAL", "USED", "PAGESZ", "NAME");
+       else
+               xnvfile_printf(it, "%9Zu %9Zu  %6Zu  %.*s\n",
+                              p->usable_mem,
+                              p->used_mem,
+                              p->page_size,
+                              sizeof(p->label),
+                              p->label);
+       return 0;
+}
+
+static struct xnvfile_snapshot_ops vfile_ops = {
+       .rewind = vfile_rewind,
+       .next = vfile_next,
+       .show = vfile_show,
+};
+
+void xnheap_init_proc(void)
+{
+       xnvfile_init_snapshot("heap", &vfile, &nkvfroot);
+}
+
+void xnheap_cleanup_proc(void)
+{
+       xnvfile_destroy_snapshot(&vfile);
+}
+
+#endif /* CONFIG_PROC_FS */
 
 static void init_extent(xnheap_t *heap, xnextent_t *extent)
 {
@@ -241,7 +329,7 @@ int xnheap_init(xnheap_t *heap,
 
        xnlock_get_irqsave(&nklock, s);
        appendq(&heapq, &heap->stat_link);
-       heapq_rev++;
+       xnvfile_touch_tag(&vfile_tag);
        xnlock_put_irqrestore(&nklock, s);
 
        xnarch_init_display_context(heap);
@@ -325,7 +413,7 @@ void xnheap_destroy(xnheap_t *heap,
 
        xnlock_get_irqsave(&nklock, s);
        removeq(&heapq, &heap->stat_link);
-       heapq_rev++;
+       xnvfile_touch_tag(&vfile_tag);
        xnlock_put_irqrestore(&nklock, s);
 
        if (!flushfn)
@@ -1313,7 +1401,7 @@ void xnheap_destroy_mapped(xnheap_t *heap,
 
        xnlock_get_irqsave(&nklock, s);
        removeq(&heapq, &heap->stat_link);
-       heapq_rev++;
+       xnvfile_touch_tag(&vfile_tag);
        xnlock_put_irqrestore(&nklock, s);
 
        len = xnheap_extentsize(heap);
@@ -1423,75 +1511,6 @@ void xnheap_destroy_mapped(xnheap_t *heap,
 }
 #endif /* !CONFIG_XENO_OPT_PERVASIVE */
 
-#ifdef CONFIG_PROC_FS
-
-#include <linux/proc_fs.h>
-
-static int heap_read_proc(char *page,
-                         char **start,
-                         off_t off, int count, int *eof, void *data)
-{
-       unsigned long rev;
-       xnholder_t *entry;
-       xnheap_t *heap;
-       int len;
-       spl_t s;
-
-       if (!xnpod_active_p())
-               return -ESRCH;
-
-       xnlock_get_irqsave(&nklock, s);
-
-restart:
-       len = 0;
-
-       entry = getheadq(&heapq);
-       while (entry) {
-               heap = container_of(entry, xnheap_t, stat_link);
-               len += sprintf(page + len,
-                              "size=%lu:used=%lu:pagesz=%lu  (%s)\n",
-                              xnheap_usable_mem(heap),
-                              xnheap_used_mem(heap),
-                              xnheap_page_size(heap),
-                              heap->label);
-
-               rev = heapq_rev;
-
-               xnlock_sync_irq(&nklock, s);
-
-               if (heapq_rev != rev)
-                       goto restart;
-
-               entry = nextq(&heapq, entry);
-       }
-
-       xnlock_put_irqrestore(&nklock, s);
-
-       len -= off;
-       if (len <= off + count)
-               *eof = 1;
-       *start = page + off;
-       if (len > count)
-               len = count;
-       if (len < 0)
-               len = 0;
-
-       return len;
-}
-
-void xnheap_init_proc(void)
-{
-       rthal_add_proc_leaf("heap", &heap_read_proc, NULL, NULL,
-                           rthal_proc_root);
-}
-
-void xnheap_cleanup_proc(void)
-{
-       remove_proc_entry("heap", rthal_proc_root);
-}
-
-#endif /* CONFIG_PROC_FS */
-
 EXPORT_SYMBOL_GPL(xnheap_init_mapped);
 EXPORT_SYMBOL_GPL(xnheap_destroy_mapped);
 


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

Reply via email to