Skip to contentSkip to conversation

Record/payback patches

PATCH Applied Alex Bennée 3 participants 20 messages Dec 9, 2016 – Dec 23, 2016 Kbuild

lore
Share & tools
lore
#0 lore raw

v3 cover Record/payback patches

Hi,

I did a bunch of tweaking to see if I could abstract the hackage for record/replay a bit more. With a little bit of light re-factoring of the send and recv functions I can move all the specific send/recv logic into the main risu.c file and avoid having copy and pasted functions for each architecture.

I've also introduced a header which makes tracking where you are in the recorded stream a little easier when debugging.

It should be noted the functions:

  int send_register_info(write_fn write_fn, void *uc);
  int recv_and_compare_register_info(read_fn read_fn, respond_fn respond, void *uc);

are pretty identical for each arch. I did consider folding even more of the logic into the common code but I wasn't sure if that would loose flexibility in the future for other architectures so I left it as is.

I've make the same changes to ppc64 although I've been compiling and testing under a qemu linux-user environment which might explain why I'm seeing crashes when I try and run it. I would appreciate the PPC guys trying it on real hardware and debugging if needed.

For reference I'm using a linux-user powered docker image (built with the debian-bootstrap recipe in the qemu.git tree) for cross compiling:

  docker run --rm -it -v /home/alex/lsrc/qemu/risu.git:/src --user=alex:alex -w /src debian:ppc64el make

There have been some minor clean-ups to the helper scripts mainly to aid testing by allowing the override of the RISU binary (I have risu-arm, risu-arm64 and risu-ppc64 in my development directory). Notes in the --- comments on each patch.

Alex Bennée (10):
risu: a bit more verbosity when running
aarch64: add hand-coded risu skeleton for directed testing
risu: paramterise send/receive functions
risu: add simple trace and replay support
risu: add support compressed tracefiles
risu_aarch64: it's -> it is
risugen: remove grocer's apostrophe from REs
new: generate_all.sh script
new: record_traces.sh helper script
new: run_risu.sh script

 Makefile                      |  10 +-
 aarch64_simd_handcoded.risu.S | 208 ++++++++++++++++++++++++++++++++++++++++++
 configure                     |  55 +++++++++++
 generate_all.sh               |  55 +++++++++++
 record_traces.sh              |  20 ++++
 risu.c                        | 139 ++++++++++++++++++++++++----
 risu.h                        |  14 ++-
 risu_aarch64.c                | 119 +++++++++++++++---------
 risu_arm.c                    | 148 +++++++++++++++++++-----------
 risu_ppc64le.c                | 127 ++++++++++++++++----------
 risu_reginfo_aarch64.h        |   7 ++
 risu_reginfo_arm.h            |   6 ++
 risu_reginfo_ppc64le.h        |   6 ++
 risugen                       |   2 +-
 run_risu.sh                   |  53 +++++++++++
 15 files changed, 805 insertions(+), 164 deletions(-)
 create mode 100644 aarch64_simd_handcoded.risu.S
 create mode 100755 generate_all.sh
 create mode 100755 record_traces.sh
 create mode 100755 run_risu.sh
Signature · 1 line
2.11.0
#1 lore raw

PATCH v3 1/10 risu: a bit more verbosity when running

Before this is could seem a little quite when running as you had no indication stuff was happening (or how fast). I only dump on the master side as I want to minimise the amount of qemu logs to sift through.

--
v3
- use portable fmt string for image_start_address
- include arm dumping position

---
 risu.c         | 15 +++++++++++++--
 risu.h         |  3 +++
 risu_aarch64.c |  3 +++
 risu_arm.c     |  3 +++
 4 files changed, 22 insertions(+), 2 deletions(-)
risu.c +13 -2
index 7e42160..bcdc219 100644
@@ -37,6 +37,16 @@ sigjmp_buf jmpbuf;
 /* Should we test for FP exception status bits? */
 int test_fp_exc = 0;
 
+long executed_tests = 0;
+void report_test_status(void *pc)
+{
+   executed_tests += 1;
+   if (executed_tests % 100 == 0) {
+      fprintf(stderr,"Executed %ld test instructions (pc=%p)\r",
+              executed_tests, pc);
+   }
+}
+
 void master_sigill(int sig, siginfo_t *si, void *uc)
 {
    switch (recv_and_compare_register_info(master_socket, uc))
@@ -61,6 +71,7 @@ void apprentice_sigill(int sig, siginfo_t *si, void *uc)
          return;
       case 1:
          /* end of test */
+         fprintf(stderr, "\nend of test\n");
          exit(0);
       default:
          /* mismatch */
@@ -129,7 +140,7 @@ int master(int sock)
    }
    master_socket = sock;
    set_sigill_handler(&master_sigill);
-   fprintf(stderr, "starting image\n");
+   fprintf(stderr, "starting master image at 0x%"PRIxPTR"\n", image_start_address);
    image_start();
    fprintf(stderr, "image returned unexpectedly\n");
    exit(1);
