# HG changeset patch # User Florian Pose # Date 1518538561 -3600 # Node ID 9e65f782e8a19ad1405b3f1454b12ea204267e53 # Parent 4f5ae7e0fbaa0d31375bc514e3cb155ba801fa69 Fixed scheduler settings in dc_user example; use CLOCK_MONOTONIC. diff -r 4f5ae7e0fbaa -r 9e65f782e8a1 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 #include #include +#include /* 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();