aboutsummaryrefslogtreecommitdiffstats
path: root/src/rt_launch.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rt_launch.c')
-rw-r--r--src/rt_launch.c85
1 files changed, 67 insertions, 18 deletions
diff --git a/src/rt_launch.c b/src/rt_launch.c
index a90bea8..cd98ad3 100644
--- a/src/rt_launch.c
+++ b/src/rt_launch.c
@@ -1,8 +1,11 @@
1#include <stdio.h> 1#include <stdio.h>
2#include <stdlib.h> 2#include <stdlib.h>
3#include <string.h>
3#include <unistd.h> 4#include <unistd.h>
5#include <limits.h>
4 6
5#include "litmus.h" 7#include "litmus.h"
8#include "adaptive.h"
6 9
7typedef struct { 10typedef struct {
8 char * exec_path; 11 char * exec_path;
@@ -20,12 +23,38 @@ int launch(void *task_info_p) {
20 23
21void usage(char *error) { 24void usage(char *error) {
22 fprintf(stderr, "%s\nUsage: launch_rt [-c {hrt|srt|be}] [-p <cpu>]" 25 fprintf(stderr, "%s\nUsage: launch_rt [-c {hrt|srt|be}] [-p <cpu>]"
23 "<wcet> <period> program arg1 arg2 ...\n", 26 "{<wcet> <period>|{-a wcet/period/utility}+}"
27 " program arg1 arg2 ...\n",
24 error); 28 error);
25 exit(1); 29 exit(1);
26} 30}
27 31
28#define OPTSTR "p:c:" 32/* argument format should be wcet/period/utility */
33static int parse_service_level(service_level_t* level, char* str)
34{
35 char *wcet, *period, *utility;
36 double u;
37 wcet = strtok(str, "/");
38 period = strtok(NULL, "/");
39 utility = strtok(NULL, "/");
40 str = strtok(NULL, "/");
41
42 if (str || !utility || !period || !wcet)
43 return 0;
44
45 level->exec_cost = atol(wcet);
46 level->period = atol(period);
47 u = atof(utility);
48
49 if (level->exec_cost == 0 || level->period < level->exec_cost ||
50 u <= 0.0 || u > 1.0)
51 return 0;
52
53 level->utility = (unsigned long) ULONG_MAX * u;
54 return 1;
55}
56
57#define OPTSTR "p:c:a:"
29 58
30int main(int argc, char** argv) 59int main(int argc, char** argv)
31{ 60{
@@ -36,9 +65,20 @@ int main(int argc, char** argv)
36 int opt; 65 int opt;
37 startup_info_t info; 66 startup_info_t info;
38 task_class_t class = RT_CLASS_HARD; 67 task_class_t class = RT_CLASS_HARD;
68
69 int adaptive = 0;
70 unsigned int level = 0;
71 service_level_t slevel[MAX_SERVICE_LEVELS];
39 72
40 while ((opt = getopt(argc, argv, OPTSTR)) != -1) { 73 while ((opt = getopt(argc, argv, OPTSTR)) != -1) {
41 switch (opt) { 74 switch (opt) {
75 case 'a':
76 adaptive = 1;
77 if (level == MAX_SERVICE_LEVELS)
78 usage("Too many service levels.");
79 if (!parse_service_level(slevel + level++, optarg))
80 usage("Bad service level.");
81 break;
42 case 'p': 82 case 'p':
43 cpu = atoi(optarg); 83 cpu = atoi(optarg);
44 break; 84 break;
@@ -58,23 +98,32 @@ int main(int argc, char** argv)
58 } 98 }
59 } 99 }
60 100
61 if (argc - optind < 3) 101 if (!adaptive) {
62 { 102 if (argc - optind < 3)
63 printf("argc: %d optind: %d\n", argc, optind); 103 usage("Arguments missing.");
64 usage("Arguments missing."); 104 wcet = atoi(argv[optind + 0]);
65 } 105 period = atoi(argv[optind + 1]);
66 wcet = atoi(argv[optind + 0]); 106 if (wcet <= 0)
67 period = atoi(argv[optind + 1]); 107 usage("The worst-case execution time must be a "
68 if (wcet <= 0) 108 "positive number.");
69 usage("The worst-case execution time must be a positive number."); 109 if (period <= 0)
70 if (period <= 0) 110 usage("The period must be a positive number.");
71 usage("The period must be a positive number."); 111 if (wcet > period) {
72 if (wcet > period) { 112 usage("The worst-case execution time must not "
73 usage("The worst-case execution time must not exceed the period."); 113 "exceed the period.");
114 }
115 info.exec_path = argv[optind + 2];
116 info.argv = argv + optind + 2;
117 ret = __create_rt_task(launch, &info, cpu, wcet, period, class);
118 } else {
119 if (argc == optind)
120 usage("Arguments missing.");
121 info.exec_path = argv[optind];
122 info.argv = argv + optind;
123 ret = create_adaptive_rt_task(launch, &info, level, slevel);
74 } 124 }
75 info.exec_path = argv[optind + 2]; 125
76 info.argv = argv + optind + 2; 126
77 ret = __create_rt_task(launch, &info, cpu, wcet, period, class);
78 if (ret < 0) { 127 if (ret < 0) {
79 perror("Could not create rt child process"); 128 perror("Could not create rt child process");
80 return 2; 129 return 2;