Skip to contentSkip to conversation

risu cleanups and improvements

PATCH Superseded Richard Henderson 3 participants 20 messages May 13, 2020 – May 18, 2020

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover risu cleanups and improvements

This patch set does alter the format of the trace files, and thus means we'll have to re-generate these. However, the space saved for sve trace files is significant, so I consider it worthwhile.

In addition, the new --dump option allows one to inspect the contents of the trace file.

r~

Richard Henderson (9):
Use bool for tracing variables
Unify master_fd and apprentice_fd to comm_fd
Hoist trace file opening
Adjust tracefile open for write
Use EXIT_FAILURE, EXIT_SUCCESS
Add magic and size to the trace header
Compute reginfo_size based on the reginfo
aarch64: Reorg sve reginfo to save space
Add --dump option to inspect trace files

 risu.h                 |  12 ++-
 risu_reginfo_aarch64.h |  16 +---
 comms.c                |  26 +++---
 reginfo.c              |  45 ++++++---
 risu.c                 | 208 ++++++++++++++++++++++++++++++-----------
 risu_reginfo_aarch64.c | 192 ++++++++++++++++++++-----------------
 risu_reginfo_arm.c     |   6 +-
 risu_reginfo_i386.c    |   8 +-
 risu_reginfo_m68k.c    |   6 +-
 risu_reginfo_ppc64.c   |   6 +-
 10 files changed, 342 insertions(+), 183 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/9 Use bool for tracing variables

---
 risu.h    | 3 ++-
 reginfo.c | 2 +-
 risu.c    | 8 ++++----
 3 files changed, 7 insertions(+), 6 deletions(-)
risu.h +2 -1
index 8d2d646..e2b4508 100644
@@ -17,6 +17,7 @@
 #include <ucontext.h>
 #include <stdio.h>
 #include <getopt.h>
+#include <stdbool.h>
 
 /* Extra option processing for architectures */
 extern const struct option * const arch_long_opts;
@@ -96,7 +97,7 @@ int recv_and_compare_register_info(read_fn read_fn,
  * Should return 0 if it was a good match (ie end of test)
  * and 1 for a mismatch.
  */
-int report_match_status(int trace);
+int report_match_status(bool trace);
 
 /* Interface provided by CPU-specific code: */
 
reginfo.c +1 -1
index dd42ae2..1b2a821 100644
@@ -141,7 +141,7 @@ int recv_and_compare_register_info(read_fn read_fn,
  * Should return 0 if it was a good match (ie end of test)
  * and 1 for a mismatch.
  */
-int report_match_status(int trace)
+int report_match_status(bool trace)
 {
     int resp = 0;
     fprintf(stderr, "match status...\n");
risu.c +4 -4
index 01525d2..79b1092 100644
@@ -31,7 +31,7 @@
 void *memblock;
 
 int apprentice_fd, master_fd;
-int trace;
+bool trace;
 size_t signal_count;
 
 #ifdef HAVE_ZLIB
@@ -228,7 +228,7 @@ int master(void)
                     signal_count);
             return 0;
         } else {
-            return report_match_status(0);
+            return report_match_status(false);
         }
     }
     set_sigill_handler(&master_sigill);
@@ -250,7 +250,7 @@ int apprentice(void)
 #endif
         close(apprentice_fd);
         fprintf(stderr, "finished early after %zd checkpoints\n", signal_count);
