aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBjoern B. Brandenburg <bbb@cs.unc.edu>2007-09-18 12:23:43 -0400
committerBjoern B. Brandenburg <bbb@cs.unc.edu>2007-09-18 12:23:43 -0400
commit957ad72229186c5d21e44366f61d58a4dfa89bfe (patch)
tree2284b3f2f4c1ed7c81ba0ccda720997fab4dab85 /src
parent5760b6ad37c794a0dd5312206184d0b8ae8e8eda (diff)
Change liblitmus to have a more sane repository layout.
Diffstat (limited to 'src')
-rw-r--r--src/edf-hsb.c48
-rw-r--r--src/hrt.c78
-rw-r--r--src/iotest.c74
-rw-r--r--src/litmus.c295
-rw-r--r--src/np_test.c56
-rw-r--r--src/rt_launch.c83
-rw-r--r--src/run.c8
-rw-r--r--src/set_rt_mode.c22
-rw-r--r--src/show_scheduler.c10
-rw-r--r--src/timeout.c36
-rw-r--r--src/wait_test.c103
11 files changed, 813 insertions, 0 deletions
diff --git a/src/edf-hsb.c b/src/edf-hsb.c
new file mode 100644
index 0000000..9ace2ca
--- /dev/null
+++ b/src/edf-hsb.c
@@ -0,0 +1,48 @@
1#include "litmus.h"
2#include "edf-hsb.h"
3
4
5typedef enum {
6 EDF_HSB_SET_HRT,
7 EDF_HSB_GET_HRT,
8 EDF_HSB_CREATE_BE
9} edf_hsb_setup_cmds_t;
10
11typedef struct {
12 int cpu;
13 unsigned int wcet;
14 unsigned int period;
15} setup_hrt_param_t;
16
17typedef struct {
18 unsigned int wcet;
19 unsigned int period;
20} create_be_param_t;
21
22int set_hrt(int cpu, unsigned int wcet, unsigned int period)
23{
24 setup_hrt_param_t param;
25 param.cpu = cpu;
26 param.wcet = wcet;
27 param.period = period;
28 return scheduler_setup(EDF_HSB_SET_HRT, &param);
29}
30
31int get_hrt(int cpu, unsigned int *wcet, unsigned int *period)
32{
33 setup_hrt_param_t param;
34 int ret;
35 param.cpu = cpu;
36 ret = scheduler_setup(EDF_HSB_GET_HRT, &param);
37 *wcet = param.wcet;
38 *period = param.period;
39 return ret;
40}
41
42int create_be(unsigned int wcet, unsigned int period)
43{
44 create_be_param_t param;
45 param.wcet = wcet;
46 param.period = period;
47 return scheduler_setup(EDF_HSB_CREATE_BE, &param);
48}
diff --git a/src/hrt.c b/src/hrt.c
new file mode 100644
index 0000000..224293c
--- /dev/null
+++ b/src/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/src/iotest.c b/src/iotest.c
new file mode 100644
index 0000000..ac07e74
--- /dev/null
+++ b/src/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/src/litmus.c b/src/litmus.c
new file mode 100644
index 0000000..65ad294
--- /dev/null
+++ b/src/litmus.c
@@ -0,0 +1,295 @@
1#include <stdlib.h>
2#include <stdio.h>
3#include <string.h>
4#include <sys/types.h>
5#include <unistd.h>
6#include <errno.h>