* [Xenomai-help] Question about rtdm_mmap_to_user() @ 2008-04-03 9:46 Perrine Martignoni 2008-04-03 10:00 ` Bosko Radivojevic 2008-04-03 10:07 ` Hannes Mayer 0 siblings, 2 replies; 11+ messages in thread From: Perrine Martignoni @ 2008-04-03 9:46 UTC (permalink / raw) To: xenomai-help [-- Attachment #1: Type: text/plain, Size: 445 bytes --] Hello, I try to allocate a buffer in kernel space (with kmalloc) and then map it into user-space (with rtdm_mmap_to_user). After, I fill in the buffer in user space with the address returned by rtdm_mmap_to_user, and when I read it into the kernel space with the kernel address, I don't have the values put in user-space. What I'm doing wrong ? Have you a simple example of use of rtdm_mmap_to_user ? Thanks in advance. Best Regards, Perrine [-- Attachment #2: Type: text/html, Size: 490 bytes --] ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Xenomai-help] Question about rtdm_mmap_to_user() 2008-04-03 9:46 [Xenomai-help] Question about rtdm_mmap_to_user() Perrine Martignoni @ 2008-04-03 10:00 ` Bosko Radivojevic 2008-04-03 12:52 ` Perrine Martignoni 2008-04-03 13:42 ` Gilles Chanteperdrix 2008-04-03 10:07 ` Hannes Mayer 1 sibling, 2 replies; 11+ messages in thread From: Bosko Radivojevic @ 2008-04-03 10:00 UTC (permalink / raw) To: Perrine Martignoni; +Cc: xenomai-help Why don't you try rt_heap_* functions? Quick example: Kernel space: RT_HEAP heap_desc; void *shared; rt_heap_create (&heap_desc, "MySHM", 2048, H_SHARED); rt_heap_alloc (&heap_desc, 0, TM_NONBLOCK, &shared); [.. cleanup ..] rt_heap_delete (&heap_desc); User space: RT_HEAP heap_desc; void *shared; rt_heap_bind (&heap_desc, "MySHM", TM_NONBLOCK); rt_heap_alloc (&heap_desc, 0, TM_NONBLOCK, &shared); [..cleanup..] rt_heap_unbind (&heap_desc); ============================================ Hope this helps :) ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Xenomai-help] Question about rtdm_mmap_to_user() 2008-04-03 10:00 ` Bosko Radivojevic @ 2008-04-03 12:52 ` Perrine Martignoni 2008-04-03 13:07 ` Jan Kiszka 2008-04-04 7:18 ` Bosko Radivojevic 2008-04-03 13:42 ` Gilles Chanteperdrix 1 sibling, 2 replies; 11+ messages in thread From: Perrine Martignoni @ 2008-04-03 12:52 UTC (permalink / raw) To: xenomai-help [-- Attachment #1: Type: text/plain, Size: 1295 bytes --] >Why don't you try rt_heap_* functions? Quick example: > >Kernel space: > >RT_HEAP heap_desc; >void *shared; > >rt_heap_create (&heap_desc, "MySHM", 2048, H_SHARED); >rt_heap_alloc (&heap_desc, 0, TM_NONBLOCK, &shared); >[.. cleanup ..] >rt_heap_delete (&heap_desc); >User space: > >RT_HEAP heap_desc; >void *shared; > >rt_heap_bind (&heap_desc, "MySHM", TM_NONBLOCK); >rt_heap_alloc (&heap_desc, 0, TM_NONBLOCK, &shared); >[..cleanup..] >rt_heap_unbind (&heap_desc); I tried exactly what you wrote. And it doesn't work. I have error -11. It doesn't find the Heap I created in kernel space. I don't understand why. I put exactly the same name. On Thu, Apr 3, 2008 at 12:00 PM, Bosko Radivojevic < bosko.radivojevic@domain.hid> wrote: > Why don't you try rt_heap_* functions? Quick example: > > Kernel space: > > RT_HEAP heap_desc; > void *shared; > > rt_heap_create (&heap_desc, "MySHM", 2048, H_SHARED); > rt_heap_alloc (&heap_desc, 0, TM_NONBLOCK, &shared); > [.. cleanup ..] > rt_heap_delete (&heap_desc); > User space: > > RT_HEAP heap_desc; > void *shared; > > rt_heap_bind (&heap_desc, "MySHM", TM_NONBLOCK); > rt_heap_alloc (&heap_desc, 0, TM_NONBLOCK, &shared); > [..cleanup..] > rt_heap_unbind (&heap_desc); > > ============================================ > > Hope this helps :) > [-- Attachment #2: Type: text/html, Size: 1860 bytes --] ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Xenomai-help] Question about rtdm_mmap_to_user() 2008-04-03 12:52 ` Perrine Martignoni @ 2008-04-03 13:07 ` Jan Kiszka 2008-04-04 7:18 ` Bosko Radivojevic 1 sibling, 0 replies; 11+ messages in thread From: Jan Kiszka @ 2008-04-03 13:07 UTC (permalink / raw) To: Perrine Martignoni; +Cc: xenomai-help [-- Attachment #1: Type: text/plain, Size: 1019 bytes --] Perrine Martignoni wrote: >> Why don't you try rt_heap_* functions? Quick example: >> >> Kernel space: >> >> RT_HEAP heap_desc; >> void *shared; >> >> rt_heap_create (&heap_desc, "MySHM", 2048, H_SHARED); >> rt_heap_alloc (&heap_desc, 0, TM_NONBLOCK, &shared); >> [.. cleanup ..] >> rt_heap_delete (&heap_desc); >> User space: >> >> RT_HEAP heap_desc; >> void *shared; >> >> rt_heap_bind (&heap_desc, "MySHM", TM_NONBLOCK); >> rt_heap_alloc (&heap_desc, 0, TM_NONBLOCK, &shared); >> [..cleanup..] >> rt_heap_unbind (&heap_desc); > > I tried exactly what you wrote. And it doesn't work. I have error -11. It > doesn't find the Heap I created in kernel space. > I don't understand why. I put exactly the same name. Mixing up RTDM and native API usage, though technically feasible, isn't a good idea anyway. Better have a look at Hannes' example, and if that one or your own version still doesn't work, post more details (Xenomai version, target architecture, test code, etc.). Jan [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 254 bytes --] ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Xenomai-help] Question about rtdm_mmap_to_user() 2008-04-03 12:52 ` Perrine Martignoni 2008-04-03 13:07 ` Jan Kiszka @ 2008-04-04 7:18 ` Bosko Radivojevic 2008-04-04 12:59 ` Perrine Martignoni 1 sibling, 1 reply; 11+ messages in thread From: Bosko Radivojevic @ 2008-04-04 7:18 UTC (permalink / raw) To: Perrine Martignoni; +Cc: xenomai-help On Thu, Apr 3, 2008 at 2:52 PM, Perrine Martignoni <perrmart@domain.hid> wrote: > >rt_heap_create (&heap_desc, "MySHM", 2048, H_SHARED); > >rt_heap_alloc (&heap_desc, 0, TM_NONBLOCK, &shared); [..] > I tried exactly what you wrote. And it doesn't work. I have error -11. It > doesn't find the Heap I created in kernel space. > I don't understand why. I put exactly the same name. rt_heap_create() must be called from kernel module init function. Here is copy&paste from my code (with checking return values): kernel_module: =========== RT_HEAP heap_desc; void *shared_mem; int init_module (void) { int ret; ret = rt_heap_create (&heap_desc, "MainSHM", 4*1024, H_SHARED); if (ret) { printk ("Error rt_heap_create: %d\n", ret); } ret = rt_heap_alloc (&heap_desc, 0, TM_NONBLOCK, &shared_mem); if (ret) { printk ("Error rt_heap_alloc: %d\n", ret); } printk ("4kB heap memory created, name: MainSHM\n"); return 1; } void cleanup_module(void) { rt_heap_delete (&heap_desc); } ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Xenomai-help] Question about rtdm_mmap_to_user() 2008-04-04 7:18 ` Bosko Radivojevic @ 2008-04-04 12:59 ` Perrine Martignoni 2008-04-04 13:04 ` Gilles Chanteperdrix 0 siblings, 1 reply; 11+ messages in thread From: Perrine Martignoni @ 2008-04-04 12:59 UTC (permalink / raw) To: Bosko Radivojevic; +Cc: xenomai-help [-- Attachment #1: Type: text/plain, Size: 2183 bytes --] >Except that the example listed in the document in question takes care of >defining the heap descriptor in global memory, not in the init_module() stack. It effectively works better with the RT_HEAP variable in global scope. I thought that the RT_HEAP variable was working like handles or descriptors in some RTOS where the life cycle of the descriptor is not correlated to the Os Object life cycle, that is to say: => enter local scope { handle myHandle = CreateOsObject(x,y,z,&err); // or err = CreateOsObject(&myHandle,x,y,z); => exit local scope } When you go out of the local scope, you can no more use the handle (and then reference the created OS object ) because it was a local variable but the object created is still alive and will not be modified because the handle was declared on the stack. So I thought that the RT_HEAP variable was just a descriptor of a Heap object managed by xenomai but not the heap object itself. Best Regards, Perrine On Fri, Apr 4, 2008 at 9:18 AM, Bosko Radivojevic < bosko.radivojevic@domain.hid> wrote: > On Thu, Apr 3, 2008 at 2:52 PM, Perrine Martignoni <perrmart@domain.hid> > wrote: > > > >rt_heap_create (&heap_desc, "MySHM", 2048, H_SHARED); > > >rt_heap_alloc (&heap_desc, 0, TM_NONBLOCK, &shared); > [..] > > I tried exactly what you wrote. And it doesn't work. I have error -11. > It > > doesn't find the Heap I created in kernel space. > > I don't understand why. I put exactly the same name. > > rt_heap_create() must be called from kernel module init function. Here > is copy&paste from my code (with checking return values): > > kernel_module: > =========== > > RT_HEAP heap_desc; > void *shared_mem; > > int init_module (void) > { > int ret; > > ret = rt_heap_create (&heap_desc, "MainSHM", 4*1024, H_SHARED); > if (ret) { > printk ("Error rt_heap_create: %d\n", ret); > } > ret = rt_heap_alloc (&heap_desc, 0, TM_NONBLOCK, &shared_mem); > if (ret) { > printk ("Error rt_heap_alloc: %d\n", ret); > } > printk ("4kB heap memory created, name: MainSHM\n"); > return 1; > } > > void cleanup_module(void) > { > rt_heap_delete (&heap_desc); > } > [-- Attachment #2: Type: text/html, Size: 3209 bytes --] ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Xenomai-help] Question about rtdm_mmap_to_user() 2008-04-04 12:59 ` Perrine Martignoni @ 2008-04-04 13:04 ` Gilles Chanteperdrix 0 siblings, 0 replies; 11+ messages in thread From: Gilles Chanteperdrix @ 2008-04-04 13:04 UTC (permalink / raw) To: Perrine Martignoni; +Cc: xenomai-help On Fri, Apr 4, 2008 at 2:59 PM, Perrine Martignoni <perrmart@domain.hid> wrote: > >Except that the example listed in the document in question takes care of > >defining the heap descriptor in global memory, not in the init_module() > stack. > > > It effectively works better with the RT_HEAP variable in global scope. > > I thought that the RT_HEAP variable was working like handles or descriptors > in some RTOS where the life cycle of the descriptor is not correlated to the > Os Object life cycle, that is to say: > > => enter local scope { > handle myHandle = > CreateOsObject(x,y,z,&err); // or err = CreateOsObject(&myHandle,x,y,z); > => exit local scope } > > When you go out of the local scope, you can no more use the handle (and then > reference the created OS object ) because it was a local variable but the > object created is still alive and will not be modified because the handle > was declared on the stack. So I thought that the RT_HEAP variable was just a > descriptor of a Heap object managed by xenomai but not the heap object > itself. The behaviour of the RT_HEAP descriptor is documented in rt_heap_create documentation. -- Gilles ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Xenomai-help] Question about rtdm_mmap_to_user() 2008-04-03 10:00 ` Bosko Radivojevic 2008-04-03 12:52 ` Perrine Martignoni @ 2008-04-03 13:42 ` Gilles Chanteperdrix 2008-04-03 14:34 ` Perrine Martignoni 1 sibling, 1 reply; 11+ messages in thread From: Gilles Chanteperdrix @ 2008-04-03 13:42 UTC (permalink / raw) To: Bosko Radivojevic; +Cc: xenomai-help On Thu, Apr 3, 2008 at 12:00 PM, Bosko Radivojevic <bosko.radivojevic@domain.hid> wrote: > Why don't you try rt_heap_* functions? Quick example: > > Kernel space: > > RT_HEAP heap_desc; > void *shared; > > rt_heap_create (&heap_desc, "MySHM", 2048, H_SHARED); > rt_heap_alloc (&heap_desc, 0, TM_NONBLOCK, &shared); > [.. cleanup ..] > rt_heap_delete (&heap_desc); > User space: > > RT_HEAP heap_desc; > void *shared; > > rt_heap_bind (&heap_desc, "MySHM", TM_NONBLOCK); > rt_heap_alloc (&heap_desc, 0, TM_NONBLOCK, &shared); > [..cleanup..] > rt_heap_unbind (&heap_desc); > > ============================================ > > Hope this helps :) This is a bad example. A good example would check the return values of the services called. -- Gilles ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Xenomai-help] Question about rtdm_mmap_to_user() 2008-04-03 13:42 ` Gilles Chanteperdrix @ 2008-04-03 14:34 ` Perrine Martignoni 2008-04-03 16:25 ` Philippe Gerum 0 siblings, 1 reply; 11+ messages in thread From: Perrine Martignoni @ 2008-04-03 14:34 UTC (permalink / raw) To: xenomai-help [-- Attachment #1: Type: text/plain, Size: 4966 bytes --] >Mixing up RTDM and native API usage, though technically feasible, isn't a good idea anyway. Better have a look at Hannes' example, >and if that one or your own version still doesn't work, post more details (Xenomai version, target architecture, test code, etc.). I found an example in Native-API-Tour.pdf which do this. I try to follow it and it doesn't work. I work on an MPC8347 with linux-2.6.23 and xenomai-2.4.0. Here is my code : *In kernel space* : I create a memory heap in init() ---------------------------------------------------------------------------------------------------------------------------------------------- #include <rtdm/rtdm_driver.h> static struct rtdm_device t_MEMDevice = { struct_version: RTDM_DEVICE_STRUCT_VER, device_flags: RTDM_NAMED_DEVICE, context_size: 0, device_name: DEV_FILE_MEMORY, open_rt: NULL, open_nrt: dmem_Open, ops:{ close_rt: NULL, close_nrt: dmem_Close, ioctl_rt: dmem_Ioctl, ioctl_nrt: dmem_Ioctl, read_rt: NULL, read_nrt: NULL, write_rt: NULL, write_rt: NULL, recvmsg_rt: NULL, recvmsg_nrt:NULL, sendmsg_rt: NULL, sendmsg_nrt:NULL, }, device_class: RTDM_CLASS_EXPERIMENTAL, device_sub_class: 222, driver_name: DRV_NAME, peripheral_name: DEV_FILE_NAME, provider_name: "-", proc_name: t_MEMDevice.device_name, }; static int dmem_Init(void) { RT_HEAP Heap; int ret =0; void *p_HeapMem = NULL; if((ret = rt_heap_create(&Heap, "HeapTest", 2048, H_MAPPABLE | H_SINGLE))) { rtdm_printk("Impossible de creer l'espace memoire Heap : ret = %d\n", ret); } ret = rt_heap_alloc(&Heap, 0, TM_INFINITE, &p_HeapMem); rtdm_printk("**DRIVER p_HeapMem %x \n", p_HeapMem); if(ret != 0) rtdm_printk("RETOUR ALLOC ret %d\n",ret); if(rtdm_dev_register(&t_MEMDevice)!=0) rtdm_printk("Enregistrement impossible du device MEMORY\n"); else rtdm_printk("Initialisation OK\n"); return 0; } static void dmem_Exit(void) { if(rtdm_dev_unregister(&t_MEMDevice,0)) rtdm_printk("Desabonnement KO\n"); else rtdm_printk("Desabonnement OK\n"); } module_init(dmem_Init); module_exit(dmem_Exit); ---------------------------------------------------------------------------------------------------------------------------------- I see in /proc/xenomai/registry/native/heaps the *HeapTest *I create. And I see that : * type=kernel:size=3017801728:used=1 In User space :* I want to bind the heap -------------------------------------------------------------------------------------------------------------------------------- #include<stdio.h> #include<stdlib.h> #include<string.h> #include <sys/mman.h> #include <native/task.h> #include <native/heap.h> #define TASK_PRIO 50 static RT_TASK s_TaskTest; static void taskTest(void *cookie) { void *p_HeapMem = NULL; int i=0; int ret=0; RT_HEAP Heap; ret = rt_heap_bind(&Heap, "HeapTest", TM_INFINITE); printf("ret heap_bind %d\n", ret); rt_heap_alloc(&Heap, 0, TM_INFINITE, &p_HeapMem); printf("p_HeapMem %x \n", p_HeapMem); } int main(int argc, char * argv[]) { int ret = 0; mlockall(MCL_CURRENT | MCL_FUTURE); // creation de la tache temps reel TaskTest if((ret = rt_task_create(&s_TaskTest, "TaskTest", 0, TASK_PRIO, T_JOINABLE))){ fprintf(stderr,"failed to create TaskTest, code %d\n",ret); return ret; } // demarrage de la tache temps reel TaskTest if((ret = rt_task_start(&s_TaskTest, &taskTest, (void *)1))){ fprintf(stderr,"failed to start TaskTest, code %d\n",ret); return ret; } rt_task_join(&s_TaskTest); return ret; } When I put NONBLOCK, I have the error -11 and when I put TM_INFINITE, it runs and doesn't stop. Best Regards, Perrine On Thu, Apr 3, 2008 at 3:42 PM, Gilles Chanteperdrix < gilles.chanteperdrix@xenomai.org> wrote: > On Thu, Apr 3, 2008 at 12:00 PM, Bosko Radivojevic > <bosko.radivojevic@domain.hid> wrote: > > Why don't you try rt_heap_* functions? Quick example: > > > > Kernel space: > > > > RT_HEAP heap_desc; > > void *shared; > > > > rt_heap_create (&heap_desc, "MySHM", 2048, H_SHARED); > > rt_heap_alloc (&heap_desc, 0, TM_NONBLOCK, &shared); > > [.. cleanup ..] > > rt_heap_delete (&heap_desc); > > User space: > > > > RT_HEAP heap_desc; > > void *shared; > > > > rt_heap_bind (&heap_desc, "MySHM", TM_NONBLOCK); > > rt_heap_alloc (&heap_desc, 0, TM_NONBLOCK, &shared); > > [..cleanup..] > > rt_heap_unbind (&heap_desc); > > > > ============================================ > > > > Hope this helps :) > > This is a bad example. A good example would check the return values of > the services called. > > -- > Gilles > [-- Attachment #2: Type: text/html, Size: 19230 bytes --] ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Xenomai-help] Question about rtdm_mmap_to_user() 2008-04-03 14:34 ` Perrine Martignoni @ 2008-04-03 16:25 ` Philippe Gerum 0 siblings, 0 replies; 11+ messages in thread From: Philippe Gerum @ 2008-04-03 16:25 UTC (permalink / raw) To: Perrine Martignoni; +Cc: xenomai-help Perrine Martignoni wrote: >>Mixing up RTDM and native API usage, though technically feasible, isn't > a good idea anyway. Better have a look at Hannes' example, >and if that > one or your own version still doesn't work, post more details (Xenomai > version, target architecture, test code, etc.). > > I found an example in Native-API-Tour.pdf which do this. I try to follow > it and it doesn't work. > Except that the example listed in the document in question takes care of defining the heap descriptor in global memory, not in the init_module() stack. > static int dmem_Init(void) > { > RT_HEAP Heap; ^^^^ this won't survive long enough. > int ret =0; > void *p_HeapMem = NULL; > ---------------------------------------------------------------------------------------------------------------------------------- > > I see in /proc/xenomai/registry/native/heaps the /HeapTest /I create. > And I see that : > > * type=kernel:size=3017801728:used=1 > i.e. we see a 2.8+ _gigabyte_ heap from which 1 single byte would be in use..., albeit you defined a 2Kb heap initially, to be used as a single contiguous segment. Getting braindamage values like this when looking at the /proc interface should ring a bell about a possible corruption of some important kernel-based information, like a heap descriptor. -- Philippe. ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Xenomai-help] Question about rtdm_mmap_to_user() 2008-04-03 9:46 [Xenomai-help] Question about rtdm_mmap_to_user() Perrine Martignoni 2008-04-03 10:00 ` Bosko Radivojevic @ 2008-04-03 10:07 ` Hannes Mayer 1 sibling, 0 replies; 11+ messages in thread From: Hannes Mayer @ 2008-04-03 10:07 UTC (permalink / raw) To: xenomai-help http://www.captain.at/xenomai-real-time-driver-example.php :-) Perrine Martignoni wrote: > Hello, > > I try to allocate a buffer in kernel space (with kmalloc) and then map > it into user-space (with rtdm_mmap_to_user). > After, I fill in the buffer in user space with the address returned by > rtdm_mmap_to_user, and when I read it into the kernel space with the > kernel address, I don't have the values put in user-space. > > What I'm doing wrong ? > Have you a simple example of use of rtdm_mmap_to_user ? > > Thanks in advance. > Best Regards, > Perrine > > > ------------------------------------------------------------------------ > > _______________________________________________ > Xenomai-help mailing list > Xenomai-help@domain.hid > https://mail.gna.org/listinfo/xenomai-help ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2008-04-04 13:04 UTC | newest] Thread overview: 11+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2008-04-03 9:46 [Xenomai-help] Question about rtdm_mmap_to_user() Perrine Martignoni 2008-04-03 10:00 ` Bosko Radivojevic 2008-04-03 12:52 ` Perrine Martignoni 2008-04-03 13:07 ` Jan Kiszka 2008-04-04 7:18 ` Bosko Radivojevic 2008-04-04 12:59 ` Perrine Martignoni 2008-04-04 13:04 ` Gilles Chanteperdrix 2008-04-03 13:42 ` Gilles Chanteperdrix 2008-04-03 14:34 ` Perrine Martignoni 2008-04-03 16:25 ` Philippe Gerum 2008-04-03 10:07 ` Hannes Mayer
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.