-        return report_match_status(1);
+        return report_match_status(true);
     }
     set_sigill_handler(&apprentice_sigill);
     fprintf(stderr, "starting apprentice image at 0x%"PRIxPTR"\n",
@@ -344,7 +344,7 @@ int main(int argc, char **argv)
             break;
         case 't':
             trace_fn = optarg;
-            trace = 1;
+            trace = true;
             break;
         case 'h':
             hostname = optarg;
Signature · 1 line
2.20.1
#3 lore raw

PATCH 2/9 Unify master_fd and apprentice_fd to comm_fd

In reply to Richard Henderson

Any one invocation cannot be both master and apprentice. Let's use only one variable for the file descriptor.

---
 risu.c | 40 ++++++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 20 deletions(-)
risu.c +20 -20
index 79b1092..059348f 100644
@@ -30,7 +30,7 @@
 
 void *memblock;
 
-int apprentice_fd, master_fd;
+static int comm_fd;
 bool trace;
 size_t signal_count;
 
@@ -50,7 +50,7 @@ sigjmp_buf jmpbuf;
 
 int read_sock(void *ptr, size_t bytes)
 {
-    return recv_data_pkt(master_fd, ptr, bytes);
+    return recv_data_pkt(comm_fd, ptr, bytes);
 }
 
 int write_trace(void *ptr, size_t bytes)
@@ -58,9 +58,9 @@ int write_trace(void *ptr, size_t bytes)
     size_t res;
 
 #ifdef HAVE_ZLIB
-    if (master_fd == STDOUT_FILENO) {
+    if (comm_fd == STDOUT_FILENO) {
 #endif
-        res = write(master_fd, ptr, bytes);
+        res = write(comm_fd, ptr, bytes);
 #ifdef HAVE_ZLIB
     } else {
         res = gzwrite(gz_trace_file, ptr, bytes);
@@ -71,14 +71,14 @@ int write_trace(void *ptr, size_t bytes)
 
 void respond_sock(int r)
 {
-    send_response_byte(master_fd, r);
+    send_response_byte(comm_fd, r);
 }
 
 /* Apprentice function */
 
 int write_sock(void *ptr, size_t bytes)
 {
-    return send_data_pkt(apprentice_fd, ptr, bytes);
+    return send_data_pkt(comm_fd, ptr, bytes);
 }
 
 int read_trace(void *ptr, size_t bytes)
@@ -86,9 +86,9 @@ int read_trace(void *ptr, size_t bytes)
     size_t res;
 
 #ifdef HAVE_ZLIB
-    if (apprentice_fd == STDIN_FILENO) {
+    if (comm_fd == STDIN_FILENO) {
 #endif
-        res = read(apprentice_fd, ptr, bytes);
+        res = read(comm_fd, ptr, bytes);
 #ifdef HAVE_ZLIB
     } else {
         res = gzread(gz_trace_file, ptr, bytes);
@@ -218,11 +218,11 @@ int master(void)
 {
     if (sigsetjmp(jmpbuf, 1)) {
 #ifdef HAVE_ZLIB
-        if (trace && master_fd != STDOUT_FILENO) {
+        if (trace && comm_fd != STDOUT_FILENO) {
             gzclose(gz_trace_file);
         }
 #endif
-        close(master_fd);
+        close(comm_fd);
         if (trace) {
             fprintf(stderr, "trace complete after %zd checkpoints\n",
                     signal_count);
@@ -244,11 +244,11 @@ int apprentice(void)
 {
     if (sigsetjmp(jmpbuf, 1)) {
 #ifdef HAVE_ZLIB
-        if (trace && apprentice_fd != STDIN_FILENO) {
+        if (trace && comm_fd != STDIN_FILENO) {
             gzclose(gz_trace_file);
         }
 #endif
-        close(apprentice_fd);
+        close(comm_fd);
         fprintf(stderr, "finished early after %zd checkpoints\n", signal_count);
         return report_match_status(true);
     }
@@ -375,31 +375,31 @@ int main(int argc, char **argv)
     if (ismaster) {
         if (trace) {
             if (strcmp(trace_fn, "-") == 0) {
-                master_fd = STDOUT_FILENO;
+                comm_fd = STDOUT_FILENO;
             } else {
-                master_fd = open(trace_fn, O_WRONLY | O_CREAT, S_IRWXU);
+                comm_fd = open(trace_fn, O_WRONLY | O_CREAT, S_IRWXU);
 #ifdef HAVE_ZLIB
-                gz_trace_file = gzdopen(master_fd, "wb9");
+                gz_trace_file = gzdopen(comm_fd, "wb9");
 #endif
             }
         } else {
             fprintf(stderr, "master port %d\n", port);
-            master_fd = master_connect(port);
+            comm_fd = master_connect(port);
         }
         return master();
     } else {
         if (trace) {
             if (strcmp(trace_fn, "-") == 0) {
-                apprentice_fd = STDIN_FILENO;
+                comm_fd = STDIN_FILENO;
             } else {
-                apprentice_fd = open(trace_fn, O_RDONLY);
+                comm_fd = open(trace_fn, O_RDONLY);
 #ifdef HAVE_ZLIB
-                gz_trace_file = gzdopen(apprentice_fd, "rb");
+                gz_trace_file = gzdopen(comm_fd, "rb");
 #endif
             }
         } else {
             fprintf(stderr, "apprentice host %s port %d\n", hostname, port);
-            apprentice_fd = apprentice_connect(hostname, port);
+            comm_fd = apprentice_connect(hostname, port);
         }
         return apprentice();
     }
Signature · 1 line
2.20.1
Reviewed-by on v1 2/9
#4 lore raw

Re: [RISU 2/9] Unify master_fd and apprentice_fd to comm_fd

Quoted 8 lines · Richard Henderson

Any one invocation cannot be both master and apprentice. Let's use only one variable for the file descriptor.

---
 risu.c | 40 ++++++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 20 deletions(-)

thanks
-- PMM

#5 lore raw

PATCH 3/9 Hoist trace file opening

In reply to Richard Henderson
---
 risu.c | 37 +++++++++++++++++--------------------
 1 file changed, 17 insertions(+), 20 deletions(-)
risu.c +17 -20
index 059348f..1c66885 100644
@@ -363,6 +363,21 @@ int main(int argc, char **argv)
         }
     }
 
+    if (trace) {
+        if (strcmp(trace_fn, "-") == 0) {
+            comm_fd = ismaster ? STDOUT_FILENO : STDIN_FILENO;
+        } else {
+            if (ismaster) {
+                comm_fd = open(trace_fn, O_WRONLY | O_CREAT, S_IRWXU);
+            } else {
+                comm_fd = open(trace_fn, O_RDONLY);
+            }
+#ifdef HAVE_ZLIB
+            gz_trace_file = gzdopen(comm_fd, ismaster ? "wb9" : "rb");
+#endif
+        }
+    }
+
     imgfile = argv[optind];
     if (!imgfile) {
         fprintf(stderr, "Error: must specify image file name\n\n");
@@ -373,31 +388,13 @@ int main(int argc, char **argv)
     load_image(imgfile);
 
     if (ismaster) {
-        if (trace) {
-            if (strcmp(trace_fn, "-") == 0) {
-                comm_fd = STDOUT_FILENO;
-            } else {
-                comm_fd = open(trace_fn, O_WRONLY | O_CREAT, S_IRWXU);
-#ifdef HAVE_ZLIB
-                gz_trace_file = gzdopen(comm_fd, "wb9");
-#endif
-            }
-        } else {
+        if (!trace) {
             fprintf(stderr, "master port %d\n", port);
             comm_fd = master_connect(port);
         }
         return master();
     } else {
-        if (trace) {
-            if (strcmp(trace_fn, "-") == 0) {
-                comm_fd = STDIN_FILENO;
-            } else {
-                comm_fd = open(trace_fn, O_RDONLY);
-#ifdef HAVE_ZLIB
-                gz_trace_file = gzdopen(comm_fd, "rb");
-#endif
-            }
-        } else {
+        if (!trace) {
             fprintf(stderr, "apprentice host %s port %d\n", hostname, port);
             comm_fd = apprentice_connect(hostname, port);
         }
Signature · 1 line
2.20.1
Reviewed-by on v1 3/9
#6 lore raw

Re: [RISU 3/9] Hoist trace file opening

Quoted 18 lines · Richard Henderson
---
 risu.c | 37 +++++++++++++++++--------------------
 1 file changed, 17 insertions(+), 20 deletions(-)
risu.c +4 -0
index 059348f..1c66885 100644
@@ -363,6 +363,21 @@ int main(int argc, char **argv)
         }
     }
 
+    if (trace) {
+        if (strcmp(trace_fn, "-") == 0) {
+            comm_fd = ismaster ? STDOUT_FILENO : STDIN_FILENO;
+        } else {

risu.c int main(int argc, char **argv) · line 379

Quoted 10 lines
risu.c +10 -0
+            if (ismaster) {
+                comm_fd = open(trace_fn, O_WRONLY | O_CREAT, S_IRWXU);
+            } else {
+                comm_fd = open(trace_fn, O_RDONLY);
+            }
+#ifdef HAVE_ZLIB
+            gz_trace_file = gzdopen(comm_fd, ismaster ? "wb9" : "rb");
+#endif
+        }
+    }

Looking at later patches in the series I see the rationale. We should really be error-checking the opens here, but that's a preexisting bug.

thanks
-- PMM

#7 lore raw

PATCH 4/9 Adjust tracefile open for write

In reply to Richard Henderson

Truncate the new output file. Rely on umask to remove group+other file permissions, if desired.

---
 risu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
risu.c +1 -1
index 1c66885..f404d8f 100644
@@ -368,7 +368,7 @@ int main(int argc, char **argv)
             comm_fd = ismaster ? STDOUT_FILENO : STDIN_FILENO;
         } else {
             if (ismaster) {
-                comm_fd = open(trace_fn, O_WRONLY | O_CREAT, S_IRWXU);
+                comm_fd = open(trace_fn, O_WRONLY | O_CREAT | O_TRUNC, 0666);
             } else {
                 comm_fd = open(trace_fn, O_RDONLY);
             }
Signature · 1 line
2.20.1
Reviewed-by on v1 4/9
#8 lore raw

Re: [RISU 4/9] Adjust tracefile open for write

Quoted 14 lines · Richard Henderson

Truncate the new output file. Rely on umask to remove group+other file permissions, if desired.

---
 risu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
risu.c +0 -0
index 1c66885..f404d8f 100644

risu.c int main(int argc, char **argv) · line 374

Quoted 8 lines
risu.c +1 -1
@@ -368,7 +368,7 @@ int main(int argc, char **argv)
             comm_fd = ismaster ? STDOUT_FILENO : STDIN_FILENO;
         } else {
             if (ismaster) {
-                comm_fd = open(trace_fn, O_WRONLY | O_CREAT, S_IRWXU);
+                comm_fd = open(trace_fn, O_WRONLY | O_CREAT | O_TRUNC, 0666);
             } else {
                 comm_fd = open(trace_fn, O_RDONLY);
             }

I dunno why we were giving it execute permissions...

thanks
-- PMM

#9 lore raw

PATCH 5/9 Use EXIT_FAILURE, EXIT_SUCCESS

In reply to Richard Henderson

Some of the time we exit via the return value from main. This can make it easier to tell what it is we're returning.

---
 comms.c                | 26 +++++++++++++-------------
 risu.c                 | 22 +++++++++++-----------
 risu_reginfo_aarch64.c |  4 ++--
 risu_reginfo_i386.c    |  2 +-
 4 files changed, 27 insertions(+), 27 deletions(-)
comms.c +13 -13
index 6946fd9..861e845 100644
@@ -31,7 +31,7 @@ int apprentice_connect(const char *hostname, int port)
     sock = socket(PF_INET, SOCK_STREAM, 0);
     if (sock < 0) {
         perror("socket");
-        exit(1);
+        exit(EXIT_FAILURE);
     }
     struct hostent *hostinfo;
     sa.sin_family = AF_INET;
@@ -39,12 +39,12 @@ int apprentice_connect(const char *hostname, int port)
     hostinfo = gethostbyname(hostname);
     if (!hostinfo) {
         fprintf(stderr, "Unknown host %s\n", hostname);
-        exit(1);
+        exit(EXIT_FAILURE);
     }
     sa.sin_addr = *(struct in_addr *) hostinfo->h_addr;
     if (connect(sock, (struct sockaddr *) &sa, sizeof(sa)) < 0) {
         perror("connect");
-        exit(1);
+        exit(EXIT_FAILURE);
     }
     return sock;
 }
@@ -56,13 +56,13 @@ int master_connect(int port)
     sock = socket(PF_INET, SOCK_STREAM, 0);
     if (sock < 0) {
         perror("socket");
-        exit(1);
+        exit(EXIT_FAILURE);
     }
     int sora = 1;
     if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &sora, sizeof(sora)) !=
         0) {
         perror("setsockopt(SO_REUSEADDR)");
-        exit(1);
+        exit(EXIT_FAILURE);
     }
 
     sa.sin_family = AF_INET;
@@ -70,11 +70,11 @@ int master_connect(int port)
     sa.sin_addr.s_addr = htonl(INADDR_ANY);
     if (bind(sock, (struct sockaddr *) &sa, sizeof(sa)) < 0) {
         perror("bind");
-        exit(1);
+        exit(EXIT_FAILURE);
     }
     if (listen(sock, 1) < 0) {
         perror("listen");
-        exit(1);
+        exit(EXIT_FAILURE);
     }
     /* Just block until we get a connection */
     fprintf(stderr, "master: waiting for connection on port %d...\n",
@@ -84,7 +84,7 @@ int master_connect(int port)
     int nsock = accept(sock, (struct sockaddr *) &csa, &csasz);
     if (nsock < 0) {
         perror("accept");
-        exit(1);
+        exit(EXIT_FAILURE);
     }
     /* We're done with the server socket now */
     close(sock);
@@ -104,7 +104,7 @@ static void recv_bytes(int sock, void *pkt, int pktlen)
                 continue;
             }
             perror("read failed");
-            exit(1);
+            exit(EXIT_FAILURE);
         }
         pktlen -= i;
         p += i;
@@ -127,7 +127,7 @@ static void recv_and_discard_bytes(int sock, int pktlen)
                 continue;
             }
             perror("read failed");
-            exit(1);
+            exit(EXIT_FAILURE);
         }
         pktlen -= i;
     }
@@ -186,12 +186,12 @@ int send_data_pkt(int sock, void *pkt, int pktlen)
 
     if (safe_writev(sock, iov, 2) == -1) {
         perror("writev failed");
-        exit(1);
+        exit(EXIT_FAILURE);
     }
 
     if (read(sock, &resp, 1) != 1) {
         perror("read failed");
-        exit(1);
+        exit(EXIT_FAILURE);
     }
     return resp;
 }
@@ -217,6 +217,6 @@ void send_response_byte(int sock, int resp)
     unsigned char r = resp;
     if (write(sock, &r, 1) != 1) {
         perror("write failed");
-        exit(1);
+        exit(EXIT_FAILURE);
     }
 }
risu.c +11 -11
index f404d8f..979341c 100644
@@ -153,13 +153,13 @@ void apprentice_sigill(int sig, siginfo_t *si, void *uc)
         return;
     case 1:
         /* end of test */
-        exit(0);
+        exit(EXIT_SUCCESS);
     default:
         /* mismatch */
         if (trace) {
             siglongjmp(jmpbuf, 1);
         }
-        exit(1);
+        exit(EXIT_FAILURE);
     }
 }
 
