scheduling_context_hypervisor.doxy 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /*
  2. * This file is part of the StarPU Handbook.
  3. * Copyright (C) 2009--2011 Universit@'e de Bordeaux 1
  4. * Copyright (C) 2010, 2011, 2012, 2013 Centre National de la Recherche Scientifique
  5. * Copyright (C) 2011, 2012 Institut National de Recherche en Informatique et Automatique
  6. * See the file version.doxy for copying conditions.
  7. */
  8. /*! \defgroup API_Scheduling_Context_Hypervisor Scheduling Context Hypervisor
  9. \struct sc_hypervisor_policy
  10. \ingroup API_Scheduling_Context_Hypervisor
  11. This structure contains all the methods that implement a hypervisor resizing policy.
  12. \var sc_hypervisor_policy::name
  13. Indicates the name of the policy, if there is not a custom policy, the policy corresponding to this name will be used by the hypervisor
  14. \var sc_hypervisor_policy::custom
  15. Indicates whether the policy is custom or not
  16. \var sc_hypervisor_policy::handle_idle_cycle
  17. It is called whenever the indicated worker executes another idle cycle in sched_ctx
  18. \var sc_hypervisor_policy::handle_pushed_task
  19. It is called whenever a task is pushed on the worker’s queue corresponding to the context sched_ctx
  20. \var sc_hypervisor_policy::handle_poped_task
  21. It is called whenever a task is poped from the worker’s queue corresponding to the context sched_ctx
  22. \var sc_hypervisor_policy::handle_idle_end
  23. It is called whenever a task is executed on the indicated worker and context after a long period of idle time
  24. \var sc_hypervisor_policy::handle_post_exec_hook
  25. It is called whenever a tag task has just been executed. The table of resize requests is provided as well as the tag
  26. \struct sc_hypervisor_policy_config
  27. \ingroup API_Scheduling_Context_Hypervisor
  28. This structure contains all configuration information of a
  29. context. It contains configuration information for each context, which
  30. can be used to construct new resize strategies.
  31. \var sc_hypervisor_policy_config::min_nworkers
  32. Indicates the minimum number of workers needed by the context
  33. \var sc_hypervisor_policy_config::max_nworkers
  34. Indicates the maximum number of workers needed by the context
  35. \var sc_hypervisor_policy_config::granularity
  36. Indicates the workers granularity of the context
  37. \var sc_hypervisor_policy_config::priority
  38. Indicates the priority of each worker in the context
  39. \var sc_hypervisor_policy_config::max_idle
  40. Indicates the maximum idle time accepted before a resize is triggered
  41. \var sc_hypervisor_policy_config::fixed_workers
  42. Indicates which workers can be moved and which ones are fixed
  43. \var sc_hypervisor_policy_config:: new_workers_max_idle
  44. Indicates the maximum idle time accepted before a resize is triggered for the workers that just arrived in the new context
  45. \struct sc_hypervisor_wrapper
  46. \ingroup API_Scheduling_Context_Hypervisor
  47. This structure is a wrapper of the contexts available in StarPU
  48. and contains all information about a context obtained by incrementing
  49. the performance counters.
  50. \var sc_hypervisor_wrapper::sched_ctx
  51. The context wrapped
  52. \var sc_hypervisor_wrapper::config
  53. The corresponding resize configuration
  54. \var sc_hypervisor_wrapper::current_idle_time
  55. The idle time counter of each worker of the context
  56. \var sc_hypervisor_wrapper::pushed_tasks
  57. The number of pushed tasks of each worker of the context
  58. \var sc_hypervisor_wrapper::poped_tasks
  59. The number of poped tasks of each worker of the context
  60. \var sc_hypervisor_wrapper::total_flops
  61. The total number of flops to execute by the context
  62. \var sc_hypervisor_wrapper::total_elapsed_flops
  63. The number of flops executed by each workers of the context
  64. \var sc_hypervisor_wrapper::elapsed_flops
  65. The number of flops executed by each worker of the context from last resize
  66. \var sc_hypervisor_wrapper::remaining_flops
  67. The number of flops that still have to be executed by the workers in the context
  68. \var sc_hypervisor_wrapper::start_time
  69. The time when he started executed
  70. \var sc_hypervisor_wrapper::resize_ack
  71. The structure confirming the last resize finished and a new one can be done
  72. \struct sc_hypervisor_resize_ack
  73. \ingroup API_Scheduling_Context_Hypervisor
  74. This structures checks if the workers moved to another context
  75. are actually taken into account in that context.
  76. \var sc_hypervisor_resize_ack::receiver_sched_ctx
  77. The context receiving the new workers
  78. \var sc_hypervisor_resize_ack::moved_workers
  79. The workers moved to the receiver context
  80. \var sc_hypervisor_resize_ack::nmoved_workers
  81. The number of workers moved
  82. \var sc_hypervisor_resize_ack::acked_workers
  83. If the value corresponding to a worker is 1, this one is taken
  84. into account in the new context if 0 not yet
  85. \struct sc_hypervisor_policy_task_pool
  86. task wrapper linked list
  87. \ingroup API_Scheduling_Context_Hypervisor
  88. \var sc_hypervisor_policy_task_pool::cl
  89. Which codelet has been executed
  90. \var sc_hypervisor_policy_task_pool::footprint
  91. Task footprint key
  92. \var sc_hypervisor_policy_task_pool::sched_ctx_id
  93. Context the task belongs to
  94. \var sc_hypervisor_policy_task_pool::n
  95. Number of tasks of this kind
  96. \var sc_hypervisor_policy_task_pool::next
  97. Other task kinds
  98. @name Managing the hypervisor
  99. \ingroup API_Scheduling_Context_Hypervisor
  100. There is a single hypervisor that is in charge of resizing contexts
  101. and the resizing strategy is chosen at the initialization of the
  102. hypervisor. A single resize can be done at a time.
  103. The Scheduling Context Hypervisor Plugin provides a series of
  104. performance counters to StarPU. By incrementing them, StarPU can help
  105. the hypervisor in the resizing decision making process. TODO maybe
  106. they should be hidden to the user
  107. \fn struct starpu_sched_ctx_performance_counters *sc_hypervisor_init(struct sc_hypervisor_policy * policy)
  108. \ingroup API_Scheduling_Context_Hypervisor
  109. Initializes the hypervisor to use the strategy provided as parameter
  110. and creates the performance counters (see \ref Performance_Counters).
  111. These performance counters represent actually some callbacks that will
  112. be used by the contexts to notify the information needed by the
  113. hypervisor.
  114. Note: The Hypervisor is actually a worker that takes this role once
  115. certain conditions trigger the resizing process (there is no
  116. additional thread assigned to the hypervisor).
  117. \fn void sc_hypervisor_shutdown(void)
  118. \ingroup API_Scheduling_Context_Hypervisor
  119. The hypervisor and all information concerning it is cleaned. There is
  120. no synchronization between this function and starpu_shutdown(). Thus,
  121. this should be called after starpu_shutdown(), because the performance
  122. counters will still need allocated callback functions.
  123. @name Registering Scheduling Contexts to the hypervisor
  124. \ingroup API_Scheduling_Context_Hypervisor
  125. Scheduling Contexts that have to be resized by the hypervisor must be
  126. first registered to the hypervisor. Whenever we want to exclude
  127. contexts from the resizing process we have to unregister them from the
  128. hypervisor.
  129. \fn void sc_hypervisor_register_ctx(unsigned sched_ctx, double total_flops)
  130. \ingroup API_Scheduling_Context_Hypervisor
  131. Register the context to the hypervisor, and indicate the number of
  132. flops the context will execute (needed for Gflops rate based strategy
  133. see \ref Resizing_strategies or any other custom strategy needing it, for
  134. the others we can pass 0.0)
  135. \fn void sc_hypervisor_unregister_ctx (unsigned sched_ctx)
  136. \ingroup API_Scheduling_Context_Hypervisor
  137. Unregister the context from the hypervisor.
  138. @name The user’s input in the resizing process
  139. \ingroup API_Scheduling_Context_Hypervisor
  140. The user can totally forbid the resizing of a certain context or can
  141. then change his mind and allow it (in this case the resizing is
  142. managed by the hypervisor, that can forbid it or allow it)
  143. \fn void sc_hypervisor_stop_resize(unsigned sched_ctx)
  144. \ingroup API_Scheduling_Context_Hypervisor
  145. Forbid resizing of a context
  146. \fn void sc_hypervisor_start_resize(unsigned sched_ctx)
  147. \ingroup API_Scheduling_Context_Hypervisor
  148. Allow resizing of a context. The user can then provide information to
  149. the hypervisor concerning the conditions of resizing.
  150. \fn void sc_hypervisor_ioctl(unsigned sched_ctx, ...)
  151. \ingroup API_Scheduling_Context_Hypervisor
  152. Inputs conditions to the context sched_ctx with the following
  153. arguments. The argument list must be zero-terminated.
  154. \def HYPERVISOR_MAX_IDLE
  155. \ingroup API_Scheduling_Context_Hypervisor
  156. This macro is used when calling sc_hypervisor_ioctl() and must be
  157. followed by 3 arguments: an array of int for the workerids to apply
  158. the condition, an int to indicate the size of the array, and a double
  159. value indicating the maximum idle time allowed for a worker before the
  160. resizing process should be triggered
  161. \def HYPERVISOR_PRIORITY
  162. \ingroup API_Scheduling_Context_Hypervisor
  163. This macro is used when calling sc_hypervisor_ioctl() and must be
  164. followed by 3 arguments: an array of int for the workerids to apply
  165. the condition, an int to indicate the size of the array, and an int
  166. value indicating the priority of the workers previously mentioned. The
  167. workers with the smallest priority are moved the first.
  168. \def HYPERVISOR_MIN_WORKERS
  169. \ingroup API_Scheduling_Context_Hypervisor
  170. This macro is used when calling sc_hypervisor_ioctl() and must be
  171. followed by 1 argument(int) indicating the minimum number of workers a
  172. context should have, underneath this limit the context cannot execute.
  173. \def HYPERVISOR_MAX_WORKERS
  174. \ingroup API_Scheduling_Context_Hypervisor
  175. This macro is used when calling sc_hypervisor_ioctl() and must be
  176. followed by 1 argument(int) indicating the maximum number of workers a
  177. context should have, above this limit the context would not be able to
  178. scale
  179. \def HYPERVISOR_GRANULARITY
  180. \ingroup API_Scheduling_Context_Hypervisor
  181. This macro is used when calling sc_hypervisor_ioctl() and must be
  182. followed by 1 argument(int) indicating the granularity of the resizing
  183. process (the number of workers should be moved from the context once
  184. it is resized) This parameter is ignore for the Gflops rate based
  185. strategy see Resizing strategies, the number of workers that have to
  186. be moved is calculated by the strategy.
  187. \def HYPERVISOR_FIXED_WORKERS
  188. \ingroup API_Scheduling_Context_Hypervisor
  189. This macro is used when calling sc_hypervisor_ioctl() and must be
  190. followed by 2 arguments: an array of int for the workerids to apply
  191. the condition and an int to indicate the size of the array. These
  192. workers are not allowed to be moved from the context.
  193. \def HYPERVISOR_MIN_TASKS
  194. \ingroup API_Scheduling_Context_Hypervisor
  195. This macro is used when calling sc_hypervisor_ioctl() and must be
  196. followed by 1 argument (int) that indicated the minimum number of
  197. tasks that have to be executed before the context could be resized.
  198. This parameter is ignored for the Application Driven strategy see
  199. Resizing strategies where the user indicates exactly when the resize
  200. should be done.
  201. \def HYPERVISOR_NEW_WORKERS_MAX_IDLE
  202. \ingroup API_Scheduling_Context_Hypervisor
  203. This macro is used when calling sc_hypervisor_ioctl() and must be
  204. followed by 1 argument, a double value indicating the maximum idle
  205. time allowed for workers that have just been moved from other contexts
  206. in the current context.
  207. \def HYPERVISOR_TIME_TO_APPLY
  208. \ingroup API_Scheduling_Context_Hypervisor
  209. This macro is used when calling sc_hypervisor_ioctl() and must be
  210. followed by 1 argument (int) indicating the tag an executed task
  211. should have such that this configuration should be taken into account.
  212. @name Defining a new hypervisor policy
  213. \ingroup API_Scheduling_Context_Hypervisor
  214. While Scheduling Context Hypervisor Plugin comes with a variety of
  215. resizing policies (see \ref Resizing_strategies), it may sometimes be
  216. desirable to implement custom policies to address specific problems.
  217. The API described below allows users to write their own resizing policy.
  218. Here an example of how to define a new policy
  219. \code{.c}
  220. struct sc_hypervisor_policy dummy_policy =
  221. {
  222. .handle_poped_task = dummy_handle_poped_task,
  223. .handle_pushed_task = dummy_handle_pushed_task,
  224. .handle_idle_cycle = dummy_handle_idle_cycle,
  225. .handle_idle_end = dummy_handle_idle_end,
  226. .handle_post_exec_hook = dummy_handle_post_exec_hook,
  227. .custom = 1,
  228. .name = "dummy"
  229. };
  230. \endcode
  231. \fn void sc_hypervisor_move_workers(unsigned sender_sched_ctx, unsigned receiver_sched_ctx, int *workers_to_move, unsigned nworkers_to_move, unsigned now);
  232. \ingroup API_Scheduling_Context_Hypervisor
  233. Moves workers from one context to another
  234. \fn struct sc_hypervisor_policy_config * sc_hypervisor_get_config(unsigned sched_ctx);
  235. \ingroup API_Scheduling_Context_Hypervisor
  236. Returns the configuration structure of a context
  237. \fn int * sc_hypervisor_get_sched_ctxs();
  238. \ingroup API_Scheduling_Context_Hypervisor
  239. Gets the contexts managed by the hypervisor
  240. \fn int sc_hypervisor_get_nsched_ctxs();
  241. \ingroup API_Scheduling_Context_Hypervisor
  242. Gets the number of contexts managed by the hypervisor
  243. \fn struct sc_hypervisor_wrapper * sc_hypervisor_get_wrapper(unsigned sched_ctx);
  244. \ingroup API_Scheduling_Context_Hypervisor
  245. Returns the wrapper corresponding the context \p sched_ctx
  246. \fn double sc_hypervisor_get_elapsed_flops_per_sched_ctx(struct sc_hypervisor_wrapper * sc_w);
  247. \ingroup API_Scheduling_Context_Hypervisor
  248. Returns the flops of a context elapsed from the last resize
  249. \fn char * sc_hypervisor_get_policy();
  250. \ingroup API_Scheduling_Context_Hypervisor
  251. Returns the name of the resizing policy the hypervisor uses
  252. */