data_request.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2013 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011, 2012, 2013 Centre National de la Recherche Scientifique
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <starpu.h>
  18. #include <common/config.h>
  19. #include <common/utils.h>
  20. #include <datawizard/datawizard.h>
  21. /* requests that have not been treated at all */
  22. static struct _starpu_data_request_list *data_requests[STARPU_MAXNODES];
  23. static struct _starpu_data_request_list *prefetch_requests[STARPU_MAXNODES];
  24. static starpu_pthread_mutex_t data_requests_list_mutex[STARPU_MAXNODES];
  25. /* requests that are not terminated (eg. async transfers) */
  26. static struct _starpu_data_request_list *data_requests_pending[STARPU_MAXNODES];
  27. static starpu_pthread_mutex_t data_requests_pending_list_mutex[STARPU_MAXNODES];
  28. void _starpu_init_data_request_lists(void)
  29. {
  30. unsigned i;
  31. for (i = 0; i < STARPU_MAXNODES; i++)
  32. {
  33. prefetch_requests[i] = _starpu_data_request_list_new();
  34. data_requests[i] = _starpu_data_request_list_new();
  35. STARPU_PTHREAD_MUTEX_INIT(&data_requests_list_mutex[i], NULL);
  36. data_requests_pending[i] = _starpu_data_request_list_new();
  37. STARPU_PTHREAD_MUTEX_INIT(&data_requests_pending_list_mutex[i], NULL);
  38. }
  39. }
  40. void _starpu_deinit_data_request_lists(void)
  41. {
  42. unsigned i;
  43. for (i = 0; i < STARPU_MAXNODES; i++)
  44. {
  45. STARPU_PTHREAD_MUTEX_DESTROY(&data_requests_pending_list_mutex[i]);
  46. _starpu_data_request_list_delete(data_requests_pending[i]);
  47. STARPU_PTHREAD_MUTEX_DESTROY(&data_requests_list_mutex[i]);
  48. _starpu_data_request_list_delete(data_requests[i]);
  49. _starpu_data_request_list_delete(prefetch_requests[i]);
  50. }
  51. }
  52. /* this should be called with the lock r->handle->header_lock taken */
  53. static void starpu_data_request_destroy(struct _starpu_data_request *r)
  54. {
  55. unsigned node;
  56. /* If this is a write only request, then there is no source and we use
  57. * the destination node to cache the request. Otherwise we store the
  58. * pending requests between src and dst. */
  59. if (r->mode & STARPU_R)
  60. {
  61. node = r->src_replicate->memory_node;
  62. }
  63. else
  64. {
  65. node = r->dst_replicate->memory_node;
  66. }
  67. STARPU_ASSERT(r->dst_replicate->request[node] == r);
  68. r->dst_replicate->request[node] = NULL;
  69. //fprintf(stderr, "DESTROY REQ %p (%d) refcnt %d\n", r, node, r->refcnt);
  70. _starpu_data_request_delete(r);
  71. }
  72. /* handle->lock should already be taken ! */
  73. struct _starpu_data_request *_starpu_create_data_request(starpu_data_handle_t handle,
  74. struct _starpu_data_replicate *src_replicate,
  75. struct _starpu_data_replicate *dst_replicate,
  76. unsigned handling_node,
  77. enum starpu_data_access_mode mode,
  78. unsigned ndeps,
  79. unsigned is_prefetch)
  80. {
  81. struct _starpu_data_request *r = _starpu_data_request_new();
  82. _starpu_spin_checklocked(&handle->header_lock);
  83. _starpu_spin_init(&r->lock);
  84. r->handle = handle;
  85. r->src_replicate = src_replicate;
  86. r->dst_replicate = dst_replicate;
  87. r->mode = mode;
  88. r->handling_node = handling_node;
  89. r->completed = 0;
  90. r->prefetch = is_prefetch;
  91. r->retval = -1;
  92. r->ndeps = ndeps;
  93. r->next_req_count = 0;
  94. r->callbacks = NULL;
  95. _starpu_spin_lock(&r->lock);
  96. /* Take a reference on the target for the request to be able to write it */
  97. dst_replicate->refcnt++;
  98. handle->busy_count++;
  99. if (mode & STARPU_R)
  100. {
  101. unsigned src_node = src_replicate->memory_node;
  102. dst_replicate->request[src_node] = r;
  103. /* Take a reference on the source for the request to be able to read it */
  104. src_replicate->refcnt++;
  105. handle->busy_count++;
  106. }
  107. else
  108. {
  109. unsigned dst_node = dst_replicate->memory_node;
  110. dst_replicate->request[dst_node] = r;
  111. }
  112. r->refcnt = 1;
  113. _starpu_spin_unlock(&r->lock);
  114. return r;
  115. }
  116. int _starpu_wait_data_request_completion(struct _starpu_data_request *r, unsigned may_alloc)
  117. {
  118. int retval;
  119. int do_delete = 0;
  120. unsigned local_node = _starpu_memory_node_get_local_key();
  121. do
  122. {
  123. _starpu_spin_lock(&r->lock);
  124. if (r->completed)
  125. break;
  126. _starpu_spin_unlock(&r->lock);
  127. #ifndef STARPU_NON_BLOCKING_DRIVERS
  128. _starpu_wake_all_blocked_workers_on_node(r->handling_node);
  129. #endif
  130. _starpu_datawizard_progress(local_node, may_alloc);
  131. }
  132. while (1);
  133. retval = r->retval;
  134. if (retval)
  135. _STARPU_DISP("REQUEST %p completed with retval %d!\n", r, r->retval);
  136. r->refcnt--;
  137. /* if nobody is waiting on that request, we can get rid of it */
  138. if (r->refcnt == 0)
  139. do_delete = 1;
  140. _starpu_spin_unlock(&r->lock);
  141. if (do_delete)
  142. starpu_data_request_destroy(r);
  143. return retval;
  144. }
  145. /* this is non blocking */
  146. void _starpu_post_data_request(struct _starpu_data_request *r, unsigned handling_node)
  147. {
  148. /* We don't have a worker for disk nodes, these should have been posted to a main RAM node */
  149. STARPU_ASSERT(starpu_node_get_kind(handling_node) != STARPU_DISK_RAM);
  150. STARPU_ASSERT(_starpu_memory_node_get_nworkers(handling_node));
  151. // _STARPU_DEBUG("POST REQUEST\n");
  152. /* If some dependencies are not fulfilled yet, we don't actually post the request */
  153. if (r->ndeps > 0)
  154. return;
  155. if (r->mode & STARPU_R)
  156. {
  157. STARPU_ASSERT(r->src_replicate->allocated);
  158. STARPU_ASSERT(r->src_replicate->refcnt);
  159. }
  160. /* insert the request in the proper list */
  161. STARPU_PTHREAD_MUTEX_LOCK(&data_requests_list_mutex[handling_node]);
  162. if (r->prefetch)
  163. _starpu_data_request_list_push_back(prefetch_requests[handling_node], r);
  164. else
  165. _starpu_data_request_list_push_back(data_requests[handling_node], r);
  166. STARPU_PTHREAD_MUTEX_UNLOCK(&data_requests_list_mutex[handling_node]);
  167. #ifndef STARPU_NON_BLOCKING_DRIVERS
  168. _starpu_wake_all_blocked_workers_on_node(handling_node);
  169. #endif
  170. }
  171. /* We assume that r->lock is taken by the caller */
  172. void _starpu_data_request_append_callback(struct _starpu_data_request *r, void (*callback_func)(void *), void *callback_arg)
  173. {
  174. STARPU_ASSERT(r);
  175. if (callback_func)
  176. {
  177. struct _starpu_callback_list *link = (struct _starpu_callback_list *) malloc(sizeof(struct _starpu_callback_list));
  178. STARPU_ASSERT(link);
  179. link->callback_func = callback_func;
  180. link->callback_arg = callback_arg;
  181. link->next = r->callbacks;
  182. r->callbacks = link;
  183. }
  184. }
  185. /* This method is called with handle's header_lock taken, and unlocks it */
  186. static void starpu_handle_data_request_completion(struct _starpu_data_request *r)
  187. {
  188. unsigned do_delete = 0;
  189. starpu_data_handle_t handle = r->handle;
  190. enum starpu_data_access_mode mode = r->mode;
  191. struct _starpu_data_replicate *src_replicate = r->src_replicate;
  192. struct _starpu_data_replicate *dst_replicate = r->dst_replicate;
  193. #ifdef STARPU_MEMORY_STATS
  194. enum _starpu_cache_state old_src_replicate_state = src_replicate->state;
  195. #endif
  196. _starpu_spin_checklocked(&handle->header_lock);
  197. _starpu_update_data_state(handle, r->dst_replicate, mode);
  198. #ifdef STARPU_MEMORY_STATS
  199. if (src_replicate->state == STARPU_INVALID)
  200. {
  201. if (old_src_replicate_state == STARPU_OWNER)
  202. _starpu_memory_handle_stats_invalidated(handle, src_replicate->memory_node);
  203. else
  204. {
  205. /* XXX Currently only ex-OWNER are tagged as invalidated */
  206. /* XXX Have to check all old state of every node in case a SHARED data become OWNED by the dst_replicate */
  207. }
  208. }
  209. if (dst_replicate->state == STARPU_SHARED)
  210. _starpu_memory_handle_stats_loaded_shared(handle, dst_replicate->memory_node);
  211. else if (dst_replicate->state == STARPU_OWNER)
  212. {
  213. _starpu_memory_handle_stats_loaded_owner(handle, dst_replicate->memory_node);
  214. }
  215. #endif
  216. #ifdef STARPU_USE_FXT
  217. unsigned src_node = src_replicate->memory_node;
  218. unsigned dst_node = dst_replicate->memory_node;
  219. size_t size = _starpu_data_get_size(handle);
  220. _STARPU_TRACE_END_DRIVER_COPY(src_node, dst_node, size, r->com_id);
  221. #endif
  222. /* Once the request has been fulfilled, we may submit the requests that
  223. * were chained to that request. */
  224. unsigned chained_req;
  225. for (chained_req = 0; chained_req < r->next_req_count; chained_req++)
  226. {
  227. struct _starpu_data_request *next_req = r->next_req[chained_req];
  228. STARPU_ASSERT(next_req->ndeps > 0);
  229. next_req->ndeps--;
  230. _starpu_post_data_request(next_req, next_req->handling_node);
  231. }
  232. r->completed = 1;
  233. /* Remove a reference on the destination replicate for the request */
  234. STARPU_ASSERT(dst_replicate->refcnt > 0);
  235. dst_replicate->refcnt--;
  236. STARPU_ASSERT(handle->busy_count > 0);
  237. handle->busy_count--;
  238. /* In case the source was "locked" by the request too */
  239. if (mode & STARPU_R)
  240. {
  241. STARPU_ASSERT(src_replicate->refcnt > 0);
  242. src_replicate->refcnt--;
  243. STARPU_ASSERT(handle->busy_count > 0);
  244. handle->busy_count--;
  245. }
  246. unsigned destroyed = _starpu_data_check_not_busy(handle);
  247. r->refcnt--;
  248. /* if nobody is waiting on that request, we can get rid of it */
  249. if (r->refcnt == 0)
  250. do_delete = 1;
  251. r->retval = 0;
  252. /* In case there are one or multiple callbacks, we execute them now. */
  253. struct _starpu_callback_list *callbacks = r->callbacks;
  254. _starpu_spin_unlock(&r->lock);
  255. if (do_delete)
  256. starpu_data_request_destroy(r);
  257. if (!destroyed)
  258. _starpu_spin_unlock(&handle->header_lock);
  259. /* We do the callback once the lock is released so that they can do
  260. * blocking operations with the handle (eg. release it) */
  261. while (callbacks)
  262. {
  263. callbacks->callback_func(callbacks->callback_arg);
  264. struct _starpu_callback_list *next = callbacks->next;
  265. free(callbacks);
  266. callbacks = next;
  267. }
  268. }
  269. /* TODO : accounting to see how much time was spent working for other people ... */
  270. static int starpu_handle_data_request(struct _starpu_data_request *r, unsigned may_alloc)
  271. {
  272. starpu_data_handle_t handle = r->handle;
  273. _starpu_spin_lock(&handle->header_lock);
  274. _starpu_spin_lock(&r->lock);
  275. struct _starpu_data_replicate *src_replicate = r->src_replicate;
  276. struct _starpu_data_replicate *dst_replicate = r->dst_replicate;
  277. enum starpu_data_access_mode r_mode = r->mode;
  278. STARPU_ASSERT(!(r_mode & STARPU_R) || src_replicate);
  279. STARPU_ASSERT(!(r_mode & STARPU_R) || src_replicate->allocated);
  280. STARPU_ASSERT(!(r_mode & STARPU_R) || src_replicate->refcnt);
  281. _starpu_spin_unlock(&r->lock);
  282. /* FIXME: the request may get upgraded from here to freeing it... */
  283. /* perform the transfer */
  284. /* the header of the data must be locked by the worker that submitted the request */
  285. r->retval = _starpu_driver_copy_data_1_to_1(handle, src_replicate,
  286. dst_replicate, !(r_mode & STARPU_R), r, may_alloc);
  287. if (r->retval == -ENOMEM)
  288. {
  289. /* If there was not enough memory, we will try to redo the
  290. * request later. */
  291. _starpu_spin_unlock(&handle->header_lock);
  292. return -ENOMEM;
  293. }
  294. if (r->retval == -EAGAIN)
  295. {
  296. /* The request was successful, but could not be terminted
  297. * immediatly. We will handle the completion of the request
  298. * asynchronously. The request is put in the list of "pending"
  299. * requests in the meantime. */
  300. _starpu_spin_unlock(&handle->header_lock);
  301. STARPU_PTHREAD_MUTEX_LOCK(&data_requests_pending_list_mutex[r->handling_node]);
  302. _starpu_data_request_list_push_front(data_requests_pending[r->handling_node], r);
  303. STARPU_PTHREAD_MUTEX_UNLOCK(&data_requests_pending_list_mutex[r->handling_node]);
  304. return -EAGAIN;
  305. }
  306. /* the request has been handled */
  307. _starpu_spin_lock(&r->lock);
  308. starpu_handle_data_request_completion(r);
  309. return 0;
  310. }
  311. void _starpu_handle_node_data_requests(unsigned src_node, unsigned may_alloc)
  312. {
  313. struct _starpu_data_request *r;
  314. struct _starpu_data_request_list *new_data_requests;
  315. /* Note: we here tell valgrind that list_empty (reading a pointer) is
  316. * as safe as if we had the lock held */
  317. VALGRIND_HG_MUTEX_LOCK_PRE(&data_requests_list_mutex[src_node], 0);
  318. VALGRIND_HG_MUTEX_LOCK_POST(&data_requests_list_mutex[src_node]);
  319. if (_starpu_data_request_list_empty(data_requests[src_node]))
  320. {
  321. VALGRIND_HG_MUTEX_UNLOCK_PRE(&data_requests_list_mutex[src_node]);
  322. VALGRIND_HG_MUTEX_UNLOCK_POST(&data_requests_list_mutex[src_node]);
  323. return;
  324. }
  325. VALGRIND_HG_MUTEX_UNLOCK_PRE(&data_requests_list_mutex[src_node]);
  326. VALGRIND_HG_MUTEX_UNLOCK_POST(&data_requests_list_mutex[src_node]);
  327. /* take all the entries from the request list */
  328. STARPU_PTHREAD_MUTEX_LOCK(&data_requests_list_mutex[src_node]);
  329. struct _starpu_data_request_list *local_list = data_requests[src_node];
  330. if (_starpu_data_request_list_empty(local_list))
  331. {
  332. /* there is no request */
  333. STARPU_PTHREAD_MUTEX_UNLOCK(&data_requests_list_mutex[src_node]);
  334. return;
  335. }
  336. /* There is an entry: we create a new empty list to replace the list of
  337. * requests, and we handle the request(s) one by one in the former
  338. * list, without concurrency issues.*/
  339. data_requests[src_node] = _starpu_data_request_list_new();
  340. STARPU_PTHREAD_MUTEX_UNLOCK(&data_requests_list_mutex[src_node]);
  341. new_data_requests = _starpu_data_request_list_new();
  342. /* for all entries of the list */
  343. while (!_starpu_data_request_list_empty(local_list))
  344. {
  345. int res;
  346. r = _starpu_data_request_list_pop_front(local_list);
  347. res = starpu_handle_data_request(r, may_alloc);
  348. if (res == -ENOMEM)
  349. {
  350. _starpu_data_request_list_push_back(new_data_requests, r);
  351. }
  352. }
  353. if (!_starpu_data_request_list_empty(new_data_requests))
  354. {
  355. STARPU_PTHREAD_MUTEX_LOCK(&data_requests_list_mutex[src_node]);
  356. _starpu_data_request_list_push_list_front(new_data_requests, data_requests[src_node]);
  357. STARPU_PTHREAD_MUTEX_UNLOCK(&data_requests_list_mutex[src_node]);
  358. }
  359. _starpu_data_request_list_delete(new_data_requests);
  360. _starpu_data_request_list_delete(local_list);
  361. }
  362. void _starpu_handle_node_prefetch_requests(unsigned src_node, unsigned may_alloc)
  363. {
  364. struct _starpu_data_request *r;
  365. struct _starpu_data_request_list *new_data_requests;
  366. struct _starpu_data_request_list *new_prefetch_requests;
  367. if (_starpu_data_request_list_empty(prefetch_requests[src_node]))
  368. return;
  369. /* take all the entries from the request list */
  370. STARPU_PTHREAD_MUTEX_LOCK(&data_requests_list_mutex[src_node]);
  371. struct _starpu_data_request_list *local_list = prefetch_requests[src_node];
  372. if (_starpu_data_request_list_empty(local_list))
  373. {
  374. /* there is no request */
  375. STARPU_PTHREAD_MUTEX_UNLOCK(&data_requests_list_mutex[src_node]);
  376. return;
  377. }
  378. /* There is an entry: we create a new empty list to replace the list of
  379. * requests, and we handle the request(s) one by one in the former
  380. * list, without concurrency issues.*/
  381. prefetch_requests[src_node] = _starpu_data_request_list_new();
  382. STARPU_PTHREAD_MUTEX_UNLOCK(&data_requests_list_mutex[src_node]);
  383. new_data_requests = _starpu_data_request_list_new();
  384. new_prefetch_requests = _starpu_data_request_list_new();
  385. /* for all entries of the list */
  386. while (!_starpu_data_request_list_empty(local_list))
  387. {
  388. int res;
  389. r = _starpu_data_request_list_pop_front(local_list);
  390. res = starpu_handle_data_request(r, may_alloc);
  391. if (res == -ENOMEM )
  392. {
  393. if (r->prefetch)
  394. _starpu_data_request_list_push_back(new_prefetch_requests, r);
  395. else
  396. {
  397. /* Prefetch request promoted while in tmp list*/
  398. _starpu_data_request_list_push_back(new_data_requests, r);
  399. }
  400. break;
  401. }
  402. }
  403. while(!_starpu_data_request_list_empty(local_list))
  404. {
  405. r = _starpu_data_request_list_pop_front(local_list);
  406. if (r->prefetch)
  407. _starpu_data_request_list_push_back(new_prefetch_requests, r);
  408. else
  409. /* Prefetch request promoted while in tmp list*/
  410. _starpu_data_request_list_push_back(new_data_requests, r);
  411. }
  412. if (!(_starpu_data_request_list_empty(new_data_requests) && _starpu_data_request_list_empty(new_prefetch_requests)))
  413. {
  414. STARPU_PTHREAD_MUTEX_LOCK(&data_requests_list_mutex[src_node]);
  415. if (!(_starpu_data_request_list_empty(new_data_requests)))
  416. _starpu_data_request_list_push_list_front(new_data_requests, data_requests[src_node]);
  417. if (!(_starpu_data_request_list_empty(new_prefetch_requests)))
  418. _starpu_data_request_list_push_list_front(new_prefetch_requests, prefetch_requests[src_node]);
  419. STARPU_PTHREAD_MUTEX_UNLOCK(&data_requests_list_mutex[src_node]);
  420. }
  421. _starpu_data_request_list_delete(new_data_requests);
  422. _starpu_data_request_list_delete(new_prefetch_requests);
  423. _starpu_data_request_list_delete(local_list);
  424. }
  425. static void _handle_pending_node_data_requests(unsigned src_node, unsigned force)
  426. {
  427. // _STARPU_DEBUG("_starpu_handle_pending_node_data_requests ...\n");
  428. //
  429. struct _starpu_data_request_list *new_data_requests_pending;
  430. if (_starpu_data_request_list_empty(data_requests_pending[src_node]))
  431. return;
  432. STARPU_PTHREAD_MUTEX_LOCK(&data_requests_pending_list_mutex[src_node]);
  433. /* for all entries of the list */
  434. struct _starpu_data_request_list *local_list = data_requests_pending[src_node];
  435. if (_starpu_data_request_list_empty(local_list))
  436. {
  437. /* there is no request */
  438. STARPU_PTHREAD_MUTEX_UNLOCK(&data_requests_pending_list_mutex[src_node]);
  439. return;
  440. }
  441. data_requests_pending[src_node] = _starpu_data_request_list_new();
  442. STARPU_PTHREAD_MUTEX_UNLOCK(&data_requests_pending_list_mutex[src_node]);
  443. new_data_requests_pending = _starpu_data_request_list_new();
  444. while (!_starpu_data_request_list_empty(local_list))
  445. {
  446. struct _starpu_data_request *r;
  447. r = _starpu_data_request_list_pop_front(local_list);
  448. starpu_data_handle_t handle = r->handle;
  449. _starpu_spin_lock(&handle->header_lock);
  450. _starpu_spin_lock(&r->lock);
  451. /* wait until the transfer is terminated */
  452. if (force)
  453. {
  454. _starpu_driver_wait_request_completion(&r->async_channel);
  455. starpu_handle_data_request_completion(r);
  456. }
  457. else
  458. {
  459. if (_starpu_driver_test_request_completion(&r->async_channel))
  460. {
  461. /* The request was completed */
  462. starpu_handle_data_request_completion(r);
  463. }
  464. else
  465. {
  466. /* The request was not completed, so we put it
  467. * back again on the list of pending requests
  468. * so that it can be handled later on. */
  469. _starpu_spin_unlock(&r->lock);
  470. _starpu_spin_unlock(&handle->header_lock);
  471. _starpu_data_request_list_push_back(new_data_requests_pending, r);
  472. }
  473. }
  474. }
  475. if (!_starpu_data_request_list_empty(new_data_requests_pending))
  476. {
  477. STARPU_PTHREAD_MUTEX_LOCK(&data_requests_pending_list_mutex[src_node]);
  478. _starpu_data_request_list_push_list_back(data_requests_pending[src_node], new_data_requests_pending);
  479. STARPU_PTHREAD_MUTEX_UNLOCK(&data_requests_pending_list_mutex[src_node]);
  480. }
  481. _starpu_data_request_list_delete(local_list);
  482. _starpu_data_request_list_delete(new_data_requests_pending);
  483. }
  484. void _starpu_handle_pending_node_data_requests(unsigned src_node)
  485. {
  486. _handle_pending_node_data_requests(src_node, 0);
  487. }
  488. void _starpu_handle_all_pending_node_data_requests(unsigned src_node)
  489. {
  490. _handle_pending_node_data_requests(src_node, 1);
  491. }
  492. int _starpu_check_that_no_data_request_exists(unsigned node)
  493. {
  494. /* XXX lock that !!! that's a quick'n'dirty test */
  495. int no_request;
  496. int no_pending;
  497. STARPU_PTHREAD_MUTEX_LOCK(&data_requests_list_mutex[node]);
  498. no_request = _starpu_data_request_list_empty(data_requests[node]);
  499. STARPU_PTHREAD_MUTEX_UNLOCK(&data_requests_list_mutex[node]);
  500. STARPU_PTHREAD_MUTEX_LOCK(&data_requests_pending_list_mutex[node]);
  501. no_pending = _starpu_data_request_list_empty(data_requests_pending[node]);
  502. STARPU_PTHREAD_MUTEX_UNLOCK(&data_requests_pending_list_mutex[node]);
  503. return (no_request && no_pending);
  504. }
  505. void _starpu_update_prefetch_status(struct _starpu_data_request *r)
  506. {
  507. STARPU_ASSERT(r->prefetch > 0);
  508. r->prefetch=0;
  509. /* We have to promote chained_request too! */
  510. unsigned chained_req;
  511. for (chained_req = 0; chained_req < r->next_req_count; chained_req++)
  512. {
  513. struct _starpu_data_request *next_req = r->next_req[chained_req];
  514. if (next_req->prefetch)
  515. _starpu_update_prefetch_status(next_req);
  516. }
  517. STARPU_PTHREAD_MUTEX_LOCK(&data_requests_list_mutex[r->handling_node]);
  518. /* The request can be in a different list (handling request or the temp list)
  519. * we have to check that it is really in the prefetch list. */
  520. struct _starpu_data_request *r_iter;
  521. for (r_iter = _starpu_data_request_list_begin(prefetch_requests[r->handling_node]);
  522. r_iter != _starpu_data_request_list_end(prefetch_requests[r->handling_node]);
  523. r_iter = _starpu_data_request_list_next(r_iter))
  524. {
  525. if (r==r_iter)
  526. {
  527. _starpu_data_request_list_erase(prefetch_requests[r->handling_node],r);
  528. _starpu_data_request_list_push_front(data_requests[r->handling_node],r);
  529. break;
  530. }
  531. }
  532. STARPU_PTHREAD_MUTEX_UNLOCK(&data_requests_list_mutex[r->handling_node]);
  533. }