diff options
author | Bjoern Brandenburg <bbb@mpi-sws.org> | 2012-08-14 14:29:17 -0400 |
---|---|---|
committer | Bjoern Brandenburg <bbb@mpi-sws.org> | 2012-08-14 14:46:16 -0400 |
commit | f215a05c0ea23c7779b1a3a4361b4d88ddc73dc1 (patch) | |
tree | 8d105f8894c1a3f52ae88561faa6e866218fcf10 | |
parent | a72371ea7d7b13bf0126b4636a7cba9e03ea12b8 (diff) |
Implement get_nr_ts_release_waiters() /proc wrapper
Add a wrapper for /proc/litmus/stats to make it easy to query the
number of tasks already waiting for a task set release.
-rw-r--r-- | bin/release_ts.c | 20 | ||||
-rw-r--r-- | include/internal.h | 3 | ||||
-rw-r--r-- | include/litmus.h | 1 | ||||
-rw-r--r-- | src/kernel_iface.c | 39 |
4 files changed, 44 insertions, 19 deletions
diff --git a/bin/release_ts.c b/bin/release_ts.c index 9740df2..7752097 100644 --- a/bin/release_ts.c +++ b/bin/release_ts.c | |||
@@ -7,6 +7,7 @@ | |||
7 | #include <fcntl.h> | 7 | #include <fcntl.h> |
8 | 8 | ||
9 | #include "litmus.h" | 9 | #include "litmus.h" |
10 | #include "internal.h" | ||
10 | 11 | ||
11 | #define OPTSTR "d:wf:" | 12 | #define OPTSTR "d:wf:" |
12 | #define NS_PER_MS 1000000 | 13 | #define NS_PER_MS 1000000 |
@@ -27,25 +28,6 @@ void usage(char *error) { | |||
27 | exit(1); | 28 | exit(1); |
28 | } | 29 | } |
29 | 30 | ||
30 | ssize_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 | |||
49 | void wait_until_ready(int expected) | 31 | void wait_until_ready(int expected) |
50 | { | 32 | { |
51 | int ready = 0, all = 0; | 33 | int ready = 0, all = 0; |
diff --git a/include/internal.h b/include/internal.h index f30ce61..747f095 100644 --- a/include/internal.h +++ b/include/internal.h | |||
@@ -26,5 +26,8 @@ int __launch_rt_task(rt_fn_t rt_prog, void *rt_arg, | |||
26 | #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) | 26 | #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) |
27 | #define BUILD_BUG_ON(condition) ((void)BUILD_BUG_ON_ZERO(condition)) | 27 | #define BUILD_BUG_ON(condition) ((void)BUILD_BUG_ON_ZERO(condition)) |
28 | 28 | ||
29 | /* I/O convenience function */ | ||
30 | ssize_t read_file(const char* fname, void* buf, size_t maxlen); | ||
31 | |||
29 | #endif | 32 | #endif |
30 | 33 | ||
diff --git a/include/litmus.h b/include/litmus.h index 82e4bd1..e4b619e 100644 --- a/include/litmus.h +++ b/include/litmus.h | |||
@@ -120,6 +120,7 @@ int requested_to_preempt(void); | |||
120 | /* task system support */ | 120 | /* task system support */ |
121 | int wait_for_ts_release(void); | 121 | int wait_for_ts_release(void); |
122 | int release_ts(lt_t *delay); | 122 | int release_ts(lt_t *delay); |
123 | int get_nr_ts_release_waiters(void); | ||
123 | 124 | ||
124 | #define __NS_PER_MS 1000000 | 125 | #define __NS_PER_MS 1000000 |
125 | 126 | ||
diff --git a/src/kernel_iface.c b/src/kernel_iface.c index 33d56df..b9c8f59 100644 --- a/src/kernel_iface.c +++ b/src/kernel_iface.c | |||
@@ -12,6 +12,8 @@ | |||
12 | #define LITMUS_CTRL_DEVICE "/dev/litmus/ctrl" | 12 | #define LITMUS_CTRL_DEVICE "/dev/litmus/ctrl" |
13 | #define CTRL_PAGES 1 | 13 | #define CTRL_PAGES 1 |
14 | 14 | ||
15 | #define LITMUS_STATS_FILE "/proc/litmus/stats" | ||
16 | |||
15 | static int map_file(const char* filename, void **addr, size_t size) | 17 | static int map_file(const char* filename, void **addr, size_t size) |
16 | { | 18 | { |
17 | int error = 0; | 19 | int error = 0; |
@@ -35,6 +37,43 @@ static int map_file(const char* filename, void **addr, size_t size) | |||
35 | return error; | 37 | return error; |
36 | } | 38 | } |
37 | 39 | ||
40 | ssize_t read_file(const char* fname, void* buf, size_t maxlen) | ||
41 | { | ||
42 | int fd; | ||
43 | ssize_t n = 0; | ||
44 | size_t got = 0; | ||
45 | |||
46 | fd = open(fname, O_RDONLY); | ||
47 | if (fd == -1) | ||
48 | return -1; | ||
49 | |||
50 | while (got < maxlen && (n = read(fd, buf + got, maxlen - got)) > 0) | ||
51 | got += n; | ||
52 | close(fd); | ||
53 | if (n < 0) | ||
54 | return -1; | ||
55 | else | ||
56 | return got; | ||
57 | } | ||
58 | |||
59 | int get_nr_ts_release_waiters(void) | ||
60 | { | ||
61 | int ready = 0, all = 0; | ||
62 | char buf[100]; | ||
63 | ssize_t len; | ||
64 | |||
65 | len = read_file(LITMUS_STATS_FILE, buf, sizeof(buf) - 1); | ||
66 | if (len >= 0) | ||
67 | len = sscanf(buf, | ||
68 | "real-time tasks = %d\n" | ||
69 | "ready for release = %d\n", | ||
70 | &all, &ready); | ||
71 | if (len == 2) | ||
72 | return ready; | ||
73 | else | ||
74 | return len; | ||
75 | } | ||
76 | |||
38 | /* thread-local pointer to control page */ | 77 | /* thread-local pointer to control page */ |
39 | static __thread struct control_page *ctrl_page; | 78 | static __thread struct control_page *ctrl_page; |
40 | 79 | ||