Skip to contentSkip to conversation

RISU record/replay patches

PATCH Applied Alex Bennée 2 participants 33 messages Jun 19, 2017 – Jun 29, 2017 Kbuild

v5 of 6 Applied Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v5 cover RISU record/replay patches

Hi,

Here is v5 of the RISU record/replay patches. The big changes are:

- new patch to sync coding standards
- handle stdin/out as a trace input/destination
- remove fprintf's from signal handlers
- swapped the static build flag with docker

I've left the "build with docker" patches in but they can be easily dropped if you want as the --static build patch goes in first. I still think it is a handy solution if the users host cross-arch setup is broken.

The alternative is to use the stdin/out pipeline and pass trace data through a (potentially native) compression binary.

Details in the commits.

Alex Bennée (13):
.gitignore: ignore build directories
README: document the coding style used for risu
all: fix up code consitency
build-all-archs: support --static flag
build-all-archs: support cross building via docker
risu: a bit more verbosity when starting
risu: paramterise send/receive functions
risu: add header to trace stream
risu: add simple trace and replay support
risu: handle trace through stdin/stdout
risu: add support compressed tracefiles
new: record_traces.sh helper script
new: run_risu.sh script

 .dir-locals.el         |   2 +
 .gitignore             |   1 +
 Makefile               |   4 +-
 README                 |   9 +
 build-all-archs        |  76 +++++++-
 comms.c                | 325 ++++++++++++++++------------------
 configure              |  55 +++++-
 record_traces.sh       |  32 ++++
 reginfo.c              | 189 +++++++++++---------
 risu.c                 | 465 ++++++++++++++++++++++++++++++++-----------------
 risu.h                 |  27 ++-
 risu_aarch64.c         |   5 +
 risu_arm.c             |  63 +++----
 risu_i386.c            | 150 ++++++++--------
 risu_m68k.c            |   7 +-
 risu_ppc64.c           |   7 +-
 risu_reginfo_aarch64.c |  60 ++++---
 risu_reginfo_aarch64.h |   3 +-
 risu_reginfo_arm.c     | 290 +++++++++++++++---------------
 risu_reginfo_arm.h     |   3 +-
 risu_reginfo_m68k.c    |  20 +--
 risu_reginfo_m68k.h    |   3 +-
 risu_reginfo_ppc64.c   |  29 ++-
 risu_reginfo_ppc64.h   |   3 +-
 run_risu.sh            |  66 +++++++
 25 files changed, 1150 insertions(+), 744 deletions(-)
 create mode 100644 .dir-locals.el
 create mode 100755 record_traces.sh
 create mode 100755 run_risu.sh
Signature · 1 line
2.13.0
#2 lore raw

PATCH v5 2/13 README: document the coding style used for risu

In reply to Alex Bennée

We also include the an Emacs .dir-locals (as per QEMU) that enforces this layout.

---
 .dir-locals.el | 2 ++
 README         | 9 +++++++++
 2 files changed, 11 insertions(+)
 create mode 100644 .dir-locals.el
.dir-locals.el new file +2 -0
new file mode 100644
index 0000000..3ac0cfc
@@ -0,0 +1,2 @@
+((c-mode . ((c-file-style . "stroustrup")
+	    (indent-tabs-mode . nil))))
README +9 -0
index 4b37b4e..858a349 100644
@@ -42,6 +42,15 @@ architecture that we support and that you have a cross compiler
 installed for. This is useful for confirming that your changes
 to risu haven't broken anything.
 
+Coding Style
+------------
+
+risu follows the same coding style as the QEMU project, namely 4
+spaces (no tabs) for indentation and the One True Brace Style variant
+of K&R. The source tree includes a .dir-locals.el for Emacs users that
+will set this automatically. Other editors are available.
+
+
 Usage
 -----
 
Signature · 1 line
2.13.0
#3 lore raw

Re: [Qemu-devel] [RISU PATCH v5 02/13] README: document the coding style used for risu

Quoted 16 lines · Alex Bennée

We also include the an Emacs .dir-locals (as per QEMU) that enforces this layout.

---
 .dir-locals.el | 2 ++
 README         | 9 +++++++++
 2 files changed, 11 insertions(+)
 create mode 100644 .dir-locals.el
.dir-locals.el new file +0 -0
new file mode 100644
index 0000000..3ac0cfc

.dir-locals.el line 2

Quoted 2 lines
.dir-locals.el new file +2 -0
@@ -0,0 +1,2 @@
+((c-mode . ((c-file-style . "stroustrup")
+           (indent-tabs-mode . nil))))

This prompted me to look at this, and this is wrong: it overrides my local emacs config with something that gets some bits of style wrong :-( Indeed there's one in QEMU now I see, and that is why my emacs behaviour has regressed. For instance given

static const VMStateDescription cmsdk_apb_uart_vmstate = {
    .name = "cmsdk-apb-uart",
    .version_id = 1,
    .minimum_version_id = 1,
    .fields = (VMStateField[]) {
        VMSTATE_END_OF_LIST()

with cursor on the blank line at the end, if I type '}' then I get

     }\n

(ie the cursor moves to a new line) but the cursor should stay after the '}' so I can type the ','.

thanks
-- PMM

#4 lore raw

PATCH v5 3/13 all: fix up code consitency

In reply to Alex Bennée

This is pretty much a mechanical change where I ran:

indent -kr

Across all the files and then fixed up all but a few violations of:

../../qemu.git/scripts/checkpatch.pl -f *.c *.h > checkpatch.out

Along with heavy use of M-x untabify to make everything consistent.

---
 comms.c                | 325 +++++++++++++++++++++++--------------------------
 reginfo.c              | 114 ++++++++---------
 risu.c                 | 310 +++++++++++++++++++++++-----------------------
 risu.h                 |   4 +-
 risu_arm.c             |  58 +++++----
 risu_i386.c            | 150 +++++++++++------------
 risu_m68k.c            |   2 +-
 risu_ppc64.c           |   2 +-
 risu_reginfo_aarch64.c |  60 +++++----
 risu_reginfo_aarch64.h |   3 +-
 risu_reginfo_arm.c     | 290 +++++++++++++++++++++----------------------
 risu_reginfo_arm.h     |   3 +-
 risu_reginfo_m68k.c    |  20 +--
 risu_reginfo_m68k.h    |   3 +-
 risu_reginfo_ppc64.c   |  29 ++---
 risu_reginfo_ppc64.h   |   3 +-
 16 files changed, 672 insertions(+), 704 deletions(-)
comms.c +153 -172
index 31be846..2900c33 100644
@@ -7,7 +7,7 @@
  *
  * Contributors:
  *     Peter Maydell (Linaro) - initial implementation
- *******************************************************************************/
+ ******************************************************************************/
 
 /* Routines for the socket communication between master and apprentice. */
 
@@ -24,76 +24,70 @@
 
 int apprentice_connect(const char *hostname, int port)
 {
-   /* We are the client end of the TCP connection */
-   int sock;
-   struct sockaddr_in sa;
-   sock = socket(PF_INET, SOCK_STREAM, 0);
-   if (sock < 0)
-   {
-      perror("socket");
-      exit(1);
-   }
-   struct hostent *hostinfo;
-   sa.sin_family = AF_INET;
-   sa.sin_port = htons(port);
-   hostinfo = gethostbyname(hostname);
-   if (!hostinfo)
-   {
-      fprintf(stderr, "Unknown host %s\n", hostname);
-      exit(1);
-   }
-   sa.sin_addr = *(struct in_addr*)hostinfo->h_addr;
-   if (connect(sock, (struct sockaddr*)&sa, sizeof(sa)) < 0)
-   {
-      perror("connect");
-      exit(1);
-   }
-   return sock;
+    /* We are the client end of the TCP connection */
+    int sock;
+    struct sockaddr_in sa;
+    sock = socket(PF_INET, SOCK_STREAM, 0);
+    if (sock < 0) {
+        perror("socket");
+        exit(1);
+    }
+    struct hostent *hostinfo;
+    sa.sin_family = AF_INET;
+    sa.sin_port = htons(port);
+    hostinfo = gethostbyname(hostname);
+    if (!hostinfo) {
+        fprintf(stderr, "Unknown host %s\n", hostname);
+        exit(1);
+    }
+    sa.sin_addr = *(struct in_addr *) hostinfo->h_addr;
+    if (connect(sock, (struct sockaddr *) &sa, sizeof(sa)) < 0) {
+        perror("connect");
+        exit(1);
+    }
+    return sock;
 }
 
 int master_connect(int port)
 {
-   int sock;
-   struct sockaddr_in sa;
-   sock = socket(PF_INET, SOCK_STREAM, 0);
-   if (sock < 0)
-   {
-      perror("socket");
-      exit(1);
-   }
-   int sora = 1;
-   if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &sora, sizeof(sora)) != 0)
-   {
-      perror("setsockopt(SO_REUSEADDR)");
-      exit(1);
-   }
+    int sock;
+    struct sockaddr_in sa;
+    sock = socket(PF_INET, SOCK_STREAM, 0);
+    if (sock < 0) {
+        perror("socket");
+        exit(1);
+    }
+    int sora = 1;
+    if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &sora, sizeof(sora)) !=
+        0) {
+        perror("setsockopt(SO_REUSEADDR)");
+        exit(1);
+    }
 
-   sa.sin_family = AF_INET;
-   sa.sin_port = htons(port);
-   sa.sin_addr.s_addr = htonl(INADDR_ANY);
-   if (bind(sock, (struct sockaddr*)&sa, sizeof(sa)) < 0)
-   {
-      perror("bind");
-      exit(1);
-   }
-   if (listen(sock, 1) < 0)
-   {
-      perror("listen");
-      exit(1);
-   }
-   /* Just block until we get a connection */
-   fprintf(stderr, "master: waiting for connection on port %d...\n", port);
-   struct sockaddr_in csa;
-   socklen_t csasz = sizeof(csa);
-   int nsock = accept(sock, (struct sockaddr*)&csa, &csasz);
-   if (nsock < 0)
-   {
-      perror("accept");
-      exit(1);
-   }
-   /* We're done with the server socket now */
-   close(sock);
-   return nsock;
+    sa.sin_family = AF_INET;
+    sa.sin_port = htons(port);
+    sa.sin_addr.s_addr = htonl(INADDR_ANY);
+    if (bind(sock, (struct sockaddr *) &sa, sizeof(sa)) < 0) {
+        perror("bind");
+        exit(1);
+    }
+    if (listen(sock, 1) < 0) {
+        perror("listen");
+        exit(1);
+    }
+    /* Just block until we get a connection */
+    fprintf(stderr, "master: waiting for connection on port %d...\n",
+            port);
+    struct sockaddr_in csa;
+    socklen_t csasz = sizeof(csa);
+    int nsock = accept(sock, (struct sockaddr *) &csa, &csasz);
+    if (nsock < 0) {
+        perror("accept");
+        exit(1);
+    }
+    /* We're done with the server socket now */
+    close(sock);
+    return nsock;
 }
 
 /* Utility functions which are just wrappers around read and writev
@@ -101,77 +95,68 @@ int master_connect(int port)
  */
 static void recv_bytes(int sock, void *pkt, int pktlen)
 {
-   char *p = pkt;
-   while (pktlen)
-   {
-      int i = read(sock, p, pktlen);
-      if (i <= 0)
-      {
-         if (errno == EINTR)
-         {
-            continue;
-         }
-         perror("read failed");
-         exit(1);
-      }
-      pktlen -= i;
-      p += i;
-   }
+    char *p = pkt;
+    while (pktlen) {
+        int i = read(sock, p, pktlen);
+        if (i <= 0) {
+            if (errno == EINTR) {
+                continue;
+            }
+            perror("read failed");
+            exit(1);
+        }
+        pktlen -= i;
+        p += i;
+    }
 }
 
 static void recv_and_discard_bytes(int sock, int pktlen)
 {
-   /* Read and discard bytes */
-   char dumpbuf[64];
-   while (pktlen)
-   {
-      int i;
-      int len = sizeof(dumpbuf);
-      if (len > pktlen)
-      {
-         len = pktlen;
-      }
-      i = read(sock, dumpbuf, len);
-      if (i <= 0)
-      {
-         if (errno == EINTR)
-         {
-            continue;
-         }
-         perror("read failed");
-         exit(1);
-      }
-      pktlen -= i;
-   }
+    /* Read and discard bytes */
+    char dumpbuf[64];
+    while (pktlen) {
+        int i;
+        int len = sizeof(dumpbuf);
+        if (len > pktlen) {
+            len = pktlen;
+        }
+        i = read(sock, dumpbuf, len);
+        if (i <= 0) {
+            if (errno == EINTR) {
+                continue;
+            }
+            perror("read failed");
+            exit(1);
+        }
+        pktlen -= i;
+    }
 }
 
 ssize_t safe_writev(int fd, struct iovec *iov_in, int iovcnt)
 {
-   /* writev, retrying for EINTR and short writes */
-   int r = 0;
-   struct iovec *iov = iov_in;
-   for (;;)
-   {
-      ssize_t i = writev(fd, iov, iovcnt);
-      if (i == -1)
-      {
-         if (errno == EINTR)
-            continue;
-         return -1;
-      }
-      r += i;
-      /* Move forward through iov to account for data transferred */
-      while (i >= iov->iov_len)
-      {
-         i -= iov->iov_len;
-         iov++;
-         iovcnt--;
-         if (iovcnt == 0) {
-            return r;
-         }
-      }
-      iov->iov_len -= i;
-   }
+    /* writev, retrying for EINTR and short writes */
+    int r = 0;
+    struct iovec *iov = iov_in;
+    for (;;) {
+        ssize_t i = writev(fd, iov, iovcnt);
+        if (i == -1) {
+            if (errno == EINTR) {
+                continue;
+            }
+            return -1;
+        }
+        r += i;
+        /* Move forward through iov to account for data transferred */
+        while (i >= iov->iov_len) {
+            i -= iov->iov_len;
+            iov++;
+            iovcnt--;
+            if (iovcnt == 0) {
+                return r;
+            }
+        }
+        iov->iov_len -= i;
+    }
 }
 
 /* Low level comms routines:
@@ -184,57 +169,53 @@ ssize_t safe_writev(int fd, struct iovec *iov_in, int iovcnt)
  */
 int send_data_pkt(int sock, void *pkt, int pktlen)
 {
-   unsigned char resp;
-   /* First we send the packet length as a network-order 32 bit value.
-    * This avoids silent deadlocks if the two sides disagree over
-    * what size data packet they are transferring. We use writev()
-    * so that both length and packet are sent in one packet; otherwise
-    * we get 300x slowdown because we hit Nagle's algorithm.
-    */
-   uint32_t net_pktlen = htonl(pktlen);
-   struct iovec iov[2];
-   iov[0].iov_base = &net_pktlen;
-   iov[0].iov_len = sizeof(net_pktlen);
-   iov[1].iov_base = pkt;
-   iov[1].iov_len = pktlen;
+    unsigned char resp;
+    /* First we send the packet length as a network-order 32 bit value.
+     * This avoids silent deadlocks if the two sides disagree over
+     * what size data packet they are transferring. We use writev()
+     * so that both length and packet are sent in one packet; otherwise
+     * we get 300x slowdown because we hit Nagle's algorithm.
+     */
+    uint32_t net_pktlen = htonl(pktlen);
+    struct iovec iov[2];
+    iov[0].iov_base = &net_pktlen;
+    iov[0].iov_len = sizeof(net_pktlen);
+    iov[1].iov_base = pkt;
+    iov[1].iov_len = pktlen;
 
-   if (safe_writev(sock, iov, 2) == -1)
-   {
-      perror("writev failed");
-      exit(1);
-   }
+    if (safe_writev(sock, iov, 2) == -1) {
+        perror("writev failed");
+        exit(1);
+    }
 
-   if (read(sock, &resp, 1) != 1)
-   {
-      perror("read failed");
-      exit(1);
-   }
-   return resp;
+    if (read(sock, &resp, 1) != 1) {
+        perror("read failed");
+        exit(1);
+    }
+    return resp;
 }
 
 int recv_data_pkt(int sock, void *pkt, int pktlen)
 {
-   uint32_t net_pktlen;
-   recv_bytes(sock, &net_pktlen, sizeof(net_pktlen));
-   net_pktlen = ntohl(net_pktlen);
-   if (pktlen != net_pktlen)
-   {
-      /* Mismatch. Read the data anyway so we can send
-       * a response back.
-       */
-      recv_and_discard_bytes(sock, net_pktlen);
-      return 1;
-   }
-   recv_bytes(sock, pkt, pktlen);
-   return 0;
+    uint32_t net_pktlen;
+    recv_bytes(sock, &net_pktlen, sizeof(net_pktlen));
+    net_pktlen = ntohl(net_pktlen);
+    if (pktlen != net_pktlen) {
+        /* Mismatch. Read the data anyway so we can send
+         * a response back.
+         */
+        recv_and_discard_bytes(sock, net_pktlen);
+        return 1;
+    }
+    recv_bytes(sock, pkt, pktlen);
+    return 0;
 }
 
 void send_response_byte(int sock, int resp)
 {
-   unsigned char r = resp;
-   if (write(sock, &r, 1) != 1)
-   {
-      perror("write failed");
-      exit(1);
-   }
+    unsigned char r = resp;
+    if (write(sock, &r, 1) != 1) {
+        perror("write failed");
+        exit(1);
+    }
 }
