aboutsummaryrefslogtreecommitdiffstats
path: root/bin/rt_launch.c
diff options
context:
space:
mode:
authorBjoern B. Brandenburg <bbb@cs.unc.edu>2008-01-23 11:26:36 -0500
committerBjoern B. Brandenburg <bbb@cs.unc.edu>2008-01-23 11:26:36 -0500
commit7e062f5db3e3888cda2d0915e14d33b9f69c4c68 (patch)
tree9ef810155fc51b564e764e448478f37b169ea507 /bin/rt_launch.c
parentd56b86e42b72abb68ba74bf540ddc259f6b20f84 (diff)
Reorganized file layout.
Diffstat (limited to 'bin/rt_launch.c')
-rw-r--r--bin/rt_launch.c149
1 files changed, 149 insertions, 0 deletions
diff --git a/bin/rt_launch.c b/bin/rt_launch.c
new file mode 100644
index 0000000..d888365
--- /dev/null
+++ b/bin/rt_launch.c
@@ -0,0 +1,149 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <unistd.h>
5#include <limits.h>
6#include <signal.h>
7
8#include "litmus.h"
9#include "adaptive.h"
10
11typedef struct {
12 char * exec_path;
13 char ** argv;
14} startup_info_t;
15
16
17int launch(void *task_info_p) {
18 startup_info_t *info = (startup_info_t*) task_info_p;
19 int ret;
20 ret = execvp(info->exec_path, info->argv);
21 perror("execv failed");
22 return ret;
23}
24
25void usage(char *error) {
26 fprintf(stderr, "%s\nUsage: \nlaunch_rt supports one of two modes:\n"
27 "\n\tlaunch_rt <SPORADIC OPTIONS> <wcet> <period> program arg1 arg2 ...\n"
28 "\n\tlaunch_rt <ADAPTIVE OPTIONS> program arg1 arg2 ...\n"
29 "\nwhere:"
30 "\n\t <SPORADIC OPTIONS> = "
31 "[-c {hrt|srt|be}] [-p <cpu>]\n"
32 "\n\t <ADAPTIVE OPTIONS> = "
33 "(-a weight/period/utility)+\n"
34 "\nExamples:"
35 "\n\trt_launch -p 2 10 100 cpu_job"
36 "\n\t => Launch cpu_job a hard real-time task with "
37 "\n\t period 100 and weight 0.1 on CPU 2.\n"
38 "\n\trt_launch -a 0.1/100/0.4 -a 0.2/75/0.5 adaptive_job"
39 "\n\t => Launch adaptive_job with two service levels"
40 "\n\n",
41 error);
42 exit(1);
43}
44
45/* argument format should be weight/period/utility */
46static int parse_service_level(service_level_t* level, char* str)
47{
48 char *weight, *period, *utility;
49 double u, w;
50 weight = strtok(str, "/");
51 period = strtok(NULL, "/");
52 utility = strtok(NULL, "/");
53 str = strtok(NULL, "/");
54
55 if (str || !utility || !period || !weight)
56 return 0;
57
58 w = atof(weight);
59 u = atof(utility);
60 level->weight = f2fp(w);
61 level->period = atol(period);
62 level->value = f2fp(u);
63
64 if (level->period == 0 ||
65 u <= 0.0 || u > 1.0 || w <= 0.0 || w > 1.0)
66 return 0;
67 return 1;
68}
69
70
71#define OPTSTR "p:c:a:"
72
73int main(int argc, char** argv)
74{
75 int ret;
76 int wcet;
77 int period;
78 int cpu = 0;
79 int opt;
80 startup_info_t info;
81 task_class_t class = RT_CLASS_HARD;
82
83 int adaptive = 0;
84 unsigned int level = 0;
85 service_level_t slevel[MAX_SERVICE_LEVELS];
86
87 while ((opt = getopt(argc, argv, OPTSTR)) != -1) {
88 switch (opt) {
89 case 'a':
90 adaptive = 1;
91 if (level == MAX_SERVICE_LEVELS)
92 usage("Too many service levels.");
93 if (!parse_service_level(slevel + level++, optarg))
94 usage("Bad service level.");
95 break;
96 case 'p':
97 cpu = atoi(optarg);
98 break;
99 case 'c':
100 class = str2class(optarg);
101 if (class == -1)
102 usage("Unknown task class.");
103 break;
104
105 case ':':
106 usage("Argument missing.");
107 break;
108 case '?':
109 default:
110 usage("Bad argument.");
111 break;
112 }
113 }
114
115 signal(SIGUSR1, SIG_IGN);
116
117 if (!adaptive) {
118 if (argc - optind < 3)
119 usage("Arguments missing.");
120 wcet = atoi(argv[optind + 0]);
121 period = atoi(argv[optind + 1]);
122 if (wcet <= 0)
123 usage("The worst-case execution time must be a "
124 "positive number.");
125 if (period <= 0)
126 usage("The period must be a positive number.");
127 if (wcet > period) {
128 usage("The worst-case execution time must not "
129 "exceed the period.");
130 }
131 info.exec_path = argv[optind + 2];
132 info.argv = argv + optind + 2;
133 ret = __create_rt_task(launch, &info, cpu, wcet, period, class);
134 } else {
135 if (argc == optind)
136 usage("Arguments missing.");
137 info.exec_path = argv[optind];
138 info.argv = argv + optind;
139 ret = create_adaptive_rt_task(launch, &info, level, slevel);
140 }
141
142
143 if (ret < 0) {
144 perror("Could not create rt child process");
145 return 2;
146 }
147
148 return 0;
149}