Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "The ‘mmap()’ method Adding the ‘mmap()’ capability to our ‘vram.c’ device-driver."— 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 virtual address-space physical address-space HIGHMEM ZONE NORMAL Kernel Text/Data VRAM Kernel space User space STACK TEXT/DATA RUNTIME LIBRARIES m map()

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 offset start (virtual address) file region to be mapped length Total extent of the file

8 Kernel data-structures task_struct mm mm_struct page directory pgd_t pgd vma vm_start vm_end vm_area_struct 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’


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

Similar presentations


Ads by Google