policy_tools.c 18 KB

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