|
@@ -356,17 +356,12 @@ static int starpu_handle_data_request(struct _starpu_data_request *r, unsigned m
|
|
|
{
|
|
|
starpu_data_handle_t handle = r->handle;
|
|
|
|
|
|
- if (prefetch) {
|
|
|
- if (_starpu_spin_trylock(&handle->header_lock))
|
|
|
- return -EBUSY;
|
|
|
- if (_starpu_spin_trylock(&r->lock))
|
|
|
- {
|
|
|
- _starpu_spin_unlock(&handle->header_lock);
|
|
|
- return -EBUSY;
|
|
|
- }
|
|
|
- } else {
|
|
|
- _starpu_spin_lock(&handle->header_lock);
|
|
|
- _starpu_spin_lock(&r->lock);
|
|
|
+ if (_starpu_spin_trylock(&handle->header_lock))
|
|
|
+ return -EBUSY;
|
|
|
+ if (_starpu_spin_trylock(&r->lock))
|
|
|
+ {
|
|
|
+ _starpu_spin_unlock(&handle->header_lock);
|
|
|
+ return -EBUSY;
|
|
|
}
|
|
|
|
|
|
struct _starpu_data_replicate *src_replicate = r->src_replicate;
|
|
@@ -420,19 +415,22 @@ static int starpu_handle_data_request(struct _starpu_data_request *r, unsigned m
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-void _starpu_handle_node_data_requests(unsigned src_node, unsigned may_alloc)
|
|
|
+int _starpu_handle_node_data_requests(unsigned src_node, unsigned may_alloc)
|
|
|
{
|
|
|
struct _starpu_data_request *r;
|
|
|
struct _starpu_data_request_list *new_data_requests;
|
|
|
+ int ret = 0;
|
|
|
|
|
|
/* Here helgrind would should that this is an un protected access.
|
|
|
* We however don't care about missing an entry, we will get called
|
|
|
* again sooner or later. */
|
|
|
if (_starpu_data_request_list_empty(data_requests[src_node]))
|
|
|
- return;
|
|
|
+ return 0;
|
|
|
|
|
|
/* take all the entries from the request list */
|
|
|
- STARPU_PTHREAD_MUTEX_LOCK(&data_requests_list_mutex[src_node]);
|
|
|
+ if (STARPU_PTHREAD_MUTEX_TRYLOCK(&data_requests_list_mutex[src_node]))
|
|
|
+ /* List is busy, do not bother with it */
|
|
|
+ return -EBUSY;
|
|
|
|
|
|
struct _starpu_data_request_list *local_list = data_requests[src_node];
|
|
|
|
|
@@ -441,7 +439,7 @@ void _starpu_handle_node_data_requests(unsigned src_node, unsigned may_alloc)
|
|
|
/* there is no request */
|
|
|
STARPU_PTHREAD_MUTEX_UNLOCK(&data_requests_list_mutex[src_node]);
|
|
|
|
|
|
- return;
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
/* There is an entry: we create a new empty list to replace the list of
|
|
@@ -463,6 +461,7 @@ void _starpu_handle_node_data_requests(unsigned src_node, unsigned may_alloc)
|
|
|
{
|
|
|
/* Too many requests at the same time, skip pushing
|
|
|
* more for now */
|
|
|
+ ret = -EBUSY;
|
|
|
break;
|
|
|
}
|
|
|
|
|
@@ -471,6 +470,8 @@ void _starpu_handle_node_data_requests(unsigned src_node, unsigned may_alloc)
|
|
|
res = starpu_handle_data_request(r, may_alloc, 0);
|
|
|
if (res != 0 && res != -EAGAIN)
|
|
|
{
|
|
|
+ /* handle is busy, or not enough memory, postpone for now */
|
|
|
+ ret = res;
|
|
|
_starpu_data_request_list_push_back(new_data_requests, r);
|
|
|
break;
|
|
|
}
|
|
@@ -491,6 +492,8 @@ void _starpu_handle_node_data_requests(unsigned src_node, unsigned may_alloc)
|
|
|
|
|
|
_starpu_data_request_list_delete(new_data_requests);
|
|
|
_starpu_data_request_list_delete(local_list);
|
|
|
+
|
|
|
+ return ret;
|
|
|
}
|
|
|
|
|
|
void _starpu_handle_node_prefetch_requests(unsigned src_node, unsigned may_alloc)
|
|
@@ -503,7 +506,9 @@ void _starpu_handle_node_prefetch_requests(unsigned src_node, unsigned may_alloc
|
|
|
return;
|
|
|
|
|
|
/* take all the entries from the request list */
|
|
|
- STARPU_PTHREAD_MUTEX_LOCK(&data_requests_list_mutex[src_node]);
|
|
|
+ if (STARPU_PTHREAD_MUTEX_TRYLOCK(&data_requests_list_mutex[src_node]))
|
|
|
+ /* List is busy, do not bother with it */
|
|
|
+ return;
|
|
|
|
|
|
struct _starpu_data_request_list *local_list = prefetch_requests[src_node];
|
|
|
|
|
@@ -587,7 +592,9 @@ static void _handle_pending_node_data_requests(unsigned src_node, unsigned force
|
|
|
if (_starpu_data_request_list_empty(data_requests_pending[src_node]))
|
|
|
return;
|
|
|
|
|
|
- STARPU_PTHREAD_MUTEX_LOCK(&data_requests_pending_list_mutex[src_node]);
|
|
|
+ if (STARPU_PTHREAD_MUTEX_TRYLOCK(&data_requests_pending_list_mutex[src_node]) && !force)
|
|
|
+ /* List is busy, do not bother with it */
|
|
|
+ return;
|
|
|
|
|
|
/* for all entries of the list */
|
|
|
struct _starpu_data_request_list *local_list = data_requests_pending[src_node];
|
|
@@ -613,8 +620,19 @@ static void _handle_pending_node_data_requests(unsigned src_node, unsigned force
|
|
|
|
|
|
starpu_data_handle_t handle = r->handle;
|
|
|
|
|
|
- _starpu_spin_lock(&handle->header_lock);
|
|
|
+ if (force)
|
|
|
+ /* Have to wait for the handle, whatever it takes */
|
|
|
+ _starpu_spin_lock(&handle->header_lock);
|
|
|
+ else
|
|
|
+ if (_starpu_spin_trylock(&handle->header_lock))
|
|
|
+ {
|
|
|
+ /* Handle is busy, retry this later */
|
|
|
+ _starpu_data_request_list_push_back(new_data_requests_pending, r);
|
|
|
+ kept++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
+ /* This shouldn't be too hard to acquire */
|
|
|
_starpu_spin_lock(&r->lock);
|
|
|
|
|
|
/* wait until the transfer is terminated */
|