diff options
author | Andrea Bastoni <bastoni@cs.unc.edu> | 2010-06-24 21:08:02 -0400 |
---|---|---|
committer | Andrea Bastoni <bastoni@cs.unc.edu> | 2010-06-24 21:08:02 -0400 |
commit | 3bcf13b5c38f23b3663f6a7030ae34383f651b4e (patch) | |
tree | 164b0c760e8db190185a9487e1aa00f1c43f85bd /bin | |
parent | c176d77f446a9f218e0bd413bfad949b286e8326 (diff) |
[NPS-F] Add rt_launch version for NPS-F algo
Diffstat (limited to 'bin')
-rw-r--r-- | bin/rt_launch_npsf.c | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/bin/rt_launch_npsf.c b/bin/rt_launch_npsf.c new file mode 100644 index 0000000..97ad361 --- /dev/null +++ b/bin/rt_launch_npsf.c | |||
@@ -0,0 +1,110 @@ | |||
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] wcet period cpu npsf-id program [arg1 arg2 ...]\n" | ||
33 | "\t-w\tSynchronous release\n" | ||
34 | "\t-v\tVerbose\n" | ||
35 | "\twcet, period in ms\n" | ||
36 | "\tprogram to be launched\n", | ||
37 | error); | ||
38 | exit(1); | ||
39 | } | ||
40 | |||
41 | |||
42 | #define OPTSTR "vw" | ||
43 | |||
44 | int main(int argc, char** argv) | ||
45 | { | ||
46 | int ret; | ||
47 | lt_t wcet; | ||
48 | lt_t period; | ||
49 | int migrate = 0; | ||
50 | int cpu = 0; | ||
51 | int npsf_id; | ||
52 | int opt; | ||
53 | int verbose = 0; | ||
54 | int wait = 0; | ||
55 | startup_info_t info; | ||
56 | |||
57 | while ((opt = getopt(argc, argv, OPTSTR)) != -1) { | ||
58 | switch (opt) { | ||
59 | case 'w': | ||
60 | wait = 1; | ||
61 | break; | ||
62 | case 'v': | ||
63 | verbose = 1; | ||
64 | break; | ||
65 | case ':': | ||
66 | usage("Argument missing."); | ||
67 | break; | ||
68 | case '?': | ||
69 | default: | ||
70 | usage("Bad argument."); | ||
71 | break; | ||
72 | } | ||
73 | } | ||
74 | |||
75 | signal(SIGUSR1, SIG_IGN); | ||
76 | |||
77 | if (argc - optind < 5) | ||
78 | usage("Arguments missing."); | ||
79 | wcet = ms2lt(atoi(argv[optind + 0])); | ||
80 | period = ms2lt(atoi(argv[optind + 1])); | ||
81 | cpu = atoi(argv[optind + 2]); | ||
82 | migrate = 1; | ||
83 | npsf_id = atoi(argv[optind + 3]); | ||
84 | if (wcet <= 0) | ||
85 | usage("The worst-case execution time must be a " | ||
86 | "positive number."); | ||
87 | if (period <= 0) | ||
88 | usage("The period must be a positive number."); | ||
89 | if (wcet > period) { | ||
90 | usage("The worst-case execution time must not " | ||
91 | "exceed the period."); | ||
92 | } | ||
93 | info.exec_path = argv[optind + 4]; | ||
94 | info.argv = argv + optind + 4; | ||
95 | info.wait = wait; | ||
96 | if (migrate) { | ||
97 | ret = be_migrate_to(cpu); | ||
98 | if (ret < 0) | ||
99 | bail_out("could not migrate to target partition"); | ||
100 | } | ||
101 | ret = __create_rt_task_npsf(launch, &info, cpu, wcet, period, npsf_id, RT_CLASS_HARD); | ||
102 | |||
103 | |||
104 | if (ret < 0) | ||
105 | bail_out("could not create rt child process"); | ||
106 | else if (verbose) | ||
107 | printf("%d\n", ret); | ||
108 | |||
109 | return 0; | ||
110 | } | ||