aboutsummaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorBjoern B. Brandenburg <bbb@cs.unc.edu>2008-12-01 04:46:18 -0500
committerBjoern B. Brandenburg <bbb@cs.unc.edu>2008-12-01 04:46:18 -0500
commita7b6bd92688343a9be234761778727fd3d07e4b2 (patch)
tree7a72baa47a7d77ded5fc7727dd3d439cfd2c04d7 /bin
parentaa387e17f6d5dcd2847ba142c6d4a8d7e5b5054d (diff)
replace run with rtspin
Diffstat (limited to 'bin')
-rw-r--r--bin/rtspin.c110
-rw-r--r--bin/run.c8
2 files changed, 110 insertions, 8 deletions
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}