aboutsummaryrefslogtreecommitdiffstats
path: root/bin
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
parentd56b86e42b72abb68ba74bf540ddc259f6b20f84 (diff)
Reorganized file layout.
Diffstat (limited to 'bin')
-rw-r--r--bin/hrt.c78
-rw-r--r--bin/iotest.c74
-rw-r--r--bin/mode_test.c116
-rw-r--r--bin/np_test.c56
-rw-r--r--bin/rt_launch.c149
-rw-r--r--bin/run.c8
-rw-r--r--bin/set_rt_mode.c46
-rw-r--r--bin/show_scheduler.c10
-rw-r--r--bin/stdump.c44
-rw-r--r--bin/timeout.c36
-rw-r--r--bin/wait_test.c103
11 files changed, 720 insertions, 0 deletions
diff --git a/bin/hrt.c b/bin/hrt.c
new file mode 100644
index 0000000..224293c
--- /dev/null
+++ b/bin/hrt.c
@@ -0,0 +1,78 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4
5#include "edf-hsb.h"
6
7
8void usage(char *name)
9{
10 fprintf(stderr,
11 "EDF-HSB server setup utility\n"
12 "Usage: %s hrt show <#cpu>\n"
13 " %s hrt set <#cpu> <wcet> <period>\n"
14 " %s be create <wcet> <period>\n",
15 name, name, name);
16 exit(1);
17}
18
19
20int hrt(int argc, char** argv)
21{
22 int wcet, period, cpu;
23
24 if (argc == 2 && !strcmp(argv[0], "show")) {
25 cpu = atoi(argv[1]);
26 if (!get_hrt(cpu, &wcet, &period))
27 printf("HRT/%d = (%d, %d)\n", cpu, wcet, period);
28 else
29 perror("cannot read HRT settings");
30 } else if (argc == 4 && !strcmp(argv[0], "set")) {
31 cpu = atoi(argv[1]);
32 wcet = atoi(argv[2]);
33 period = atoi(argv[3]);
34 printf("Setting HRT/%d to (%d, %d)", cpu, wcet, period);
35 if (!set_hrt(cpu, wcet, period))
36 printf(" OK.\n");
37 else {
38 printf("\n");
39 perror("cannot write HRT settings");
40 }
41 } else
42 return 1;
43
44 return 0;
45}
46
47int be(int argc, char** argv)
48{
49 int wcet, period;
50 if (argc == 3 && !strcmp(argv[0], "create")) {
51 wcet = atoi(argv[1]);
52 period = atoi(argv[2]);
53 printf("Creating BE with (%d, %d)", wcet, period);
54 if (!create_be(wcet, period))
55 printf(" OK.\n");
56 else {
57 printf("\n");
58 perror("cannot create BE server");
59 }
60 return 0;
61 }
62 else
63 return 1;
64}
65
66int main(int argc, char** argv)
67{
68 int ret = 1;
69 if (argc > 1) {
70 if (!strcmp(argv[1], "hrt"))
71 ret = hrt(argc - 2, argv + 2);
72 else if (!strcmp(argv[1], "be"))
73 ret = be(argc - 2, argv + 2);
74 }
75 if (ret)
76 usage(argv[0]);
77 return ret;
78}
diff --git a/bin/iotest.c b/bin/iotest.c
new file mode 100644
index 0000000..ac07e74
--- /dev/null
+++ b/bin/iotest.c
@@ -0,0 +1,74 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <signal.h>
4#include <unistd.h>
5#include <sys/time.h>
6#include <sys/wait.h>
7
8#include "litmus.h"
9
10#define US_PER_MS 1000
11
12int iotest(void *nil) {
13 int id = getpid();
14 FILE* file;
15 char str[255];
16 unsigned long last = 0;
17 struct timeval time;
18
19 printf("I'am real time task %d doing IO!\n", id);
20 snprintf(str, sizeof(str), "rt-io-%d.txt", id);
21 file = fopen(str, "w");
22 if (!file) {
23 perror("could not open file for output");
24 exit(1);
25 }
26 while (1) {
27 gettimeofday(&time, NULL);
28 if (time.tv_usec - last > US_PER_MS) {
29 fprintf(file, "ran at %lus %lums\n", time.tv_sec, time.tv_usec / US_PER_MS);
30 last = time.tv_usec;
31 }
32 fflush(file);
33 }
34 return id;
35}
36
37#define NUMTASKS 4
38
39int main(int argc, char** argv)
40{
41 int rt_task[NUMTASKS];
42 int i;
43 int ret, pid;
44
45 for (i = 0; i < NUMTASKS; i++) {
46 /* func arg cpu wcet period */
47 rt_task[i] = create_rt_task(iotest, NULL, 0, 25, 100);
48 if (rt_task[i] < 0) {
49 perror("Could not create rt child process");
50 }
51 }
52
53 sync();
54 sync();
55
56 printf(":: Starting real-time mode.\n");
57 set_rt_mode(MODE_RT_RUN);
58
59 printf(":: Sleeping...\n");
60 sleep(120);
61
62 printf("Killing real-time tasks.\n");
63 for (i = 0; i < NUMTASKS; i++) {
64 printf(":: sending SIGKILL to %d\n", rt_task[i]);
65 kill(rt_task[i], SIGKILL);
66 }
67 for (i = 0; i < NUMTASKS; i++) {
68 pid = wait(&ret);
69 printf(":: %d exited with status %d\n", pid, ret);
70 }
71 printf(":: Leaving real-time mode.\n");
72 set_rt_mode(MODE_NON_RT);
73 return 0;
74}
diff --git a/bin/mode_test.c b/bin/mode_test.c
new file mode 100644
index 0000000..8bdf21b
--- /dev/null
+++ b/bin/mode_test.c
@@ -0,0 +1,116 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <signal.h>
4#include <unistd.h>
5#include <sys/time.h>
6#include <sys/wait.h>
7#include <sys/types.h>
8#include <sys/stat.h>
9#include <fcntl.h>
10
11#include "litmus.h"
12
13#define US_PER_MS 1000
14
15int prefix(void)
16{
17 char field[1024];
18 int prefix[1024];
19 int i, sum = 0;
20
21 for (i = 0; i < 1024; i++) {
22 sum += field[i];
23 prefix[i] = sum;
24 }
25 return sum;
26}
27
28void do_stuff(void)
29{
30 int i =0, j =0;
31
32 for (; i < 50000; i++)
33 j += prefix();
34}
35
36#define CALL(sc) do { ret = sc; if (ret == -1) {perror(" (!!) " #sc " failed"); /*exit(1)*/;}} while (0);
37
38unsigned int job_no;
39
40void next(void)
41{
42 int ret;
43 unsigned int actual;
44 CALL(get_job_no(&actual));
45 CALL(wait_for_job_release(++job_no));
46 printf("Now executing job %u, waited for %u\n", actual, job_no);
47}
48
49int main(int argc, char** argv)
50{
51 int ret;
52
53 init_litmus();
54
55 CALL(getpid());
56 printf("my pid is %d\n", ret);
57
58
59 CALL(get_job_no(&job_no));
60 printf("my job_no is %u", job_no);
61
62 CALL( task_mode(LITMUS_RT_TASK) );
63
64 CALL( sporadic_global(3, 33) );
65
66 CALL( task_mode(LITMUS_RT_TASK) );
67
68 next();
69 do_stuff();
70
71 next();
72 do_stuff();
73
74 next();
75 do_stuff();
76
77 CALL( task_mode(BACKGROUND_TASK) );
78
79 do_stuff();
80 do_stuff();
81 do_stuff();
82 do_stuff();
83 do_stuff();
84
85 CALL( task_mode(LITMUS_RT_TASK) );
86
87 do_stuff();
88 do_stuff();
89 do_stuff();
90 do_stuff();
91 do_stuff();
92
93
94 next();
95 next();
96 next();
97 next();
98 next();
99 next();
100 next();
101
102
103 next();
104 do_stuff();
105
106 next();
107 do_stuff();
108
109 next();
110 do_stuff();
111
112 CALL( task_mode(BACKGROUND_TASK) );
113 printf("Exiting...\n");
114
115 return 0;
116}
diff --git a/bin/np_test.c b/bin/np_test.c
new file mode 100644
index 0000000..dad68aa
--- /dev/null
+++ b/bin/np_test.c
@@ -0,0 +1,56 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <signal.h>
4#include <unistd.h>
5#include <sys/time.h>
6#include <sys/wait.h>
7#include <sys/types.h>
8#include <sys/stat.h>
9#include <fcntl.h>
10
11#include "litmus.h"
12
13#define US_PER_MS 1000
14
15#define NUMTASKS 4
16
17int prefix(void)
18{
19 char field[1024];
20 int prefix[1024];
21 int i, sum = 0;
22
23 for (i = 0; i < 1024; i++) {
24 sum += field[i];
25 prefix[i] = sum;
26 }
27 return sum;
28}
29
30
31void do_stuff(void)
32{
33 int i =0, j =0;
34
35 for (; i < 50000; i++)
36 j += prefix();
37}
38
39#define CALL(sc) do { ret = sc; if (ret == -1) {perror(" (!!) " #sc " failed: "); /*exit(1)*/;}} while (0);
40
41
42int main(int argc, char** argv)
43{
44 int ret;
45
46 init_litmus();
47
48 enter_np();
49
50 do_stuff();
51
52 exit_np();
53
54
55 return 0;
56}
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}
diff --git a/bin/run.c b/bin/run.c
new file mode 100644
index 0000000..3719d6f
--- /dev/null
+++ b/bin/run.c
@@ -0,0 +1,8 @@
1
2
3int main(int argc, char** argv)
4{
5 int i;
6 for (i = 0; i < 500000000; i++);
7 return 0;
8}
diff --git a/bin/set_rt_mode.c b/bin/set_rt_mode.c
new file mode 100644
index 0000000..510da70
--- /dev/null
+++ b/bin/set_rt_mode.c
@@ -0,0 +1,46 @@
1#include <stdio.h>
2#include <strings.h>
3#include <stdlib.h>
4#include <string.h>
5#include <errno.h>
6
7#include "litmus.h"
8
9
10void die(const char* str)
11{
12 fprintf(stderr, "%s\n%s\n", str,
13 "Usage: set_rt_mode [-v] {on|off}");
14 exit(127);
15}
16
17int main(int argc, char** argv)
18{
19 int ret;
20 int verbose = 0;
21 char* cmd = argv[1];
22
23 if (argc == 3 && !strcmp(argv[1], "-v")) {
24 verbose = 1;
25 cmd = argv[2];
26 }
27 if (argc == 2 || verbose) {
28 if (!strcmp(cmd, "on")) {
29 if (verbose)
30 printf("Enabling real-time mode.\n");
31 ret = set_rt_mode(MODE_RT_RUN);
32 if (ret && verbose)
33 perror("set_rt_mode failed");
34 exit(ret ? errno : 0);
35 } else if (!strcmp(cmd, "off")) {
36 if (verbose)
37 printf("Disabling real-time mode.\n");
38 ret = set_rt_mode(MODE_NON_RT);
39 if (ret && verbose)
40 perror("set_rt_mode failed");
41 exit(ret ? errno : 0);
42 }
43 }
44 die("Bad arguments.");
45 return 0;
46}
diff --git a/bin/show_scheduler.c b/bin/show_scheduler.c
new file mode 100644
index 0000000..7026e2a
--- /dev/null
+++ b/bin/show_scheduler.c
@@ -0,0 +1,10 @@
1#include <sys/types.h>
2#include <stdio.h>
3
4#include "litmus.h"
5
6int main(int argc, char** argv) {
7 spolicy scheduler = sched_getpolicy();
8 printf("%s\n", get_scheduler_name(scheduler));
9 return 0;
10}
diff --git a/bin/stdump.c b/bin/stdump.c
new file mode 100644
index 0000000..282fb31
--- /dev/null
+++ b/bin/stdump.c
@@ -0,0 +1,44 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4
5
6#include "litmus.h"
7#include "adaptive.h"
8#include "sched_trace.h"
9
10int show_sl_chg(trace_header_t* hdr)
11{
12 service_level_change_record_t *rec;
13
14 rec = (service_level_change_record_t*) hdr;
15 printf("SL CHANGE : PID=%d PERIOD=%lu\n", rec->task.pid,
16 rec->new_level.period);
17 return 0;
18}
19
20int show_weight_error(trace_header_t* hdr)
21{
22 weight_error_record_t *rec;
23
24 rec = (weight_error_record_t*) hdr;
25 printf("WEIGHT ERR: PID=%d EST=%5.4f ACT=%5.4f\n", rec->task,
26 fp2f(rec->estimate), fp2f(rec->actual));
27 return 0;
28}
29
30
31int main(int argc, char** argv)
32{
33 record_callback_t cb;
34 int ret;
35
36 init_record_callback(&cb);
37 set_callback(ST_SERVICE_LEVEL_CHANGE, show_sl_chg, &cb);
38 set_callback(ST_WEIGHT_ERROR, show_weight_error, &cb);
39
40 ret = walk_sched_trace_files_ordered(argv + 1, argc - 1, 0, &cb);
41 if (ret != 0)
42 perror("walk failed");
43 return 0;
44}
diff --git a/bin/timeout.c b/bin/timeout.c
new file mode 100644
index 0000000..ba513f9
--- /dev/null
+++ b/bin/timeout.c
@@ -0,0 +1,36 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <unistd.h>
4
5#include "litmus.h"
6
7int main(int argc, char** argv)
8{
9 int timeout;
10 rt_param_t my_param;
11
12 if (argc != 2)
13 {
14 printf("Usage: %s <timeout in seconds>\n", argv[0]);
15 exit(1);
16 }
17 timeout = atoi(argv[1]);
18 if (timeout <= 0) {
19 printf("Timeout must be a positive number.\n");
20 exit(1);
21 }
22
23 /* printf("This is the kill real-time mode task.\n"
24 "Expected end of real %u seconds.\n", timeout);
25 */
26 /* get_rt_task_param(getpid(), &my_param);
27 show_rt_param(&my_param);
28 */
29
30 sleep(timeout);
31
32
33 set_rt_mode(MODE_NON_RT);
34 printf("End of real-time mode.\n");
35 return 0;
36}
diff --git a/bin/wait_test.c b/bin/wait_test.c
new file mode 100644
index 0000000..efd4d90
--- /dev/null
+++ b/bin/wait_test.c
@@ -0,0 +1,103 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <signal.h>
4#include <unistd.h>
5#include <sys/time.h>
6#include <sys/wait.h>
7#include <sys/types.h>
8#include <sys/stat.h>
9#include <fcntl.h>
10
11#include "litmus.h"
12
13#define US_PER_MS 1000
14
15#define NUMTASKS 4
16
17int prefix(void)
18{
19 char field[1024];
20 int prefix[1024];
21 int i, sum = 0;
22
23 for (i = 0; i < 1024; i++) {
24 sum += field[i];
25 prefix[i] = sum;
26 }
27 return sum;
28}
29
30
31void do_stuff(void)
32{
33 int i =0, j =0;
34
35 for (; i < 50000; i++)
36 j += prefix();
37}
38
39#define CALL(sc) do { ret = sc; if (ret == -1) {perror(" (!!) " #sc " failed: "); /*exit(1)*/;}} while (0);
40
41unsigned int job_no;
42
43
44void next(void)
45{
46 int ret;
47 unsigned int actual;
48 CALL(get_job_no(&actual));
49 CALL(wait_for_job_release(++job_no));
50 printf("Now executing job %u, waited for %u\n", actual, job_no);
51}
52
53void sync_jobs(void)
54{
55 int ret;
56 unsigned int actual;
57 CALL(get_job_no(&actual));
58 job_no = actual;
59}
60
61
62int main(int argc, char** argv)
63{
64 int ret;
65
66 init_litmus();
67
68 CALL(getpid());
69 printf("my pid is %d\n", ret);
70
71
72 CALL(get_job_no(&job_no));
73 printf("my job_no is %u", job_no);
74
75 next();
76 next();
77 next();
78
79 /* now overrun a job for good */
80 do_stuff();
81 do_stuff();
82 do_stuff();
83 do_stuff();
84 do_stuff();
85 do_stuff();
86 do_stuff();
87 do_stuff();
88 do_stuff();
89 do_stuff();
90
91
92 next();
93 next();
94 next();
95 next();
96 sync_jobs();
97 next();
98 next();
99 next();
100
101
102 return 0;
103}