Pārlūkot izejas kodu

Add a set of functions to manipulate all queues attached to a memory node.

Cédric Augonnet 16 gadi atpakaļ
vecāks
revīzija
7ddfe04a88
2 mainītis faili ar 48 papildinājumiem un 0 dzēšanām
  1. 43 0
      src/core/workers.c
  2. 5 0
      src/core/workers.h

+ 43 - 0
src/core/workers.c

@@ -418,6 +418,49 @@ typedef enum {
 /* 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;
+
+	take_mutex(&descr.attached_queues_mutex);
+
+	unsigned nqueues = descr.queues_count[nodeid];
+
+	for (q_id = 0; q_id < nqueues; q_id++)
+	{
+		q  = descr.attached_queues_per_node[nodeid][q_id];
+		switch (op) {
+			case BROADCAST:
+				pthread_cond_broadcast(&q->activity_cond);
+				break;
+			case LOCK:
+				pthread_mutex_lock(&q->activity_mutex);
+				break;
+			case UNLOCK:
+				pthread_mutex_unlock(&q->activity_mutex);
+				break;
+		}
+	}
+
+	release_mutex(&descr.attached_queues_mutex);
+}
+
+inline void lock_all_queues_attached_to_node(unsigned node)
+{
+	operate_on_all_queues_attached_to_node(node, LOCK);
+}
+
+inline void unlock_all_queues_attached_to_node(unsigned node)
+{
+	operate_on_all_queues_attached_to_node(node, UNLOCK);
+}
+
+inline void broadcast_all_queues_attached_to_node(unsigned node)
+{
+	operate_on_all_queues_attached_to_node(node, BROADCAST);
+}
+
 static void operate_on_all_queues(queue_op op)
 {
 	unsigned q_id;

+ 5 - 0
src/core/workers.h

@@ -111,4 +111,9 @@ inline uint32_t may_submit_cuda_task(void);
 inline uint32_t may_submit_core_task(void);
 
 
+inline void lock_all_queues_attached_to_node(unsigned node);
+inline void unlock_all_queues_attached_to_node(unsigned node);
+inline void broadcast_all_queues_attached_to_node(unsigned node);
+
+
 #endif // __WORKERS_H__