* [Xenomai-help] RT Heap in Userspace
@ 2006-01-12 10:36 Stephan Zimmermann
2006-01-12 15:49 ` Philippe Gerum
2006-01-12 23:14 ` Jan Kiszka
0 siblings, 2 replies; 3+ messages in thread
From: Stephan Zimmermann @ 2006-01-12 10:36 UTC (permalink / raw)
To: xenomai
Hello again,
based on your information about memory allocation, I tried out the following:
in main:
// creating the Heap
ret = rt_heap_create(&rt_heap,"Main-RT-Heap",rt_heapsize,H_FIFO);
global:
// overloaded operator new
void* operator new(size_t size){
void* newmem = NULL;
int ret = rt_heap_alloc(&rt_heap,size,TM_INFINITE,&newmem);
printf("new memory allocated: %i bytes, return %i\n",size,ret); fflush(NULL);
return newmem;
}
This works fine, as long as I use a standard 'malloc' in my operator new. When
executing the rt_... code, creating the heap returns 0 as expected. But
trying to allocate some Memory insode of it using operator new fails with
-EEINVAL.
Reading the API-Doc more thoroughly, I saw a statement that H_SHARED is
implicitly set, when a heap is created from Userspace (where my program
executes).
So, is ist possible to do what I try, or will I need to run in kernelspace for
it? Maybe there is some 'trick' to do it?
Thaks for your help, Stephan
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Xenomai-help] RT Heap in Userspace
2006-01-12 10:36 [Xenomai-help] RT Heap in Userspace Stephan Zimmermann
@ 2006-01-12 15:49 ` Philippe Gerum
2006-01-12 23:14 ` Jan Kiszka
1 sibling, 0 replies; 3+ messages in thread
From: Philippe Gerum @ 2006-01-12 15:49 UTC (permalink / raw)
To: Stephan Zimmermann; +Cc: xenomai
Stephan Zimmermann wrote:
> Hello again,
> based on your information about memory allocation, I tried out the following:
>
> in main:
> // creating the Heap
> ret = rt_heap_create(&rt_heap,"Main-RT-Heap",rt_heapsize,H_FIFO);
>
> global:
> // overloaded operator new
> void* operator new(size_t size){
> void* newmem = NULL;
> int ret = rt_heap_alloc(&rt_heap,size,TM_INFINITE,&newmem);
> printf("new memory allocated: %i bytes, return %i\n",size,ret); fflush(NULL);
> return newmem;
> }
>
> This works fine, as long as I use a standard 'malloc' in my operator new. When
> executing the rt_... code, creating the heap returns 0 as expected. But
> trying to allocate some Memory insode of it using operator new fails with
> -EEINVAL.
>
> Reading the API-Doc more thoroughly, I saw a statement that H_SHARED is
> implicitly set, when a heap is created from Userspace (where my program
> executes).
> So, is ist possible to do what I try, or will I need to run in kernelspace for
> it? Maybe there is some 'trick' to do it?
>
Not yet. For the time being, user-space heaps are always built as single shared
memory segments, which is a useless limitation. There is a plan to fix that in a
reasonable future, by decoupling the mappable heap property from the
single-segment one (i.e. which will allow in turn to create shared heaps which are
not necessarily single-segment areas). If your application can bare higher
execution latencies as a result of calling the allocator for a while, then you
might consider sticking with malloc until this fix is available.
Sidenote: going for kernel-space with C++ always seemed to me a bad idea. It's not
that it is impossible, it's just that it often turns out to be a maintenance hell
provided you want to keep your options reasonably open regarding your kernel+gcc
combo of choice.
> Thaks for your help, Stephan
>
> _______________________________________________
> Xenomai-help mailing list
> Xenomai-help@domain.hid
> https://mail.gna.org/listinfo/xenomai-help
>
--
Philippe.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Xenomai-help] RT Heap in Userspace
2006-01-12 10:36 [Xenomai-help] RT Heap in Userspace Stephan Zimmermann
2006-01-12 15:49 ` Philippe Gerum
@ 2006-01-12 23:14 ` Jan Kiszka
1 sibling, 0 replies; 3+ messages in thread
From: Jan Kiszka @ 2006-01-12 23:14 UTC (permalink / raw)
To: Stephan Zimmermann; +Cc: xenomai
[-- Attachment #1: Type: text/plain, Size: 1414 bytes --]
Stephan Zimmermann wrote:
> Hello again,
> based on your information about memory allocation, I tried out the following:
>
> in main:
> // creating the Heap
> ret = rt_heap_create(&rt_heap,"Main-RT-Heap",rt_heapsize,H_FIFO);
>
> global:
> // overloaded operator new
> void* operator new(size_t size){
> void* newmem = NULL;
> int ret = rt_heap_alloc(&rt_heap,size,TM_INFINITE,&newmem);
> printf("new memory allocated: %i bytes, return %i\n",size,ret); fflush(NULL);
> return newmem;
> }
>
> This works fine, as long as I use a standard 'malloc' in my operator new. When
> executing the rt_... code, creating the heap returns 0 as expected. But
> trying to allocate some Memory insode of it using operator new fails with
> -EEINVAL.
>
> Reading the API-Doc more thoroughly, I saw a statement that H_SHARED is
> implicitly set, when a heap is created from Userspace (where my program
> executes).
> So, is ist possible to do what I try, or will I need to run in kernelspace for
> it? Maybe there is some 'trick' to do it?
>
If you do not depend on sharing the allocated memory between multiple
processes or kernel and user space, you may want to take a look at this
deterministic allocator library:
http://rtportal.upv.es/rtmalloc/allocators/tlsf/index.shtml
Should be straightforward to use it (at least it was with a previous
version I once tried).
Jan
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 250 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2006-01-12 23:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-01-12 10:36 [Xenomai-help] RT Heap in Userspace Stephan Zimmermann
2006-01-12 15:49 ` Philippe Gerum
2006-01-12 23:14 ` Jan Kiszka
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.