@@ -173,7 +173,7 @@ static void set_sigill_handler(void (*fn) (int, siginfo_t *, void *))
     sigemptyset(&sa.sa_mask);
     if (sigaction(SIGILL, &sa, 0) != 0) {
         perror("sigaction");
-        exit(1);
+        exit(EXIT_FAILURE);
     }
 }
 
@@ -190,11 +190,11 @@ void load_image(const char *imgfile)
     int fd = open(imgfile, O_RDONLY);
     if (fd < 0) {
         fprintf(stderr, "failed to open image file %s\n", imgfile);
-        exit(1);
+        exit(EXIT_FAILURE);
     }
     if (fstat(fd, &st) != 0) {
         perror("fstat");
-        exit(1);
+        exit(EXIT_FAILURE);
     }
     size_t len = st.st_size;
     void *addr;
@@ -207,7 +207,7 @@ void load_image(const char *imgfile)
              0);
     if (!addr) {
         perror("mmap");
-        exit(1);
+        exit(EXIT_FAILURE);
     }
     close(fd);
     image_start = addr;
@@ -226,7 +226,7 @@ int master(void)
         if (trace) {
             fprintf(stderr, "trace complete after %zd checkpoints\n",
                     signal_count);
-            return 0;
+            return EXIT_SUCCESS;
         } else {
             return report_match_status(false);
         }
