1 / 12

The ‘mmap()’ method

The ‘mmap()’ method. Adding the ‘mmap()’ capability to our ‘vram.c’ device-driver. Purpose of ‘mmap()’. The ‘mmap()’ system-call creates a new region in the task’s virtual memory map, and associates that region with a file (or with a device-file such as ‘/dev/vram’)

aran
Download Presentation

The ‘mmap()’ method

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The ‘mmap()’ method Adding the ‘mmap()’ capability to our ‘vram.c’ device-driver

  2. Purpose of ‘mmap()’ • The ‘mmap()’ system-call creates a new region in the task’s virtual memory map, and associates that region with a file (or with a device-file such as ‘/dev/vram’) • It returns a pointer to this memory area • Thus it allows the program to access the file as if it were an array in user-space • Avoids ‘read()’ and ‘write()’ system-calls

  3. Mapping vram to userspace Kernel Text/Data Kernel space VRAM m map() STACK VRAM User space RUNTIME LIBRARIES HIGHMEM ZONE NORMAL TEXT/DATA physical address-space virtual address-space

  4. ‘mmap()’ syntax void *mmap( void *start, size_t length, int prot, int flags, int fd, off_t offset );

  5. The ‘page-protection’ bits • PROT_READ • PROT_WRITE • PROT_EXEC • PROT_NONE

  6. The ‘flags’ bits • MAP_SHARED • MAP_PRIVATE • MAP_FIXED • MAP_ANONYMOUS • MAP_GROWSDOWN • MAP_DENYWRITE • MAP_EXECUTABLE • MAP_LOCKED • MAP_NORESERVE • MAP_POPULATE • MAP_NONBLOCK

  7. The region to be mapped Total extent of the file file region to be mapped offset length start (virtual address)

  8. Kernel data-structures task_struct mm_struct vm_area_struct mm vma vm_start vm_end pgd vm_start vm_end vm_start vm_end pgd_t page directory vm_start vm_end vm_start vm_end vm_start vm_end vm_start vm_end

  9. The ‘munmap()’ syntax int munmap( void *start, int length );

  10. Demo-program: ‘vrammdraw’ • We added ‘my_mmap()’ to our ‘vram.c’ device-driver (calling it ‘vramm.c’) • We wrote an application (actually a new version of our ‘vramdraw.cpp’ program) that calls our driver’s ‘mmap()’ method • You can try it out – it’s on class website

  11. In-class exercise #1 • Write a new version of our ‘grabber1.cpp’ and ‘grabber2.cpp’ demo-programs which will ‘grab’ a screen-image and write it out to a file, but will NOT make system-calls to ‘read()’ from the ‘/dev/vram’ device-file (it will instead use ‘mmap()’ to map the video display memory into user-space so it can be accessed just like an ordinary array)

  12. In-class exercise #2 • Use the Linux ‘time’ command to compare the execution-speed of your ‘grabber3’ to observed speeds of ‘grabber1’, ’grabber2’

More Related