aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile10
-rw-r--r--bin/rtspin.c110
-rw-r--r--bin/run.c8
3 files changed, 115 insertions, 13 deletions
diff --git a/Makefile b/Makefile
index 361a891..63bdd53 100644
--- a/Makefile
+++ b/Makefile
@@ -18,8 +18,8 @@ LIBS= ./liblitmus.a
18 18
19LIB_OBJ= litmus.o syscalls.o sched_trace.o task.o kernel_iface.o 19LIB_OBJ= litmus.o syscalls.o sched_trace.o task.o kernel_iface.o
20 20
21TARGETS = run rt_launch liblitmus.a \ 21TARGETS = rt_launch liblitmus.a \
22 wait_test np_test mode_test base_task base_mt_task release_ts showst 22 wait_test np_test mode_test base_task base_mt_task release_ts showst rtspin
23 23
24vpath %.h include/ 24vpath %.h include/
25vpath %.c src/ bin/ 25vpath %.c src/ bin/
@@ -43,12 +43,12 @@ mode_test: mode_test.o litmus.h liblitmus.a
43np_test: np_test.o litmus.h liblitmus.a 43np_test: np_test.o litmus.h liblitmus.a
44 ${CC} ${CFLAGS} -static -o np_test np_test.o ${LIBS} 44 ${CC} ${CFLAGS} -static -o np_test np_test.o ${LIBS}
45 45
46run: run.o ${LIBS}
47 ${CC} ${CFLAGS} -o run run.o ${LIBS}
48
49rt_launch: liblitmus.a litmus.h rt_launch.o common.o 46rt_launch: liblitmus.a litmus.h rt_launch.o common.o
50 ${CC} ${CFLAGS} -static -o rt_launch rt_launch.o common.o ${LIBS} 47 ${CC} ${CFLAGS} -static -o rt_launch rt_launch.o common.o ${LIBS}
51 48
49rtspin: liblitmus.a litmus.h rtspin.o common.o
50 ${CC} ${CFLAGS} -static -o rtspin rtspin.o common.o ${LIBS}
51
52release_ts: liblitmus.a litmus.h release_ts.o 52release_ts: liblitmus.a litmus.h release_ts.o
53 ${CC} ${CFLAGS} -static -o release_ts release_ts.o ${LIBS} 53 ${CC} ${CFLAGS} -static -o release_ts release_ts.o ${LIBS}
54 54
diff --git a/bin/rtspin.c b/bin/rtspin.c
new file mode 100644
index 0000000..435e496
--- /dev/null
+++ b/bin/rtspin.c
@@ -0,0 +1,110 @@
1#include <sys/time.h>
2
3#include <stdio.h>
4#include <stdlib.h>
5#include <unistd.h>
6#include <time.h>
7
8
9#include "litmus.h"
10#include "common.h"
11
12void usage(char *error) {
13 fprintf(stderr, "Error: %s\n", error);
14 fprintf(stderr, "Usage: rt_spin [-w] [-p PARTITION] [-c CLASS] WCET PERIOD DURATION\n");
15 exit(1);
16}
17
18static double wctime()
19{
20 struct timeval tv;
21 gettimeofday(&tv, NULL);
22 return (tv.tv_sec + 1E-6 * tv.tv_usec);
23}
24
25#define OPTSTR "p:c:w"
26
27int main(int argc, char** argv)
28{
29 int i;
30 int ret;
31 lt_t wcet;
32 lt_t period;
33 int migrate = 0;
34 int cpu = 0;
35 int opt;
36 int wait = 0;
37 double duration, start;
38 task_class_t class = RT_CLASS_HARD;
39
40 while ((opt = getopt(argc, argv, OPTSTR)) != -1) {
41 switch (opt) {
42 case 'w':
43 wait = 1;
44 break;
45 case 'p':
46 cpu = atoi(optarg);
47 migrate = 1;
48 break;
49 case 'c':
50 class = str2class(optarg);
51 if (class == -1)
52 usage("Unknown task class.");
53 break;
54 case ':':
55 usage("Argument missing.");
56 break;
57 case '?':
58 default:
59 usage("Bad argument.");
60 break;
61 }
62 }
63
64 if (argc - optind < 3)
65 usage("Arguments missing.");
66 wcet = atoi(argv[optind + 0]);
67 period = atoi(argv[optind + 1]);
68 duration = atof(argv[optind + 2]);
69 if (wcet <= 0)
70 usage("The worst-case execution time must be a "
71 "positive number.");
72 if (period <= 0)
73 usage("The period must be a positive number.");
74 if (wcet > period) {
75 usage("The worst-case execution time must not "
76 "exceed the period.");
77 }
78 if (migrate) {
79 ret = be_migrate_to(cpu);
80 if (ret < 0)
81 bail_out("could not migrate to target partition");
82 }
83
84// printf("wcet: %llu\nperiod: %llu\n", wcet, period);
85 ret = sporadic_task(wcet, period, 0, cpu, class, migrate);
86
87 if (ret < 0)
88 bail_out("could not become rt tasks.");
89
90// ret = init_litmus();
91// if (ret < 0)
92// perror("init_litmus()");
93
94 ret = task_mode(LITMUS_RT_TASK);
95 if (ret != 0)
96 bail_out("task_mode()");
97
98 if (wait) {
99 ret = wait_for_ts_release();
100 if (ret != 0)
101 bail_out("wait_for_ts_release()");
102 }
103 start = wctime();
104
105 while (start + duration > wctime()) {
106 for (i = 0; i < 500000; i++);
107 }
108
109 return 0;
110}
diff --git a/bin/run.c b/bin/run.c
deleted file mode 100644
index 3719d6f..0000000
--- a/bin/run.c
+++ /dev/null
@@ -1,8 +0,0 @@
1
2
3int main(int argc, char** argv)
4{
5 int i;
6 for (i = 0; i < 500000000; i++);
7 return 0;
8}