From: Laurent MAZET Date: Thu, 4 Dec 2025 16:24:49 +0000 (+0100) Subject: add proc option X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=3ffb11f88191cbef8b687215d57ac0ca0330668f;p=benchmarks.git add proc option --- diff --git a/main.c b/main.c index 3387156..bb08d9f 100644 --- a/main.c +++ b/main.c @@ -33,6 +33,7 @@ int hist_bin = 10; int mode = 0; int nb = 1000; int nb_cores = 0; +int proc = 0; char *output = NULL; extern char *message; @@ -44,7 +45,7 @@ extern int (*parse_arg_ext) (char *); int usage (int ret) { FILE *fd = ret ? stderr : stdout; - fprintf (fd, "usage: %s [-a int] [-b int] [-d int] [-e int] [-h] [-k int] [-m int] [-n int] [-o file] [-s]\n", progname); + fprintf (fd, "usage: %s [-a int] [-b int] [-d int] [-e int] [-h] [-k int] [-m int] [-n int] [-o file] [-p int] [-s]\n", progname); fprintf (fd, " -a: avoid aberrand valies (%g%%)\n", abe_per); fprintf (fd, " -d: delay process start for (%ds)\n", delay); fprintf (fd, " -b: nb bins for histogram (%d)\n", hist_bin); @@ -54,6 +55,7 @@ int usage (int ret) fprintf (fd, " -m: 0 for threads, 1 ping-pong process, 2 ping process, 3 pong process (%d)\n", mode); fprintf (fd, " -n: nb measurements (%d)\n", nb); fprintf (fd, " -o: output raw data (%s)\n", (output) ? output : "none"); + fprintf (fd, " -p: processor (%d)\n", proc); fprintf (fd, " -s: display statistics (%s)\n", (do_stat) ? "yes" : "no"); if (usage_ext) { fprintf (fd, "extension:\n"); @@ -80,9 +82,15 @@ typedef struct { void *launch (void *arg) { launch_param_t *param = (launch_param_t *)arg; + cpu_set_t cpu_mask; + if (sched_getaffinity (0, sizeof (cpu_set_t), &cpu_mask) != 0) { + fprintf (stderr, "error: sched_getaffinity\n"); + RETURN (mode, 1); + } + int nbcores = CPU_COUNT(&cpu_mask); int cpu = (nb_cores == 1) ? 0 : (nb_cores == 2) ? param->target : -1; if (cpu != -1) { - cpu_set_t cpu_mask; + cpu = (proc + cpu) % nbcores; CPU_ZERO (&cpu_mask); CPU_SET (cpu, &cpu_mask); if (sched_setaffinity (0, sizeof (cpu_set_t), &cpu_mask) != 0) { @@ -197,6 +205,14 @@ int main (int argc, char *argv[]) } output = arg; break; + case 'p': + arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL; + if (arg == NULL) { + fprintf (stderr, "%s: processor id not specified\n", progname); + return usage (1); + } + proc = atoi (arg); + break; case 's': do_stat = 1; break;