summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarsten Emde <carsten.emde@osadl.org>2009-12-14 14:19:03 +0100
committerJohn Kacur <jkacur@redhat.com>2009-12-14 14:21:19 +0100
commitdce15eefef03154a684d5274aebe5a036ed45f99 (patch)
treec9ca31786c043f9d57c905da75abbe93a110a263
parenta6d367302e932b3a1d1865adf64a1a29b4d54ee4 (diff)
downloadrt-tests-dce15eefef03154a684d5274aebe5a036ed45f99.tar.gz
Start a separate library of functions for the rt-test suite.
The first couple are taken from cyclictest. Signed-off-by: Carsten Emde <carsten.emde@osadl.org> Signed-off-by: John Kacur <jkacur@redhat.com>
-rw-r--r--src/lib/rt-utils.c65
-rw-r--r--src/lib/rt-utils.h6
2 files changed, 71 insertions, 0 deletions
diff --git a/src/lib/rt-utils.c b/src/lib/rt-utils.c
new file mode 100644
index 0000000..4e7597c
--- /dev/null
+++ b/src/lib/rt-utils.c
@@ -0,0 +1,65 @@
+#include <stdio.h>
+#include <string.h>
+#include <sched.h>
+#include "rt-utils.h"
+
+static char debugfileprefix[MAX_PATH];
+
+/*
+ * Finds the tracing directory in a mounted debugfs
+ */
+char *get_debugfileprefix(void)
+{
+ char type[100];
+ FILE *fp;
+ int size;
+
+ if (debugfileprefix[0] != '\0')
+ return debugfileprefix;
+
+ if ((fp = fopen("/proc/mounts","r")) == NULL)
+ return debugfileprefix;
+
+ while (fscanf(fp, "%*s %"
+ STR(MAX_PATH)
+ "s %99s %*s %*d %*d\n",
+ debugfileprefix, type) == 2) {
+ if (strcmp(type, "debugfs") == 0)
+ break;
+ }
+ fclose(fp);
+
+ if (strcmp(type, "debugfs") != 0) {
+ debugfileprefix[0] = '\0';
+ return debugfileprefix;
+ }
+
+ size = sizeof(debugfileprefix) - strlen(debugfileprefix);
+ strncat(debugfileprefix, "/tracing/", size);
+
+ return debugfileprefix;
+}
+
+int check_privs(void)
+{
+ int policy = sched_getscheduler(0);
+ struct sched_param param;
+
+ /* if we're already running a realtime scheduler
+ * then we *should* be able to change things later
+ */
+ if (policy == SCHED_FIFO || policy == SCHED_RR)
+ return 0;
+
+ /* try to change to SCHED_FIFO */
+ param.sched_priority = 1;
+ if (sched_setscheduler(0, SCHED_FIFO, &param)) {
+ fprintf(stderr, "Unable to change scheduling policy!\n");
+ fprintf(stderr, "either run as root or join realtime group\n");
+ return 1;
+ }
+
+ /* we're good; change back and return success */
+ sched_setscheduler(0, policy, NULL);
+ return 0;
+}
diff --git a/src/lib/rt-utils.h b/src/lib/rt-utils.h
new file mode 100644
index 0000000..e9c8cdd
--- /dev/null
+++ b/src/lib/rt-utils.h
@@ -0,0 +1,6 @@
+#define _STR(x) #x
+#define STR(x) _STR(x)
+#define MAX_PATH 256
+
+int check_privs(void);
+char *get_debugfileprefix(void);