@@ -237,7 +237,7 @@ int master(void)
     fprintf(stderr, "starting image\n");
     image_start();
     fprintf(stderr, "image returned unexpectedly\n");
-    exit(1);
+    return EXIT_FAILURE;
 }
 
 int apprentice(void)
@@ -258,7 +258,7 @@ int apprentice(void)
     fprintf(stderr, "starting image\n");
     image_start();
     fprintf(stderr, "image returned unexpectedly\n");
-    exit(1);
+    return EXIT_FAILURE;
 }
 
 int ismaster;
@@ -355,7 +355,7 @@ int main(int argc, char **argv)
             break;
         case '?':
             usage();
-            exit(1);
+            return EXIT_FAILURE;
         default:
             assert(c >= FIRST_ARCH_OPT);
             process_arch_opt(c, optarg);
@@ -382,7 +382,7 @@ int main(int argc, char **argv)
     if (!imgfile) {
         fprintf(stderr, "Error: must specify image file name\n\n");
         usage();
-        exit(1);
+        return EXIT_FAILURE;
     }
 
     load_image(imgfile);
risu_reginfo_aarch64.c +2 -2
index 00d1c8b..028c690 100644
@@ -51,7 +51,7 @@ void process_arch_opt(int opt, const char *arg)
 
     if (test_sve <= 0 || test_sve > SVE_VQ_MAX) {
         fprintf(stderr, "Invalid value for VQ (1-%d)\n", SVE_VQ_MAX);
-        exit(1);
+        exit(EXIT_FAILURE);
     }
     want = sve_vl_from_vq(test_sve);
     got = prctl(PR_SVE_SET_VL, want);
