home *** CD-ROM | disk | FTP | other *** search
/ Chip 1999 October / CHIP_CD_1999_10_PL.iso / offline / software / be / Be Book / Drivers / doc < prev    next >
Encoding:
Text File  |  1999-05-10  |  2.3 KB  |  68 lines

  1. Starting with the beta Genki 6, the kernel enforces
  2. a little more strictly certain rules on how
  3. kernel add-ons like drivers and bus_managers use
  4. spinlocks and disable interrupts. Here's a quick
  5. reminder about the basic principles. Don't hesitate
  6. to discuss it with us at devinfo@be.com.
  7.  
  8.  
  9. synchronization: semaphores vs. spinlocks:
  10. ------------------------------------------
  11.  
  12. Semaphores should be used whenever possible,
  13. because they do not incur busy waiting. The
  14. only reason to use spinlocks is for critical
  15. sections executed by interrupt handlers.
  16. It is a very bad programming error to acquire
  17. a semaphore in an interrupt handler. This
  18. makes spinlock the only alternative available
  19. at interrupt time.
  20.  
  21. Spinlock-protected critical sections should
  22. be executed with interrupts disabled. It is
  23. not necessary to explicitly disable interrupts
  24. in spinlock-protected critical sections used only
  25. by interrupt handlers because they are invoked
  26. with interrupts already disabled.
  27.  
  28. There are very few things that may be done in
  29. a spinlock-protected critical section. All the
  30. restrictions that apply to code run with interrupts
  31. disabled apply here (see list below under next section).
  32. And other rules apply in addition. Here's the list of
  33. what can be done:
  34. - touch hardware registers (through bus managers
  35.   hooks)
  36. - touch memory that is locked down. No memory can
  37.   be allocated!
  38. - call the following functions:
  39.     kernel:
  40.         . system_time()
  41.         . atomic_XXX()
  42.     bus managers:
  43.         IO functions: read_io_XX(), write_io_XX()
  44.  
  45. disabling interrupts:
  46. ---------------------
  47.  
  48. Disable interrupts only around critical sections
  49. protected by spinlocks (see discussion on spinlocks).
  50. If you think you need to disable interrupts for
  51. another reason, discuss it with us at devsupport@be.com.
  52.  
  53. Disable interrupts for the shortest time possible -- never
  54. longer than 50us. Because interrupt handlers are
  55. executed implicitely with interrupts disabled, they
  56. should not run than 50 us as well.
  57.  
  58. No blocking call can be made when interrupts are disabled.
  59. In addition to what you can do in spinlock-protected
  60. sections, here a list of the calls you can make:
  61. - release_sem_etc() with B_DO_NO_RESCHEDULE as flags.
  62. - get_sem_count()
  63. - add_timer(), cancel_timer()
  64. - dprintf()
  65.  
  66. If you feel you need to call a function that is not in
  67. this list, discuss it with us at devinfo@be.com.
  68.