From patchwork Fri Jun 2 16:08:46 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: 101291 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp480652qge; Fri, 2 Jun 2017 09:22:59 -0700 (PDT) X-Received: by 10.55.90.196 with SMTP id o187mr9007293qkb.113.1496420579223; Fri, 02 Jun 2017 09:22:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496420579; cv=none; d=google.com; s=arc-20160816; b=wukzaZOmmB5vQJcWAhtm5mhvJKua2E0k35DAViz84372r6RMSwW/iy9jlGchRFyvp0 K0gesxeM8DKyP7MV0It/c51Zp5YcrSFEjJb+nbuRayZfeX/gr3Xq4OwMiOSANkEXcQW1 WEPa4v5+KJuwZSSIHzzeDmW/1cqbqaJu3Rvz8MtcjrWENZmg4Dwqy9wa12leLl9KJKaI GDct4nnBL6jZK/HjB88+ASCEK8vaNoJlHLwkY8gDag/0QQiDIgReTgPdiHQI4sdiWVtq rTEb0nZy3/exLBHWb3Dtu+ZYmJI3YiUiNWoMQwY1u/URkoqlIHKtSfK8o9pIoOxcPJq4 Z+Sw== 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=aoDGsASb1Sn5DU/8OVTdKtYRk9ItiOqu9FWIY1Effxs=; b=PWUGZlXYtB64aKg/7S51Zt1yaNwfgDMQjHuloaho51sPXukEodz/jMtE1Sw6BmHkxc +Vd6gAhML6yqNAvycosMvUycm5LJfQYQ/P81bApJupnGN6TaO9CISvmzhJGyfNWJ0RsN u08n71sqVu+OwGUXMDYaz9yd/KnYdSKC8RUVHyaoq69ernU2QSDw6WLvSvYIvncZdysL pJm/4ICv0cMOS4KJQ1nNZwSiH4L7xssp965vyJTX0jFUWNQDhaaG0B3dj5XSE1PtDnQc ZMeimoCKQAG7pNKQV1omxhc+/Ft57c0Sk/GaO1ALR9UYg4A1Ukwd19UeIhDa9ZZpFkEH DI6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org; 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 e126si23144393qkb.105.2017.06.02.09.22.58 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 02 Jun 2017 09:22:59 -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; 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]:50644 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGpLk-000213-ET for patch@linaro.org; Fri, 02 Jun 2017 12:22:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54485) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGp81-00062D-Dx for qemu-devel@nongnu.org; Fri, 02 Jun 2017 12:08:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGp80-000536-43 for qemu-devel@nongnu.org; Fri, 02 Jun 2017 12:08:45 -0400 Received: from mail-wr0-x230.google.com ([2a00:1450:400c:c0c::230]:34477) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGp7z-00052T-Q5 for qemu-devel@nongnu.org; Fri, 02 Jun 2017 12:08:44 -0400 Received: by mail-wr0-x230.google.com with SMTP id g76so9356778wrd.1 for ; Fri, 02 Jun 2017 09:08:43 -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=aoDGsASb1Sn5DU/8OVTdKtYRk9ItiOqu9FWIY1Effxs=; b=A42UanfzIrr/Tr/SdPlBh6aao4TB98YVh7DUH1VWnNdlGlGSakKgsYSMkkqLAgIjfK N/D1+XjY4FVqOCIJ+Iu0Alc5v6JOHYI+w9J/pa79a43N8toL6VLB3cWhDMoy3Uj1Dphk UeO/vsZPM3ZpAM1hKE5HLLMogTfoK4D1ZXvjI= 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=aoDGsASb1Sn5DU/8OVTdKtYRk9ItiOqu9FWIY1Effxs=; b=Td4NbWMBYXIexs7UMcnKsC8m5/cpFgUt3emqAeNntMDSfX4colhIOZWpZg12oKQwK1 DzShlzA3+50axIvnZRXvd02kvyo9xWlcBUfM5Q/3PxZYBJpidGW+LZj5dgmWBraOz9gB xv8ZwLyFI4c1/g9DymNTwYquZ1NP5ESFBGFoFYep1kcEnqGKrdbgBLVrg2GKSSxyO/jV K4h5ZbP+rdrjVF7bErlAfOtasaNnWByOPmzWTOWaVkbka6x+/bKWGUAKHCD3n6YSbgTl wBBC/gN9jDN2fcUrd4qovz0tGMAM3tIYl1Hnu4lrJQMpRxD/B0cogm8QVaZ/5CelkynB 2Tew== X-Gm-Message-State: AODbwcAZft3zy7dPXGg0UmciFzstI+kEuYu0LG6YMe6QcwbdgceA/z9F sn5pLbLHRJdbRh/l X-Received: by 10.223.169.83 with SMTP id u77mr597010wrc.13.1496419722813; Fri, 02 Jun 2017 09:08:42 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id y6sm27577949wrc.51.2017.06.02.09.08.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Jun 2017 09:08:39 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id B51A93E0449; Fri, 2 Jun 2017 17:08:54 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Fri, 2 Jun 2017 17:08:46 +0100 Message-Id: <20170602160848.4913-9-alex.bennee@linaro.org> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170602160848.4913-1-alex.bennee@linaro.org> References: <20170602160848.4913-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::230 Subject: [Qemu-devel] [RISU PATCH v4 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 -- 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 | 30 +++++++++++++++++++++++++++--- 3 files changed, 82 insertions(+), 7 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 137cbbf..275c5a9 100644 --- a/risu.c +++ b/risu.c @@ -26,6 +26,8 @@ #include #include +#include "config.h" + #include "risu.h" void *memblock = 0; @@ -33,6 +35,11 @@ void *memblock = 0; int apprentice_socket, master_socket; int trace_file = 0; +#ifdef HAVE_ZLIB +#include +gzFile gz_trace_file; +#endif + sigjmp_buf jmpbuf; /* Should we test for FP exception status bits? */ @@ -59,7 +66,11 @@ int read_sock(void *ptr, size_t bytes) int write_trace(void *ptr, size_t bytes) { +#ifdef HAVE_ZLIB + size_t res = gzwrite(gz_trace_file, ptr, bytes); +#else size_t res = write(trace_file, ptr, bytes); +#endif return (res == bytes) ? 0 : 1; } @@ -77,7 +88,11 @@ int write_sock(void *ptr, size_t bytes) int read_trace(void *ptr, size_t bytes) { +#ifdef HAVE_ZLIB + size_t res = gzread(gz_trace_file, ptr, bytes); +#else size_t res = read(trace_file, ptr, bytes); +#endif return (res == bytes) ? 0 : 1; } @@ -202,9 +217,12 @@ int master(int sock) { if (sigsetjmp(jmpbuf, 1)) { - if (trace_file) { - close(trace_file); - fprintf(stderr,"\nDone...\n"); + if (trace_file) + { +#ifdef HAVE_ZLIB + gzclose(gz_trace_file); +#endif + fprintf(stderr,"Done...\n"); return 0; } else { return report_match_status(); @@ -320,6 +338,9 @@ int main(int argc, char **argv) if (trace_fn) { trace_file = open(trace_fn, O_WRONLY|O_CREAT, S_IRWXU); +#ifdef HAVE_ZLIB + gz_trace_file = gzdopen(trace_file, "wb9"); +#endif } else { fprintf(stderr, "master port %d\n", port); sock = master_connect(port); @@ -331,6 +352,9 @@ int main(int argc, char **argv) if (trace_fn) { trace_file = open(trace_fn, O_RDONLY); +#ifdef HAVE_ZLIB + gz_trace_file = gzdopen(trace_file, "rb"); +#endif } else { fprintf(stderr, "apprentice host %s port %d\n", hostname, port); sock = apprentice_connect(hostname, port);