@@ -62,7 +62,7 @@ void process_arch_opt(int opt, const char *arg)
             fprintf(stderr, "Unsupported value for VQ (%d != %d)\n",
                     test_sve, (int)sve_vq_from_vl(got));
         }
-        exit(1);
+        exit(EXIT_FAILURE);
     }
 #else
     abort();
risu_reginfo_i386.c +1 -1
index 194e0ad..60fc239 100644
@@ -69,7 +69,7 @@ void process_arch_opt(int opt, const char *arg)
             fprintf(stderr,
                     "Unable to parse '%s' in '%s' into an xfeatures integer mask\n",
                     endptr, arg);
-            exit(1);
+            exit(EXIT_FAILURE);
         }
     }
 }
Signature · 1 line
2.20.1
#11 lore raw

Re: [RISU 5/9] Use EXIT_FAILURE, EXIT_SUCCESS

Quoted 9 lines · Peter Maydell
Quoted 5 lines · Richard Henderson

Some of the time we exit via the return value from main. This can make it easier to tell what it is we're returning.

I don't really see the benefit personally, but

It wasn't so much for the direct calls of exit, but when we return an "int" that gets passed to exit later.

r~

#12 lore raw

PATCH 6/9 Add magic and size to the trace header

In reply to Richard Henderson

