From patchwork Mon Jun 19 10:46:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 105826 Delivered-To: patch@linaro.org Received: by 10.140.91.2 with SMTP id y2csp811662qgd; Mon, 19 Jun 2017 03:54:55 -0700 (PDT) X-Received: by 10.31.172.88 with SMTP id v85mr9443245vke.57.1497869695478; Mon, 19 Jun 2017 03:54:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497869695; cv=none; d=google.com; s=arc-20160816; b=pqI1gT4/NfeT0VpVE6i2BzqG9M1BwMZCxLVjsdW64aBGbFusOE2Quioupcb/kJyStu HnWOk/27EziQNVsvaC6VSPJrIWhghmwY7V6pZDLQG6S3NVhxM8g+eHBIg2A/TzB6TIru WLNmg+rBTvfAK2fn4xjIIVQCVZJNrWfWSAS+0ulp7mZrh/PIXqpehAs95YHfCr+lA8pr vHHQEDapfb44tOjBXnFUfn0bVaH2Y3RBbe6ycG6AvElo+rx7wIqhIUh+/ZHyJKCXbZK1 5zRqo6Nr5bexoJsFIoI5w0V4FyV9oCxKYmJSEc8UetYk0/JaPi97LekbtWGCCkT3gbQJ PByQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=DGEbXD9mMXbBGln9tuuvpUF13T88QmXb9vdOIGA4H+c=; b=domTNYabps57NRCeD3/Dd1RxUldulL1aAAwb+VTgpOxdn/fvNJXOmBmAmPCJjx/bNw T0iZgH1DwNA/ngEqyk6p8Cnw5mh0AUxFKW2xTifQ3ASIZhNPHrjPldsyyFEZXU3idXlD /X8sP2CQN5HBDLH1T72xMbE3xEpSPNIcyEu/hI47Zq8R8hUSKV6uheCCJpkUL7dy8g/S 7tkiB35YF62kvvRFbRqaNewAJ3l+BJDcHMull9yZOFbNmomPPonh6HycSOVhC51UJESl FI3fCxvC9UlZV50hqvEfMG6ziTvb16WYYOksMeEBfeawEZX6Mfid5ADf2qwTEYfd3PMj 7sHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.b=D7XXAbks; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id j70si4405349vki.192.2017.06.19.03.54.55 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 19 Jun 2017 03:54:55 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.b=D7XXAbks; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:41683 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dMuKc-0006Hm-VA for patch@linaro.org; Mon, 19 Jun 2017 06:54:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42838) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dMuIT-0004TO-K7 for qemu-devel@nongnu.org; Mon, 19 Jun 2017 06:52:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dMuIS-0000NX-0k for qemu-devel@nongnu.org; Mon, 19 Jun 2017 06:52:41 -0400 Received: from mail-wr0-x22d.google.com ([2a00:1450:400c:c0c::22d]:33903) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dMuIR-0000Mh-N2 for qemu-devel@nongnu.org; Mon, 19 Jun 2017 06:52:39 -0400 Received: by mail-wr0-x22d.google.com with SMTP id 77so69584091wrb.1 for ; Mon, 19 Jun 2017 03:52:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DGEbXD9mMXbBGln9tuuvpUF13T88QmXb9vdOIGA4H+c=; b=D7XXAbksIPAFUN+tRpS9Rcj+w2Hee5k84EmxB+acVsvZP2PVcIGBh6EIIQ3pfG59pI H7rPOhDST17qf7z+vUNRkj2uEfmJt8mK45ADUnptCuk8RNJ3aGpj5zHEaUqhojFPJwSm YwA+T7mND89xMOLJz7xjtvgAPCxhjgZS1/QMg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DGEbXD9mMXbBGln9tuuvpUF13T88QmXb9vdOIGA4H+c=; b=MoWE1+ixeAr6Kq0k9THidOf0mxMUtzZ6IDCIx6q7oIyvlFnpchvoeq6QwP74IczwZy aEUQEfSrxv2DP5sT2w00d8XpCV6d7z87tGMoHtrVWI/30i307YK4Za8aCsLZZMh8MV7C mdxxYzJSpfBQBu6RiaRD7sRCHmJOkIlZBtzEIKiqurxugQpuSUg8mgBG5Ygu+KDGPovw vFyQRAxBjJHfNkkRK2x2ZY+7jjgy+9AfQVh4w2GStzE1SXRa/utR8aR45FF1r/5VGhIl wXhD8o5m9+1ikgSVO+hSK/E6gREHaVQl0HsV7Z1r65NRh5hkdSvQN6gQ9CY/uZtqnZmb RalA== X-Gm-Message-State: AKS2vOxw2KAqk5qB9iP/VSSAJLJIJTo0+qeEb64y406nOnzKT9PL6Vv1 ZeLohSiIBIGNF76hx8i87Q== X-Received: by 10.223.128.200 with SMTP id 66mr14333710wrl.99.1497869558181; Mon, 19 Jun 2017 03:52:38 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id a99sm16483319wrc.64.2017.06.19.03.52.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Jun 2017 03:52:37 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 873E63E0C96; Mon, 19 Jun 2017 11:47:00 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Mon, 19 Jun 2017 11:46:53 +0100 Message-Id: <20170619104655.31104-12-alex.bennee@linaro.org> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170619104655.31104-1-alex.bennee@linaro.org> References: <20170619104655.31104-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::22d Subject: [Qemu-devel] [RISU PATCH v5 11/13] risu: add support compressed tracefiles X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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. Signed-off-by: Alex Bennée -- 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(-) -- 2.13.0 Reviewed-by: Peter Maydell diff --git a/Makefile b/Makefile index 9a29bb4..ca80eef 100644 --- a/Makefile +++ b/Makefile @@ -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 $^ > $@ diff --git a/configure b/configure index c4b5adb..1dc527b 100755 --- a/configure +++ b/configure @@ -32,6 +32,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 +} + check_define() { c=${tmp_dir}/check_define_${1} cat > ${c}.c < ${c}.c < +#include +#include +#include + +int main(void) { $1 thisone; return 0; } +EOF + compile $c +} + +check_lib() { + c=${tmp_dir}/check_lib${1} + cat > ${c}.c < +#include <$2.h> + +int main(void) { $3; return 0; } +EOF + compile $c && link $c $1 +} + +generate_config() { + cfg=config.h + echo "generating config.h..." + + echo "/* config.h - generated by the 'configure' script */" > $cfg + echo "#ifndef CONFIG_H" >> $cfg + echo "#define CONFIG_H 1" >> $cfg + + if check_lib z zlib "zlibVersion()"; then + echo "#define HAVE_ZLIB 1" >> $cfg + LDFLAGS=-lz + fi + + echo "#endif /* CONFIG_H */" >> $cfg + + echo "...done" +} + generate_makefilein() { m=Makefile.in echo "generating Makefile.in..." @@ -65,11 +111,13 @@ generate_makefilein() { echo "# Makefile.in - generated by the 'configure' script" > $m echo "ARCH:=${ARCH}" >> $m echo "CC:=${CC}" >> $m + echo "LDFLAGS:=${LDFLAGS}" >> $m echo "AS:=${AS}" >> $m echo "OBJCOPY:=${OBJCOPY}" >> $m echo "OBJDUMP:=${OBJDUMP}" >> $m echo "STATIC:=${STATIC}" >> $m echo "SRCDIR:=${SRCDIR}" >> $m + echo "BUILD_INC:=${BUILD_INC}" >> $m echo "...done" } @@ -118,6 +166,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}" @@ -125,15 +174,17 @@ if test "x${ARCH}" = "x"; then guess_arch fi -generate_makefilein - # Are we in a separate build tree? If so, link the Makefile # so that 'make' works. if test ! -e Makefile; then echo "linking Makefile..." + BUILD_INC="-I $(pwd)" ln -s "${SRCDIR}/Makefile" . fi +generate_config +generate_makefilein + rm -r "$tmp_dir" echo "type 'make' to start the build" diff --git a/risu.c b/risu.c index e94b54b..6986e4c 100644 --- a/risu.c +++ b/risu.c @@ -26,6 +26,8 @@ #include #include +#include "config.h" + #include "risu.h" void *memblock; @@ -34,6 +36,11 @@ int apprentice_fd, master_fd; int trace; size_t signal_count; +#ifdef HAVE_ZLIB +#include +gzFile gz_trace_file; +#endif + sigjmp_buf jmpbuf; /* Should we test for FP exception status bits? */ @@ -48,7 +55,17 @@ int read_sock(void *ptr, size_t bytes) int write_trace(void *ptr, size_t bytes) { - size_t res = write(master_fd, ptr, bytes); + size_t res; + +#ifdef HAVE_ZLIB + if (master_fd == STDOUT_FILENO) { +#endif + res = write(master_fd, ptr, bytes); +#ifdef HAVE_ZLIB + } else { + res = gzwrite(gz_trace_file, ptr, bytes); + } +#endif return (res == bytes) ? 0 : 1; } @@ -66,7 +83,18 @@ int write_sock(void *ptr, size_t bytes) int read_trace(void *ptr, size_t bytes) { - size_t res = read(apprentice_fd, ptr, bytes); + size_t res; + +#ifdef HAVE_ZLIB + if (apprentice_fd == STDIN_FILENO) { +#endif + res = read(apprentice_fd, ptr, bytes); +#ifdef HAVE_ZLIB + } else { + res = gzread(gz_trace_file, ptr, bytes); + } +#endif + return (res == bytes) ? 0 : 1; } @@ -189,6 +217,11 @@ void load_image(const char *imgfile) int master(void) { if (sigsetjmp(jmpbuf, 1)) { +#ifdef HAVE_ZLIB + if (trace && master_fd != STDOUT_FILENO) { + gzclose(gz_trace_file); + } +#endif close(master_fd); if (trace) { fprintf(stderr, "trace complete after %zd checkpoints\n", signal_count); @@ -209,6 +242,11 @@ int master(void) int apprentice(void) { if (sigsetjmp(jmpbuf, 1)) { +#ifdef HAVE_ZLIB + if (trace && apprentice_fd != STDIN_FILENO) { + gzclose(gz_trace_file); + } +#endif close(apprentice_fd); fprintf(stderr, "finished early after %zd checkpoints\n", signal_count); return report_match_status(); @@ -316,6 +354,9 @@ int main(int argc, char **argv) master_fd = fileno(stdout); } else { master_fd = open(trace_fn, O_WRONLY|O_CREAT, S_IRWXU); +#ifdef HAVE_ZLIB + gz_trace_file = gzdopen(master_fd, "wb9"); +#endif } } else { fprintf(stderr, "master port %d\n", port); @@ -328,6 +369,9 @@ int main(int argc, char **argv) apprentice_fd = fileno(stdin); } else { apprentice_fd = open(trace_fn, O_RDONLY); +#ifdef HAVE_ZLIB + gz_trace_file = gzdopen(apprentice_fd, "rb"); +#endif } } else { fprintf(stderr, "apprentice host %s port %d\n", hostname, port);