data_request.c 20 KB

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