Sanity check that we're not getting out of sync with the trace stream. This will be especially bad with the change in size of the sve save data.

---
 risu.h    |  6 +++++-
 reginfo.c | 42 ++++++++++++++++++++++++++++++++----------
 2 files changed, 37 insertions(+), 11 deletions(-)
risu.h +5 -1
index e2b4508..3fc198f 100644
@@ -62,10 +62,14 @@ extern void *memblock;
 struct reginfo;
 
 typedef struct {
-   uintptr_t pc;
+   uint32_t magic;
+   uint32_t size;
    uint32_t risu_op;
+   uintptr_t pc;
 } trace_header_t;
 
+#define RISU_MAGIC  (('R' << 24) | ('i' << 16) | ('S' << 8) | 'u')
+
 /* Functions operating on reginfo */
 
 /* Function prototypes for read/write helper functions.
reginfo.c +32 -10

87 lines not on this page · raw message

Signature · 1 line
2.20.1
#13 lore raw

PATCH 7/9 Compute reginfo_size based on the reginfo

In reply to Richard Henderson

This will allow dumping of SVE frames without having to know the SVE vector length beforehand.

---
 risu.h                 | 2 +-
 reginfo.c              | 7 ++++---
 risu_reginfo_aarch64.c | 4 ++--
 risu_reginfo_arm.c     | 2 +-
 risu_reginfo_i386.c    | 2 +-
 risu_reginfo_m68k.c    | 2 +-
 risu_reginfo_ppc64.c   | 2 +-
 7 files changed, 11 insertions(+), 10 deletions(-)
risu.h +1 -1
index 3fc198f..0ae7fa9 100644
@@ -139,6 +139,6 @@ int reginfo_dump(struct reginfo *ri, FILE * f);
 int reginfo_dump_mismatch(struct reginfo *m, struct reginfo *a, FILE *f);
 
 /* return size of reginfo */
-const int reginfo_size(void);
+int reginfo_size(struct reginfo *ri);
 
 #endif /* RISU_H */
reginfo.c +4 -3
index a4f7da6..1727867 100644
@@ -40,7 +40,7 @@ int send_register_info(write_fn write_fn, void *uc)
     case OP_TESTEND:
     case OP_COMPARE:
     default:
-        header.size = reginfo_size();
+        header.size = reginfo_size(&ri);
         extra = &ri;
         break;
 
