From: Laurent MAZET Date: Fri, 5 Dec 2025 15:06:18 +0000 (+0100) Subject: add a load mode based on allocation/desallocation X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=ed78f0f8f9c1c9d0630b7c78442699cafc84841b;p=benchmarks.git add a load mode based on allocation/desallocation --- diff --git a/load.c b/load.c index 852c5a2..6ef166a 100644 --- 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; }