sched_policy.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2016 Université de Bordeaux
  4. * Copyright (C) 2010-2017 CNRS
  5. * Copyright (C) 2011, 2016 INRIA
  6. * Copyright (C) 2016 Uppsala University
  7. *
  8. * StarPU is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU Lesser General Public License as published by
  10. * the Free Software Foundation; either version 2.1 of the License, or (at
  11. * your option) any later version.
  12. *
  13. * StarPU is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16. *
  17. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  18. */
  19. #include <starpu.h>
  20. #include <common/config.h>
  21. #include <common/utils.h>
  22. #include <core/sched_policy.h>
  23. #include <profiling/profiling.h>
  24. #include <common/barrier.h>
  25. #include <core/debug.h>
  26. static int use_prefetch = 0;
  27. static double idle[STARPU_NMAXWORKERS];
  28. static double idle_start[STARPU_NMAXWORKERS];
  29. long _starpu_task_break_on_push = -1;
  30. long _starpu_task_break_on_pop = -1;
  31. long _starpu_task_break_on_sched = -1;
  32. static const char *starpu_idle_file;
  33. void _starpu_sched_init(void)
  34. {
  35. _starpu_task_break_on_push = starpu_get_env_number_default("STARPU_TASK_BREAK_ON_PUSH", -1);
  36. _starpu_task_break_on_pop = starpu_get_env_number_default("STARPU_TASK_BREAK_ON_POP", -1);
  37. _starpu_task_break_on_sched = starpu_get_env_number_default("STARPU_TASK_BREAK_ON_SCHED", -1);
  38. starpu_idle_file = starpu_getenv("STARPU_IDLE_FILE");
  39. }
  40. int starpu_get_prefetch_flag(void)
  41. {
  42. return use_prefetch;
  43. }
  44. static struct starpu_sched_policy *predefined_policies[] =
  45. {
  46. &_starpu_sched_modular_eager_policy,
  47. &_starpu_sched_modular_eager_prefetching_policy,
  48. &_starpu_sched_modular_prio_policy,
  49. &_starpu_sched_modular_prio_prefetching_policy,
  50. &_starpu_sched_modular_random_policy,
  51. &_starpu_sched_modular_random_prio_policy,
  52. &_starpu_sched_modular_random_prefetching_policy,
  53. &_starpu_sched_modular_random_prio_prefetching_policy,
  54. &_starpu_sched_modular_ws_policy,
  55. &_starpu_sched_modular_heft_policy,
  56. &_starpu_sched_modular_heft2_policy,
  57. &_starpu_sched_eager_policy,
  58. &_starpu_sched_prio_policy,
  59. &_starpu_sched_random_policy,
  60. &_starpu_sched_lws_policy,
  61. &_starpu_sched_ws_policy,
  62. &_starpu_sched_dm_policy,
  63. &_starpu_sched_dmda_policy,
  64. &_starpu_sched_dmda_ready_policy,
  65. &_starpu_sched_dmda_sorted_policy,
  66. &_starpu_sched_dmda_sorted_decision_policy,
  67. &_starpu_sched_parallel_heft_policy,
  68. &_starpu_sched_peager_policy,
  69. &_starpu_sched_heteroprio_policy,
  70. &_starpu_sched_graph_test_policy,
  71. NULL
  72. };
  73. struct starpu_sched_policy **starpu_sched_get_predefined_policies()
  74. {
  75. return predefined_policies;
  76. }
  77. struct starpu_sched_policy *_starpu_get_sched_policy(struct _starpu_sched_ctx *sched_ctx)
  78. {
  79. return sched_ctx->sched_policy;
  80. }
  81. void starpu_sched_policy_set_post_exec_hook(void (*post_exec_hook)(struct starpu_task *task, unsigned sched_ctx_id), const char *policy_name)
  82. {
  83. int i;
  84. struct _starpu_sched_ctx *sched_ctx;
  85. for(i = 0; i < STARPU_NMAX_SCHED_CTXS; i++)
  86. {
  87. sched_ctx = _starpu_get_sched_ctx_struct(i);
  88. if (sched_ctx && sched_ctx->sched_policy)
  89. sched_ctx->sched_policy->post_exec_hook = post_exec_hook;
  90. else
  91. break;
  92. }
  93. }
  94. /*
  95. * Methods to initialize the scheduling policy
  96. */
  97. static void load_sched_policy(struct starpu_sched_policy *sched_policy, struct _starpu_sched_ctx *sched_ctx)
  98. {
  99. STARPU_ASSERT(sched_policy);
  100. #ifdef STARPU_VERBOSE
  101. if (sched_policy->policy_name)
  102. {
  103. if (sched_policy->policy_description)
  104. _STARPU_DEBUG("Use %s scheduler (%s)\n", sched_policy->policy_name, sched_policy->policy_description);
  105. else
  106. _STARPU_DEBUG("Use %s scheduler \n", sched_policy->policy_name);
  107. }
  108. #endif
  109. struct starpu_sched_policy *policy = sched_ctx->sched_policy;
  110. memcpy(policy, sched_policy, sizeof(*policy));
  111. }
  112. static struct starpu_sched_policy *find_sched_policy_from_name(const char *policy_name)
  113. {
  114. if (!policy_name)
  115. return NULL;
  116. if (strcmp(policy_name, "") == 0)
  117. return NULL;
  118. if (strncmp(policy_name, "heft", 4) == 0)
  119. {
  120. _STARPU_MSG("Warning: heft is now called \"dmda\".\n");
  121. return &_starpu_sched_dmda_policy;
  122. }
  123. struct starpu_sched_policy **policy;
  124. for(policy=predefined_policies ; *policy!=NULL ; policy++)
  125. {
  126. struct starpu_sched_policy *p = *policy;
  127. if (p->policy_name)
  128. {
  129. if (strcmp(policy_name, p->policy_name) == 0)
  130. {
  131. /* we found a policy with the requested name */
  132. return p;
  133. }
  134. }
  135. }
  136. if (strcmp(policy_name, "help") != 0)
  137. _STARPU_MSG("Warning: scheduling policy '%s' was not found, try 'help' to get a list\n", policy_name);
  138. /* nothing was found */
  139. return NULL;
  140. }
  141. static void display_sched_help_message(FILE *stream)
  142. {
  143. const char *sched_env = starpu_getenv("STARPU_SCHED");
  144. if (sched_env && (strcmp(sched_env, "help") == 0))
  145. {
  146. /* display the description of all predefined policies */
  147. struct starpu_sched_policy **policy;
  148. fprintf(stream, "\nThe variable STARPU_SCHED can be set to one of the following strings:\n");
  149. for(policy=predefined_policies ; *policy!=NULL ; policy++)
  150. {
  151. struct starpu_sched_policy *p = *policy;
  152. fprintf(stream, "%-30s\t-> %s\n", p->policy_name, p->policy_description);
  153. }
  154. fprintf(stream, "\n");
  155. }
  156. }
  157. struct starpu_sched_policy *_starpu_select_sched_policy(struct _starpu_machine_config *config, const char *required_policy)
  158. {
  159. struct starpu_sched_policy *selected_policy = NULL;
  160. struct starpu_conf *user_conf = &config->conf;
  161. if(required_policy)
  162. selected_policy = find_sched_policy_from_name(required_policy);
  163. /* If there is a policy that matches the required name, return it */
  164. if (selected_policy)
  165. return selected_policy;
  166. /* First, we check whether the application explicitely gave a scheduling policy or not */
  167. if (user_conf && (user_conf->sched_policy))
  168. return user_conf->sched_policy;
  169. /* Otherwise, we look if the application specified the name of a policy to load */
  170. const char *sched_pol_name;
  171. sched_pol_name = starpu_getenv("STARPU_SCHED");
  172. if (sched_pol_name == NULL && user_conf && user_conf->sched_policy_name)
  173. sched_pol_name = user_conf->sched_policy_name;
  174. if (sched_pol_name)
  175. selected_policy = find_sched_policy_from_name(sched_pol_name);
  176. /* If there is a policy that matches the name, return it */
  177. if (selected_policy)
  178. return selected_policy;
  179. /* If no policy was specified, we use the eager policy by default */
  180. return &_starpu_sched_eager_policy;
  181. }
  182. void _starpu_init_sched_policy(struct _starpu_machine_config *config, struct _starpu_sched_ctx *sched_ctx, struct starpu_sched_policy *selected_policy)
  183. {
  184. /* Perhaps we have to display some help */
  185. display_sched_help_message(stderr);
  186. /* Prefetch is activated by default */
  187. use_prefetch = starpu_get_env_number("STARPU_PREFETCH");
  188. if (use_prefetch == -1)
  189. use_prefetch = 1;
  190. /* Set calibrate flag */
  191. _starpu_set_calibrate_flag(config->conf.calibrate);
  192. load_sched_policy(selected_policy, sched_ctx);
  193. if (starpu_get_env_number_default("STARPU_WORKER_TREE", 0))
  194. {
  195. #ifdef STARPU_HAVE_HWLOC
  196. sched_ctx->sched_policy->worker_type = STARPU_WORKER_TREE;
  197. #else
  198. _STARPU_DISP("STARPU_WORKER_TREE ignored, please rebuild StarPU with hwloc support to enable it.");
  199. #endif
  200. }
  201. starpu_sched_ctx_create_worker_collection(sched_ctx->id,
  202. sched_ctx->sched_policy->worker_type);
  203. _STARPU_TRACE_WORKER_SCHEDULING_PUSH;
  204. sched_ctx->sched_policy->init_sched(sched_ctx->id);
  205. _STARPU_TRACE_WORKER_SCHEDULING_POP;
  206. }
  207. void _starpu_deinit_sched_policy(struct _starpu_sched_ctx *sched_ctx)
  208. {
  209. struct starpu_sched_policy *policy = sched_ctx->sched_policy;
  210. if (policy->deinit_sched)
  211. {
  212. _STARPU_TRACE_WORKER_SCHEDULING_PUSH;
  213. policy->deinit_sched(sched_ctx->id);
  214. _STARPU_TRACE_WORKER_SCHEDULING_POP;
  215. }
  216. starpu_sched_ctx_delete_worker_collection(sched_ctx->id);
  217. }
  218. void _starpu_sched_task_submit(struct starpu_task *task)
  219. {
  220. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(task->sched_ctx);
  221. if (!sched_ctx->sched_policy)
  222. return;
  223. if (!sched_ctx->sched_policy->submit_hook)
  224. return;
  225. _STARPU_TRACE_WORKER_SCHEDULING_PUSH;
  226. sched_ctx->sched_policy->submit_hook(task);
  227. _STARPU_TRACE_WORKER_SCHEDULING_POP;
  228. }
  229. void _starpu_sched_do_schedule(unsigned sched_ctx_id)
  230. {
  231. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
  232. if (!sched_ctx->sched_policy)
  233. return;
  234. if (!sched_ctx->sched_policy->do_schedule)
  235. return;
  236. _STARPU_TRACE_WORKER_SCHEDULING_PUSH;
  237. sched_ctx->sched_policy->do_schedule(sched_ctx_id);
  238. _STARPU_TRACE_WORKER_SCHEDULING_POP;
  239. }
  240. static void _starpu_push_task_on_specific_worker_notify_sched(struct starpu_task *task, struct _starpu_worker *worker, int workerid, int perf_workerid)
  241. {
  242. /* if we push a task on a specific worker, notify all the sched_ctxs the worker belongs to */
  243. struct _starpu_sched_ctx_list_iterator list_it;
  244. _starpu_sched_ctx_list_iterator_init(worker->sched_ctx_list, &list_it);
  245. while (_starpu_sched_ctx_list_iterator_has_next(&list_it))
  246. {
  247. struct _starpu_sched_ctx_elt *e = _starpu_sched_ctx_list_iterator_get_next(&list_it);
  248. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(e->sched_ctx);
  249. if (sched_ctx->sched_policy != NULL && sched_ctx->sched_policy->push_task_notify)
  250. {
  251. _STARPU_TRACE_WORKER_SCHEDULING_PUSH;
  252. sched_ctx->sched_policy->push_task_notify(task, workerid, perf_workerid, sched_ctx->id);
  253. _STARPU_TRACE_WORKER_SCHEDULING_POP;
  254. }
  255. }
  256. }
  257. /* Enqueue a task into the list of tasks explicitely attached to a worker. In
  258. * case workerid identifies a combined worker, a task will be enqueued into
  259. * each worker of the combination. */
  260. static int _starpu_push_task_on_specific_worker(struct starpu_task *task, int workerid)
  261. {
  262. int nbasic_workers = (int)starpu_worker_get_count();
  263. /* Is this a basic worker or a combined worker ? */
  264. int is_basic_worker = (workerid < nbasic_workers);
  265. unsigned memory_node;
  266. struct _starpu_worker *worker = NULL;
  267. struct _starpu_combined_worker *combined_worker = NULL;
  268. if (is_basic_worker)
  269. {
  270. worker = _starpu_get_worker_struct(workerid);
  271. memory_node = worker->memory_node;
  272. }
  273. else
  274. {
  275. combined_worker = _starpu_get_combined_worker_struct(workerid);
  276. memory_node = combined_worker->memory_node;
  277. }
  278. if (use_prefetch)
  279. starpu_prefetch_task_input_on_node(task, memory_node);
  280. if (is_basic_worker)
  281. _starpu_push_task_on_specific_worker_notify_sched(task, worker, workerid, workerid);
  282. else
  283. {
  284. /* Notify all workers of the combined worker */
  285. int worker_size = combined_worker->worker_size;
  286. int *combined_workerid = combined_worker->combined_workerid;
  287. int j;
  288. for (j = 0; j < worker_size; j++)
  289. {
  290. int subworkerid = combined_workerid[j];
  291. _starpu_push_task_on_specific_worker_notify_sched(task, _starpu_get_worker_struct(subworkerid), subworkerid, workerid);
  292. }
  293. }
  294. #ifdef STARPU_USE_SC_HYPERVISOR
  295. starpu_sched_ctx_call_pushed_task_cb(workerid, task->sched_ctx);
  296. #endif //STARPU_USE_SC_HYPERVISOR
  297. if (is_basic_worker)
  298. {
  299. unsigned node = starpu_worker_get_memory_node(workerid);
  300. if (_starpu_task_uses_multiformat_handles(task))
  301. {
  302. unsigned nbuffers = STARPU_TASK_GET_NBUFFERS(task);
  303. unsigned i;
  304. for (i = 0; i < nbuffers; i++)
  305. {
  306. struct starpu_task *conversion_task;
  307. starpu_data_handle_t handle;
  308. handle = STARPU_TASK_GET_HANDLE(task, i);
  309. if (!_starpu_handle_needs_conversion_task(handle, node))
  310. continue;
  311. conversion_task = _starpu_create_conversion_task(handle, node);
  312. conversion_task->mf_skip = 1;
  313. conversion_task->execute_on_a_specific_worker = 1;
  314. conversion_task->workerid = workerid;
  315. _starpu_task_submit_conversion_task(conversion_task, workerid);
  316. //_STARPU_DEBUG("Pushing a conversion task\n");
  317. }
  318. for (i = 0; i < nbuffers; i++)
  319. {
  320. starpu_data_handle_t handle = STARPU_TASK_GET_HANDLE(task, i);
  321. handle->mf_node = node;
  322. }
  323. }
  324. // if(task->sched_ctx != _starpu_get_initial_sched_ctx()->id)
  325. if(task->priority > 0)
  326. return _starpu_push_local_task(worker, task, 1);
  327. else
  328. return _starpu_push_local_task(worker, task, 0);
  329. }
  330. else
  331. {
  332. /* This is a combined worker so we create task aliases */
  333. int worker_size = combined_worker->worker_size;
  334. int *combined_workerid = combined_worker->combined_workerid;
  335. int ret = 0;
  336. struct _starpu_job *job = _starpu_get_job_associated_to_task(task);
  337. job->task_size = worker_size;
  338. job->combined_workerid = workerid;
  339. job->active_task_alias_count = 0;
  340. STARPU_PTHREAD_BARRIER_INIT(&job->before_work_barrier, NULL, worker_size);
  341. STARPU_PTHREAD_BARRIER_INIT(&job->after_work_barrier, NULL, worker_size);
  342. job->after_work_busy_barrier = worker_size;
  343. /* Note: we have to call that early, or else the task may have
  344. * disappeared already */
  345. starpu_push_task_end(task);
  346. int j;
  347. for (j = 0; j < worker_size; j++)
  348. {
  349. struct starpu_task *alias = starpu_task_dup(task);
  350. alias->destroy = 1;
  351. worker = _starpu_get_worker_struct(combined_workerid[j]);
  352. ret |= _starpu_push_local_task(worker, alias, 0);
  353. }
  354. return ret;
  355. }
  356. }
  357. /* the generic interface that call the proper underlying implementation */
  358. int _starpu_push_task(struct _starpu_job *j)
  359. {
  360. if(j->task->prologue_callback_func)
  361. j->task->prologue_callback_func(j->task->prologue_callback_arg);
  362. return _starpu_repush_task(j);
  363. }
  364. int _starpu_repush_task(struct _starpu_job *j)
  365. {
  366. struct starpu_task *task = j->task;
  367. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(task->sched_ctx);
  368. int ret;
  369. _STARPU_LOG_IN();
  370. unsigned can_push = _starpu_increment_nready_tasks_of_sched_ctx(task->sched_ctx, task->flops, task);
  371. task->status = STARPU_TASK_READY;
  372. STARPU_AYU_ADDTOTASKQUEUE(j->job_id, -1);
  373. /* if the context does not have any workers save the tasks in a temp list */
  374. if(!sched_ctx->is_initial_sched)
  375. {
  376. /*if there are workers in the ctx that are not able to execute tasks
  377. we consider the ctx empty */
  378. unsigned nworkers = _starpu_nworkers_able_to_execute_task(task, sched_ctx);
  379. if(nworkers == 0)
  380. {
  381. STARPU_PTHREAD_MUTEX_LOCK(&sched_ctx->empty_ctx_mutex);
  382. starpu_task_list_push_front(&sched_ctx->empty_ctx_tasks, task);
  383. STARPU_PTHREAD_MUTEX_UNLOCK(&sched_ctx->empty_ctx_mutex);
  384. #ifdef STARPU_USE_SC_HYPERVISOR
  385. if(sched_ctx->id != 0 && sched_ctx->perf_counters != NULL
  386. && sched_ctx->perf_counters->notify_empty_ctx)
  387. {
  388. _STARPU_TRACE_HYPERVISOR_BEGIN();
  389. sched_ctx->perf_counters->notify_empty_ctx(sched_ctx->id, task);
  390. _STARPU_TRACE_HYPERVISOR_END();
  391. }
  392. #endif
  393. return 0;
  394. }
  395. }
  396. if(!can_push)
  397. return 0;
  398. /* in case there is no codelet associated to the task (that's a control
  399. * task), we directly execute its callback and enforce the
  400. * corresponding dependencies */
  401. if (task->cl == NULL || task->cl->where == STARPU_NOWHERE)
  402. {
  403. if (task->prologue_callback_pop_func)
  404. task->prologue_callback_pop_func(task->prologue_callback_pop_arg);
  405. if (task->cl && task->cl->specific_nodes)
  406. {
  407. /* Nothing to do, but we are asked to fetch data on some memory nodes */
  408. _starpu_fetch_nowhere_task_input(j);
  409. }
  410. else
  411. {
  412. if (task->cl)
  413. __starpu_push_task_output(j);
  414. _starpu_handle_job_termination(j);
  415. _STARPU_LOG_OUT_TAG("handle_job_termination");
  416. }
  417. return 0;
  418. }
  419. ret = _starpu_push_task_to_workers(task);
  420. if (ret == -EAGAIN)
  421. /* pushed to empty context, that's fine */
  422. ret = 0;
  423. return ret;
  424. }
  425. int _starpu_push_task_to_workers(struct starpu_task *task)
  426. {
  427. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(task->sched_ctx);
  428. unsigned nworkers = 0;
  429. _STARPU_TRACE_JOB_PUSH(task, task->priority > 0);
  430. /* if the contexts still does not have workers put the task back to its place in
  431. the empty ctx list */
  432. if(!sched_ctx->is_initial_sched)
  433. {
  434. /*if there are workers in the ctx that are not able to execute tasks
  435. we consider the ctx empty */
  436. nworkers = _starpu_nworkers_able_to_execute_task(task, sched_ctx);
  437. if (nworkers == 0)
  438. {
  439. STARPU_PTHREAD_MUTEX_LOCK(&sched_ctx->empty_ctx_mutex);
  440. starpu_task_list_push_back(&sched_ctx->empty_ctx_tasks, task);
  441. STARPU_PTHREAD_MUTEX_UNLOCK(&sched_ctx->empty_ctx_mutex);
  442. #ifdef STARPU_USE_SC_HYPERVISOR
  443. if(sched_ctx->id != 0 && sched_ctx->perf_counters != NULL
  444. && sched_ctx->perf_counters->notify_empty_ctx)
  445. {
  446. _STARPU_TRACE_HYPERVISOR_BEGIN();
  447. sched_ctx->perf_counters->notify_empty_ctx(sched_ctx->id, task);
  448. _STARPU_TRACE_HYPERVISOR_END();
  449. }
  450. #endif
  451. return -EAGAIN;
  452. }
  453. }
  454. _starpu_profiling_set_task_push_start_time(task);
  455. int ret = 0;
  456. if (STARPU_UNLIKELY(task->execute_on_a_specific_worker))
  457. {
  458. unsigned node = starpu_worker_get_memory_node(task->workerid);
  459. if (starpu_get_prefetch_flag())
  460. starpu_prefetch_task_input_on_node(task, node);
  461. ret = _starpu_push_task_on_specific_worker(task, task->workerid);
  462. }
  463. else
  464. {
  465. struct _starpu_machine_config *config = _starpu_get_machine_config();
  466. /* When a task can only be executed on a given arch and we have
  467. * only one memory node for that arch, we can systematically
  468. * prefetch before the scheduling decision. */
  469. if (starpu_get_prefetch_flag())
  470. {
  471. if (task->cl->where == STARPU_CPU && config->cpus_nodeid >= 0)
  472. starpu_prefetch_task_input_on_node(task, config->cpus_nodeid);
  473. else if (task->cl->where == STARPU_CUDA && config->cuda_nodeid >= 0)
  474. starpu_prefetch_task_input_on_node(task, config->cuda_nodeid);
  475. else if (task->cl->where == STARPU_OPENCL && config->opencl_nodeid >= 0)
  476. starpu_prefetch_task_input_on_node(task, config->opencl_nodeid);
  477. else if (task->cl->where == STARPU_MIC && config->mic_nodeid >= 0)
  478. starpu_prefetch_task_input_on_node(task, config->mic_nodeid);
  479. else if (task->cl->where == STARPU_SCC && config->scc_nodeid >= 0)
  480. starpu_prefetch_task_input_on_node(task, config->scc_nodeid);
  481. }
  482. if(!sched_ctx->sched_policy)
  483. {
  484. /* Note: we have to call that early, or else the task may have
  485. * disappeared already */
  486. starpu_push_task_end(task);
  487. if(!sched_ctx->awake_workers)
  488. ret = _starpu_push_task_on_specific_worker(task, sched_ctx->main_master);
  489. else
  490. {
  491. struct starpu_worker_collection *workers = sched_ctx->workers;
  492. struct _starpu_job *job = _starpu_get_job_associated_to_task(task);
  493. job->task_size = workers->nworkers;
  494. job->combined_workerid = -1; // workerid; its a ctx not combined worker
  495. job->active_task_alias_count = 0;
  496. STARPU_PTHREAD_BARRIER_INIT(&job->before_work_barrier, NULL, workers->nworkers);
  497. STARPU_PTHREAD_BARRIER_INIT(&job->after_work_barrier, NULL, workers->nworkers);
  498. job->after_work_busy_barrier = workers->nworkers;
  499. struct starpu_sched_ctx_iterator it;
  500. if(workers->init_iterator)
  501. workers->init_iterator(workers, &it);
  502. while(workers->has_next(workers, &it))
  503. {
  504. unsigned workerid = workers->get_next(workers, &it);
  505. struct starpu_task *alias = starpu_task_dup(task);
  506. alias->destroy = 1;
  507. ret |= _starpu_push_task_on_specific_worker(alias, workerid);
  508. }
  509. }
  510. }
  511. else
  512. {
  513. STARPU_ASSERT(sched_ctx->sched_policy->push_task);
  514. /* check out if there are any workers in the context */
  515. starpu_pthread_rwlock_t *changing_ctx_mutex = _starpu_sched_ctx_get_changing_ctx_mutex(sched_ctx->id);
  516. STARPU_PTHREAD_RWLOCK_RDLOCK(changing_ctx_mutex);
  517. nworkers = starpu_sched_ctx_get_nworkers(sched_ctx->id);
  518. if (nworkers == 0)
  519. ret = -1;
  520. else
  521. {
  522. _STARPU_TASK_BREAK_ON(task, push);
  523. _STARPU_TRACE_WORKER_SCHEDULING_PUSH;
  524. ret = sched_ctx->sched_policy->push_task(task);
  525. _STARPU_TRACE_WORKER_SCHEDULING_POP;
  526. }
  527. STARPU_PTHREAD_RWLOCK_UNLOCK(changing_ctx_mutex);
  528. }
  529. if(ret == -1)
  530. {
  531. _STARPU_MSG("repush task \n");
  532. _STARPU_TRACE_JOB_POP(task, task->priority > 0);
  533. ret = _starpu_push_task_to_workers(task);
  534. }
  535. }
  536. /* Note: from here, the task might have been destroyed already! */
  537. _STARPU_LOG_OUT();
  538. return ret;
  539. }
  540. /* This is called right after the scheduler has pushed a task to a queue
  541. * but just before releasing mutexes: we need the task to still be alive!
  542. */
  543. int starpu_push_task_end(struct starpu_task *task)
  544. {
  545. _starpu_profiling_set_task_push_end_time(task);
  546. task->scheduled = 1;
  547. return 0;
  548. }
  549. /* This is called right after the scheduler has pushed a task to a queue
  550. * but just before releasing mutexes: we need the task to still be alive!
  551. */
  552. int _starpu_pop_task_end(struct starpu_task *task)
  553. {
  554. if (!task)
  555. return 0;
  556. _STARPU_TRACE_JOB_POP(task, task->priority > 0);
  557. return 0;
  558. }
  559. /*
  560. * Given a handle that needs to be converted in order to be used on the given
  561. * node, returns a task that takes care of the conversion.
  562. */
  563. struct starpu_task *_starpu_create_conversion_task(starpu_data_handle_t handle,
  564. unsigned int node)
  565. {
  566. return _starpu_create_conversion_task_for_arch(handle, starpu_node_get_kind(node));
  567. }
  568. struct starpu_task *_starpu_create_conversion_task_for_arch(starpu_data_handle_t handle,
  569. enum starpu_node_kind node_kind)
  570. {
  571. struct starpu_task *conversion_task;
  572. #if defined(STARPU_USE_OPENCL) || defined(STARPU_USE_CUDA) || defined(STARPU_USE_MIC) || defined(STARPU_USE_SCC) || defined(STARPU_SIMGRID)
  573. struct starpu_multiformat_interface *format_interface;
  574. #endif
  575. conversion_task = starpu_task_create();
  576. conversion_task->name = "conversion_task";
  577. conversion_task->synchronous = 0;
  578. STARPU_TASK_SET_HANDLE(conversion_task, handle, 0);
  579. #if defined(STARPU_USE_OPENCL) || defined(STARPU_USE_CUDA) || defined(STARPU_USE_MIC) || defined(STARPU_USE_SCC) || defined(STARPU_SIMGRID)
  580. /* The node does not really matter here */
  581. format_interface = (struct starpu_multiformat_interface *) starpu_data_get_interface_on_node(handle, STARPU_MAIN_RAM);
  582. #endif
  583. _starpu_spin_lock(&handle->header_lock);
  584. handle->refcnt++;
  585. handle->busy_count++;
  586. _starpu_spin_unlock(&handle->header_lock);
  587. switch(node_kind)
  588. {
  589. case STARPU_CPU_RAM:
  590. case STARPU_SCC_RAM:
  591. case STARPU_SCC_SHM:
  592. switch (starpu_node_get_kind(handle->mf_node))
  593. {
  594. case STARPU_CPU_RAM:
  595. case STARPU_SCC_RAM:
  596. case STARPU_SCC_SHM:
  597. STARPU_ABORT();
  598. #if defined(STARPU_USE_CUDA) || defined(STARPU_SIMGRID)
  599. case STARPU_CUDA_RAM:
  600. {
  601. struct starpu_multiformat_data_interface_ops *mf_ops;
  602. mf_ops = (struct starpu_multiformat_data_interface_ops *) handle->ops->get_mf_ops(format_interface);
  603. conversion_task->cl = mf_ops->cuda_to_cpu_cl;
  604. break;
  605. }
  606. #endif
  607. #if defined(STARPU_USE_OPENCL) || defined(STARPU_SIMGRID)
  608. case STARPU_OPENCL_RAM:
  609. {
  610. struct starpu_multiformat_data_interface_ops *mf_ops;
  611. mf_ops = (struct starpu_multiformat_data_interface_ops *) handle->ops->get_mf_ops(format_interface);
  612. conversion_task->cl = mf_ops->opencl_to_cpu_cl;
  613. break;
  614. }
  615. #endif
  616. #ifdef STARPU_USE_MIC
  617. case STARPU_MIC_RAM:
  618. {
  619. struct starpu_multiformat_data_interface_ops *mf_ops;
  620. mf_ops = (struct starpu_multiformat_data_interface_ops *) handle->ops->get_mf_ops(format_interface);
  621. conversion_task->cl = mf_ops->mic_to_cpu_cl;
  622. break;
  623. }
  624. #endif
  625. default:
  626. _STARPU_ERROR("Oops : %u\n", handle->mf_node);
  627. }
  628. break;
  629. #if defined(STARPU_USE_CUDA) || defined(STARPU_SIMGRID)
  630. case STARPU_CUDA_RAM:
  631. {
  632. struct starpu_multiformat_data_interface_ops *mf_ops;
  633. mf_ops = (struct starpu_multiformat_data_interface_ops *) handle->ops->get_mf_ops(format_interface);
  634. conversion_task->cl = mf_ops->cpu_to_cuda_cl;
  635. break;
  636. }
  637. #endif
  638. #if defined(STARPU_USE_OPENCL) || defined(STARPU_SIMGRID)
  639. case STARPU_OPENCL_RAM:
  640. {
  641. struct starpu_multiformat_data_interface_ops *mf_ops;
  642. mf_ops = (struct starpu_multiformat_data_interface_ops *) handle->ops->get_mf_ops(format_interface);
  643. conversion_task->cl = mf_ops->cpu_to_opencl_cl;
  644. break;
  645. }
  646. #endif
  647. #ifdef STARPU_USE_MIC
  648. case STARPU_MIC_RAM:
  649. {
  650. struct starpu_multiformat_data_interface_ops *mf_ops;
  651. mf_ops = (struct starpu_multiformat_data_interface_ops *) handle->ops->get_mf_ops(format_interface);
  652. conversion_task->cl = mf_ops->cpu_to_mic_cl;
  653. break;
  654. }
  655. #endif
  656. default:
  657. STARPU_ABORT();
  658. }
  659. STARPU_TASK_SET_MODE(conversion_task, STARPU_RW, 0);
  660. return conversion_task;
  661. }
  662. static
  663. struct _starpu_sched_ctx* _get_next_sched_ctx_to_pop_into(struct _starpu_worker *worker)
  664. {
  665. struct _starpu_sched_ctx_elt *e = NULL;
  666. struct _starpu_sched_ctx_list_iterator list_it;
  667. int found = 0;
  668. _starpu_sched_ctx_list_iterator_init(worker->sched_ctx_list, &list_it);
  669. while (_starpu_sched_ctx_list_iterator_has_next(&list_it))
  670. {
  671. e = _starpu_sched_ctx_list_iterator_get_next(&list_it);
  672. if (e->task_number > 0)
  673. return _starpu_get_sched_ctx_struct(e->sched_ctx);
  674. }
  675. _starpu_sched_ctx_list_iterator_init(worker->sched_ctx_list, &list_it);
  676. while (_starpu_sched_ctx_list_iterator_has_next(&list_it))
  677. {
  678. e = _starpu_sched_ctx_list_iterator_get_next(&list_it);
  679. if (e->last_poped)
  680. {
  681. e->last_poped = 0;
  682. if (_starpu_sched_ctx_list_iterator_has_next(&list_it))
  683. {
  684. e = _starpu_sched_ctx_list_iterator_get_next(&list_it);
  685. found = 1;
  686. }
  687. break;
  688. }
  689. }
  690. if (!found)
  691. e = worker->sched_ctx_list->head;
  692. e->last_poped = 1;
  693. return _starpu_get_sched_ctx_struct(e->sched_ctx);
  694. }
  695. struct starpu_task *_starpu_pop_task(struct _starpu_worker *worker)
  696. {
  697. struct starpu_task *task;
  698. int worker_id;
  699. unsigned node;
  700. /* We can't tell in advance which task will be picked up, so we measure
  701. * a timestamp, and will attribute it afterwards to the task. */
  702. int profiling = starpu_profiling_status_get();
  703. struct timespec pop_start_time;
  704. if (profiling)
  705. _starpu_clock_gettime(&pop_start_time);
  706. pick:
  707. /* perhaps there is some local task to be executed first */
  708. task = _starpu_pop_local_task(worker);
  709. if (task)
  710. _STARPU_TASK_BREAK_ON(task, pop);
  711. /* get tasks from the stacks of the strategy */
  712. if(!task)
  713. {
  714. struct _starpu_sched_ctx *sched_ctx ;
  715. #ifndef STARPU_NON_BLOCKING_DRIVERS
  716. int been_here[STARPU_NMAX_SCHED_CTXS];
  717. int i;
  718. for(i = 0; i < STARPU_NMAX_SCHED_CTXS; i++)
  719. been_here[i] = 0;
  720. while(!task)
  721. #endif
  722. {
  723. if(worker->nsched_ctxs == 1)
  724. sched_ctx = _starpu_get_initial_sched_ctx();
  725. else
  726. {
  727. while(1)
  728. {
  729. /** Caution
  730. * If you use multiple contexts your scheduler *needs*
  731. * to update the variable task_number of the ctx list.
  732. * In order to get the best performances.
  733. * This is done using functions :
  734. * starpu_sched_ctx_list_task_counters_increment...(...)
  735. * starpu_sched_ctx_list_task_counters_decrement...(...)
  736. **/
  737. sched_ctx = _get_next_sched_ctx_to_pop_into(worker);
  738. if(worker->removed_from_ctx[sched_ctx->id] == 1 && worker->shares_tasks_lists[sched_ctx->id] == 1)
  739. {
  740. _starpu_worker_gets_out_of_ctx(sched_ctx->id, worker);
  741. worker->removed_from_ctx[sched_ctx->id] = 0;
  742. sched_ctx = NULL;
  743. }
  744. else
  745. break;
  746. }
  747. }
  748. if(sched_ctx && sched_ctx->id != STARPU_NMAX_SCHED_CTXS)
  749. {
  750. if (sched_ctx->sched_policy && sched_ctx->sched_policy->pop_task)
  751. {
  752. /* Note: we do not push the scheduling state here, because
  753. * otherwise when a worker is idle, we'd keep
  754. * pushing/popping a scheduling state here, while what we
  755. * want to see in the trace is a permanent idle state. */
  756. task = sched_ctx->sched_policy->pop_task(sched_ctx->id);
  757. if (task)
  758. _STARPU_TASK_BREAK_ON(task, pop);
  759. _starpu_pop_task_end(task);
  760. }
  761. }
  762. if(!task)
  763. {
  764. /* it doesn't matter if it shares tasks list or not in the scheduler,
  765. if it does not have any task to pop just get it out of here */
  766. /* however if it shares a task list it will be removed as soon as he
  767. finishes this job (in handle_job_termination) */
  768. if(worker->removed_from_ctx[sched_ctx->id])
  769. {
  770. _starpu_worker_gets_out_of_ctx(sched_ctx->id, worker);
  771. worker->removed_from_ctx[sched_ctx->id] = 0;
  772. }
  773. #ifdef STARPU_USE_SC_HYPERVISOR
  774. if(worker->pop_ctx_priority)
  775. {
  776. struct starpu_sched_ctx_performance_counters *perf_counters = sched_ctx->perf_counters;
  777. if(sched_ctx->id != 0 && perf_counters != NULL && perf_counters->notify_idle_cycle && _starpu_sched_ctx_allow_hypervisor(sched_ctx->id))
  778. {
  779. // _STARPU_TRACE_HYPERVISOR_BEGIN();
  780. perf_counters->notify_idle_cycle(sched_ctx->id, worker->workerid, 1.0);
  781. // _STARPU_TRACE_HYPERVISOR_END();
  782. }
  783. }
  784. #endif //STARPU_USE_SC_HYPERVISOR
  785. #ifndef STARPU_NON_BLOCKING_DRIVERS
  786. if(been_here[sched_ctx->id] || worker->nsched_ctxs == 1)
  787. break;
  788. been_here[sched_ctx->id] = 1;
  789. #endif
  790. }
  791. }
  792. }
  793. if (!task)
  794. {
  795. if (starpu_idle_file)
  796. idle_start[worker->workerid] = starpu_timing_now();
  797. return NULL;
  798. }
  799. if(starpu_idle_file && idle_start[worker->workerid] != 0.0)
  800. {
  801. double idle_end = starpu_timing_now();
  802. idle[worker->workerid] += (idle_end - idle_start[worker->workerid]);
  803. idle_start[worker->workerid] = 0.0;
  804. }
  805. #ifdef STARPU_USE_SC_HYPERVISOR
  806. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(task->sched_ctx);
  807. struct starpu_sched_ctx_performance_counters *perf_counters = sched_ctx->perf_counters;
  808. if(sched_ctx->id != 0 && perf_counters != NULL && perf_counters->notify_poped_task && _starpu_sched_ctx_allow_hypervisor(sched_ctx->id))
  809. {
  810. // _STARPU_TRACE_HYPERVISOR_BEGIN();
  811. perf_counters->notify_poped_task(task->sched_ctx, worker->workerid);
  812. // _STARPU_TRACE_HYPERVISOR_END();
  813. }
  814. #endif //STARPU_USE_SC_HYPERVISOR
  815. /* Make sure we do not bother with all the multiformat-specific code if
  816. * it is not necessary. */
  817. if (!_starpu_task_uses_multiformat_handles(task))
  818. goto profiling;
  819. /* This is either a conversion task, or a regular task for which the
  820. * conversion tasks have already been created and submitted */
  821. if (task->mf_skip)
  822. goto profiling;
  823. /*
  824. * This worker may not be able to execute this task. In this case, we
  825. * should return the task anyway. It will be pushed back almost immediatly.
  826. * This way, we avoid computing and executing the conversions tasks.
  827. * Here, we do not care about what implementation is used.
  828. */
  829. worker_id = starpu_worker_get_id_check();
  830. if (!starpu_worker_can_execute_task_first_impl(worker_id, task, NULL))
  831. return task;
  832. node = starpu_worker_get_memory_node(worker_id);
  833. /*
  834. * We do have a task that uses multiformat handles. Let's create the
  835. * required conversion tasks.
  836. */
  837. STARPU_PTHREAD_MUTEX_UNLOCK_SCHED(&worker->sched_mutex);
  838. unsigned i;
  839. unsigned nbuffers = STARPU_TASK_GET_NBUFFERS(task);
  840. for (i = 0; i < nbuffers; i++)
  841. {
  842. struct starpu_task *conversion_task;
  843. starpu_data_handle_t handle;
  844. handle = STARPU_TASK_GET_HANDLE(task, i);
  845. if (!_starpu_handle_needs_conversion_task(handle, node))
  846. continue;
  847. conversion_task = _starpu_create_conversion_task(handle, node);
  848. conversion_task->mf_skip = 1;
  849. conversion_task->execute_on_a_specific_worker = 1;
  850. conversion_task->workerid = worker_id;
  851. /*
  852. * Next tasks will need to know where these handles have gone.
  853. */
  854. handle->mf_node = node;
  855. _starpu_task_submit_conversion_task(conversion_task, worker_id);
  856. }
  857. task->mf_skip = 1;
  858. starpu_task_list_push_back(&worker->local_tasks, task);
  859. STARPU_PTHREAD_MUTEX_LOCK_SCHED(&worker->sched_mutex);
  860. goto pick;
  861. profiling:
  862. if (profiling)
  863. {
  864. struct starpu_profiling_task_info *profiling_info;
  865. profiling_info = task->profiling_info;
  866. /* The task may have been created before profiling was enabled,
  867. * so we check if the profiling_info structure is available
  868. * even though we already tested if profiling is enabled. */
  869. if (profiling_info)
  870. {
  871. memcpy(&profiling_info->pop_start_time,
  872. &pop_start_time, sizeof(struct timespec));
  873. _starpu_clock_gettime(&profiling_info->pop_end_time);
  874. }
  875. }
  876. if(task->prologue_callback_pop_func)
  877. task->prologue_callback_pop_func(task->prologue_callback_pop_arg);
  878. return task;
  879. }
  880. struct starpu_task *_starpu_pop_every_task(struct _starpu_sched_ctx *sched_ctx)
  881. {
  882. struct starpu_task *task = NULL;
  883. if(sched_ctx->sched_policy)
  884. {
  885. STARPU_ASSERT(sched_ctx->sched_policy->pop_every_task);
  886. /* TODO set profiling info */
  887. if(sched_ctx->sched_policy->pop_every_task)
  888. {
  889. _STARPU_TRACE_WORKER_SCHEDULING_PUSH;
  890. task = sched_ctx->sched_policy->pop_every_task(sched_ctx->id);
  891. _STARPU_TRACE_WORKER_SCHEDULING_POP;
  892. }
  893. }
  894. return task;
  895. }
  896. void _starpu_sched_pre_exec_hook(struct starpu_task *task)
  897. {
  898. unsigned sched_ctx_id = starpu_sched_ctx_get_ctx_for_task(task);
  899. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
  900. if (sched_ctx->sched_policy && sched_ctx->sched_policy->pre_exec_hook)
  901. {
  902. _STARPU_TRACE_WORKER_SCHEDULING_PUSH;
  903. sched_ctx->sched_policy->pre_exec_hook(task, sched_ctx_id);
  904. _STARPU_TRACE_WORKER_SCHEDULING_POP;
  905. }
  906. if(!sched_ctx->sched_policy)
  907. {
  908. int workerid = starpu_worker_get_id();
  909. struct _starpu_worker *worker = _starpu_get_worker_struct(workerid);
  910. struct _starpu_sched_ctx *other_sched_ctx;
  911. struct _starpu_sched_ctx_elt *e = NULL;
  912. struct _starpu_sched_ctx_list_iterator list_it;
  913. _starpu_sched_ctx_list_iterator_init(worker->sched_ctx_list, &list_it);
  914. while (_starpu_sched_ctx_list_iterator_has_next(&list_it))
  915. {
  916. e = _starpu_sched_ctx_list_iterator_get_next(&list_it);
  917. other_sched_ctx = _starpu_get_sched_ctx_struct(e->sched_ctx);
  918. if (other_sched_ctx != sched_ctx &&
  919. other_sched_ctx->sched_policy != NULL &&
  920. other_sched_ctx->sched_policy->pre_exec_hook)
  921. {
  922. _STARPU_TRACE_WORKER_SCHEDULING_PUSH;
  923. other_sched_ctx->sched_policy->pre_exec_hook(task, other_sched_ctx->id);
  924. _STARPU_TRACE_WORKER_SCHEDULING_POP;
  925. }
  926. }
  927. }
  928. }
  929. void _starpu_sched_post_exec_hook(struct starpu_task *task)
  930. {
  931. unsigned sched_ctx_id = starpu_sched_ctx_get_ctx_for_task(task);
  932. struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
  933. if (sched_ctx->sched_policy && sched_ctx->sched_policy->post_exec_hook)
  934. {
  935. _STARPU_TRACE_WORKER_SCHEDULING_PUSH;
  936. sched_ctx->sched_policy->post_exec_hook(task, sched_ctx_id);
  937. _STARPU_TRACE_WORKER_SCHEDULING_POP;
  938. }
  939. if(!sched_ctx->sched_policy)
  940. {
  941. int workerid = starpu_worker_get_id();
  942. struct _starpu_worker *worker = _starpu_get_worker_struct(workerid);
  943. struct _starpu_sched_ctx *other_sched_ctx;
  944. struct _starpu_sched_ctx_elt *e = NULL;
  945. struct _starpu_sched_ctx_list_iterator list_it;
  946. _starpu_sched_ctx_list_iterator_init(worker->sched_ctx_list, &list_it);
  947. while (_starpu_sched_ctx_list_iterator_has_next(&list_it))
  948. {
  949. e = _starpu_sched_ctx_list_iterator_get_next(&list_it);
  950. other_sched_ctx = _starpu_get_sched_ctx_struct(e->sched_ctx);
  951. if (other_sched_ctx != sched_ctx &&
  952. other_sched_ctx->sched_policy != NULL &&
  953. other_sched_ctx->sched_policy->post_exec_hook)
  954. {
  955. _STARPU_TRACE_WORKER_SCHEDULING_PUSH;
  956. other_sched_ctx->sched_policy->post_exec_hook(task, other_sched_ctx->id);
  957. _STARPU_TRACE_WORKER_SCHEDULING_POP;
  958. }
  959. }
  960. }
  961. }
  962. void _starpu_wait_on_sched_event(void)
  963. {
  964. struct _starpu_worker *worker = _starpu_get_local_worker_key();
  965. STARPU_PTHREAD_MUTEX_LOCK_SCHED(&worker->sched_mutex);
  966. _starpu_handle_all_pending_node_data_requests(worker->memory_node);
  967. if (_starpu_machine_is_running())
  968. {
  969. #ifndef STARPU_NON_BLOCKING_DRIVERS
  970. STARPU_PTHREAD_COND_WAIT(&worker->sched_cond,
  971. &worker->sched_mutex);
  972. #endif
  973. }
  974. STARPU_PTHREAD_MUTEX_UNLOCK_SCHED(&worker->sched_mutex);
  975. }
  976. /* The scheduling policy may put tasks directly into a worker's local queue so
  977. * that it is not always necessary to create its own queue when the local queue
  978. * is sufficient. If "back" not null, the task is put at the back of the queue
  979. * where the worker will pop tasks first. Setting "back" to 0 therefore ensures
  980. * a FIFO ordering. */
  981. int starpu_push_local_task(int workerid, struct starpu_task *task, int prio)
  982. {
  983. struct _starpu_worker *worker = _starpu_get_worker_struct(workerid);
  984. return _starpu_push_local_task(worker, task, prio);
  985. }
  986. void _starpu_print_idle_time()
  987. {
  988. if(!starpu_idle_file)
  989. return;
  990. double all_idle = 0.0;
  991. int i = 0;
  992. for(i = 0; i < STARPU_NMAXWORKERS; i++)
  993. all_idle += idle[i];
  994. FILE *f;
  995. f = fopen(starpu_idle_file, "a");
  996. if (!f)
  997. {
  998. _STARPU_MSG("couldn't open %s: %s\n", starpu_idle_file, strerror(errno));
  999. }
  1000. else
  1001. {
  1002. fprintf(f, "%lf \n", all_idle);
  1003. fclose(f);
  1004. }
  1005. }