policy_tools.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2013 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. #include "sc_hypervisor_policy.h"
  17. #include "sc_hypervisor_intern.h"
  18. #include "sc_hypervisor_lp.h"
  19. static int _compute_priority(unsigned sched_ctx)
  20. {
  21. struct sc_hypervisor_policy_config *config = sc_hypervisor_get_config(sched_ctx);
  22. int total_priority = 0;
  23. struct starpu_worker_collection *workers = starpu_sched_ctx_get_worker_collection(sched_ctx);
  24. int worker;
  25. struct starpu_sched_ctx_iterator it;
  26. workers->init_iterator(workers, &it);
  27. while(workers->has_next(workers, &it))
  28. {
  29. worker = workers->get_next(workers, &it);
  30. total_priority += config->priority[worker];
  31. }
  32. return total_priority;
  33. }
  34. /* find the context with the lowest priority */
  35. unsigned sc_hypervisor_find_lowest_prio_sched_ctx(unsigned req_sched_ctx, int nworkers_to_move)
  36. {
  37. int i;
  38. int highest_priority = -1;
  39. int current_priority = 0;
  40. unsigned sched_ctx = STARPU_NMAX_SCHED_CTXS;
  41. unsigned *sched_ctxs = sc_hypervisor_get_sched_ctxs();
  42. int nsched_ctxs = sc_hypervisor_get_nsched_ctxs();
  43. struct sc_hypervisor_policy_config *config = NULL;
  44. for(i = 0; i < nsched_ctxs; i++)
  45. {
  46. if(sched_ctxs[i] != STARPU_NMAX_SCHED_CTXS && sched_ctxs[i] != req_sched_ctx)
  47. {
  48. int nworkers = (int)starpu_sched_ctx_get_nworkers(sched_ctxs[i]);
  49. config = sc_hypervisor_get_config(sched_ctxs[i]);
  50. if((nworkers + nworkers_to_move) <= config->max_nworkers)
  51. {
  52. current_priority = _compute_priority(sched_ctxs[i]);
  53. if (highest_priority < current_priority)
  54. {
  55. highest_priority = current_priority;
  56. sched_ctx = sched_ctxs[i];
  57. }
  58. }
  59. }
  60. }
  61. return sched_ctx;
  62. }
  63. int* sc_hypervisor_get_idlest_workers_in_list(int *start, int *workers, int nall_workers, int *nworkers, enum starpu_worker_archtype arch)
  64. {
  65. int *curr_workers = (int*)malloc((*nworkers)*sizeof(int));
  66. int w, worker;
  67. int nfound_workers = 0;
  68. for(w = 0; w < nall_workers; w++)
  69. {
  70. if(nfound_workers >= *nworkers)
  71. break;
  72. worker = workers == NULL ? w : workers[w];
  73. enum starpu_worker_archtype curr_arch = starpu_worker_get_type(worker);
  74. if(arch == STARPU_ANY_WORKER || curr_arch == arch)
  75. {
  76. if(w >= *start)
  77. {
  78. curr_workers[nfound_workers++] = worker;
  79. *start = w+1;
  80. }
  81. }
  82. }
  83. if(nfound_workers < *nworkers)
  84. *nworkers = nfound_workers;
  85. return curr_workers;
  86. }
  87. /* get first nworkers with the highest idle time in the context */
  88. int* sc_hypervisor_get_idlest_workers(unsigned sched_ctx, int *nworkers, enum starpu_worker_archtype arch)
  89. {
  90. struct sc_hypervisor_wrapper* sc_w = sc_hypervisor_get_wrapper(sched_ctx);
  91. struct sc_hypervisor_policy_config *config = sc_hypervisor_get_config(sched_ctx);
  92. int *curr_workers = (int*)malloc((*nworkers) * sizeof(int));
  93. int i;
  94. for(i = 0; i < *nworkers; i++)
  95. curr_workers[i] = -1;
  96. struct starpu_worker_collection *workers = starpu_sched_ctx_get_worker_collection(sched_ctx);
  97. int index;
  98. int worker;
  99. int considered = 0;
  100. struct starpu_sched_ctx_iterator it;
  101. workers->init_iterator(workers, &it);
  102. for(index = 0; index < *nworkers; index++)
  103. {
  104. while(workers->has_next(workers, &it))
  105. {
  106. considered = 0;
  107. worker = workers->get_next(workers, &it);
  108. enum starpu_worker_archtype curr_arch = starpu_worker_get_type(worker);
  109. if(arch == STARPU_ANY_WORKER || curr_arch == arch)
  110. {
  111. if(!config->fixed_workers[worker])
  112. {
  113. for(i = 0; i < index; i++)
  114. {
  115. if(curr_workers[i] == worker)
  116. {
  117. considered = 1;
  118. break;
  119. }
  120. }
  121. if(!considered)
  122. {
  123. /* the first iteration*/
  124. if(curr_workers[index] < 0)
  125. curr_workers[index] = worker;
  126. /* small priority worker is the first to leave the ctx*/
  127. else if(config->priority[worker] <
  128. config->priority[curr_workers[index]])
  129. curr_workers[index] = worker;
  130. /* if we don't consider priorities check for the workers
  131. with the biggest idle time */
  132. else if(config->priority[worker] ==
  133. config->priority[curr_workers[index]])
  134. {
  135. double worker_idle_time = sc_w->current_idle_time[worker];
  136. double curr_worker_idle_time = sc_w->current_idle_time[curr_workers[index]];
  137. if(worker_idle_time > curr_worker_idle_time)
  138. curr_workers[index] = worker;
  139. }
  140. }
  141. }
  142. }
  143. }
  144. if(curr_workers[index] < 0)
  145. {
  146. *nworkers = index;
  147. break;
  148. }
  149. }
  150. return curr_workers;
  151. }
  152. /* get the number of workers in the context that are allowed to be moved (that are not fixed) */
  153. int sc_hypervisor_get_movable_nworkers(struct sc_hypervisor_policy_config *config, unsigned sched_ctx, enum starpu_worker_archtype arch)
  154. {
  155. struct starpu_worker_collection *workers = starpu_sched_ctx_get_worker_collection(sched_ctx);
  156. int potential_workers = 0;
  157. int worker;
  158. struct starpu_sched_ctx_iterator it;
  159. workers->init_iterator(workers, &it);
  160. while(workers->has_next(workers, &it))
  161. {
  162. worker = workers->get_next(workers, &it);
  163. enum starpu_worker_archtype curr_arch = starpu_worker_get_type(worker);
  164. if(arch == STARPU_ANY_WORKER || curr_arch == arch)
  165. {
  166. if(!config->fixed_workers[worker])
  167. potential_workers++;
  168. }
  169. }
  170. return potential_workers;
  171. }
  172. /* compute the number of workers that should be moved depending:
  173. - on the min/max number of workers in a context imposed by the user,
  174. - on the resource granularity imposed by the user for the resizing process*/
  175. int sc_hypervisor_compute_nworkers_to_move(unsigned req_sched_ctx)
  176. {
  177. struct sc_hypervisor_policy_config *config = sc_hypervisor_get_config(req_sched_ctx);
  178. int nworkers = (int)starpu_sched_ctx_get_nworkers(req_sched_ctx);
  179. int nworkers_to_move = 0;
  180. int potential_moving_workers = (int)sc_hypervisor_get_movable_nworkers(config, req_sched_ctx, STARPU_ANY_WORKER);
  181. if(potential_moving_workers > 0)
  182. {
  183. if(potential_moving_workers <= config->min_nworkers)
  184. /* if we have to give more than min better give it all */
  185. /* => empty ctx will block until having the required workers */
  186. nworkers_to_move = potential_moving_workers;
  187. else if(potential_moving_workers > config->max_nworkers)
  188. {
  189. if((potential_moving_workers - config->granularity) > config->max_nworkers)
  190. // nworkers_to_move = config->granularity;
  191. nworkers_to_move = potential_moving_workers;
  192. else
  193. nworkers_to_move = potential_moving_workers - config->max_nworkers;
  194. }
  195. else if(potential_moving_workers > config->granularity)
  196. {
  197. if((nworkers - config->granularity) > config->min_nworkers)
  198. nworkers_to_move = config->granularity;
  199. else
  200. nworkers_to_move = potential_moving_workers - config->min_nworkers;
  201. }
  202. else
  203. {
  204. int nfixed_workers = nworkers - potential_moving_workers;
  205. if(nfixed_workers >= config->min_nworkers)
  206. nworkers_to_move = potential_moving_workers;
  207. else
  208. nworkers_to_move = potential_moving_workers - (config->min_nworkers - nfixed_workers);
  209. }
  210. if((nworkers - nworkers_to_move) > config->max_nworkers)
  211. nworkers_to_move = nworkers - config->max_nworkers;
  212. }
  213. return nworkers_to_move;
  214. }
  215. unsigned sc_hypervisor_policy_resize(unsigned sender_sched_ctx, unsigned receiver_sched_ctx, unsigned force_resize, unsigned now)
  216. {
  217. int ret = 1;
  218. if(force_resize)
  219. starpu_pthread_mutex_lock(&act_hypervisor_mutex);
  220. else
  221. ret = starpu_pthread_mutex_trylock(&act_hypervisor_mutex);
  222. if(ret != EBUSY)
  223. {
  224. int nworkers_to_move = sc_hypervisor_compute_nworkers_to_move(sender_sched_ctx);
  225. if(nworkers_to_move > 0)
  226. {
  227. unsigned poor_sched_ctx = STARPU_NMAX_SCHED_CTXS;
  228. if(receiver_sched_ctx == STARPU_NMAX_SCHED_CTXS)
  229. {
  230. poor_sched_ctx = sc_hypervisor_find_lowest_prio_sched_ctx(sender_sched_ctx, (unsigned)nworkers_to_move);
  231. }
  232. else
  233. {
  234. poor_sched_ctx = receiver_sched_ctx;
  235. struct sc_hypervisor_policy_config *config = sc_hypervisor_get_config(poor_sched_ctx);
  236. int nworkers = (int)starpu_sched_ctx_get_nworkers(poor_sched_ctx);
  237. int nshared_workers = (int)starpu_sched_ctx_get_nshared_workers(sender_sched_ctx, poor_sched_ctx);
  238. if((nworkers+nworkers_to_move-nshared_workers) > config->max_nworkers)
  239. nworkers_to_move = nworkers > config->max_nworkers ? 0 : (config->max_nworkers - nworkers+nshared_workers);
  240. if(nworkers_to_move == 0) poor_sched_ctx = STARPU_NMAX_SCHED_CTXS;
  241. }
  242. if(poor_sched_ctx != STARPU_NMAX_SCHED_CTXS)
  243. {
  244. int *workers_to_move = sc_hypervisor_get_idlest_workers(sender_sched_ctx, &nworkers_to_move, STARPU_ANY_WORKER);
  245. sc_hypervisor_move_workers(sender_sched_ctx, poor_sched_ctx, workers_to_move, nworkers_to_move, now);
  246. struct sc_hypervisor_policy_config *new_config = sc_hypervisor_get_config(poor_sched_ctx);
  247. int i;
  248. for(i = 0; i < nworkers_to_move; i++)
  249. new_config->max_idle[workers_to_move[i]] = new_config->max_idle[workers_to_move[i]] !=MAX_IDLE_TIME ? new_config->max_idle[workers_to_move[i]] : new_config->new_workers_max_idle;
  250. free(workers_to_move);
  251. }
  252. }
  253. starpu_pthread_mutex_unlock(&act_hypervisor_mutex);
  254. return 1;
  255. }
  256. return 0;
  257. }
  258. unsigned sc_hypervisor_policy_resize_to_unknown_receiver(unsigned sender_sched_ctx, unsigned now)
  259. {
  260. return sc_hypervisor_policy_resize(sender_sched_ctx, STARPU_NMAX_SCHED_CTXS, 0, now);
  261. }
  262. double sc_hypervisor_get_slowest_ctx_exec_time(void)
  263. {
  264. unsigned *sched_ctxs = sc_hypervisor_get_sched_ctxs();
  265. int nsched_ctxs = sc_hypervisor_get_nsched_ctxs();
  266. /* double curr_time = starpu_timing_now(); */
  267. double slowest_time = 0.0;
  268. int s;
  269. struct sc_hypervisor_wrapper* sc_w;
  270. for(s = 0; s < nsched_ctxs; s++)
  271. {
  272. sc_w = sc_hypervisor_get_wrapper(sched_ctxs[s]);
  273. // double elapsed_time = (curr_time - sc_w->start_time)/1000000;
  274. struct sc_hypervisor_policy_config *config = sc_hypervisor_get_config(sc_w->sched_ctx);
  275. double elapsed_time = (config->ispeed_ctx_sample/1000000000.0)/sc_hypervisor_get_ctx_speed(sc_w);
  276. if(elapsed_time > slowest_time)
  277. slowest_time = elapsed_time;
  278. }
  279. return slowest_time;
  280. }
  281. double sc_hypervisor_get_fastest_ctx_exec_time(void)
  282. {
  283. unsigned *sched_ctxs = sc_hypervisor_get_sched_ctxs();
  284. int nsched_ctxs = sc_hypervisor_get_nsched_ctxs();
  285. double curr_time = starpu_timing_now();
  286. double fastest_time = curr_time;
  287. int s;
  288. struct sc_hypervisor_wrapper* sc_w;
  289. for(s = 0; s < nsched_ctxs; s++)
  290. {
  291. sc_w = sc_hypervisor_get_wrapper(sched_ctxs[s]);
  292. struct sc_hypervisor_policy_config *config = sc_hypervisor_get_config(sc_w->sched_ctx);
  293. double elapsed_time = (config->ispeed_ctx_sample/1000000000.0)/sc_hypervisor_get_ctx_speed(sc_w);
  294. if(elapsed_time < fastest_time)
  295. fastest_time = elapsed_time;
  296. }
  297. return fastest_time;
  298. }
  299. void sc_hypervisor_group_workers_by_type(struct types_of_workers *tw, int *total_nw)
  300. {
  301. unsigned w;
  302. for(w = 0; w < tw->nw; w++)
  303. total_nw[w] = 0;
  304. if(tw->ncpus != 0)
  305. {
  306. total_nw[0] = tw->ncpus;
  307. if(tw->ncuda != 0)
  308. total_nw[1] = tw->ncuda;
  309. }
  310. else
  311. {
  312. if(tw->ncuda != 0)
  313. total_nw[0] =tw->ncuda;
  314. }
  315. }
  316. enum starpu_worker_archtype sc_hypervisor_get_arch_for_index(unsigned w, struct types_of_workers *tw)
  317. {
  318. if(w == 0)
  319. {
  320. if(tw->ncpus != 0)
  321. return STARPU_CPU_WORKER;
  322. else
  323. return STARPU_CUDA_WORKER;
  324. }
  325. else
  326. if(tw->ncuda != 0)
  327. return STARPU_CUDA_WORKER;
  328. return STARPU_CPU_WORKER;
  329. }
  330. unsigned sc_hypervisor_get_index_for_arch(enum starpu_worker_archtype arch, struct types_of_workers *tw)
  331. {
  332. if(arch == STARPU_CPU_WORKER)
  333. {
  334. if(tw->ncpus != 0)
  335. return 0;
  336. }
  337. else
  338. {
  339. if(arch == STARPU_CUDA_WORKER)
  340. {
  341. if(tw->ncpus != 0)
  342. return 1;
  343. else
  344. return 0;
  345. }
  346. }
  347. return 0;
  348. }
  349. void sc_hypervisor_get_tasks_times(int nw, int nt, double times[nw][nt], int *workers, unsigned size_ctxs, struct sc_hypervisor_policy_task_pool *task_pools)
  350. {
  351. struct sc_hypervisor_policy_task_pool *tp;
  352. int w, t;
  353. for(w = 0; w < nw; w++)
  354. for(t = 0; t < nt; t++)
  355. times[w][t] = NAN;
  356. for (w = 0; w < nw; w++)
  357. {
  358. for (t = 0, tp = task_pools; tp; t++, tp = tp->next)
  359. {
  360. int worker = workers == NULL ? w : workers[w];
  361. struct starpu_perfmodel_arch* arch = starpu_worker_get_perf_archtype(worker, STARPU_NMAX_SCHED_CTXS);
  362. double length = starpu_perfmodel_history_based_expected_perf(tp->cl->model, arch, tp->footprint);
  363. if (isnan(length))
  364. times[w][t] = NAN;
  365. else
  366. {
  367. times[w][t] = (length / 1000.);
  368. double transfer_time = 0.0;
  369. unsigned worker_in_ctx = starpu_sched_ctx_contains_worker(worker, tp->sched_ctx_id);
  370. enum starpu_worker_archtype arch = starpu_worker_get_type(worker);
  371. if(!worker_in_ctx && !size_ctxs)
  372. {
  373. if(arch == STARPU_CUDA_WORKER)
  374. {
  375. double transfer_speed = starpu_transfer_bandwidth(STARPU_MAIN_RAM, starpu_worker_get_memory_node(worker));
  376. if(transfer_speed > 0.0)
  377. transfer_time += (tp->data_size / transfer_speed) / 1000. ;
  378. double latency = starpu_transfer_latency(STARPU_MAIN_RAM, starpu_worker_get_memory_node(worker));
  379. transfer_time += latency/1000.;
  380. // transfer_time *=4;
  381. }
  382. else if(arch == STARPU_CPU_WORKER)
  383. {
  384. if(!starpu_sched_ctx_contains_type_of_worker(arch, tp->sched_ctx_id))
  385. {
  386. double transfer_speed = starpu_transfer_bandwidth(starpu_worker_get_memory_node(worker), STARPU_MAIN_RAM);
  387. if(transfer_speed > 0.0)
  388. transfer_time += (tp->data_size / transfer_speed) / 1000. ;
  389. double latency = starpu_transfer_latency(starpu_worker_get_memory_node(worker), STARPU_MAIN_RAM);
  390. transfer_time += latency / 1000.;
  391. }
  392. }
  393. }
  394. // printf("%d/%d %s x %d time = %lf transfer_time = %lf\n", w, tp->sched_ctx_id, tp->cl->model->symbol, tp->n, times[w][t], transfer_time);
  395. times[w][t] += transfer_time;
  396. }
  397. // printf("sc%d w%d task %s nt %d times %lf s\n", tp->sched_ctx_id, w, tp->cl->model->symbol, tp->n, times[w][t]);
  398. }
  399. }
  400. }
  401. unsigned sc_hypervisor_check_idle(unsigned sched_ctx, int worker)
  402. {
  403. struct sc_hypervisor_wrapper* sc_w = sc_hypervisor_get_wrapper(sched_ctx);
  404. struct sc_hypervisor_policy_config *config = sc_w->config;
  405. if(config != NULL)
  406. {
  407. if(sc_w->idle_time[worker] > config->max_idle[worker])
  408. {
  409. // printf("w%d/ctx%d: current idle %lf max_idle %lf\n", worker, sched_ctx, sc_w->idle_time[worker], config->max_idle[worker]);
  410. return 1;
  411. }
  412. }
  413. return 0;
  414. }
  415. /* check if there is a big speed gap between the contexts */
  416. unsigned sc_hypervisor_check_speed_gap_btw_ctxs(unsigned *sched_ctxs_in, int ns_in, int *workers_in, int nworkers_in)
  417. {
  418. unsigned *sched_ctxs = sched_ctxs_in == NULL ? sc_hypervisor_get_sched_ctxs() : sched_ctxs_in;
  419. int ns = ns_in == -1 ? sc_hypervisor_get_nsched_ctxs() : ns_in;
  420. int *workers = workers_in;
  421. int nworkers = nworkers_in == -1 ? starpu_worker_get_count() : nworkers_in;
  422. int i = 0, j = 0;
  423. struct sc_hypervisor_wrapper* sc_w;
  424. struct sc_hypervisor_wrapper* other_sc_w;
  425. double optimal_v[ns];
  426. unsigned has_opt_v = 1;
  427. for(i = 0; i < ns; i++)
  428. {
  429. optimal_v[i] = _get_optimal_v(sched_ctxs[i]);
  430. if(optimal_v[i] == 0.0)
  431. {
  432. has_opt_v = 0;
  433. break;
  434. }
  435. }
  436. /*if an optimal speed has not been computed yet do it now */
  437. if(!has_opt_v)
  438. {
  439. struct types_of_workers *tw = sc_hypervisor_get_types_of_workers(workers, nworkers);
  440. int nw = tw->nw;
  441. double nworkers_per_ctx[ns][nw];
  442. int total_nw[nw];
  443. sc_hypervisor_group_workers_by_type(tw, total_nw);
  444. // double vmax = sc_hypervisor_lp_get_nworkers_per_ctx(ns, nw, nworkers_per_ctx, total_nw, tw, sched_ctxs);
  445. // if(vmax != 0.0)
  446. {
  447. for(i = 0; i < ns; i++)
  448. {
  449. sc_w = sc_hypervisor_get_wrapper(sched_ctxs[i]);
  450. double v[nw];
  451. optimal_v[i] = 0.0;
  452. int w;
  453. for(w = 0; w < nw; w++)
  454. {
  455. v[w] = sc_hypervisor_get_speed(sc_w, sc_hypervisor_get_arch_for_index(w, tw));
  456. optimal_v[i] += nworkers_per_ctx[i][w] == -1.0 ? 0.0 : nworkers_per_ctx[i][w]*v[w];
  457. }
  458. _set_optimal_v(sched_ctxs[i], optimal_v[i]);
  459. }
  460. has_opt_v = 1;
  461. }
  462. }
  463. /* if we have an optimal speed for each type of worker compare the monitored one with the
  464. theoretical one */
  465. if(has_opt_v)
  466. {
  467. for(i = 0; i < ns; i++)
  468. {
  469. sc_w = sc_hypervisor_get_wrapper(sched_ctxs[i]);
  470. double ctx_v = sc_hypervisor_get_ctx_speed(sc_w);
  471. if(ctx_v == -1.0)
  472. return 0;
  473. }
  474. for(i = 0; i < ns; i++)
  475. {
  476. sc_w = sc_hypervisor_get_wrapper(sched_ctxs[i]);
  477. double ctx_v = sc_hypervisor_get_ctx_speed(sc_w);
  478. ctx_v = ctx_v < 0.01 ? 0.0 : ctx_v;
  479. double max_vel = _get_max_speed_gap();
  480. if(ctx_v != -1.0 && ((ctx_v < (1-max_vel)*optimal_v[i]) || ctx_v > (1+max_vel)*optimal_v[i]))
  481. {
  482. return 1;
  483. }
  484. }
  485. }
  486. else /* if we have not been able to compute a theoretical speed consider the env variable
  487. SC_MAX_SPEED_GAP and compare the speed of the contexts, whenever the difference
  488. btw them is greater than the max value the function returns true */
  489. {
  490. for(i = 0; i < ns; i++)
  491. {
  492. sc_w = sc_hypervisor_get_wrapper(sched_ctxs[i]);
  493. double ctx_v = sc_hypervisor_get_ctx_speed(sc_w);
  494. if(ctx_v != -1.0)
  495. {
  496. for(j = 0; j < ns; j++)
  497. {
  498. if(sched_ctxs[i] != sched_ctxs[j])
  499. {
  500. unsigned nworkers = starpu_sched_ctx_get_nworkers(sched_ctxs[j]);
  501. if(nworkers == 0)
  502. return 1;
  503. other_sc_w = sc_hypervisor_get_wrapper(sched_ctxs[j]);
  504. double other_ctx_v = sc_hypervisor_get_ctx_speed(other_sc_w);
  505. if(other_ctx_v != -1.0)
  506. {
  507. double gap = ctx_v < other_ctx_v ? other_ctx_v / ctx_v : ctx_v / other_ctx_v;
  508. double max_vel = _get_max_speed_gap();
  509. if(gap > max_vel)
  510. return 1;
  511. }
  512. }
  513. }
  514. }
  515. }
  516. }
  517. return 0;
  518. }
  519. unsigned sc_hypervisor_check_speed_gap_btw_ctxs_on_level(int level, int *workers_in, int nworkers_in, unsigned father_sched_ctx_id, unsigned **sched_ctxs, int *nsched_ctxs)
  520. {
  521. sc_hypervisor_get_ctxs_on_level(sched_ctxs, nsched_ctxs, level, father_sched_ctx_id);
  522. if(*nsched_ctxs > 0)
  523. return sc_hypervisor_check_speed_gap_btw_ctxs(*sched_ctxs, *nsched_ctxs, workers_in, nworkers_in);
  524. return 0;
  525. }
  526. unsigned sc_hypervisor_criteria_fulfilled(unsigned sched_ctx, int worker)
  527. {
  528. unsigned criteria = sc_hypervisor_get_resize_criteria();
  529. if(criteria != SC_NOTHING)
  530. {
  531. if(criteria == SC_IDLE)
  532. return sc_hypervisor_check_idle(sched_ctx, worker);
  533. else
  534. return sc_hypervisor_check_speed_gap_btw_ctxs(NULL, -1, NULL, -1);
  535. }
  536. else
  537. return 0;
  538. }