From patchwork Wed Jun 21 15:42:42 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: 106106 Delivered-To: patch@linaro.org Received: by 10.140.91.2 with SMTP id y2csp1996952qgd; Wed, 21 Jun 2017 08:48:32 -0700 (PDT) X-Received: by 10.237.61.153 with SMTP id i25mr10053314qtf.239.1498060112203; Wed, 21 Jun 2017 08:48:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1498060112; cv=none; d=google.com; s=arc-20160816; b=WahbL6MrXmbErDSEE9mKaC+jB/9zVl5nIhkH8O68rIdTmGQIb+Qy/4AiwybYqTj4fK iCuOgehuDFvML0Y6vaa3Vy0PWromvBmf+vOGDF4o9J01T97TWmFhsSSQF3ZrfkFAQ7BW qzsVrVKKFlIJJYjiqCCZux6Y3D4h7+MHQiwRg/vvqCOX1FaM9sPh3u/F5xazxvLhKh8f HrvRkRtkZr5Y3SIs979IeD/hemuo5EjVk4JbENsqdYO2C5zGvGOyd45ej0W1fo9nCZbc j3rcGde7YhAlYtgxlDPo9NtXqSO6fSpcfs1YIAw2ic40XgoeaiSrUi1NyhY+klnkWfWA I1lw== 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=TRQ9xQL7UydABoEzt+l7InX1CtycIHDBFIhRZGNlsS0=; b=s/36DKURsRa9YeM8cPfLtNL2KmGijpjutghSK1p3g+9YIeB3GdtcpI3xqaiMcZppCK 9pyPkLiPNgY6dOc0LFr+VT5A/dzLtH7DDIsPCPPZe4iSdm+CRGUhSMDoyfS0D/FsjQ5s H9y6xQDQzgo0RBPeo9kGqQct40MAKBnnC5P6TcH19Ob2y+Sel0cvqwk1fkbgZj/6tIvF CSgKE159bmMiaNHUOc6uaibDwow1HROWZqYixYY3D9U37bClby0cdYMrBJ7YmtbRHaKk 6qhm1+tg7zs3P8i0jIFq4kRWOOixqX6mVDuIDoFAgy5L6wu9puKVo+u20yfkzZz38jgl v/6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.b=jujg+k2S; 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 v41si4453959qta.244.2017.06.21.08.48.31 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 21 Jun 2017 08:48:32 -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=jujg+k2S; 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]:54766 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dNhrp-0003ci-Ko for patch@linaro.org; Wed, 21 Jun 2017 11:48:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52536) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dNhlr-0006Ii-Te for qemu-devel@nongnu.org; Wed, 21 Jun 2017 11:42:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dNhlq-0002sX-CV for qemu-devel@nongnu.org; Wed, 21 Jun 2017 11:42:19 -0400 Received: from mail-wr0-x22d.google.com ([2a00:1450:400c:c0c::22d]:34189) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dNhlq-0002s8-2k for qemu-devel@nongnu.org; Wed, 21 Jun 2017 11:42:18 -0400 Received: by mail-wr0-x22d.google.com with SMTP id 77so140154192wrb.1 for ; Wed, 21 Jun 2017 08:42:17 -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=TRQ9xQL7UydABoEzt+l7InX1CtycIHDBFIhRZGNlsS0=; b=jujg+k2SXJdY/G6yl4CxEvawgjSBpYNil3XlKu0CwlSkqfLSRYz6qRA1prcVtA/ii3 XIgnMfZ12+q/Qa3M2Ss81Nn2g4dZLNgxUFo85F37dER5+z+1xNnoBDPiz138h28kXfiu GzmWzNsyBS9NKKvI5hG51pr6u5AKvrqBEs64A= 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=TRQ9xQL7UydABoEzt+l7InX1CtycIHDBFIhRZGNlsS0=; b=bN8sLXVDbbtzwHmKxKvlOWa1nIprAdYe3vMo+MJIlBOsa2xByIe5cWAn50gDVx70gu TbUjPyETLC3k8JYDnJPnEGmYAOs3mXQIC9vqBLKtSNJZyjmmQnO7Rb92Px0S48j11Nvh vNVfTwj8jVGJFibu+sCRREJKbVs4Q7Snkhrni/dLb7vzCtiqedwRe0hppVq/NXgOrpJM /VoAtnDQ96m1A5/8dtQkL2fpuup10twxvh1ntE3eFByjNqFEgy4+2cMidC5WHqZHFuur IHfm0cNoPmI7f9VZabJMZ+c67IfN0n/u/LEKjhbXkQ09ghDCXqHgWAvw38DpNcDdhZwm IUIA== X-Gm-Message-State: AKS2vOzS+LWbmYusHMFViZfk9rldqsDhYGQDdtz/kSBxwpQ6+scXuFL/ xOGmPcKzQJgAKAX2f8c8qQ== X-Received: by 10.223.151.155 with SMTP id s27mr12019460wrb.159.1498059736870; Wed, 21 Jun 2017 08:42:16 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id 201sm15986870wmr.4.2017.06.21.08.42.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Jun 2017 08:42:12 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 7C69D3E0F98; Wed, 21 Jun 2017 16:42:51 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Wed, 21 Jun 2017 16:42:42 +0100 Message-Id: <20170621154244.28309-9-alex.bennee@linaro.org> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170621154244.28309-1-alex.bennee@linaro.org> References: <20170621154244.28309-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 v6 08/10] 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 Reviewed-by: Peter Maydell -- 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 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 476475c..47e50ad 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 = STDOUT_FILENO; } 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 = STDIN_FILENO; } 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);