hypervisor_api.texi 14 KB

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