From 642049ba7d30b24fb9927a22d44d6b84139668dc Mon Sep 17 00:00:00 2001 From: Bjoern Brandenburg Date: Fri, 11 Jan 2013 10:17:10 +0100 Subject: Make release_ts a bit more userfriendly The -f option required manually *also* setting the -w option. This is no longer required. While at it, simplify the code by using the /proc interface. --- bin/release_ts.c | 28 ++++------------------------ include/litmus.h | 1 + src/kernel_iface.c | 15 ++++++++++----- 3 files changed, 15 insertions(+), 29 deletions(-) diff --git a/bin/release_ts.c b/bin/release_ts.c index 7752097..c2f6d4c 100644 --- a/bin/release_ts.c +++ b/bin/release_ts.c @@ -31,35 +31,14 @@ void usage(char *error) { void wait_until_ready(int expected) { int ready = 0, all = 0; - char buf[100]; int loops = 0; - ssize_t len; - do { if (loops++ > 0) sleep(1); - len = read_file(LITMUS_STATS_FILE, buf, sizeof(buf) - 1); - if (len < 0) { - fprintf(stderr, - "(EE) Error while reading '%s': %m.\n" - "(EE) Ignoring -w option.\n", - LITMUS_STATS_FILE); - break; - } else { - len = sscanf(buf, - "real-time tasks = %d\n" - "ready for release = %d\n", - &all, &ready); - if (len != 2) { - fprintf(stderr, - "(EE) Could not parse '%s'.\n" - "(EE) Ignoring -w option.\n", - LITMUS_STATS_FILE); - break; - } - } - } while (expected > ready || ready < all); + if (!read_litmus_stats(&ready, &all)) + perror("read_litmus_stats"); + } while (expected > ready || (!expected && ready < all)); } int main(int argc, char** argv) @@ -79,6 +58,7 @@ int main(int argc, char** argv) wait = 1; break; case 'f': + wait = 1; expected = atoi(optarg); break; case ':': diff --git a/include/litmus.h b/include/litmus.h index 677f9a9..3777088 100644 --- a/include/litmus.h +++ b/include/litmus.h @@ -121,6 +121,7 @@ int requested_to_preempt(void); int wait_for_ts_release(void); int release_ts(lt_t *delay); int get_nr_ts_release_waiters(void); +int read_litmus_stats(int *ready, int *total); #define __NS_PER_MS 1000000 diff --git a/src/kernel_iface.c b/src/kernel_iface.c index 4cc1af5..e446102 100644 --- a/src/kernel_iface.c +++ b/src/kernel_iface.c @@ -56,9 +56,8 @@ ssize_t read_file(const char* fname, void* buf, size_t maxlen) return got; } -int get_nr_ts_release_waiters(void) +int read_litmus_stats(int *ready, int *all) { - int ready = 0, all = 0; char buf[100]; ssize_t len; @@ -67,11 +66,17 @@ int get_nr_ts_release_waiters(void) len = sscanf(buf, "real-time tasks = %d\n" "ready for release = %d\n", - &all, &ready); - if (len == 2) + all, ready); + return len == 2; +} + +int get_nr_ts_release_waiters(void) +{ + int ready, all; + if (read_litmus_stats(&ready, &all)) return ready; else - return len; + return -1; } /* thread-local pointer to control page */ -- cgit v1.2.2