rt-utils: Add helper to parse/print scheduling policies

Signed-off-by: Daniel Wagner <daniel.wagner@bmw-carit.de>
This commit is contained in:
Daniel Wagner 2014-11-05 10:09:43 +01:00 committed by Clark Williams
parent ef2dee4232
commit e875ad63d3
2 changed files with 43 additions and 0 deletions

View File

@ -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 */

View File

@ -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;
}