processor.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. /*
  2. * Mach Operating System
  3. * Copyright (c) 1991,1990,1989 Carnegie Mellon University.
  4. * Copyright (c) 1993,1994 The University of Utah and
  5. * the Computer Systems Laboratory (CSL).
  6. * All rights reserved.
  7. *
  8. * Permission to use, copy, modify and distribute this software and its
  9. * documentation is hereby granted, provided that both the copyright
  10. * notice and this permission notice appear in all copies of the
  11. * software, derivative works or modified versions, and any portions
  12. * thereof, and that both notices appear in supporting documentation.
  13. *
  14. * CARNEGIE MELLON, THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF
  15. * THIS SOFTWARE IN ITS "AS IS" CONDITION, AND DISCLAIM ANY LIABILITY
  16. * OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF
  17. * THIS SOFTWARE.
  18. *
  19. * Carnegie Mellon requests users of this software to return to
  20. *
  21. * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
  22. * School of Computer Science
  23. * Carnegie Mellon University
  24. * Pittsburgh PA 15213-3890
  25. *
  26. * any improvements or extensions that they make and grant Carnegie Mellon
  27. * the rights to redistribute these changes.
  28. */
  29. /*
  30. * processor.h: Processor and processor-set definitions.
  31. */
  32. #ifndef _KERN_PROCESSOR_H_
  33. #define _KERN_PROCESSOR_H_
  34. /*
  35. * Data structures for managing processors and sets of processors.
  36. */
  37. #include <mach/boolean.h>
  38. #include <mach/kern_return.h>
  39. #include <mach/port.h>
  40. #include <mach/processor_info.h>
  41. #include <kern/cpu_number.h>
  42. #include <kern/lock.h>
  43. #include <kern/queue.h>
  44. #include <kern/sched.h>
  45. #include <kern/kern_types.h>
  46. #include <kern/host.h>
  47. #if NCPUS > 1
  48. #include <machine/ast_types.h>
  49. #endif /* NCPUS > 1 */
  50. struct processor_set {
  51. struct run_queue runq; /* runq for this set */
  52. queue_head_t idle_queue; /* idle processors */
  53. int idle_count; /* how many ? */
  54. decl_simple_lock_data(, idle_lock) /* lock for above */
  55. queue_head_t processors; /* all processors here */
  56. int processor_count; /* how many ? */
  57. boolean_t empty; /* true if no processors */
  58. queue_head_t tasks; /* tasks assigned */
  59. int task_count; /* how many */
  60. queue_head_t threads; /* threads in this set */
  61. int thread_count; /* how many */
  62. int ref_count; /* structure ref count */
  63. decl_simple_lock_data(, ref_lock) /* lock for ref count */
  64. queue_chain_t all_psets; /* link for all_psets */
  65. boolean_t active; /* is pset in use */
  66. decl_simple_lock_data(, lock) /* lock for everything else */
  67. struct ipc_port * pset_self; /* port for operations */
  68. struct ipc_port * pset_name_self; /* port for information */
  69. int max_priority; /* maximum priority */
  70. #if MACH_FIXPRI
  71. int policies; /* bit vector for policies */
  72. #endif /* MACH_FIXPRI */
  73. int set_quantum; /* current default quantum */
  74. #if NCPUS > 1
  75. int quantum_adj_index; /* runtime quantum adj. */
  76. decl_simple_lock_data(, quantum_adj_lock) /* lock for above */
  77. int machine_quantum[NCPUS+1]; /* ditto */
  78. #endif /* NCPUS > 1 */
  79. long mach_factor; /* mach_factor */
  80. long load_average; /* load_average */
  81. long sched_load; /* load avg for scheduler */
  82. };
  83. extern struct processor_set default_pset;
  84. struct processor {
  85. struct run_queue runq; /* local runq for this processor */
  86. /* XXX want to do this round robin eventually */
  87. queue_chain_t processor_queue; /* idle/assign/shutdown queue link */
  88. int state; /* See below */
  89. struct thread *next_thread; /* next thread to run if dispatched */
  90. struct thread *idle_thread; /* this processor's idle thread. */
  91. int quantum; /* quantum for current thread */
  92. boolean_t first_quantum; /* first quantum in succession */
  93. int last_quantum; /* last quantum assigned */
  94. processor_set_t processor_set; /* processor set I belong to */
  95. processor_set_t processor_set_next; /* set I will belong to */
  96. queue_chain_t processors; /* all processors in set */
  97. decl_simple_lock_data(, lock)
  98. struct ipc_port *processor_self; /* port for operations */
  99. int slot_num; /* machine-indep slot number */
  100. #if NCPUS > 1
  101. ast_check_t ast_check_data; /* for remote ast_check invocation */
  102. #endif /* NCPUS > 1 */
  103. /* punt id data temporarily */
  104. };
  105. typedef struct processor Processor;
  106. extern struct processor processor_array[NCPUS];
  107. /*
  108. * Chain of all processor sets.
  109. */
  110. extern queue_head_t all_psets;
  111. extern int all_psets_count;
  112. decl_simple_lock_data(extern, all_psets_lock);
  113. /*
  114. * The lock ordering is:
  115. *
  116. * all_psets_lock
  117. * |
  118. * |
  119. * V
  120. * pset_lock
  121. * |
  122. * +-----------+---------------+-------------------+
  123. * | | | |
  124. * | | | |
  125. * | | V V
  126. * | | task_lock pset_self->ip_lock
  127. * | | | |
  128. * | | +-----------+---------------+ |
  129. * | | | | |
  130. * | V V V V
  131. * | thread_lock* pset_ref_lock
  132. * | |
  133. * | +-------+
  134. * | | |
  135. * | | V
  136. * | | runq_lock*
  137. * | |
  138. * V V
  139. * processor_lock*
  140. * |
  141. * |
  142. * V
  143. * pset_idle_lock*
  144. * |
  145. * |
  146. * V
  147. * action_lock*
  148. *
  149. * Locks marked with "*" are taken at splsched.
  150. */
  151. /*
  152. * XXX need a pointer to the master processor structure
  153. */
  154. extern processor_t master_processor;
  155. /*
  156. * NOTE: The processor->processor_set link is needed in one of the
  157. * scheduler's critical paths. [Figure out where to look for another
  158. * thread to run on this processor.] It is accessed without locking.
  159. * The following access protocol controls this field.
  160. *
  161. * Read from own processor - just read.
  162. * Read from another processor - lock processor structure during read.
  163. * Write from own processor - lock processor structure during write.
  164. * Write from another processor - NOT PERMITTED.
  165. *
  166. */
  167. /*
  168. * Processor state locking:
  169. *
  170. * Values for the processor state are defined below. If the processor
  171. * is off-line or being shutdown, then it is only necessary to lock
  172. * the processor to change its state. Otherwise it is only necessary
  173. * to lock its processor set's idle_lock. Scheduler code will
  174. * typically lock only the idle_lock, but processor manipulation code
  175. * will often lock both.
  176. */
  177. #define PROCESSOR_OFF_LINE 0 /* Not in system */
  178. #define PROCESSOR_RUNNING 1 /* Running normally */
  179. #define PROCESSOR_IDLE 2 /* idle */
  180. #define PROCESSOR_DISPATCHING 3 /* dispatching (idle -> running) */
  181. #define PROCESSOR_ASSIGN 4 /* Assignment is changing */
  182. #define PROCESSOR_SHUTDOWN 5 /* Being shutdown */
  183. /*
  184. * Use processor ptr array to find current processor's data structure.
  185. * This replaces a multiplication (index into processor_array) with
  186. * an array lookup and a memory reference. It also allows us to save
  187. * space if processor numbering gets too sparse.
  188. */
  189. extern processor_t processor_ptr[NCPUS];
  190. #define cpu_to_processor(i) (processor_ptr[i])
  191. #define current_processor() (processor_ptr[cpu_number()])
  192. #define current_processor_set() (current_processor()->processor_set)
  193. /* Compatibility -- will go away */
  194. #define cpu_state(slot_num) (processor_ptr[slot_num]->state)
  195. #define cpu_idle(slot_num) (cpu_state(slot_num) == PROCESSOR_IDLE)
  196. /* Useful lock macros */
  197. #define pset_lock(pset) simple_lock(&(pset)->lock)
  198. #define pset_unlock(pset) simple_unlock(&(pset)->lock)
  199. #define pset_ref_lock(pset) simple_lock(&(pset)->ref_lock)
  200. #define pset_ref_unlock(pset) simple_unlock(&(pset)->ref_lock)
  201. #define processor_lock(pr) simple_lock(&(pr)->lock)
  202. #define processor_unlock(pr) simple_unlock(&(pr)->lock)
  203. typedef mach_port_t *processor_array_t;
  204. typedef mach_port_t *processor_set_array_t;
  205. typedef mach_port_t *processor_set_name_array_t;
  206. /*
  207. * Exported functions
  208. */
  209. /* Initialization */
  210. #ifdef KERNEL
  211. #if MACH_HOST
  212. extern void pset_sys_init(void);
  213. #endif /* MACH_HOST */
  214. /* Pset internal functions */
  215. extern void pset_sys_bootstrap(void);
  216. extern void pset_reference(processor_set_t);
  217. extern void pset_deallocate(processor_set_t);
  218. extern void pset_remove_processor(processor_set_t, processor_t);
  219. extern void pset_add_processor(processor_set_t, processor_t);
  220. extern void pset_remove_task(processor_set_t, struct task *);
  221. extern void pset_add_task(processor_set_t, struct task *);
  222. extern void pset_remove_thread(processor_set_t, struct thread *);
  223. extern void pset_add_thread(processor_set_t, struct thread *);
  224. extern void thread_change_psets(struct thread *,
  225. processor_set_t, processor_set_t);
  226. /* Processor interface */
  227. extern kern_return_t processor_get_assignment(
  228. processor_t processor,
  229. processor_set_t *processor_set);
  230. extern kern_return_t processor_info(
  231. processor_t processor,
  232. int flavor,
  233. host_t * host,
  234. processor_info_t info,
  235. natural_t * count);
  236. extern kern_return_t processor_start(
  237. processor_t processor);
  238. extern kern_return_t processor_exit(
  239. processor_t processor);
  240. extern kern_return_t processor_control(
  241. processor_t processor,
  242. processor_info_t info,
  243. natural_t count);
  244. /* Pset interface */
  245. extern kern_return_t processor_set_create(
  246. host_t host,
  247. processor_set_t *new_set,
  248. processor_set_t *new_name);
  249. extern kern_return_t processor_set_destroy(
  250. processor_set_t pset);
  251. extern kern_return_t processor_set_info(
  252. processor_set_t pset,
  253. int flavor,
  254. host_t *host,
  255. processor_set_info_t info,
  256. natural_t *count);
  257. extern kern_return_t processor_set_max_priority(
  258. processor_set_t pset,
  259. int max_priority,
  260. boolean_t change_threads);
  261. extern kern_return_t processor_set_policy_enable(
  262. processor_set_t pset,
  263. int policy);
  264. extern kern_return_t processor_set_policy_disable(
  265. processor_set_t pset,
  266. int policy,
  267. boolean_t change_threads);
  268. extern kern_return_t processor_set_tasks(
  269. processor_set_t pset,
  270. task_array_t *task_list,
  271. natural_t *count);
  272. extern kern_return_t processor_set_threads(
  273. processor_set_t pset,
  274. thread_array_t *thread_list,
  275. natural_t *count);
  276. #endif
  277. void processor_doaction(processor_t processor);
  278. void processor_doshutdown(processor_t processor);
  279. void quantum_set(processor_set_t pset);
  280. void pset_init(processor_set_t pset);
  281. void processor_init(processor_t pr, int slot_num);
  282. #endif /* _KERN_PROCESSOR_H_ */