diff options
Diffstat (limited to 'bin/iotest.c')
-rw-r--r-- | bin/iotest.c | 74 |
1 files changed, 0 insertions, 74 deletions
diff --git a/bin/iotest.c b/bin/iotest.c deleted file mode 100644 index ac07e74..0000000 --- a/bin/iotest.c +++ /dev/null | |||
@@ -1,74 +0,0 @@ | |||
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 | |||
12 | int 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 | |||
39 | int 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 | } | ||