Selaa lähdekoodia

Protect data header with a starpu_spinlock_t instead of a pthread_spinlock_t.

Cédric Augonnet 16 vuotta sitten
vanhempi
commit
51d00b2d26

+ 9 - 8
src/core/dependencies/data-concurrency.c

@@ -17,6 +17,7 @@
 #include <core/dependencies/data-concurrency.h>
 #include <datawizard/coherency.h>
 #include <core/policies/sched_policy.h>
+#include <common/starpu-spinlock.h>
 
 #ifdef NO_DATA_RW_LOCK
 
@@ -63,7 +64,7 @@ unsigned attempt_to_submit_data_request_from_apps(data_state *data, starpu_acces
 {
 	unsigned ret;
 
-	pthread_spin_lock(&data->header_lock);
+	starpu_spin_lock(&data->header_lock);
 
 	if (data->refcnt == 0)
 	{
@@ -103,7 +104,7 @@ unsigned attempt_to_submit_data_request_from_apps(data_state *data, starpu_acces
 		}
 	}
 
-	pthread_spin_unlock(&data->header_lock);
+	starpu_spin_unlock(&data->header_lock);
 	return ret;
 }
 
@@ -114,7 +115,7 @@ static unsigned attempt_to_submit_data_request_from_job(job_t j, unsigned buffer
 	data_state *data = j->task->buffers[buffer_index].handle;
 	starpu_access_mode mode = j->task->buffers[buffer_index].mode;
 
-	pthread_spin_lock(&data->header_lock);
+	starpu_spin_lock(&data->header_lock);
 
 	if (data->refcnt == 0)
 	{
@@ -154,7 +155,7 @@ static unsigned attempt_to_submit_data_request_from_job(job_t j, unsigned buffer
 		}
 	}
 
-	pthread_spin_unlock(&data->header_lock);
+	starpu_spin_unlock(&data->header_lock);
 	return ret;
 }
 
@@ -189,7 +190,7 @@ unsigned submit_job_enforce_data_deps(job_t j)
 
 void notify_data_dependencies(data_state *data)
 {
-	pthread_spin_lock(&data->header_lock);
+	starpu_spin_lock(&data->header_lock);
 
 	data->refcnt--;
 
@@ -200,7 +201,7 @@ void notify_data_dependencies(data_state *data)
 
 		data->refcnt++;
 	
-		pthread_spin_unlock(&data->header_lock);
+		starpu_spin_unlock(&data->header_lock);
 
 		if (r->is_requested_by_codelet)
 		{
@@ -217,10 +218,10 @@ void notify_data_dependencies(data_state *data)
 
 		data_requester_delete(r);
 		
-		pthread_spin_lock(&data->header_lock);
+		starpu_spin_lock(&data->header_lock);
 	}
 	
-	pthread_spin_unlock(&data->header_lock);
+	starpu_spin_unlock(&data->header_lock);
 
 }
 

+ 15 - 15
src/datawizard/coherency.c

@@ -96,7 +96,7 @@ static void update_data_state(data_state *state, uint32_t requesting_node,
 int _fetch_data(data_state *state, uint32_t requesting_node,
 			uint8_t read, uint8_t write)
 {
-	while (pthread_spin_trylock(&state->header_lock)) {
+	while (starpu_spin_trylock(&state->header_lock)) {
 		datawizard_progress(requesting_node);
 	}
 
@@ -107,7 +107,7 @@ int _fetch_data(data_state *state, uint32_t requesting_node,
 	if ((local_state == OWNER) || (local_state == SHARED && !write))
 	{
 		/* the local node already got its data */
-		pthread_spin_unlock(&state->header_lock);
+		starpu_spin_unlock(&state->header_lock);
 		msi_cache_hit(requesting_node);
 		return 0;
 	}
@@ -126,7 +126,7 @@ int _fetch_data(data_state *state, uint32_t requesting_node,
 
 		}
 		
-		pthread_spin_unlock(&state->header_lock);
+		starpu_spin_unlock(&state->header_lock);
 		msi_cache_hit(requesting_node);
 		return 0;
 	}
@@ -150,13 +150,13 @@ int _fetch_data(data_state *state, uint32_t requesting_node,
 
 	update_data_state(state, requesting_node, write);
 
-	pthread_spin_unlock(&state->header_lock);
+	starpu_spin_unlock(&state->header_lock);
 
 	return 0;
 
 enomem:
 	/* there was not enough local memory to fetch the data */
-	pthread_spin_unlock(&state->header_lock);
+	starpu_spin_unlock(&state->header_lock);
 	return -ENOMEM;
 }
 
@@ -181,11 +181,11 @@ static int fetch_data(data_state *state, starpu_access_mode mode)
 	}
 #endif
 
-	while (pthread_spin_trylock(&state->header_lock))
+	while (starpu_spin_trylock(&state->header_lock))
 		datawizard_progress(requesting_node);
 
 	state->per_node[requesting_node].refcnt++;
-	pthread_spin_unlock(&state->header_lock);
+	starpu_spin_unlock(&state->header_lock);
 
 	ret = _fetch_data(state, requesting_node, read, write);
 	if (ret != 0)
@@ -194,11 +194,11 @@ static int fetch_data(data_state *state, starpu_access_mode mode)
 	return 0;
 enomem:
 	/* we did not get the data so remove the lock anyway */
-	while (pthread_spin_trylock(&state->header_lock))
+	while (starpu_spin_trylock(&state->header_lock))
 		datawizard_progress(requesting_node);
 
 	state->per_node[requesting_node].refcnt--;
-	pthread_spin_unlock(&state->header_lock);
+	starpu_spin_unlock(&state->header_lock);
 
 #ifndef NO_DATA_RW_LOCK
 	release_rw_lock(&state->data_lock);
@@ -229,11 +229,11 @@ static void release_data(data_state *state, uint32_t default_wb_mask)
 		write_through_data(state, requesting_node, wb_mask);
 	}
 
-	while (pthread_spin_trylock(&state->header_lock))
+	while (starpu_spin_trylock(&state->header_lock))
 		datawizard_progress(requesting_node);
 
 	state->per_node[requesting_node].refcnt--;
-	pthread_spin_unlock(&state->header_lock);
+	starpu_spin_unlock(&state->header_lock);
 
 #ifndef NO_DATA_RW_LOCK
 	/* this is intended to make data accessible again */
@@ -294,7 +294,7 @@ void push_codelet_output(starpu_buffer_descr *descrs, unsigned nbuffers, uint32_
 
 int request_data_allocation(data_state *state, uint32_t node)
 {
-	pthread_spin_lock(&state->header_lock);
+	starpu_spin_lock(&state->header_lock);
 
 	int ret;
 	ret = allocate_per_node_buffer(state, node);
@@ -303,7 +303,7 @@ int request_data_allocation(data_state *state, uint32_t node)
 	/* XXX quick and dirty hack */
 	state->per_node[node].automatically_allocated = 0;	
 
-	pthread_spin_unlock(&state->header_lock);
+	starpu_spin_unlock(&state->header_lock);
 
 	return 0;
 }
@@ -382,7 +382,7 @@ void starpu_sync_data_with_mem(data_state *state)
 
 static inline void do_notify_data_modification(data_state *state, uint32_t modifying_node)
 {
-	pthread_spin_lock(&state->header_lock);
+	starpu_spin_lock(&state->header_lock);
 
 	unsigned node = 0;
 	for (node = 0; node < MAXNODES; node++)
@@ -391,7 +391,7 @@ static inline void do_notify_data_modification(data_state *state, uint32_t modif
 			(node == modifying_node?OWNER:INVALID);
 	}
 
-	pthread_spin_unlock(&state->header_lock);
+	starpu_spin_unlock(&state->header_lock);
 }
 
 #ifdef NO_DATA_RW_LOCK

+ 2 - 1
src/datawizard/coherency.h

@@ -27,6 +27,7 @@
 #include <starpu.h>
 
 #include <pthread.h>
+#include <common/starpu-spinlock.h>
 #include <common/rwlock.h>
 #include <common/timing.h>
 #include <common/fxt.h>
@@ -106,7 +107,7 @@ typedef struct starpu_data_state_t {
 	rw_lock	data_lock;
 #endif
 	/* protect meta data */
-	pthread_spinlock_t header_lock;
+	starpu_spinlock_t header_lock;
 
 	uint32_t nnodes; /* the number of memory nodes that may use it */
 	struct starpu_data_state_t *children;

+ 2 - 2
src/datawizard/data_request.c

@@ -70,7 +70,7 @@ int post_data_request(data_state *state, uint32_t src_node, uint32_t dst_node)
 	 * TODO: handle the situation of a possible invalidation caused by
 	 * memory eviction mechanism. This could be done by the means of a
 	 * specific state (or flag) in the MSI protocol. */
-	pthread_spin_unlock(&state->header_lock);
+	starpu_spin_unlock(&state->header_lock);
 #endif
 
 //	/* wait for the request to be performed */
@@ -96,7 +96,7 @@ int post_data_request(data_state *state, uint32_t src_node, uint32_t dst_node)
 	pthread_mutex_unlock(&data_requests_list_mutex[src_node]);
 
 #ifdef NO_DATA_RW_LOCK
-	pthread_spin_lock(&state->header_lock);
+	starpu_spin_lock(&state->header_lock);
 #endif
 
 	retvalue = r->retval;

+ 10 - 10
src/datawizard/hierarchy.c

@@ -51,10 +51,10 @@ void register_new_data(data_state *state, uint32_t home_node, uint32_t wb_mask)
 	state->req_list = data_requester_list_new();
 	state->refcnt = 0;
 #endif
-	pthread_spin_init(&state->header_lock, 0);
+	starpu_spin_init(&state->header_lock);
 
 	/* first take care to properly lock the data */
-	pthread_spin_lock(&state->header_lock);
+	starpu_spin_lock(&state->header_lock);
 
 	/* we assume that all nodes may use that data */
 	state->nnodes = MAXNODES;
@@ -90,7 +90,7 @@ void register_new_data(data_state *state, uint32_t home_node, uint32_t wb_mask)
 	}
 
 	/* now the data is available ! */
-	pthread_spin_unlock(&state->header_lock);
+	starpu_spin_unlock(&state->header_lock);
 }
 
 /*
@@ -167,7 +167,7 @@ void starpu_partition_data(data_state *initial_data, starpu_filter *f)
 	int i;
 
 	/* first take care to properly lock the data header */
-	pthread_spin_lock(&initial_data->header_lock);
+	starpu_spin_lock(&initial_data->header_lock);
 
 	/* there should not be mutiple filters applied on the same data */
 	STARPU_ASSERT(initial_data->nchildren == 0);
@@ -202,7 +202,7 @@ void starpu_partition_data(data_state *initial_data, starpu_filter *f)
 		children->req_list = data_requester_list_new();
 		children->refcnt = 0;
 #endif
-		pthread_spin_init(&children->header_lock, 0);
+		starpu_spin_init(&children->header_lock);
 
 		unsigned node;
 		for (node = 0; node < MAXNODES; node++)
@@ -217,7 +217,7 @@ void starpu_partition_data(data_state *initial_data, starpu_filter *f)
 	}
 
 	/* now let the header */
-	pthread_spin_unlock(&initial_data->header_lock);
+	starpu_spin_unlock(&initial_data->header_lock);
 }
 
 void starpu_unpartition_data(data_state *root_data, uint32_t gathering_node)
