diff options
Diffstat (limited to 'bin/rt_launch_edfos.c')
-rw-r--r-- | bin/rt_launch_edfos.c | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/bin/rt_launch_edfos.c b/bin/rt_launch_edfos.c new file mode 100644 index 0000000..43ebee5 --- /dev/null +++ b/bin/rt_launch_edfos.c | |||
@@ -0,0 +1,138 @@ | |||
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 "common.h" | ||
10 | |||
11 | typedef struct { | ||
12 | int wait; | ||
13 | char * exec_path; | ||
14 | char ** argv; | ||
15 | } startup_info_t; | ||
16 | |||
17 | |||
18 | int launch(void *task_info_p) { | ||
19 | startup_info_t *info = (startup_info_t*) task_info_p; | ||
20 | int ret; | ||
21 | if (info->wait) { | ||
22 | ret = wait_for_ts_release(); | ||
23 | if (ret != 0) | ||
24 | perror("wait_for_ts_release()"); | ||
25 | } | ||
26 | ret = execvp(info->exec_path, info->argv); | ||
27 | perror("execv failed"); | ||
28 | return ret; | ||
29 | } | ||
30 | |||
31 | void usage(char *error) { | ||
32 | fprintf(stderr, "%s\nUsage: rt_launch [-w][-v][-p cpu][-c hrt | srt | be] wcet period" | ||
33 | " fracnum1 fracden1 cpu1 fracnum2 fracden2 cpu2 program [arg1 arg2 ...]\n" | ||
34 | "\t-w\tSynchronous release\n" | ||
35 | "\t-v\tVerbose\n" | ||
36 | "\t-p\tcpu (or initial cpu)\n" | ||
37 | "\t-c\tClass\n" | ||
38 | "\twcet, period in ms\n" | ||
39 | "\tprogram to be launched\n", | ||
40 | error); | ||
41 | exit(1); | ||
42 | } | ||
43 | |||
44 | |||
45 | #define OPTSTR "p:c:vw" | ||
46 | |||
47 | int main(int argc, char** argv) | ||
48 | { | ||
49 | int ret; | ||
50 | lt_t wcet; | ||
51 | lt_t period; | ||
52 | /* [num,den] */ | ||
53 | lt_t fracs[NR_CPUS][2]; | ||
54 | int migrate = 0; | ||
55 | int cpu = 0; | ||
56 | int opt; | ||
57 | int verbose = 0; | ||
58 | int wait = 0; | ||
59 | int i; | ||
60 | startup_info_t info; | ||
61 | task_class_t class = RT_CLASS_HARD; | ||
62 | |||
63 | for (i = 0; i < NR_CPUS; i++) { | ||
64 | fracs[i][0] = 0; | ||
65 | fracs[i][1] = 0; | ||
66 | } | ||
67 | |||
68 | while ((opt = getopt(argc, argv, OPTSTR)) != -1) { | ||
69 | switch (opt) { | ||
70 | case 'w': | ||
71 | wait = 1; | ||
72 | break; | ||
73 | case 'v': | ||
74 | verbose = 1; | ||
75 | break; | ||
76 | case 'p': | ||
77 | cpu = atoi(optarg); | ||
78 | fracs[cpu][0] = 1; | ||
79 | fracs[cpu][1] = 1; | ||
80 | migrate = 1; | ||
81 | break; | ||
82 | case 'c': | ||
83 | class = str2class(optarg); | ||
84 | if (class == -1) | ||
85 | usage("Unknown task class."); | ||
86 | break; | ||
87 | case ':': | ||
88 | usage("Argument missing."); | ||
89 | break; | ||
90 | case '?': | ||
91 | default: | ||
92 | usage("Bad argument."); | ||
93 | break; | ||
94 | } | ||
95 | } | ||
96 | |||
97 | signal(SIGUSR1, SIG_IGN); | ||
98 | |||
99 | if ((argc - (optind + 2)) % 3 != 0) | ||
100 | usage("Arguments missing."); | ||
101 | wcet = ms2lt(atoi(argv[optind + 0])); | ||
102 | period = ms2lt(atoi(argv[optind + 1])); | ||
103 | |||
104 | for (i = optind + 1; i < argc; i+= 3) { | ||
105 | cpu = atoi(argv[i+2]); | ||
106 | fracs[cpu][0] = atoi(argv[i]); | ||
107 | fracs[cpu][1] = atoi(argv[i+1]); | ||
108 | } | ||
109 | if (wcet <= 0) | ||
110 | usage("The worst-case execution time must be a " | ||
111 | "positive number."); | ||
112 | if (period <= 0) | ||
113 | usage("The period must be a positive number."); | ||
114 | if (wcet > period) { | ||
115 | usage("The worst-case execution time must not " | ||
116 | "exceed the period."); | ||
117 | } | ||
118 | info.exec_path = argv[optind + 8]; | ||
119 | info.argv = argv + optind + 8; | ||
120 | info.wait = wait; | ||
121 | if (migrate) { | ||
122 | ret = be_migrate_to(cpu); | ||
123 | if (ret < 0) | ||
124 | bail_out("could not migrate to target partition"); | ||
125 | } | ||
126 | /* create in src/task.c a new wrapper for the __launch_rt_task | ||
127 | * which takes the fraction and the cpus */ | ||
128 | ret = __create_rt_task_edfos(launch, &info, wcet, period, fracs, | ||
129 | class); | ||
130 | |||
131 | |||
132 | if (ret < 0) | ||
133 | bail_out("could not create rt child process"); | ||
134 | else if (verbose) | ||
135 | printf("%d\n", ret); | ||
136 | |||
137 | return 0; | ||
138 | } | ||