reginfo.c +58 -56

138 lines not on this page · raw message

risu.c +151 -159

362 lines not on this page · raw message

risu.h +2 -2
index 883bcf7..3fbeda8 100644
@@ -7,7 +7,7 @@
  *
  * Contributors:
  *     Peter Maydell (Linaro) - initial implementation
- *******************************************************************************/
+ ******************************************************************************/
 
 #ifndef RISU_H
 #define RISU_H
@@ -99,7 +99,7 @@ void reginfo_init(struct reginfo *ri, ucontext_t *uc);
 int reginfo_is_eq(struct reginfo *r1, struct reginfo *r2);
 
 /* print reginfo state to a stream, returns 1 on success, 0 on failure */
-int reginfo_dump(struct reginfo *ri, FILE *f);
+int reginfo_dump(struct reginfo *ri, FILE * f);
 
 /* reginfo_dump_mismatch: print mismatch details to a stream, ret nonzero=ok */
 int reginfo_dump_mismatch(struct reginfo *m, struct reginfo *a, FILE *f);
risu_arm.c +28 -30

87 lines not on this page · raw message

risu_i386.c +70 -80

207 lines not on this page · raw message

risu_m68k.c +1 -1
index f84ac7a..0bf5c14 100644
@@ -10,7 +10,7 @@
 
 void advance_pc(void *vuc)
 {
-    ucontext_t *uc = (ucontext_t*)vuc;
+    ucontext_t *uc = (ucontext_t *) vuc;
     uc->uc_mcontext.gregs[R_PC] += 4;
 }
 
risu_ppc64.c +1 -1
index b575078..eb60573 100644
@@ -15,7 +15,7 @@
 
 void advance_pc(void *vuc)
 {
-    ucontext_t *uc = (ucontext_t*)vuc;
+    ucontext_t *uc = (ucontext_t *) vuc;
     uc->uc_mcontext.regs->nip += 4;
 }
 
risu_reginfo_aarch64.c +36 -24

135 lines not on this page · raw message

risu_reginfo_aarch64.h +1 -2
index 3d1b2fd..a05fb4e 100644
@@ -13,8 +13,7 @@
 #ifndef RISU_REGINFO_AARCH64_H
 #define RISU_REGINFO_AARCH64_H
 
