[Cbe-oss-dev] [PATCH 08/23]MARS/base: workload queue cleanup
Yuji Mano
yuji.mano at am.sony.com
Sat Mar 14 12:18:28 EST 2009
This just moves some static functions in the workload queue implementation in
preparation for patches in series.
Signed-off-by: Yuji Mano <yuji.mano at am.sony.com>
---
base/src/host/lib/workload_queue.c | 192 ++++++++++++++++++-------------------
1 file changed, 97 insertions(+), 95 deletions(-)
--- a/base/src/host/lib/workload_queue.c
+++ b/base/src/host/lib/workload_queue.c
@@ -72,6 +72,101 @@ static inline uint64_t get_block_bits_ea
sizeof(uint64_t) * index;
}
+static int change_bits(struct mars_context *mars,
+ uint16_t id,
+ uint64_t *workload_ea,
+ 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,
+ void (*callback)(struct mars_context *mars, uint16_t id))
+{
+ int block;
+ int index;
+ uint64_t queue_ea;
+ uint64_t block_ea;
+ uint64_t bits_ea;
+ uint64_t bits;
+
+ /* check function params */
+ if (!mars)
+ return MARS_ERROR_NULL;
+ if (!mars->workload_queue_ea)
+ return MARS_ERROR_PARAMS;
+ if (id >= MARS_WORKLOAD_MAX)
+ return MARS_ERROR_PARAMS;
+
+ queue_ea = mars->workload_queue_ea;
+
+ /* calculate block/index from id */
+ block = id / MARS_WORKLOAD_PER_BLOCK;
+ index = id % MARS_WORKLOAD_PER_BLOCK;
+
+ /* prepare work area for queue block */
+ block_ea = get_block_ea(queue_ea, block);
+
+ mars_mutex_lock(block_ea);
+
+ /* get bits from workload queue block */
+ bits_ea = get_block_bits_ea(block_ea, index);
+ bits = mars_ea_get_uint64(bits_ea);
+
+ /* check for valid state */
+ if (!(*check_bits)(bits, check_bits_param)) {
+ mars_mutex_unlock(block_ea);
+ return MARS_ERROR_STATE;
+ }
+
+ /* reset workload queue bits and set state to new state */
+ bits = (*set_bits)(bits, set_bits_param);
+
+ /* 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 */
+ if (workload_ea)
+ *workload_ea = get_workload_ea(queue_ea, id);
+
+ return MARS_SUCCESS;
+}
+
+static int check_state_bits(uint64_t bits, uint64_t state)
+{
+ return (MARS_BITS_GET(&bits, WORKLOAD_STATE) == state);
+}
+
+static int check_state_bits_not(uint64_t bits, uint64_t state)
+{
+ return (MARS_BITS_GET(&bits, WORKLOAD_STATE) != state);
+}
+
+static uint64_t set_state_bits(uint64_t bits, uint64_t state)
+{
+ MARS_BITS_SET(&bits, WORKLOAD_STATE, 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,
+ 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,
+ callback);
+}
+
static void init_header(uint64_t queue_ea)
{
int block;
@@ -304,9 +399,11 @@ int mars_workload_queue_add_begin(struct
break;
}
+ /* no more free workload queue entry */
if (block >= MARS_WORKLOAD_NUM_BLOCKS)
return MARS_ERROR_LIMIT;
+ /* calculate and return workload id */
*id = block * MARS_WORKLOAD_PER_BLOCK + index;
/* if requested set workload context pointer to return */
@@ -316,101 +413,6 @@ int mars_workload_queue_add_begin(struct
return MARS_SUCCESS;
}
-static int change_bits(struct mars_context *mars,
- uint16_t id,
- uint64_t *workload_ea,
- 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,
- void (*callback)(struct mars_context *mars, uint16_t id))
-{
- int block;
- int index;
- uint64_t queue_ea;
- uint64_t block_ea;
- uint64_t bits_ea;
- uint64_t bits;
-
- /* check function params */
- if (!mars)
- return MARS_ERROR_NULL;
- if (!mars->workload_queue_ea)
- return MARS_ERROR_PARAMS;
- if (id >= MARS_WORKLOAD_MAX)
- return MARS_ERROR_PARAMS;
-
- queue_ea = mars->workload_queue_ea;
-
- /* calculate block/index from id */
- block = id / MARS_WORKLOAD_PER_BLOCK;
- index = id % MARS_WORKLOAD_PER_BLOCK;
-
- /* prepare work area for queue block */
- block_ea = get_block_ea(queue_ea, block);
-
- mars_mutex_lock(block_ea);
-
- /* get bits from workload queue block */
- bits_ea = get_block_bits_ea(block_ea, index);
- bits = mars_ea_get_uint64(bits_ea);
-
- /* check for valid state */
- if (!(*check_bits)(bits, check_bits_param)) {
- mars_mutex_unlock(block_ea);
- return MARS_ERROR_STATE;
- }
-
- /* reset workload queue bits and set state to new state */
- bits = (*set_bits)(bits, set_bits_param);
-
- /* 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 */
- if (workload_ea)
- *workload_ea = get_workload_ea(queue_ea, id);
-
- return MARS_SUCCESS;
-}
-
-static int check_state_bits(uint64_t bits, uint64_t state)
-{
- return (MARS_BITS_GET(&bits, WORKLOAD_STATE) == state);
-}
-
-static int check_state_bits_not(uint64_t bits, uint64_t state)
-{
- return (MARS_BITS_GET(&bits, WORKLOAD_STATE) != state);
-}
-
-static uint64_t set_state_bits(uint64_t bits, uint64_t state)
-{
- MARS_BITS_SET(&bits, WORKLOAD_STATE, 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,
- 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,
- callback);
-}
-
int mars_workload_queue_add_end(struct mars_context *mars,
uint16_t id)
{
More information about the cbe-oss-dev
mailing list