@@ -139,7 +150,7 @@ int apprentice(int sock)
 {
    apprentice_socket = sock;
    set_sigill_handler(&apprentice_sigill);
-   fprintf(stderr, "starting image\n");
+   fprintf(stderr, "starting apprentice image at 0x%"PRIxPTR"\n", image_start_address);
    image_start();
    fprintf(stderr, "image returned unexpectedly\n");
    exit(1);
risu.h +3 -0
index 26ed834..e4bb323 100644
@@ -26,6 +26,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
@@ -59,6 +60,8 @@ int recv_and_compare_register_info(int sock, void *uc);
  */
 int report_match_status(void);
 
+void report_test_status(void *pc);
+
 /* Move the PC past this faulting insn by adjusting ucontext
  */
 void advance_pc(void *uc);
risu_aarch64.c +3 -0
index 547f987..1595604 100644
@@ -28,6 +28,9 @@ void advance_pc(void *vuc)
 {
     ucontext_t *uc = vuc;
     uc->uc_mcontext.pc += 4;
+    if (ismaster) {
+      report_test_status((void *) uc->uc_mcontext.pc);
+    }
 }
 
 static void set_x0(void *vuc, uint64_t x0)
risu_arm.c +3 -0
index bdfb59b..c3fe3d3 100644
@@ -50,6 +50,9 @@ void advance_pc(void *vuc)
 {
    ucontext_t *uc = vuc;
    uc->uc_mcontext.arm_pc += insnsize(uc);
+   if (ismaster) {
+      report_test_status((void *) uc->uc_mcontext.arm_pc);
+   }
 }
 
 static void set_r0(void *vuc, uint32_t r0)
Signature · 1 line
2.11.0
#2 lore raw

Re: [Qemu-devel] [RISU PATCH v3 01/10] risu: a bit more verbosity when running

Quoted 3 lines · Alex Bennée

Before this is could seem a little quite when running as you had no indication stuff was happening (or how fast). I only dump on the master side as I want to minimise the amount of qemu logs to sift through.

Yeah, more progress info would be good. (I used to have a patchset that made risu print '.' every so often but I dunno where that disappeared to.)

Quoted 19 lines

--
v3
- use portable fmt string for image_start_address
- include arm dumping position

---
 risu.c         | 15 +++++++++++++--
 risu.h         |  3 +++
 risu_aarch64.c |  3 +++
 risu_arm.c     |  3 +++
 4 files changed, 22 insertions(+), 2 deletions(-)
risu.c +0 -0
index 7e42160..bcdc219 100644
@@ -37,6 +37,16 @@ sigjmp_buf jmpbuf;
 /* Should we test for FP exception status bits? */

risu.c sigjmp_buf jmpbuf; · line 47

Quoted 10 lines
risu.c +8 -0
 int test_fp_exc = 0;
 
+long executed_tests = 0;
+void report_test_status(void *pc)
+{
+   executed_tests += 1;
+   if (executed_tests % 100 == 0) {
+      fprintf(stderr,"Executed %ld test instructions (pc=%p)\r",
+              executed_tests, pc);
+   }

I think this is too much info to be printing every 100 instructions, though. We should either just print '.'s or print info less often.

Also, you're inside a signal handler, so trying to use libc stdio is probably a bad idea. With '.' you can at least stick to write() which is OK inside signal handlers.

risu.c void apprentice_sigill(int sig, siginfo_t *si, void *uc) · line 75

Quoted 11 lines
risu.c +3 -0
+}
+
 void master_sigill(int sig, siginfo_t *si, void *uc)
 {
    switch (recv_and_compare_register_info(master_socket, uc))
@@ -61,6 +71,7 @@ void apprentice_sigill(int sig, siginfo_t *si, void *uc)
          return;
       case 1:
          /* end of test */
+         fprintf(stderr, "\nend of test\n");
          exit(0);

This is also inside a signal handler. (If that's too annoying you can do what master_sigill() does for this, and siglongjmp() out to somewhere more convenient.)

risu.c void apprentice_sigill(int sig, siginfo_t *si, void *uc) · line 77

Quoted 2 lines
risu.c +0 -0
       default:
          /* mismatch */

The default case is about to do 'exit(1);' -- should we print something there too?

Quoted 44 lines
risu.c +2 -2
@@ -129,7 +140,7 @@ int master(int sock)
    }
    master_socket = sock;
    set_sigill_handler(&master_sigill);
-   fprintf(stderr, "starting image\n");
+   fprintf(stderr, "starting master image at 0x%"PRIxPTR"\n", image_start_address);
    image_start();
    fprintf(stderr, "image returned unexpectedly\n");
    exit(1);
@@ -139,7 +150,7 @@ int apprentice(int sock)
 {
    apprentice_socket = sock;
    set_sigill_handler(&apprentice_sigill);
-   fprintf(stderr, "starting image\n");
+   fprintf(stderr, "starting apprentice image at 0x%"PRIxPTR"\n", image_start_address);
    image_start();
    fprintf(stderr, "image returned unexpectedly\n");
    exit(1);
risu.h +3 -0
index 26ed834..e4bb323 100644
@@ -26,6 +26,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
@@ -59,6 +60,8 @@ int recv_and_compare_register_info(int sock, void *uc);
  */
 int report_match_status(void);
 
+void report_test_status(void *pc);
+
 /* Move the PC past this faulting insn by adjusting ucontext
  */
 void advance_pc(void *uc);
risu_aarch64.c +0 -0
index 547f987..1595604 100644

risu_aarch64.c void advance_pc(void *vuc) · line 34

Quoted 7 lines
risu_aarch64.c +3 -0
@@ -28,6 +28,9 @@ void advance_pc(void *vuc)
 {
     ucontext_t *uc = vuc;
     uc->uc_mcontext.pc += 4;
+    if (ismaster) {
+      report_test_status((void *) uc->uc_mcontext.pc);
+    }
 }

I think it would be nicer to do the progress info directly from master_sigill()/apprentice_sigill(). That means that you don't have to change the advance_pc() function for every architecture, and you don't need a global for ismaster either, because you know by virtue of which function you were in. (If you're dead set on printing the guest PC we should add a uint64_t get_guest_pc(void *vuc) function for the progress info function to use, but I'd rather not bother.)

Quoted 16 lines
risu_aarch64.c +0 -0
 static void set_x0(void *vuc, uint64_t x0)
risu_arm.c +3 -1
index bdfb59b..c3fe3d3 100644
@@ -50,6 +50,9 @@ void advance_pc(void *vuc)
 {
    ucontext_t *uc = vuc;
    uc->uc_mcontext.arm_pc += insnsize(uc);
+   if (ismaster) {
+      report_test_status((void *) uc->uc_mcontext.arm_pc);
+   }
 }
 
 static void set_r0(void *vuc, uint32_t r0)
--
Quoted 1 line

2.11.0

thanks
-- PMM

#3 lore raw

PATCH v3 2/10 aarch64: add hand-coded risu skeleton for directed testing

In reply to Alex Bennée

Sometimes you want absolute control over your test set-up to feed explicit values into the test. This started as an experiment but might be useful for further developing tests.

---
 Makefile                      |   7 ++
 aarch64_simd_handcoded.risu.S | 208 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 215 insertions(+)
 create mode 100644 aarch64_simd_handcoded.risu.S
Makefile +7 -0
index bfa8cac..4202c35 100644
@@ -36,6 +36,13 @@ $(PROG): $(OBJS)
 %.risu.asm: %.risu.bin
 	${OBJDUMP} -b binary -m $(ARCH) -D $^ > $@
 
+# hand-coded tests
+%.risu.bin: %.risu.elf
+	$(OBJCOPY) -O binary $< $@
+
+%.risu.elf: %.risu.S
+	${AS} -o $@ $^
+
 %.o: %.c $(HDRS)
 	$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -c $<
 
aarch64_simd_handcoded.risu.S new file +208 -0

208 lines not on this page · raw message

Signature · 1 line
2.11.0
#4 lore raw

Re: [Qemu-devel] [RISU PATCH v3 02/10] aarch64: add hand-coded risu skeleton for directed testing

Quoted 5 lines · Alex Bennée

Sometimes you want absolute control over your test set-up to feed explicit values into the test. This started as an experiment but might be useful for further developing tests.

I really don't like this patch, I'm afraid. I'd rather not have it in the tree, because it implies that we expect that people might want to write (or contribute back to us) handcoded test cases. I don't think we should be encouraging that at all.

I only wrote the test_i386.s and test_arm.s originally because I hadn't yet written the risugen script and wanted to test the C code I'd written. Perhaps we should delete them now as being obsolete...

thanks
-- PMM

#5 lore raw

PATCH v3 3/10 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 work without hacking up the arch specific stuff.

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

---
v3
- new for v3
- arm, aarch64, ppc64

---
 risu.c                 |  23 +++++++-
 risu.h                 |  11 +++-
 risu_aarch64.c         | 115 ++++++++++++++++++++++++--------------
 risu_arm.c             | 147 +++++++++++++++++++++++++++++++------------------
 risu_ppc64le.c         | 127 ++++++++++++++++++++++++++----------------
 risu_reginfo_aarch64.h |   7 +++
 risu_reginfo_arm.h     |   6 ++
 risu_reginfo_ppc64le.h |   6 ++
 8 files changed, 295 insertions(+), 147 deletions(-)
risu.c +21 -2
index bcdc219..22571cd 100644
@@ -47,9 +47,28 @@ void report_test_status(void *pc)
    }
 }
 
+/* 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 */
@@ -63,7 +82,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 */
risu.h +9 -2
index e4bb323..b0178df 100644
@@ -40,17 +40,24 @@ extern int ismaster;
 
 /* Interface provided by CPU-specific code: */
 
+/* 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
risu_aarch64.c +74 -41

156 lines not on this page · raw message

risu_arm.c +92 -55

182 lines not on this page · raw message

risu_ppc64le.c +80 -47

156 lines not on this page · raw message

risu_reginfo_aarch64.h +7 -0
index 166b76c..db51cb2 100644
@@ -28,6 +28,13 @@ struct reginfo
     __uint128_t vregs[32];
 };
 
+typedef struct
+{
+    uint64_t pc;
+    uint32_t risu_op;
+} trace_header_t;
+
+
 /* initialize structure from a ucontext */
 void reginfo_init(struct reginfo *ri, ucontext_t *uc);
 
risu_reginfo_arm.h +6 -0
index 80c28c6..7e7e408 100644
@@ -23,6 +23,12 @@ struct reginfo
     uint32_t fpscr;
 };
 
