diff options
author | Yuji Mano <yuji.mano@am.sony.com> | 2009-02-09 12:26:20 -0800 |
---|---|---|
committer | Yuji Mano <yuji.mano@am.sony.com> | 2009-02-11 11:04:16 -0800 |
commit | 0ecc3b735f194baf6f50b2dbe0c0e2315bd53257 (patch) | |
tree | cb524ac5dd9929f6d733d5adb799cd62bfe663e7 | |
parent | eef565c951c86501740861d02fe46b2fbbce10ea (diff) | |
download | mars-src-0ecc3b735f194baf6f50b2dbe0c0e2315bd53257.tar.gz |
base: Workload queue cleanup
This cleans up some of the workload queue code in preparation for following
patches.
Signed-off-by: Yuji Mano <yuji.mano@am.sony.com>
Acked-by: Kazunori Asayama <asayama@sm.sony.co.jp>
-rw-r--r-- | base/src/host/lib/workload_queue.c | 139 |
1 files changed, 86 insertions, 53 deletions
diff --git a/base/src/host/lib/workload_queue.c b/base/src/host/lib/workload_queue.c index 2ff60af..677a6bc 100644 --- a/base/src/host/lib/workload_queue.c +++ b/base/src/host/lib/workload_queue.c @@ -72,6 +72,25 @@ static inline uint64_t get_block_bits_ea(uint64_t block_ea, int index) sizeof(uint64_t) * index; } +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_block(uint64_t block_ea, uint64_t initial_bits) { int index; @@ -83,16 +102,34 @@ static void init_block(uint64_t block_ea, uint64_t initial_bits) for (index = 0; index < MARS_WORKLOAD_PER_BLOCK; index++) block->bits[index] = initial_bits; + /* update queue block on EA */ mars_ea_put(block_ea, block, sizeof(struct mars_workload_queue_block)); + + /* reset mutex portion of queue block */ mars_mutex_reset(block_ea); } -int mars_workload_queue_create(struct mars_context *mars) +static void init_blocks(uint64_t queue_ea) { int block; + uint64_t bits = 0; + + /* create initial bit pattern of workload queue blocks */ + MARS_BITS_SET(&bits, STATE, MARS_WORKLOAD_STATE_NONE); + + /* other bits are set by mars_workload_queue_schedule_begin properly */ + + /* 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); + } +} + +int mars_workload_queue_create(struct mars_context *mars) +{ uint64_t queue_ea; - uint64_t bits; - struct mars_workload_queue *queue; /* check function params */ if (!mars) @@ -101,36 +138,16 @@ int mars_workload_queue_create(struct mars_context *mars) return MARS_ERROR_STATE; /* allocate workload instance */ - queue_ea = mars_ea_memalign( - MARS_WORKLOAD_QUEUE_ALIGN, - sizeof(struct mars_workload_queue)); + queue_ea = mars_ea_memalign(MARS_WORKLOAD_QUEUE_ALIGN, + sizeof(struct mars_workload_queue)); 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 +304,8 @@ static int change_bits(struct mars_context *mars, 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 +349,10 @@ static int change_bits(struct mars_context *mars, /* 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 +367,11 @@ static int check_state_bits(uint64_t bits, uint64_t state) 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 +379,18 @@ static uint64_t set_state_bits(uint64_t bits, uint64_t state) 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 +398,8 @@ int mars_workload_queue_add_end(struct mars_context *mars, { 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 +407,8 @@ int mars_workload_queue_add_cancel(struct mars_context *mars, { 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 +417,8 @@ int mars_workload_queue_remove_begin(struct mars_context *mars, { 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 +426,8 @@ int mars_workload_queue_remove_end(struct mars_context *mars, { 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 +435,13 @@ int mars_workload_queue_remove_cancel(struct mars_context *mars, { 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 +457,8 @@ int mars_workload_queue_schedule_begin(struct mars_context *mars, { 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 +466,8 @@ int mars_workload_queue_schedule_end(struct mars_context *mars, { 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 +475,8 @@ int mars_workload_queue_schedule_cancel(struct mars_context *mars, { 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 +558,9 @@ int mars_workload_queue_try_wait(struct mars_context *mars, 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 +569,7 @@ int mars_workload_queue_signal_send(struct mars_context *mars, 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); } |