preempt.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #ifndef __LINUX_PREEMPT_H
  2. #define __LINUX_PREEMPT_H
  3. /*
  4. * include/linux/preempt.h - macros for accessing and manipulating
  5. * preempt_count (used for kernel preemption, interrupt count, etc.)
  6. */
  7. #include <linux/thread_info.h>
  8. #include <linux/linkage.h>
  9. #include <linux/list.h>
  10. #ifdef CONFIG_DEBUG_PREEMPT
  11. extern void add_preempt_count(int val);
  12. extern void sub_preempt_count(int val);
  13. #else
  14. # define add_preempt_count(val) do { preempt_count() += (val); } while (0)
  15. # define sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
  16. #endif
  17. #define inc_preempt_count() add_preempt_count(1)
  18. #define dec_preempt_count() sub_preempt_count(1)
  19. #define preempt_count() (current_thread_info()->preempt_count)
  20. #ifdef CONFIG_PREEMPT
  21. asmlinkage void preempt_schedule(void);
  22. #define preempt_disable() \
  23. do { \
  24. inc_preempt_count(); \
  25. barrier(); \
  26. } while (0)
  27. #define preempt_enable_no_resched() \
  28. do { \
  29. barrier(); \
  30. dec_preempt_count(); \
  31. } while (0)
  32. #define preempt_check_resched() \
  33. do { \
  34. if (unlikely(test_thread_flag(TIF_NEED_RESCHED))) \
  35. preempt_schedule(); \
  36. } while (0)
  37. #define preempt_enable() \
  38. do { \
  39. preempt_enable_no_resched(); \
  40. barrier(); \
  41. preempt_check_resched(); \
  42. } while (0)
  43. #else
  44. #define preempt_disable() do { } while (0)
  45. #define preempt_enable_no_resched() do { } while (0)
  46. #define preempt_enable() do { } while (0)
  47. #define preempt_check_resched() do { } while (0)
  48. #endif
  49. #ifdef CONFIG_PREEMPT_NOTIFIERS
  50. struct preempt_notifier;
  51. /**
  52. * preempt_ops - notifiers called when a task is preempted and rescheduled
  53. * @sched_in: we're about to be rescheduled:
  54. * notifier: struct preempt_notifier for the task being scheduled
  55. * cpu: cpu we're scheduled on
  56. * @sched_out: we've just been preempted
  57. * notifier: struct preempt_notifier for the task being preempted
  58. * next: the task that's kicking us out
  59. */
  60. struct preempt_ops {
  61. void (*sched_in)(struct preempt_notifier *notifier, int cpu);
  62. void (*sched_out)(struct preempt_notifier *notifier,
  63. struct task_struct *next);
  64. };
  65. /**
  66. * preempt_notifier - key for installing preemption notifiers
  67. * @link: internal use
  68. * @ops: defines the notifier functions to be called
  69. *
  70. * Usually used in conjunction with container_of().
  71. */
  72. struct preempt_notifier {
  73. struct hlist_node link;
  74. struct preempt_ops *ops;
  75. };
  76. void preempt_notifier_register(struct preempt_notifier *notifier);
  77. void preempt_notifier_unregister(struct preempt_notifier *notifier);
  78. static inline void preempt_notifier_init(struct preempt_notifier *notifier,
  79. struct preempt_ops *ops)
  80. {
  81. INIT_HLIST_NODE(&notifier->link);
  82. notifier->ops = ops;
  83. }
  84. #endif
  85. #endif /* __LINUX_PREEMPT_H */