data_request.c 19 KB

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