add proc option
authorLaurent MAZET <laurent.mazet@thalesgroup.com>
Thu, 4 Dec 2025 16:24:49 +0000 (17:24 +0100)
committerLaurent MAZET <laurent.mazet@thalesgroup.com>
Thu, 4 Dec 2025 16:24:49 +0000 (17:24 +0100)
main.c

diff --git a/main.c b/main.c
index 33871562b6ba11a63c4d4ed92afa1955df2d2c0d..bb08d9f4123953cc4e123308a778e2de92365fca 100644 (file)
--- 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;