@@ -225,7 +225,7 @@ void starpu_unpartition_data(data_state *root_data, uint32_t gathering_node)
 	int child;
 	unsigned node;
 
-	pthread_spin_lock(&root_data->header_lock);
+	starpu_spin_lock(&root_data->header_lock);
 
 #ifdef NO_DATA_RW_LOCK
 #warning starpu_unpartition_data is not supported with NO_DATA_RW_LOCK yet ...
@@ -302,13 +302,13 @@ void starpu_unpartition_data(data_state *root_data, uint32_t gathering_node)
 	root_data->nchildren = 0;
 
 	/* now the parent may be used again so we release the lock */
-	pthread_spin_unlock(&root_data->header_lock);
+	starpu_spin_unlock(&root_data->header_lock);
 }
 
 void starpu_advise_if_data_is_important(data_state *state, unsigned is_important)
 {
 
-	pthread_spin_lock(&state->header_lock);
+	starpu_spin_lock(&state->header_lock);
 
 	/* first take all the children lock (in order !) */
 	int child;
@@ -322,6 +322,6 @@ void starpu_advise_if_data_is_important(data_state *state, unsigned is_important
 	state->is_not_important = !is_important;
 
 	/* now the parent may be used again so we release the lock */
-	pthread_spin_unlock(&state->header_lock);
+	starpu_spin_unlock(&state->header_lock);
 
 }

+ 2 - 2
src/datawizard/memalloc.c

@@ -49,7 +49,7 @@ static void lock_all_subtree(data_state *data)
 	if (data->nchildren == 0)
 	{
 		/* this is a leaf */	
-		while (pthread_spin_trylock(&data->header_lock))
+		while (starpu_spin_trylock(&data->header_lock))
 			datawizard_progress(get_local_memory_node());
 	}
 	else {
@@ -67,7 +67,7 @@ static void unlock_all_subtree(data_state *data)
 	if (data->nchildren == 0)
 	{
 		/* this is a leaf */	
-		pthread_spin_unlock(&data->header_lock);
+		starpu_spin_unlock(&data->header_lock);
 	}
 	else {
 		/* lock all sub-subtrees children */

+ 2 - 2
src/datawizard/write_back.c

@@ -25,7 +25,7 @@ void write_through_data(data_state *state, uint32_t requesting_node,
 		return;
 	}
 
-	while (pthread_spin_trylock(&state->header_lock))
+	while (starpu_spin_trylock(&state->header_lock))
 		datawizard_progress(requesting_node);
 
 	/* first commit all changes onto the nodes specified by the mask */
@@ -59,7 +59,7 @@ void write_through_data(data_state *state, uint32_t requesting_node,
 		state->per_node[requesting_node].state = SHARED;
 	}
 
-	pthread_spin_unlock(&state->header_lock);
+	starpu_spin_unlock(&state->header_lock);
 }
 
 void data_set_wb_mask(data_state *data, uint32_t wb_mask)