+typedef struct
+{
+    uint32_t pc;
+    uint32_t risu_op;
+} trace_header_t;
+
 /* initialize a reginfo structure with data from uc */
 void reginfo_init(struct reginfo *ri, ucontext_t *uc);
 
risu_reginfo_ppc64le.h +6 -0
index abe6002..49b4938 100644
@@ -25,6 +25,12 @@ struct reginfo
     vrregset_t vrregs;
 };
 
+typedef struct
+{
+    uint64_t pc;
+    uint32_t risu_op;
+} trace_header_t;
+
 /* initialize structure from a ucontext */
 void reginfo_init(struct reginfo *ri, ucontext_t *uc);
 
Signature · 1 line
2.11.0
#6 lore raw

Re: [Qemu-devel] [RISU PATCH v3 03/10] risu: paramterise send/receive functions

On 9 December 2016 at 11:48, Alex Bennée <[email protected]> wrote:

("parameterise" in subject)

Quoted 7 lines

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 work without hacking up the arch specific stuff.

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

"also" tends to mean "I know this ought to be two patches really". Can I ask you to split it up? I don't want to be too picky for testing tool code, but this is a pretty big patch so I think it's worth doing.

Missing signed-off-by line.

Quoted 63 lines

---
v3
- new for v3
- arm, aarch64, ppc64

---
 risu.c                 |  23 +++++++-
 risu.h                 |  11 +++-
 risu_aarch64.c         | 115 ++++++++++++++++++++++++--------------
 risu_arm.c             | 147 +++++++++++++++++++++++++++++++------------------
 risu_ppc64le.c         | 127 ++++++++++++++++++++++++++----------------
 risu_reginfo_aarch64.h |   7 +++
 risu_reginfo_arm.h     |   6 ++
 risu_reginfo_ppc64le.h |   6 ++
 8 files changed, 295 insertions(+), 147 deletions(-)
risu.c +21 -2
index bcdc219..22571cd 100644
@@ -47,9 +47,28 @@ void report_test_status(void *pc)
    }
 }
 
+/* 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 */
@@ -63,7 +82,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 */
risu.h +0 -0
index e4bb323..b0178df 100644

risu.h extern int ismaster; · line 48

Quoted 9 lines
risu.h +6 -0
@@ -40,17 +40,24 @@ extern int ismaster;
 
 /* Interface provided by CPU-specific code: */
 
+/* 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);

I'm going to ask you to indulge a style preference:
typedefs for function pointers should be the type of the function:
typedef int write_fn(void *ptr, size_t bytes);

and then when you're dealing with it you use the '*', eg
int send_register_info(write_fn *writefn, void *uc);

I think it's clearer because it means the type name fits what it
is: a "write_fn" is a function, and a "write_fn *" is a pointer to a function.

Quoted 23 lines
risu_reginfo_aarch64.h +7 -0
index 166b76c..db51cb2 100644
@@ -28,6 +28,13 @@ struct reginfo
     __uint128_t vregs[32];
 };
 
+typedef struct
+{
+    uint64_t pc;
+    uint32_t risu_op;
+} trace_header_t;
+
+
 /* initialize structure from a ucontext */
 void reginfo_init(struct reginfo *ri, ucontext_t *uc);
 
risu_reginfo_arm.h +0 -0
index 80c28c6..7e7e408 100644

risu_reginfo_arm.h struct reginfo · line 30

Quoted 8 lines
risu_reginfo_arm.h +5 -0
@@ -23,6 +23,12 @@ struct reginfo
     uint32_t fpscr;
 };
 
+typedef struct
+{
+    uint32_t pc;
+    uint32_t risu_op;
+} trace_header_t;

Can we just transfer the PC as 64 bits on all architectures, so we don't need to define a struct for each one?

Quoted 22 lines
risu_reginfo_arm.h +1 -0
+
 /* initialize a reginfo structure with data from uc */
 void reginfo_init(struct reginfo *ri, ucontext_t *uc);
 
risu_reginfo_ppc64le.h +6 -1
index abe6002..49b4938 100644
@@ -25,6 +25,12 @@ struct reginfo
     vrregset_t vrregs;
 };
 
+typedef struct
+{
+    uint64_t pc;
+    uint32_t risu_op;
+} trace_header_t;
+
 /* initialize structure from a ucontext */
 void reginfo_init(struct reginfo *ri, ucontext_t *uc);
 
--
Quoted 1 line

2.11.0

thanks
-- PMM

#7 lore raw

PATCH v3 4/10 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.

---

v2
- moved read/write functions into main risu.c
- cleaned up formatting
- report more in apprentice --trace mode
v3
- fix options parsing
- re-factored so no need for copy & paste

---
 risu.c         | 108 +++++++++++++++++++++++++++++++++++++++++++++++----------
 risu_aarch64.c |   5 ++-
 risu_arm.c     |   4 +--
 3 files changed, 93 insertions(+), 24 deletions(-)
risu.c +90 -18
index 22571cd..173dd3c 100644
@@ -31,6 +31,7 @@
 void *memblock = 0;
 
 int apprentice_socket, master_socket;
+int trace_file = 0;
 
 sigjmp_buf jmpbuf;
 
@@ -40,10 +41,12 @@ int test_fp_exc = 0;
 long executed_tests = 0;
 void report_test_status(void *pc)
 {
-   executed_tests += 1;
-   if (executed_tests % 100 == 0) {
-      fprintf(stderr,"Executed %ld test instructions (pc=%p)\r",
-              executed_tests, pc);
+   if (ismaster || trace_file) {
+      executed_tests += 1;
+      if (executed_tests % 100 == 0) {
+         fprintf(stderr,"Executed %ld test instructions (pc=%p)\r",
+                 executed_tests, pc);
+      }
    }
 }
 
@@ -54,6 +57,12 @@ int read_sock(void *ptr, size_t bytes)
    return recv_data_pkt(master_socket, ptr, bytes);
 }
 
