sched_ctx.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011, 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 <core/sched_policy.h>
  17. #include <core/sched_ctx.h>
  18. #include <common/utils.h>
  19. starpu_pthread_mutex_t changing_ctx_mutex[STARPU_NMAX_SCHED_CTXS];
  20. extern struct starpu_worker_collection worker_list;
  21. static starpu_pthread_mutex_t sched_ctx_manag = STARPU_PTHREAD_MUTEX_INITIALIZER;
  22. static starpu_pthread_mutex_t finished_submit_mutex = STARPU_PTHREAD_MUTEX_INITIALIZER;
  23. struct starpu_task stop_submission_task = STARPU_TASK_INITIALIZER;
  24. starpu_pthread_key_t sched_ctx_key;
  25. unsigned with_hypervisor = 0;
  26. double max_time_worker_on_ctx = -1.0;
  27. static unsigned _starpu_get_first_free_sched_ctx(struct _starpu_machine_config *config);
  28. static unsigned _starpu_worker_get_first_free_sched_ctx(struct _starpu_worker *worker);
  29. static unsigned _starpu_worker_get_sched_ctx_id(struct _starpu_worker *worker, unsigned sched_ctx_id);
  30. static unsigned _get_workers_list(struct _starpu_sched_ctx *sched_ctx, int **workerids);
  31. static void _starpu_worker_gets_into_ctx(unsigned sched_ctx_id, struct _starpu_worker *worker)
  32. {
  33. unsigned worker_sched_ctx_id = _starpu_worker_get_sched_ctx_id(worker, sched_ctx_id);
  34. /* the worker was planning to go away in another ctx but finally he changed his mind &
  35. he's staying */
  36. if (worker_sched_ctx_id == STARPU_NMAX_SCHED_CTXS)
  37. {
  38. worker_sched_ctx_id = _starpu_worker_get_first_free_sched_ctx(worker);
  39. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
  40. /* add context to worker */
  41. worker->sched_ctx[worker_sched_ctx_id] = sched_ctx;
  42. worker->nsched_ctxs++;
  43. worker->active_ctx = sched_ctx_id;
  44. }
  45. worker->removed_from_ctx[sched_ctx_id] = 0;
  46. return;
  47. }
  48. void _starpu_worker_gets_out_of_ctx(unsigned sched_ctx_id, struct _starpu_worker *worker)
  49. {
  50. unsigned worker_sched_ctx_id = _starpu_worker_get_sched_ctx_id(worker, sched_ctx_id);
  51. /* remove context from worker */
  52. if(worker->sched_ctx[worker_sched_ctx_id]->sched_policy && worker->sched_ctx[worker_sched_ctx_id]->sched_policy->remove_workers)
  53. worker->sched_ctx[worker_sched_ctx_id]->sched_policy->remove_workers(sched_ctx_id, &worker->workerid, 1);
  54. worker->sched_ctx[worker_sched_ctx_id] = NULL;
  55. worker->nsched_ctxs--;
  56. return;
  57. }
  58. static void _starpu_update_workers_with_ctx(int *workerids, int nworkers, int sched_ctx_id)
  59. {
  60. int i;
  61. struct _starpu_worker *worker = NULL;
  62. struct _starpu_worker *curr_worker = _starpu_get_local_worker_key();
  63. for(i = 0; i < nworkers; i++)
  64. {
  65. worker = _starpu_get_worker_struct(workerids[i]);
  66. /* if the current thread requires resize it's no need
  67. to lock it in order to change its sched_ctx info */
  68. if(curr_worker && curr_worker == worker)
  69. _starpu_worker_gets_into_ctx(sched_ctx_id, worker);
  70. else
  71. {
  72. STARPU_PTHREAD_MUTEX_LOCK(&worker->sched_mutex);
  73. _starpu_worker_gets_into_ctx(sched_ctx_id, worker);
  74. STARPU_PTHREAD_MUTEX_UNLOCK(&worker->sched_mutex);
  75. }
  76. }
  77. return;
  78. }
  79. static void _starpu_update_workers_without_ctx(int *workerids, int nworkers, int sched_ctx_id, unsigned now)
  80. {
  81. int i;
  82. struct _starpu_worker *worker = NULL;
  83. struct _starpu_worker *curr_worker = _starpu_get_local_worker_key();
  84. for(i = 0; i < nworkers; i++)
  85. {
  86. worker = _starpu_get_worker_struct(workerids[i]);
  87. if(now)
  88. {
  89. if(curr_worker && curr_worker == worker)
  90. _starpu_worker_gets_out_of_ctx(sched_ctx_id, worker);
  91. else
  92. {
  93. STARPU_PTHREAD_MUTEX_LOCK(&worker->sched_mutex);
  94. _starpu_worker_gets_out_of_ctx(sched_ctx_id, worker);
  95. STARPU_PTHREAD_MUTEX_UNLOCK(&worker->sched_mutex);
  96. }
  97. }
  98. else
  99. {
  100. if(curr_worker && curr_worker == worker)
  101. worker->removed_from_ctx[sched_ctx_id] = 1;
  102. else
  103. {
  104. STARPU_PTHREAD_MUTEX_LOCK(&worker->sched_mutex);
  105. worker->removed_from_ctx[sched_ctx_id] = 1;
  106. STARPU_PTHREAD_MUTEX_UNLOCK(&worker->sched_mutex);
  107. }
  108. }
  109. }
  110. return;
  111. }
  112. void starpu_sched_ctx_stop_task_submission()
  113. {
  114. _starpu_exclude_task_from_dag(&stop_submission_task);
  115. _starpu_task_submit_internally(&stop_submission_task);
  116. }
  117. static void _starpu_add_workers_to_sched_ctx(struct _starpu_sched_ctx *sched_ctx, int *workerids, int nworkers,
  118. int *added_workers, int *n_added_workers)
  119. {
  120. struct starpu_worker_collection *workers = sched_ctx->workers;
  121. struct _starpu_machine_config *config = (struct _starpu_machine_config *)_starpu_get_machine_config();
  122. int nworkers_to_add = nworkers == -1 ? (int)config->topology.nworkers : nworkers;
  123. int workers_to_add[nworkers_to_add];
  124. int i = 0;
  125. for(i = 0; i < nworkers_to_add; i++)
  126. {
  127. /* added_workers is NULL for the call of this func at the creation of the context*/
  128. /* if the function is called at the creation of the context it's no need to do this verif */
  129. if(added_workers)
  130. {
  131. int worker = workers->add(workers, (workerids == NULL ? i : workerids[i]));
  132. if(worker >= 0)
  133. added_workers[(*n_added_workers)++] = worker;
  134. else
  135. {
  136. struct _starpu_worker *worker_str = _starpu_get_worker_struct(workerids[i]);
  137. STARPU_PTHREAD_MUTEX_LOCK(&worker_str->sched_mutex);
  138. worker_str->removed_from_ctx[sched_ctx->id] = 0;
  139. STARPU_PTHREAD_MUTEX_UNLOCK(&worker_str->sched_mutex);
  140. }
  141. }
  142. else
  143. {
  144. int worker = (workerids == NULL ? i : workerids[i]);
  145. workers->add(workers, worker);
  146. workers_to_add[i] = worker;
  147. }
  148. }
  149. if(sched_ctx->sched_policy->add_workers)
  150. {
  151. if(added_workers)
  152. {
  153. if(*n_added_workers > 0)
  154. sched_ctx->sched_policy->add_workers(sched_ctx->id, added_workers, *n_added_workers);
  155. }
  156. else
  157. sched_ctx->sched_policy->add_workers(sched_ctx->id, workers_to_add, nworkers_to_add);
  158. }
  159. return;
  160. }
  161. static void _starpu_remove_workers_from_sched_ctx(struct _starpu_sched_ctx *sched_ctx, int *workerids,
  162. int nworkers, int *removed_workers, int *n_removed_workers)
  163. {
  164. struct starpu_worker_collection *workers = sched_ctx->workers;
  165. int i = 0;
  166. for(i = 0; i < nworkers; i++)
  167. {
  168. if(workers->nworkers > 0)
  169. {
  170. if(_starpu_worker_belongs_to_a_sched_ctx(workerids[i], sched_ctx->id))
  171. {
  172. int worker = workers->remove(workers, workerids[i]);
  173. if(worker >= 0)
  174. removed_workers[(*n_removed_workers)++] = worker;
  175. }
  176. }
  177. }
  178. return;
  179. }
  180. static void _starpu_sched_ctx_free_scheduling_data(struct _starpu_sched_ctx *sched_ctx)
  181. {
  182. int *workerids = NULL;
  183. unsigned nworkers_ctx = _get_workers_list(sched_ctx, &workerids);
  184. if(nworkers_ctx > 0 && sched_ctx->sched_policy->remove_workers)
  185. sched_ctx->sched_policy->remove_workers(sched_ctx->id, workerids, nworkers_ctx);
  186. free(workerids);
  187. return;
  188. }
  189. struct _starpu_sched_ctx* _starpu_create_sched_ctx(const char *policy_name, int *workerids,
  190. int nworkers_ctx, unsigned is_initial_sched,
  191. const char *sched_name)
  192. {
  193. struct _starpu_machine_config *config = (struct _starpu_machine_config *)_starpu_get_machine_config();
  194. STARPU_PTHREAD_MUTEX_LOCK(&sched_ctx_manag);
  195. STARPU_ASSERT(config->topology.nsched_ctxs < STARPU_NMAX_SCHED_CTXS);
  196. unsigned id = _starpu_get_first_free_sched_ctx(config);
  197. struct _starpu_sched_ctx *sched_ctx = &config->sched_ctxs[id];
  198. sched_ctx->id = id;
  199. config->topology.nsched_ctxs++;
  200. STARPU_PTHREAD_MUTEX_UNLOCK(&sched_ctx_manag);
  201. int nworkers = config->topology.nworkers;
  202. STARPU_ASSERT(nworkers_ctx <= nworkers);
  203. STARPU_PTHREAD_MUTEX_INIT(&sched_ctx->empty_ctx_mutex, NULL);
  204. starpu_task_list_init(&sched_ctx->empty_ctx_tasks);
  205. sched_ctx->sched_policy = (struct starpu_sched_policy*)malloc(sizeof(struct starpu_sched_policy));
  206. sched_ctx->is_initial_sched = is_initial_sched;
  207. sched_ctx->name = sched_name;
  208. sched_ctx->inheritor = STARPU_NMAX_SCHED_CTXS;
  209. sched_ctx->finished_submit = 0;
  210. sched_ctx->min_priority = 0;
  211. sched_ctx->max_priority = 1;
  212. _starpu_barrier_counter_init(&sched_ctx->tasks_barrier, 0);
  213. /*init the strategy structs and the worker_collection of the ressources of the context */
  214. _starpu_init_sched_policy(config, sched_ctx, policy_name);
  215. /* construct the collection of workers(list/tree/etc.) */
  216. sched_ctx->workers->init(sched_ctx->workers);
  217. /* after having an worker_collection on the ressources add them */
  218. _starpu_add_workers_to_sched_ctx(sched_ctx, workerids, nworkers_ctx, NULL, NULL);
  219. /* if we create the initial big sched ctx we can update workers' status here
  220. because they haven't been launched yet */
  221. if(is_initial_sched)
  222. {
  223. int i;
  224. /*initialize the mutexes for all contexts */
  225. for(i = 0; i < STARPU_NMAX_SCHED_CTXS; i++)
  226. STARPU_PTHREAD_MUTEX_INIT(&changing_ctx_mutex[i], NULL);
  227. for(i = 0; i < nworkers; i++)
  228. {
  229. struct _starpu_worker *worker = _starpu_get_worker_struct(i);
  230. worker->sched_ctx[_starpu_worker_get_first_free_sched_ctx(worker)] = sched_ctx;
  231. worker->nsched_ctxs++;
  232. }
  233. }
  234. int w;
  235. for(w = 0; w < STARPU_NMAXWORKERS; w++)
  236. {
  237. sched_ctx->pop_counter[w] = 0;
  238. }
  239. return sched_ctx;
  240. }
  241. static void _get_workers(int min, int max, int *workers, int *nw, enum starpu_archtype arch, unsigned allow_overlap)
  242. {
  243. int pus[max];
  244. int npus = 0;
  245. int i;
  246. int n = 0;
  247. struct _starpu_machine_config *config = (struct _starpu_machine_config *)_starpu_get_machine_config();
  248. if(config->topology.nsched_ctxs == 1)
  249. {
  250. /*we have all available resources */
  251. npus = starpu_worker_get_nids_by_type(arch, pus, max);
  252. /*TODO: hierarchical ctxs: get max good workers: close one to another */
  253. for(i = 0; i < npus; i++)
  254. workers[(*nw)++] = pus[i];
  255. }
  256. else
  257. {
  258. unsigned enough_ressources = 0;
  259. npus = starpu_worker_get_nids_ctx_free_by_type(arch, pus, max);
  260. for(i = 0; i < npus; i++)
  261. workers[(*nw)++] = pus[i];
  262. if(npus == max)
  263. /*we have enough available resources */
  264. enough_ressources = 1;
  265. if(!enough_ressources && npus >= min)
  266. /*we have enough available resources */
  267. enough_ressources = 1;
  268. if(!enough_ressources)
  269. {
  270. /* try to get ressources from ctx who have more than the min of workers they need */
  271. int s;
  272. for(s = 1; s < STARPU_NMAX_SCHED_CTXS; s++)
  273. {
  274. if(config->sched_ctxs[s].id != STARPU_NMAX_SCHED_CTXS)
  275. {
  276. int _npus = 0;
  277. int _pus[STARPU_NMAXWORKERS];
  278. _npus = starpu_get_workers_of_sched_ctx(config->sched_ctxs[s].id, _pus, arch);
  279. int ctx_min = arch == STARPU_CPU_WORKER ? config->sched_ctxs[s].min_ncpus : config->sched_ctxs[s].min_ngpus;
  280. if(_npus > ctx_min)
  281. {
  282. if(npus < min)
  283. {
  284. n = (_npus - ctx_min) > (min - npus) ? min - npus : (_npus - ctx_min);
  285. npus += n;
  286. }
  287. /*TODO: hierarchical ctxs: get n good workers: close to the other ones I already assigned to the ctx */
  288. for(i = 0; i < n; i++)
  289. workers[(*nw)++] = _pus[i];
  290. starpu_sched_ctx_remove_workers(_pus, n, config->sched_ctxs[s].id);
  291. }
  292. }
  293. }
  294. if(npus >= min)
  295. enough_ressources = 1;
  296. }
  297. if(!enough_ressources)
  298. {
  299. /* if there is no available workers to satisfy the minimum required
  300. give them workers proportional to their requirements*/
  301. int global_npus = starpu_worker_get_count_by_type(arch);
  302. int req_npus = 0;
  303. int s;
  304. for(s = 1; s < STARPU_NMAX_SCHED_CTXS; s++)
  305. if(config->sched_ctxs[s].id != STARPU_NMAX_SCHED_CTXS)
  306. req_npus += arch == STARPU_CPU_WORKER ? config->sched_ctxs[s].min_ncpus : config->sched_ctxs[s].min_ngpus;
  307. req_npus += min;
  308. for(s = 1; s < STARPU_NMAX_SCHED_CTXS; s++)
  309. {
  310. if(config->sched_ctxs[s].id != STARPU_NMAX_SCHED_CTXS)
  311. {
  312. int ctx_min = arch == STARPU_CPU_WORKER ? config->sched_ctxs[s].min_ncpus : config->sched_ctxs[s].min_ngpus;
  313. double needed_npus = ((double)ctx_min * (double)global_npus) / (double)req_npus;
  314. int _npus = 0;
  315. int _pus[STARPU_NMAXWORKERS];
  316. _npus = starpu_get_workers_of_sched_ctx(config->sched_ctxs[s].id, _pus, arch);
  317. if(needed_npus < (double)_npus)
  318. {
  319. double npus_to_rem = (double)_npus - needed_npus;
  320. int x = floor(npus_to_rem);
  321. double x_double = (double)x;
  322. double diff = npus_to_rem - x_double;
  323. int npus_to_remove = diff >= 0.5 ? x+1 : x;
  324. int pus_to_remove[npus_to_remove];
  325. int c = 0;
  326. /*TODO: hierarchical ctxs: get npus_to_remove good workers: close to the other ones I already assigned to the ctx */
  327. for(i = _npus-1; i >= (_npus - npus_to_remove); i--)
  328. {
  329. workers[(*nw)++] = _pus[i];
  330. pus_to_remove[c++] = _pus[i];
  331. }
  332. if(!allow_overlap)
  333. starpu_sched_ctx_remove_workers(pus_to_remove, npus_to_remove, config->sched_ctxs[s].id);
  334. }
  335. }
  336. }
  337. }
  338. }
  339. }
  340. unsigned starpu_sched_ctx_create_inside_interval(const char *policy_name, const char *sched_name,
  341. int min_ncpus, int max_ncpus, int min_ngpus, int max_ngpus,
  342. unsigned allow_overlap)
  343. {
  344. struct _starpu_sched_ctx *sched_ctx = NULL;
  345. int workers[max_ncpus + max_ngpus];
  346. int nw = 0;
  347. STARPU_PTHREAD_MUTEX_LOCK(&sched_ctx_manag);
  348. _get_workers(min_ncpus, max_ncpus, workers, &nw, STARPU_CPU_WORKER, allow_overlap);
  349. _get_workers(min_ngpus, max_ngpus, workers, &nw, STARPU_CUDA_WORKER, allow_overlap);
  350. STARPU_PTHREAD_MUTEX_UNLOCK(&sched_ctx_manag);
  351. int i;
  352. printf("%d: ", nw);
  353. for(i = 0; i < nw; i++)
  354. printf("%d ", workers[i]);
  355. printf("\n");
  356. sched_ctx = _starpu_create_sched_ctx(policy_name, workers, nw, 0, sched_name);
  357. sched_ctx->min_ncpus = min_ncpus;
  358. sched_ctx->max_ncpus = max_ncpus;
  359. sched_ctx->min_ngpus = min_ngpus;
  360. sched_ctx->max_ngpus = max_ngpus;
  361. _starpu_update_workers_without_ctx(sched_ctx->workers->workerids, sched_ctx->workers->nworkers, sched_ctx->id, 0);
  362. #ifdef STARPU_USE_SC_HYPERVISOR
  363. sched_ctx->perf_counters = NULL;
  364. #endif
  365. return sched_ctx->id;
  366. }
  367. unsigned starpu_sched_ctx_create(const char *policy_name, int *workerids,
  368. int nworkers, const char *sched_name)
  369. {
  370. struct _starpu_sched_ctx *sched_ctx = NULL;
  371. sched_ctx = _starpu_create_sched_ctx(policy_name, workerids, nworkers, 0, sched_name);
  372. _starpu_update_workers_with_ctx(sched_ctx->workers->workerids, sched_ctx->workers->nworkers, sched_ctx->id);
  373. #ifdef STARPU_USE_SC_HYPERVISOR
  374. sched_ctx->perf_counters = NULL;
  375. #endif
  376. return sched_ctx->id;
  377. }
  378. #ifdef STARPU_USE_SC_HYPERVISOR
  379. void starpu_sched_ctx_set_perf_counters(unsigned sched_ctx_id, struct starpu_sched_ctx_performance_counters *perf_counters)
  380. {
  381. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
  382. sched_ctx->perf_counters = perf_counters;
  383. return;
  384. }
  385. #endif
  386. /* free all structures for the context */
  387. static void _starpu_delete_sched_ctx(struct _starpu_sched_ctx *sched_ctx)
  388. {
  389. STARPU_ASSERT(sched_ctx->id != STARPU_NMAX_SCHED_CTXS);
  390. _starpu_deinit_sched_policy(sched_ctx);
  391. free(sched_ctx->sched_policy);
  392. sched_ctx->sched_policy = NULL;
  393. STARPU_PTHREAD_MUTEX_DESTROY(&sched_ctx->empty_ctx_mutex);
  394. sched_ctx->id = STARPU_NMAX_SCHED_CTXS;
  395. struct _starpu_machine_config *config = _starpu_get_machine_config();
  396. STARPU_PTHREAD_MUTEX_LOCK(&sched_ctx_manag);
  397. config->topology.nsched_ctxs--;
  398. STARPU_PTHREAD_MUTEX_UNLOCK(&sched_ctx_manag);
  399. }
  400. void starpu_sched_ctx_delete(unsigned sched_ctx_id)
  401. {
  402. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
  403. #ifdef STARPU_USE_SC_HYPERVISOR
  404. if(sched_ctx != NULL && sched_ctx_id != 0 && sched_ctx_id != STARPU_NMAX_SCHED_CTXS
  405. && sched_ctx->perf_counters != NULL)
  406. sched_ctx->perf_counters->notify_delete_context(sched_ctx_id);
  407. #endif //STARPU_USE_SC_HYPERVISOR
  408. unsigned inheritor_sched_ctx_id = sched_ctx->inheritor;
  409. struct _starpu_sched_ctx *inheritor_sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx->inheritor);
  410. STARPU_PTHREAD_MUTEX_LOCK(&changing_ctx_mutex[sched_ctx_id]);
  411. STARPU_ASSERT(sched_ctx->id != STARPU_NMAX_SCHED_CTXS);
  412. int *workerids;
  413. unsigned nworkers_ctx = _get_workers_list(sched_ctx, &workerids);
  414. /*if both of them have all the ressources is pointless*/
  415. /*trying to transfer ressources from one ctx to the other*/
  416. struct _starpu_machine_config *config = (struct _starpu_machine_config *)_starpu_get_machine_config();
  417. unsigned nworkers = config->topology.nworkers;
  418. if(nworkers_ctx > 0 && inheritor_sched_ctx && inheritor_sched_ctx->id != STARPU_NMAX_SCHED_CTXS &&
  419. !(nworkers_ctx == nworkers && nworkers_ctx == inheritor_sched_ctx->workers->nworkers))
  420. {
  421. starpu_sched_ctx_add_workers(workerids, nworkers_ctx, inheritor_sched_ctx_id);
  422. }
  423. if(!_starpu_wait_for_all_tasks_of_sched_ctx(sched_ctx_id))
  424. {
  425. /*if btw the mutex release & the mutex lock the context has changed take care to free all
  426. scheduling data before deleting the context */
  427. _starpu_update_workers_without_ctx(workerids, nworkers_ctx, sched_ctx_id, 1);
  428. // _starpu_sched_ctx_free_scheduling_data(sched_ctx);
  429. _starpu_delete_sched_ctx(sched_ctx);
  430. }
  431. /* workerids is malloc-ed in _get_workers_list, don't forget to free it when
  432. you don't use it anymore */
  433. free(workerids);
  434. STARPU_PTHREAD_MUTEX_UNLOCK(&changing_ctx_mutex[sched_ctx_id]);
  435. return;
  436. }
  437. /* called after the workers are terminated so we don't have anything else to do but free the memory*/
  438. void _starpu_delete_all_sched_ctxs()
  439. {
  440. unsigned i;
  441. for(i = 0; i < STARPU_NMAX_SCHED_CTXS; i++)
  442. {
  443. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(i);
  444. STARPU_PTHREAD_MUTEX_LOCK(&changing_ctx_mutex[i]);
  445. if(sched_ctx->id != STARPU_NMAX_SCHED_CTXS)
  446. {
  447. _starpu_sched_ctx_free_scheduling_data(sched_ctx);
  448. _starpu_barrier_counter_destroy(&sched_ctx->tasks_barrier);
  449. _starpu_delete_sched_ctx(sched_ctx);
  450. }
  451. STARPU_PTHREAD_MUTEX_UNLOCK(&changing_ctx_mutex[i]);
  452. STARPU_PTHREAD_MUTEX_DESTROY(&changing_ctx_mutex[i]);
  453. }
  454. return;
  455. }
  456. static void _starpu_check_workers(int *workerids, int nworkers)
  457. {
  458. struct _starpu_machine_config *config = (struct _starpu_machine_config *)_starpu_get_machine_config();
  459. int nworkers_conf = config->topology.nworkers;
  460. int i;
  461. for(i = 0; i < nworkers; i++)
  462. {
  463. /* take care the user does not ask for a resource that does not exist */
  464. STARPU_ASSERT_MSG(workerids[i] >= 0 && workerids[i] <= nworkers_conf, "workerid = %d", workerids[i]);
  465. }
  466. }
  467. void _starpu_fetch_tasks_from_empty_ctx_list(struct _starpu_sched_ctx *sched_ctx)
  468. {
  469. unsigned unlocked = 0;
  470. STARPU_PTHREAD_MUTEX_LOCK(&sched_ctx->empty_ctx_mutex);
  471. if(starpu_task_list_empty(&sched_ctx->empty_ctx_tasks))
  472. {
  473. STARPU_PTHREAD_MUTEX_UNLOCK(&sched_ctx->empty_ctx_mutex);
  474. return;
  475. }
  476. else
  477. /* you're not suppose to get here if you deleted the context
  478. so no point in having the mutex locked */
  479. STARPU_PTHREAD_MUTEX_UNLOCK(&changing_ctx_mutex[sched_ctx->id]);
  480. while(!starpu_task_list_empty(&sched_ctx->empty_ctx_tasks))
  481. {
  482. if(unlocked)
  483. STARPU_PTHREAD_MUTEX_LOCK(&sched_ctx->empty_ctx_mutex);
  484. struct starpu_task *old_task = starpu_task_list_pop_back(&sched_ctx->empty_ctx_tasks);
  485. unlocked = 1;
  486. STARPU_PTHREAD_MUTEX_UNLOCK(&sched_ctx->empty_ctx_mutex);
  487. if(old_task == &stop_submission_task)
  488. break;
  489. int ret = _starpu_push_task_to_workers(old_task);
  490. /* if we should stop poping from empty ctx tasks */
  491. if(ret == -EAGAIN) break;
  492. }
  493. if(!unlocked)
  494. STARPU_PTHREAD_MUTEX_UNLOCK(&sched_ctx->empty_ctx_mutex);
  495. /* leave the mutex as it was to avoid pbs in the caller function */
  496. STARPU_PTHREAD_MUTEX_LOCK(&changing_ctx_mutex[sched_ctx->id]);
  497. return;
  498. }
  499. void starpu_sched_ctx_add_workers(int *workers_to_add, int nworkers_to_add, unsigned sched_ctx_id)
  500. {
  501. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
  502. int added_workers[nworkers_to_add];
  503. int n_added_workers = 0;
  504. STARPU_PTHREAD_MUTEX_LOCK(&changing_ctx_mutex[sched_ctx_id]);
  505. STARPU_ASSERT(workers_to_add != NULL && nworkers_to_add > 0);
  506. _starpu_check_workers(workers_to_add, nworkers_to_add);
  507. /* if the context has not already been deleted */
  508. if(sched_ctx->id != STARPU_NMAX_SCHED_CTXS)
  509. {
  510. _starpu_add_workers_to_sched_ctx(sched_ctx, workers_to_add, nworkers_to_add, added_workers, &n_added_workers);
  511. if(n_added_workers > 0)
  512. {
  513. _starpu_update_workers_with_ctx(added_workers, n_added_workers, sched_ctx->id);
  514. }
  515. _starpu_fetch_tasks_from_empty_ctx_list(sched_ctx);
  516. }
  517. STARPU_PTHREAD_MUTEX_UNLOCK(&changing_ctx_mutex[sched_ctx_id]);
  518. return;
  519. }
  520. void starpu_sched_ctx_remove_workers(int *workers_to_remove, int nworkers_to_remove, unsigned sched_ctx_id)
  521. {
  522. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
  523. int removed_workers[sched_ctx->workers->nworkers];
  524. int n_removed_workers = 0;
  525. _starpu_check_workers(workers_to_remove, nworkers_to_remove);
  526. STARPU_PTHREAD_MUTEX_LOCK(&changing_ctx_mutex[sched_ctx_id]);
  527. /* if the context has not already been deleted */
  528. if(sched_ctx->id != STARPU_NMAX_SCHED_CTXS)
  529. {
  530. _starpu_remove_workers_from_sched_ctx(sched_ctx, workers_to_remove, nworkers_to_remove, removed_workers, &n_removed_workers);
  531. if(n_removed_workers > 0)
  532. _starpu_update_workers_without_ctx(removed_workers, n_removed_workers, sched_ctx->id, 0);
  533. }
  534. STARPU_PTHREAD_MUTEX_UNLOCK(&changing_ctx_mutex[sched_ctx_id]);
  535. return;
  536. }
  537. /* unused sched_ctx have the id STARPU_NMAX_SCHED_CTXS */
  538. void _starpu_init_all_sched_ctxs(struct _starpu_machine_config *config)
  539. {
  540. starpu_pthread_key_create(&sched_ctx_key, NULL);
  541. unsigned i;
  542. for(i = 0; i < STARPU_NMAX_SCHED_CTXS; i++)
  543. config->sched_ctxs[i].id = STARPU_NMAX_SCHED_CTXS;
  544. char* max_time_on_ctx = getenv("STARPU_MAX_TIME_ON_CTX");
  545. if (max_time_on_ctx != NULL)
  546. max_time_worker_on_ctx = atof(max_time_on_ctx);
  547. return;
  548. }
  549. /* unused sched_ctx pointers of a worker are NULL */
  550. void _starpu_init_sched_ctx_for_worker(unsigned workerid)
  551. {
  552. struct _starpu_worker *worker = _starpu_get_worker_struct(workerid);
  553. worker->sched_ctx = (struct _starpu_sched_ctx**)malloc(STARPU_NMAX_SCHED_CTXS * sizeof(struct _starpu_sched_ctx*));
  554. unsigned i;
  555. for(i = 0; i < STARPU_NMAX_SCHED_CTXS; i++)
  556. worker->sched_ctx[i] = NULL;
  557. return;
  558. }
  559. void _starpu_delete_sched_ctx_for_worker(unsigned workerid)
  560. {
  561. struct _starpu_worker *worker = _starpu_get_worker_struct(workerid);
  562. free(worker->sched_ctx);
  563. }
  564. /* sched_ctx aren't necessarly one next to another */
  565. /* for eg when we remove one its place is free */
  566. /* when we add new one we reuse its place */
  567. static unsigned _starpu_get_first_free_sched_ctx(struct _starpu_machine_config *config)
  568. {
  569. unsigned i;
  570. for(i = 0; i < STARPU_NMAX_SCHED_CTXS; i++)
  571. if(config->sched_ctxs[i].id == STARPU_NMAX_SCHED_CTXS)
  572. return i;
  573. STARPU_ASSERT(0);
  574. return STARPU_NMAX_SCHED_CTXS;
  575. }
  576. static unsigned _starpu_worker_get_first_free_sched_ctx(struct _starpu_worker *worker)
  577. {
  578. unsigned i;
  579. for(i = 0; i < STARPU_NMAX_SCHED_CTXS; i++)
  580. if(worker->sched_ctx[i] == NULL)
  581. return i;
  582. STARPU_ASSERT(0);
  583. return STARPU_NMAX_SCHED_CTXS;
  584. }
  585. static unsigned _starpu_worker_get_sched_ctx_id(struct _starpu_worker *worker, unsigned sched_ctx_id)
  586. {
  587. unsigned to_be_deleted = STARPU_NMAX_SCHED_CTXS;
  588. unsigned i;
  589. for(i = 0; i < STARPU_NMAX_SCHED_CTXS; i++)
  590. {
  591. if(worker->sched_ctx[i] != NULL)
  592. {
  593. if(worker->sched_ctx[i]->id == sched_ctx_id)
  594. return i;
  595. else if(worker->sched_ctx[i]->id == STARPU_NMAX_SCHED_CTXS)
  596. to_be_deleted = i;
  597. }
  598. }
  599. return to_be_deleted;
  600. }
  601. int _starpu_wait_for_all_tasks_of_sched_ctx(unsigned sched_ctx_id)
  602. {
  603. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
  604. if (STARPU_UNLIKELY(!_starpu_worker_may_perform_blocking_calls()))
  605. return -EDEADLK;
  606. return _starpu_barrier_counter_wait_for_empty_counter(&sched_ctx->tasks_barrier);
  607. }
  608. void _starpu_decrement_nsubmitted_tasks_of_sched_ctx(unsigned sched_ctx_id)
  609. {
  610. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
  611. int finished = _starpu_barrier_counter_decrement_until_empty_counter(&sched_ctx->tasks_barrier);
  612. /*when finished decrementing the tasks if the user signaled he will not submit tasks anymore
  613. we can move all its workers to the inheritor context */
  614. if(finished && sched_ctx->inheritor != STARPU_NMAX_SCHED_CTXS)
  615. {
  616. STARPU_PTHREAD_MUTEX_LOCK(&finished_submit_mutex);
  617. if(sched_ctx->finished_submit)
  618. {
  619. STARPU_PTHREAD_MUTEX_UNLOCK(&finished_submit_mutex);
  620. /* take care the context is not deleted or changed at the same time */
  621. STARPU_PTHREAD_MUTEX_LOCK(&changing_ctx_mutex[sched_ctx_id]);
  622. if(sched_ctx->id != STARPU_NMAX_SCHED_CTXS)
  623. {
  624. int *workerids = NULL;
  625. unsigned nworkers = _get_workers_list(sched_ctx, &workerids);
  626. if(nworkers > 0)
  627. {
  628. starpu_sched_ctx_add_workers(workerids, nworkers, sched_ctx->inheritor);
  629. free(workerids);
  630. }
  631. }
  632. STARPU_PTHREAD_MUTEX_UNLOCK(&changing_ctx_mutex[sched_ctx_id]);
  633. return;
  634. }
  635. STARPU_PTHREAD_MUTEX_UNLOCK(&finished_submit_mutex);
  636. }
  637. return;
  638. }
  639. void _starpu_increment_nsubmitted_tasks_of_sched_ctx(unsigned sched_ctx_id)
  640. {
  641. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
  642. _starpu_barrier_counter_increment(&sched_ctx->tasks_barrier);
  643. }
  644. void starpu_sched_ctx_set_context(unsigned *sched_ctx)
  645. {
  646. starpu_pthread_setspecific(sched_ctx_key, (void*)sched_ctx);
  647. }
  648. unsigned starpu_sched_ctx_get_context()
  649. {
  650. unsigned *sched_ctx = (unsigned*)starpu_pthread_getspecific(sched_ctx_key);
  651. if(sched_ctx == NULL)
  652. return STARPU_NMAX_SCHED_CTXS;
  653. STARPU_ASSERT(*sched_ctx < STARPU_NMAX_SCHED_CTXS);
  654. return *sched_ctx;
  655. }
  656. void starpu_sched_ctx_notify_hypervisor_exists()
  657. {
  658. with_hypervisor = 1;
  659. }
  660. unsigned starpu_sched_ctx_check_if_hypervisor_exists()
  661. {
  662. return with_hypervisor;
  663. }
  664. unsigned _starpu_get_nsched_ctxs()
  665. {
  666. struct _starpu_machine_config *config = (struct _starpu_machine_config *)_starpu_get_machine_config();
  667. return config->topology.nsched_ctxs;
  668. }
  669. void starpu_sched_ctx_set_policy_data(unsigned sched_ctx_id, void* policy_data)
  670. {
  671. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
  672. sched_ctx->policy_data = policy_data;
  673. }
  674. void* starpu_sched_ctx_get_policy_data(unsigned sched_ctx_id)
  675. {
  676. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
  677. return sched_ctx->policy_data;
  678. }
  679. struct starpu_worker_collection* starpu_sched_ctx_create_worker_collection(unsigned sched_ctx_id, int worker_collection_type)
  680. {
  681. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
  682. sched_ctx->workers = (struct starpu_worker_collection*)malloc(sizeof(struct starpu_worker_collection));
  683. switch(worker_collection_type)
  684. {
  685. case STARPU_WORKER_LIST:
  686. sched_ctx->workers->has_next = worker_list.has_next;
  687. sched_ctx->workers->get_next = worker_list.get_next;
  688. sched_ctx->workers->add = worker_list.add;
  689. sched_ctx->workers->remove = worker_list.remove;
  690. sched_ctx->workers->init = worker_list.init;
  691. sched_ctx->workers->deinit = worker_list.deinit;
  692. sched_ctx->workers->init_iterator = worker_list.init_iterator;
  693. sched_ctx->workers->type = STARPU_WORKER_LIST;
  694. break;
  695. }
  696. return sched_ctx->workers;
  697. }
  698. static unsigned _get_workers_list(struct _starpu_sched_ctx *sched_ctx, int **workerids)
  699. {
  700. struct starpu_worker_collection *workers = sched_ctx->workers;
  701. *workerids = (int*)malloc(workers->nworkers*sizeof(int));
  702. int worker;
  703. unsigned nworkers = 0;
  704. struct starpu_sched_ctx_iterator it;
  705. if(workers->init_iterator)
  706. workers->init_iterator(workers, &it);
  707. while(workers->has_next(workers, &it))
  708. {
  709. worker = workers->get_next(workers, &it);
  710. (*workerids)[nworkers++] = worker;
  711. }
  712. return nworkers;
  713. }
  714. void starpu_sched_ctx_delete_worker_collection(unsigned sched_ctx_id)
  715. {
  716. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
  717. sched_ctx->workers->deinit(sched_ctx->workers);
  718. free(sched_ctx->workers);
  719. }
  720. struct starpu_worker_collection* starpu_sched_ctx_get_worker_collection(unsigned sched_ctx_id)
  721. {
  722. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
  723. return sched_ctx->workers;
  724. }
  725. int starpu_get_workers_of_sched_ctx(unsigned sched_ctx_id, int *pus, enum starpu_archtype arch)
  726. {
  727. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
  728. struct starpu_worker_collection *workers = sched_ctx->workers;
  729. int worker;
  730. int npus = 0;
  731. struct starpu_sched_ctx_iterator it;
  732. if(workers->init_iterator)
  733. workers->init_iterator(workers, &it);
  734. while(workers->has_next(workers, &it))
  735. {
  736. worker = workers->get_next(workers, &it);
  737. enum starpu_archtype curr_arch = starpu_worker_get_type(worker);
  738. if(curr_arch == arch)
  739. pus[npus++] = worker;
  740. }
  741. return npus;
  742. }
  743. starpu_pthread_mutex_t* _starpu_sched_ctx_get_changing_ctx_mutex(unsigned sched_ctx_id)
  744. {
  745. return &changing_ctx_mutex[sched_ctx_id];
  746. }
  747. unsigned starpu_sched_ctx_get_nworkers(unsigned sched_ctx_id)
  748. {
  749. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
  750. if(sched_ctx != NULL)
  751. return sched_ctx->workers->nworkers;
  752. else
  753. return 0;
  754. }
  755. unsigned starpu_sched_ctx_get_nshared_workers(unsigned sched_ctx_id, unsigned sched_ctx_id2)
  756. {
  757. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
  758. struct _starpu_sched_ctx *sched_ctx2 = _starpu_get_sched_ctx_struct(sched_ctx_id2);
  759. struct starpu_worker_collection *workers = sched_ctx->workers;
  760. struct starpu_worker_collection *workers2 = sched_ctx2->workers;
  761. int worker, worker2;
  762. int shared_workers = 0;
  763. struct starpu_sched_ctx_iterator it1, it2;
  764. if(workers->init_iterator)
  765. workers->init_iterator(workers, &it1);
  766. if(workers2->init_iterator)
  767. workers2->init_iterator(workers2, &it2);
  768. while(workers->has_next(workers, &it1))
  769. {
  770. worker = workers->get_next(workers, &it1);
  771. while(workers2->has_next(workers2, &it2))
  772. {
  773. worker2 = workers2->get_next(workers2, &it2);
  774. if(worker == worker2)
  775. shared_workers++;
  776. }
  777. }
  778. return shared_workers;
  779. }
  780. unsigned starpu_sched_ctx_contains_worker(int workerid, unsigned sched_ctx_id)
  781. {
  782. /* struct _starpu_worker *worker = _starpu_get_worker_struct(workerid); */
  783. /* unsigned i; */
  784. /* for(i = 0; i < STARPU_NMAX_SCHED_CTXS; i++) */
  785. /* { */
  786. /* if(worker->sched_ctx[i] && worker->sched_ctx[i]->id == sched_ctx_id) */
  787. /* return 1; */
  788. /* } */
  789. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
  790. struct starpu_worker_collection *workers = sched_ctx->workers;
  791. int worker;
  792. struct starpu_sched_ctx_iterator it;
  793. if(workers->init_iterator)
  794. workers->init_iterator(workers, &it);
  795. while(workers->has_next(workers, &it))
  796. {
  797. worker = workers->get_next(workers, &it);
  798. if(worker == workerid)
  799. return 1;
  800. }
  801. return 0;
  802. }
  803. unsigned _starpu_worker_belongs_to_a_sched_ctx(int workerid, unsigned sched_ctx_id)
  804. {
  805. struct _starpu_machine_config *config = (struct _starpu_machine_config *)_starpu_get_machine_config();
  806. int i;
  807. struct _starpu_sched_ctx *sched_ctx = NULL;
  808. for(i = 0; i < STARPU_NMAX_SCHED_CTXS; i++)
  809. {
  810. sched_ctx = &config->sched_ctxs[i];
  811. if(sched_ctx && sched_ctx->id != STARPU_NMAX_SCHED_CTXS && sched_ctx->id != sched_ctx_id)
  812. if(starpu_sched_ctx_contains_worker(workerid, sched_ctx->id))
  813. return 1;
  814. }
  815. return 0;
  816. }
  817. unsigned starpu_sched_ctx_overlapping_ctxs_on_worker(int workerid)
  818. {
  819. struct _starpu_worker *worker = _starpu_get_worker_struct(workerid);
  820. return worker->nsched_ctxs > 1;
  821. }
  822. unsigned starpu_sched_ctx_is_ctxs_turn(int workerid, unsigned sched_ctx_id)
  823. {
  824. if(max_time_worker_on_ctx == -1.0) return 1;
  825. struct _starpu_worker *worker = _starpu_get_worker_struct(workerid);
  826. return worker->active_ctx == sched_ctx_id;
  827. }
  828. void starpu_sched_ctx_set_turn_to_other_ctx(int workerid, unsigned sched_ctx_id)
  829. {
  830. struct _starpu_worker *worker = _starpu_get_worker_struct(workerid);
  831. struct _starpu_sched_ctx *other_sched_ctx = NULL;
  832. struct _starpu_sched_ctx *active_sched_ctx = NULL;
  833. int i;
  834. for(i = 0; i < STARPU_NMAX_SCHED_CTXS; i++)
  835. {
  836. other_sched_ctx = worker->sched_ctx[i];
  837. if(other_sched_ctx != NULL && other_sched_ctx->id != STARPU_NMAX_SCHED_CTXS &&
  838. other_sched_ctx->id != 0 && other_sched_ctx->id != sched_ctx_id)
  839. {
  840. worker->active_ctx = other_sched_ctx->id;
  841. active_sched_ctx = other_sched_ctx;
  842. break;
  843. }
  844. }
  845. if(active_sched_ctx != NULL && worker->active_ctx != sched_ctx_id)
  846. {
  847. _starpu_fetch_tasks_from_empty_ctx_list(active_sched_ctx);
  848. }
  849. }
  850. double starpu_sched_ctx_get_max_time_worker_on_ctx(void)
  851. {
  852. return max_time_worker_on_ctx;
  853. }
  854. void starpu_sched_ctx_set_inheritor(unsigned sched_ctx_id, unsigned inheritor)
  855. {
  856. STARPU_ASSERT(inheritor < STARPU_NMAX_SCHED_CTXS);
  857. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
  858. sched_ctx->inheritor = inheritor;
  859. return;
  860. }
  861. void starpu_sched_ctx_finished_submit(unsigned sched_ctx_id)
  862. {
  863. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
  864. STARPU_PTHREAD_MUTEX_LOCK(&finished_submit_mutex);
  865. sched_ctx->finished_submit = 1;
  866. STARPU_PTHREAD_MUTEX_UNLOCK(&finished_submit_mutex);
  867. return;
  868. }
  869. #ifdef STARPU_USE_SC_HYPERVISOR
  870. void _starpu_sched_ctx_call_poped_task_cb(int workerid, struct starpu_task *task, size_t data_size, uint32_t footprint)
  871. {
  872. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(task->sched_ctx);
  873. if(sched_ctx != NULL && task->sched_ctx != _starpu_get_initial_sched_ctx()->id && task->sched_ctx != STARPU_NMAX_SCHED_CTXS
  874. && sched_ctx->perf_counters != NULL)
  875. sched_ctx->perf_counters->notify_poped_task(task->sched_ctx, workerid, task, data_size, footprint);
  876. }
  877. void starpu_sched_ctx_call_pushed_task_cb(int workerid, unsigned sched_ctx_id)
  878. {
  879. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
  880. if(sched_ctx != NULL && sched_ctx_id != _starpu_get_initial_sched_ctx()->id && sched_ctx_id != STARPU_NMAX_SCHED_CTXS
  881. && sched_ctx->perf_counters != NULL)
  882. sched_ctx->perf_counters->notify_pushed_task(sched_ctx_id, workerid);
  883. }
  884. #endif //STARPU_USE_SC_HYPERVISOR
  885. int starpu_sched_get_min_priority(void)
  886. {
  887. return starpu_sched_ctx_get_min_priority(_starpu_get_initial_sched_ctx()->id);
  888. }
  889. int starpu_sched_get_max_priority(void)
  890. {
  891. return starpu_sched_ctx_get_max_priority(_starpu_get_initial_sched_ctx()->id);
  892. }
  893. int starpu_sched_set_min_priority(int min_prio)
  894. {
  895. return starpu_sched_ctx_set_min_priority(_starpu_get_initial_sched_ctx()->id, min_prio);
  896. }
  897. int starpu_sched_set_max_priority(int max_prio)
  898. {
  899. return starpu_sched_ctx_set_max_priority(_starpu_get_initial_sched_ctx()->id, max_prio);
  900. }
  901. int starpu_sched_ctx_get_min_priority(unsigned sched_ctx_id)
  902. {
  903. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
  904. return sched_ctx->min_priority;
  905. }
  906. int starpu_sched_ctx_get_max_priority(unsigned sched_ctx_id)
  907. {
  908. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
  909. return sched_ctx->max_priority;
  910. }
  911. int starpu_sched_ctx_set_min_priority(unsigned sched_ctx_id, int min_prio)
  912. {
  913. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
  914. sched_ctx->min_priority = min_prio;
  915. return 0;
  916. }
  917. int starpu_sched_ctx_set_max_priority(unsigned sched_ctx_id, int max_prio)
  918. {
  919. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
  920. sched_ctx->max_priority = max_prio;
  921. return 0;
  922. }