task.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * Mach Operating System
  3. * Copyright (c) 1993-1988 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: task.h
  28. * Author: Avadis Tevanian, Jr.
  29. *
  30. * This file contains the structure definitions for tasks.
  31. *
  32. */
  33. #ifndef GNUMACH_KERN_TASK_H_
  34. #define GNUMACH_KERN_TASK_H_
  35. #include <mach/boolean.h>
  36. #include <mach/port.h>
  37. #include <mach/time_value.h>
  38. #include <mach/mach_param.h>
  39. #include <mach/task_info.h>
  40. #include <mach_debug/mach_debug_types.h>
  41. #include <kern/kern_types.h>
  42. #include <kern/lock.h>
  43. #include <kern/queue.h>
  44. #include <kern/pc_sample.h>
  45. #include <kern/processor.h>
  46. #include <kern/syscall_emulation.h>
  47. #include <vm/vm_types.h>
  48. #include <machine/task.h>
  49. /*
  50. * Task name buffer size. The size is chosen so that struct task fits
  51. * into three cache lines. The size of a cache line on a typical CPU
  52. * is 64 bytes.
  53. */
  54. #define TASK_NAME_SIZE 32
  55. struct task {
  56. /* Synchronization/destruction information */
  57. decl_simple_lock_data(,lock) /* Task's lock */
  58. int ref_count; /* Number of references to me */
  59. /* Flags */
  60. unsigned int active:1, /* Task has not been terminated */
  61. /* boolean_t */ may_assign:1, /* can assigned pset be changed? */
  62. assign_active:1; /* waiting for may_assign */
  63. /* Miscellaneous */
  64. vm_map_t map; /* Address space description */
  65. queue_chain_t pset_tasks; /* list of tasks assigned to pset */
  66. int suspend_count; /* Internal scheduling only */
  67. /* Thread information */
  68. queue_head_t thread_list; /* list of threads */
  69. int thread_count; /* number of threads */
  70. processor_set_t processor_set; /* processor set for new threads */
  71. /* User-visible scheduling information */
  72. int user_stop_count; /* outstanding stops */
  73. int priority; /* for new threads */
  74. /* Statistics */
  75. time_value_t total_user_time;
  76. /* total user time for dead threads */
  77. time_value_t total_system_time;
  78. /* total system time for dead threads */
  79. time_value_t creation_time; /* time stamp at creation */
  80. /* IPC structures */
  81. decl_simple_lock_data(, itk_lock_data)
  82. struct ipc_port *itk_self; /* not a right, doesn't hold ref */
  83. struct ipc_port *itk_sself; /* a send right */
  84. struct ipc_port *itk_exception; /* a send right */
  85. struct ipc_port *itk_bootstrap; /* a send right */
  86. struct ipc_port *itk_registered[TASK_PORT_REGISTER_MAX];
  87. /* all send rights */
  88. struct ipc_space *itk_space;
  89. #if 0
  90. /* User space system call emulation support */
  91. struct eml_dispatch *eml_dispatch;
  92. #endif
  93. struct task_struct * linux_task;
  94. sample_control_t pc_sample;
  95. #if FAST_TAS
  96. #define TASK_FAST_TAS_NRAS 8
  97. vm_offset_t fast_tas_base[TASK_FAST_TAS_NRAS];
  98. vm_offset_t fast_tas_end[TASK_FAST_TAS_NRAS];
  99. #endif /* FAST_TAS */
  100. /* Hardware specific data. */
  101. machine_task_t machine;
  102. /* Statistics */
  103. natural_t faults; /* page faults counter */
  104. natural_t zero_fills; /* zero fill pages counter */
  105. natural_t reactivations; /* reactivated pages counter */
  106. natural_t pageins; /* actual pageins couter */
  107. natural_t cow_faults; /* copy-on-write faults counter */
  108. natural_t messages_sent; /* messages sent counter */
  109. natural_t messages_received; /* messages received counter */
  110. char name[TASK_NAME_SIZE];
  111. };
  112. #define task_lock(task) simple_lock(&(task)->lock)
  113. #define task_unlock(task) simple_unlock(&(task)->lock)
  114. #define itk_lock_init(task) simple_lock_init(&(task)->itk_lock_data)
  115. #define itk_lock(task) simple_lock(&(task)->itk_lock_data)
  116. #define itk_unlock(task) simple_unlock(&(task)->itk_lock_data)
  117. /*
  118. * Exported routines/macros
  119. */
  120. extern kern_return_t task_create(
  121. task_t parent_task,
  122. boolean_t inherit_memory,
  123. task_t *child_task);
  124. extern kern_return_t task_create_kernel(
  125. task_t parent_task,
  126. boolean_t inherit_memory,
  127. task_t *child_task);
  128. extern kern_return_t task_terminate(
  129. task_t task);
  130. extern kern_return_t task_suspend(
  131. task_t task);
  132. extern kern_return_t task_resume(
  133. task_t task);
  134. extern kern_return_t task_threads(
  135. task_t task,
  136. thread_array_t *thread_list,
  137. natural_t *count);
  138. extern kern_return_t task_info(
  139. task_t task,
  140. int flavor,
  141. task_info_t task_info_out,
  142. natural_t *task_info_count);
  143. extern kern_return_t task_get_special_port(
  144. task_t task,
  145. int which,
  146. struct ipc_port **portp);
  147. extern kern_return_t task_set_special_port(
  148. task_t task,
  149. int which,
  150. struct ipc_port *port);
  151. extern kern_return_t task_assign(
  152. task_t task,
  153. processor_set_t new_pset,
  154. boolean_t assign_threads);
  155. extern kern_return_t task_assign_default(
  156. task_t task,
  157. boolean_t assign_threads);
  158. extern kern_return_t task_set_name(
  159. task_t task,
  160. kernel_debug_name_t name);
  161. extern void consider_task_collect(void);
  162. /*
  163. * Internal only routines
  164. */
  165. extern void task_init(void);
  166. extern void task_reference(task_t);
  167. extern void task_deallocate(task_t);
  168. extern void task_hold_locked(task_t);
  169. extern kern_return_t task_hold(task_t);
  170. extern kern_return_t task_dowait(task_t, boolean_t);
  171. extern kern_return_t task_release(task_t);
  172. extern task_t kernel_task;
  173. #endif /* _KERN_TASK_H_ */