Fixed scheduler settings in dc_user example; use CLOCK_MONOTONIC. stable-1.5
authorFlorian Pose
Tue, 13 Feb 2018 17:16:01 +0100
branchstable-1.5
changeset 2698 9e65f782e8a1
parent 2697 4f5ae7e0fbaa
child 2699 ed6b9e0d7c05
child 2723 37d89f56e9f1
Fixed scheduler settings in dc_user example; use CLOCK_MONOTONIC.
examples/dc_user/main.c
--- 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, &param) == -1) {
+        perror("sched_setscheduler failed");
+    }
 
 	printf("Starting cyclic function.\n");
     cyclic_task();