Date: Thu, 27 Oct 2016 01:43:21 +0000 (UTC) From: Giulio Moro Message-ID: <308568998.3587071.1477532601674@mail.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit References: <308568998.3587071.1477532601674.ref@mail.yahoo.com> Subject: [Xenomai] accessing mmap'ed memory causes mode switches Reply-To: Giulio Moro List-Id: Discussions about the Xenomai project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "xenomai@xenomai.org" Hello there, I am new to the list, I am working on this project https://github.com/BelaPlatform/Bela/ for real-time audio on the BeagleBone Black using Xenomai. I am trying to use Xenomai's POSIX skin to create and access shared memory objects, but I am getting mode switches to secondary mode every time I try to access (read or write) the mapped memory, using Xenomai 2.6.3 on Debian ARM Linux 3.8.13r81 (https://github.com/RobertCNelson/bb-kernel/tree/3.8.13-xenomai-r81 ). I would expect no mode switches to take place once the memory is mapped and accessed at least once. Full listing below, Notes: - I build with gcc -I. shm.c `xeno-config --skin posix --cflags` `xeno-config --skin posix --ldflags` `xeno-config --skin native --ldflags` -o shm which evaluates to gcc -I. shm.c -I/usr/xenomai/include -D_GNU_SOURCE -D_REENTRANT -D__XENO__ -I/usr/xenomai/include/posix -Wl,@/usr/xenomai/lib/posix.wrappers -L/usr/xenomai/lib -lpthread_rt -lxenomai -lpthread -lrt -lnative -L/usr/xenomai/lib -lxenomai -lpthread -lrt -o shm - I tried to explicitly use __wrap_shm_open and __wrap_mmap , no change. - I tried with and without the CONFIG_XENO_OPT_POSIX_SHM config line in the kernel, no change. - the documentation does not state that O_DIRECT can only be used when CONFIG_XENO_OPT_POSIX_SHM is activated - the description of the return values for mmap is wrong in the docs http://www.xenomai.org/documentation/trunk/html/api/group__posix__shm.html : it says it returns 0 on success, while it returns the pointer to the memory. minimal example (does not compile, gives you an idea) fd = shm_open(SHM_NAME, O_RDWR | O_CREAT | O_DIRECT, 0); size_t len = 40; ftruncate(fd, len);void* addr = mmap(ignored, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); float* arr = (float*)addr; //causes mode switches: printf("%f\n", arr[n]); Full listing: https://gist.github.com/giuliomoro/457c8cde1eda6190a28566b3288d38c0 Kernel config file: https://gist.github.com/giuliomoro/283c92049704652c06a26ed08669966a Best, Giulio