Browse Source

Make the "mem_node_descr" structure that describes all the memory nodes static:
use the get_memory_node_description to access it instead of an "extern
mem_node_descr descr;".

Cédric Augonnet 16 years ago
parent
commit
ad5e3077bf

+ 12 - 11
src/core/workers.c

@@ -221,21 +221,20 @@ typedef enum {
 	UNLOCK
 } queue_op;
 
-/* XXX we should use an accessor */
-extern mem_node_descr descr;
-
 static void operate_on_all_queues_attached_to_node(unsigned nodeid, queue_op op)
 {
 	unsigned q_id;
 	struct jobq_s *q;
 
-	pthread_spin_lock(&descr.attached_queues_mutex);
+	mem_node_descr * const descr = get_memory_node_description();
+
+	pthread_spin_lock(&descr->attached_queues_mutex);
 
-	unsigned nqueues = descr.queues_count[nodeid];
+	unsigned nqueues = descr->queues_count[nodeid];
 
 	for (q_id = 0; q_id < nqueues; q_id++)
 	{
-		q  = descr.attached_queues_per_node[nodeid][q_id];
+		q  = descr->attached_queues_per_node[nodeid][q_id];
 		switch (op) {
 			case BROADCAST:
 				pthread_cond_broadcast(&q->activity_cond);
@@ -249,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_spin_unlock(&descr->attached_queues_mutex);
 }
 
 inline void lock_all_queues_attached_to_node(unsigned node)
@@ -272,13 +271,15 @@ static void operate_on_all_queues(queue_op op)
 	unsigned q_id;
 	struct jobq_s *q;
 
-	pthread_spin_lock(&descr.attached_queues_mutex);
+	mem_node_descr * const descr = get_memory_node_description();
+
+	pthread_spin_lock(&descr->attached_queues_mutex);
 
-	unsigned nqueues = descr.total_queues_count;
+	unsigned nqueues = descr->total_queues_count;
 
 	for (q_id = 0; q_id < nqueues; q_id++)
 	{
-		q  = descr.attached_queues_all[q_id];
+		q  = descr->attached_queues_all[q_id];
 		switch (op) {
 			case BROADCAST:
 				pthread_cond_broadcast(&q->activity_cond);
@@ -292,7 +293,7 @@ static void operate_on_all_queues(queue_op op)
 		}
 	}
 
-	pthread_spin_unlock(&descr.attached_queues_mutex);
+	pthread_spin_unlock(&descr->attached_queues_mutex);
 }
 
 static void kill_all_workers(struct machine_config_s *config)

+ 12 - 9
src/datawizard/copy-driver.c

@@ -22,21 +22,20 @@
 #include "copy-driver.h"
 #include "memalloc.h"
 
-/* TODO write an accessor */
-extern mem_node_descr descr;
-
 void wake_all_blocked_workers_on_node(unsigned nodeid)
 {
 	/* wake up all queues on that node */
 	unsigned q_id;
 
-	pthread_spin_lock(&descr.attached_queues_mutex);
+	mem_node_descr * const descr = get_memory_node_description();
+
+	pthread_spin_lock(&descr->attached_queues_mutex);
 
-	unsigned nqueues = descr.queues_count[nodeid];
+	unsigned nqueues = descr->queues_count[nodeid];
 	for (q_id = 0; q_id < nqueues; q_id++)
 	{
 		struct jobq_s *q;
-		q  = descr.attached_queues_per_node[nodeid][q_id];
+		q  = descr->attached_queues_per_node[nodeid][q_id];
 
 		/* wake anybody waiting on that queue */
 		pthread_mutex_lock(&q->activity_mutex);
@@ -44,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_spin_unlock(&descr->attached_queues_mutex);
 }
 
 void wake_all_blocked_workers(void)
@@ -53,6 +52,7 @@ void wake_all_blocked_workers(void)
 	struct sched_policy_s *sched = get_sched_policy();
 	pthread_cond_t *sched_cond = &sched->sched_activity_cond;
 	pthread_mutex_t *sched_mutex = &sched->sched_activity_mutex;
+	mem_node_descr * const descr = get_memory_node_description();
 
 	pthread_mutex_lock(sched_mutex);
 	pthread_cond_broadcast(sched_cond);
@@ -60,7 +60,8 @@ void wake_all_blocked_workers(void)
 
 	/* workers may be blocked on the various queues' conditions */
 	unsigned node;
-	for (node = 0; node < descr.nnodes; node++)
+	unsigned nnodes =  descr->nnodes;
+	for (node = 0; node < nnodes; node++)
 	{
 		wake_all_blocked_workers_on_node(node);
 	}
@@ -135,6 +136,8 @@ static uint32_t choose_src_node(uint32_t src_node_mask)
 	unsigned src_node = 0;
 	unsigned i;
 
+	mem_node_descr * const descr = get_memory_node_description();
+
 	/* first find the node that will be the actual source */
 	for (i = 0; i < MAXNODES; i++)
 	{
@@ -145,7 +148,7 @@ static uint32_t choose_src_node(uint32_t src_node_mask)
 
 			/* however GPU are expensive sources, really !
 			 * 	other should be ok */
-			if (descr.nodes[i] != CUDA_RAM)
+			if (descr->nodes[i] != CUDA_RAM)
 				break;
 
 			/* XXX do a better algorithm to distribute the memory copies */

+ 0 - 1
src/datawizard/memalloc.c

@@ -17,7 +17,6 @@
 #include "memalloc.h"
 #include <datawizard/footprint.h>
 
-extern mem_node_descr descr;
 pthread_spinlock_t mc_mutex[MAXNODES]; 
 static mem_chunk_list_t mc_list[MAXNODES];
 static mem_chunk_list_t mc_list_to_free[MAXNODES];

+ 6 - 1
src/datawizard/memory_nodes.c

@@ -22,7 +22,7 @@
 #include "copy-driver.h"
 #include "memalloc.h"
 
-mem_node_descr descr;
+static mem_node_descr descr;
 static pthread_key_t memory_node_key;
 
 void init_memory_nodes(void)
@@ -69,6 +69,11 @@ unsigned get_local_memory_node(void)
 	return *memory_node;
 }
 
+inline mem_node_descr *get_memory_node_description(void)
+{
+	return &descr;
+}
+
 inline node_kind get_node_kind(uint32_t node)
 {
 	return descr.nodes[node];

+ 2 - 0
src/datawizard/memory_nodes.h

@@ -57,4 +57,6 @@ void memory_node_attach_queue(struct jobq_s *q, unsigned nodeid);
 
 node_kind get_node_kind(uint32_t node);
 
+inline mem_node_descr *get_memory_node_description(void);
+
 #endif // __MEMORY_NODES_H__