load support sched other and fifo
authorLaurent Mazet <mazet@softndesign.org>
Tue, 14 Oct 2025 20:41:49 +0000 (22:41 +0200)
committerLaurent Mazet <mazet@softndesign.org>
Tue, 14 Oct 2025 20:41:49 +0000 (22:41 +0200)
load.c

diff --git a/load.c b/load.c
index 2c2ec79b6f5d305dab0747ca8e229525f002008d..e5f6c7274ad7c7275a21b3c956ccb71ef99f594d 100644 (file)
--- a/load.c
+++ b/load.c
@@ -12,7 +12,6 @@
 
 /* constants */
 
-#define RT_PRIO 80
 //#define N 32
 #define N 10
 #define BREATH 20
@@ -23,6 +22,7 @@ char *progname = NULL;
 char *version = "0.1";
 
 int nb_threads = 1;
+int sched_rt_prio = 50;
 
 /* types */
 
@@ -40,6 +40,7 @@ int usage (int ret)
     fprintf (fd, " -h: help message\n");
     fprintf (fd, " -n: number of thread (%d)\n", nb_threads);
     fprintf (fd, " -n: print version\n");
+    fprintf (fd, " -r: real-time priority, -1 to desactivate (%d)\n", sched_rt_prio);
     fprintf (fd, "%s version %s\n", progname, version);
 
     return ret;
@@ -114,7 +115,7 @@ double determinant (matrix_t *matrix)
         double val;
         get_matrix (matrix, 0, l, &val);
         det += sign * val * determinant (comatrix);
-        usleep (BREATH);
+        //usleep (BREATH);
     }
     free_matrix (comatrix);
 
@@ -129,7 +130,7 @@ void generate_matrix (matrix_t *matrix)
             double val = base * (rand () - RAND_MAX / 2) / (double)RAND_MAX;
             set_matrix (matrix, i, j, val);
         }
-        usleep (BREATH);
+        //usleep (BREATH);
     }
 }
 
@@ -177,6 +178,14 @@ int main (int argc, char *argv[])
             }
             nb_threads = atoi (arg);
             break;
+        case 'r':
+            arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL;
+            if (arg == NULL) {
+                fprintf (stderr, "%s: real-time scheduler mode not specified\n", progname);
+                return usage (1);
+            }
+            sched_rt_prio = atoi (arg);
+            break;
         case 'v':
             printf ("version: %s\n", version);
             break;
@@ -186,22 +195,24 @@ int main (int argc, char *argv[])
         }
     }
 
-#if 1
-    /* real-time process */
+    if (sched_rt_prio >= 0) {
+
+        /* real-time process */
+
+        struct sched_param param = {0};
+        if (sched_getparam (0, &param) != 0) {
+            fprintf (stderr, "error: sched_getparam\n");
+            return 1;
+        }
+        param.sched_priority = sched_rt_prio;
+        int rc = sched_setscheduler (0, SCHED_FIFO, &param); /* non-preemptive */
+        // int rc = sched_setscheduler (0, SCHED_RR, &param); /* preemptive */
+        if (rc != 0) {
+            fprintf (stderr, "error: sched_setscheduler\n");
+            return 1;
+        }
 
-    struct sched_param param = {0};
-    if (sched_getparam (0, &param) != 0) {
-        fprintf (stderr, "error: sched_getparam\n");
-        return 1;
-    }
-    param.sched_priority = RT_PRIO;
-    int rc = sched_setscheduler (0, SCHED_FIFO, &param); /* non-preemptive */
-    // int rc = sched_setscheduler (0, SCHED_RR, &param); /* preemptive */
-    if (rc != 0) {
-        fprintf (stderr, "error: sched_setscheduler\n");
-        return 1;
     }
-#endif
 
     /* main process */