@@ -121,8 +121,9 @@ int recv_and_compare_register_info(read_fn read_fn,
         /* Do a simple register compare on (a) explicit request
          * (b) end of test (c) a non-risuop UNDEF
          */
-        if (header.size != reginfo_size() ||
-            read_fn(&apprentice_ri, header.size)) {
+        if (header.size > sizeof(struct reginfo) ||
+            read_fn(&apprentice_ri, header.size) ||
+            header.size != reginfo_size(&apprentice_ri)) {
             packet_mismatch = 1;
             resp = 2;
         } else if (!reginfo_is_eq(&master_ri, &apprentice_ri)) {
risu_reginfo_aarch64.c +2 -2
index 028c690..7044648 100644
@@ -69,7 +69,7 @@ void process_arch_opt(int opt, const char *arg)
 #endif
 }
 
-const int reginfo_size(void)
+int reginfo_size(struct reginfo *ri)
 {
     int size = offsetof(struct reginfo, simd.end);
 #ifdef SVE_MAGIC
@@ -194,7 +194,7 @@ void reginfo_init(struct reginfo *ri, ucontext_t *uc)
 /* reginfo_is_eq: compare the reginfo structs, returns nonzero if equal */
 int reginfo_is_eq(struct reginfo *r1, struct reginfo *r2)
 {
-    return memcmp(r1, r2, reginfo_size()) == 0;
+    return memcmp(r1, r2, reginfo_size(r1)) == 0;
 }
 
 #ifdef SVE_MAGIC
risu_reginfo_arm.c +1 -1
index 3662f12..3832e27 100644
@@ -36,7 +36,7 @@ void process_arch_opt(int opt, const char *arg)
     abort();
 }
 
-const int reginfo_size(void)
+int reginfo_size(struct reginfo *ri)
 {
     return sizeof(struct reginfo);
 }
risu_reginfo_i386.c +1 -1
index 60fc239..902d33e 100644
@@ -74,7 +74,7 @@ void process_arch_opt(int opt, const char *arg)
     }
 }
 
-const int reginfo_size(void)
+int reginfo_size(struct reginfo *ri)
 {
     return sizeof(struct reginfo);
 }
risu_reginfo_m68k.c +1 -1
index 32b28c8..361f172 100644
@@ -23,7 +23,7 @@ void process_arch_opt(int opt, const char *arg)
     abort();
 }
 
-const int reginfo_size(void)
+int reginfo_size(struct reginfo *ri)
 {
     return sizeof(struct reginfo);
 }
risu_reginfo_ppc64.c +1 -1
index 071c951..c86313c 100644
@@ -32,7 +32,7 @@ void process_arch_opt(int opt, const char *arg)
     abort();
 }
 
-const int reginfo_size(void)
+int reginfo_size(struct reginfo *ri)
 {
     return sizeof(struct reginfo);
 }
Signature · 1 line
2.20.1
#14 lore raw

PATCH 8/9 aarch64: Reorg sve reginfo to save space

In reply to Richard Henderson

Mirror the signal frame by storing all of the registers as a lump. Use the signal macros to pull out the values.

---
 risu_reginfo_aarch64.h |  16 +----
 risu_reginfo_aarch64.c | 135 +++++++++++++++++++++--------------------
 2 files changed, 73 insertions(+), 78 deletions(-)
risu_reginfo_aarch64.h +3 -13
index c33b86f..01076b4 100644
@@ -17,20 +17,8 @@
 
 struct simd_reginfo {
     __uint128_t vregs[32];
-    char end[0];
 };
 
-#ifdef SVE_MAGIC
-struct sve_reginfo {
-    /* SVE */
-    uint16_t    vl; /* current VL */
-    __uint128_t zregs[SVE_NUM_ZREGS][SVE_VQ_MAX];
-    uint16_t    pregs[SVE_NUM_PREGS][SVE_VQ_MAX];
-    uint16_t    ffr[SVE_VQ_MAX];
-    char end[0];
-};
-#endif
-
 /* The kernel headers set this based on future arch extensions.
    The current arch maximum is 16.  Save space below.  */
 #undef SVE_VQ_MAX
@@ -47,11 +35,13 @@ struct reginfo {
     /* FP/SIMD */
     uint32_t fpsr;
     uint32_t fpcr;
+    uint32_t sve_vl;
 
     union {
         struct simd_reginfo simd;
 #ifdef SVE_MAGIC
-        struct sve_reginfo sve;
+        char sve[SVE_SIG_CONTEXT_SIZE(16) - SVE_SIG_REGS_OFFSET]
+            __attribute__((aligned(16)));
 #endif
     };
 };
risu_reginfo_aarch64.c +70 -65

194 lines not on this page · raw message

Signature · 1 line
2.20.1
#15 lore raw

PATCH 9/9 Add --dump option to inspect trace files

In reply to Richard Henderson

Adjust some of the aarch64 code to look at the reginfo struct instead of looking at test_sve, so that we do not need to pass the --test-sve option in order to dump sve trace files.

---
 risu.h                 |   1 +
 risu.c                 | 111 ++++++++++++++++++++++++++++++++++++++++-
 risu_reginfo_aarch64.c |  55 ++++++++++++--------
 risu_reginfo_arm.c     |   4 ++
 risu_reginfo_i386.c    |   4 ++
 risu_reginfo_m68k.c    |   4 ++
 risu_reginfo_ppc64.c   |   4 ++
 7 files changed, 161 insertions(+), 22 deletions(-)
