?? readme
字號:
INTRODUCTIONThe mbuff.o module and /dev/mbuff is intended to be used as a shared memory device making memory allocated in the kernel usingvmalloc possible to map in the user space. Such memory does not needto be reserved at the system startup and its size is not limited by memoryfragmentation. The allocated memory is logically (but not physically) countinuous. It can not be swapped out, so is well suited for real timeapplications, especially communication between real time tasks and user spaceor other high bandwidth kernel-user data exchange.INSTALLATIONMake sure you have in /usr/src/linux the configured sources of currentlyrunning kernel.The support for the "misc device driver" should be ON in the kernel config.The module is tested with 2.0.36-38, 2.2.12-15 and 2.3.99pre3 SMP and singleprocessor kernels.To test:make testlsmoddmesglsmod (repeat until you see usage count returning to 0).rmmod mbuffRemove -DSHM_DEMO from CFLAGS in Makefile.cp -a ./mbuff /dev/mbuffSet the uid,gid and permissions of /dev/mbuff according to your security policy.make clean; makecp mbuff.o /lib/modules/`uname -r`/miscdepmod -amodprobe mbuffBASIC USAGEThe simplest example is the file demo.c distributed with the package. The void * mbuff_alloc(const char *name, int size)function allocates new area and maps it, or just maps already existing area.The function returns the pointer to the mapped area or NULL in the caseof failure (no /dev/mbuff, bad permisions, mbuff.o not loaded,not enough memory, or size greater than the size of already allocated area).The first call does real allocation (swapping out some programs if neccesary),the next calls should use the "size" argument equal or less than the oneused at the first allocation.mbuff_alloc should be called by each process accessing the memory, as wellas in kernel module. Every process calling mbuff_alloc is responsible for freeing it before exit.It can be done with void mbuff_free(const char *name, void * mbuf)function. It will unmap the memory and decrease usage counter, so when the lastprocess unmaps the memory, it will be freed. "mbuf" should be the pointerreturned initially by mbuff_alloc.For people who often forget to deallocate the memory, there isvoid * mbuff_attach(const char *name, int size)function - it works like mbuff_alloc, exept it does not increase usage counter- memory can be deallocated automatically on munmap (e.g. process gets killed).To unmap it earlier usevoid mbuff_detach(const char *name, void * mbuf)function. All it does is just munmap call.It makes sense to use mbuff_attach and mbuff_detach only in user space.I would advice to declare "volatile" all pointers operating on the shared area - this prevents compiler from guessing the contents.WARNING: mbuff_allocate calls vmalloc, may need to swap out some memory - do not call it from real time nor interrupt nor timer context. This code may call schedule() ! It should be safe to call it from RT-FIFO handler. And of course it may be called in init_module().HOW IT WORKSWell, for details I have to say "read the sources". If you are reallyinterested, compile with debugging and run "make test".Important thing to note are return codes from ioctl functions. They returnthe size of the area (if it exists at the time of return), or a negativeerror code. IOCTL_MBUFF_DEALLOCATE returns size of the area if it stillexists, 0 if it has been just definitively deallocated or negative -EINVALif there is no such named area. You do not need to worry if on the lastDEALLOCATE call you still get positive value - it means just somethingelse is using it.More documentation will follow in next versions. The home site for themodule is http://crds.chemie.unibas.ch/PCI-MIO-E/ - get mbuff-*.tar.gz--Tomasz Motylewski<motyl@stan.chemie.unibas.ch>, <motyl@ip.pl>P.S. I should also mention that there exists another driver("portable_shm") written by Paolo Mantegazza which is based on this code- it is distributed with RTAI version of real time Linux -http://www.aero.polimi.it/projects/rtai/ . It is written for 2.2 SMPkernel. However I would recommend you to use my version of the driver :-)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -