workers.h 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2017 Université de Bordeaux
  4. * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2016, 2017 CNRS
  5. * Copyright (C) 2011, 2016-2017 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. #ifndef __WORKERS_H__
  20. #define __WORKERS_H__
  21. #include <limits.h>
  22. #include <starpu.h>
  23. #include <common/config.h>
  24. #include <common/timing.h>
  25. #include <common/fxt.h>
  26. #include <common/thread.h>
  27. #include <core/jobs.h>
  28. #include <core/perfmodel/perfmodel.h>
  29. #include <core/sched_policy.h>
  30. #include <core/topology.h>
  31. #include <core/errorcheck.h>
  32. #include <core/sched_ctx.h>
  33. #include <core/sched_ctx_list.h>
  34. #ifdef STARPU_HAVE_HWLOC
  35. #include <hwloc.h>
  36. #endif
  37. #include <core/drivers.h>
  38. #include <drivers/cuda/driver_cuda.h>
  39. #include <drivers/opencl/driver_opencl.h>
  40. #ifdef STARPU_USE_MIC
  41. #include <drivers/mic/driver_mic_source.h>
  42. #endif /* STARPU_USE_MIC */
  43. #ifdef STARPU_USE_SCC
  44. #include <drivers/scc/driver_scc_source.h>
  45. #endif
  46. #ifdef STARPU_USE_MPI_MASTER_SLAVE
  47. #include <drivers/mpi/driver_mpi_source.h>
  48. #endif
  49. #include <drivers/cpu/driver_cpu.h>
  50. #include <datawizard/datawizard.h>
  51. #include <starpu_parameters.h>
  52. #define STARPU_MAX_PIPELINE 4
  53. enum initialization { UNINITIALIZED = 0, CHANGING, INITIALIZED };
  54. struct _starpu_ctx_change_list;
  55. /* This is initialized from in _starpu_worker_init */
  56. LIST_TYPE(_starpu_worker,
  57. struct _starpu_machine_config *config;
  58. starpu_pthread_mutex_t mutex;
  59. enum starpu_worker_archtype arch; /* what is the type of worker ? */
  60. uint32_t worker_mask; /* what is the type of worker ? */
  61. struct starpu_perfmodel_arch perf_arch; /* in case there are different models of the same arch */
  62. starpu_pthread_t worker_thread; /* the thread which runs the worker */
  63. unsigned devid; /* which cpu/gpu/etc is controlled by the worker ? */
  64. unsigned subworkerid; /* which sub-worker this one is for the cpu/gpu */
  65. int bindid; /* which cpu is the driver bound to ? (logical index) */
  66. int workerid; /* uniquely identify the worker among all processing units types */
  67. int combined_workerid; /* combined worker currently using this worker */
  68. int current_rank; /* current rank in case the worker is used in a parallel fashion */
  69. int worker_size; /* size of the worker in case we use a combined worker */
  70. starpu_pthread_cond_t started_cond; /* indicate when the worker is ready */
  71. starpu_pthread_cond_t ready_cond; /* indicate when the worker is ready */
  72. unsigned memory_node; /* which memory node is the worker associated with ? */
  73. /* condition variable used for passive waiting operations on worker
  74. * STARPU_PTHREAD_COND_BROADCAST must be used instead of STARPU_PTHREAD_COND_SIGNAL,
  75. * since the condition is shared for multiple purpose */
  76. starpu_pthread_cond_t sched_cond;
  77. starpu_pthread_mutex_t sched_mutex; /* mutex protecting sched_cond */
  78. unsigned state_relax_refcnt; /* mark scheduling sections where other workers can safely access the worker state */
  79. #ifdef STARPU_SPINLOCK_CHECK
  80. const char *relax_on_file;
  81. int relax_on_line;
  82. const char *relax_on_func;
  83. const char *relax_off_file;
  84. int relax_off_line;
  85. const char *relax_off_func;
  86. #endif
  87. unsigned state_sched_op_pending; /* a task pop is ongoing even though sched_mutex may temporarily be unlocked */
  88. unsigned state_changing_ctx_waiting; /* a thread is waiting for operations such as pop to complete before acquiring sched_mutex and modifying the worker ctx*/
  89. unsigned state_changing_ctx_notice; /* the worker ctx is about to change or being changed, wait for flag to be cleared before starting new scheduling operations */
  90. unsigned state_blocked_in_parallel; /* worker is currently blocked on a parallel section */
  91. unsigned state_blocked_in_parallel_observed; /* the blocked state of the worker has been observed by another worker during a relaxed section */
  92. unsigned state_block_in_parallel_req; /* a request for state transition from unblocked to blocked is pending */
  93. unsigned state_block_in_parallel_ack; /* a block request has been honored */
  94. unsigned state_unblock_in_parallel_req; /* a request for state transition from blocked to unblocked is pending */
  95. unsigned state_unblock_in_parallel_ack; /* an unblock request has been honored */
  96. /* cumulative blocking depth
  97. * - =0 worker unblocked
  98. * - >0 worker blocked
  99. * - transition from 0 to 1 triggers a block_req
  100. * - transition from 1 to 0 triggers a unblock_req
  101. */
  102. unsigned block_in_parallel_ref_count;
  103. /* list of deferred context changes
  104. *
  105. * when the current thread is a worker, _and_ this worker is in a
  106. * scheduling operation, new ctx changes are queued to this list for
  107. * subsequent processing once worker completes the ongoing scheduling
  108. * operation */
  109. struct _starpu_ctx_change_list ctx_change_list;
  110. struct starpu_task_list local_tasks; /* this queue contains tasks that have been explicitely submitted to that queue */
  111. struct starpu_task **local_ordered_tasks; /* this queue contains tasks that have been explicitely submitted to that queue with an explicit order */
  112. unsigned local_ordered_tasks_size; /* this records the size of local_ordered_tasks */
  113. unsigned current_ordered_task; /* this records the index (within local_ordered_tasks) of the next ordered task to be executed */
  114. unsigned current_ordered_task_order; /* this records the order of the next ordered task to be executed */
  115. struct starpu_task *current_task; /* task currently executed by this worker (non-pipelined version) */
  116. struct starpu_task *current_tasks[STARPU_MAX_PIPELINE]; /* tasks currently executed by this worker (pipelined version) */
  117. #ifdef STARPU_SIMGRID
  118. starpu_pthread_wait_t wait;
  119. #endif
  120. unsigned char first_task; /* Index of first task in the pipeline */
  121. unsigned char ntasks; /* number of tasks in the pipeline */
  122. unsigned char pipeline_length; /* number of tasks to be put in the pipeline */
  123. unsigned char pipeline_stuck; /* whether a task prevents us from pipelining */
  124. struct _starpu_worker_set *set; /* in case this worker belongs to a set */
  125. unsigned worker_is_running;
  126. unsigned worker_is_initialized;
  127. enum _starpu_worker_status status; /* what is the worker doing now ? (eg. CALLBACK) */
  128. unsigned state_keep_awake; /* !0 if a task has been pushed to the worker and the task has not yet been seen by the worker, the worker should no go to sleep before processing this task*/
  129. char name[64];
  130. char short_name[10];
  131. unsigned run_by_starpu; /* Is this run by StarPU or directly by the application ? */
  132. struct _starpu_driver_ops *driver_ops;
  133. struct _starpu_sched_ctx_list *sched_ctx_list;
  134. int tmp_sched_ctx;
  135. unsigned nsched_ctxs; /* the no of contexts a worker belongs to*/
  136. struct _starpu_barrier_counter tasks_barrier; /* wait for the tasks submitted */
  137. unsigned has_prev_init; /* had already been inited in another ctx */
  138. unsigned removed_from_ctx[STARPU_NMAX_SCHED_CTXS+1];
  139. unsigned spinning_backoff ; /* number of cycles to pause when spinning */
  140. unsigned nb_buffers_transferred; /* number of piece of data already send to worker */
  141. unsigned nb_buffers_totransfer; /* number of piece of data already send to worker */
  142. struct starpu_task *task_transferring; /* The buffers of this task are being sent */
  143. /* indicate whether the workers shares tasks lists with other workers*/
  144. /* in this case when removing him from a context it disapears instantly */
  145. unsigned shares_tasks_lists[STARPU_NMAX_SCHED_CTXS+1];
  146. /* boolean to chose the next ctx a worker will pop into */
  147. unsigned poped_in_ctx[STARPU_NMAX_SCHED_CTXS+1];
  148. /* boolean indicating at which moment we checked all ctxs and change phase for the booleab poped_in_ctx*/
  149. /* one for each of the 2 priorities*/
  150. unsigned reverse_phase[2];
  151. /* indicate which priority of ctx is currently active: the values are 0 or 1*/
  152. unsigned pop_ctx_priority;
  153. /* bool to indicate if the worker is slave in a ctx */
  154. unsigned is_slave_somewhere;
  155. struct _starpu_sched_ctx *stream_ctx;
  156. #ifdef __GLIBC__
  157. cpu_set_t cpu_set;
  158. #endif /* __GLIBC__ */
  159. #ifdef STARPU_HAVE_HWLOC
  160. hwloc_bitmap_t hwloc_cpu_set;
  161. #endif
  162. );
  163. struct _starpu_combined_worker
  164. {
  165. struct starpu_perfmodel_arch perf_arch; /* in case there are different models of the same arch */
  166. uint32_t worker_mask; /* what is the type of workers ? */
  167. int worker_size;
  168. unsigned memory_node; /* which memory node is associated that worker to ? */
  169. int combined_workerid[STARPU_NMAXWORKERS];
  170. #ifdef STARPU_USE_MP
  171. int count;
  172. starpu_pthread_mutex_t count_mutex;
  173. #endif
  174. #ifdef __GLIBC__
  175. cpu_set_t cpu_set;
  176. #endif /* __GLIBC__ */
  177. #ifdef STARPU_HAVE_HWLOC
  178. hwloc_bitmap_t hwloc_cpu_set;
  179. #endif
  180. };
  181. /* in case a single CPU worker may control multiple
  182. * accelerators (eg. Gordon for n SPUs) */
  183. struct _starpu_worker_set
  184. {
  185. starpu_pthread_mutex_t mutex;
  186. starpu_pthread_t worker_thread; /* the thread which runs the worker */
  187. unsigned nworkers;
  188. unsigned started; /* Only one thread for the whole set */
  189. void *retval;
  190. struct _starpu_worker *workers;
  191. starpu_pthread_cond_t ready_cond; /* indicate when the set is ready */
  192. unsigned set_is_initialized;
  193. };
  194. #ifdef STARPU_USE_MPI_MASTER_SLAVE
  195. extern struct _starpu_worker_set mpi_worker_set[STARPU_MAXMPIDEVS];
  196. #endif
  197. struct _starpu_machine_topology
  198. {
  199. /* Total number of workers. */
  200. unsigned nworkers;
  201. /* Total number of combined workers. */
  202. unsigned ncombinedworkers;
  203. unsigned nsched_ctxs;
  204. #ifdef STARPU_HAVE_HWLOC
  205. /* Topology as detected by hwloc. */
  206. hwloc_topology_t hwtopology;
  207. #endif
  208. /* custom hwloc tree*/
  209. struct starpu_tree *tree;
  210. /* Total number of CPUs, as detected by the topology code. May
  211. * be different from the actual number of CPU workers.
  212. */
  213. unsigned nhwcpus;
  214. /* Total number of PUs, as detected by the topology code. May
  215. * be different from the actual number of PU workers.
  216. */
  217. unsigned nhwpus;
  218. /* Total number of CUDA devices, as detected. May be different
  219. * from the actual number of CUDA workers.
  220. */
  221. unsigned nhwcudagpus;
  222. /* Total number of OpenCL devices, as detected. May be
  223. * different from the actual number of OpenCL workers.
  224. */
  225. unsigned nhwopenclgpus;
  226. /* Total number of SCC cores, as detected. May be different
  227. * from the actual number of core workers.
  228. */
  229. unsigned nhwscc;
  230. /* Total number of MPI nodes, as detected. May be different
  231. * from the actual number of node workers.
  232. */
  233. unsigned nhwmpi;
  234. /* Actual number of CPU workers used by StarPU. */
  235. unsigned ncpus;
  236. /* Actual number of CUDA GPUs used by StarPU. */
  237. unsigned ncudagpus;
  238. unsigned nworkerpercuda;
  239. int cuda_th_per_stream;
  240. int cuda_th_per_dev;
  241. /* Actual number of OpenCL workers used by StarPU. */
  242. unsigned nopenclgpus;
  243. /* Actual number of SCC workers used by StarPU. */
  244. unsigned nsccdevices;
  245. /* Actual number of MPI workers used by StarPU. */
  246. unsigned nmpidevices;
  247. unsigned nhwmpidevices;
  248. unsigned nhwmpicores[STARPU_MAXMPIDEVS]; // Each MPI node has its set of cores.
  249. unsigned nmpicores[STARPU_MAXMPIDEVS];
  250. /* Topology of MP nodes (mainly MIC and SCC) as well as necessary
  251. * objects to communicate with them. */
  252. unsigned nhwmicdevices;
  253. unsigned nmicdevices;
  254. unsigned nhwmiccores[STARPU_MAXMICDEVS]; // Each MIC node has its set of cores.
  255. unsigned nmiccores[STARPU_MAXMICDEVS];
  256. /* Indicates the successive logical PU identifier that should be used
  257. * to bind the workers. It is either filled according to the
  258. * user's explicit parameters (from starpu_conf) or according
  259. * to the STARPU_WORKERS_CPUID env. variable. Otherwise, a
  260. * round-robin policy is used to distributed the workers over
  261. * the cores.
  262. */
  263. unsigned workers_bindid[STARPU_NMAXWORKERS];
  264. /* Indicates the successive CUDA identifier that should be
  265. * used by the CUDA driver. It is either filled according to
  266. * the user's explicit parameters (from starpu_conf) or
  267. * according to the STARPU_WORKERS_CUDAID env. variable.
  268. * Otherwise, they are taken in ID order.
  269. */
  270. unsigned workers_cuda_gpuid[STARPU_NMAXWORKERS];
  271. /* Indicates the successive OpenCL identifier that should be
  272. * used by the OpenCL driver. It is either filled according
  273. * to the user's explicit parameters (from starpu_conf) or
  274. * according to the STARPU_WORKERS_OPENCLID env. variable.
  275. * Otherwise, they are taken in ID order.
  276. */
  277. unsigned workers_opencl_gpuid[STARPU_NMAXWORKERS];
  278. /** Indicates the successive MIC devices that should be used
  279. * by the MIC driver. It is either filled according to the
  280. * user's explicit parameters (from starpu_conf) or according
  281. * to the STARPU_WORKERS_MICID env. variable. Otherwise, they
  282. * are taken in ID order. */
  283. /* TODO */
  284. /* unsigned workers_mic_deviceid[STARPU_NMAXWORKERS]; */
  285. /* Which SCC(s) do we use ? */
  286. /* Indicates the successive SCC devices that should be used by
  287. * the SCC driver. It is either filled according to the
  288. * user's explicit parameters (from starpu_conf) or according
  289. * to the STARPU_WORKERS_SCCID env. variable. Otherwise, they
  290. * are taken in ID order.
  291. */
  292. unsigned workers_scc_deviceid[STARPU_NMAXWORKERS];
  293. unsigned workers_mpi_ms_deviceid[STARPU_NMAXWORKERS];
  294. };
  295. struct _starpu_machine_config
  296. {
  297. struct _starpu_machine_topology topology;
  298. #ifdef STARPU_HAVE_HWLOC
  299. int cpu_depth;
  300. int pu_depth;
  301. #endif
  302. /* Where to bind next worker ? */
  303. int current_bindid;
  304. char currently_bound[STARPU_NMAXWORKERS];
  305. /* Which GPU(s) do we use for CUDA ? */
  306. int current_cuda_gpuid;
  307. /* Which GPU(s) do we use for OpenCL ? */
  308. int current_opencl_gpuid;
  309. /* Which MIC do we use? */
  310. int current_mic_deviceid;
  311. /* Which SCC do we use? */
  312. int current_scc_deviceid;
  313. /* Which MPI do we use? */
  314. int current_mpi_deviceid;
  315. /* Memory node for cpus, if only one */
  316. int cpus_nodeid;
  317. /* Memory node for CUDA, if only one */
  318. int cuda_nodeid;
  319. /* Memory node for OpenCL, if only one */
  320. int opencl_nodeid;
  321. /* Memory node for MIC, if only one */
  322. int mic_nodeid;
  323. /* Memory node for SCC, if only one */
  324. int scc_nodeid;
  325. /* Memory node for MPI, if only one */
  326. int mpi_nodeid;
  327. /* Basic workers : each of this worker is running its own driver and
  328. * can be combined with other basic workers. */
  329. struct _starpu_worker workers[STARPU_NMAXWORKERS];
  330. /* Combined workers: these worker are a combination of basic workers
  331. * that can run parallel tasks together. */
  332. struct _starpu_combined_worker combined_workers[STARPU_NMAX_COMBINEDWORKERS];
  333. /* Translation table from bindid to worker IDs */
  334. struct {
  335. int *workerids;
  336. unsigned nworkers; /* size of workerids */
  337. } *bindid_workers;
  338. unsigned nbindid; /* size of bindid_workers */
  339. /* This bitmask indicates which kinds of worker are available. For
  340. * instance it is possible to test if there is a CUDA worker with
  341. * the result of (worker_mask & STARPU_CUDA). */
  342. uint32_t worker_mask;
  343. /* either the user given configuration passed to starpu_init or a default configuration */
  344. struct starpu_conf conf;
  345. /* this flag is set until the runtime is stopped */
  346. unsigned running;
  347. int disable_kernels;
  348. /* Number of calls to starpu_pause() - calls to starpu_resume(). When >0,
  349. * StarPU should pause. */
  350. int pause_depth;
  351. /* all the sched ctx of the current instance of starpu */
  352. struct _starpu_sched_ctx sched_ctxs[STARPU_NMAX_SCHED_CTXS+1];
  353. /* this flag is set until the application is finished submitting tasks */
  354. unsigned submitting;
  355. int watchdog_ok;
  356. starpu_pthread_mutex_t submitted_mutex;
  357. };
  358. extern struct _starpu_machine_config _starpu_config STARPU_ATTRIBUTE_INTERNAL;
  359. extern int _starpu_keys_initialized STARPU_ATTRIBUTE_INTERNAL;
  360. extern starpu_pthread_key_t _starpu_worker_key STARPU_ATTRIBUTE_INTERNAL;
  361. extern starpu_pthread_key_t _starpu_worker_set_key STARPU_ATTRIBUTE_INTERNAL;
  362. /* Three functions to manage argv, argc */
  363. void _starpu_set_argc_argv(int *argc, char ***argv);
  364. int *_starpu_get_argc();
  365. char ***_starpu_get_argv();
  366. /* Fill conf with environment variables */
  367. void _starpu_conf_check_environment(struct starpu_conf *conf);
  368. /* Called by the driver when it is ready to pause */
  369. void _starpu_may_pause(void);
  370. /* Has starpu_shutdown already been called ? */
  371. static inline unsigned _starpu_machine_is_running(void)
  372. {
  373. unsigned ret;
  374. /* running is just protected by a memory barrier */
  375. STARPU_RMB();
  376. ANNOTATE_HAPPENS_AFTER(&_starpu_config.running);
  377. ret = _starpu_config.running;
  378. ANNOTATE_HAPPENS_BEFORE(&_starpu_config.running);
  379. return ret;
  380. }
  381. /* Check if there is a worker that may execute the task. */
  382. uint32_t _starpu_worker_exists(struct starpu_task *);
  383. /* Is there a worker that can execute CUDA code ? */
  384. uint32_t _starpu_can_submit_cuda_task(void);
  385. /* Is there a worker that can execute CPU code ? */
  386. uint32_t _starpu_can_submit_cpu_task(void);
  387. /* Is there a worker that can execute OpenCL code ? */
  388. uint32_t _starpu_can_submit_opencl_task(void);
  389. /* Is there a worker that can execute OpenCL code ? */
  390. uint32_t _starpu_can_submit_scc_task(void);
  391. /* Check whether there is anything that the worker should do instead of
  392. * sleeping (waiting on something to happen). */
  393. unsigned _starpu_worker_can_block(unsigned memnode, struct _starpu_worker *worker);
  394. /* This function must be called to block a worker. It puts the worker in a
  395. * sleeping state until there is some event that forces the worker to wake up.
  396. * */
  397. void _starpu_block_worker(int workerid, starpu_pthread_cond_t *cond, starpu_pthread_mutex_t *mutex);
  398. /* This function initializes the current driver for the given worker */
  399. void _starpu_driver_start(struct _starpu_worker *worker, unsigned fut_key, unsigned sync);
  400. /* This function initializes the current thread for the given worker */
  401. void _starpu_worker_start(struct _starpu_worker *worker, unsigned fut_key, unsigned sync);
  402. static inline unsigned _starpu_worker_get_count(void)
  403. {
  404. return _starpu_config.topology.nworkers;
  405. }
  406. #define starpu_worker_get_count _starpu_worker_get_count
  407. /* The _starpu_worker structure describes all the state of a StarPU worker.
  408. * This function sets the pthread key which stores a pointer to this structure.
  409. * */
  410. static inline void _starpu_set_local_worker_key(struct _starpu_worker *worker)
  411. {
  412. STARPU_ASSERT(_starpu_keys_initialized);
  413. STARPU_PTHREAD_SETSPECIFIC(_starpu_worker_key, worker);
  414. }
  415. /* Returns the _starpu_worker structure that describes the state of the
  416. * current worker. */
  417. static inline struct _starpu_worker *_starpu_get_local_worker_key(void)
  418. {
  419. if (!_starpu_keys_initialized)
  420. return NULL;
  421. return (struct _starpu_worker *) STARPU_PTHREAD_GETSPECIFIC(_starpu_worker_key);
  422. }
  423. /* The _starpu_worker_set structure describes all the state of a StarPU worker_set.
  424. * This function sets the pthread key which stores a pointer to this structure.
  425. * */
  426. static inline void _starpu_set_local_worker_set_key(struct _starpu_worker_set *worker)
  427. {
  428. STARPU_ASSERT(_starpu_keys_initialized);
  429. STARPU_PTHREAD_SETSPECIFIC(_starpu_worker_set_key, worker);
  430. }
  431. /* Returns the _starpu_worker_set structure that describes the state of the
  432. * current worker_set. */
  433. static inline struct _starpu_worker_set *_starpu_get_local_worker_set_key(void)
  434. {
  435. if (!_starpu_keys_initialized)
  436. return NULL;
  437. return (struct _starpu_worker_set *) STARPU_PTHREAD_GETSPECIFIC(_starpu_worker_set_key);
  438. }
  439. /* Returns the _starpu_worker structure that describes the state of the
  440. * specified worker. */
  441. static inline struct _starpu_worker *_starpu_get_worker_struct(unsigned id)
  442. {
  443. STARPU_ASSERT(id < starpu_worker_get_count());
  444. return &_starpu_config.workers[id];
  445. }
  446. /* Returns the starpu_sched_ctx structure that describes the state of the
  447. * specified ctx */
  448. static inline struct _starpu_sched_ctx *_starpu_get_sched_ctx_struct(unsigned id)
  449. {
  450. if(id > STARPU_NMAX_SCHED_CTXS) return NULL;
  451. return &_starpu_config.sched_ctxs[id];
  452. }
  453. struct _starpu_combined_worker *_starpu_get_combined_worker_struct(unsigned id);
  454. /* Returns the structure that describes the overall machine configuration (eg.
  455. * all workers and topology). */
  456. static inline struct _starpu_machine_config *_starpu_get_machine_config(void)
  457. {
  458. return &_starpu_config;
  459. }
  460. /* Return whether kernels should be run (<=0) or not (>0) */
  461. static inline int _starpu_get_disable_kernels(void)
  462. {
  463. return _starpu_config.disable_kernels;
  464. }
  465. /* Retrieve the status which indicates what the worker is currently doing. */
  466. static inline enum _starpu_worker_status _starpu_worker_get_status(int workerid)
  467. {
  468. return _starpu_config.workers[workerid].status;
  469. }
  470. /* Change the status of the worker which indicates what the worker is currently
  471. * doing (eg. executing a callback). */
  472. static inline void _starpu_worker_set_status(int workerid, enum _starpu_worker_status status)
  473. {
  474. _starpu_config.workers[workerid].status = status;
  475. }
  476. /* We keep an initial sched ctx which might be used in case no other ctx is available */
  477. static inline struct _starpu_sched_ctx* _starpu_get_initial_sched_ctx(void)
  478. {
  479. return &_starpu_config.sched_ctxs[STARPU_GLOBAL_SCHED_CTX];
  480. }
  481. int starpu_worker_get_nids_by_type(enum starpu_worker_archtype type, int *workerids, int maxsize);
  482. /* returns workers not belonging to any context, be careful no mutex is used,
  483. the list might not be updated */
  484. int starpu_worker_get_nids_ctx_free_by_type(enum starpu_worker_archtype type, int *workerids, int maxsize);
  485. static inline unsigned _starpu_worker_mutex_is_sched_mutex(int workerid, starpu_pthread_mutex_t *mutex)
  486. {
  487. struct _starpu_worker *w = _starpu_get_worker_struct(workerid);
  488. return &w->sched_mutex == mutex;
  489. }
  490. static inline int _starpu_worker_get_nsched_ctxs(int workerid)
  491. {
  492. return _starpu_config.workers[workerid].nsched_ctxs;
  493. }
  494. /* Get the total number of sched_ctxs created till now */
  495. static inline unsigned _starpu_get_nsched_ctxs(void)
  496. {
  497. /* topology.nsched_ctxs may be increased asynchronously in sched_ctx_create */
  498. STARPU_RMB();
  499. return _starpu_config.topology.nsched_ctxs;
  500. }
  501. /* Inlined version when building the core. */
  502. static inline int _starpu_worker_get_id(void)
  503. {
  504. struct _starpu_worker * worker;
  505. worker = _starpu_get_local_worker_key();
  506. if (worker)
  507. {
  508. return worker->workerid;
  509. }
  510. else
  511. {
  512. /* there is no worker associated to that thread, perhaps it is
  513. * a thread from the application or this is some SPU worker */
  514. return -1;
  515. }
  516. }
  517. #define starpu_worker_get_id _starpu_worker_get_id
  518. /* Similar behaviour to starpu_worker_get_id() but fails when called from outside a worker */
  519. /* This returns an unsigned object on purpose, so that the caller is sure to get a positive value */
  520. static inline unsigned __starpu_worker_get_id_check(const char *f, int l)
  521. {
  522. (void) l;
  523. (void) f;
  524. int id = starpu_worker_get_id();
  525. STARPU_ASSERT_MSG(id>=0, "%s:%d Cannot be called from outside a worker\n", f, l);
  526. return id;
  527. }
  528. #define _starpu_worker_get_id_check(f,l) __starpu_worker_get_id_check(f,l)
  529. void _starpu_worker_set_stream_ctx(unsigned workerid, struct _starpu_sched_ctx *sched_ctx);
  530. struct _starpu_sched_ctx* _starpu_worker_get_ctx_stream(unsigned stream_workerid);
  531. /* Send a request to the worker to block, before a parallel task is about to
  532. * begin.
  533. *
  534. * Must be called with worker's sched_mutex held.
  535. */
  536. static inline void _starpu_worker_request_blocking_in_parallel(struct _starpu_worker * const worker)
  537. {
  538. /* flush pending requests to start on a fresh transaction epoch */
  539. while (worker->state_unblock_in_parallel_req)
  540. STARPU_PTHREAD_COND_WAIT(&worker->sched_cond, &worker->sched_mutex);
  541. /* announce blocking intent */
  542. STARPU_ASSERT(worker->block_in_parallel_ref_count < UINT_MAX);
  543. worker->block_in_parallel_ref_count++;
  544. if (worker->block_in_parallel_ref_count == 1)
  545. {
  546. /* only the transition from 0 to 1 triggers the block_in_parallel_req */
  547. STARPU_ASSERT(!worker->state_blocked_in_parallel);
  548. STARPU_ASSERT(!worker->state_block_in_parallel_req);
  549. STARPU_ASSERT(!worker->state_block_in_parallel_ack);
  550. STARPU_ASSERT(!worker->state_unblock_in_parallel_req);
  551. STARPU_ASSERT(!worker->state_unblock_in_parallel_ack);
  552. /* trigger the block_in_parallel_req */
  553. worker->state_block_in_parallel_req = 1;
  554. STARPU_PTHREAD_COND_BROADCAST(&worker->sched_cond);
  555. /* wait for block_in_parallel_req to be processed */
  556. while (!worker->state_block_in_parallel_ack)
  557. STARPU_PTHREAD_COND_WAIT(&worker->sched_cond, &worker->sched_mutex);
  558. STARPU_ASSERT(worker->block_in_parallel_ref_count >= 1);
  559. STARPU_ASSERT(worker->state_block_in_parallel_req);
  560. STARPU_ASSERT(worker->state_blocked_in_parallel);
  561. /* reset block_in_parallel_req state flags */
  562. worker->state_block_in_parallel_req = 0;
  563. worker->state_block_in_parallel_ack = 0;
  564. /* broadcast block_in_parallel_req state flags reset */
  565. STARPU_PTHREAD_COND_BROADCAST(&worker->sched_cond);
  566. }
  567. }
  568. /* Send a request to the worker to unblock, after a parallel task is complete.
  569. *
  570. * Must be called with worker's sched_mutex held.
  571. */
  572. static inline void _starpu_worker_request_unblocking_in_parallel(struct _starpu_worker * const worker)
  573. {
  574. /* flush pending requests to start on a fresh transaction epoch */
  575. while (worker->state_block_in_parallel_req)
  576. STARPU_PTHREAD_COND_WAIT(&worker->sched_cond, &worker->sched_mutex);
  577. /* unblocking may be requested unconditionnally
  578. * thus, check is unblocking is really needed */
  579. if (worker->state_blocked_in_parallel)
  580. {
  581. if (worker->block_in_parallel_ref_count == 1)
  582. {
  583. /* only the transition from 1 to 0 triggers the unblock_in_parallel_req */
  584. STARPU_ASSERT(!worker->state_block_in_parallel_req);
  585. STARPU_ASSERT(!worker->state_block_in_parallel_ack);
  586. STARPU_ASSERT(!worker->state_unblock_in_parallel_req);
  587. STARPU_ASSERT(!worker->state_unblock_in_parallel_ack);
  588. /* trigger the unblock_in_parallel_req */
  589. worker->state_unblock_in_parallel_req = 1;
  590. STARPU_PTHREAD_COND_BROADCAST(&worker->sched_cond);
  591. /* wait for the unblock_in_parallel_req to be processed */
  592. while (!worker->state_unblock_in_parallel_ack)
  593. STARPU_PTHREAD_COND_WAIT(&worker->sched_cond, &worker->sched_mutex);
  594. STARPU_ASSERT(worker->state_unblock_in_parallel_req);
  595. STARPU_ASSERT(!worker->state_blocked_in_parallel);
  596. /* reset unblock_in_parallel_req state flags */
  597. worker->state_unblock_in_parallel_req = 0;
  598. worker->state_unblock_in_parallel_ack = 0;
  599. /* broadcast unblock_in_parallel_req state flags reset */
  600. STARPU_PTHREAD_COND_BROADCAST(&worker->sched_cond);
  601. }
  602. /* announce unblocking complete */
  603. STARPU_ASSERT(worker->block_in_parallel_ref_count > 0);
  604. worker->block_in_parallel_ref_count--;
  605. }
  606. }
  607. /* Called by the the worker to process incoming requests to block or unblock on
  608. * parallel task boundaries.
  609. *
  610. * Must be called with worker's sched_mutex held.
  611. */
  612. static inline void _starpu_worker_process_block_in_parallel_requests(struct _starpu_worker * const worker)
  613. {
  614. while (worker->state_block_in_parallel_req)
  615. {
  616. STARPU_ASSERT(!worker->state_blocked_in_parallel);
  617. STARPU_ASSERT(!worker->state_block_in_parallel_ack);
  618. STARPU_ASSERT(!worker->state_unblock_in_parallel_req);
  619. STARPU_ASSERT(!worker->state_unblock_in_parallel_ack);
  620. STARPU_ASSERT(worker->block_in_parallel_ref_count > 0);
  621. /* enter effective blocked state */
  622. worker->state_blocked_in_parallel = 1;
  623. /* notify block_in_parallel_req processing */
  624. worker->state_block_in_parallel_ack = 1;
  625. STARPU_PTHREAD_COND_BROADCAST(&worker->sched_cond);
  626. /* block */
  627. while (!worker->state_unblock_in_parallel_req)
  628. STARPU_PTHREAD_COND_WAIT(&worker->sched_cond, &worker->sched_mutex);
  629. STARPU_ASSERT(worker->state_blocked_in_parallel);
  630. STARPU_ASSERT(!worker->state_block_in_parallel_req);
  631. STARPU_ASSERT(!worker->state_block_in_parallel_ack);
  632. STARPU_ASSERT(!worker->state_unblock_in_parallel_ack);
  633. STARPU_ASSERT(worker->block_in_parallel_ref_count > 0);
  634. /* leave effective blocked state */
  635. worker->state_blocked_in_parallel = 0;
  636. /* notify unblock_in_parallel_req processing */
  637. worker->state_unblock_in_parallel_ack = 1;
  638. STARPU_PTHREAD_COND_BROADCAST(&worker->sched_cond);
  639. }
  640. }
  641. /* Mark the beginning of a scheduling operation by the worker. No worker
  642. * blocking operations on parallel tasks and no scheduling context change
  643. * operations must be performed on contexts containing the worker, on
  644. * contexts about to add the worker and on contexts about to remove the
  645. * worker, while the scheduling operation is in process. The sched mutex
  646. * of the worker may only be acquired permanently by another thread when
  647. * no scheduling operation is in process, or when a scheduling operation
  648. * is in process _and_ worker->state_relax_refcnt!=0. If a
  649. * scheduling operation is in process _and_
  650. * worker->state_relax_refcnt==0, a thread other than the worker
  651. * must wait on condition worker->sched_cond for
  652. * worker->state_relax_refcnt!=0 to become true, before acquiring
  653. * the worker sched mutex permanently.
  654. *
  655. * Must be called with worker's sched_mutex held.
  656. */
  657. #ifdef STARPU_SPINLOCK_CHECK
  658. static inline void __starpu_worker_enter_sched_op(struct _starpu_worker * const worker, const char*file, int line, const char* func)
  659. #else
  660. static inline void _starpu_worker_enter_sched_op(struct _starpu_worker * const worker)
  661. #endif
  662. {
  663. STARPU_ASSERT(!worker->state_sched_op_pending);
  664. if (!worker->state_blocked_in_parallel_observed)
  665. {
  666. /* process pending block requests before entering a sched_op region */
  667. _starpu_worker_process_block_in_parallel_requests(worker);
  668. while (worker->state_changing_ctx_notice)
  669. {
  670. STARPU_PTHREAD_COND_WAIT(&worker->sched_cond, &worker->sched_mutex);
  671. /* new block requests may have been triggered during the wait,
  672. * need to check again */
  673. _starpu_worker_process_block_in_parallel_requests(worker);
  674. }
  675. }
  676. else
  677. {
  678. /* if someone observed the worker state since the last call, postpone block request
  679. * processing for one sched_op turn more, because the observer will not have seen
  680. * new block requests between its observation and now.
  681. *
  682. * however, the worker still has to wait for context change operations to complete
  683. * before entering sched_op again*/
  684. while (worker->state_changing_ctx_notice)
  685. {
  686. STARPU_PTHREAD_COND_WAIT(&worker->sched_cond, &worker->sched_mutex);
  687. }
  688. }
  689. /* no block request and no ctx change ahead,
  690. * enter sched_op */
  691. worker->state_sched_op_pending = 1;
  692. worker->state_blocked_in_parallel_observed = 0;
  693. worker->state_relax_refcnt = 0;
  694. #ifdef STARPU_SPINLOCK_CHECK
  695. worker->relax_on_file = file;
  696. worker->relax_on_line = line;
  697. worker->relax_on_func = func;
  698. #endif
  699. }
  700. #ifdef STARPU_SPINLOCK_CHECK
  701. #define _starpu_worker_enter_sched_op(worker) __starpu_worker_enter_sched_op((worker), __FILE__, __LINE__, __starpu_func__)
  702. #endif
  703. /* Mark the end of a scheduling operation by the worker.
  704. *
  705. * Must be called with worker's sched_mutex held.
  706. */
  707. void _starpu_worker_apply_deferred_ctx_changes(void);
  708. #ifdef STARPU_SPINLOCK_CHECK
  709. static inline void __starpu_worker_leave_sched_op(struct _starpu_worker * const worker, const char*file, int line, const char* func)
  710. #else
  711. static inline void _starpu_worker_leave_sched_op(struct _starpu_worker * const worker)
  712. #endif
  713. {
  714. STARPU_ASSERT(worker->state_sched_op_pending);
  715. worker->state_relax_refcnt = 1;
  716. #ifdef STARPU_SPINLOCK_CHECK
  717. worker->relax_off_file = file;
  718. worker->relax_off_line = line;
  719. worker->relax_off_func = func;
  720. #endif
  721. worker->state_sched_op_pending = 0;
  722. STARPU_PTHREAD_COND_BROADCAST(&worker->sched_cond);
  723. _starpu_worker_apply_deferred_ctx_changes();
  724. }
  725. #ifdef STARPU_SPINLOCK_CHECK
  726. #define _starpu_worker_leave_sched_op(worker) __starpu_worker_leave_sched_op((worker), __FILE__, __LINE__, __starpu_func__)
  727. #endif
  728. static inline int _starpu_worker_sched_op_pending(void)
  729. {
  730. int workerid = starpu_worker_get_id();
  731. if (workerid == -1)
  732. return 0;
  733. struct _starpu_worker *worker = _starpu_get_worker_struct(workerid);
  734. STARPU_ASSERT(worker != NULL);
  735. return worker->state_sched_op_pending;
  736. }
  737. /* Must be called before altering a context related to the worker
  738. * whether about adding the worker to a context, removing it from a
  739. * context or modifying the set of workers of a context of which the
  740. * worker is a member, to mark the beginning of a context change
  741. * operation. The sched mutex of the worker must be held before calling
  742. * this function.
  743. *
  744. * Must be called with worker's sched_mutex held.
  745. */
  746. static inline void _starpu_worker_enter_changing_ctx_op(struct _starpu_worker * const worker)
  747. {
  748. /* flush pending requests to start on a fresh transaction epoch */
  749. while (worker->state_changing_ctx_notice)
  750. STARPU_PTHREAD_COND_WAIT(&worker->sched_cond, &worker->sched_mutex);
  751. /* announce changing_ctx intent
  752. *
  753. * - an already started sched_op is allowed to complete
  754. * - no new sched_op may be started
  755. */
  756. worker->state_changing_ctx_notice = 1;
  757. /* allow for an already started sched_op to complete */
  758. if (worker->state_sched_op_pending)
  759. {
  760. /* request sched_op to broadcast when way is cleared */
  761. worker->state_changing_ctx_waiting = 1;
  762. /* wait for sched_op completion */
  763. STARPU_PTHREAD_COND_BROADCAST(&worker->sched_cond);
  764. do
  765. {
  766. STARPU_PTHREAD_COND_WAIT(&worker->sched_cond, &worker->sched_mutex);
  767. }
  768. while (worker->state_sched_op_pending);
  769. /* reset flag so other sched_ops wont have to broadcast state */
  770. worker->state_changing_ctx_waiting = 0;
  771. }
  772. }
  773. /* Mark the end of a context change operation.
  774. *
  775. * Must be called with worker's sched_mutex held.
  776. */
  777. static inline void _starpu_worker_leave_changing_ctx_op(struct _starpu_worker * const worker)
  778. {
  779. worker->state_changing_ctx_notice = 0;
  780. STARPU_PTHREAD_COND_BROADCAST(&worker->sched_cond);
  781. }
  782. /* Temporarily allow other worker to access current worker state, when still scheduling,
  783. * but the scheduling has not yet been made or is already done */
  784. #ifdef STARPU_SPINLOCK_CHECK
  785. static inline void __starpu_worker_relax_on(const char*file, int line, const char* func)
  786. #else
  787. static inline void _starpu_worker_relax_on(void)
  788. #endif
  789. {
  790. int workerid = starpu_worker_get_id();
  791. if (workerid == -1)
  792. return;
  793. struct _starpu_worker *worker = _starpu_get_worker_struct(workerid);
  794. STARPU_ASSERT(worker != NULL);
  795. if (!worker->state_sched_op_pending)
  796. return;
  797. STARPU_PTHREAD_MUTEX_LOCK_SCHED(&worker->sched_mutex);
  798. #ifdef STARPU_SPINLOCK_CHECK
  799. STARPU_ASSERT_MSG(worker->state_relax_refcnt<UINT_MAX, "relax last turn on in %s (%s:%d)\n", worker->relax_on_func, worker->relax_on_file, worker->relax_on_line);
  800. #else
  801. STARPU_ASSERT(worker->state_relax_refcnt<UINT_MAX);
  802. #endif
  803. worker->state_relax_refcnt++;
  804. #ifdef STARPU_SPINLOCK_CHECK
  805. worker->relax_on_file = file;
  806. worker->relax_on_line = line;
  807. worker->relax_on_func = func;
  808. #endif
  809. STARPU_PTHREAD_COND_BROADCAST(&worker->sched_cond);
  810. STARPU_PTHREAD_MUTEX_UNLOCK_SCHED(&worker->sched_mutex);
  811. }
  812. #ifdef STARPU_SPINLOCK_CHECK
  813. #define _starpu_worker_relax_on() __starpu_worker_relax_on(__FILE__, __LINE__, __starpu_func__)
  814. #endif
  815. #ifdef STARPU_SPINLOCK_CHECK
  816. static inline void __starpu_worker_relax_off(const char*file, int line, const char* func)
  817. #else
  818. static inline void _starpu_worker_relax_off(void)
  819. #endif
  820. {
  821. int workerid = starpu_worker_get_id();
  822. if (workerid == -1)
  823. return;
  824. struct _starpu_worker *worker = _starpu_get_worker_struct(workerid);
  825. STARPU_ASSERT(worker != NULL);
  826. if (!worker->state_sched_op_pending)
  827. return;
  828. STARPU_PTHREAD_MUTEX_LOCK_SCHED(&worker->sched_mutex);
  829. #ifdef STARPU_SPINLOCK_CHECK
  830. STARPU_ASSERT_MSG(worker->state_relax_refcnt>0, "relax last turn off in %s (%s:%d)\n", worker->relax_on_func, worker->relax_on_file, worker->relax_on_line);
  831. #else
  832. STARPU_ASSERT(worker->state_relax_refcnt>0);
  833. #endif
  834. worker->state_relax_refcnt--;
  835. #ifdef STARPU_SPINLOCK_CHECK
  836. worker->relax_off_file = file;
  837. worker->relax_off_line = line;
  838. worker->relax_off_func = func;
  839. #endif
  840. STARPU_PTHREAD_MUTEX_UNLOCK_SCHED(&worker->sched_mutex);
  841. }
  842. #ifdef STARPU_SPINLOCK_CHECK
  843. #define _starpu_worker_relax_off() __starpu_worker_relax_off(__FILE__, __LINE__, __starpu_func__)
  844. #endif
  845. static inline int _starpu_worker_get_relax_state(void)
  846. {
  847. int workerid = starpu_worker_get_id();
  848. if (workerid < 0)
  849. return 1;
  850. struct _starpu_worker *worker = _starpu_get_worker_struct(workerid);
  851. STARPU_ASSERT(worker != NULL);
  852. return worker->state_relax_refcnt != 0;
  853. }
  854. /* lock a worker for observing contents
  855. *
  856. * notes:
  857. * - if the observed worker is not in state_relax_refcnt, the function block until the state is reached */
  858. static inline void _starpu_worker_lock(int workerid)
  859. {
  860. struct _starpu_worker *worker = _starpu_get_worker_struct(workerid);
  861. STARPU_ASSERT(worker != NULL);
  862. int cur_workerid = starpu_worker_get_id();
  863. if (workerid != cur_workerid)
  864. {
  865. _starpu_worker_relax_on();
  866. STARPU_PTHREAD_MUTEX_LOCK_SCHED(&worker->sched_mutex);
  867. while (!worker->state_relax_refcnt)
  868. {
  869. STARPU_PTHREAD_COND_WAIT(&worker->sched_cond, &worker->sched_mutex);
  870. }
  871. }
  872. else
  873. {
  874. STARPU_PTHREAD_MUTEX_LOCK_SCHED(&worker->sched_mutex);
  875. }
  876. }
  877. static inline int _starpu_worker_trylock(int workerid)
  878. {
  879. struct _starpu_worker *worker = _starpu_get_worker_struct(workerid);
  880. STARPU_ASSERT(worker != NULL);
  881. int ret = STARPU_PTHREAD_MUTEX_TRYLOCK_SCHED(&worker->sched_mutex);
  882. int cur_workerid = starpu_worker_get_id();
  883. if (!ret)
  884. {
  885. if (workerid != cur_workerid) {
  886. ret = !worker->state_relax_refcnt;
  887. if (ret)
  888. STARPU_PTHREAD_MUTEX_UNLOCK_SCHED(&worker->sched_mutex);
  889. }
  890. }
  891. if (!ret && workerid != cur_workerid)
  892. {
  893. _starpu_worker_relax_on();
  894. }
  895. return ret;
  896. }
  897. static inline void _starpu_worker_unlock(int workerid)
  898. {
  899. struct _starpu_worker *worker = _starpu_get_worker_struct(workerid);
  900. STARPU_ASSERT(worker != NULL);
  901. STARPU_PTHREAD_MUTEX_UNLOCK_SCHED(&worker->sched_mutex);
  902. int cur_workerid = starpu_worker_get_id();
  903. if (workerid != cur_workerid)
  904. {
  905. _starpu_worker_relax_off();
  906. }
  907. }
  908. static inline void _starpu_worker_lock_self(void)
  909. {
  910. int workerid = starpu_worker_get_id_check();
  911. struct _starpu_worker *worker = _starpu_get_worker_struct(workerid);
  912. STARPU_ASSERT(worker != NULL);
  913. STARPU_PTHREAD_MUTEX_LOCK_SCHED(&worker->sched_mutex);
  914. }
  915. static inline void _starpu_worker_unlock_self(void)
  916. {
  917. int workerid = starpu_worker_get_id_check();
  918. struct _starpu_worker *worker = _starpu_get_worker_struct(workerid);
  919. STARPU_ASSERT(worker != NULL);
  920. STARPU_PTHREAD_MUTEX_UNLOCK_SCHED(&worker->sched_mutex);
  921. }
  922. static inline int _starpu_wake_worker_relax(int workerid)
  923. {
  924. _starpu_worker_lock(workerid);
  925. int ret = starpu_wake_worker_locked(workerid);
  926. _starpu_worker_unlock(workerid);
  927. return ret;
  928. }
  929. /* Allow a worker pulling a task it cannot execute to properly refuse it and
  930. * send it back to the scheduler.
  931. */
  932. void _starpu_worker_refuse_task(struct _starpu_worker *worker, struct starpu_task *task);
  933. #endif // __WORKERS_H__