aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuji Mano <yuji.mano@am.sony.com>2009-03-26 17:32:17 -0700
committerYuji Mano <yuji.mano@am.sony.com>2009-03-26 17:32:17 -0700
commit48a72cc6c514ce6f46a028c6aa342552ab3487a3 (patch)
treef93682e18cbd757410ed998fb117045b20ba9707
parentef4494404273e2c419160497c7b7e970c9a72771 (diff)
downloadmars-src-48a72cc6c514ce6f46a028c6aa342552ab3487a3.tar.gz
samples: Add unschedule sample
-rw-r--r--samples/Makefile1
-rw-r--r--samples/README4
-rw-r--r--samples/schedule/host.c4
-rw-r--r--samples/unschedule/Makefile29
-rw-r--r--samples/unschedule/host.c153
-rw-r--r--samples/unschedule/mpu_task1.c88
-rw-r--r--samples/unschedule/mpu_task2.c58
7 files changed, 335 insertions, 2 deletions
diff --git a/samples/Makefile b/samples/Makefile
index ea19465..6de65f8 100644
--- a/samples/Makefile
+++ b/samples/Makefile
@@ -41,6 +41,7 @@ SUBDIRS = \
semaphore \
shared_context \
signal \
+ unschedule \
workload_module \
yield
diff --git a/samples/README b/samples/README
index 0e5f124..2fff680 100644
--- a/samples/README
+++ b/samples/README
@@ -101,6 +101,10 @@ explanations about each sample program are displayed when running the samples.
| synchronization between the host-processor main
| program and multiple MPU programs.
|
+|---/unschedule A simple example of how MARS tasks can be
+| unscheduled from execution from both the host or
+| from other MARS tasks.
+|
|---/workload_module A simple example of how to create a custom
| workload module.
|
diff --git a/samples/schedule/host.c b/samples/schedule/host.c
index bc81dd3..d1510b4 100644
--- a/samples/schedule/host.c
+++ b/samples/schedule/host.c
@@ -28,10 +28,10 @@
"\
MARS Task Schedule Sample \n\
------------------------ \n\
-This program shows the basic example of scheduling MARS tasks \n\
+This program shows the basic example of scheduling MARS tasks. \n\
Initialiazed tasks can be scheduled from both host and MPU \n\
\n\
-This program creates 2 different tasks. Once instance of \n\
+This program creates 2 different tasks. One instance of \n\
the first task is created and %d instances of the second \n\
task is created. \n\
\n\
diff --git a/samples/unschedule/Makefile b/samples/unschedule/Makefile
new file mode 100644
index 0000000..d4c92f9
--- /dev/null
+++ b/samples/unschedule/Makefile
@@ -0,0 +1,29 @@
+## Makefile
+#
+# Copyright 2008 Sony Corporation of America
+#
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+#
+
+sample = unschedule
+sample_objs = host.o mpu_task1.task_eo mpu_task2.task_eo
+
+include ../config.mk
+include ../rules.mk
diff --git a/samples/unschedule/host.c b/samples/unschedule/host.c
new file mode 100644
index 0000000..61d8343
--- /dev/null
+++ b/samples/unschedule/host.c
@@ -0,0 +1,153 @@
+/*
+ * Copyright 2008 Sony Corporation of America
+ *
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include <unistd.h>
+#include <libspe2.h>
+#include <mars/task.h>
+
+#define INFO \
+"\
+MARS Task Unschedule Sample \n\
+------------------------ \n\
+This program shows the basic example of unscheduling MARS tasks.\n\
+Scheduled tasks can be unscheduled from both host and MPU \n\
+ \n\
+This program creates 2 different tasks. One instance of \n\
+the first task is created and %d instances of the second \n\
+task is created. \n\
+ \n\
+The first task is scheduled for execution by the host. \n\
+The first task then schedules %d instances of the second \n\
+task for execution using the sub task's id's specified \n\
+by the arguments passed in by the host during scheduling. \n\
+The task then enters a wait state until sub tasks are finished. \n\
+ \n\
+The first sub task instance enters an infinite yielding loop. \n\
+The second sub task instance enters an infinite wait state. \n\
+ \n\
+Both the host and first task are waiting for one of the 2 sub \n\
+tasks to complete. Therefore, it is necessary for the host to \n\
+unschedule the first sub task so the first task can resume and \n\
+unschedule the second sub task so that both host and first task \n\
+can resume and complete the sample. \n\
+\n", NUM_TASKS, NUM_TASKS
+
+#define NUM_TASKS 2
+
+extern struct spe_program_handle mpu_task1_prog;
+extern struct spe_program_handle mpu_task2_prog;
+
+static struct mars_context *mars_ctx;
+static struct mars_task_id task1_id;
+static struct mars_task_id task2_id[NUM_TASKS] __attribute__((aligned(16)));
+static struct mars_task_args task_args;
+
+int main(void)
+{
+ int ret, i, exit_code;
+
+ printf(INFO);
+
+ ret = mars_context_create(&mars_ctx, 0, 0);
+ if (ret) {
+ printf("MARS context create failed! (%d)\n", ret);
+ return 1;
+ }
+
+ ret = mars_task_create(mars_ctx, &task1_id, "Task 1",
+ mpu_task1_prog.elf_image, MARS_TASK_CONTEXT_SAVE_SIZE_MAX);
+ if (ret) {
+ printf("MARS task 1 create failed! (%d)\n", ret);
+ return 1;
+ }
+
+ for (i = 0; i < NUM_TASKS; i++) {
+ char name[MARS_TASK_NAME_LEN_MAX];
+
+ snprintf(name, MARS_TASK_NAME_LEN_MAX, "Task 2.%d", i);
+ ret = mars_task_create(mars_ctx, &task2_id[i], name,
+ mpu_task2_prog.elf_image, MARS_TASK_CONTEXT_SAVE_SIZE_MAX);
+ if (ret) {
+ printf("MARS task 2 create failed! (%d)\n", ret);
+ return 1;
+ }
+ }
+
+ task_args.type.u64[0] = mars_ptr_to_ea(&task2_id[0]);
+ task_args.type.u64[1] = mars_ptr_to_ea(&task2_id[1]);
+ ret = mars_task_schedule(&task1_id, &task_args, 0);
+ if (ret) {
+ printf("MARS task 1 schedule failed! (%d)\n", ret);
+ return 1;
+ }
+
+ sleep(1);
+
+ printf("HOST : Unscheduling Sub Task 1\n");
+
+ ret = mars_task_unschedule(&task2_id[0], 123);
+ if (ret) {
+ printf("MARS task 2.0 unschedule failed! (%d)\n", ret);
+ return 1;
+ }
+
+ printf("HOST : Waiting for Sub Task 2 to finish...\n");
+
+ ret = mars_task_wait(&task2_id[1], &exit_code);
+ if (ret) {
+ printf("MARS task 2.1 wait failed! (%d)\n", ret);
+ return 1;
+ } else if (exit_code) {
+ printf("HOST : Sub Task 2 returned (exit_code = %d)\n", exit_code);
+ }
+
+ ret = mars_task_wait(&task1_id, NULL);
+ if (ret) {
+ printf("MARS task 1 wait failed! (%d)\n", ret);
+ return 1;
+ }
+
+ ret = mars_task_destroy(&task1_id);
+ if (ret) {
+ printf("MARS task 1 destroy failed! (%d)\n", ret);
+ return 1;
+ }
+
+ for (i = 0; i < NUM_TASKS; i++) {
+ ret = mars_task_destroy(&task2_id[i]);
+ if (ret) {
+ printf("MARS task 2 destroy failed! (%d)\n", ret);
+ return 1;
+ }
+ }
+
+ ret = mars_context_destroy(mars_ctx);
+ if (ret) {
+ printf("MARS context destroy failed! (%d)\n", ret);
+ return 1;
+ }
+
+ return 0;
+}
+
+
diff --git a/samples/unschedule/mpu_task1.c b/samples/unschedule/mpu_task1.c
new file mode 100644
index 0000000..9e055d7
--- /dev/null
+++ b/samples/unschedule/mpu_task1.c
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2008 Sony Corporation of America
+ *
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include <stdio.h>
+#include <spu_mfcio.h>
+#include <mars/task.h>
+
+int mars_task_main(const struct mars_task_args *task_args)
+{
+ int ret, exit_code;
+ struct mars_task_id task2_0_id;
+ struct mars_task_id task2_1_id;
+ struct mars_task_args args;
+
+ printf("MPU(%d): %s - Started\n",
+ mars_task_get_kernel_id(), mars_task_get_name());
+
+ mfc_get(&task2_0_id, task_args->type.u64[0], sizeof(struct mars_task_id), 0,0,0);
+ mfc_get(&task2_1_id, task_args->type.u64[1], sizeof(struct mars_task_id), 0,0,0);
+ mfc_write_tag_mask(1 << 0);
+ mfc_read_tag_status_all();
+
+ printf("MPU(%d): %s - Scheduling Sub Task 1...\n",
+ mars_task_get_kernel_id(), mars_task_get_name());
+
+ args.type.u32[0] = 0;
+ ret = mars_task_schedule(&task2_0_id, &args, 0);
+ if (ret) {
+ printf("MARS task 2.0 schedule failed! (%d)\n", ret);
+ return 1;
+ }
+
+ printf("MPU(%d): %s - Scheduling Sub Task 2...\n",
+ mars_task_get_kernel_id(), mars_task_get_name());
+
+ args.type.u32[0] = 1;
+ ret = mars_task_schedule(&task2_1_id, &args, 0);
+ if (ret) {
+ printf("MARS task 2.1 schedule failed! (%d)\n", ret);
+ return 1;
+ }
+
+ printf("MPU(%d): %s - Waiting for Sub Task 1 to finish...\n",
+ mars_task_get_kernel_id(), mars_task_get_name());
+
+ ret = mars_task_wait(&task2_0_id, &exit_code);
+ if (ret) {
+ printf("MARS task 2.0 wait failed! (%d)\n", ret);
+ return 1;
+ } else if (exit_code) {
+ printf("MPU(%d): %s - Sub Task 1 returned (exit_code = %d)\n",
+ mars_task_get_kernel_id(), mars_task_get_name(), exit_code);
+ }
+
+ printf("MPU(%d): %s - Unscheduling Sub Task 2\n",
+ mars_task_get_kernel_id(), mars_task_get_name());
+
+ ret = mars_task_unschedule(&task2_1_id, 321);
+ if (ret) {
+ printf("MARS task 2.1 unschedule failed! (%d)\n", ret);
+ return 1;
+ }
+
+ printf("MPU(%d): %s - Finished\n",
+ mars_task_get_kernel_id(), mars_task_get_name());
+
+ return 0;
+}
diff --git a/samples/unschedule/mpu_task2.c b/samples/unschedule/mpu_task2.c
new file mode 100644
index 0000000..38f7d2e
--- /dev/null
+++ b/samples/unschedule/mpu_task2.c
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2008 Sony Corporation of America
+ *
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include <stdio.h>
+#include <mars/task.h>
+
+int mars_task_main(const struct mars_task_args *task_args)
+{
+ int ret;
+
+ printf("MPU(%d): %s - Started\n",
+ mars_task_get_kernel_id(), mars_task_get_name());
+
+ if (task_args->type.u32[0]) {
+ printf("MPU(%d): %s - Enter Infinite Wait State...\n",
+ mars_task_get_kernel_id(), mars_task_get_name());
+ ret = mars_task_signal_wait();
+ if (ret != MARS_SUCCESS) {
+ printf("MARS task signal wait failed! (%d)\n", ret);
+ return 1;
+ }
+ } else {
+ printf("MPU(%d): %s - Enter Infinite Yield Loop...\n",
+ mars_task_get_kernel_id(), mars_task_get_name());
+ while (1) {
+ ret = mars_task_yield();
+ if (ret != MARS_SUCCESS) {
+ printf("MARS task yield failed! (%d)\n", ret);
+ return 1;
+ }
+ }
+ }
+
+ printf("MPU(%d): %s - Finished\n",
+ mars_task_get_kernel_id(), mars_task_get_name());
+
+ return 0;
+}