[Cbe-oss-dev] [PATCH 09/28]MARS/base: workload queue cleanup

Yuji Mano yuji.mano at am.sony.com
Fri Feb 6 13:31:14 EST 2009


This cleans up some of the workload queue code in preparation for following
patches. This moves out some initialization code into separate functions
and adds a callback parameter to the change_bits/change_state functions.

Signed-off-by: Yuji Mano <yuji.mano at am.sony.com>
---
 base/src/host/lib/workload_queue.c |  144 +++++++++++++++++++++----------------
 1 file changed, 85 insertions(+), 59 deletions(-)

--- a/base/src/host/lib/workload_queue.c
+++ b/base/src/host/lib/workload_queue.c
@@ -72,27 +72,56 @@ static inline uint64_t get_block_bits_ea
 	       sizeof(uint64_t) * index;
 }
 
-static void init_block(uint64_t block_ea, uint64_t initial_bits)
+static void init_header(uint64_t queue_ea)
 {
+	struct mars_workload_queue *queue;
+
+	/* prepare work area for queue header */
+	queue = mars_ea_work_area_get(queue_ea,
+		MARS_WORKLOAD_QUEUE_ALIGN,
+		sizeof(struct mars_workload_queue_header));
+
+	/* initialize workload queue header */
+	queue->header.flag = MARS_WORKLOAD_QUEUE_FLAG_NONE;
+	queue->header.queue_ea = queue_ea;
+	queue->header.context_ea =
+		queue_ea + offsetof(struct mars_workload_queue, context);
+
+	/* update queue header on EA */
+	mars_ea_put(queue_ea, queue, sizeof(struct mars_workload_queue_header));
+}
+
+static void init_blocks(uint64_t queue_ea)
+{
+	int block;
 	int index;
-	struct mars_workload_queue_block *block =
-		mars_ea_work_area_get(block_ea,
-				      MARS_WORKLOAD_QUEUE_BLOCK_ALIGN,
-				      sizeof(struct mars_workload_queue_block));
+	uint64_t bits = 0;
+	struct mars_workload_queue_block *queue_block;
+
+	/* create initial bit pattern of workload queue blocks */
+	MARS_BITS_SET(&bits, STATE, MARS_WORKLOAD_STATE_NONE);
 
-	for (index = 0; index < MARS_WORKLOAD_PER_BLOCK; index++)
-		block->bits[index] = initial_bits;
+	/* other bits are set by mars_workload_queue_schedule_begin properly */
 
-	mars_ea_put(block_ea, block, sizeof(struct mars_workload_queue_block));
-	mars_mutex_reset(block_ea);
+	/* initialize workload queue blocks */
+	for (block = 0; block < MARS_WORKLOAD_NUM_BLOCKS; block++) {
+		uint64_t block_ea = get_block_ea(queue_ea, block);
+		queue_block = mars_ea_work_area_get(
+				block_ea, MARS_WORKLOAD_QUEUE_BLOCK_ALIGN,
+				sizeof(struct mars_workload_queue_block));
+
+		for (index = 0; index < MARS_WORKLOAD_PER_BLOCK; index++)
+			queue_block->bits[index] = bits;
+
+		mars_ea_put(block_ea, queue_block,
+			    sizeof(struct mars_workload_queue_block));
+		mars_mutex_reset(block_ea);
+	}
 }
 
 int mars_workload_queue_create(struct mars_context *mars)
 {
-	int block;
 	uint64_t queue_ea;
-	uint64_t bits;
-	struct mars_workload_queue *queue;
 
 	/* check function params */
 	if (!mars)
@@ -107,30 +136,11 @@ int mars_workload_queue_create(struct ma
 	if (!queue_ea)
 		return MARS_ERROR_MEMORY;
 
-	/* prepare work area for queue header */
-	queue = mars_ea_work_area_get(queue_ea,
-		MARS_WORKLOAD_QUEUE_ALIGN,
-		sizeof(struct mars_workload_queue_header));
-
 	/* initialize workload queue header */
-	queue->header.flag = MARS_WORKLOAD_QUEUE_FLAG_NONE;
-	queue->header.queue_ea = queue_ea;
-	queue->header.context_ea =
-		queue_ea + offsetof(struct mars_workload_queue, context);
-
-	/* update queue header on EA */
-	mars_ea_put(queue_ea, queue, sizeof(struct mars_workload_queue_header));
-
-	/* create initial bit pattern of workload queue entries */
-	bits = 0;
-	MARS_BITS_SET(&bits, STATE, MARS_WORKLOAD_STATE_NONE);
-	/* other bits are set by mars_workload_queue_schedule_begin properly */
+	init_header(queue_ea);
 
 	/* initialize workload queue blocks */
-	for (block = 0; block < MARS_WORKLOAD_NUM_BLOCKS; block++) {
-		uint64_t block_ea = get_block_ea(queue_ea, block);
-		init_block(block_ea, bits);
-	}
+	init_blocks(queue_ea);
 
 	/* sync EA */
 	mars_ea_sync();
@@ -287,7 +297,8 @@ static int change_bits(struct mars_conte
 		       int (*check_bits)(uint64_t bits, uint64_t param),
 		       uint64_t check_bits_param,
 		       uint64_t (*set_bits)(uint64_t bits, uint64_t param),
-		       uint64_t set_bits_param)
+		       uint64_t set_bits_param,
+		       void (*callback)(struct mars_context *mars, uint16_t id))
 {
 	int block;
 	int index;
@@ -331,6 +342,10 @@ static int change_bits(struct mars_conte
 	/* store new bits into queue block */
 	mars_ea_put_uint64(bits_ea, bits);
 
+	/* if callback requested call it */
+	if (callback)
+		(*callback)(mars, id);
+
 	mars_mutex_unlock(block_ea);
 
 	/* if requested set workload context pointer to return */
@@ -345,6 +360,11 @@ static int check_state_bits(uint64_t bit
 	return (MARS_BITS_GET(&bits, STATE) == state);
 }
 
+static int check_state_bits_not(uint64_t bits, uint64_t state)
+{
+	return (MARS_BITS_GET(&bits, STATE) != state);
+}
+
 static uint64_t set_state_bits(uint64_t bits, uint64_t state)
 {
 	MARS_BITS_SET(&bits, STATE, state);
@@ -352,15 +372,18 @@ static uint64_t set_state_bits(uint64_t 
 	return bits;
 }
 
-static int change_state(struct mars_context *mars,
-			uint16_t id,
-			uint64_t *workload_ea,
-			unsigned int old_state,
-			unsigned int new_state)
+static int change_state(
+		struct mars_context *mars,
+		uint16_t id,
+		uint64_t *workload_ea,
+		unsigned int old_state,
+		unsigned int new_state,
+		void (*callback)(struct mars_context *mars, uint16_t id))
 {
 	return change_bits(mars, id, workload_ea,
 			   check_state_bits, old_state,
-			   set_state_bits, new_state);
+			   set_state_bits, new_state,
+			   callback);
 }
 
 int mars_workload_queue_add_end(struct mars_context *mars,
@@ -368,7 +391,8 @@ int mars_workload_queue_add_end(struct m
 {
 	return change_state(mars, id, NULL,
 			    MARS_WORKLOAD_STATE_ADDING,
-			    MARS_WORKLOAD_STATE_FINISHED);
+			    MARS_WORKLOAD_STATE_FINISHED,
+			    NULL);
 }
 
 int mars_workload_queue_add_cancel(struct mars_context *mars,
@@ -376,7 +400,8 @@ int mars_workload_queue_add_cancel(struc
 {
 	return change_state(mars, id, NULL,
 			    MARS_WORKLOAD_STATE_ADDING,
-			    MARS_WORKLOAD_STATE_NONE);
+			    MARS_WORKLOAD_STATE_NONE,
+			    NULL);
 }
 
 int mars_workload_queue_remove_begin(struct mars_context *mars,
@@ -385,7 +410,8 @@ int mars_workload_queue_remove_begin(str
 {
 	return change_state(mars, id, workload_ea,
 			    MARS_WORKLOAD_STATE_FINISHED,
-			    MARS_WORKLOAD_STATE_REMOVING);
+			    MARS_WORKLOAD_STATE_REMOVING,
+			    NULL);
 }
 
 int mars_workload_queue_remove_end(struct mars_context *mars,
@@ -393,7 +419,8 @@ int mars_workload_queue_remove_end(struc
 {
 	return change_state(mars, id, NULL,
 			    MARS_WORKLOAD_STATE_REMOVING,
-			    MARS_WORKLOAD_STATE_NONE);
+			    MARS_WORKLOAD_STATE_NONE,
+			    NULL);
 }
 
 int mars_workload_queue_remove_cancel(struct mars_context *mars,
@@ -401,11 +428,13 @@ int mars_workload_queue_remove_cancel(st
 {
 	return change_state(mars, id, NULL,
 			    MARS_WORKLOAD_STATE_REMOVING,
-			    MARS_WORKLOAD_STATE_FINISHED);
+			    MARS_WORKLOAD_STATE_FINISHED,
+			    NULL);
 }
 
 static uint64_t set_schedule_bits(uint64_t bits, uint64_t priority)
 {
+	/* set the info bits inside queue block for this workload */
 	MARS_BITS_SET(&bits, STATE, MARS_WORKLOAD_STATE_SCHEDULING);
 	MARS_BITS_SET(&bits, PRIORITY, priority);
 	MARS_BITS_SET(&bits, COUNTER, MARS_WORKLOAD_COUNTER_MIN);
@@ -421,7 +450,8 @@ int mars_workload_queue_schedule_begin(s
 {
 	return change_bits(mars, id, workload_ea,
 			   check_state_bits, MARS_WORKLOAD_STATE_FINISHED,
-			   set_schedule_bits, priority);
+			   set_schedule_bits, priority,
+			   NULL);
 }
 
 int mars_workload_queue_schedule_end(struct mars_context *mars,
@@ -429,7 +459,8 @@ int mars_workload_queue_schedule_end(str
 {
 	return change_state(mars, id, NULL,
 			    MARS_WORKLOAD_STATE_SCHEDULING,
-			    MARS_WORKLOAD_STATE_READY);
+			    MARS_WORKLOAD_STATE_READY,
+			    NULL);
 }
 
 int mars_workload_queue_schedule_cancel(struct mars_context *mars,
@@ -437,7 +468,8 @@ int mars_workload_queue_schedule_cancel(
 {
 	return change_state(mars, id, NULL,
 			    MARS_WORKLOAD_STATE_SCHEDULING,
-			    MARS_WORKLOAD_STATE_FINISHED);
+			    MARS_WORKLOAD_STATE_FINISHED,
+			    NULL);
 }
 
 static int is_workload_finished(uint32_t upper, void *param)
@@ -519,16 +551,9 @@ int mars_workload_queue_try_wait(struct 
 	return workload_queue_wait(mars, id, 1, workload_ea);
 }
 
-static int check_signal_bits(uint64_t bits, uint64_t params)
-{
-	(void)params;
-
-	return (MARS_BITS_GET(&bits, STATE) != MARS_WORKLOAD_STATE_NONE);
-}
-
-static uint64_t set_signal_bits(uint64_t bits, uint64_t value)
+static uint64_t set_signal_bits(uint64_t bits, uint64_t signal)
 {
-	MARS_BITS_SET(&bits, SIGNAL, value);
+	MARS_BITS_SET(&bits, SIGNAL, signal);
 
 	return bits;
 }
@@ -537,6 +562,7 @@ int mars_workload_queue_signal_send(stru
 				    uint16_t id)
 {
 	return change_bits(mars, id, NULL,
-			   check_signal_bits, 0,
-			   set_signal_bits, MARS_WORKLOAD_SIGNAL_ON);
+			   check_state_bits_not, MARS_WORKLOAD_STATE_NONE,
+			   set_signal_bits, MARS_WORKLOAD_SIGNAL_ON,
+			   NULL);
 }







More information about the cbe-oss-dev mailing list