add a load mode based on allocation/desallocation master
authorLaurent MAZET <laurent.mazet@thalesgroup.com>
Fri, 5 Dec 2025 15:06:18 +0000 (16:06 +0100)
committerLaurent MAZET <laurent.mazet@thalesgroup.com>
Fri, 5 Dec 2025 15:06:18 +0000 (16:06 +0100)
load.c

diff --git a/load.c b/load.c
index 852c5a2953779d0bdd224fcc9d23b46b820161a8..6ef166a1417366ca6352630415e97e4bbba60ecd 100644 (file)
--- a/load.c
+++ b/load.c
@@ -27,6 +27,7 @@ char *version = "0.1";
 
 int nb_threads = 1;
 int sched_rt_prio = 50;
+int do_clock = 0;
 int mode = 0;
 
 /* types */
@@ -41,9 +42,11 @@ typedef struct {
 int usage (int ret)
 {
     FILE *fd = ret ? stderr : stdout;
-    fprintf (fd, "usage: %s [-c] [-h] [-n int] [-r int] [-v]\n", progname);
+    fprintf (fd, "usage: %s [-a|-m] [-c] [-h] [-n int] [-r int] [-v]\n", progname);
+    fprintf (fd, " -a: load with allocation\n");
     fprintf (fd, " -c: estimate clock\n");
     fprintf (fd, " -h: help message\n");
+    fprintf (fd, " -m: load with mathematics\n");
     fprintf (fd, " -n: number of thread (%d)\n", nb_threads);
     fprintf (fd, " -r: real-time priority, -1 to desactivate (%d)\n", sched_rt_prio);
     fprintf (fd, " -v: print version\n");
@@ -171,7 +174,7 @@ void generate_matrix (matrix_t *matrix)
     }
 }
 
-void *work (__attribute__((unused)) void *arg)
+void *work_math (__attribute__((unused)) void *arg)
 {
     while (1) {
         matrix_t *matrix = alloc_matrix (N);
@@ -183,6 +186,16 @@ void *work (__attribute__((unused)) void *arg)
     pthread_exit (NULL);
 }
 
+void *work_alloc (__attribute__((unused)) void *arg)
+{
+    while (1) {
+        matrix_t *matrix = alloc_matrix (N);
+        //generate_matrix (matrix);
+        free_matrix (matrix);
+    }
+    pthread_exit (NULL);
+}
+
 double estimate_tics_clock (void)
 {
     int n = 4;
@@ -274,9 +287,15 @@ int main (int argc, char *argv[])
         }
         char c = arg[1];
         switch (c) {
+        case 'a':
+            mode = 1;
+            break;
         case 'c':
             arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL;
-            mode = (arg == NULL) ? 1 : atoi (arg);
+            do_clock = (arg == NULL) ? 1 : atoi (arg);
+            break;
+        case 'm':
+            mode = 0;
             break;
         case 'n':
             arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL;
@@ -324,7 +343,7 @@ int main (int argc, char *argv[])
 
     /* main process */
 
-    if (mode)  {
+    if (do_clock)  {
         cpu_set_t cpu_mask;
         CPU_ZERO (&cpu_mask);
         CPU_SET (0, &cpu_mask);
@@ -332,7 +351,7 @@ int main (int argc, char *argv[])
             fprintf (stderr, "error: sched_setaffinity\n");
             return 1;
         }
-        while (mode--) {
+        while (do_clock--) {
             printf ("\r");
             printf ("Tics clock: %.0fMHz", estimate_tics_clock () / 1e6);
             printf ("\t");
@@ -347,7 +366,7 @@ int main (int argc, char *argv[])
         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) {
+            if (pthread_create (&tid[i], NULL, (mode == 1) ? work_alloc : work_math, NULL) != 0) {
                 fprintf (stderr, "error on pthread_create\n");
                 return 1;
             }