+int write_trace(void *ptr, size_t bytes)
+{
+   size_t res = write(trace_file, ptr, bytes);
+   return (res == bytes) ? 0 : 1;
+}
+
 void respond_sock(int r)
 {
    send_response_byte(master_socket, r);
@@ -66,26 +75,62 @@ int write_sock(void *ptr, size_t bytes)
    return send_data_pkt(apprentice_socket, ptr, bytes);
 }
 
+int read_trace(void *ptr, size_t bytes)
+{
+   size_t res = read(trace_file, 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:
+         fprintf(stderr,"%s: got response of %d\n", __func__, r);
+         break;
+   }
+}
+
 void master_sigill(int sig, siginfo_t *si, void *uc)
 {
-   switch (recv_and_compare_register_info(read_sock, respond_sock, uc))
+   int r;
+
+   if (trace_file) {
+      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 */
+         /* All OK */
          advance_pc(uc);
          return;
       default:
          /* mismatch, or end of test */
          siglongjmp(jmpbuf, 1);
+         /* never */
+         return;
    }
 }
 
 void apprentice_sigill(int sig, siginfo_t *si, void *uc)
 {
-   switch (send_register_info(write_sock, uc))
+   int r;
+
+   if (trace_file) {
+      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 */
+         /* All OK */
          advance_pc(uc);
          return;
       case 1:
@@ -94,6 +139,9 @@ void apprentice_sigill(int sig, siginfo_t *si, void *uc)
          exit(0);
       default:
          /* mismatch */
+         if (trace_file) {
+            report_match_status();
+         }
          exit(1);
    }
 }
@@ -155,7 +203,13 @@ int master(int sock)
 {
    if (sigsetjmp(jmpbuf, 1))
    {
-      return report_match_status();
+      if (trace_file) {
+         close(trace_file);
+         fprintf(stderr,"\nDone...\n");
+         return 0;
+      } else {
+         return report_match_status();
+      }
    }
    master_socket = sock;
    set_sigill_handler(&master_sigill);
@@ -184,6 +238,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");
    fprintf(stderr, "  -p, --port=PORT   Specify the port to connect to/listen on (default 9191)\n");
 }
@@ -194,6 +249,7 @@ int main(int argc, char **argv)
    uint16_t port = 9191;
    char *hostname = "localhost";
    char *imgfile;
+   char *trace_fn = NULL;
    int sock;
 
    // TODO clean this up later
@@ -204,13 +260,14 @@ int main(int argc, char **argv)
          {
             { "help", no_argument, 0, '?'},
             { "master", no_argument, &ismaster, 1 },
+            { "trace", required_argument, 0, 't' },
             { "host", required_argument, 0, 'h' },
             { "port", required_argument, 0, 'p' },
             { "test-fp-exc", no_argument, &test_fp_exc, 1 },
             { 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;
@@ -223,6 +280,11 @@ int main(int argc, char **argv)
             /* flag set by getopt_long, do nothing */
             break;
          }
+         case 't':
+         {
+           trace_fn = optarg;
+           break;
+         }
          case 'h':
          {
             hostname = optarg;
@@ -253,18 +315,28 @@ 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_fn)
+       {
+         trace_file = open(trace_fn, O_WRONLY|O_CREAT, S_IRWXU);
+       } else {
+         fprintf(stderr, "master port %d\n", port);
+         sock = master_connect(port);
+       }
+     return master(sock);
    }
    else
-   {
-      fprintf(stderr, "apprentice host %s port %d\n", hostname, port);
-      sock = apprentice_connect(hostname, port);
-      return apprentice(sock);
+     {
+     if (trace_fn)
+       {
+         trace_file = open(trace_fn, O_RDONLY);
+       } else {
+         fprintf(stderr, "apprentice host %s port %d\n", hostname, port);
+         sock = apprentice_connect(hostname, port);
+       }
+     return apprentice(sock);
    }
 }
 
risu_aarch64.c +2 -3
index c4c0d4d..7f9f612 100644
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <ucontext.h>
 #include <string.h>
+#include <unistd.h>
 
 #include "risu.h"
 #include "risu_reginfo_aarch64.h"
@@ -28,9 +29,7 @@ void advance_pc(void *vuc)
 {
     ucontext_t *uc = vuc;
     uc->uc_mcontext.pc += 4;
-    if (ismaster) {
-      report_test_status((void *) uc->uc_mcontext.pc);
-    }
+    report_test_status((void *) uc->uc_mcontext.pc);
 }
 
 static void set_x0(void *vuc, uint64_t x0)
risu_arm.c +1 -3
index 474729c..77bdcac 100644
@@ -50,9 +50,7 @@ void advance_pc(void *vuc)
 {
    ucontext_t *uc = vuc;
    uc->uc_mcontext.arm_pc += insnsize(uc);
-   if (ismaster) {
-      report_test_status((void *) uc->uc_mcontext.arm_pc);
-   }
+   report_test_status((void *) uc->uc_mcontext.arm_pc);
 }
 
 static void set_r0(void *vuc, uint32_t r0)
Signature · 1 line
2.11.0
#8 lore raw

Re: [Qemu-devel] [RISU PATCH v3 04/10] 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.

Most of this looks good.

Quoted 65 lines

---

v2
- moved read/write functions into main risu.c
- cleaned up formatting
- report more in apprentice --trace mode
v3
- fix options parsing
- re-factored so no need for copy & paste

---
 risu.c         | 108 +++++++++++++++++++++++++++++++++++++++++++++++----------
 risu_aarch64.c |   5 ++-
 risu_arm.c     |   4 +--
 3 files changed, 93 insertions(+), 24 deletions(-)
risu.c +17 -4
index 22571cd..173dd3c 100644
@@ -31,6 +31,7 @@
 void *memblock = 0;
 
 int apprentice_socket, master_socket;
+int trace_file = 0;
 
 sigjmp_buf jmpbuf;
 
@@ -40,10 +41,12 @@ int test_fp_exc = 0;
 long executed_tests = 0;
 void report_test_status(void *pc)
 {
-   executed_tests += 1;
-   if (executed_tests % 100 == 0) {
-      fprintf(stderr,"Executed %ld test instructions (pc=%p)\r",
-              executed_tests, pc);
+   if (ismaster || trace_file) {
+      executed_tests += 1;
+      if (executed_tests % 100 == 0) {
+         fprintf(stderr,"Executed %ld test instructions (pc=%p)\r",
+                 executed_tests, pc);
+      }
    }
 }
 
@@ -54,6 +57,12 @@ int read_sock(void *ptr, size_t bytes)
    return recv_data_pkt(master_socket, ptr, bytes);
 }
 
