diff options
author | Yuji Mano <yuji.mano@am.sony.com> | 2009-03-19 13:54:46 -0700 |
---|---|---|
committer | Yuji Mano <yuji.mano@am.sony.com> | 2009-03-23 12:20:52 -0700 |
commit | c5fcfc5ee25f24e8ec071e2e9a0907ec9cfd0730 (patch) | |
tree | c7f4c7b62f08a4577ff79d5b1b507c3ed46ba014 | |
parent | f0cce3535783388e4e7e3c858c7ff2d20b82748a (diff) | |
download | mars-src-c5fcfc5ee25f24e8ec071e2e9a0907ec9cfd0730.tar.gz |
task: Remove memmove usage
This patch removes the use of memmove from task semaphore and queue
implementations and uses a circular buffer for storing the wait id's to improve
performance and reduce code size.
Signed-off-by: Yuji Mano <yuji.mano@am.sony.com>
Acked-by: Kazunori Asayama <asayama@sm.sony.co.jp>
-rw-r--r-- | task/include/common/mars/task_semaphore_types.h | 2 | ||||
-rw-r--r-- | task/src/common/task_queue_internal_types.h | 4 | ||||
-rw-r--r-- | task/src/common/task_semaphore_internal_types.h | 2 | ||||
-rw-r--r-- | task/src/host/lib/task_queue.c | 20 | ||||
-rw-r--r-- | task/src/host/lib/task_semaphore.c | 3 | ||||
-rw-r--r-- | task/src/mpu/lib/task_queue.c | 30 | ||||
-rw-r--r-- | task/src/mpu/lib/task_semaphore.c | 16 |
7 files changed, 43 insertions, 34 deletions
diff --git a/task/include/common/mars/task_semaphore_types.h b/task/include/common/mars/task_semaphore_types.h index b59aacc..2200804 100644 --- a/task/include/common/mars/task_semaphore_types.h +++ b/task/include/common/mars/task_semaphore_types.h @@ -48,7 +48,7 @@ * \ingroup group_mars_task_semaphore * \brief Maximum task accesses allowed for single semaphore */ -#define MARS_TASK_SEMAPHORE_WAIT_MAX 55 +#define MARS_TASK_SEMAPHORE_WAIT_MAX 54 /** * \ingroup group_mars_task_semaphore diff --git a/task/src/common/task_queue_internal_types.h b/task/src/common/task_queue_internal_types.h index 0cb8fcd..f14afdf 100644 --- a/task/src/common/task_queue_internal_types.h +++ b/task/src/common/task_queue_internal_types.h @@ -57,8 +57,10 @@ struct mars_task_queue { uint64_t buffer_ea; uint64_t push_ea; uint64_t pop_ea; + uint8_t pad; uint8_t direction; - uint8_t pad[3]; + uint8_t push_wait_head; + uint8_t pop_wait_head; uint16_t push_wait_count; uint16_t pop_wait_count; uint16_t push_wait_id[MARS_TASK_QUEUE_WAIT_MAX]; diff --git a/task/src/common/task_semaphore_internal_types.h b/task/src/common/task_semaphore_internal_types.h index 3fb7387..816ab75 100644 --- a/task/src/common/task_semaphore_internal_types.h +++ b/task/src/common/task_semaphore_internal_types.h @@ -49,6 +49,8 @@ struct mars_task_semaphore { int32_t count; uint16_t wait_count; uint16_t wait_id[MARS_TASK_SEMAPHORE_WAIT_MAX]; + uint8_t wait_head; + uint8_t pad; uint64_t mars_context_ea; } __attribute__((aligned(MARS_TASK_SEMAPHORE_ALIGN))); diff --git a/task/src/host/lib/task_queue.c b/task/src/host/lib/task_queue.c index 149c65a..cceed90 100644 --- a/task/src/host/lib/task_queue.c +++ b/task/src/host/lib/task_queue.c @@ -35,8 +35,6 @@ * LIBRARY OR THE USE OR OTHER DEALINGS IN THE LIBRARY. */ -#include <string.h> - #include "config.h" #include <mars/base.h> @@ -108,6 +106,8 @@ int mars_task_queue_create(struct mars_context *mars, queue->count = 0; queue->push_wait_count = 0; queue->pop_wait_count = 0; + queue->push_wait_head = 0; + queue->pop_wait_head = 0; /* update queue on EA */ mars_ea_put(queue_ea, queue, MARS_TASK_QUEUE_SIZE); @@ -210,13 +210,13 @@ static void push_update(struct mars_task_queue *queue) /* signal waiting task that queue is ready for pop */ if (queue->pop_wait_count) { /* signal waiting task */ - mars_workload_queue_signal_send(mars, queue->pop_wait_id[0]); + mars_workload_queue_signal_send(mars, + queue->pop_wait_id[queue->pop_wait_head]); /* flush id from pop wait list */ queue->pop_wait_count--; - memmove(&queue->pop_wait_id[0], - &queue->pop_wait_id[1], - sizeof(uint16_t) * queue->pop_wait_count); + queue->pop_wait_head++; + queue->pop_wait_head %= MARS_TASK_QUEUE_WAIT_MAX; } /* increment queue count */ @@ -307,13 +307,13 @@ static void pop_update(struct mars_task_queue *queue) /* signal waiting task that queue is ready for push */ if (queue->push_wait_count) { /* signal waiting task */ - mars_workload_queue_signal_send(mars, queue->push_wait_id[0]); + mars_workload_queue_signal_send(mars, + queue->push_wait_id[queue->push_wait_head]); /* flush id from push wait list */ queue->push_wait_count--; - memmove(&queue->push_wait_id[0], - &queue->push_wait_id[1], - sizeof(uint16_t) * queue->push_wait_count); + queue->push_wait_head++; + queue->push_wait_head %= MARS_TASK_QUEUE_WAIT_MAX; } /* decrement queue count */ diff --git a/task/src/host/lib/task_semaphore.c b/task/src/host/lib/task_semaphore.c index 545af09..4ebfa5a 100644 --- a/task/src/host/lib/task_semaphore.c +++ b/task/src/host/lib/task_semaphore.c @@ -35,8 +35,6 @@ * LIBRARY OR THE USE OR OTHER DEALINGS IN THE LIBRARY. */ -#include <stdlib.h> - #include "config.h" #include <mars/base.h> @@ -75,6 +73,7 @@ int mars_task_semaphore_create(struct mars_context *mars, semaphore->mars_context_ea = mars_ptr_to_ea(mars); semaphore->count = count; semaphore->wait_count = 0; + semaphore->wait_head = 0; /* update semaphore on EA */ mars_ea_put(semaphore_ea, semaphore, MARS_TASK_SEMAPHORE_SIZE); diff --git a/task/src/mpu/lib/task_queue.c b/task/src/mpu/lib/task_queue.c index 68cd001..51cbbb4 100644 --- a/task/src/mpu/lib/task_queue.c +++ b/task/src/mpu/lib/task_queue.c @@ -36,7 +36,6 @@ */ #include <stddef.h> -#include <string.h> #include "config.h" @@ -125,13 +124,13 @@ static int push_update(void) /* signal waiting task that queue is ready for pop */ if (queue.pop_wait_count) { /* signal waiting task */ - mars_task_module_signal_send(queue.pop_wait_id[0]); + mars_task_module_signal_send( + queue.pop_wait_id[queue.pop_wait_head]); /* flush id from pop wait list */ queue.pop_wait_count--; - memmove(&queue.pop_wait_id[0], - &queue.pop_wait_id[1], - sizeof(uint16_t) * queue.pop_wait_count); + queue.pop_wait_head++; + queue.pop_wait_head %= MARS_TASK_QUEUE_WAIT_MAX; } /* increment queue count */ @@ -181,6 +180,8 @@ static int push(uint64_t queue_ea, const void *data, /* queue is full so wait */ while (queue.count == queue.depth) { + uint8_t push_wait_tail; + /* only try so return busy */ if (try) { mars_mutex_unlock_put(queue_ea, @@ -196,8 +197,9 @@ static int push(uint64_t queue_ea, const void *data, } /* add id to push wait list */ - queue.push_wait_id[queue.push_wait_count] = - task->id.workload_id; + push_wait_tail = (queue.push_wait_head + queue.push_wait_count) + % MARS_TASK_QUEUE_WAIT_MAX; + queue.push_wait_id[push_wait_tail] = task->id.workload_id; queue.push_wait_count++; mars_mutex_unlock_put(queue_ea, (struct mars_mutex *)&queue); @@ -294,13 +296,13 @@ static int pop_update(void) /* signal waiting task that queue is ready for push */ if (queue.push_wait_count) { /* signal waiting task */ - mars_task_module_signal_send(queue.push_wait_id[0]); + mars_task_module_signal_send( + queue.push_wait_id[queue.push_wait_head]); /* flush id from push wait list */ queue.push_wait_count--; - memmove(&queue.push_wait_id[0], - &queue.push_wait_id[1], - sizeof(uint16_t) * queue.push_wait_count); + queue.push_wait_head++; + queue.push_wait_head %= MARS_TASK_QUEUE_WAIT_MAX; } /* decrement queue count */ @@ -350,6 +352,8 @@ static int pop(uint64_t queue_ea, void *data, /* queue is empty so wait */ while (!queue.count) { + uint8_t pop_wait_tail; + /* only try so return busy */ if (try) { mars_mutex_unlock_put(queue_ea, @@ -365,7 +369,9 @@ static int pop(uint64_t queue_ea, void *data, } /* add id to pop wait list */ - queue.pop_wait_id[queue.pop_wait_count] = task->id.workload_id; + pop_wait_tail = (queue.pop_wait_head + queue.pop_wait_count) + % MARS_TASK_QUEUE_WAIT_MAX; + queue.pop_wait_id[pop_wait_tail] = task->id.workload_id; queue.pop_wait_count++; mars_mutex_unlock_put(queue_ea, (struct mars_mutex *)&queue); diff --git a/task/src/mpu/lib/task_semaphore.c b/task/src/mpu/lib/task_semaphore.c index 842651a..a39e6f4 100644 --- a/task/src/mpu/lib/task_semaphore.c +++ b/task/src/mpu/lib/task_semaphore.c @@ -35,9 +35,6 @@ * LIBRARY OR THE USE OR OTHER DEALINGS IN THE LIBRARY. */ -#include <stdlib.h> -#include <string.h> - #include "config.h" #include <mars/error.h> @@ -78,8 +75,11 @@ int mars_task_semaphore_acquire(uint64_t semaphore_ea) } if (semaphore.count <= 0) { + uint8_t wait_tail = (semaphore.wait_head + semaphore.wait_count) + % MARS_TASK_SEMAPHORE_WAIT_MAX; + /* add id to wait list */ - semaphore.wait_id[semaphore.wait_count] = task->id.workload_id; + semaphore.wait_id[wait_tail] = task->id.workload_id; semaphore.wait_count++; mars_mutex_unlock_put(semaphore_ea, @@ -118,13 +118,13 @@ int mars_task_semaphore_release(uint64_t semaphore_ea) semaphore.count--; /* signal waiting task */ - mars_task_module_signal_send(semaphore.wait_id[0]); + mars_task_module_signal_send( + semaphore.wait_id[semaphore.wait_head]); /* flush id from wait list */ semaphore.wait_count--; - memmove(&semaphore.wait_id[0], - &semaphore.wait_id[1], - sizeof(uint16_t) * semaphore.wait_count); + semaphore.wait_head++; + semaphore.wait_head %= MARS_TASK_SEMAPHORE_WAIT_MAX; } mars_mutex_unlock_put(semaphore_ea, (struct mars_mutex *)&semaphore); |