scheduling_context_hypervisor.doxy 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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 sc_hypervisor_policy
  10. \ingroup Scheduling_Context_Hypervisor
  11. \brief 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 Scheduling_Context_Hypervisor
  28. \brief 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 Scheduling_Context_Hypervisor
  47. \brief 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 Scheduling_Context_Hypervisor
  74. \brief 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. @name Managing the hypervisor
  86. \ingroup Scheduling_Context_Hypervisor
  87. There is a single hypervisor that is in charge of resizing contexts
  88. and the resizing strategy is chosen at the initialization of the
  89. hypervisor. A single resize can be done at a time.
  90. The Scheduling Context Hypervisor Plugin provides a series of
  91. performance counters to StarPU. By incrementing them, StarPU can help
  92. the hypervisor in the resizing decision making process. TODO maybe
  93. they should be hidden to the user
  94. \fn struct starpu_sched_ctx_performance_counters *sc_hypervisor_init(struct sc_hypervisor_policy * policy)
  95. \ingroup Scheduling_Context_Hypervisor
  96. Initializes the hypervisor to use the strategy provided as parameter
  97. and creates the performance counters (see \ref Performance_Counters).
  98. These performance counters represent actually some callbacks that will
  99. be used by the contexts to notify the information needed by the
  100. hypervisor.
  101. Note: The Hypervisor is actually a worker that takes this role once
  102. certain conditions trigger the resizing process (there is no
  103. additional thread assigned to the hypervisor).
  104. \fn void sc_hypervisor_shutdown(void)
  105. \ingroup Scheduling_Context_Hypervisor
  106. The hypervisor and all information concerning it is cleaned. There is
  107. no synchronization between this function and starpu_shutdown(). Thus,
  108. this should be called after starpu_shutdown(), because the performance
  109. counters will still need allocated callback functions.
  110. @name Registering Scheduling Contexts to the hypervisor
  111. \ingroup Scheduling_Context_Hypervisor
  112. Scheduling Contexts that have to be resized by the hypervisor must be
  113. first registered to the hypervisor. Whenever we want to exclude
  114. contexts from the resizing process we have to unregister them from the
  115. hypervisor.
  116. \fn void sc_hypervisor_register_ctx(unsigned sched_ctx, double total_flops)
  117. \ingroup Scheduling_Context_Hypervisor
  118. Register the context to the hypervisor, and indicate the number of
  119. flops the context will execute (needed for Gflops rate based strategy
  120. see \ref Resizing_strategies or any other custom strategy needing it, for
  121. the others we can pass 0.0)
  122. \fn void sc_hypervisor_unregister_ctx (unsigned sched_ctx)
  123. \ingroup Scheduling_Context_Hypervisor
  124. Unregister the context from the hypervisor.
  125. @name The user’s input in the resizing process
  126. \ingroup Scheduling_Context_Hypervisor
  127. The user can totally forbid the resizing of a certain context or can
  128. then change his mind and allow it (in this case the resizing is
  129. managed by the hypervisor, that can forbid it or allow it)
  130. \fn void sc_hypervisor_stop_resize(unsigned sched_ctx)
  131. \ingroup Scheduling_Context_Hypervisor
  132. Forbid resizing of a context
  133. \fn void sc_hypervisor_start_resize(unsigned sched_ctx)
  134. \ingroup Scheduling_Context_Hypervisor
  135. Allow resizing of a context. The user can then provide information to
  136. the hypervisor concerning the conditions of resizing.
  137. \fn void sc_hypervisor_ioctl(unsigned sched_ctx, ...)
  138. \ingroup Scheduling_Context_Hypervisor
  139. Inputs conditions to the context sched_ctx with the following
  140. arguments. The argument list must be zero-terminated.
  141. \def HYPERVISOR_MAX_IDLE
  142. \ingroup Scheduling_Context_Hypervisor
  143. This macro is used when calling sc_hypervisor_ioctl() and must be
  144. followed by 3 arguments: an array of int for the workerids to apply
  145. the condition, an int to indicate the size of the array, and a double
  146. value indicating the maximum idle time allowed for a worker before the
  147. resizing process should be triggered
  148. \def HYPERVISOR_PRIORITY
  149. \ingroup Scheduling_Context_Hypervisor
  150. This macro is used when calling sc_hypervisor_ioctl() and must be
  151. followed by 3 arguments: an array of int for the workerids to apply
  152. the condition, an int to indicate the size of the array, and an int
  153. value indicating the priority of the workers previously mentioned. The
  154. workers with the smallest priority are moved the first.
  155. \def HYPERVISOR_MIN_WORKERS
  156. \ingroup Scheduling_Context_Hypervisor
  157. This macro is used when calling sc_hypervisor_ioctl() and must be
  158. followed by 1 argument(int) indicating the minimum number of workers a
  159. context should have, underneath this limit the context cannot execute.
  160. \def HYPERVISOR_MAX_WORKERS
  161. \ingroup Scheduling_Context_Hypervisor
  162. This macro is used when calling sc_hypervisor_ioctl() and must be
  163. followed by 1 argument(int) indicating the maximum number of workers a
  164. context should have, above this limit the context would not be able to
  165. scale
  166. \def HYPERVISOR_GRANULARITY
  167. \ingroup Scheduling_Context_Hypervisor
  168. This macro is used when calling sc_hypervisor_ioctl() and must be
  169. followed by 1 argument(int) indicating the granularity of the resizing
  170. process (the number of workers should be moved from the context once
  171. it is resized) This parameter is ignore for the Gflops rate based
  172. strategy see Resizing strategies, the number of workers that have to
  173. be moved is calculated by the strategy.
  174. \def HYPERVISOR_FIXED_WORKERS
  175. \ingroup Scheduling_Context_Hypervisor
  176. This macro is used when calling sc_hypervisor_ioctl() and must be
  177. followed by 2 arguments: an array of int for the workerids to apply
  178. the condition and an int to indicate the size of the array. These
  179. workers are not allowed to be moved from the context.
  180. \def HYPERVISOR_MIN_TASKS
  181. \ingroup Scheduling_Context_Hypervisor
  182. This macro is used when calling sc_hypervisor_ioctl() and must be
  183. followed by 1 argument (int) that indicated the minimum number of
  184. tasks that have to be executed before the context could be resized.
  185. This parameter is ignored for the Application Driven strategy see
  186. Resizing strategies where the user indicates exactly when the resize
  187. should be done.
  188. \def HYPERVISOR_NEW_WORKERS_MAX_IDLE
  189. \ingroup Scheduling_Context_Hypervisor
  190. This macro is used when calling sc_hypervisor_ioctl() and must be
  191. followed by 1 argument, a double value indicating the maximum idle
  192. time allowed for workers that have just been moved from other contexts
  193. in the current context.
  194. \def HYPERVISOR_TIME_TO_APPLY
  195. \ingroup Scheduling_Context_Hypervisor
  196. This macro is used when calling sc_hypervisor_ioctl() and must be
  197. followed by 1 argument (int) indicating the tag an executed task
  198. should have such that this configuration should be taken into account.
  199. @name Defining a new hypervisor policy
  200. \ingroup Scheduling_Context_Hypervisor
  201. While Scheduling Context Hypervisor Plugin comes with a variety of
  202. resizing policies (see \ref Resizing_strategies), it may sometimes be
  203. desirable to implement custom policies to address specific problems.
  204. The API described below allows users to write their own resizing policy.
  205. Here an example of how to define a new policy
  206. \code{.c}
  207. struct sc_hypervisor_policy dummy_policy =
  208. {
  209. .handle_poped_task = dummy_handle_poped_task,
  210. .handle_pushed_task = dummy_handle_pushed_task,
  211. .handle_idle_cycle = dummy_handle_idle_cycle,
  212. .handle_idle_end = dummy_handle_idle_end,
  213. .handle_post_exec_hook = dummy_handle_post_exec_hook,
  214. .custom = 1,
  215. .name = "dummy"
  216. };
  217. \endcode
  218. \fn void sc_hypervisor_move_workers(unsigned sender_sched_ctx, unsigned receiver_sched_ctx, int *workers_to_move, unsigned nworkers_to_move, unsigned now);
  219. \ingroup Scheduling_Context_Hypervisor
  220. Moves workers from one context to another
  221. \fn struct sc_hypervisor_policy_config * sc_hypervisor_get_config(unsigned sched_ctx);
  222. \ingroup Scheduling_Context_Hypervisor
  223. Returns the configuration structure of a context
  224. \fn int * sc_hypervisor_get_sched_ctxs();
  225. \ingroup Scheduling_Contex_Hypervisor
  226. Gets the contexts managed by the hypervisor
  227. \fn int sc_hypervisor_get_nsched_ctxs();
  228. \ingroup Scheduling_Context_Hypervisor
  229. Gets the number of contexts managed by the hypervisor
  230. \fn struct sc_hypervisor_wrapper * sc_hypervisor_get_wrapper(unsigned sched_ctx);
  231. \ingroup Scheduling_Context_Hypervisor
  232. Returns the wrapper corresponding the context \p sched_ctx
  233. \fn double sc_hypervisor_get_elapsed_flops_per_sched_ctx(struct sc_hypervisor_wrapper * sc_w);
  234. \ingroup Scheduling_Context_Hypervisor
  235. Returns the flops of a context elapsed from the last resize
  236. \fn char * sc_hypervisor_get_policy();
  237. \ingroup Scheduling_Context_Hypervisor
  238. Returns the name of the resizing policy the hypervisor uses
  239. */