Merge remote-tracking branch 'refs/remotes/origin/master'
authorLaurent MAZET <laurent.mazet@thalesgroup.com>
Wed, 8 Oct 2025 09:27:49 +0000 (11:27 +0200)
committerLaurent MAZET <laurent.mazet@thalesgroup.com>
Wed, 8 Oct 2025 12:53:39 +0000 (14:53 +0200)
1  2 
gettable.sh
load.c

diff --cc gettable.sh
index 1280967e4274c6795152bb78cd1a01a08f5d68b4,1280967e4274c6795152bb78cd1a01a08f5d68b4..4d852081b271518614c35cbfcf2fd3882535957e
@@@ -2,9 -2,9 +2,11 @@@
  
  echo "Test & Load & Minimum (us) & Average (us) & Maximun (us) & Standard Dev. (us) & 25th % (us) & Median (us) & 75th % (us)"
  
++nbcpu=$(grep -c processor /proc/cpuinfo)
  for t in *.exe; do
    t=${t/.exe/};
--  for p in 0 50 100; do
++  for k in $(seq 0 $nbcpu); do
++    p=$(expr $k \* 100 / $nbcpu)
      f=$t-$p%.log
      [ -f $f ] && awk -f gettable.awk -v COMMENT=$p% $f
    done
diff --cc load.c
index f2a2d0fe163fdfe752f78cceb76c354f3a5264eb,3726d33e4240b07f9c5f92b80c3073d44078adad..c4a896b877b7dc8345494f5943ad2b7e34f316ce
--- 1/load.c
--- 2/load.c
+++ b/load.c
@@@ -1,21 -1,16 +1,21 @@@
  /* depend: */
  /* cflags: */
--/* linker: */
++/* linker: -lpthread */
  
  #include <assert.h>
+ //#include <math.h>
++#include <pthread.h>
++#include <sched.h>
  #include <stdio.h>
  #include <stdlib.h>
++#include <unistd.h>
  
  /* constants */
  
- #define MAXSIZE 16;
- /* types */
- typedef struct {
-     int n;
-     double *mat;
- } matrix_t;
++#define RT_PRIO 80
+ //#define N 32
+ #define N 10
++#define BREATH 50
  
  /* static variables */
  
@@@ -107,11 -109,23 +114,36 @@@ double determinant (matrix_t *matrix
          double val;
          get_matrix (matrix, 0, l, &val);
          det += sign * val * determinant (comatrix);
++        usleep (BREATH);
      }
+     free_matrix (comatrix);
  
      return det;
  }
  
+ void generate_matrix (matrix_t *matrix)
+ {
+     double base = 10 * drand48 () - 5;
+     for (int i = 0; i < matrix->n; i++) {
+         for (int j = 0; j < matrix->n; j++) {
+             double val = base * (rand () - RAND_MAX / 2) / (double)RAND_MAX;
+             set_matrix (matrix, i, j, val);
+         }
++        usleep (BREATH);
+     }
+ }
++void *work (__attribute__((unused)) void *arg)
++{
++    while (1) {
++        matrix_t *matrix = alloc_matrix (N);
++        generate_matrix (matrix);
++        double det = determinant (matrix);
++        printf ("det: %g\n", det);
++    }
++    pthread_exit (NULL);
++}
++
  /* main function */
  
  int main (int argc, char *argv[])
          }
      }
  
++#if 1
++    /* 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 = 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 */
 -    while (1) {
 -        matrix_t *matrix = alloc_matrix (N);
 -        generate_matrix (matrix);
 -        double det = determinant (matrix);
 -        printf ("det: %g\n", det);
 +
++    if (nb_threads == 0) {
++        while (1) {
++            sleep (60);
++        }
++    } else {
++        pthread_t *tid = (pthread_t *) calloc (nb_threads, sizeof (pthread_t));
++        assert (tid);
++        for (int i = 0; i < nb_threads; i++) {
++            if (pthread_create (&tid[i], NULL, work, NULL) != 0) {
++                fprintf (stderr, "error on pthread_create\n");
++                return 1;
++            }
++        }
++
++        for (int i = 0; i < nb_threads; i++) {
++            pthread_join (tid[i], NULL);
++        }
+     }
      return 0;
  }