aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazunori Asayama <asayama@sm.sony.co.jp>2009-02-11 11:42:19 -0800
committerYuji Mano <yuji.mano@am.sony.com>2009-02-11 11:42:19 -0800
commit28a8d5ac0b7758e07e28638fc763d2639647ba4f (patch)
treef7f256e5f2ba6a6a1855f79f53493d6ea708df29
parentffb47a8d4dd36d63fa0accf1f94fecf0a012fffe (diff)
downloadmars-src-28a8d5ac0b7758e07e28638fc763d2639647ba4f.tar.gz
samples: Fix measurement partial context save
Fix measurement of partial context save sample's performance The sample 'partial_context_save' doesn't show actual performance of context save since it calls a number of MARS API functions and 'printf' during the measurement. This patch modifies the sample so it can measure correct performance of context save, by eliminating extra function calls during the measurement. Signed-off-by: Kazunori Asayama <asayama@sm.sony.co.jp> Signed-off-by: Yuji Mano <yuji.mano@am.sony.com>
-rw-r--r--samples/partial_context_save/host.c61
-rw-r--r--samples/partial_context_save/mpu_task.c30
2 files changed, 44 insertions, 47 deletions
diff --git a/samples/partial_context_save/host.c b/samples/partial_context_save/host.c
index 34029f3..3c5f286 100644
--- a/samples/partial_context_save/host.c
+++ b/samples/partial_context_save/host.c
@@ -30,57 +30,41 @@
"\
MARS Partial Context Save Sample \n\
-------------------------------- \n\
-This program is a simple example to show how to create and \n\
-execute a task that does context switches optimized by \n\
-specifying partial context save paramters during task creation. \n\
+This program is a simple example to show how a task's context \n\
+switching is optimized by the task module's partial context \n\
+switching feature. The task module calculates how much of the \n\
+MPU storage is being used by the task and only saves and \n\
+restores the used areas of the MPU storage. \n\
\n\
-The task being run in this program is a very simple MPU \n\
-program that yields to perform a context switch. \n\
+The task being run in this program is a very simple MPU program \n\
+that yields to perform a context switch. \n\
\n\
-The first time the task is created and run, a full context \n\
-switch is specified. \n\
+The first time the task is created and run, almost all MPU \n\
+storage is consumed. \n\
\n\
-The second time the task is created and run, a partial context \n\
-switch is specified. \n\
+The second time the task is created and run, only small part of \n\
+MPU storage is consumed. \n\
\n"
-#define TIMER_START(timer)\
-{\
- struct timeval tv;\
- gettimeofday(&tv, NULL);\
- timer = tv.tv_sec * 1000000 + tv.tv_usec;\
-}
-
-#define TIMER_STOP(timer)\
-{\
- struct timeval tv;\
- gettimeofday(&tv, NULL);\
- timer = tv.tv_sec * 1000000 + tv.tv_usec - timer;\
-}
-
extern struct spe_program_handle mpu_task_prog;
static struct mars_context *mars_ctx;
static struct mars_task_id task_id;
-static struct mars_task_context_save_unit MARS_TASK_CONTEXT_SAVE_PARTIAL[] =
-{
- { .addr = 0, .size = 0x10000 },
- { .addr = MARS_TASK_CONTEXT_SAVE_SIZE_MAX - 0x12000, .size = 0x12000 },
- { .addr = 0, .size = 0 },
-};
-int run_task_switch(const struct mars_task_context_save_unit *context_save_unit)
+int run_task_switch(uint32_t dummy_data_size)
{
int ret;
+ struct mars_task_args task_args;
ret = mars_task_create(mars_ctx, &task_id, "Task",
- mpu_task_prog.elf_image, context_save_unit);
+ mpu_task_prog.elf_image, MARS_TASK_CONTEXT_SAVE_SIZE_MAX);
if (ret) {
printf("MARS task create failed! (%d)\n", ret);
return 1;
}
- ret = mars_task_schedule(&task_id, NULL, 0);
+ task_args.type.u32[0] = dummy_data_size;
+ ret = mars_task_schedule(&task_id, &task_args, 0);
if (ret) {
printf("MARS task schedule failed! (%d)\n", ret);
return 1;
@@ -104,7 +88,6 @@ int run_task_switch(const struct mars_task_context_save_unit *context_save_unit)
int main(void)
{
int ret;
- unsigned long long timer;
printf(INFO);
@@ -114,19 +97,15 @@ int main(void)
return 1;
}
- TIMER_START(timer);
- ret = run_task_switch(MARS_TASK_CONTEXT_SAVE_ALL);
+ printf("\nNearly Full Context Save\n");
+ ret = run_task_switch(MARS_TASK_CONTEXT_SAVE_SIZE_MAX - 1024 * 16);
if (ret)
return 1;
- TIMER_STOP(timer);
- printf("Full Context Save took - %.0f us\n\n", (float)timer);
- TIMER_START(timer);
- ret = run_task_switch(MARS_TASK_CONTEXT_SAVE_PARTIAL);
+ printf("\nPartial Context Save\n");
+ ret = run_task_switch(0);
if (ret)
return 1;
- TIMER_STOP(timer);
- printf("Partial Context Save took - %.0f us\n", (float)timer);
ret = mars_context_destroy(mars_ctx);
if (ret) {
diff --git a/samples/partial_context_save/mpu_task.c b/samples/partial_context_save/mpu_task.c
index 2652cd9..ef61c59 100644
--- a/samples/partial_context_save/mpu_task.c
+++ b/samples/partial_context_save/mpu_task.c
@@ -22,19 +22,37 @@
*/
#include <stdio.h>
+#include <stdlib.h>
#include <mars/mars.h>
+#define ITERATIONS 10
+
int mars_task_main(const struct mars_task_args *task_args)
{
- (void)task_args;
+ int i;
+ uint32_t kernel_id_start[ITERATIONS], kernel_id_end[ITERATIONS];
+ uint32_t ticks_start[ITERATIONS], ticks_end[ITERATIONS];
+
+ if (task_args->type.u32[0]) {
+ malloc(task_args->type.u32[0]);
+ }
+
+ for (i = 0; i < ITERATIONS; i++) {
+ kernel_id_start[i] = mars_task_get_kernel_id();
+ ticks_start[i] = mars_task_get_ticks();
- printf("MPU(%d): %s - Started\n",
- mars_task_get_kernel_id(), mars_task_get_name());
+ mars_task_yield();
- mars_task_yield();
+ ticks_end[i] = mars_task_get_ticks();
+ kernel_id_end[i] = mars_task_get_kernel_id();
+ }
- printf("MPU(%d): %s - Finished\n",
- mars_task_get_kernel_id(), mars_task_get_name());
+ for (i = 0; i < ITERATIONS; i++) {
+ printf("MPU(%d) => MPU(%d): %s: %d ticks%s\n",
+ kernel_id_start[i], kernel_id_end[i],
+ mars_task_get_name(), ticks_end[i] - ticks_start[i],
+ (i == 0 || kernel_id_start[i] != kernel_id_end[i]) ? " (unreliable)" : "");
+ }
return 0;
}