risu.h +1 -0
index 0ae7fa9..515e5c2 100644
@@ -23,6 +23,7 @@
 extern const struct option * const arch_long_opts;
 extern const char * const arch_extra_help;
 void process_arch_opt(int opt, const char *arg);
+void arch_init(void);
 #define FIRST_ARCH_OPT   0x100
 
 /* GCC computed include to pull in the correct risu_reginfo_*.h for
risu.c +109 -2

163 lines not on this page · raw message

risu_reginfo_aarch64.c +35 -20

98 lines not on this page · raw message

risu_reginfo_arm.c +4 -0
index 3832e27..2982435 100644
@@ -36,6 +36,10 @@ void process_arch_opt(int opt, const char *arg)
     abort();
 }
 
+void arch_init(void)
+{
+}
+
 int reginfo_size(struct reginfo *ri)
 {
     return sizeof(struct reginfo);
risu_reginfo_i386.c +4 -0
index 902d33e..68f2323 100644
@@ -74,6 +74,10 @@ void process_arch_opt(int opt, const char *arg)
     }
 }
 
+void arch_init(void)
+{
+}
+
 int reginfo_size(struct reginfo *ri)
 {
     return sizeof(struct reginfo);
risu_reginfo_m68k.c +4 -0
index 361f172..499fdc4 100644
@@ -23,6 +23,10 @@ void process_arch_opt(int opt, const char *arg)
     abort();
 }
 
+void arch_init(void)
+{
+}
+
 int reginfo_size(struct reginfo *ri)
 {
     return sizeof(struct reginfo);
risu_reginfo_ppc64.c +4 -0
index c86313c..3b04747 100644
@@ -32,6 +32,10 @@ void process_arch_opt(int opt, const char *arg)
     abort();
 }
 
+void arch_init(void)
+{
+}
+
 int reginfo_size(struct reginfo *ri)
 {
     return sizeof(struct reginfo);
Signature · 1 line
2.20.1
#16 lore raw
In reply to Richard Henderson
Quoted 7 lines · Richard Henderson

This patch set does alter the format of the trace files, and thus means we'll have to re-generate these. However, the space saved for sve trace files is significant, so I consider it worthwhile.

In addition, the new --dump option allows one to inspect the contents of the trace file.

Alex, would you mind reviewing these risu patches, given that they're mostly trace related? (Also you're the one who'll have to regenerate a lot of trace files :-))

Richard: if you feed an old trace file to the new risu, what error message does it give?

thanks
-- PMM

#17 lore raw
Quoted 7 lines · Peter Maydell
Quoted 5 lines · Richard Henderson

This patch set does alter the format of the trace files, and thus means we'll have to re-generate these. However, the space saved for sve trace files is significant, so I consider it worthwhile.

Quoted 6 lines
Quoted 2 lines

In addition, the new --dump option allows one to inspect the contents of the trace file.

Alex, would you mind reviewing these risu patches, given that they're mostly trace related? (Also you're the one who'll have to regenerate a lot of trace files :-))

Sure. I'll have a look in the morning.

Quoted 6 lines

Richard: if you feed an old trace file to the new risu, what error message does it give?

thanks
-- PMM

Signature · 1 line
Alex Bennée
#18 lore raw
In reply to Peter Maydell
Quoted 10 lines · Peter Maydell
Quoted 7 lines · Richard Henderson

This patch set does alter the format of the trace files, and thus means we'll have to re-generate these. However, the space saved for sve trace files is significant, so I consider it worthwhile.

In addition, the new --dump option allows one to inspect the contents of the trace file.

Quoted 6 lines

Alex, would you mind reviewing these risu patches, given that they're mostly trace related? (Also you're the one who'll have to regenerate a lot of trace files :-))

Richard: if you feed an old trace file to the new risu, what error message does it give?

Bah, it should have generated an error vs the magic number, but doesn't -- it silently exits with success. Alex, expect a v2.

r~

#19 lore raw
Quoted 6 lines · Richard Henderson
Quoted 2 lines · Peter Maydell

Richard: if you feed an old trace file to the new risu, what error message does it give?

Bah, it should have generated an error vs the magic number, but doesn't -- it silently exits with success. Alex, expect a v2.

Double bah. Typo in git checkout, so I didn't actually switch branches for the test. It does print an error, but not a useful one:

match status...
mismatch on regs!

I'll improve this.

r~