[Cbe-oss-dev] [PATCH 8/10] MARS: workload counter use defines and prevent overflow
Yuji Mano
Yuji.Mano at am.sony.com
Wed Aug 6 04:54:46 EST 2008
This defines new macros for workload counter min/max, increases the workload
counter size, and prevents integer wraparound/overflow.
Signed-off-by: Yuji Mano <yuji.mano at am.sony.com>
---
include/common/mars/mars_workload_types.h | 5 ++++-
src/host/lib/mars_workload_queue.c | 6 +++---
src/mpu/kernel/mars_kernel_scheduler.c | 5 +++--
src/mpu/kernel/mars_kernel_workload.c | 2 +-
4 files changed, 11 insertions(+), 7 deletions(-)
--- a/include/common/mars/mars_workload_types.h
+++ b/include/common/mars/mars_workload_types.h
@@ -59,6 +59,9 @@ extern "C" {
#define MARS_WORKLOAD_PRIORITY_MIN 0x00 /* minimum priority */
#define MARS_WORKLOAD_PRIORITY_MAX 0xff /* maximum priority */
+#define MARS_WORKLOAD_COUNTER_MIN 0x0000 /* minimum counter */
+#define MARS_WORKLOAD_COUNTER_MAX 0xffff /* maximum counter */
+
#define MARS_WORKLOAD_MAX 1024 /* wl max */
#define MARS_WORKLOAD_PER_BLOCK 16 /* wl per block */
#define MARS_WORKLOAD_NUM_BLOCKS 64 /* wl max / per block */
@@ -88,7 +91,7 @@ struct mars_workload_queue_header {
struct mars_workload_queue_block {
uint8_t state[MARS_WORKLOAD_PER_BLOCK];
uint8_t priority[MARS_WORKLOAD_PER_BLOCK];
- uint8_t counter[MARS_WORKLOAD_PER_BLOCK];
+ uint16_t counter[MARS_WORKLOAD_PER_BLOCK];
uint8_t signal[MARS_WORKLOAD_PER_BLOCK];
uint16_t wait[MARS_WORKLOAD_PER_BLOCK];
} __attribute__((aligned(MARS_WORKLOAD_QUEUE_BLOCK_ALIGN)));
--- a/src/host/lib/mars_workload_queue.c
+++ b/src/host/lib/mars_workload_queue.c
@@ -110,7 +110,7 @@ int workload_queue_add(struct mars_workl
/* update workload queue header info */
queue->block[block].state[index] = MARS_WORKLOAD_STATE_FINISHED;
queue->block[block].priority[index] = MARS_WORKLOAD_PRIORITY_MIN;
- queue->block[block].counter[index] = 0;
+ queue->block[block].counter[index] = MARS_WORKLOAD_COUNTER_MIN;
queue->block[block].signal[index] = 0;
queue->block[block].wait[index] = MARS_WORKLOAD_ID_NONE;
queue->header.count++;
@@ -138,7 +138,7 @@ int workload_queue_remove(struct mars_wo
/* update workload queue info */
queue->block[block].state[index] = MARS_WORKLOAD_STATE_NONE;
queue->block[block].priority[index] = MARS_WORKLOAD_PRIORITY_MIN;
- queue->block[block].counter[index] = 0;
+ queue->block[block].counter[index] = MARS_WORKLOAD_COUNTER_MIN;
queue->block[block].signal[index] = 0;
queue->block[block].wait[index] = MARS_WORKLOAD_ID_NONE;
queue->header.count--;
@@ -178,7 +178,7 @@ int workload_queue_schedule(struct mars_
queue->block[block].state[index] = MARS_WORKLOAD_STATE_READY;
queue->block[block].priority[index] = priority;
- queue->block[block].counter[index] = 0;
+ queue->block[block].counter[index] = MARS_WORKLOAD_COUNTER_MIN;
queue->block[block].signal[index] = 0;
queue->block[block].wait[index] = MARS_WORKLOAD_ID_NONE;
--- a/src/mpu/kernel/mars_kernel_scheduler.c
+++ b/src/mpu/kernel/mars_kernel_scheduler.c
@@ -73,7 +73,8 @@ static int search_block(struct mars_work
index = i;
max_count = block->counter[i];
}
- block->counter[i]++;
+ if (block->counter[i] < MARS_WORKLOAD_COUNTER_MAX)
+ block->counter[i]++;
break;
case MARS_WORKLOAD_STATE_WAITING:
if (block->wait[i] != MARS_WORKLOAD_ID_NONE) {
@@ -131,7 +132,7 @@ static int reserve_block(int block)
queue_block.state[index] = MARS_WORKLOAD_STATE_RUNNING;
/* reset the counter for reserved workload */
- queue_block.counter[index] = 0;
+ queue_block.counter[index] = MARS_WORKLOAD_COUNTER_MIN;
}
/* attempt to write back workload queue block to cache line */
--- a/src/mpu/kernel/mars_kernel_workload.c
+++ b/src/mpu/kernel/mars_kernel_workload.c
@@ -173,7 +173,7 @@ int workload_schedule(uint16_t workload_
queue_block.state[index] = MARS_WORKLOAD_STATE_READY;
queue_block.priority[index] = priority;
- queue_block.counter[index] = 0;
+ queue_block.counter[index] = MARS_WORKLOAD_COUNTER_MIN;
queue_block.signal[index] = 0;
queue_block.wait[index] = MARS_WORKLOAD_ID_NONE;
More information about the cbe-oss-dev
mailing list