Record/playback patches
cover Record/playback patches
Hi Peter,
I've been cleaning things up so I thought I should re-post my current state. These all apply to the current master.
I had to regenerate all the risu binaries as I'd used --no-fp for a bunch of them originally which was causing failures. I'm not sure if this is due to the FP registers not being cleared by the kernel if FP isn't used - but we certainly don't do anything to them except when set by the memory/context blocks (without --no-fp). This led me to write the 3 noddy scripts included here.
The record/playback is still aarch64 only. I'm open to ideas to do this more cleanly otherwise if anyone has access to some PPC hardware I can port the record/playback code to the other architectures.
Feel free to cherry-pick any of the minor patches as you wish ;-)
Alex Bennée (9):
risu: a bit more verbosity when running
aarch64: add hand-coded risu skeleton for directed testing
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 | 16 ++++ risu.c | 116 ++++++++++++++++++----- risu.h | 15 +++ risu_aarch64.c | 89 +++++++++++++++++- risu_reginfo_aarch64.h | 7 ++ risugen | 2 +- run_risu.sh | 51 +++++++++++ 11 files changed, 598 insertions(+), 26 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.10.2
PATCH 1/9 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.
--- risu.c | 15 +++++++++++++-- risu.h | 3 +++ risu_aarch64.c | 3 +++ 3 files changed, 19 insertions(+), 2 deletions(-)
risu.c +13 -2
@@ -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%lx\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%lx\n" , image_start_address);image_start ();fprintf (stderr,"image returned unexpectedly\n" );exit (1 );
risu.h +3 -0
@@ -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
@@ -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)
Signature · 1 line
2.10.2
PATCH 2/9 aarch64: add hand-coded risu skeleton for directed testing
In reply to Alex BennéeSometimes 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
@@ -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.10.2
PATCH 3/9 risu: add simple trace and replay support
In reply to Alex BennéeThis adds a very dumb and easily breakable trace and replay support to the aarch64 build of risu. 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.
There is an inevitable amount of copy&paste between the trace file and socket based code. Ideally it would be nice to have as much of this as common as possible and reduce the re-implementation between the various backends.
---
v2
- moved read/write functions into main risu.c
- cleaned up formatting
- report more in apprentice --trace mode
v3
- fix options parsing
--- risu.c | 104 +++++++++++++++++++++++++++++++++++++------------ risu.h | 12 ++++++ risu_aarch64.c | 90 ++++++++++++++++++++++++++++++++++++++++-- risu_reginfo_aarch64.h | 7 ++++ 4 files changed, 185 insertions(+), 28 deletions(-)
risu.c +79 -25
@@ -31,6 +31,7 @@void *memblock =0 ;int apprentice_socket, master_socket; +int trace_file =0 ;sigjmp_buf jmpbuf;
@@ -40,31 +41,57 @@ 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); + } } } +int write_trace (void *ptr,size_t bytes) +{ +size_t res =write (trace_file, ptr, bytes); +return res == bytes; +} + +int read_trace (void *ptr,size_t bytes) +{ +size_t res =read (trace_file, ptr, bytes); +return res == bytes; +} +void master_sigill (int sig,siginfo_t *si,void *uc) { -switch (recv_and_compare_register_info (master_socket, uc)) - { -case 0 : -/* match OK */ -advance_pc (uc); -return ; -default : -/* mismatch, or end of test */ -siglongjmp (jmpbuf,1 ); +if (trace_file) { +if (write_to_tracefile (write_trace, uc)!=0 ) { +/* end of test */ +siglongjmp (jmpbuf,1 ); +/* never */ +return ; + } + }else { +if (recv_and_compare_register_info (master_socket, uc)!=0 ) { +/* mismatch, or end of test */ +siglongjmp (jmpbuf,1 ); +/* never */ +return ; + } } +advance_pc (uc); }void apprentice_sigill (int sig,siginfo_t *si,void *uc) { -switch (send_register_info (apprentice_socket, uc)) - { +int resp; +if (trace_file) { + resp =read_tracefile_and_check (read_trace, uc); + }else { + resp =send_register_info (apprentice_socket, uc); + } +switch (resp) + {case 0 :/* match OK */ advance_pc (uc);
@@ -75,6 +102,9 @@ void apprentice_sigill(int sig, siginfo_t *si, void *uc)exit (0 );default :/* mismatch */ +if (trace_file) { +report_match_status (); + }exit (1 ); } }
@@ -136,7 +166,13 @@ int master(int sock) {if (sigsetjmp (jmpbuf,1 )) { -return report_match_status (); +if (trace_file) { +close (trace_file); +fprintf (stderr,"Done...\n" ); +return 0 ; + }else { +return report_match_status (); + } } master_socket = sock;set_sigill_handler (&master_sigill);
@@ -165,6 +201,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" ); }
@@ -175,6 +212,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
@@ -185,13 +223,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;
@@ -204,6 +243,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;
@@ -234,18 +278,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.h +12 -0
@@ -52,6 +52,18 @@ int send_register_info(int sock, void *uc);*/ int recv_and_compare_register_info (int sock,void *uc); +/* 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 (*trace_write_fn ) (void *ptr,size_t bytes); +typedef int (*trace_read_fn ) (void *ptr,size_t bytes); + +/* Write out to trace file */ +int write_to_tracefile (trace_write_fn write_fn,void *uc); + +/* Read from trace file and check */ +int read_tracefile_and_check (trace_read_fn read_fn,void * uc); +/* Print a useful report on the status of the last comparison * done in recv_and_compare_register_info(). This is called on * exit, so need not restrict itself to signal-safe functions.
risu_aarch64.c +87 -3
108 lines not on this page · raw message
risu_reginfo_aarch64.h +7 -0
@@ -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);
Signature · 1 line
2.10.2
PATCH 4/9 risu: add support compressed tracefiles
In reply to Alex BennéeThis 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 | 13 +++++++++---- 3 files changed, 66 insertions(+), 5 deletions(-)
Makefile +2 -1
@@ -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 +9 -4
@@ -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;
@@ -52,13 +54,13 @@ void report_test_status(void *pc)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; }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; }
@@ -166,8 +168,9 @@ int master(int sock) {if (sigsetjmp (jmpbuf,1 )) { -if (trace_file) { -close (trace_file); +if (trace_file) + { +gzclose (gz_trace_file);fprintf (stderr,"Done...\n" );return 0 ; }else {
@@ -284,6 +287,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);
@@ -295,6 +299,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.10.2
PATCH 5/9 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
@@ -82,7 +82,7 @@ int send_register_info(int sock, 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 (int sock,void *uc)
Signature · 1 line
2.10.2
PATCH 6/9 risugen: remove grocer's apostrophe from REs
In reply to Alex BennéeThis also fixes perl-modes confusion about escaped strings.
--- risugen | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
risugen +1 -1
@@ -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.10.2
PATCH 7/9 new: generate_all.sh script
In reply to Alex BennéeA 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
@@ -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.10.2
PATCH 8/9 new: record_traces.sh helper script
In reply to Alex BennéeA simple script to run through a bunch of binaries and generate their trace files.
--- record_traces.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100755 record_traces.sh
record_traces.sh new file +16 -0
@@ -0,0 +1,16 @@ +#!/bin/sh +# +# Record traces +# +# A risu helper script to batch process a bunch of binaries and record their outputs +# +set -e + + +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.10.2
PATCH 9/9 new: run_risu.sh script
In reply to Alex BennéeA 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.
--- run_risu.sh | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 run_risu.sh
run_risu.sh new file +51 -0
@@ -0,0 +1,51 @@ +#!/bin/bash +# +# Run risu against a set of binaries + trace files +# +# +#set -e + +passed=() +failed=() +missing=() + +script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P) +risu_path=${script_dir}/risu + +for f in $@; do + t="$f.trace" + echo "Running $f against $t" + if [ -e $t ]; then + ${QEMU} ${risu_path} $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.10.2
Quoted 12 lines · Alex Bennée
Hi Peter,
I've been cleaning things up so I thought I should re-post my current state. These all apply to the current master.
I had to regenerate all the risu binaries as I'd used --no-fp for a bunch of them originally which was causing failures. I'm not sure if this is due to the FP registers not being cleared by the kernel if FP isn't used - but we certainly don't do anything to them except when set by the memory/context blocks (without --no-fp). This led me to write the 3 noddy scripts included here.
Quoted 3 lines
The record/playback is still aarch64 only. I'm open to ideas to do this more cleanly otherwise if anyone has access to some PPC hardware I can port the record/playback code to the other architectures.
Excellent job, Alex
I can make the PPC port here. I still have work to do in Risu for PPC so I can include this in my task as well. I'm planning to start working on it this week.
Thank you
Quoted 34 lines
Feel free to cherry-pick any of the minor patches as you wish ;-)
Alex Bennée (9):
risu: a bit more verbosity when running
aarch64: add hand-coded risu skeleton for directed testing
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.shscript
new:record_traces.shhelper script
new:run_risu.shscriptMakefile | 10 +- aarch64_simd_handcoded.risu.S | 208 ++++++++++++++++++++++++++++++++++++++++++ configure | 55 +++++++++++ generate_all.sh | 55 +++++++++++ record_traces.sh | 16 ++++ risu.c | 116 ++++++++++++++++++----- risu.h | 15 +++ risu_aarch64.c | 89 +++++++++++++++++- risu_reginfo_aarch64.h | 7 ++ risugen | 2 +- run_risu.sh | 51 +++++++++++ 11 files changed, 598 insertions(+), 26 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.shSignature · 1 line
2.10.2