+int write_trace(void *ptr, size_t bytes)
+{
+   size_t res = write(trace_file, ptr, bytes);
+   return (res == bytes) ? 0 : 1;
+}
+
 void respond_sock(int r)
 {
    send_response_byte(master_socket, r);
@@ -66,26 +75,62 @@ int write_sock(void *ptr, size_t bytes)
    return send_data_pkt(apprentice_socket, ptr, bytes);
 }
 
+int read_trace(void *ptr, size_t bytes)
+{
+   size_t res = read(trace_file, ptr, bytes);
+   return (res == bytes) ? 0 : 1;

risu.c int write_sock(void *ptr, size_t bytes) · line 91

Quoted 10 lines
risu.c +10 -0
+}
+
+void respond_trace(int r)
+{
+   switch (r) {
+      case 0: /* test ok */
+      case 1: /* end of test */
+         break;
+      default:
+         fprintf(stderr,"%s: got response of %d\n", __func__, r);

Is this a "something is broken/can't happen" case?

Anyway, you're in a signal handler so shouldn't use fprintf.

Quoted 17 lines
risu.c +13 -1
+         break;
+   }
+}
+
 void master_sigill(int sig, siginfo_t *si, void *uc)
 {
-   switch (recv_and_compare_register_info(read_sock, respond_sock, uc))
+   int r;
+
+   if (trace_file) {
+      r = send_register_info(write_trace, uc);
+   } else {
+      r = recv_and_compare_register_info(read_sock, respond_sock, uc);
+   }
+
+   switch (r)
    {

risu.c int write_sock(void *ptr, size_t bytes) · line 116

Quoted 10 lines
risu.c +3 -1
       case 0:
-         /* match OK */
+         /* All OK */
          advance_pc(uc);
          return;
       default:
          /* mismatch, or end of test */
          siglongjmp(jmpbuf, 1);
+         /* never */
+         return;

Is your compiler complaining about this? You should probably get a better compiler (others will likely complain that the return is dead, because siglongjmp is marked 'noreturn' in the system headers).

Quoted 99 lines
risu.c +30 -5
    }
 }
 
 void apprentice_sigill(int sig, siginfo_t *si, void *uc)
 {
-   switch (send_register_info(write_sock, uc))
+   int r;
+
+   if (trace_file) {
+      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 */
+         /* All OK */
          advance_pc(uc);
          return;
       case 1:
@@ -94,6 +139,9 @@ void apprentice_sigill(int sig, siginfo_t *si, void *uc)
          exit(0);
       default:
          /* mismatch */
+         if (trace_file) {
+            report_match_status();
+         }
          exit(1);
    }
 }
@@ -155,7 +203,13 @@ int master(int sock)
 {
    if (sigsetjmp(jmpbuf, 1))
    {
-      return report_match_status();
+      if (trace_file) {
+         close(trace_file);
+         fprintf(stderr,"\nDone...\n");
+         return 0;
+      } else {
+         return report_match_status();
+      }
    }
    master_socket = sock;
    set_sigill_handler(&master_sigill);
@@ -184,6 +238,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");
    fprintf(stderr, "  -p, --port=PORT   Specify the port to connect to/listen on (default 9191)\n");
 }
@@ -194,6 +249,7 @@ int main(int argc, char **argv)
    uint16_t port = 9191;
    char *hostname = "localhost";
    char *imgfile;
+   char *trace_fn = NULL;
    int sock;
 
    // TODO clean this up later
