scheduling_context_hypervisor.doxy 14 KB

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