aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjoern B. Brandenburg <bbb@cs.unc.edu>2009-05-02 21:49:31 -0400
committerBjoern B. Brandenburg <bbb@cs.unc.edu>2009-05-02 21:49:31 -0400
commita1c578f34752e20cb24bfd568775efe465980da7 (patch)
tree51817cf90338a7120eddb69905ce923e5adca7b3
parenta231b2295173fa77816e1eac0b20402de879998f (diff)
release: add -w and -f options
-rw-r--r--bin/release_ts.c79
1 files changed, 77 insertions, 2 deletions
diff --git a/bin/release_ts.c b/bin/release_ts.c
index 4d4c9e8..9740df2 100644
--- a/bin/release_ts.c
+++ b/bin/release_ts.c
@@ -2,24 +2,90 @@
2#include <stdio.h> 2#include <stdio.h>
3#include <unistd.h> 3#include <unistd.h>
4 4
5#include <sys/types.h>
6#include <sys/stat.h>
7#include <fcntl.h>
8
5#include "litmus.h" 9#include "litmus.h"
6 10
7#define OPTSTR "d:" 11#define OPTSTR "d:wf:"
8#define NS_PER_MS 1000000 12#define NS_PER_MS 1000000
9 13
14#define LITMUS_STATS_FILE "/proc/litmus/stats"
15
10void usage(char *error) { 16void usage(char *error) {
11 fprintf(stderr, 17 fprintf(stderr,
12 "%s\n" 18 "%s\n"
13 "Usage: release_ts [-d <delay in ms>]\n", 19 "Usage: release_ts [OPTIONS]\n"
20 "\n"
21 "Options: -d <delay in ms> (default: 1000ms)\n"
22 " -w wait until all tasks are ready for release\n"
23 " (as determined by /proc/litmus/stats\n"
24 " -f <#tasks> wait for #tasks (default: 0)\n"
25 "\n",
14 error); 26 error);
15 exit(1); 27 exit(1);
16} 28}
17 29
30ssize_t read_file(const char* fname, void* buf, size_t maxlen)
31{
32 int fd;
33 ssize_t n = 0;
34 size_t got = 0;
35
36 fd = open(fname, O_RDONLY);
37 if (fd == -1)
38 return -1;
39
40 while (got < maxlen && (n = read(fd, buf + got, maxlen - got)) > 0)
41 got += n;
42 close(fd);
43 if (n < 0)
44 return -1;
45 else
46 return got;
47}
48
49void wait_until_ready(int expected)
50{
51 int ready = 0, all = 0;
52 char buf[100];
53 int loops = 0;
54 ssize_t len;
55
56
57 do {
58 if (loops++ > 0)
59 sleep(1);
60 len = read_file(LITMUS_STATS_FILE, buf, sizeof(buf) - 1);
61 if (len < 0) {
62 fprintf(stderr,
63 "(EE) Error while reading '%s': %m.\n"
64 "(EE) Ignoring -w option.\n",
65 LITMUS_STATS_FILE);
66 break;
67 } else {
68 len = sscanf(buf,
69 "real-time tasks = %d\n"
70 "ready for release = %d\n",
71 &all, &ready);
72 if (len != 2) {
73 fprintf(stderr,
74 "(EE) Could not parse '%s'.\n"
75 "(EE) Ignoring -w option.\n",
76 LITMUS_STATS_FILE);
77 break;
78 }
79 }
80 } while (expected > ready || ready < all);
81}
18 82
19int main(int argc, char** argv) 83int main(int argc, char** argv)
20{ 84{
21 int released; 85 int released;
22 lt_t delay = ms2lt(1000); 86 lt_t delay = ms2lt(1000);
87 int wait = 0;
88 int expected = 0;
23 int opt; 89 int opt;
24 90
25 while ((opt = getopt(argc, argv, OPTSTR)) != -1) { 91 while ((opt = getopt(argc, argv, OPTSTR)) != -1) {
@@ -27,6 +93,12 @@ int main(int argc, char** argv)
27 case 'd': 93 case 'd':
28 delay = ms2lt(atoi(optarg)); 94 delay = ms2lt(atoi(optarg));
29 break; 95 break;
96 case 'w':
97 wait = 1;
98 break;
99 case 'f':
100 expected = atoi(optarg);
101 break;
30 case ':': 102 case ':':
31 usage("Argument missing."); 103 usage("Argument missing.");
32 break; 104 break;
@@ -37,6 +109,9 @@ int main(int argc, char** argv)
37 } 109 }
38 } 110 }
39 111
112 if (wait)
113 wait_until_ready(expected);
114
40 released = release_ts(&delay); 115 released = release_ts(&delay);
41 if (released < 0) { 116 if (released < 0) {
42 perror("release task system"); 117 perror("release task system");