Friday, December 16, 2005

Userspace VFB Updates

Gerd Knorr pointed me to a VFB driver he recently wrote for UML. The similiarities are pretty interesting and a good sign that I'm going in a plausible direction. Gerd is doing one thing in his driver that peeks my interest quite a bit.

Userspace VFB writes (ala X) are challenging because userspace gets to map the framebuffer directly into its address space. Since there is not update notification mechanism, this makes it very challenging to determine when the framebuffer should be blitted on screen (and which portions should be blitted). Its terribly wasteful to blit the entire framebuffer 30 times a second and even more wasteful to try and map that to something like VNC.

I had briefly considered using demand paging to work around this problem. Linux's mmap() is lazy in that it only maps pages when they are first read/written. You could potentially trap writes by changing the mappings to be read-only or even just not actually map the pages.

Of course, you want to avoid taking a hit for every single byte read/write. I figured this was going to be challenging and put it off. Gerd, however, has found a simple and clever approach. Gerd uses a timer that fires at the FPS rate and if there was a page that has been mapped in since then, he removes the mapping and issues appropriate updates. That's it. It's quite simple and yet also quite powerful. It has all the right properties too of little-to-no performance overhead when the display is idle. I'll certainly be adopting it for the Xen VFB.