@@ -204,13 +260,14 @@ int main(int argc, char **argv)
          {
             { "help", no_argument, 0, '?'},
             { "master", no_argument, &ismaster, 1 },
+            { "trace", required_argument, 0, 't' },
             { "host", required_argument, 0, 'h' },
             { "port", required_argument, 0, 'p' },
             { "test-fp-exc", no_argument, &test_fp_exc, 1 },
             { 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;
@@ -223,6 +280,11 @@ int main(int argc, char **argv)
             /* flag set by getopt_long, do nothing */
             break;
          }
+         case 't':
+         {
+           trace_fn = optarg;
+           break;
+         }
          case 'h':
          {
             hostname = optarg;
@@ -253,18 +315,28 @@ int main(int argc, char **argv)
    }
 
    load_image(imgfile);
-
+
    if (ismaster)
    {

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

Quoted 10 lines
risu.c +7 -3
-      fprintf(stderr, "master port %d\n", port);
-      sock = master_connect(port);
-      return master(sock);
+     if (trace_fn)
+       {
+         trace_file = open(trace_fn, O_WRONLY|O_CREAT, S_IRWXU);
+       } else {
+         fprintf(stderr, "master port %d\n", port);
+         sock = master_connect(port);
+       }

GNU coding standards indentation ? I know risu's indenting is a bit of a mess but we have not quite sunk that low yet :-)

Quoted 24 lines
risu.c +10 -4
+     return master(sock);
    }
    else
-   {
-      fprintf(stderr, "apprentice host %s port %d\n", hostname, port);
-      sock = apprentice_connect(hostname, port);
-      return apprentice(sock);
+     {
+     if (trace_fn)
+       {
+         trace_file = open(trace_fn, O_RDONLY);
+       } else {
+         fprintf(stderr, "apprentice host %s port %d\n", hostname, port);
+         sock = apprentice_connect(hostname, port);
+       }
+     return apprentice(sock);
    }
 }
 
risu_aarch64.c +0 -0
index c4c0d4d..7f9f612 100644

risu_aarch64.c line 16

Quoted 4 lines
risu_aarch64.c +1 -0
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <ucontext.h>
 #include <string.h>
+#include <unistd.h>

Why this include?

Quoted 19 lines
risu_aarch64.c +1 -3
 #include "risu.h"
 #include "risu_reginfo_aarch64.h"
@@ -28,9 +29,7 @@ void advance_pc(void *vuc)
 {
     ucontext_t *uc = vuc;
     uc->uc_mcontext.pc += 4;
-    if (ismaster) {
-      report_test_status((void *) uc->uc_mcontext.pc);
-    }
+    report_test_status((void *) uc->uc_mcontext.pc);
 }
 
 static void set_x0(void *vuc, uint64_t x0)
risu_arm.c +0 -0
index 474729c..77bdcac 100644

risu_arm.c void advance_pc(void *vuc) · line 54

Quoted 8 lines
risu_arm.c +1 -3
@@ -50,9 +50,7 @@ void advance_pc(void *vuc)
 {
    ucontext_t *uc = vuc;
    uc->uc_mcontext.arm_pc += insnsize(uc);
-   if (ismaster) {
-      report_test_status((void *) uc->uc_mcontext.arm_pc);
-   }
+   report_test_status((void *) uc->uc_mcontext.arm_pc);
 }

These bits should just vanish if you fix or drop the earlier patch that added report_test_status() calls here.

Quoted 4 lines
risu_arm.c +0 -1
 static void set_r0(void *vuc, uint32_t r0)
--

2.11.0

thanks
-- PMM

#9 lore raw

PATCH v3 5/10 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.

---
 Makefile  |  3 ++-
 configure | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 risu.c    | 15 ++++++++++-----
 3 files changed, 67 insertions(+), 6 deletions(-)
Makefile +2 -1
index 4202c35..4a2ef02 100644
@@ -14,6 +14,7 @@
 include Makefile.in
 
 CFLAGS ?= -g -Wall
+LDFLAGS += -lz
 
 PROG=risu
 SRCS=risu.c comms.c risu_$(ARCH).c risu_reginfo_$(ARCH).c
@@ -31,7 +32,7 @@ all: $(PROG) $(BINS)
 dump: $(RISU_ASMS)
 
 $(PROG): $(OBJS)
-	$(CC) $(STATIC) $(CFLAGS) -o $@ $^
+	$(CC) $(STATIC) $(CFLAGS) -o $@ $^ $(LDFLAGS) 
 
 %.risu.asm: %.risu.bin
 	${OBJDUMP} -b binary -m $(ARCH) -D $^ > $@
configure +55 -0

79 lines not on this page · raw message

risu.c +10 -5
index 173dd3c..3670bb1 100644
@@ -25,6 +25,7 @@
 #include <sys/mman.h>
 #include <fcntl.h>
 #include <string.h>
+#include <zlib.h>
 
 #include "risu.h"
 
@@ -32,6 +33,7 @@ void *memblock = 0;
 
 int apprentice_socket, master_socket;
 int trace_file = 0;
+gzFile gz_trace_file;
 
 sigjmp_buf jmpbuf;
 
@@ -59,7 +61,7 @@ int read_sock(void *ptr, size_t bytes)
 
 int write_trace(void *ptr, size_t bytes)
 {
-   size_t res = write(trace_file, ptr, bytes);
+   size_t res = gzwrite(gz_trace_file, ptr, bytes);
    return (res == bytes) ? 0 : 1;
 }
 
@@ -77,7 +79,7 @@ int write_sock(void *ptr, size_t bytes)
 
 int read_trace(void *ptr, size_t bytes)
 {
-   size_t res = read(trace_file, ptr, bytes);
+   size_t res = gzread(gz_trace_file, ptr, bytes);
    return (res == bytes) ? 0 : 1;
 }
 
@@ -203,9 +205,10 @@ int master(int sock)
 {
    if (sigsetjmp(jmpbuf, 1))
    {
-      if (trace_file) {
-         close(trace_file);
-         fprintf(stderr,"\nDone...\n");
+      if (trace_file)
+      {
+         gzclose(gz_trace_file);
+         fprintf(stderr,"Done...\n");
          return 0;
       } else {
          return report_match_status();
@@ -321,6 +324,7 @@ int main(int argc, char **argv)
      if (trace_fn)
        {
          trace_file = open(trace_fn, O_WRONLY|O_CREAT, S_IRWXU);
+         gz_trace_file = gzdopen(trace_file, "wb9");
        } else {
          fprintf(stderr, "master port %d\n", port);
          sock = master_connect(port);
@@ -332,6 +336,7 @@ int main(int argc, char **argv)
      if (trace_fn)
        {
          trace_file = open(trace_fn, O_RDONLY);
+         gz_trace_file = gzdopen(trace_file, "rb");
        } else {
          fprintf(stderr, "apprentice host %s port %d\n", hostname, port);
          sock = apprentice_connect(hostname, port);
Signature · 1 line
2.11.0
#10 lore raw

Re: [Qemu-devel] [RISU PATCH v3 05/10] risu: add support compressed tracefiles

Quoted 24 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.

---
 Makefile  |  3 ++-
 configure | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 risu.c    | 15 ++++++++++-----
 3 files changed, 67 insertions(+), 6 deletions(-)
Makefile +1 -0
index 4202c35..4a2ef02 100644
@@ -14,6 +14,7 @@
 include Makefile.in
 
 CFLAGS ?= -g -Wall
+LDFLAGS += -lz
 
 PROG=risu
 SRCS=risu.c comms.c risu_$(ARCH).c risu_reginfo_$(ARCH).c

Makefile all: $(PROG) $(BINS) · line 35

Quoted 5 lines
Makefile +1 -1
@@ -31,7 +32,7 @@ all: $(PROG) $(BINS)
 dump: $(RISU_ASMS)
 
 $(PROG): $(OBJS)
-       $(CC) $(STATIC) $(CFLAGS) -o $@ $^
+       $(CC) $(STATIC) $(CFLAGS) -o $@ $^ $(LDFLAGS)

(I think there's a stray space at the end of this line.)

Quoted 8 lines
Makefile +0 -0
 %.risu.asm: %.risu.bin
        ${OBJDUMP} -b binary -m $(ARCH) -D $^ > $@
configure +0 -0
index f81bdb5..d11680f 100755

configure compile() { · line 11

Quoted 6 lines
configure +3 -0
@@ -6,6 +6,10 @@ compile() {
     $CC $CFLAGS -c -o ${1}.o ${1}.c 2>/dev/null
 }
 
+link() {
+    $LD $LDFLAGS -l${2} -o ${1} ${1}.o 2>/dev/null
+}

I would ask you to get the shell quoting right, but I see we don't do that in the existing configure code, so never mind.

Quoted 36 lines
configure +29 -0
+
 check_define() {
     c=${tmp_dir}/check_define_${1}
     cat > ${c}.c <<EOF
@@ -34,6 +38,50 @@ guess_arch() {
     fi
 }
 
+check_type() {
+    c=${tmp_dir}/check_type_${1}
+    cat > ${c}.c <<EOF
+#include <inttypes.h>
+#include <stdint.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+
+int main(void) { $1 thisone; return 0; }
+EOF
+    compile $c
+}
+
+check_lib() {
+    c=${tmp_dir}/check_lib${1}
+    cat > ${c}.c <<EOF
+#include <stdint.h>
+#include <$2.h>
+
+int main(void) { $3; return 0; }
+EOF
+    compile $c && link $c $1
+}
+
+generate_config() {
+    cfg=config.h
+    echo "generating config.h..."
+

configure guess_arch() { · line 78

Quoted 10 lines
configure +10 -0
+    echo "/* config.h - generated by the 'configure' script */" > $cfg
+    echo "#ifndef CONFIG_H" >> $cfg
+    echo "#define CONFIG_H 1" >> $cfg
+
+    if check_type uintptr_t ; then
+        echo "#define HAVE_UINTPTR_T 1" >> $cfg
+    fi
+    if check_type socklen_t ; then
+        echo "#define HAVE_SOCKLEN_T 1" >> $cfg
+    fi

In what circumstances would we not have uintptr_t and socklen_t types? We know we're building for Linux, after all.

Quoted 99 lines
configure +13 -0
+
+    echo "#endif /* CONFIG_H */" >> $cfg
+
+    echo "...done"
+}
+
 generate_makefilein() {
     m=Makefile.in
     echo "generating Makefile.in..."
@@ -93,6 +141,7 @@ done
 
 CC="${CC-${CROSS_PREFIX}gcc}"
 AS="${AS-${CROSS_PREFIX}as}"
+LD="${LD-${CROSS_PREFIX}ld}"
 OBJCOPY="${OBJCOPY-${CROSS_PREFIX}objcopy}"
 OBJDUMP="${OBJDUMP-${CROSS_PREFIX}objdump}"
 
@@ -100,6 +149,12 @@ if test "x${ARCH}" = "x"; then
     guess_arch
 fi
 
+if ! check_lib z zlib "zlibVersion()"; then
+    echo "Cannot find libz compression library"
+    exit 1
+fi
+
+generate_config
 generate_makefilein
 
 echo "type 'make' to start the build"
risu.c +10 -6
index 173dd3c..3670bb1 100644
@@ -25,6 +25,7 @@
 #include <sys/mman.h>
 #include <fcntl.h>
 #include <string.h>
+#include <zlib.h>
 
 #include "risu.h"
 
@@ -32,6 +33,7 @@ void *memblock = 0;
 
 int apprentice_socket, master_socket;
 int trace_file = 0;
+gzFile gz_trace_file;
 
 sigjmp_buf jmpbuf;
 
@@ -59,7 +61,7 @@ int read_sock(void *ptr, size_t bytes)
 
 int write_trace(void *ptr, size_t bytes)
 {
-   size_t res = write(trace_file, ptr, bytes);
+   size_t res = gzwrite(gz_trace_file, ptr, bytes);
    return (res == bytes) ? 0 : 1;
 }
 
@@ -77,7 +79,7 @@ int write_sock(void *ptr, size_t bytes)
 
 int read_trace(void *ptr, size_t bytes)
 {
-   size_t res = read(trace_file, ptr, bytes);
+   size_t res = gzread(gz_trace_file, ptr, bytes);
    return (res == bytes) ? 0 : 1;
 }
 
@@ -203,9 +205,10 @@ int master(int sock)
 {
    if (sigsetjmp(jmpbuf, 1))
    {
-      if (trace_file) {
-         close(trace_file);
-         fprintf(stderr,"\nDone...\n");
+      if (trace_file)
+      {
+         gzclose(gz_trace_file);
+         fprintf(stderr,"Done...\n");
          return 0;
       } else {
          return report_match_status();
@@ -321,6 +324,7 @@ int main(int argc, char **argv)
      if (trace_fn)
        {
          trace_file = open(trace_fn, O_WRONLY|O_CREAT, S_IRWXU);
+         gz_trace_file = gzdopen(trace_file, "wb9");
        } else {
          fprintf(stderr, "master port %d\n", port);
          sock = master_connect(port);
@@ -332,6 +336,7 @@ int main(int argc, char **argv)
      if (trace_fn)
        {
          trace_file = open(trace_fn, O_RDONLY);
+         gz_trace_file = gzdopen(trace_file, "rb");
        } else {
          fprintf(stderr, "apprentice host %s port %d\n", hostname, port);
          sock = apprentice_connect(hostname, port);
--
Quoted 1 line

2.11.0

Changes to the C code are fine.

thanks
-- PMM

#11 lore raw

PATCH v3 6/10 risu_aarch64: it's -> it is

In reply to Alex Bennée
---
 risu_aarch64.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
risu_aarch64.c +1 -1
index 7f9f612..8e3539e 100644
@@ -97,7 +97,7 @@ int send_register_info(write_fn write_fn, void *uc)
  * NB: called from a signal handler.
  *
  * We don't have any kind of identifying info in the incoming data
- * that says whether it's register or memory data, so if the two
+ * 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(read_fn read_fn, respond_fn resp_fn, void *uc)
Signature · 1 line
2.11.0
#12 lore raw

Re: [Qemu-devel] [RISU PATCH v3 06/10] risu_aarch64: it's -> it is

Quoted 10 lines · Alex Bennée
---
 risu_aarch64.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
risu_aarch64.c +0 -0
index 7f9f612..8e3539e 100644

risu_aarch64.c int send_register_info(write_fn write_fn, void *uc) · line 103

Quoted 8 lines
risu_aarch64.c +1 -1
@@ -97,7 +97,7 @@ int send_register_info(write_fn write_fn, void *uc)
  * NB: called from a signal handler.
  *
  * We don't have any kind of identifying info in the incoming data
- * that says whether it's register or memory data, so if the two
+ * 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(read_fn read_fn, respond_fn resp_fn, void *uc)

Applied to risu master, thanks.

-- PMM

#13 lore raw

PATCH v3 7/10 risugen: remove grocer's apostrophe from REs

In reply to Alex Bennée

This also fixes perl-modes confusion about escaped strings.

---
 risugen | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
risugen +1 -1
index a604fe5..77a550b 100755
@@ -288,7 +288,7 @@ Valid options:
                    'VMULL' will match 'VMULL A1' and 'VMULL A2' but not
                    'VMULL_scalar A1'. This is generally what you wanted.
     --not-pattern re[,re...] : exclude patterns matching regular expression.
-                   These RE's are applied after the matching pattern which
+                   These REs are applied after the matching pattern which
                    is useful if you want to exclude a specific instruction from
                    a general set you have excluded.
      --no-fp      : disable floating point: no fp init, randomization etc.
Signature · 1 line
2.11.0
#14 lore raw

Re: [Qemu-devel] [RISU PATCH v3 07/10] risugen: remove grocer's apostrophe from REs

Quoted 1 line · Alex Bennée

This also fixes perl-modes confusion about escaped strings.

Missing apostrophe: should be "perl-mode's" :-)

Quoted 2 lines

Applied to risu master with that fixed; thanks.

-- PMM

Quoted 20 lines
---
 risugen | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
risugen +1 -2
index a604fe5..77a550b 100755
@@ -288,7 +288,7 @@ Valid options:
                    'VMULL' will match 'VMULL A1' and 'VMULL A2' but not
                    'VMULL_scalar A1'. This is generally what you wanted.
     --not-pattern re[,re...] : exclude patterns matching regular expression.
-                   These RE's are applied after the matching pattern which
+                   These REs are applied after the matching pattern which
                    is useful if you want to exclude a specific instruction from
                    a general set you have excluded.
      --no-fp      : disable floating point: no fp init, randomization etc.
--

2.11.0

#15 lore raw

PATCH v3 8/10 new: generate_all.sh script

In reply to Alex Bennée

A simple script to cut up a full .risu file and generate binaries for the whole set. Call with risu file and instruction count and directory:

./generate_all.sh aarch64.risu 4 20000 testcases.aarch64

---
 generate_all.sh | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)
 create mode 100755 generate_all.sh
generate_all.sh new file +55 -0
new file mode 100755
index 0000000..4c490be
@@ -0,0 +1,55 @@
+#!/bin/sh
+#
+# Generate All Patterns
+#
+# Work through a given .risu file and generate full coverage
+#
+
+BASE_SHELL_PARAMS="./risugen"
+
+risufile=$1
+divisor=$2
+insns=$3
+dir=$4
+
+if test -z "$risufile"; then
+    echo "Need to specify a risu defintiion file"
+    exit 1
+fi
+
+if test -z "$divisor"; then
+    divisor=4
+fi
+
+if test -n "$insns"; then
+    BASE_SHELL_PARAMS="${BASE_SHELL_PARAMS} --numinsns $insns"
+fi
+
+if test -n "dir"; then
+    mkdir -p $dir
+else
+    dir="./"
+fi
+
+ALL_INSNS=$(cat $risufile | ag "^\w" | cut -f 1 -d " " | sort)
+COUNT=$(cat $risufile | ag "^\w" | cut -f 1 -d " " | wc -l)
+set -- $ALL_INSNS
+
+GROUP=$((COUNT / $divisor))
+
+while test $# -gt 0 ; do
+    INSN_PATTERNS=""
+    I_FILE="$dir/insn_"
+    for i in `seq 1 $divisor`; do
+        I=$1
+        if test -n "${I}"; then
+            shift
+            INSN_PATTERNS="${INSN_PATTERNS} --pattern ${I}"
+            I_FILE="${I_FILE}${I}_"
+        fi
+    done
+    I_FILE="${I_FILE}_INC.risu.bin"
+    CMD="$BASE_SHELL_PARAMS ${INSN_PATTERNS} $risufile ${I_FILE}"
+    echo "Running: $CMD"
+    $CMD
+done
Signature · 1 line
2.11.0
#16 lore raw

PATCH v3 9/10 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.

---
v3
- allow overriding of RISU binary

---
 record_traces.sh | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100755 record_traces.sh
record_traces.sh new file +20 -0
new file mode 100755
index 0000000..78ce47f
@@ -0,0 +1,20 @@
+#!/bin/sh
+#
+# Record traces
+#
+# A risu helper script to batch process a bunch of binaries and record their outputs
+#
+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.11.0
#17 lore raw

PATCH v3 10/10 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.

---
v3
- tweak to allow specifying RISU binary

---
 run_risu.sh | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100755 run_risu.sh
run_risu.sh new file +53 -0
new file mode 100755
index 0000000..7740d6f
@@ -0,0 +1,53 @@
+#!/bin/bash
+#
+# Run risu against a set of binaries + trace files
+#
+#
+#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.11.0
#18 lore raw
In reply to Alex Bennée
Quoted 27 lines · Alex Bennée

I did a bunch of tweaking to see if I could abstract the hackage for record/replay a bit more. With a little bit of light re-factoring of the send and recv functions I can move all the specific send/recv logic into the main risu.c file and avoid having copy and pasted functions for each architecture.

I've also introduced a header which makes tracking where you are in the recorded stream a little easier when debugging.

It should be noted the functions:

  int send_register_info(write_fn write_fn, void *uc);
  int recv_and_compare_register_info(read_fn read_fn, respond_fn respond, void *uc);

are pretty identical for each arch. I did consider folding even more of the logic into the common code but I wasn't sure if that would loose flexibility in the future for other architectures so I left it as is.

I've make the same changes to ppc64 although I've been compiling and testing under a qemu linux-user environment which might explain why I'm seeing crashes when I try and run it. I would appreciate the PPC guys trying it on real hardware and debugging if needed.

For reference I'm using a linux-user powered docker image (built with the debian-bootstrap recipe in the qemu.git tree) for cross compiling:

Quoted 6 lines
  docker run --rm -it -v /home/alex/lsrc/qemu/risu.git:/src --user=alex:alex -w /src debian:ppc64el make

There have been some minor clean-ups to the helper scripts mainly to aid testing by allowing the override of the RISU binary (I have risu-arm, risu-arm64 and risu-ppc64 in my development directory). Notes in the --- comments on each patch.

This generally looks good -- I've applied the two trivial typo fixes, and commented on the other patches except for the new scripts. I don't think there's much more work to do to get these applied.

Could we have a patch which updates README to document the new functionality?

I won't have a chance to look at the scripts until next year, I expect, but from a quick glance they seem to be reasonably separate from the actual record/replay implementation.

thanks
-- PMM

#19 lore raw
In reply to Alex Bennée
Quoted 21 lines · Alex Bennée

Hi,

I did a bunch of tweaking to see if I could abstract the hackage for record/replay a bit more. With a little bit of light re-factoring of the send and recv functions I can move all the specific send/recv logic into the main risu.c file and avoid having copy and pasted functions for each architecture.

I've also introduced a header which makes tracking where you are in the recorded stream a little easier when debugging.

It should be noted the functions:

  int send_register_info(write_fn write_fn, void *uc);
  int recv_and_compare_register_info(read_fn read_fn, respond_fn respond, void *uc);

are pretty identical for each arch. I did consider folding even more of the logic into the common code but I wasn't sure if that would loose flexibility in the future for other architectures so I left it as is.

Quoted 4 lines

I've make the same changes to ppc64 although I've been compiling and testing under a qemu linux-user environment which might explain why I'm seeing crashes when I try and run it. I would appreciate the PPC guys trying it on real hardware and debugging if needed.

Sure, I'm starting working on it. I'll try the real hardware, softmmu, and linux-user. I have an idea about what leads to the crash (already have a fix for it). As soon as I have your feature working for ppc I'll send the patches here.

Thanks Alex!

Quoted 47 lines

For reference I'm using a linux-user powered docker image (built with the debian-bootstrap recipe in the qemu.git tree) for cross compiling:

  docker run --rm -it -v /home/alex/lsrc/qemu/risu.git:/src --user=alex:alex -w /src debian:ppc64el make

There have been some minor clean-ups to the helper scripts mainly to aid testing by allowing the override of the RISU binary (I have risu-arm, risu-arm64 and risu-ppc64 in my development directory). Notes in the --- comments on each patch.

Alex Bennée (10):
risu: a bit more verbosity when running
aarch64: add hand-coded risu skeleton for directed testing
risu: paramterise send/receive functions
risu: add simple trace and replay support
risu: add support compressed tracefiles
risu_aarch64: it's -> it is
risugen: remove grocer's apostrophe from REs
new: generate_all.sh script
new: record_traces.sh helper script
new: run_risu.sh script

 Makefile                      |  10 +-
 aarch64_simd_handcoded.risu.S | 208 ++++++++++++++++++++++++++++++++++++++++++
 configure                     |  55 +++++++++++
 generate_all.sh               |  55 +++++++++++
 record_traces.sh              |  20 ++++
 risu.c                        | 139 ++++++++++++++++++++++++----
 risu.h                        |  14 ++-
 risu_aarch64.c                | 119 +++++++++++++++---------
 risu_arm.c                    | 148 +++++++++++++++++++-----------
 risu_ppc64le.c                | 127 ++++++++++++++++----------
 risu_reginfo_aarch64.h        |   7 ++
 risu_reginfo_arm.h            |   6 ++
 risu_reginfo_ppc64le.h        |   6 ++
 risugen                       |   2 +-
 run_risu.sh                   |  53 +++++++++++
 15 files changed, 805 insertions(+), 164 deletions(-)
 create mode 100644 aarch64_simd_handcoded.risu.S
 create mode 100755 generate_all.sh
 create mode 100755 record_traces.sh
 create mode 100755 run_risu.sh
Signature · 1 line
2.11.0