Re: [Xenomai-core] [PATCH] fix xnheap_alloc rounding

2006-07-14 Thread Philippe Gerum
On Tue, 2006-07-11 at 16:02 +0200, Jan Kiszka wrote:
 Hi,
 
 playing a stupid rt_heap user (actually I didn't just play this...), I
 stumbled over this undocumented oddity:
 
 rt_heap_create(heap, name, 1, H_PRIO|H_MAPPABLE);
 rt_heap_alloc(heap, 1, TM_NONBLOCK, ptr);
 
 Creation is successful, allocation fails. The reason: while during
 creation the net heap size is rounded down to page boundaries, the
 allocation of memory  PAGE_SIZE is rounded up. One could add H_SINGLE
 to the flags, but this may even result in allocating less memory than
 the user expected, causing severe problems later.
 
 How to resolve this best? I thought about rounding twice in
 rt_head_create (one time the net size, the second time including the
 overhead), but this encodes characteristics of the underlying heap
 allocator into the skin (I have a generic heap allocator framework in
 mind for 2.3).

The nucleus heap expects the caller to pass it the memory which is going
to be used to fulfill allocation requests, so there is already a builtin
dependency from any client heap manager on the nucleus implementation.
Double rounding is therefore the way to go, since callers need to be
fixed so that they provide enough memory to the xnheap manager when
specializing its behaviour.

  So I decided to do this rounding in xnheap_overhead()
 instead, see attached patch. Hope I didn't skewed up any calculation. At
 least the scenario above now works fine.
 
 Jan
 plain text document attachment (xnheap_overhead-fix-rounding.patch)
 Index: include/nucleus/heap.h
 ===
 --- include/nucleus/heap.h(revision 1322)
 +++ include/nucleus/heap.h(working copy)
 @@ -109,8 +109,14 @@ extern xnheap_t kheap;
  #define xnheap_used_mem(heap)((heap)-ubytes)
  #define xnheap_max_contiguous(heap)  ((heap)-maxcont)
  #define xnheap_overhead(hsize,psize) \
 -((sizeof(xnextent_t) + (((hsize) - sizeof(xnextent_t)) / (psize)) + \
 - XNHEAP_MINALIGNSZ - 1)  ~(XNHEAP_MINALIGNSZ - 1))
 +({ \
 +u_long rounded_hsize = (hsize + psize - 1)  ~(psize - 1); \
 +u_long overhead = ((sizeof(xnextent_t) + \
 + (((rounded_hsize) - sizeof(xnextent_t)) / (psize)) + \
 + XNHEAP_MINALIGNSZ - 1)  ~(XNHEAP_MINALIGNSZ - 1)); \
 +overhead += rounded_hsize - hsize; \
 +overhead; \
 +})
  
  #define xnmalloc(size) xnheap_alloc(kheap,size)
  #define xnfree(ptr)xnheap_free(kheap,ptr)
 ___
 Xenomai-core mailing list
 Xenomai-core@gna.org
 https://mail.gna.org/listinfo/xenomai-core
-- 
Philippe.



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


Re: [Xenomai-core] [PATCH] optimise syscall mux-code calculation

2006-07-14 Thread Philippe Gerum
On Thu, 2006-07-13 at 13:13 +0200, Jan Kiszka wrote:
 Hi,
 
 some may recall the micro-optimisation thread I once started. Here is
 now a simple approach to deal with the yet suboptimal mux-code
 calculation in user-space. Code saving:
 
 Before:
textdata bss dec hex filename
   18004 476   8   184884838 native/.libs/libnative.so
   27445 696   4   281456df1 posix/.libs/libpthread_rt.so
 
 After:
textdata bss dec hex filename
   17172 476   8   1765644f8 native/.libs/libnative.so
   26805 696   4   275056b71 posix/.libs/libpthread_rt.so
 
 Of course, this also results in a few ops less being executed on each
 Xenomai syscall invocation (not many cycles, though).
 
 Tested without problems on x86 so far.
 

This is post 2.2 stuff since we need to check this critical change
against each and every supported arch. Since this breaks the ABI
including the ascending compatibility between old apps and new kernel
support, this won't make it during the v2 series either.

 Jan
 plain text document attachment (optimise-muxcode-calculation.patch)
 ---
  include/asm-arm/syscall.h  |   25 +
  include/asm-blackfin/syscall.h |4 +++-
  include/asm-i386/syscall.h |3 ++-
  include/asm-ia64/syscall.h |   23 ---
  include/asm-powerpc/syscall.h  |3 ++-
  ksrc/nucleus/shadow.c  |3 ++-
  6 files changed, 34 insertions(+), 27 deletions(-)
 
 Index: xenomai/include/asm-arm/syscall.h
 ===
 --- xenomai.orig/include/asm-arm/syscall.h
 +++ xenomai/include/asm-arm/syscall.h
 @@ -26,6 +26,7 @@
  #include asm-generic/xenomai/syscall.h
  
  #define __xn_mux_code(id,op)((op  24)|((id  16)  
 0xff)|(__xn_sys_mux  0x))
 +#define __xn_mux_code_shft(shifted_id,op) ((op  
 24)|shifted_id|(__xn_sys_mux  0x))

+#define __xn_mux_code_shft(shifted_id,op) ((op  24)|shifted_id)

should be enough.

snip

 Index: xenomai/include/asm-blackfin/syscall.h
 ===
 --- xenomai.orig/include/asm-blackfin/syscall.h
 +++ xenomai/include/asm-blackfin/syscall.h
 @@ -27,6 +27,7 @@
 (i.e. negative syscall number in orig_p0 meaning non-syscall
 entry). */
  #define __xn_mux_code(id,op)   ((id  24)|((op  16)  
 0xff)|(__xn_sys_mux  0x))
 +#define __xn_mux_code_fast(shifted_id,op) ((op  
 24)|shifted_id|(__xn_sys_mux  0x))
  

Breakage alert.

-- 
Philippe.



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