From nobody Wed Nov 5 13:57:38 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1498060166998751.3173521607879; Wed, 21 Jun 2017 08:49:26 -0700 (PDT) Received: from localhost ([::1]:54769 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dNhsi-0004FO-Hu for importer@patchew.org; Wed, 21 Jun 2017 11:49:24 -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) 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) 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) From: =?UTF-8?q?Alex=20Benn=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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=20Benn=C3=A9e?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 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=C3=A9e 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(-) diff --git a/Makefile b/Makefile index 9a29bb4..ca80eef 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ VPATH=3D$(SRCDIR) =20 CFLAGS ?=3D -g =20 -ALL_CFLAGS =3D -Wall -D_GNU_SOURCE -DARCH=3D$(ARCH) $(CFLAGS) $(EXTRA_CFLA= GS) +ALL_CFLAGS =3D -Wall -D_GNU_SOURCE -DARCH=3D$(ARCH) $(BUILD_INC) $(CFLAGS)= $(EXTRA_CFLAGS) =20 PROG=3Drisu SRCS=3Drisu.c comms.c reginfo.c risu_$(ARCH).c risu_reginfo_$(ARCH).c @@ -35,7 +35,7 @@ all: $(PROG) $(BINS) dump: $(RISU_ASMS) =20 $(PROG): $(OBJS) - $(CC) $(STATIC) $(ALL_CFLAGS) -o $@ $^ + $(CC) $(STATIC) $(ALL_CFLAGS) -o $@ $^ $(LDFLAGS) =20 %.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 } =20 +link() { + $LD $LDFLAGS -l${2} -o ${1} ${1}.o 2>/dev/null +} + check_define() { c=3D${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=3D${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=3Dconfig.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=3D-lz + fi + + echo "#endif /* CONFIG_H */" >> $cfg + + echo "...done" +} + generate_makefilein() { m=3DMakefile.in echo "generating Makefile.in..." @@ -65,11 +111,13 @@ generate_makefilein() { echo "# Makefile.in - generated by the 'configure' script" > $m echo "ARCH:=3D${ARCH}" >> $m echo "CC:=3D${CC}" >> $m + echo "LDFLAGS:=3D${LDFLAGS}" >> $m echo "AS:=3D${AS}" >> $m echo "OBJCOPY:=3D${OBJCOPY}" >> $m echo "OBJDUMP:=3D${OBJDUMP}" >> $m echo "STATIC:=3D${STATIC}" >> $m echo "SRCDIR:=3D${SRCDIR}" >> $m + echo "BUILD_INC:=3D${BUILD_INC}" >> $m =20 echo "...done" } @@ -118,6 +166,7 @@ done =20 CC=3D"${CC-${CROSS_PREFIX}gcc}" AS=3D"${AS-${CROSS_PREFIX}as}" +LD=3D"${LD-${CROSS_PREFIX}ld}" OBJCOPY=3D"${OBJCOPY-${CROSS_PREFIX}objcopy}" OBJDUMP=3D"${OBJDUMP-${CROSS_PREFIX}objdump}" =20 @@ -125,15 +174,17 @@ if test "x${ARCH}" =3D "x"; then guess_arch fi =20 -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=3D"-I $(pwd)" ln -s "${SRCDIR}/Makefile" . fi =20 +generate_config +generate_makefilein + rm -r "$tmp_dir" =20 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 =20 +#include "config.h" + #include "risu.h" =20 void *memblock; @@ -34,6 +36,11 @@ int apprentice_fd, master_fd; int trace; size_t signal_count; =20 +#ifdef HAVE_ZLIB +#include +gzFile gz_trace_file; +#endif + sigjmp_buf jmpbuf; =20 /* Should we test for FP exception status bits? */ @@ -48,7 +55,17 @@ int read_sock(void *ptr, size_t bytes) =20 int write_trace(void *ptr, size_t bytes) { - size_t res =3D write(master_fd, ptr, bytes); + size_t res; + +#ifdef HAVE_ZLIB + if (master_fd =3D=3D STDOUT_FILENO) { +#endif + res =3D write(master_fd, ptr, bytes); +#ifdef HAVE_ZLIB + } else { + res =3D gzwrite(gz_trace_file, ptr, bytes); + } +#endif return (res =3D=3D bytes) ? 0 : 1; } =20 @@ -66,7 +83,18 @@ int write_sock(void *ptr, size_t bytes) =20 int read_trace(void *ptr, size_t bytes) { - size_t res =3D read(apprentice_fd, ptr, bytes); + size_t res; + +#ifdef HAVE_ZLIB + if (apprentice_fd =3D=3D STDIN_FILENO) { +#endif + res =3D read(apprentice_fd, ptr, bytes); +#ifdef HAVE_ZLIB + } else { + res =3D gzread(gz_trace_file, ptr, bytes); + } +#endif + return (res =3D=3D bytes) ? 0 : 1; } =20 @@ -189,6 +217,11 @@ void load_image(const char *imgfile) int master(void) { if (sigsetjmp(jmpbuf, 1)) { +#ifdef HAVE_ZLIB + if (trace && master_fd !=3D STDOUT_FILENO) { + gzclose(gz_trace_file); + } +#endif close(master_fd); if (trace) { fprintf(stderr, "trace complete after %zd checkpoints\n", sign= al_count); @@ -209,6 +242,11 @@ int master(void) int apprentice(void) { if (sigsetjmp(jmpbuf, 1)) { +#ifdef HAVE_ZLIB + if (trace && apprentice_fd !=3D STDIN_FILENO) { + gzclose(gz_trace_file); + } +#endif close(apprentice_fd); fprintf(stderr, "finished early after %zd checkpoints\n", signal_c= ount); return report_match_status(); @@ -316,6 +354,9 @@ int main(int argc, char **argv) master_fd =3D STDOUT_FILENO; } else { master_fd =3D open(trace_fn, O_WRONLY|O_CREAT, S_IRWXU); +#ifdef HAVE_ZLIB + gz_trace_file =3D 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 =3D STDIN_FILENO; } else { apprentice_fd =3D open(trace_fn, O_RDONLY); +#ifdef HAVE_ZLIB + gz_trace_file =3D gzdopen(apprentice_fd, "rb"); +#endif } } else { fprintf(stderr, "apprentice host %s port %d\n", hostname, port= ); --=20 2.13.0