Signed-off-by: Daniel Wagner <daniel.wagner@xxxxxxxxxxxx> --- 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 <stdint.h> + #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 <sys/stat.h> #include <unistd.h> #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; +} -- 1.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-rt-users" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html