sched_ctx_config.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. #include <sched_ctx_hypervisor_intern.h>
  2. static struct policy_config* _create_config(void)
  3. {
  4. struct policy_config *config = (struct policy_config *)malloc(sizeof(struct policy_config));
  5. config->min_nworkers = -1;
  6. config->max_nworkers = -1;
  7. config->new_workers_max_idle = -1.0;
  8. int i;
  9. for(i = 0; i < STARPU_NMAXWORKERS; i++)
  10. {
  11. config->granularity = -1;
  12. config->priority[i] = -1;
  13. config->fixed_workers[i] = -1;
  14. config->max_idle[i] = -1.0;
  15. config->empty_ctx_max_idle[i] = -1.0;
  16. config->min_working[i] = -1.0;
  17. }
  18. return config;
  19. }
  20. static void _update_config(struct policy_config *old, struct policy_config* new)
  21. {
  22. old->min_nworkers = new->min_nworkers != -1 ? new->min_nworkers : old->min_nworkers ;
  23. old->max_nworkers = new->max_nworkers != -1 ? new->max_nworkers : old->max_nworkers ;
  24. old->new_workers_max_idle = new->new_workers_max_idle != -1.0 ? new->new_workers_max_idle : old->new_workers_max_idle;
  25. old->granularity = new->granularity != -1 ? new->granularity : old->granularity;
  26. int i;
  27. for(i = 0; i < STARPU_NMAXWORKERS; i++)
  28. {
  29. old->priority[i] = new->priority[i] != -1 ? new->priority[i] : old->priority[i];
  30. old->fixed_workers[i] = new->fixed_workers[i] != -1 ? new->fixed_workers[i] : old->fixed_workers[i];
  31. old->max_idle[i] = new->max_idle[i] != -1.0 ? new->max_idle[i] : old->max_idle[i];
  32. old->empty_ctx_max_idle[i] = new->empty_ctx_max_idle[i] != -1.0 ? new->empty_ctx_max_idle[i] : old->empty_ctx_max_idle[i];
  33. old->min_working[i] = new->min_working[i] != -1.0 ? new->min_working[i] : old->min_working[i];
  34. }
  35. }
  36. void sched_ctx_hypervisor_set_config(unsigned sched_ctx, void *config)
  37. {
  38. printf("%d: ", sched_ctx );
  39. if(hypervisor.sched_ctx_w[sched_ctx].config != NULL && config != NULL)
  40. {
  41. _update_config(hypervisor.sched_ctx_w[sched_ctx].config, config);
  42. }
  43. else
  44. hypervisor.sched_ctx_w[sched_ctx].config = config;
  45. return;
  46. }
  47. void _add_config(unsigned sched_ctx)
  48. {
  49. struct policy_config *config = _create_config();
  50. config->min_nworkers = 0;
  51. config->max_nworkers = 0;
  52. config->new_workers_max_idle = MAX_IDLE_TIME;
  53. int i;
  54. for(i = 0; i < STARPU_NMAXWORKERS; i++)
  55. {
  56. config->granularity = 1;
  57. config->priority[i] = 0;
  58. config->fixed_workers[i] = 0;
  59. config->max_idle[i] = MAX_IDLE_TIME;
  60. config->empty_ctx_max_idle[i] = MAX_IDLE_TIME;
  61. config->min_working[i] = MIN_WORKING_TIME;
  62. }
  63. sched_ctx_hypervisor_set_config(sched_ctx, config);
  64. }
  65. void _remove_config(unsigned sched_ctx)
  66. {
  67. sched_ctx_hypervisor_set_config(sched_ctx, NULL);
  68. }
  69. struct policy_config* sched_ctx_hypervisor_get_config(unsigned sched_ctx)
  70. {
  71. return hypervisor.sched_ctx_w[sched_ctx].config;
  72. }
  73. static struct policy_config* _ioctl(unsigned sched_ctx, va_list varg_list, unsigned later)
  74. {
  75. struct policy_config *config = NULL;
  76. if(later)
  77. config = _create_config();
  78. else
  79. config = sched_ctx_hypervisor_get_config(sched_ctx);
  80. assert(config != NULL);
  81. int arg_type;
  82. int i;
  83. int *workerids;
  84. int nworkers;
  85. while ((arg_type = va_arg(varg_list, int)) != 0)
  86. {
  87. switch(arg_type)
  88. {
  89. case HYPERVISOR_MAX_IDLE:
  90. workerids = va_arg(varg_list, int*);
  91. nworkers = va_arg(varg_list, int);
  92. double max_idle = va_arg(varg_list, double);
  93. for(i = 0; i < nworkers; i++)
  94. config->max_idle[workerids[i]] = max_idle;
  95. break;
  96. case HYPERVISOR_EMPTY_CTX_MAX_IDLE:
  97. workerids = va_arg(varg_list, int*);
  98. nworkers = va_arg(varg_list, int);
  99. double empty_ctx_max_idle = va_arg(varg_list, double);
  100. for(i = 0; i < nworkers; i++)
  101. config->empty_ctx_max_idle[workerids[i]] = empty_ctx_max_idle;
  102. break;
  103. case HYPERVISOR_MIN_WORKING:
  104. workerids = va_arg(varg_list, int*);
  105. nworkers = va_arg(varg_list, int);
  106. double min_working = va_arg(varg_list, double);
  107. for(i = 0; i < nworkers; i++)
  108. config->min_working[workerids[i]] = min_working;
  109. break;
  110. case HYPERVISOR_PRIORITY:
  111. workerids = va_arg(varg_list, int*);
  112. nworkers = va_arg(varg_list, int);
  113. int priority = va_arg(varg_list, int);
  114. for(i = 0; i < nworkers; i++)
  115. config->priority[workerids[i]] = priority;
  116. break;
  117. case HYPERVISOR_MIN_WORKERS:
  118. config->min_nworkers = va_arg(varg_list, unsigned);
  119. break;
  120. case HYPERVISOR_MAX_WORKERS:
  121. config->max_nworkers = va_arg(varg_list, unsigned);
  122. break;
  123. case HYPERVISOR_GRANULARITY:
  124. config->granularity = va_arg(varg_list, unsigned);
  125. break;
  126. case HYPERVISOR_FIXED_WORKERS:
  127. workerids = va_arg(varg_list, int*);
  128. nworkers = va_arg(varg_list, int);
  129. for(i = 0; i < nworkers; i++)
  130. config->fixed_workers[workerids[i]] = 1;
  131. break;
  132. case HYPERVISOR_NEW_WORKERS_MAX_IDLE:
  133. config->new_workers_max_idle = va_arg(varg_list, double);
  134. break;
  135. /* not important for the strateg, needed just to jump these args in the iteration of the args */
  136. case HYPERVISOR_TIME_TO_APPLY:
  137. va_arg(varg_list, int);
  138. break;
  139. case HYPERVISOR_MIN_TASKS:
  140. va_arg(varg_list, int);
  141. break;
  142. }
  143. }
  144. va_end(varg_list);
  145. return later ? config : NULL;
  146. }
  147. void sched_ctx_hypervisor_ioctl(unsigned sched_ctx, ...)
  148. {
  149. va_list varg_list;
  150. va_start(varg_list, sched_ctx);
  151. int arg_type;
  152. int stop = 0;
  153. int task_tag = -1;
  154. while ((arg_type = va_arg(varg_list, int)) != 0)
  155. {
  156. switch(arg_type)
  157. {
  158. case HYPERVISOR_TIME_TO_APPLY:
  159. task_tag = va_arg(varg_list, int);
  160. stop = 1;
  161. break;
  162. case HYPERVISOR_MIN_TASKS:
  163. hypervisor.min_tasks = va_arg(varg_list, int);
  164. break;
  165. }
  166. if(stop) break;
  167. }
  168. va_end(varg_list);
  169. va_start(varg_list, sched_ctx);
  170. /* if config not null => save hypervisor configuration and consider it later */
  171. struct policy_config *config = _ioctl(sched_ctx, varg_list, (task_tag > 0));
  172. if(config != NULL)
  173. _starpu_htbl_insert_32(&hypervisor.configurations[sched_ctx], (uint32_t)task_tag, config);
  174. return;
  175. }