sched_ctx_hypervisor.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011, 2012 INRIA
  4. *
  5. * StarPU is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * StarPU is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #ifndef SCHED_CTX_HYPERVISOR_H
  17. #define SCHED_CTX_HYPERVISOR_H
  18. #include <starpu.h>
  19. #include <pthread.h>
  20. #ifdef __cplusplus
  21. extern "C"
  22. {
  23. #endif
  24. #ifdef STARPU_DEVEL
  25. # warning rename all objects to start with sched_ctx_hypervisor
  26. #endif
  27. /* ioctl properties*/
  28. #define HYPERVISOR_MAX_IDLE -1
  29. #define HYPERVISOR_MIN_WORKING -2
  30. #define HYPERVISOR_PRIORITY -3
  31. #define HYPERVISOR_MIN_WORKERS -4
  32. #define HYPERVISOR_MAX_WORKERS -5
  33. #define HYPERVISOR_GRANULARITY -6
  34. #define HYPERVISOR_FIXED_WORKERS -7
  35. #define HYPERVISOR_MIN_TASKS -8
  36. #define HYPERVISOR_NEW_WORKERS_MAX_IDLE -9
  37. #define HYPERVISOR_TIME_TO_APPLY -10
  38. #define HYPERVISOR_EMPTY_CTX_MAX_IDLE -11
  39. #define HYPERVISOR_NULL -12
  40. #define HYPERVISOR_ISPEED_W_SAMPLE -13
  41. #define HYPERVISOR_ISPEED_CTX_SAMPLE -14
  42. pthread_mutex_t act_hypervisor_mutex;
  43. #define MAX_IDLE_TIME 5000000000
  44. #define MIN_WORKING_TIME 500
  45. struct sched_ctx_hypervisor_policy_config
  46. {
  47. /* underneath this limit we cannot resize */
  48. int min_nworkers;
  49. /* above this limit we cannot resize */
  50. int max_nworkers;
  51. /*resize granularity */
  52. int granularity;
  53. /* priority for a worker to stay in this context */
  54. /* the smaller the priority the faster it will be moved */
  55. /* to another context */
  56. int priority[STARPU_NMAXWORKERS];
  57. /* above this limit the priority of the worker is reduced */
  58. double max_idle[STARPU_NMAXWORKERS];
  59. /* underneath this limit the priority of the worker is reduced */
  60. double min_working[STARPU_NMAXWORKERS];
  61. /* workers that will not move */
  62. int fixed_workers[STARPU_NMAXWORKERS];
  63. /* max idle for the workers that will be added during the resizing process*/
  64. double new_workers_max_idle;
  65. /* above this context we allow removing all workers */
  66. double empty_ctx_max_idle[STARPU_NMAXWORKERS];
  67. /* sample used to compute the instant speed per worker*/
  68. double ispeed_w_sample[STARPU_NMAXWORKERS];
  69. /* sample used to compute the instant speed per ctx*/
  70. double ispeed_ctx_sample;
  71. };
  72. struct sched_ctx_hypervisor_resize_ack
  73. {
  74. int receiver_sched_ctx;
  75. int *moved_workers;
  76. int nmoved_workers;
  77. int *acked_workers;
  78. };
  79. /* wrapper attached to a sched_ctx storing monitoring information */
  80. struct sched_ctx_hypervisor_wrapper
  81. {
  82. /* the sched_ctx it monitors */
  83. unsigned sched_ctx;
  84. /* user configuration meant to limit resizing */
  85. struct sched_ctx_hypervisor_policy_config *config;
  86. /* idle time of workers in this context */
  87. double current_idle_time[STARPU_NMAXWORKERS];
  88. /* list of workers that will leave this contexts (lazy resizing process) */
  89. int worker_to_be_removed[STARPU_NMAXWORKERS];
  90. /* number of tasks pushed on each worker in this ctx */
  91. int pushed_tasks[STARPU_NMAXWORKERS];
  92. /* number of tasks poped from each worker in this ctx */
  93. int poped_tasks[STARPU_NMAXWORKERS];
  94. /* number of flops the context has to execute */
  95. double total_flops;
  96. /* number of flops executed since the biginning until now */
  97. double total_elapsed_flops[STARPU_NMAXWORKERS];
  98. /* number of flops executed since last resizing */
  99. double elapsed_flops[STARPU_NMAXWORKERS];
  100. /* data quantity executed on each worker in this ctx */
  101. size_t elapsed_data[STARPU_NMAXWORKERS];
  102. /* nr of tasks executed on each worker in this ctx */
  103. int elapsed_tasks[STARPU_NMAXWORKERS];
  104. /* the average speed of workers when they belonged to this context */
  105. double ref_velocity[STARPU_NMAXWORKERS];
  106. /* number of flops submitted to this ctx */
  107. double submitted_flops;
  108. /* number of flops that still have to be executed in this ctx */
  109. double remaining_flops;
  110. /* the start time of the resizing sample of this context*/
  111. double start_time;
  112. /* the first time a task was pushed to this context*/
  113. double real_start_time;
  114. /* the workers don't leave the current ctx until the receiver ctx
  115. doesn't ack the receive of these workers */
  116. struct sched_ctx_hypervisor_resize_ack resize_ack;
  117. /* mutex to protect the ack of workers */
  118. pthread_mutex_t mutex;
  119. };
  120. /* Forward declaration of an internal data structure
  121. * FIXME: Remove when no longer exposed. */
  122. struct resize_request_entry;
  123. struct sched_ctx_hypervisor_policy
  124. {
  125. const char* name;
  126. unsigned custom;
  127. void (*size_ctxs)(int *sched_ctxs, int nsched_ctxs , int *workers, int nworkers);
  128. void (*handle_idle_cycle)(unsigned sched_ctx, int worker);
  129. void (*handle_pushed_task)(unsigned sched_ctx, int worker);
  130. void (*handle_poped_task)(unsigned sched_ctx, int worker,struct starpu_task *task, uint32_t footprint);
  131. void (*handle_idle_end)(unsigned sched_ctx, int worker);
  132. void (*handle_post_exec_hook)(unsigned sched_ctx, int task_tag);
  133. void (*handle_submitted_job)(struct starpu_task *task, unsigned footprint);
  134. void (*end_ctx)(unsigned sched_ctx);
  135. };
  136. struct starpu_sched_ctx_performance_counters *sched_ctx_hypervisor_init(struct sched_ctx_hypervisor_policy *policy);
  137. void sched_ctx_hypervisor_shutdown(void);
  138. void sched_ctx_hypervisor_register_ctx(unsigned sched_ctx, double total_flops);
  139. void sched_ctx_hypervisor_unregister_ctx(unsigned sched_ctx);
  140. void sched_ctx_hypervisor_resize(unsigned sched_ctx, int task_tag);
  141. void sched_ctx_hypervisor_move_workers(unsigned sender_sched_ctx, unsigned receiver_sched_ctx, int *workers_to_move, unsigned nworkers_to_move, unsigned now);
  142. void sched_ctx_hypervisor_stop_resize(unsigned sched_ctx);
  143. void sched_ctx_hypervisor_start_resize(unsigned sched_ctx);
  144. void sched_ctx_hypervisor_ioctl(unsigned sched_ctx, ...);
  145. void sched_ctx_hypervisor_set_config(unsigned sched_ctx, void *config);
  146. struct sched_ctx_hypervisor_policy_config *sched_ctx_hypervisor_get_config(unsigned sched_ctx);
  147. int *sched_ctx_hypervisor_get_sched_ctxs();
  148. int sched_ctx_hypervisor_get_nsched_ctxs();
  149. int sched_ctx_hypervisor_get_nworkers_ctx(unsigned sched_ctx, enum starpu_archtype arch);
  150. struct sched_ctx_hypervisor_wrapper *sched_ctx_hypervisor_get_wrapper(unsigned sched_ctx);
  151. double sched_ctx_hypervisor_get_elapsed_flops_per_sched_ctx(struct sched_ctx_hypervisor_wrapper *sc_w);
  152. double sched_ctx_hypervisor_get_total_elapsed_flops_per_sched_ctx(struct sched_ctx_hypervisor_wrapper* sc_w);
  153. const char *sched_ctx_hypervisor_get_policy();
  154. void sched_ctx_hypervisor_add_workers_to_sched_ctx(int* workers_to_add, unsigned nworkers_to_add, unsigned sched_ctx);
  155. void sched_ctx_hypervisor_remove_workers_from_sched_ctx(int* workers_to_remove, unsigned nworkers_to_remove, unsigned sched_ctx, unsigned now);
  156. void sched_ctx_hypervisor_size_ctxs(int *sched_ctxs, int nsched_ctxs, int *workers, int nworkers);
  157. unsigned sched_ctx_hypervisor_get_size_req(int **sched_ctxs, int* nsched_ctxs, int **workers, int *nworkers);
  158. void sched_ctx_hypervisor_save_size_req(int *sched_ctxs, int nsched_ctxs, int *workers, int nworkers);
  159. void sched_ctx_hypervisor_free_size_req(void);
  160. unsigned sched_ctx_hypervisor_can_resize(unsigned sched_ctx);
  161. /* compute an average value of the cpu/cuda velocity */
  162. double sched_ctx_hypervisor_get_velocity_per_worker_type(struct sched_ctx_hypervisor_wrapper* sc_w, enum starpu_archtype arch);
  163. double sched_ctx_hypervisor_get_velocity(struct sched_ctx_hypervisor_wrapper *sc_w, enum starpu_archtype arch);
  164. #ifdef __cplusplus
  165. }
  166. #endif
  167. #endif