deferred_io.txt 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. Deferred IO
  2. -----------
  3. Deferred IO is a way to delay and repurpose IO. It uses host memory as a
  4. buffer and the MMU pagefault as a pretrigger for when to perform the device
  5. IO. The following example may be a useful explanation of how one such setup
  6. works:
  7. - userspace app like Xfbdev mmaps framebuffer
  8. - deferred IO and driver sets up fault and page_mkwrite handlers
  9. - userspace app tries to write to mmaped vaddress
  10. - we get pagefault and reach fault handler
  11. - fault handler finds and returns physical page
  12. - we get page_mkwrite where we add this page to a list
  13. - schedule a workqueue task to be run after a delay
  14. - app continues writing to that page with no additional cost. this is
  15. the key benefit.
  16. - the workqueue task comes in and mkcleans the pages on the list, then
  17. completes the work associated with updating the framebuffer. this is
  18. the real work talking to the device.
  19. - app tries to write to the address (that has now been mkcleaned)
  20. - get pagefault and the above sequence occurs again
  21. As can be seen from above, one benefit is roughly to allow bursty framebuffer
  22. writes to occur at minimum cost. Then after some time when hopefully things
  23. have gone quiet, we go and really update the framebuffer which would be
  24. a relatively more expensive operation.
  25. For some types of nonvolatile high latency displays, the desired image is
  26. the final image rather than the intermediate stages which is why it's okay
  27. to not update for each write that is occurring.
  28. It may be the case that this is useful in other scenarios as well. Paul Mundt
  29. has mentioned a case where it is beneficial to use the page count to decide
  30. whether to coalesce and issue SG DMA or to do memory bursts.
  31. Another one may be if one has a device framebuffer that is in an usual format,
  32. say diagonally shifting RGB, this may then be a mechanism for you to allow
  33. apps to pretend to have a normal framebuffer but reswizzle for the device
  34. framebuffer at vsync time based on the touched pagelist.
  35. How to use it: (for applications)
  36. ---------------------------------
  37. No changes needed. mmap the framebuffer like normal and just use it.
  38. How to use it: (for fbdev drivers)
  39. ----------------------------------
  40. The following example may be helpful.
  41. 1. Setup your structure. Eg:
  42. static struct fb_deferred_io hecubafb_defio = {
  43. .delay = HZ,
  44. .deferred_io = hecubafb_dpy_deferred_io,
  45. };
  46. The delay is the minimum delay between when the page_mkwrite trigger occurs
  47. and when the deferred_io callback is called. The deferred_io callback is
  48. explained below.
  49. 2. Setup your deferred IO callback. Eg:
  50. static void hecubafb_dpy_deferred_io(struct fb_info *info,
  51. struct list_head *pagelist)
  52. The deferred_io callback is where you would perform all your IO to the display
  53. device. You receive the pagelist which is the list of pages that were written
  54. to during the delay. You must not modify this list. This callback is called
  55. from a workqueue.
  56. 3. Call init
  57. info->fbdefio = &hecubafb_defio;
  58. fb_deferred_io_init(info);
  59. 4. Call cleanup
  60. fb_deferred_io_cleanup(info);