Просмотр исходного кода

Use RW-locks to protect the list of queues that are attached to a memory node
(we only modify it during the initialization).

Cédric Augonnet лет назад: 16
Родитель
Сommit
5efb35d115

+ 1 - 1
src/core/policies/sched_policy.c

@@ -122,7 +122,7 @@ void init_sched_policy(struct machine_config_s *config, struct starpu_conf *user
 	pthread_key_create(&policy.local_queue_key, NULL);
 
 	mem_node_descr * const descr = get_memory_node_description();
-	pthread_spin_init(&descr->attached_queues_mutex, 0);
+	pthread_rwlock_init(&descr->attached_queues_rwlock, NULL);
 	descr->total_queues_count = 0;
 
 	policy.init_sched(config, &policy);

+ 4 - 4
src/core/workers.c

@@ -228,7 +228,7 @@ static void operate_on_all_queues_attached_to_node(unsigned nodeid, queue_op op)
 
 	mem_node_descr * const descr = get_memory_node_description();
 
-	pthread_spin_lock(&descr->attached_queues_mutex);
+	pthread_rwlock_rdlock(&descr->attached_queues_rwlock);
 
 	unsigned nqueues = descr->queues_count[nodeid];
 
@@ -248,7 +248,7 @@ static void operate_on_all_queues_attached_to_node(unsigned nodeid, queue_op op)
 		}
 	}
 
-	pthread_spin_unlock(&descr->attached_queues_mutex);
+	pthread_rwlock_unlock(&descr->attached_queues_rwlock);
 }
 
 inline void lock_all_queues_attached_to_node(unsigned node)
@@ -273,7 +273,7 @@ static void operate_on_all_queues(queue_op op)
 
 	mem_node_descr * const descr = get_memory_node_description();
 
-	pthread_spin_lock(&descr->attached_queues_mutex);
+	pthread_rwlock_rdlock(&descr->attached_queues_rwlock);
 
 	unsigned nqueues = descr->total_queues_count;
 
@@ -293,7 +293,7 @@ static void operate_on_all_queues(queue_op op)
 		}
 	}
 
-	pthread_spin_unlock(&descr->attached_queues_mutex);
+	pthread_rwlock_unlock(&descr->attached_queues_rwlock);
 }
 
 static void kill_all_workers(struct machine_config_s *config)

+ 2 - 2
src/datawizard/copy-driver.c

@@ -29,7 +29,7 @@ void wake_all_blocked_workers_on_node(unsigned nodeid)
 
 	mem_node_descr * const descr = get_memory_node_description();
 
-	pthread_spin_lock(&descr->attached_queues_mutex);
+	pthread_rwlock_rdlock(&descr->attached_queues_rwlock);
 
 	unsigned nqueues = descr->queues_count[nodeid];
 	for (q_id = 0; q_id < nqueues; q_id++)
@@ -43,7 +43,7 @@ void wake_all_blocked_workers_on_node(unsigned nodeid)
 		pthread_mutex_unlock(&q->activity_mutex);
 	}
 
-	pthread_spin_unlock(&descr->attached_queues_mutex);
+	pthread_rwlock_unlock(&descr->attached_queues_rwlock);
 }
 
 void wake_all_blocked_workers(void)

+ 4 - 4
src/datawizard/memory_nodes.c

@@ -102,7 +102,7 @@ void memory_node_attach_queue(struct jobq_s *q, unsigned nodeid)
 	unsigned queue;
 	unsigned nqueues_total, nqueues;
 	
-	pthread_spin_lock(&descr.attached_queues_mutex);
+	pthread_rwlock_wrlock(&descr.attached_queues_rwlock);
 
 	/* we only insert the queue if it's not already in the list */
 	nqueues = descr.queues_count[nodeid];
@@ -111,7 +111,7 @@ void memory_node_attach_queue(struct jobq_s *q, unsigned nodeid)
 		if (descr.attached_queues_per_node[nodeid][queue] == q)
 		{
 			/* the queue is already in the list */
-			pthread_spin_unlock(&descr.attached_queues_mutex);
+			pthread_rwlock_unlock(&descr.attached_queues_rwlock);
 			return;
 		}
 	}
@@ -127,7 +127,7 @@ void memory_node_attach_queue(struct jobq_s *q, unsigned nodeid)
 		if (descr.attached_queues_all[queue] == q)
 		{
 			/* the queue is already in the global list */
-			pthread_spin_unlock(&descr.attached_queues_mutex);
+			pthread_rwlock_unlock(&descr.attached_queues_rwlock);
 			return;
 		}
 	} 
@@ -136,7 +136,7 @@ void memory_node_attach_queue(struct jobq_s *q, unsigned nodeid)
 	descr.attached_queues_all[nqueues_total] = q;
 	descr.total_queues_count++;
 
-	pthread_spin_unlock(&descr.attached_queues_mutex);
+	pthread_rwlock_unlock(&descr.attached_queues_rwlock);
 }
 
 

+ 1 - 1
src/datawizard/memory_nodes.h

@@ -38,7 +38,7 @@ typedef struct {
 	/* the list of queues that are attached to a given node */
 	// XXX 32 is set randomly !
 	// TODO move this 2 lists outside mem_node_descr
-	pthread_spinlock_t attached_queues_mutex;
+	pthread_rwlock_t attached_queues_rwlock;
 	struct jobq_s *attached_queues_per_node[MAXNODES][32];
 	struct jobq_s *attached_queues_all[MAXNODES*32];
 	/* the number of queues attached to each node */