sched_prim.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. * Mach Operating System
  3. * Copyright (c) 1992,1991,1990,1989,1988,1987 Carnegie Mellon University
  4. * All Rights Reserved.
  5. *
  6. * Permission to use, copy, modify and distribute this software and its
  7. * documentation is hereby granted, provided that both the copyright
  8. * notice and this permission notice appear in all copies of the
  9. * software, derivative works or modified versions, and any portions
  10. * thereof, and that both notices appear in supporting documentation.
  11. *
  12. * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
  13. * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
  14. * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  15. *
  16. * Carnegie Mellon requests users of this software to return to
  17. *
  18. * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
  19. * School of Computer Science
  20. * Carnegie Mellon University
  21. * Pittsburgh PA 15213-3890
  22. *
  23. * any improvements or extensions that they make and grant Carnegie Mellon
  24. * the rights to redistribute these changes.
  25. */
  26. /*
  27. * File: sched_prim.h
  28. * Author: David Golub
  29. *
  30. * Scheduling primitive definitions file
  31. *
  32. */
  33. #ifndef _KERN_SCHED_PRIM_H_
  34. #define _KERN_SCHED_PRIM_H_
  35. #include <mach/boolean.h>
  36. #include <mach/message.h> /* for mach_msg_timeout_t */
  37. #include <kern/lock.h>
  38. #include <kern/kern_types.h> /* for thread_t */
  39. /*
  40. * Possible results of assert_wait - returned in
  41. * current_thread()->wait_result.
  42. */
  43. #define THREAD_AWAKENED 0 /* normal wakeup */
  44. #define THREAD_TIMED_OUT 1 /* timeout expired */
  45. #define THREAD_INTERRUPTED 2 /* interrupted by clear_wait */
  46. #define THREAD_RESTART 3 /* restart operation entirely */
  47. typedef void *event_t; /* wait event */
  48. typedef void (*continuation_t)(void); /* continuation */
  49. #define thread_no_continuation ((continuation_t) 0) /* no continuation */
  50. /*
  51. * Exported interface to sched_prim.c.
  52. */
  53. extern void sched_init(void);
  54. extern void assert_wait(
  55. event_t event,
  56. boolean_t interruptible);
  57. extern void clear_wait(
  58. thread_t thread,
  59. int result,
  60. boolean_t interrupt_only);
  61. extern void thread_sleep(
  62. event_t event,
  63. simple_lock_t lock,
  64. boolean_t interruptible);
  65. extern void thread_wakeup(void); /* for function pointers */
  66. extern boolean_t thread_wakeup_prim(
  67. event_t event,
  68. boolean_t one_thread,
  69. int result);
  70. extern boolean_t thread_invoke(
  71. thread_t old_thread,
  72. continuation_t continuation,
  73. thread_t new_thread);
  74. extern void thread_block(
  75. continuation_t continuation);
  76. extern kern_return_t thread_unblock(
  77. thread_t thread,kern_return_t wresult);
  78. extern void thread_run(
  79. continuation_t continuation,
  80. thread_t new_thread);
  81. extern void thread_set_timeout(
  82. int t);
  83. extern void thread_setrun(
  84. thread_t thread,
  85. boolean_t may_preempt);
  86. extern void thread_dispatch(
  87. thread_t thread);
  88. extern void thread_continue(
  89. thread_t old_thread);
  90. extern void thread_go(
  91. thread_t thread);
  92. extern void thread_will_wait(
  93. thread_t thread);
  94. extern void thread_will_wait_with_timeout(
  95. thread_t thread,
  96. mach_msg_timeout_t msecs);
  97. extern boolean_t thread_handoff(
  98. thread_t old_thread,
  99. continuation_t continuation,
  100. thread_t new_thread);
  101. extern void recompute_priorities(void *param);
  102. extern void update_priority(
  103. thread_t thread);
  104. extern void compute_my_priority(
  105. thread_t thread);
  106. extern void thread_bind(
  107. thread_t thread,
  108. processor_t processor);
  109. extern void compute_priority(
  110. thread_t thread,
  111. boolean_t resched);
  112. extern void thread_timeout_setup(
  113. thread_t thread);
  114. /*
  115. * Routines defined as macros
  116. */
  117. #define thread_wakeup(x) \
  118. thread_wakeup_prim((x), FALSE, THREAD_AWAKENED)
  119. #define thread_wakeup_with_result(x, z) \
  120. thread_wakeup_prim((x), FALSE, (z))
  121. #define thread_wakeup_one(x) \
  122. thread_wakeup_prim((x), TRUE, THREAD_AWAKENED)
  123. /*
  124. * Machine-dependent code must define these functions.
  125. */
  126. extern void thread_bootstrap_return(void) __attribute__((noreturn));
  127. extern void thread_exception_return(void) __attribute__((noreturn));
  128. extern void __attribute__((__noreturn__)) thread_syscall_return(kern_return_t);
  129. extern thread_t switch_context(
  130. thread_t old_thread,
  131. continuation_t continuation,
  132. thread_t new_thread);
  133. extern void stack_handoff(
  134. thread_t old_thread,
  135. thread_t new_thread);
  136. /*
  137. * These functions are either defined in kern/thread.c
  138. * via machine-dependent stack_attach and stack_detach functions,
  139. * or are defined directly by machine-dependent code.
  140. */
  141. extern kern_return_t stack_alloc(
  142. thread_t thread,
  143. void (*resume)(thread_t));
  144. extern boolean_t stack_alloc_try(
  145. thread_t thread,
  146. void (*resume)(thread_t));
  147. extern void stack_free(
  148. thread_t thread);
  149. /*
  150. * Convert a timeout in milliseconds (mach_msg_timeout_t)
  151. * to a timeout in ticks (for use by set_timeout).
  152. * This conversion rounds UP so that small timeouts
  153. * at least wait for one tick instead of not waiting at all.
  154. */
  155. #define convert_ipc_timeout_to_ticks(millis) \
  156. (((millis) * hz + 999) / 1000)
  157. void set_pri(thread_t th, int pri, boolean_t resched);
  158. void do_thread_scan(void);
  159. thread_t choose_pset_thread(processor_t myprocessor, processor_set_t pset);
  160. #if DEBUG
  161. #include <kern/sched.h> /* for run_queue_t */
  162. void checkrq(run_queue_t rq, const char *msg);
  163. void thread_check(thread_t th, run_queue_t rq);
  164. #endif /* DEBUG */
  165. extern void idle_thread(void) __attribute__((noreturn));
  166. extern void sched_thread(void);
  167. #endif /* _KERN_SCHED_PRIM_H_ */