-struct reginfo
-{
+struct reginfo {
     uint64_t fault_address;
     uint64_t regs[31];
     uint64_t sp;
risu_reginfo_arm.c +145 -145

318 lines not on this page · raw message

risu_reginfo_arm.h +1 -2
index 96e5791..60754a9 100644
@@ -13,8 +13,7 @@
 #ifndef RISU_REGINFO_ARM_H
 #define RISU_REGINFO_ARM_H
 
-struct reginfo
-{
+struct reginfo {
     uint64_t fpregs[32];
     uint32_t faulting_insn;
     uint32_t faulting_insn_size;
risu_reginfo_m68k.c +10 -10
index 45950b1..4ff0aa8 100644
@@ -20,7 +20,7 @@ void reginfo_init(struct reginfo *ri, ucontext_t *uc)
     int i;
     memset(ri, 0, sizeof(*ri));
 
-    ri->faulting_insn = *((uint32_t *)uc->uc_mcontext.gregs[R_PC]);
+    ri->faulting_insn = *((uint32_t *) uc->uc_mcontext.gregs[R_PC]);
     ri->pc = uc->uc_mcontext.gregs[R_PC] - image_start_address;
 
     for (i = 0; i < NGREG; i++) {
@@ -78,8 +78,7 @@ int reginfo_is_eq(struct reginfo *m, struct reginfo *a)
 int reginfo_dump(struct reginfo *ri, FILE *f)
 {
     int i;
-    fprintf(f, "  pc            \e[1;101;37m0x%08x\e[0m\n",
-            ri->pc);
+    fprintf(f, "  pc            \e[1;101;37m0x%08x\e[0m\n", ri->pc);
 
     fprintf(f, "\tPC: %08x\n", ri->gregs[R_PC]);
     fprintf(f, "\tPS: %04x\n", ri->gregs[R_PS]);
@@ -101,14 +100,14 @@ int reginfo_dump(struct reginfo *ri, FILE *f)
     return !ferror(f);
 }
 
-int reginfo_dump_mismatch(struct reginfo *m, struct reginfo *a, FILE *f)
+int reginfo_dump_mismatch(struct reginfo *m, struct reginfo *a, FILE * f)
 {
     int i;
 
     if (m->gregs[R_PS] != a->gregs[R_PS]) {
-            fprintf(f, "Mismatch: Register PS\n");
-            fprintf(f, "master: [%x] - apprentice: [%x]\n",
-                    m->gregs[R_PS], a->gregs[R_PS]);
+        fprintf(f, "Mismatch: Register PS\n");
+        fprintf(f, "master: [%x] - apprentice: [%x]\n",
+                m->gregs[R_PS], a->gregs[R_PS]);
     }
 
     for (i = 0; i < 16; i++) {
@@ -116,9 +115,10 @@ int reginfo_dump_mismatch(struct reginfo *m, struct reginfo *a, FILE *f)
             continue;
         }
         if (m->gregs[i] != a->gregs[i]) {
-            fprintf(f, "Mismatch: Register %c%d\n", i < 8 ? 'D' : 'A', i % 8);
-            fprintf(f, "master: [%x] - apprentice: [%x]\n",
-                    m->gregs[i], a->gregs[i]);
+            fprintf(f, "Mismatch: Register %c%d\n", i < 8 ? 'D' : 'A',
+                    i % 8);
+            fprintf(f, "master: [%x] - apprentice: [%x]\n", m->gregs[i],
+                    a->gregs[i]);
         }
     }
 
risu_reginfo_m68k.h +1 -2
index 06ea61d..c1c9fe6 100644
@@ -9,8 +9,7 @@
 #ifndef RISU_REGINFO_M68K_H
 #define RISU_REGINFO_M68K_H
 
-struct reginfo
-{
+struct reginfo {
     uint32_t faulting_insn;
     uint32_t pc;
     gregset_t gregs;
risu_reginfo_ppc64.c +13 -16
index ae86263..eb9c12b 100644
@@ -28,7 +28,7 @@ void reginfo_init(struct reginfo *ri, ucontext_t *uc)
     int i;
     memset(ri, 0, sizeof(*ri));
 
-    ri->faulting_insn = *((uint32_t *)uc->uc_mcontext.regs->nip);
+    ri->faulting_insn = *((uint32_t *) uc->uc_mcontext.regs->nip);
     ri->nip = uc->uc_mcontext.regs->nip - image_start_address;
 
     for (i = 0; i < NGREG; i++) {
@@ -76,16 +76,16 @@ int reginfo_is_eq(struct reginfo *m, struct reginfo *a)
             continue;
         }
 
-        if  (m->fpregs[i] != a->fpregs[i]) {
+        if (m->fpregs[i] != a->fpregs[i]) {
             return 0;
         }
     }
 
     for (i = 0; i < 32; i++) {
         if (m->vrregs.vrregs[i][0] != a->vrregs.vrregs[i][0] ||
-                m->vrregs.vrregs[i][1] != a->vrregs.vrregs[i][1] ||
-                m->vrregs.vrregs[i][2] != a->vrregs.vrregs[i][2] ||
-                m->vrregs.vrregs[i][3] != a->vrregs.vrregs[i][3]) {
+            m->vrregs.vrregs[i][1] != a->vrregs.vrregs[i][1] ||
+            m->vrregs.vrregs[i][2] != a->vrregs.vrregs[i][2] ||
+            m->vrregs.vrregs[i][3] != a->vrregs.vrregs[i][3]) {
             return 0;
         }
     }
@@ -93,7 +93,7 @@ int reginfo_is_eq(struct reginfo *m, struct reginfo *a)
 }
 
 /* reginfo_dump: print state to a stream, returns nonzero on success */
-int reginfo_dump(struct reginfo *ri, FILE *f)
+int reginfo_dump(struct reginfo *ri, FILE * f)
 {
     int i;
 
@@ -153,14 +153,12 @@ int reginfo_dump_mismatch(struct reginfo *m, struct reginfo *a, FILE *f)
 
     if (m->gregs[XER] != a->gregs[XER]) {
         fprintf(f, "Mismatch: XER\n");
-        fprintf(f, "m: [%lx] != a: [%lx]\n",
-                m->gregs[XER], a->gregs[XER]);
+        fprintf(f, "m: [%lx] != a: [%lx]\n", m->gregs[XER], a->gregs[XER]);
     }
 
     if (m->gregs[CCR] != a->gregs[CCR]) {
         fprintf(f, "Mismatch: Cond. Register\n");
-        fprintf(f, "m: [%lx] != a: [%lx]\n",
-                m->gregs[CCR], a->gregs[CCR]);
+        fprintf(f, "m: [%lx] != a: [%lx]\n", m->gregs[CCR], a->gregs[CCR]);
     }
 
     for (i = 0; i < 32; i++) {
@@ -168,18 +166,17 @@ int reginfo_dump_mismatch(struct reginfo *m, struct reginfo *a, FILE *f)
             continue;
         }
 
-        if  (m->fpregs[i] != a->fpregs[i]) {
+        if (m->fpregs[i] != a->fpregs[i]) {
             fprintf(f, "Mismatch: Register r%d\n", i);
-            fprintf(f, "m: [%f] != a: [%f]\n",
-                    m->fpregs[i], a->fpregs[i]);
+            fprintf(f, "m: [%f] != a: [%f]\n", m->fpregs[i], a->fpregs[i]);
         }
     }
 
     for (i = 0; i < 32; i++) {
         if (m->vrregs.vrregs[i][0] != a->vrregs.vrregs[i][0] ||
-                m->vrregs.vrregs[i][1] != a->vrregs.vrregs[i][1] ||
-                m->vrregs.vrregs[i][2] != a->vrregs.vrregs[i][2] ||
-                m->vrregs.vrregs[i][3] != a->vrregs.vrregs[i][3]) {
+            m->vrregs.vrregs[i][1] != a->vrregs.vrregs[i][1] ||
+            m->vrregs.vrregs[i][2] != a->vrregs.vrregs[i][2] ||
+            m->vrregs.vrregs[i][3] != a->vrregs.vrregs[i][3]) {
 
             fprintf(f, "Mismatch: Register vr%d\n", i);
             fprintf(f, "m: [%x, %x, %x, %x] != a: [%x, %x, %x, %x]\n",
risu_reginfo_ppc64.h +1 -2
index 826143e..7f2c962 100644
@@ -14,8 +14,7 @@
 #ifndef RISU_REGINFO_PPC64LE_H
 #define RISU_REGINFO_PPC64LE_H
 
-struct reginfo
-{
+struct reginfo {
     uint32_t faulting_insn;
     uint32_t prev_insn;
     uint64_t nip;
Signature · 1 line
2.13.0
#5 lore raw

Re: [Qemu-devel] [RISU PATCH v5 03/13] all: fix up code consitency

Quoted 75 lines · Alex Bennée

This is pretty much a mechanical change where I ran:

indent -kr

Across all the files and then fixed up all but a few violations of:

../../qemu.git/scripts/checkpatch.pl -f *.c *.h > checkpatch.out

Along with heavy use of M-x untabify to make everything consistent.

risu_reginfo_arm.c +19 -34
index 5309f3a..8e6736b 100644
@@ -26,173 +26,173 @@ extern int insnsize(ucontext_t *uc);
 
 static void reginfo_init_vfp(struct reginfo *ri, ucontext_t *uc)
 {
-   // Read VFP registers. These live in uc->uc_regspace, which is
-   // a sequence of
-   //   u32 magic
-   //   u32 size
-   //   data....
-   // blocks. We have to skip through to find the one for VFP.
-   unsigned long *rs = uc->uc_regspace;
-
-   for (;;)
-   {
-      switch (*rs++)
-      {
-         case 0:
-         {
-            /* We didn't find any VFP at all (probably a no-VFP
-             * kernel). Zero out all the state to avoid mismatches.
-             */
-            int j;
-            for (j = 0; j < 32; j++)
-               ri->fpregs[j] = 0;
-            ri->fpscr = 0;
-            return;
-         }
-         case 0x56465001: /* VFP_MAGIC */
-         {
-            /* This is the one we care about. The format (after the size word)
-             * is 32 * 64 bit registers, then the 32 bit fpscr, then some stuff
-             * we don't care about.
-             */
-            int i;
-            /* Skip if it's smaller than we expected (should never happen!) */
-            if (*rs < ((32*2)+1))
+    /* Read VFP registers. These live in uc->uc_regspace, which is
+     * a sequence of
+     *   u32 magic
+     *   u32 size
+     *   data....
+     * blocks. We have to skip through to find the one for VFP.
+     */
+    unsigned long *rs = uc->uc_regspace;
+
+    for (;;) {
+        switch (*rs++) {
+        case 0:
             {
-               rs += (*rs / 4);
-               break;
+                /* We didn't find any VFP at all (probably a no-VFP
+                 * kernel). Zero out all the state to avoid mismatches.
+                 */
+                int j;
+                for (j = 0; j < 32; j++) {
+                    ri->fpregs[j] = 0;
+                }

risu_reginfo_arm.c extern int insnsize(ucontext_t *uc); · line 54

Quoted 10 lines
risu_reginfo_arm.c +4 -4
+                ri->fpscr = 0;
+                return;
             }
-            rs++;
-            for (i = 0; i < 32; i++)
+        case 0x56465001:        /* VFP_MAGIC */
             {
-               ri->fpregs[i] = *rs++;
-               ri->fpregs[i] |= (uint64_t)(*rs++) << 32;
+                /* This is the one we care about. The format (after

Something seems to have gone wrong in this file -- note the extra indent of {} blocks after "case 0:". The others are all fine though so I'll just fix this locally.

thanks
-- PMM

#6 lore raw

Re: [Qemu-devel] [RISU PATCH v5 03/13] all: fix up code consitency

Quoted 3 lines · Peter Maydell

Something seems to have gone wrong in this file -- note the extra indent of {} blocks after "case 0:". The others are all fine though so I'll just fix this locally.

...fixed up version applied to risu master.

thanks
-- PMM

#7 lore raw

PATCH v5 4/13 build-all-archs: support --static flag

In reply to Alex Bennée

---
v5
- swap with docker patch so later can be dropped if not wanted

---
 build-all-archs | 34 +++++++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)
build-all-archs +33 -1
index 2768727..581a1b4 100755
@@ -14,6 +14,38 @@
 # So we notice risugen failing even though it's in a pipeline
 set -o pipefail
 
+# Simple usage
+usage() {
+    cat <<-EOF
+        Usage: $0 [options]
+
+        Options include:
+            --static               build a static binary
+
+EOF
+    exit 1
+}
+
+while [[ "$1" = -* ]]; do
+    opt="$1"; shift
+    arg=
+    if [[ "$opt" = *=* ]]; then
+        arg="${opt#*=}"
+        opt="${opt%%=*}"
+    fi
+    case "$opt" in
+        --static)
+            CONF="--static"
+            ;;
+        --help)
+            usage
+            ;;
+        *)
+            usage
+            ;;
+    esac
+done
+
 # Debian stretch and Ubuntu Xenial have cross compiler packages for
 # all of these:
 # gcc-arm-linux-gnueabihf gcc-aarch64-linux-gnu gcc-m68k-linux-gnu
@@ -36,7 +68,7 @@ for triplet in aarch64-linux-gnu arm-linux-gnueabihf m68k-linux-gnu \
     rm -rf build/${triplet}
     mkdir -p build/${triplet}
 
-    (cd build/${triplet} && CROSS_PREFIX="${triplet}-"  ../../configure)
+    (cd build/${triplet} && CROSS_PREFIX="${triplet}-"  ../../configure ${CONF})
     make -C build/${triplet} EXTRA_CFLAGS=-Werror
 
 done
Signature · 1 line
2.13.0
#8 lore raw

Re: [Qemu-devel] [RISU PATCH v5 04/13] build-all-archs: support --static flag

Quoted 6 lines · Alex Bennée

---
v5
- swap with docker patch so later can be dropped if not wanted
---

Applied to master, thanks.

-- PMM

#9 lore raw

PATCH v5 5/13 build-all-archs: support cross building via docker

In reply to Alex Bennée

If we want to link to any other libraries we might find using simple cross toolchains doesn't work so well. One way around this is to use a dockerised cross-toolchain which then won't clash with your host system. If the user specifies --use-docker the obvious will be done.

By default we use the QEMU projects qemu:debian-FOO-cross images as RISU hackers are likely to be QEMU developers too. However any docker tag can be passed on the command line.

If none of the docker images have usable compilers we fall back to checking the host path.

---
v5
- swapped with --static patch so this can be dropped if desired

---
 build-all-archs | 46 +++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 39 insertions(+), 7 deletions(-)
build-all-archs +39 -7
index 581a1b4..63918e5 100755
@@ -11,9 +11,6 @@
 # Contributors:
 #     Peter Maydell (Linaro) - initial implementation
 
-# So we notice risugen failing even though it's in a pipeline
-set -o pipefail
-
 # Simple usage
 usage() {
     cat <<-EOF
@@ -21,7 +18,10 @@ usage() {
 
         Options include:
             --static               build a static binary
+            --use-docker[=tags]    use docker cross compile
 
+        If specifying docker the default will be to use the any
+        qemu:debian-FOO-cross targets available on your system.
 EOF
     exit 1
 }
@@ -37,6 +37,14 @@ while [[ "$1" = -* ]]; do
         --static)
             CONF="--static"
             ;;
+        --use-docker)
+            if [ -z "$arg" ]; then
+                default_tags=$(docker images qemu --format "{{.Repository}}:{{.Tag}}" | grep "\(arm\|power\).*cross$")
+                docker_tags=$(echo $default_tags | sed 's/\n/\s/g' )
+            else
+                docker_tags="$arg"
+            fi
+            ;;
         --help)
             usage
             ;;
@@ -48,10 +56,24 @@ done
 
 # Debian stretch and Ubuntu Xenial have cross compiler packages for
 # all of these:
-# gcc-arm-linux-gnueabihf gcc-aarch64-linux-gnu gcc-m68k-linux-gnu
-# gcc-powerpc64le-linux-gnu gcc-powerpc64-linux-gnu
+#   gcc-arm-linux-gnueabihf gcc-aarch64-linux-gnu gcc-m68k-linux-gnu
+#   gcc-powerpc64le-linux-gnu gcc-powerpc64-linux-gnu
+# If docker is enabled we just brute force the various images until we
+# can set the one that has a workable cross compiler.
+
+DOCKER_RUN="docker run --rm -t -u $(id -u) -v $(pwd):$(pwd) -w $(pwd)"
 
 program_exists() {
+    if [ ! -z "$docker_tags" ]; then
+        use_docker_tag=""
+        for tag in $docker_tags; do
+            if ${DOCKER_RUN} ${tag} /bin/bash -c "command -v $1 >/dev/null"; then
+                use_docker_tag=$tag
+                return
+            fi
+        done
+    fi
+
     command -v "$1" >/dev/null 2>&1
 }
 
@@ -62,19 +84,29 @@ for triplet in aarch64-linux-gnu arm-linux-gnueabihf m68k-linux-gnu \
     if ! program_exists "${triplet}-gcc"; then
         echo "Skipping ${triplet}: no compiler found"
         continue
+    else
+        echo "Building ${triplet} on ${use_docker_tag:-host}..."
     fi
 
     # Do a complete rebuild from scratch, because it's cheap enough.
     rm -rf build/${triplet}
     mkdir -p build/${triplet}
 
-    (cd build/${triplet} && CROSS_PREFIX="${triplet}-"  ../../configure ${CONF})
-    make -C build/${triplet} EXTRA_CFLAGS=-Werror
+    CONFIGURE="cd build/${triplet} && CROSS_PREFIX="${triplet}-"  ../../configure ${CONF}"
+    MAKE="make -C build/${triplet} EXTRA_CFLAGS=-Werror"
 
+    if [ -z "$use_docker_tag" ]; then
+        /bin/bash -c "${CONFIGURE}"
+        ${MAKE}
+    else
+        ${DOCKER_RUN} $use_docker_tag /bin/bash -c "${CONFIGURE}"
+        ${DOCKER_RUN} $use_docker_tag /bin/bash -c "${MAKE}"
+    fi
 done
 
 # Now run risugen for all architectures
 mkdir -p build/risuout
+set -o pipefail # detect failures in pipeline
 
 for f in *.risu; do
     echo "Running risugen on $f..."
Signature · 1 line
2.13.0
#10 lore raw

Re: [Qemu-devel] [RISU PATCH v5 05/13] build-all-archs: support cross building via docker

Quoted 5 lines · Alex Bennée

If we want to link to any other libraries we might find using simple cross toolchains doesn't work so well. One way around this is to use a dockerised cross-toolchain which then won't clash with your host system. If the user specifies --use-docker the obvious will be done.

Quoted 8 lines

By default we use the QEMU projects qemu:debian-FOO-cross images as RISU hackers are likely to be QEMU developers too. However any docker tag can be passed on the command line.

If none of the docker images have usable compilers we fall back to checking the host path.

$ ./build-all-archs --use-docker
Got permission denied while trying to connect to the Docker daemon
socket at unix:///var/run/docker.sock: Get
http://%2Fvar%2Frun%2Fdocker.sock/v1.27/images/json?filters=%7B%22reference%22%3A%7B%22qemu%22%3Atrue%7D%7D:
dial unix /var/run/docker.sock: connect: permission denied

but maybe my local docker setup is just broken?

thanks
-- PMM

#11 lore raw

Re: [Qemu-devel] [RISU PATCH v5 05/13] build-all-archs: support cross building via docker

Quoted 15 lines · Peter Maydell
Quoted 5 lines · Alex Bennée

If we want to link to any other libraries we might find using simple cross toolchains doesn't work so well. One way around this is to use a dockerised cross-toolchain which then won't clash with your host system. If the user specifies --use-docker the obvious will be done.

Quoted 8 lines

By default we use the QEMU projects qemu:debian-FOO-cross images as RISU hackers are likely to be QEMU developers too. However any docker tag can be passed on the command line.

If none of the docker images have usable compilers we fall back to checking the host path.

Quoted 7 lines
$ ./build-all-archs --use-docker
Got permission denied while trying to connect to the Docker daemon
socket at unix:///var/run/docker.sock: Get
http://%2Fvar%2Frun%2Fdocker.sock/v1.27/images/json?filters=%7B%22reference%22%3A%7B%22qemu%22%3Atrue%7D%7D:
dial unix /var/run/docker.sock: connect: permission denied

but maybe my local docker setup is just broken?

Generally you need to add yourself to the "docker" group to have access. This isn't recommended in production but the alternative is to preface all docker calls with sudo and set up permissions that way. The official docs discuss it here:

https://docs.docker.com/engine/installation/linux/linux-postinstall/

The advice that "only trusted users should be allowed to control your Docker daemon." is valid but irrelevant to developers who generally have complete control of their own box.

Quoted 3 lines

thanks
-- PMM

--
Alex Bennée

#12 lore raw

PATCH v5 6/13 risu: a bit more verbosity when starting

In reply to Alex Bennée

When debugging faults it is useful to know where the generated instructions are living.

--
v5
- dropped all the status update due to signal handler contraints
v3
- use portable fmt string for image_start_address
- include arm dumping position

---
 risu.c | 4 ++++
 risu.h | 3 +++
 2 files changed, 7 insertions(+)
risu.c +4 -0
index 2cd6d22..a10422a 100644
@@ -124,6 +124,8 @@ int master(int sock)
     }
     master_socket = sock;
     set_sigill_handler(&master_sigill);
+    fprintf(stderr, "starting master image at 0x%"PRIxPTR"\n",
+            image_start_address);
     fprintf(stderr, "starting image\n");
     image_start();
     fprintf(stderr, "image returned unexpectedly\n");
@@ -134,6 +136,8 @@ int apprentice(int sock)
 {
     apprentice_socket = sock;
     set_sigill_handler(&apprentice_sigill);
+    fprintf(stderr, "starting apprentice image at 0x%"PRIxPTR"\n",
+            image_start_address);
     fprintf(stderr, "starting image\n");
     image_start();
     fprintf(stderr, "image returned unexpectedly\n");
risu.h +3 -0
index 3fbeda8..78a7313 100644
@@ -37,6 +37,7 @@ extern uintptr_t image_start_address;
 extern void *memblock;
 
 extern int test_fp_exc;
+extern int ismaster;
 
 /* Ops code under test can request from risu: */
 #define OP_COMPARE 0
@@ -72,6 +73,8 @@ int recv_and_compare_register_info(int sock, void *uc);
  */
 int report_match_status(void);
 
+void report_test_status(void *pc);
+
 /* Interface provided by CPU-specific code: */
 
 /* Move the PC past this faulting insn by adjusting ucontext
Signature · 1 line
2.13.0
#13 lore raw

Re: [Qemu-devel] [RISU PATCH v5 06/13] risu: a bit more verbosity when starting

Quoted 6 lines · Alex Bennée

When debugging faults it is useful to know where the generated instructions are living.

--

Separator should be '---'.

Quoted 45 lines

v5
- dropped all the status update due to signal handler contraints
v3
- use portable fmt string for image_start_address
- include arm dumping position

---
 risu.c | 4 ++++
 risu.h | 3 +++
 2 files changed, 7 insertions(+)
risu.c +4 -0
index 2cd6d22..a10422a 100644
@@ -124,6 +124,8 @@ int master(int sock)
     }
     master_socket = sock;
     set_sigill_handler(&master_sigill);
+    fprintf(stderr, "starting master image at 0x%"PRIxPTR"\n",
+            image_start_address);
     fprintf(stderr, "starting image\n");
     image_start();
     fprintf(stderr, "image returned unexpectedly\n");
@@ -134,6 +136,8 @@ int apprentice(int sock)
 {
     apprentice_socket = sock;
     set_sigill_handler(&apprentice_sigill);
+    fprintf(stderr, "starting apprentice image at 0x%"PRIxPTR"\n",
+            image_start_address);
     fprintf(stderr, "starting image\n");
     image_start();
     fprintf(stderr, "image returned unexpectedly\n");
risu.h +1 -0
index 3fbeda8..78a7313 100644
@@ -37,6 +37,7 @@ extern uintptr_t image_start_address;
 extern void *memblock;
 
 extern int test_fp_exc;
+extern int ismaster;
 
 /* Ops code under test can request from risu: */
 #define OP_COMPARE 0

risu.h int recv_and_compare_register_info(int sock, void *uc);

Quoted 9 lines
risu.h +2 -1
@@ -72,6 +73,8 @@ int recv_and_compare_register_info(int sock, void *uc);
  */
 int report_match_status(void);
 
+void report_test_status(void *pc);
+
 /* Interface provided by CPU-specific code: */
 
 /* Move the PC past this faulting insn by adjusting ucontext
--

Stray extra changes here ?

thanks
-- PMM

#14 lore raw

PATCH v5 7/13 risu: paramterise send/receive functions

In reply to Alex Bennée

This is a precursor to record/playback support. Instead of passing the socket fd we now pass helper functions for reading/writing and responding. This will allow us to do the rest of the record/playback cleanly outside of the main worker function.

---
v5
- re-base without tab/format cleanps
v4
- split header code
- fix formatting foo-bar's
v3
- new for v3
- arm, aarch64, ppc64

---
 reginfo.c | 39 +++++++++++++++++++--------------------
 risu.c    | 23 +++++++++++++++++++++--
 risu.h    | 11 +++++++++--
 3 files changed, 49 insertions(+), 24 deletions(-)
reginfo.c +19 -20
index 31bb99f..90cea8f 100644
@@ -21,7 +21,7 @@ uint8_t apprentice_memblock[MEMBLOCKLEN];
 static int mem_used;
 static int packet_mismatch;
 
-int send_register_info(int sock, void *uc)
+int send_register_info(write_fn write_fn, void *uc)
 {
     struct reginfo ri;
     int op;
@@ -29,24 +29,25 @@ int send_register_info(int sock, void *uc)
     op = get_risuop(&ri);
 
     switch (op) {
-    case OP_COMPARE:
     case OP_TESTEND:
-    default:
-        /* Do a simple register compare on (a) explicit request
-         * (b) end of test (c) a non-risuop UNDEF
-         */
-        return send_data_pkt(sock, &ri, sizeof(ri));
+        write_fn(&ri, sizeof(ri));
+        return 1;
     case OP_SETMEMBLOCK:
-        memblock = (void *) (uintptr_t) get_reginfo_paramreg(&ri);
+        memblock = (void *)(uintptr_t)get_reginfo_paramreg(&ri);
         break;
     case OP_GETMEMBLOCK:
         set_ucontext_paramreg(uc,
-                              get_reginfo_paramreg(&ri) +
-                              (uintptr_t) memblock);
+                              get_reginfo_paramreg(&ri) + (uintptr_t)memblock);
         break;
     case OP_COMPAREMEM:
-        return send_data_pkt(sock, memblock, MEMBLOCKLEN);
+        return write_fn(memblock, MEMBLOCKLEN);
         break;
+    case OP_COMPARE:
+    default:
+        /* Do a simple register compare on (a) explicit request
+         * (b) end of test (c) a non-risuop UNDEF
+         */
+        return write_fn(&ri, sizeof(ri));
     }
     return 0;
 }
@@ -59,7 +60,7 @@ int send_register_info(int sock, void *uc)
  * that says whether it is register or memory data, so if the two
  * sides get out of sync then we will fail obscurely.
  */
-int recv_and_compare_register_info(int sock, void *uc)
+int recv_and_compare_register_info(read_fn read_fn, respond_fn resp_fn, void *uc)
 {
     int resp = 0, op;
 
@@ -73,36 +74,34 @@ int recv_and_compare_register_info(int sock, void *uc)
         /* Do a simple register compare on (a) explicit request
          * (b) end of test (c) a non-risuop UNDEF
          */
-        if (recv_data_pkt(sock, &apprentice_ri, sizeof(apprentice_ri))) {
+        if (read_fn(&apprentice_ri, sizeof(apprentice_ri))) {
             packet_mismatch = 1;
             resp = 2;
-
         } else if (!reginfo_is_eq(&master_ri, &apprentice_ri)) {
             /* register mismatch */
             resp = 2;
-
         } else if (op == OP_TESTEND) {
             resp = 1;
         }
-        send_response_byte(sock, resp);
+        resp_fn(resp);
         break;
     case OP_SETMEMBLOCK:
-        memblock = (void *) (uintptr_t) get_reginfo_paramreg(&master_ri);
+        memblock = (void *)(uintptr_t)get_reginfo_paramreg(&master_ri);
         break;
     case OP_GETMEMBLOCK:
         set_ucontext_paramreg(uc, get_reginfo_paramreg(&master_ri) +
-                              (uintptr_t) memblock);
+                              (uintptr_t)memblock);
         break;
     case OP_COMPAREMEM:
         mem_used = 1;
-        if (recv_data_pkt(sock, apprentice_memblock, MEMBLOCKLEN)) {
+        if (read_fn(apprentice_memblock, MEMBLOCKLEN)) {
             packet_mismatch = 1;
             resp = 2;
         } else if (memcmp(memblock, apprentice_memblock, MEMBLOCKLEN) != 0) {
             /* memory mismatch */
             resp = 2;
         }
-        send_response_byte(sock, resp);
+        resp_fn(resp);
         break;
     }
 
risu.c +21 -2
index a10422a..88e586c 100644
@@ -37,9 +37,28 @@ sigjmp_buf jmpbuf;
 /* Should we test for FP exception status bits? */
 int test_fp_exc;
 
+/* Master functions */
+
+int read_sock(void *ptr, size_t bytes)
+{
+    return recv_data_pkt(master_socket, ptr, bytes);
+}
+
+void respond_sock(int r)
+{
+    send_response_byte(master_socket, r);
+}
+
+/* Apprentice function */
+
+int write_sock(void *ptr, size_t bytes)
+{
+    return send_data_pkt(apprentice_socket, ptr, bytes);
+}
+
 void master_sigill(int sig, siginfo_t *si, void *uc)
 {
-    switch (recv_and_compare_register_info(master_socket, uc)) {
+    switch (recv_and_compare_register_info(read_sock, respond_sock, uc)) {
     case 0:
         /* match OK */
         advance_pc(uc);
@@ -52,7 +71,7 @@ void master_sigill(int sig, siginfo_t *si, void *uc)
 
 void apprentice_sigill(int sig, siginfo_t *si, void *uc)
 {
-    switch (send_register_info(apprentice_socket, uc)) {
+    switch (send_register_info(write_sock, uc)) {
     case 0:
         /* match OK */
         advance_pc(uc);
risu.h +9 -2
index 78a7313..32241bc 100644
@@ -53,17 +53,24 @@ struct reginfo;
 
 /* Functions operating on reginfo */
 
+/* To keep the read/write logic from multiplying across all arches
+ * we wrap up the function here to keep all the changes in one place
+ */
+typedef int (*write_fn) (void *ptr, size_t bytes);
+typedef int (*read_fn) (void *ptr, size_t bytes);
+typedef void (*respond_fn) (int response);
+
 /* Send the register information from the struct ucontext down the socket.
  * Return the response code from the master.
  * NB: called from a signal handler.
  */
-int send_register_info(int sock, void *uc);
+int send_register_info(write_fn write_fn, void *uc);
 
 /* Read register info from the socket and compare it with that from the
  * ucontext. Return 0 for match, 1 for end-of-test, 2 for mismatch.
  * NB: called from a signal handler.
  */
-int recv_and_compare_register_info(int sock, void *uc);
+int recv_and_compare_register_info(read_fn read_fn, respond_fn respond, void *uc);
 
 /* Print a useful report on the status of the last comparison
  * done in recv_and_compare_register_info(). This is called on
Signature · 1 line
2.13.0
#15 lore raw

Re: [Qemu-devel] [RISU PATCH v5 07/13] risu: paramterise send/receive functions

Quoted 38 lines · Alex Bennée

This is a precursor to record/playback support. Instead of passing the socket fd we now pass helper functions for reading/writing and responding. This will allow us to do the rest of the record/playback cleanly outside of the main worker function.

---
v5
- re-base without tab/format cleanps
v4
- split header code
- fix formatting foo-bar's
v3
- new for v3
- arm, aarch64, ppc64

---
 reginfo.c | 39 +++++++++++++++++++--------------------
 risu.c    | 23 +++++++++++++++++++++--
 risu.h    | 11 +++++++++--
 3 files changed, 49 insertions(+), 24 deletions(-)
reginfo.c +1 -1
index 31bb99f..90cea8f 100644
@@ -21,7 +21,7 @@ uint8_t apprentice_memblock[MEMBLOCKLEN];
 static int mem_used;
 static int packet_mismatch;
 
-int send_register_info(int sock, void *uc)
+int send_register_info(write_fn write_fn, void *uc)
 {
     struct reginfo ri;
     int op;
@@ -29,24 +29,25 @@ int send_register_info(int sock, void *uc)
     op = get_risuop(&ri);
 

reginfo.c int send_register_info(int sock, void *uc) · line 34

Quoted 10 lines
reginfo.c +2 -6
     switch (op) {
-    case OP_COMPARE:
     case OP_TESTEND:
-    default:
-        /* Do a simple register compare on (a) explicit request
-         * (b) end of test (c) a non-risuop UNDEF
-         */
-        return send_data_pkt(sock, &ri, sizeof(ri));
+        write_fn(&ri, sizeof(ri));
+        return 1;

Why the change from "return write function's return value" to "ignore return value and always return 1" for OP_TESTEND ?

reginfo.c int send_register_info(int sock, void *uc) · line 44

Quoted 4 lines
reginfo.c +1 -1
     case OP_COMPAREMEM:
-        return send_data_pkt(sock, memblock, MEMBLOCKLEN);
+        return write_fn(memblock, MEMBLOCKLEN);
         break;

...here we still just pass the return value through, for instance.

Quoted 109 lines
reginfo.c +13 -9
+    case OP_COMPARE:
+    default:
+        /* Do a simple register compare on (a) explicit request
+         * (b) end of test (c) a non-risuop UNDEF
+         */
+        return write_fn(&ri, sizeof(ri));
     }
     return 0;
 }
@@ -59,7 +60,7 @@ int send_register_info(int sock, void *uc)
  * that says whether it is register or memory data, so if the two
  * sides get out of sync then we will fail obscurely.
  */
-int recv_and_compare_register_info(int sock, void *uc)
+int recv_and_compare_register_info(read_fn read_fn, respond_fn resp_fn, void *uc)
 {
     int resp = 0, op;
 
@@ -73,36 +74,34 @@ int recv_and_compare_register_info(int sock, void *uc)
         /* Do a simple register compare on (a) explicit request
          * (b) end of test (c) a non-risuop UNDEF
          */
-        if (recv_data_pkt(sock, &apprentice_ri, sizeof(apprentice_ri))) {
+        if (read_fn(&apprentice_ri, sizeof(apprentice_ri))) {
             packet_mismatch = 1;
             resp = 2;
-
         } else if (!reginfo_is_eq(&master_ri, &apprentice_ri)) {
             /* register mismatch */
             resp = 2;
-
         } else if (op == OP_TESTEND) {
             resp = 1;
         }
-        send_response_byte(sock, resp);
+        resp_fn(resp);
         break;
     case OP_SETMEMBLOCK:
-        memblock = (void *) (uintptr_t) get_reginfo_paramreg(&master_ri);
+        memblock = (void *)(uintptr_t)get_reginfo_paramreg(&master_ri);
         break;
     case OP_GETMEMBLOCK:
         set_ucontext_paramreg(uc, get_reginfo_paramreg(&master_ri) +
-                              (uintptr_t) memblock);
+                              (uintptr_t)memblock);
         break;
     case OP_COMPAREMEM:
         mem_used = 1;
-        if (recv_data_pkt(sock, apprentice_memblock, MEMBLOCKLEN)) {
+        if (read_fn(apprentice_memblock, MEMBLOCKLEN)) {
             packet_mismatch = 1;
             resp = 2;
         } else if (memcmp(memblock, apprentice_memblock, MEMBLOCKLEN) != 0) {
             /* memory mismatch */
             resp = 2;
         }
-        send_response_byte(sock, resp);
+        resp_fn(resp);
         break;
     }
 
risu.c +21 -2
index a10422a..88e586c 100644
@@ -37,9 +37,28 @@ sigjmp_buf jmpbuf;
 /* Should we test for FP exception status bits? */
 int test_fp_exc;
 
+/* Master functions */
+
+int read_sock(void *ptr, size_t bytes)
+{
+    return recv_data_pkt(master_socket, ptr, bytes);
+}
+
+void respond_sock(int r)
+{
+    send_response_byte(master_socket, r);
+}
+
+/* Apprentice function */
+
+int write_sock(void *ptr, size_t bytes)
+{
+    return send_data_pkt(apprentice_socket, ptr, bytes);
+}
+
 void master_sigill(int sig, siginfo_t *si, void *uc)
 {
-    switch (recv_and_compare_register_info(master_socket, uc)) {
+    switch (recv_and_compare_register_info(read_sock, respond_sock, uc)) {
     case 0:
         /* match OK */
         advance_pc(uc);
@@ -52,7 +71,7 @@ void master_sigill(int sig, siginfo_t *si, void *uc)
 
 void apprentice_sigill(int sig, siginfo_t *si, void *uc)
 {
-    switch (send_register_info(apprentice_socket, uc)) {
+    switch (send_register_info(write_sock, uc)) {
     case 0:
         /* match OK */
         advance_pc(uc);
risu.h +0 -0
index 78a7313..32241bc 100644

risu.h struct reginfo; · line 58

Quoted 6 lines
risu.h +3 -0
@@ -53,17 +53,24 @@ struct reginfo;
 
 /* Functions operating on reginfo */
 
+/* To keep the read/write logic from multiplying across all arches
+ * we wrap up the function here to keep all the changes in one place
+ */

Stale comment? The calling code is not per-arch any more.

Quoted 21 lines
risu.h +6 -3
+typedef int (*write_fn) (void *ptr, size_t bytes);
+typedef int (*read_fn) (void *ptr, size_t bytes);
+typedef void (*respond_fn) (int response);
+
 /* Send the register information from the struct ucontext down the socket.
  * Return the response code from the master.
  * NB: called from a signal handler.
  */
-int send_register_info(int sock, void *uc);
+int send_register_info(write_fn write_fn, void *uc);
 
 /* Read register info from the socket and compare it with that from the
  * ucontext. Return 0 for match, 1 for end-of-test, 2 for mismatch.
  * NB: called from a signal handler.
  */
-int recv_and_compare_register_info(int sock, void *uc);
+int recv_and_compare_register_info(read_fn read_fn, respond_fn respond, void *uc);
 
 /* Print a useful report on the status of the last comparison
  * done in recv_and_compare_register_info(). This is called on
--
Quoted 2 lines

2.13.0

thanks
-- PMM

#16 lore raw

Re: [Qemu-devel] [RISU PATCH v5 07/13] risu: paramterise send/receive functions

Quoted 39 lines · Peter Maydell
Quoted 38 lines · Alex Bennée

This is a precursor to record/playback support. Instead of passing the socket fd we now pass helper functions for reading/writing and responding. This will allow us to do the rest of the record/playback cleanly outside of the main worker function.

---
v5
- re-base without tab/format cleanps
v4
- split header code
- fix formatting foo-bar's
v3
- new for v3
- arm, aarch64, ppc64

---
 reginfo.c | 39 +++++++++++++++++++--------------------
 risu.c    | 23 +++++++++++++++++++++--
 risu.h    | 11 +++++++++--
 3 files changed, 49 insertions(+), 24 deletions(-)
reginfo.c +1 -1
index 31bb99f..90cea8f 100644
@@ -21,7 +21,7 @@ uint8_t apprentice_memblock[MEMBLOCKLEN];
 static int mem_used;
 static int packet_mismatch;
 
-int send_register_info(int sock, void *uc)
+int send_register_info(write_fn write_fn, void *uc)
 {
     struct reginfo ri;
     int op;
@@ -29,24 +29,25 @@ int send_register_info(int sock, void *uc)
     op = get_risuop(&ri);
 
Quoted 13 lines

reginfo.c int send_register_info(int sock, void *uc) · line 34

Quoted 10 lines
reginfo.c +2 -6
     switch (op) {
-    case OP_COMPARE:
     case OP_TESTEND:
-    default:
-        /* Do a simple register compare on (a) explicit request
-         * (b) end of test (c) a non-risuop UNDEF
-         */
-        return send_data_pkt(sock, &ri, sizeof(ri));
+        write_fn(&ri, sizeof(ri));
+        return 1;

Why the change from "return write function's return value" to "ignore return value and always return 1" for OP_TESTEND ?

Hmm possibly a re-base snaggle. I'll fix it up.

Quoted 118 lines

reginfo.c int send_register_info(int sock, void *uc) · line 44

Quoted 5 lines
reginfo.c +1 -1
     case OP_COMPAREMEM:
-        return send_data_pkt(sock, memblock, MEMBLOCKLEN);
+        return write_fn(memblock, MEMBLOCKLEN);
         break;

...here we still just pass the return value through, for instance.

Quoted 110 lines
reginfo.c +13 -9
+    case OP_COMPARE:
+    default:
+        /* Do a simple register compare on (a) explicit request
+         * (b) end of test (c) a non-risuop UNDEF
+         */
+        return write_fn(&ri, sizeof(ri));
     }
     return 0;
 }
@@ -59,7 +60,7 @@ int send_register_info(int sock, void *uc)
  * that says whether it is register or memory data, so if the two
  * sides get out of sync then we will fail obscurely.
  */
-int recv_and_compare_register_info(int sock, void *uc)
+int recv_and_compare_register_info(read_fn read_fn, respond_fn resp_fn, void *uc)
 {
     int resp = 0, op;
 
@@ -73,36 +74,34 @@ int recv_and_compare_register_info(int sock, void *uc)
         /* Do a simple register compare on (a) explicit request
          * (b) end of test (c) a non-risuop UNDEF
          */
-        if (recv_data_pkt(sock, &apprentice_ri, sizeof(apprentice_ri))) {
+        if (read_fn(&apprentice_ri, sizeof(apprentice_ri))) {
             packet_mismatch = 1;
             resp = 2;
-
         } else if (!reginfo_is_eq(&master_ri, &apprentice_ri)) {
             /* register mismatch */
             resp = 2;
-
         } else if (op == OP_TESTEND) {
             resp = 1;
         }
-        send_response_byte(sock, resp);
+        resp_fn(resp);
         break;
     case OP_SETMEMBLOCK:
-        memblock = (void *) (uintptr_t) get_reginfo_paramreg(&master_ri);
+        memblock = (void *)(uintptr_t)get_reginfo_paramreg(&master_ri);
         break;
     case OP_GETMEMBLOCK:
         set_ucontext_paramreg(uc, get_reginfo_paramreg(&master_ri) +
-                              (uintptr_t) memblock);
+                              (uintptr_t)memblock);
         break;
     case OP_COMPAREMEM:
         mem_used = 1;
-        if (recv_data_pkt(sock, apprentice_memblock, MEMBLOCKLEN)) {
+        if (read_fn(apprentice_memblock, MEMBLOCKLEN)) {
             packet_mismatch = 1;
             resp = 2;
         } else if (memcmp(memblock, apprentice_memblock, MEMBLOCKLEN) != 0) {
             /* memory mismatch */
             resp = 2;
         }
-        send_response_byte(sock, resp);
+        resp_fn(resp);
         break;
     }
 
risu.c +21 -2
index a10422a..88e586c 100644
@@ -37,9 +37,28 @@ sigjmp_buf jmpbuf;
 /* Should we test for FP exception status bits? */
 int test_fp_exc;
 
+/* Master functions */
+
+int read_sock(void *ptr, size_t bytes)
+{
+    return recv_data_pkt(master_socket, ptr, bytes);
+}
+
+void respond_sock(int r)
+{
+    send_response_byte(master_socket, r);
+}
+
+/* Apprentice function */
+
+int write_sock(void *ptr, size_t bytes)
+{
+    return send_data_pkt(apprentice_socket, ptr, bytes);
+}
+
 void master_sigill(int sig, siginfo_t *si, void *uc)
 {
-    switch (recv_and_compare_register_info(master_socket, uc)) {
+    switch (recv_and_compare_register_info(read_sock, respond_sock, uc)) {
     case 0:
         /* match OK */
         advance_pc(uc);
@@ -52,7 +71,7 @@ void master_sigill(int sig, siginfo_t *si, void *uc)
 
 void apprentice_sigill(int sig, siginfo_t *si, void *uc)
 {
-    switch (send_register_info(apprentice_socket, uc)) {
+    switch (send_register_info(write_sock, uc)) {
     case 0:
         /* match OK */
         advance_pc(uc);
risu.h +0 -0
index 78a7313..32241bc 100644
@@ -53,17 +53,24 @@ struct reginfo;
 
Quoted 7 lines

risu.h struct reginfo; · line 58

Quoted 5 lines
risu.h +3 -0
 /* Functions operating on reginfo */
 
+/* To keep the read/write logic from multiplying across all arches
+ * we wrap up the function here to keep all the changes in one place
+ */

Stale comment? The calling code is not per-arch any more.

Yes, I'll remove

Quoted 19 lines
Quoted 19 lines
risu.h +6 -2
+typedef int (*write_fn) (void *ptr, size_t bytes);
+typedef int (*read_fn) (void *ptr, size_t bytes);
+typedef void (*respond_fn) (int response);
+
 /* Send the register information from the struct ucontext down the socket.
  * Return the response code from the master.
  * NB: called from a signal handler.
  */
-int send_register_info(int sock, void *uc);
+int send_register_info(write_fn write_fn, void *uc);
 
 /* Read register info from the socket and compare it with that from the
  * ucontext. Return 0 for match, 1 for end-of-test, 2 for mismatch.
  * NB: called from a signal handler.
  */
-int recv_and_compare_register_info(int sock, void *uc);
+int recv_and_compare_register_info(read_fn read_fn, respond_fn respond, void *uc);
 
Quoted 8 lines
Quoted 5 lines
risu.h +0 -1
 /* Print a useful report on the status of the last comparison
  * done in recv_and_compare_register_info(). This is called on
--

2.13.0

thanks
-- PMM

--
Alex Bennée

#17 lore raw

Re: [Qemu-devel] [RISU PATCH v5 07/13] risu: paramterise send/receive functions

In reply to Peter Maydell
Quoted 39 lines · Peter Maydell
Quoted 38 lines · Alex Bennée

This is a precursor to record/playback support. Instead of passing the socket fd we now pass helper functions for reading/writing and responding. This will allow us to do the rest of the record/playback cleanly outside of the main worker function.

---
v5
- re-base without tab/format cleanps
v4
- split header code
- fix formatting foo-bar's
v3
- new for v3
- arm, aarch64, ppc64

---
 reginfo.c | 39 +++++++++++++++++++--------------------
 risu.c    | 23 +++++++++++++++++++++--
 risu.h    | 11 +++++++++--
 3 files changed, 49 insertions(+), 24 deletions(-)
reginfo.c +1 -1
index 31bb99f..90cea8f 100644
@@ -21,7 +21,7 @@ uint8_t apprentice_memblock[MEMBLOCKLEN];
 static int mem_used;
 static int packet_mismatch;
 
-int send_register_info(int sock, void *uc)
+int send_register_info(write_fn write_fn, void *uc)
 {
     struct reginfo ri;
     int op;
@@ -29,24 +29,25 @@ int send_register_info(int sock, void *uc)
     op = get_risuop(&ri);
 
Quoted 13 lines

reginfo.c int send_register_info(int sock, void *uc) · line 34

Quoted 10 lines
reginfo.c +2 -6
     switch (op) {
-    case OP_COMPARE:
     case OP_TESTEND:
-    default:
-        /* Do a simple register compare on (a) explicit request
-         * (b) end of test (c) a non-risuop UNDEF
-         */
-        return send_data_pkt(sock, &ri, sizeof(ri));
+        write_fn(&ri, sizeof(ri));
+        return 1;

Why the change from "return write function's return value" to "ignore return value and always return 1" for OP_TESTEND ?

And now I remember why ;-)

As write_fn may no longer return a ack code from the apprentice we need to ensure we always respond here. There is a bit of discrepancy here between send_data_pkt which returns a result from afar and write_trace which returns 0 when bytes_written == what we wanted to write.

Quoted 144 lines

reginfo.c int send_register_info(int sock, void *uc) · line 44

Quoted 5 lines
reginfo.c +1 -1
     case OP_COMPAREMEM:
-        return send_data_pkt(sock, memblock, MEMBLOCKLEN);
+        return write_fn(memblock, MEMBLOCKLEN);
         break;

...here we still just pass the return value through, for instance.

Quoted 109 lines
reginfo.c +13 -9
+    case OP_COMPARE:
+    default:
+        /* Do a simple register compare on (a) explicit request
+         * (b) end of test (c) a non-risuop UNDEF
+         */
+        return write_fn(&ri, sizeof(ri));
     }
     return 0;
 }
@@ -59,7 +60,7 @@ int send_register_info(int sock, void *uc)
  * that says whether it is register or memory data, so if the two
  * sides get out of sync then we will fail obscurely.
  */
-int recv_and_compare_register_info(int sock, void *uc)
+int recv_and_compare_register_info(read_fn read_fn, respond_fn resp_fn, void *uc)
 {
     int resp = 0, op;
 
@@ -73,36 +74,34 @@ int recv_and_compare_register_info(int sock, void *uc)
         /* Do a simple register compare on (a) explicit request
          * (b) end of test (c) a non-risuop UNDEF
          */
-        if (recv_data_pkt(sock, &apprentice_ri, sizeof(apprentice_ri))) {
+        if (read_fn(&apprentice_ri, sizeof(apprentice_ri))) {
             packet_mismatch = 1;
             resp = 2;
-
         } else if (!reginfo_is_eq(&master_ri, &apprentice_ri)) {
             /* register mismatch */
             resp = 2;
-
         } else if (op == OP_TESTEND) {
             resp = 1;
         }
-        send_response_byte(sock, resp);
+        resp_fn(resp);
         break;
     case OP_SETMEMBLOCK:
-        memblock = (void *) (uintptr_t) get_reginfo_paramreg(&master_ri);
+        memblock = (void *)(uintptr_t)get_reginfo_paramreg(&master_ri);
         break;
     case OP_GETMEMBLOCK:
         set_ucontext_paramreg(uc, get_reginfo_paramreg(&master_ri) +
-                              (uintptr_t) memblock);
+                              (uintptr_t)memblock);
         break;
     case OP_COMPAREMEM:
         mem_used = 1;
-        if (recv_data_pkt(sock, apprentice_memblock, MEMBLOCKLEN)) {
+        if (read_fn(apprentice_memblock, MEMBLOCKLEN)) {
             packet_mismatch = 1;
             resp = 2;
         } else if (memcmp(memblock, apprentice_memblock, MEMBLOCKLEN) != 0) {
             /* memory mismatch */
             resp = 2;
         }
-        send_response_byte(sock, resp);
+        resp_fn(resp);
         break;
     }
 
risu.c +21 -2
index a10422a..88e586c 100644
@@ -37,9 +37,28 @@ sigjmp_buf jmpbuf;
 /* Should we test for FP exception status bits? */
 int test_fp_exc;
 
+/* Master functions */
+
+int read_sock(void *ptr, size_t bytes)
+{
+    return recv_data_pkt(master_socket, ptr, bytes);
+}
+
+void respond_sock(int r)
+{
+    send_response_byte(master_socket, r);
+}
+
+/* Apprentice function */
+
+int write_sock(void *ptr, size_t bytes)
+{
+    return send_data_pkt(apprentice_socket, ptr, bytes);
+}
+
 void master_sigill(int sig, siginfo_t *si, void *uc)
 {
-    switch (recv_and_compare_register_info(master_socket, uc)) {
+    switch (recv_and_compare_register_info(read_sock, respond_sock, uc)) {
     case 0:
         /* match OK */
         advance_pc(uc);
@@ -52,7 +71,7 @@ void master_sigill(int sig, siginfo_t *si, void *uc)
 
 void apprentice_sigill(int sig, siginfo_t *si, void *uc)
 {
-    switch (send_register_info(apprentice_socket, uc)) {
+    switch (send_register_info(write_sock, uc)) {
     case 0:
         /* match OK */
         advance_pc(uc);
risu.h +0 -0
index 78a7313..32241bc 100644

risu.h struct reginfo; · line 58

Quoted 6 lines
risu.h +3 -0
@@ -53,17 +53,24 @@ struct reginfo;
 
 /* Functions operating on reginfo */
 
+/* To keep the read/write logic from multiplying across all arches
+ * we wrap up the function here to keep all the changes in one place
+ */

Stale comment? The calling code is not per-arch any more.

Quoted 18 lines
risu.h +6 -2
+typedef int (*write_fn) (void *ptr, size_t bytes);
+typedef int (*read_fn) (void *ptr, size_t bytes);
+typedef void (*respond_fn) (int response);
+
 /* Send the register information from the struct ucontext down the socket.
  * Return the response code from the master.
  * NB: called from a signal handler.
  */
-int send_register_info(int sock, void *uc);
+int send_register_info(write_fn write_fn, void *uc);
 
 /* Read register info from the socket and compare it with that from the
  * ucontext. Return 0 for match, 1 for end-of-test, 2 for mismatch.
  * NB: called from a signal handler.
  */
-int recv_and_compare_register_info(int sock, void *uc);
+int recv_and_compare_register_info(read_fn read_fn, respond_fn respond, void *uc);
 
Quoted 8 lines
Quoted 5 lines
risu.h +0 -1
 /* Print a useful report on the status of the last comparison
  * done in recv_and_compare_register_info(). This is called on
--

2.13.0

thanks
-- PMM

--
Alex Bennée

#18 lore raw

PATCH v5 8/13 risu: add header to trace stream

In reply to Alex Bennée

I've also added a header packet with pc/risu op in it so we can keep better track of how things are going.

---
v5
- re-base without formatting fixes
- dropped fprintfs in signal context
v4
- split from previous patch

---
 reginfo.c      | 94 +++++++++++++++++++++++++++++++++++++---------------------
 risu.h         |  9 ++++++
 risu_aarch64.c |  5 ++++
 risu_arm.c     |  5 ++++
 risu_m68k.c    |  5 ++++
 risu_ppc64.c   |  5 ++++
 6 files changed, 89 insertions(+), 34 deletions(-)
reginfo.c +60 -34
index 90cea8f..4ff937f 100644
@@ -24,10 +24,19 @@ static int packet_mismatch;
 int send_register_info(write_fn write_fn, void *uc)
 {
     struct reginfo ri;
+    trace_header_t header;
     int op;
+
     reginfo_init(&ri, uc);
     op = get_risuop(&ri);
 
+    /* Write a header with PC/op to keep in sync */
+    header.pc = get_pc(&ri);
+    header.risu_op = op;
+    if (write_fn(&header, sizeof(header)) != 0) {
+        return -1;
+    }
+
     switch (op) {
     case OP_TESTEND:
         write_fn(&ri, sizeof(ri));
@@ -63,46 +72,63 @@ int send_register_info(write_fn write_fn, void *uc)
 int recv_and_compare_register_info(read_fn read_fn, respond_fn resp_fn, void *uc)
 {
     int resp = 0, op;
+    trace_header_t header;
 
     reginfo_init(&master_ri, uc);
     op = get_risuop(&master_ri);
 
-    switch (op) {
-    case OP_COMPARE:
-    case OP_TESTEND:
-    default:
-        /* Do a simple register compare on (a) explicit request
-         * (b) end of test (c) a non-risuop UNDEF
-         */
-        if (read_fn(&apprentice_ri, sizeof(apprentice_ri))) {
-            packet_mismatch = 1;
-            resp = 2;
-        } else if (!reginfo_is_eq(&master_ri, &apprentice_ri)) {
-            /* register mismatch */
-            resp = 2;
-        } else if (op == OP_TESTEND) {
-            resp = 1;
-        }
-        resp_fn(resp);
-        break;
-    case OP_SETMEMBLOCK:
-        memblock = (void *)(uintptr_t)get_reginfo_paramreg(&master_ri);
-        break;
-    case OP_GETMEMBLOCK:
-        set_ucontext_paramreg(uc, get_reginfo_paramreg(&master_ri) +
-                              (uintptr_t)memblock);
-        break;
-    case OP_COMPAREMEM:
-        mem_used = 1;
-        if (read_fn(apprentice_memblock, MEMBLOCKLEN)) {
-            packet_mismatch = 1;
-            resp = 2;
-        } else if (memcmp(memblock, apprentice_memblock, MEMBLOCKLEN) != 0) {
-            /* memory mismatch */
-            resp = 2;
+    if (read_fn(&header, sizeof(header)) != 0) {
+        return -1;
+    }
+
+    if (header.risu_op == op ) {
+
+        /* send OK for the header */
+        resp_fn(0);
+
+        switch (op) {
+        case OP_COMPARE:
+        case OP_TESTEND:
+        default:
+            /* Do a simple register compare on (a) explicit request
+             * (b) end of test (c) a non-risuop UNDEF
+             */
+            if (read_fn(&apprentice_ri, sizeof(apprentice_ri))) {
+                packet_mismatch = 1;
+                resp = 2;
+
+            } else if (!reginfo_is_eq(&master_ri, &apprentice_ri)) {
+                /* register mismatch */
+                resp = 2;
+
+            } else if (op == OP_TESTEND) {
+                resp = 1;
+            }
+            resp_fn(resp);
+            break;
+        case OP_SETMEMBLOCK:
+            memblock = (void *)(uintptr_t)get_reginfo_paramreg(&master_ri);
+            break;
+        case OP_GETMEMBLOCK:
+            set_ucontext_paramreg(uc, get_reginfo_paramreg(&master_ri) +
+                                  (uintptr_t)memblock);
+            break;
+        case OP_COMPAREMEM:
+            mem_used = 1;
+            if (read_fn(apprentice_memblock, MEMBLOCKLEN)) {
+                packet_mismatch = 1;
+                resp = 2;
+            } else if (memcmp(memblock, apprentice_memblock, MEMBLOCKLEN) != 0) {
+                /* memory mismatch */
+                resp = 2;
+            }
+            resp_fn(resp);
+            break;
         }
+    } else {
+        /* We are out of sync */
+        resp = 2;
         resp_fn(resp);
-        break;
     }
 
     return resp;
risu.h +9 -0
index 32241bc..e9e70ab 100644
@@ -51,6 +51,12 @@ extern int ismaster;
 
 struct reginfo;
 
+typedef struct
+{
+   uintptr_t pc;
+   uint32_t risu_op;
+} trace_header_t;
+
 /* Functions operating on reginfo */
 
 /* To keep the read/write logic from multiplying across all arches
@@ -102,6 +108,9 @@ uint64_t get_reginfo_paramreg(struct reginfo *ri);
  */
 int get_risuop(struct reginfo *ri);
 
+/* Return the PC from a reginfo */
+uintptr_t get_pc(struct reginfo *ri);
+
 /* initialize structure from a ucontext */
 void reginfo_init(struct reginfo *ri, ucontext_t *uc);
 
risu_aarch64.c +5 -0
index 9c6809d..492d141 100644
@@ -40,3 +40,8 @@ int get_risuop(struct reginfo *ri)
     uint32_t risukey = 0x00005af0;
     return (key != risukey) ? -1 : op;
 }
+
+uintptr_t get_pc(struct reginfo *ri)
+{
+   return ri->pc;
+}
risu_arm.c +5 -0
index a55c6c2..5fcb2a5 100644
@@ -68,3 +68,8 @@ int get_risuop(struct reginfo *ri)
     uint32_t risukey = (isz == 2) ? 0xdee0 : 0xe7fe5af0;
     return (key != risukey) ? -1 : op;
 }
+
+uintptr_t get_pc(struct reginfo *ri)
+{
+   return ri->gpreg[15];
+}
risu_m68k.c +5 -0
index 0bf5c14..1056eef 100644
@@ -33,3 +33,8 @@ int get_risuop(struct reginfo *ri)
     uint32_t risukey = 0x4afc7000;
     return (key != risukey) ? -1 : op;
 }
+
+uintptr_t get_pc(struct reginfo *ri)
+{
+    return ri->gregs[R_PC];
+}
risu_ppc64.c +5 -0
index eb60573..83f8d1f 100644
@@ -38,3 +38,8 @@ int get_risuop(struct reginfo *ri)
     uint32_t risukey = 0x00005af0;
     return (key != risukey) ? -1 : op;
 }
+
+uintptr_t get_pc(struct reginfo *ri)
+{
+   return ri->nip;
+}
Signature · 1 line
2.13.0
Reviewed-by on v5 8/13
#19 lore raw

Re: [Qemu-devel] [RISU PATCH v5 08/13] risu: add header to trace stream

Quoted 81 lines · Alex Bennée

I've also added a header packet with pc/risu op in it so we can keep better track of how things are going.

---
v5
- re-base without formatting fixes
- dropped fprintfs in signal context
v4
- split from previous patch

---
 reginfo.c      | 94 +++++++++++++++++++++++++++++++++++++---------------------
 risu.h         |  9 ++++++
 risu_aarch64.c |  5 ++++
 risu_arm.c     |  5 ++++
 risu_m68k.c    |  5 ++++
 risu_ppc64.c   |  5 ++++
 6 files changed, 89 insertions(+), 34 deletions(-)
reginfo.c +10 -28
index 90cea8f..4ff937f 100644
@@ -24,10 +24,19 @@ static int packet_mismatch;
 int send_register_info(write_fn write_fn, void *uc)
 {
     struct reginfo ri;
+    trace_header_t header;
     int op;
+
     reginfo_init(&ri, uc);
     op = get_risuop(&ri);
 
+    /* Write a header with PC/op to keep in sync */
+    header.pc = get_pc(&ri);
+    header.risu_op = op;
+    if (write_fn(&header, sizeof(header)) != 0) {
+        return -1;
+    }
+
     switch (op) {
     case OP_TESTEND:
         write_fn(&ri, sizeof(ri));
@@ -63,46 +72,63 @@ int send_register_info(write_fn write_fn, void *uc)
 int recv_and_compare_register_info(read_fn read_fn, respond_fn resp_fn, void *uc)
 {
     int resp = 0, op;
+    trace_header_t header;
 
     reginfo_init(&master_ri, uc);
     op = get_risuop(&master_ri);
 
-    switch (op) {
-    case OP_COMPARE:
-    case OP_TESTEND:
-    default:
-        /* Do a simple register compare on (a) explicit request
-         * (b) end of test (c) a non-risuop UNDEF
-         */
-        if (read_fn(&apprentice_ri, sizeof(apprentice_ri))) {
-            packet_mismatch = 1;
-            resp = 2;
-        } else if (!reginfo_is_eq(&master_ri, &apprentice_ri)) {
-            /* register mismatch */
-            resp = 2;
-        } else if (op == OP_TESTEND) {
-            resp = 1;
-        }
-        resp_fn(resp);
-        break;
-    case OP_SETMEMBLOCK:
-        memblock = (void *)(uintptr_t)get_reginfo_paramreg(&master_ri);
-        break;
-    case OP_GETMEMBLOCK:
-        set_ucontext_paramreg(uc, get_reginfo_paramreg(&master_ri) +
-                              (uintptr_t)memblock);
-        break;
-    case OP_COMPAREMEM:
-        mem_used = 1;
-        if (read_fn(apprentice_memblock, MEMBLOCKLEN)) {

reginfo.c int send_register_info(write_fn write_fn, void *uc) · line 84

Quoted 10 lines
reginfo.c +5 -5
-            packet_mismatch = 1;
-            resp = 2;
-        } else if (memcmp(memblock, apprentice_memblock, MEMBLOCKLEN) != 0) {
-            /* memory mismatch */
-            resp = 2;
+    if (read_fn(&header, sizeof(header)) != 0) {
+        return -1;
+    }
+
+    if (header.risu_op == op ) {

Stray extra space.

Quoted 38 lines
reginfo.c +38 -0
+
+        /* send OK for the header */
+        resp_fn(0);
+
+        switch (op) {
+        case OP_COMPARE:
+        case OP_TESTEND:
+        default:
+            /* Do a simple register compare on (a) explicit request
+             * (b) end of test (c) a non-risuop UNDEF
+             */
+            if (read_fn(&apprentice_ri, sizeof(apprentice_ri))) {
+                packet_mismatch = 1;
+                resp = 2;
+
+            } else if (!reginfo_is_eq(&master_ri, &apprentice_ri)) {
+                /* register mismatch */
+                resp = 2;
+
+            } else if (op == OP_TESTEND) {
+                resp = 1;
+            }
+            resp_fn(resp);
+            break;
+        case OP_SETMEMBLOCK:
+            memblock = (void *)(uintptr_t)get_reginfo_paramreg(&master_ri);
+            break;
+        case OP_GETMEMBLOCK:
+            set_ucontext_paramreg(uc, get_reginfo_paramreg(&master_ri) +
+                                  (uintptr_t)memblock);
+            break;
+        case OP_COMPAREMEM:
+            mem_used = 1;
+            if (read_fn(apprentice_memblock, MEMBLOCKLEN)) {
+                packet_mismatch = 1;
+                resp = 2;
+            } else if (memcmp(memblock, apprentice_memblock, MEMBLOCKLEN) != 0) {
+                /* memory mismatch */

reginfo.c int send_register_info(write_fn write_fn, void *uc) · line 105

Quoted 10 lines
reginfo.c +7 -1
+                resp = 2;
+            }
+            resp_fn(resp);
+            break;
         }
+    } else {
+        /* We are out of sync */
+        resp = 2;
         resp_fn(resp);
-        break;

This is probably easier to read if structured the other way up, so:

     if (header.risu_op != op) {
        /* out of sync */
        ...
        return resp;
     }

and then you can leave the rest of the function alone.

Quoted 35 lines
reginfo.c +0 -0
     }
 
     return resp;
risu.h +9 -0
index 32241bc..e9e70ab 100644
@@ -51,6 +51,12 @@ extern int ismaster;
 
 struct reginfo;
 
+typedef struct
+{
+   uintptr_t pc;
+   uint32_t risu_op;
+} trace_header_t;
+
 /* Functions operating on reginfo */
 
 /* To keep the read/write logic from multiplying across all arches
@@ -102,6 +108,9 @@ uint64_t get_reginfo_paramreg(struct reginfo *ri);
  */
 int get_risuop(struct reginfo *ri);
 
+/* Return the PC from a reginfo */
+uintptr_t get_pc(struct reginfo *ri);
+
 /* initialize structure from a ucontext */
 void reginfo_init(struct reginfo *ri, ucontext_t *uc);
 
risu_aarch64.c +0 -0
index 9c6809d..492d141 100644

risu_aarch64.c int get_risuop(struct reginfo *ri) · line 46

Quoted 7 lines
risu_aarch64.c +4 -0
@@ -40,3 +40,8 @@ int get_risuop(struct reginfo *ri)
     uint32_t risukey = 0x00005af0;
     return (key != risukey) ? -1 : op;
 }
+
+uintptr_t get_pc(struct reginfo *ri)
+{
+   return ri->pc;

Indent here (and in some of the other versions of this function) isn't matching the standard set up in earlier patches.

Quoted 32 lines
risu_aarch64.c +1 -0
+}
risu_arm.c +5 -0
index a55c6c2..5fcb2a5 100644
@@ -68,3 +68,8 @@ int get_risuop(struct reginfo *ri)
     uint32_t risukey = (isz == 2) ? 0xdee0 : 0xe7fe5af0;
     return (key != risukey) ? -1 : op;
 }
+
+uintptr_t get_pc(struct reginfo *ri)
+{
+   return ri->gpreg[15];
+}
risu_m68k.c +5 -0
index 0bf5c14..1056eef 100644
@@ -33,3 +33,8 @@ int get_risuop(struct reginfo *ri)
     uint32_t risukey = 0x4afc7000;
     return (key != risukey) ? -1 : op;
 }
+
+uintptr_t get_pc(struct reginfo *ri)
+{
+    return ri->gregs[R_PC];
+}
risu_ppc64.c +0 -0
index eb60573..83f8d1f 100644

risu_ppc64.c int get_risuop(struct reginfo *ri)

Quoted 9 lines
risu_ppc64.c +5 -1
@@ -38,3 +38,8 @@ int get_risuop(struct reginfo *ri)
     uint32_t risukey = 0x00005af0;
     return (key != risukey) ? -1 : op;
 }
+
+uintptr_t get_pc(struct reginfo *ri)
+{
+   return ri->nip;
+}
--

Otherwise

thanks
-- PMM

#20 lore raw

PATCH v5 9/13 risu: add simple trace and replay support

In reply to Alex Bennée

This adds a very dumb and easily breakable trace and replay support. In --master mode the various risu ops trigger a write of register/memory state into a binary file which can be played back to an apprentice. Currently there is no validation of the image source so feeding the wrong image will fail straight away.

The trace files will get very big for any appreciable sized test file and this will be addressed in later patches.

---
v5
- re-base without formatting fixes
- unify socket/file descriptors
- count number of signals/checkpoint
- all output from sigjmp (not in signhandlers)
v4
- fix formatting mess
- abort() instead of reporting de-sync
- don't fake return for compiler
v3
- fix options parsing
- re-factored so no need for copy & paste
v2
- moved read/write functions into main risu.c
- cleaned up formatting
- report more in apprentice --trace mode

---
 risu.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 93 insertions(+), 19 deletions(-)
risu.c +93 -19
index 88e586c..93c274b 100644
@@ -30,7 +30,9 @@
 
 void *memblock;
 
-int apprentice_socket, master_socket;
+int apprentice_fd, master_fd;
+int trace;
+size_t signal_count;
 
 sigjmp_buf jmpbuf;
 
@@ -41,24 +43,60 @@ int test_fp_exc;
 
 int read_sock(void *ptr, size_t bytes)
 {
-    return recv_data_pkt(master_socket, ptr, bytes);
+    return recv_data_pkt(master_fd, ptr, bytes);
+}
+
+int write_trace(void *ptr, size_t bytes)
+{
+    size_t res = write(master_fd, ptr, bytes);
+    return (res == bytes) ? 0 : 1;
 }
 
 void respond_sock(int r)
 {
-    send_response_byte(master_socket, r);
+    send_response_byte(master_fd, r);
 }
 
 /* Apprentice function */
 
 int write_sock(void *ptr, size_t bytes)
 {
-    return send_data_pkt(apprentice_socket, ptr, bytes);
+    return send_data_pkt(apprentice_fd, ptr, bytes);
+}
+
+int read_trace(void *ptr, size_t bytes)
+{
+    size_t res = read(apprentice_fd, ptr, bytes);
+    return (res == bytes) ? 0 : 1;
+}
+
+void respond_trace(int r)
+{
+    switch (r) {
+    case 0: /* test ok */
+    case 1: /* end of test */
+        break;
+    default:
+        /* mismatch - if tracing we need to report, otherwise barf */
+        if (!trace) {
+           abort();
+        }
+        break;
+    }
 }
 
 void master_sigill(int sig, siginfo_t *si, void *uc)
 {
-    switch (recv_and_compare_register_info(read_sock, respond_sock, uc)) {
+    int r;
+    signal_count++;
+
+    if (trace) {
+        r = send_register_info(write_trace, uc);
+    } else {
+        r = recv_and_compare_register_info(read_sock, respond_sock, uc);
+    }
+
+    switch (r) {
     case 0:
         /* match OK */
         advance_pc(uc);
@@ -71,7 +109,16 @@ void master_sigill(int sig, siginfo_t *si, void *uc)
 
 void apprentice_sigill(int sig, siginfo_t *si, void *uc)
 {
-    switch (send_register_info(write_sock, uc)) {
+    int r;
+    signal_count++;
+
+    if (trace) {
+        r = recv_and_compare_register_info(read_trace, respond_trace, uc);
+    } else {
+        r = send_register_info(write_sock, uc);
+    }
+
+    switch (r) {
     case 0:
         /* match OK */
         advance_pc(uc);
@@ -81,6 +128,9 @@ void apprentice_sigill(int sig, siginfo_t *si, void *uc)
         exit(0);
     default:
         /* mismatch */
+        if (trace) {
+            siglongjmp(jmpbuf, 1);
+        }
         exit(1);
     }
 }
@@ -136,12 +186,17 @@ void load_image(const char *imgfile)
     image_start_address = (uintptr_t) addr;
 }
 
-int master(int sock)
+int master(void)
 {
     if (sigsetjmp(jmpbuf, 1)) {
-        return report_match_status();
+        close(master_fd);
+        if (trace) {
+            fprintf(stderr, "trace complete after %zd checkpoints\n", signal_count);
+            return 0;
+        } else {
+            return report_match_status();
+        }
     }
-    master_socket = sock;
     set_sigill_handler(&master_sigill);
     fprintf(stderr, "starting master image at 0x%"PRIxPTR"\n",
             image_start_address);
@@ -151,9 +206,13 @@ int master(int sock)
     exit(1);
 }
 
-int apprentice(int sock)
+int apprentice(void)
 {
-    apprentice_socket = sock;
+    if (sigsetjmp(jmpbuf, 1)) {
+        close(apprentice_fd);
+        fprintf(stderr, "finished early after %zd checkpoints\n", signal_count);
+        return report_match_status();
+    }
     set_sigill_handler(&apprentice_sigill);
     fprintf(stderr, "starting apprentice image at 0x%"PRIxPTR"\n",
             image_start_address);
@@ -175,6 +234,7 @@ void usage(void)
     fprintf(stderr, "between master and apprentice risu processes.\n\n");
     fprintf(stderr, "Options:\n");
     fprintf(stderr, "  --master          Be the master (server)\n");
+    fprintf(stderr, "  -t, --trace=FILE  Record/playback trace file\n");
     fprintf(stderr,
             "  -h, --host=HOST   Specify master host machine (apprentice only)"
             "\n");
@@ -189,7 +249,7 @@ int main(int argc, char **argv)
     uint16_t port = 9191;
     char *hostname = "localhost";
     char *imgfile;
-    int sock;
+    char *trace_fn = NULL;
 
     /* TODO clean this up later */
 
@@ -203,7 +263,7 @@ int main(int argc, char **argv)
             {0, 0, 0, 0}
         };
         int optidx = 0;
-        int c = getopt_long(argc, argv, "h:p:", longopts, &optidx);
+        int c = getopt_long(argc, argv, "h:p:t:", longopts, &optidx);
         if (c == -1) {
             break;
         }
@@ -214,6 +274,12 @@ int main(int argc, char **argv)
             /* flag set by getopt_long, do nothing */
             break;
         }
+        case 't':
+        {
+            trace_fn = optarg;
+            trace = 1;
+            break;
+        }
         case 'h':
         {
             hostname = optarg;
@@ -245,12 +311,20 @@ int main(int argc, char **argv)
     load_image(imgfile);
 
     if (ismaster) {
-        fprintf(stderr, "master port %d\n", port);
-        sock = master_connect(port);
-        return master(sock);
+        if (trace) {
+            master_fd = open(trace_fn, O_WRONLY|O_CREAT, S_IRWXU);
+        } else {
+            fprintf(stderr, "master port %d\n", port);
+            master_fd = master_connect(port);
+        }
+        return master();
     } else {
-        fprintf(stderr, "apprentice host %s port %d\n", hostname, port);
-        sock = apprentice_connect(hostname, port);
-        return apprentice(sock);
+        if (trace) {
+            apprentice_fd = open(trace_fn, O_RDONLY);
+        } else {
+            fprintf(stderr, "apprentice host %s port %d\n", hostname, port);
+            apprentice_fd = apprentice_connect(hostname, port);
+        }
+        return apprentice();
     }
 }
Signature · 1 line
2.13.0
Reviewed-by on v5 9/13
#21 lore raw

Re: [Qemu-devel] [RISU PATCH v5 09/13] risu: add simple trace and replay support

Quoted 10 lines · Alex Bennée

This adds a very dumb and easily breakable trace and replay support. In --master mode the various risu ops trigger a write of register/memory state into a binary file which can be played back to an apprentice. Currently there is no validation of the image source so feeding the wrong image will fail straight away.

The trace files will get very big for any appreciable sized test file and this will be addressed in later patches.

thanks
-- PMM

#22 lore raw

PATCH v5 10/13 risu: handle trace through stdin/stdout

In reply to Alex Bennée

Trace files can get quite large so it would be useful to be able to just capture the trace stream with stdin/stdout for processing in a pipe line. The sort of case where this is useful is for building static binaries where zlib support is missing for whatever reason.

It can also be used in testing pipelines.

---
 risu.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
risu.c +10 -2
index 93c274b..e94b54b 100644
@@ -312,7 +312,11 @@ int main(int argc, char **argv)
 
     if (ismaster) {
         if (trace) {
-            master_fd = open(trace_fn, O_WRONLY|O_CREAT, S_IRWXU);
+            if (strncmp(trace_fn, "-", strlen(trace_fn))==0) {
+                master_fd = fileno(stdout);
+            } else {
+                master_fd = open(trace_fn, O_WRONLY|O_CREAT, S_IRWXU);
+            }
         } else {
             fprintf(stderr, "master port %d\n", port);
             master_fd = master_connect(port);
@@ -320,7 +324,11 @@ int main(int argc, char **argv)
         return master();
     } else {
         if (trace) {
-            apprentice_fd = open(trace_fn, O_RDONLY);
+            if (strncmp(trace_fn, "-", strlen(trace_fn))==0) {
+                apprentice_fd = fileno(stdin);
+            } else {
+                apprentice_fd = open(trace_fn, O_RDONLY);
+            }
         } else {
             fprintf(stderr, "apprentice host %s port %d\n", hostname, port);
             apprentice_fd = apprentice_connect(hostname, port);
Signature · 1 line
2.13.0
#23 lore raw

Re: [Qemu-devel] [RISU PATCH v5 10/13] risu: handle trace through stdin/stdout

Quoted 17 lines · Alex Bennée

Trace files can get quite large so it would be useful to be able to just capture the trace stream with stdin/stdout for processing in a pipe line. The sort of case where this is useful is for building static binaries where zlib support is missing for whatever reason.

It can also be used in testing pipelines.

---
 risu.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
risu.c +0 -0
index 93c274b..e94b54b 100644

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

Quoted 5 lines
risu.c +1 -1
@@ -312,7 +312,11 @@ int main(int argc, char **argv)
 
     if (ismaster) {
         if (trace) {
-            master_fd = open(trace_fn, O_WRONLY|O_CREAT, S_IRWXU);
+            if (strncmp(trace_fn, "-", strlen(trace_fn))==0) {

Why not just strcmp() ?

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

Quoted 1 line
risu.c +1 -0
+                master_fd = fileno(stdout);
   = STDOUT_FILENO;

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

Quoted 13 lines
risu.c +5 -1
+            } else {
+                master_fd = open(trace_fn, O_WRONLY|O_CREAT, S_IRWXU);
+            }
         } else {
             fprintf(stderr, "master port %d\n", port);
             master_fd = master_connect(port);
@@ -320,7 +324,11 @@ int main(int argc, char **argv)
         return master();
     } else {
         if (trace) {
-            apprentice_fd = open(trace_fn, O_RDONLY);
+            if (strncmp(trace_fn, "-", strlen(trace_fn))==0) {
+                apprentice_fd = fileno(stdin);

= STDIN_FILENO;

Quoted 9 lines
risu.c +3 -1
+            } else {
+                apprentice_fd = open(trace_fn, O_RDONLY);
+            }
         } else {
             fprintf(stderr, "apprentice host %s port %d\n", hostname, port);
             apprentice_fd = apprentice_connect(hostname, port);
--

2.13.0

thanks
-- PMM

#24 lore raw

Re: [Qemu-devel] [RISU PATCH v5 10/13] risu: handle trace through stdin/stdout

Quoted 19 lines · Peter Maydell
Quoted 18 lines · Alex Bennée

Trace files can get quite large so it would be useful to be able to just capture the trace stream with stdin/stdout for processing in a pipe line. The sort of case where this is useful is for building static binaries where zlib support is missing for whatever reason.

It can also be used in testing pipelines.

---
 risu.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
risu.c +0 -0
index 93c274b..e94b54b 100644
@@ -312,7 +312,11 @@ int main(int argc, char **argv)
 
Quoted 6 lines

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

Quoted 4 lines
risu.c +1 -1
     if (ismaster) {
         if (trace) {
-            master_fd = open(trace_fn, O_WRONLY|O_CREAT, S_IRWXU);
+            if (strncmp(trace_fn, "-", strlen(trace_fn))==0) {

Why not just strcmp() ?

Years of habit...

Quoted 4 lines

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

Quoted 2 lines
risu.c +1 -0
+                master_fd = fileno(stdout);
   = STDOUT_FILENO;

heh , the original version used that. I'll put it back.

Quoted 27 lines
Quoted 8 lines
risu.c +3 -0
+            } else {
+                master_fd = open(trace_fn, O_WRONLY|O_CREAT, S_IRWXU);
+            }
         } else {
             fprintf(stderr, "master port %d\n", port);
             master_fd = master_connect(port);

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

Quoted 6 lines
risu.c +2 -1
@@ -320,7 +324,11 @@ int main(int argc, char **argv)
         return master();
     } else {
         if (trace) {
-            apprentice_fd = open(trace_fn, O_RDONLY);
+            if (strncmp(trace_fn, "-", strlen(trace_fn))==0) {
+                apprentice_fd = fileno(stdin);

= STDIN_FILENO;

Quoted 9 lines
risu.c +3 -1
+            } else {
+                apprentice_fd = open(trace_fn, O_RDONLY);
+            }
         } else {
             fprintf(stderr, "apprentice host %s port %d\n", hostname, port);
             apprentice_fd = apprentice_connect(hostname, port);
--

2.13.0

Quoted 2 lines

thanks
-- PMM

--
Alex Bennée

#25 lore raw

PATCH v5 11/13 risu: add support compressed tracefiles

In reply to Alex Bennée

This uses the magic of zlib's gzread/write interface to wrap the tracefile in compression. The code changes are tiny. I spent more time messing about with the configure/linker stuff to auto-detect bits.

As you need decent multi-arch support or a correctly setup cross toolchain we fall back if we can't compile with zlib. This unfortunately needs some #ifdef hackery around the zlib bits in risu.c.

--
v5
- re-base
- also don't use zlib if using stdio fds
v4
- removed redundant config.h output, added HAVE_ZLIB
- added BUILD_INC to deal with out-of-tree builds

---
 Makefile  |  4 ++--
 configure | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
 risu.c    | 48 ++++++++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 101 insertions(+), 6 deletions(-)
Makefile +2 -2
index 9a29bb4..ca80eef 100644
@@ -17,7 +17,7 @@ VPATH=$(SRCDIR)
 
 CFLAGS ?= -g
 
-ALL_CFLAGS = -Wall -D_GNU_SOURCE -DARCH=$(ARCH) $(CFLAGS) $(EXTRA_CFLAGS)
+ALL_CFLAGS = -Wall -D_GNU_SOURCE -DARCH=$(ARCH) $(BUILD_INC) $(CFLAGS) $(EXTRA_CFLAGS)
 
 PROG=risu
 SRCS=risu.c comms.c reginfo.c risu_$(ARCH).c risu_reginfo_$(ARCH).c
@@ -35,7 +35,7 @@ all: $(PROG) $(BINS)
 dump: $(RISU_ASMS)
 
 $(PROG): $(OBJS)
-	$(CC) $(STATIC) $(ALL_CFLAGS) -o $@ $^
+	$(CC) $(STATIC) $(ALL_CFLAGS) -o $@ $^ $(LDFLAGS)
 
 %.risu.asm: %.risu.bin
 	${OBJDUMP} -b binary -m $(ARCH) -D $^ > $@
configure +53 -2

97 lines not on this page · raw message

risu.c +46 -2

96 lines not on this page · raw message

Signature · 1 line
2.13.0
Reviewed-by on v5 11/13
#26 lore raw

Re: [Qemu-devel] [RISU PATCH v5 11/13] risu: add support compressed tracefiles

Quoted 10 lines · Alex Bennée

This uses the magic of zlib's gzread/write interface to wrap the tracefile in compression. The code changes are tiny. I spent more time messing about with the configure/linker stuff to auto-detect bits.

As you need decent multi-arch support or a correctly setup cross toolchain we fall back if we can't compile with zlib. This unfortunately needs some #ifdef hackery around the zlib bits in risu.c.

(it would be nice if we could just mandate gzip, but we could spend a lot of time messing about here that doesn't seem worthwhile.)

thanks
-- PMM

#27 lore raw

PATCH v5 12/13 new: record_traces.sh helper script

In reply to Alex Bennée

A simple script to run through a bunch of binaries and generate their trace files.

---
v5
- author, license and usage header
v3
- allow overriding of RISU binary

---
 record_traces.sh | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
 create mode 100755 record_traces.sh
record_traces.sh new file +32 -0
new file mode 100755
index 0000000..1234a61
@@ -0,0 +1,32 @@
+#!/bin/sh
+#
+# A risu helper script to batch process a bunch of binaries and record their outputs
+#
+# Copyright (c) 2017 Linaro Limited
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+#     Alex Bennée <[email protected]> - initial implementation
+#
+# Usage:
+#   export RISU=/path/to/risu
+#   ./record_traces.sh  ./testcases.aarch64/*.bin
+#
+
+set -e
+
+if test -z "$RISU"; then
+    script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)
+    RISU=${script_dir}/risu
+fi
+
+for f in $@; do
+    echo "Running risu against $f"
+    t="$f.trace"
+    ${RISU} --master $f -t $t
+    echo "Checking trace file OK"
+    ${RISU} $f -t $t
+done
Signature · 1 line
2.13.0
#28 lore raw

Re: [Qemu-devel] [RISU PATCH v5 12/13] new: record_traces.sh helper script

Quoted 10 lines · Alex Bennée

A simple script to run through a bunch of binaries and generate their trace files.

---
v5
- author, license and usage header
v3
- allow overriding of RISU binary

Quoted 4 lines
---
 record_traces.sh | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
 create mode 100755 record_traces.sh

Another one for contrib/, I think.

thanks
-- PMM

#29 lore raw

Re: [Qemu-devel] [RISU PATCH v5 12/13] new: record_traces.sh helper script

Quoted 16 lines · Peter Maydell
Quoted 10 lines · Alex Bennée

A simple script to run through a bunch of binaries and generate their trace files.

---
v5
- author, license and usage header
v3
- allow overriding of RISU binary

Quoted 4 lines
---
 record_traces.sh | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
 create mode 100755 record_traces.sh
Quoted 1 line

Another one for contrib/, I think.

OK will do.

Quoted 3 lines

thanks
-- PMM

--
Alex Bennée

#30 lore raw

PATCH v5 13/13 new: run_risu.sh script

In reply to Alex Bennée

A simple script to work through running all of a bunch of files with record/playback traces. Dumps a summary and the number of failed tests at the end.

---
v5
- author, license, usage header
v3
- tweak to allow specifying RISU binary

---
 run_risu.sh | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)
 create mode 100755 run_risu.sh
run_risu.sh new file +66 -0
new file mode 100755
index 0000000..439cd36
@@ -0,0 +1,66 @@
+#!/bin/bash
+#
+# Run risu against a set of binaries + trace files
+#
+# Copyright (c) 2017 Linaro Limited
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+#     Alex Bennée <[email protected]> - initial implementation
+#
+# Usage:
+#   (optional) export QEMU=/path/to/qemu
+#   (optional) export RISU=/path/to/risu
+#   ./run_risu.sh  ./testcases.aarch64/*.bin
+
+set -e
+
+passed=()
+failed=()
+missing=()
+
+if test -z "$RISU"; then
+    script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)
+    RISU=${script_dir}/risu
+fi
+
+for f in $@; do
+    t="$f.trace"
+    echo "Running $f against $t"
+    if [ -e $t ]; then
+        ${QEMU} ${RISU} $f -t $t
+        if [ $? == 0 ]; then
+            passed=( "${passed[@]}" $f )
+        else
+            failed=( "${failed[@]}" $f )
+        fi
+    else
+        missing=( "${missing[@]}" $f )
+    fi
+done
+
+if test ${#missing[@]} -gt 0; then
+    echo "Tests missing ${#missing[@]} trace files:"
+    for m in "${missing[@]}"; do
+        echo "$m"
+    done
+fi
+
+if test ${#passed[@]} -gt 0; then
+    echo "Passed ${#passed[@]} tests:"
+    for p in "${passed[@]}"; do
+        echo "$p"
+    done
+fi
+
+if test ${#failed[@]} -gt 0; then
+    echo "Failed ${#failed[@]} tests:"
+    for f in "${failed[@]}"; do
+        echo "$f"
+    done
+fi
+
+exit ${#failed[@]}
Signature · 1 line
2.13.0
#31 lore raw

Re: [Qemu-devel] [RISU PATCH v5 13/13] new: run_risu.sh script

run_risu.sh

Quoted 17 lines · Alex Bennée

A simple script to work through running all of a bunch of files with record/playback traces. Dumps a summary and the number of failed tests at the end.

---
v5
- author, license, usage header
v3
- tweak to allow specifying RISU binary

---
 run_risu.sh | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)
 create mode 100755 run_risu.sh
run_risu.sh +0 -0

I think this should go into contrib/.

thanks
-- PMM

#32 lore raw

Re: [Qemu-devel] [RISU PATCH v5 13/13] new: run_risu.sh script

Quoted 17 lines · Peter Maydell
Quoted 16 lines · Alex Bennée

A simple script to work through running all of a bunch of files with record/playback traces. Dumps a summary and the number of failed tests at the end.

---
v5
- author, license, usage header
v3
- tweak to allow specifying RISU binary

---
 run_risu.sh | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)
 create mode 100755 run_risu.sh
Quoted 3 lines

run_risu.sh

Quoted 1 line
run_risu.sh +0 -0

I think this should go into contrib/.

OK will do.

Quoted 3 lines

thanks
-- PMM

--
Alex Bennée