Fixed scheduler settings in dc_user example; use CLOCK_MONOTONIC.
--- a/examples/dc_user/main.c Tue Feb 06 14:58:14 2018 +0100
+++ b/examples/dc_user/main.c Tue Feb 13 17:16:01 2018 +0100
@@ -38,6 +38,7 @@
#include <time.h>
#include <sys/mman.h>
#include <malloc.h>
+#include <sched.h> /* sched_setscheduler() */
/****************************************************************************/
@@ -47,7 +48,7 @@
// Application parameters
#define FREQUENCY 1000
-#define CLOCK_TO_USE CLOCK_REALTIME
+#define CLOCK_TO_USE CLOCK_MONOTONIC
#define MEASURE_TIMING
/****************************************************************************/
@@ -313,10 +314,15 @@
return -1;
}
- pid_t pid = getpid();
- if (setpriority(PRIO_PROCESS, pid, -19))
- fprintf(stderr, "Warning: Failed to set priority: %s\n",
- strerror(errno));
+ /* Set priority */
+
+ struct sched_param param = {};
+ param.sched_priority = sched_get_priority_max(SCHED_FIFO);
+
+ printf("Using priority %i.", param.sched_priority);
+ if (sched_setscheduler(0, SCHED_FIFO, ¶m) == -1) {
+ perror("sched_setscheduler failed");
+ }
printf("Starting cyclic function.\n");
cyclic_task();