[Xenomai-core] [PATCH] native: Avoid double release on queue/heap auto-cleanup

2009-10-22 Thread Jan Kiszka
Jan Kiszka wrote:
 We are currently leaking user space heap/queue objects when the owner
 terminates without deleting them before. Fix it by releasing the objects
 in the corresponding cleanup callbacks which are also called on owner
 termination.

Just realized that we need this patch in addition:



Commit 3a7330b164 also requires this patch to avoid that the queue and
heap objects are released twice on automatic cleanup (via the xnheap
release handler and via the ppd object queue flush).

Signed-off-by: Jan Kiszka jan.kis...@siemens.com
---

 include/native/heap.h  |2 +-
 include/native/queue.h |2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/native/heap.h b/include/native/heap.h
index 5444a43..0c2a7a2 100644
--- a/include/native/heap.h
+++ b/include/native/heap.h
@@ -117,7 +117,7 @@ void __native_heap_pkg_cleanup(void);
 
 static inline void __native_heap_flush_rq(xnqueue_t *rq)
 {
-   xeno_flush_rq(RT_HEAP, rq, heap);
+   xeno_flush_rq_norelease(RT_HEAP, rq, heap);
 }
 
 int rt_heap_delete_inner(RT_HEAP *heap,
diff --git a/include/native/queue.h b/include/native/queue.h
index 77925c2..2951c42 100644
--- a/include/native/queue.h
+++ b/include/native/queue.h
@@ -129,7 +129,7 @@ void __native_queue_pkg_cleanup(void);
 
 static inline void __native_queue_flush_rq(xnqueue_t *rq)
 {
-   xeno_flush_rq(RT_QUEUE, rq, queue);
+   xeno_flush_rq_norelease(RT_QUEUE, rq, queue);
 }
 
 ssize_t rt_queue_receive_inner(RT_QUEUE *q, void **bufp,

___
Xenomai-core mailing list
Xenomai-core@gna.org
https://mail.gna.org/listinfo/xenomai-core


Re: [Xenomai-core] [PATCH v3 9/9] nucleus: Include all heaps in statistics

2009-10-22 Thread Jan Kiszka
Philippe Gerum wrote:
 On Tue, 2009-10-20 at 13:37 +0200, Jan Kiszka wrote:
 This extends /proc/xenomai/heap with statistics about all currently used
 heaps. It takes care to flush nklock while iterating of this potentially
 long list.

 Signed-off-by: Jan Kiszka jan.kis...@siemens.com
 ---

  include/nucleus/heap.h|   12 +++-
  ksrc/drivers/ipc/iddp.c   |3 +
  ksrc/drivers/ipc/xddp.c   |6 ++
  ksrc/nucleus/heap.c   |  131 
 -
  ksrc/nucleus/module.c |2 -
  ksrc/nucleus/pod.c|5 +-
  ksrc/nucleus/shadow.c |5 +-
  ksrc/skins/native/heap.c  |6 +-
  ksrc/skins/native/pipe.c  |4 +
  ksrc/skins/native/queue.c |6 +-
  ksrc/skins/posix/shm.c|4 +
  ksrc/skins/psos+/rn.c |6 +-
  ksrc/skins/rtai/shm.c |7 ++
  ksrc/skins/vrtx/heap.c|6 +-
  ksrc/skins/vrtx/syscall.c |3 +
  15 files changed, 169 insertions(+), 37 deletions(-)

 diff --git a/include/nucleus/heap.h b/include/nucleus/heap.h
 index 44db738..f653cd7 100644
 --- a/include/nucleus/heap.h
 +++ b/include/nucleus/heap.h
 @@ -115,6 +115,10 @@ typedef struct xnheap {

   XNARCH_DECL_DISPLAY_CONTEXT();

 + xnholder_t stat_link;   /* Link in heapq */
 +
 + char name[48];
 
 s,48,XNOBJECT_NAME_LEN

OK, but XNOBJECT_NAME_LEN+16 (due to class prefixes and additional
information like the minor ID).

 
 +
  } xnheap_t;

  extern xnheap_t kheap;
 @@ -202,7 +206,8 @@ void xnheap_cleanup_proc(void);

  int xnheap_init_mapped(xnheap_t *heap,
  u_long heapsize,
 -int memflags);
 +int memflags,
 +const char *name, ...);

 
 The va_list is handy, but this breaks the common pattern used throughout
 the rest of the nucleus, based on passing pre-formatted labels. So
 either we make all creation calls use va_lists (but xnthread would need
 more work), or we make xnheap_init_mapped use the not-so-handy current
 form.
 
 Actually, providing xnheap_set_name() and a name parameter/va_list to
 xnheap_init* is one too many, this clutters an inner interface
 uselessly. The latter should go away, assuming that anon heaps may still
 exist.

If we want to print all heaps, we should at least set a name indicating
their class. And therefore we need to pass a descriptive name along with
/every/ heap initialization. Forcing the majority of xnheap_init users
to additionally issue xnheap_set_name is the cluttering a wanted to
avoid. Only a minority needs this split-up, and therefore you see both
interfaces in my patch.

 
  void xnheap_destroy_mapped(xnheap_t *heap,
  void (*release)(struct xnheap *heap),
 @@ -224,7 +229,10 @@ void xnheap_destroy_mapped(xnheap_t *heap,
  int xnheap_init(xnheap_t *heap,
   void *heapaddr,
   u_long heapsize,
 - u_long pagesize);
 + u_long pagesize,
 + const char *name, ...);
 +
 +void xnheap_set_name(xnheap_t *heap, const char *name, ...);

  void xnheap_destroy(xnheap_t *heap,
   void (*flushfn)(xnheap_t *heap,
 diff --git a/ksrc/drivers/ipc/iddp.c b/ksrc/drivers/ipc/iddp.c
 index a407946..b6382f1 100644
 --- a/ksrc/drivers/ipc/iddp.c
 +++ b/ksrc/drivers/ipc/iddp.c
 @@ -559,7 +559,8 @@ static int __iddp_bind_socket(struct rtipc_private *priv,
   }

   ret = xnheap_init(sk-privpool,
 -   poolmem, poolsz, XNHEAP_PAGE_SIZE);
 +   poolmem, poolsz, XNHEAP_PAGE_SIZE,
 +   ippd: %d, port);
   if (ret) {
   xnarch_free_host_mem(poolmem, poolsz);
   goto fail;
 diff --git a/ksrc/drivers/ipc/xddp.c b/ksrc/drivers/ipc/xddp.c
 index f62147a..a5dafef 100644
 --- a/ksrc/drivers/ipc/xddp.c
 +++ b/ksrc/drivers/ipc/xddp.c
 @@ -703,7 +703,7 @@ static int __xddp_bind_socket(struct rtipc_private *priv,
   }

   ret = xnheap_init(sk-privpool,
 -   poolmem, poolsz, XNHEAP_PAGE_SIZE);
 +   poolmem, poolsz, XNHEAP_PAGE_SIZE, );
   if (ret) {
   xnarch_free_host_mem(poolmem, poolsz);
   goto fail;
 @@ -746,6 +746,10 @@ static int __xddp_bind_socket(struct rtipc_private 
 *priv,
   sk-minor = ret;
   sa-sipc_port = ret;
   sk-name = *sa;
 +
 + if (poolsz  0)
 + xnheap_set_name(sk-bufpool, xddp: %d, sa-sipc_port);
 +
   /* Set default destination if unset at binding time. */
   if (sk-peer.sipc_port  0)
   sk-peer = *sa;
 diff --git a/ksrc/nucleus/heap.c b/ksrc/nucleus/heap.c
 index 96c46f8..793d1c5 100644
 --- a/ksrc/nucleus/heap.c
 +++ b/ksrc/nucleus/heap.c
 @@ -76,6 +76,9 @@ EXPORT_SYMBOL_GPL(kheap);
  xnheap_t kstacks;/* Private stack pool */
  #endif

 +static DEFINE_XNQUEUE(heapq);/* Heap list for /proc reporting */