aboutsummaryrefslogtreecommitdiffstats
path: root/rt_launch.c
diff options
context:
space:
mode:
authorBjoern B. Brandenburg <bbb@jupiter-cs.cs.unc.edu>2007-02-05 18:31:20 -0500
committerBjoern B. Brandenburg <bbb@jupiter-cs.cs.unc.edu>2007-02-05 18:31:20 -0500
commitb32b21bd57b21b249447e2944c4473e0d196bb4f (patch)
treefea9e8712fbc97f30003065074a1ff180f3e1de4 /rt_launch.c
liblitmus essential tools
liblitmus should consist only of the litmus library and the essential tools.
Diffstat (limited to 'rt_launch.c')
-rw-r--r--rt_launch.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/rt_launch.c b/rt_launch.c
new file mode 100644
index 0000000..31e6447
--- /dev/null
+++ b/rt_launch.c
@@ -0,0 +1,83 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <unistd.h>
4
5#include "litmus.h"
6
7typedef struct {
8 char * exec_path;
9 char ** argv;
10} startup_info_t;
11
12
13int launch(void *task_info_p) {
14 startup_info_t *info = (startup_info_t*) task_info_p;
15 int ret;
16 ret = execv(info->exec_path, info->argv);
17 perror("execv failed");
18 return ret;
19}
20
21void usage(char *error) {
22 fprintf(stderr, "%s\nUsage: launch_rt [-c {hrt|srt|be}] [-p <cpu>]"
23 "<wcet> <period> program arg1 arg2 ...\n",
24 error);
25 exit(1);
26}
27
28#define OPTSTR "p:c:"
29
30int main(int argc, char** argv)
31{
32 int ret;
33 int wcet;
34 int period;
35 int cpu = 0;
36 int opt;
37 startup_info_t info;
38 task_class_t class = RT_CLASS_HARD;
39
40 while ((opt = getopt(argc, argv, OPTSTR)) != -1) {
41 switch (opt) {
42 case 'p':
43 cpu = atoi(optarg);
44 break;
45 case 'c':
46 class = str2class(optarg);
47 if (class == -1)
48 usage("Unknown task class.");
49 break;
50
51 case ':':
52 usage("Argument missing.");
53 break;
54 case '?':
55 default:
56 usage("Unknown flag.");
57 break;
58 }
59 }
60
61 if (argc - optind < 3)
62 {
63 printf("argc: %d optind: %d\n", argc, optind);
64 usage("Arguments missing.");
65 }
66 wcet = atoi(argv[optind + 0]);
67 period = atoi(argv[optind + 1]);
68 if (wcet <= 0)
69 usage("The worst-case execution time must be a positive number.");
70 if (period <= 0)
71 usage("The period must be a positive number.");
72 if (wcet > period) {
73 usage("The worst-case execution time must not exceed the period.");
74 }
75 info.exec_path = argv[optind + 2];
76 info.argv = argv + optind + 2;
77 ret = __create_rt_task(launch, &info, cpu, wcet, period, class);
78 if (ret < 0) {
79 perror("Could not create rt child process");
80 }
81
82 return 0;
83}