From e875ad63d36a316bbe0f8233fffa5b67cfe837a4 Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Wed, 5 Nov 2014 10:09:43 +0100 Subject: rt-utils: Add helper to parse/print scheduling policies Signed-off-by: Daniel Wagner --- src/include/rt-utils.h | 5 +++++ src/lib/rt-utils.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/src/include/rt-utils.h b/src/include/rt-utils.h index 4a7d01f..37f46c8 100644 --- a/src/include/rt-utils.h +++ b/src/include/rt-utils.h @@ -1,6 +1,8 @@ #ifndef __RT_UTILS_H #define __RT_UTILS_H +#include + #define _STR(x) #x #define STR(x) _STR(x) #define MAX_PATH 256 @@ -17,4 +19,7 @@ int event_disable(char *event); int event_enable_all(void); int event_disable_all(void); +const char *policy_to_string(int policy); +uint32_t string_to_policy(const char *str); + #endif /* __RT_UTILS.H */ diff --git a/src/lib/rt-utils.c b/src/lib/rt-utils.c index f4da4b3..df522fe 100644 --- a/src/lib/rt-utils.c +++ b/src/lib/rt-utils.c @@ -17,6 +17,7 @@ #include #include #include "rt-utils.h" +#include "rt-sched.h" #include "error.h" static char debugfileprefix[MAX_PATH]; @@ -273,3 +274,40 @@ int check_privs(void) return sched_setscheduler(0, policy, &old_param); } +const char *policy_to_string(int policy) +{ + switch (policy) { + case SCHED_OTHER: + return "SCHED_OTHER"; + case SCHED_FIFO: + return "SCHED_FIFO"; + case SCHED_RR: + return "SCHED_RR"; + case SCHED_BATCH: + return "SCHED_BATCH"; + case SCHED_IDLE: + return "SCHED_IDLE"; + case SCHED_DEADLINE: + return "SCHED_DEADLINE"; + } + + return "unknown"; +} + +uint32_t string_to_policy(const char *str) +{ + if (!strcmp(str, "other")) + return SCHED_OTHER; + else if (!strcmp(str, "fifo")) + return SCHED_FIFO; + else if (!strcmp(str, "rr")) + return SCHED_RR; + else if (!strcmp(str, "batch")) + return SCHED_BATCH; + else if (!strcmp(str, "idle")) + return SCHED_IDLE; + else if (!strcmp(str, "deadline")) + return SCHED_DEADLINE; + + return 0; +} -- cgit 1.2.3-korg