From patchwork Thu Jan 22 14:01:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 431820 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id D0CE014028F for ; Fri, 23 Jan 2015 01:02:28 +1100 (AEDT) Received: from localhost ([::1]:53425 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YEIL5-0001gF-2z for incoming@patchwork.ozlabs.org; Thu, 22 Jan 2015 09:02:27 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32799) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YEIKR-0000hU-MW for qemu-devel@nongnu.org; Thu, 22 Jan 2015 09:01:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YEIKN-00017B-Iy for qemu-devel@nongnu.org; Thu, 22 Jan 2015 09:01:47 -0500 Received: from cantor2.suse.de ([195.135.220.15]:39668 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YEIKN-00016w-CS for qemu-devel@nongnu.org; Thu, 22 Jan 2015 09:01:43 -0500 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 1C5CEACB0; Thu, 22 Jan 2015 14:01:41 +0000 (UTC) From: Alexander Graf To: qemu-devel@nongnu.org Date: Thu, 22 Jan 2015 15:01:38 +0100 Message-Id: <1421935300-8579-3-git-send-email-agraf@suse.de> X-Mailer: git-send-email 1.7.12.4 In-Reply-To: <1421935300-8579-1-git-send-email-agraf@suse.de> References: <1421935300-8579-1-git-send-email-agraf@suse.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 195.135.220.15 Cc: quintela@redhat.com, amit.shah@redhat.com, pbonzini@redhat.com, alex.bennee@linaro.org, afaerber@suse.de Subject: [Qemu-devel] [PATCH v4 2/4] qemu-file: Add fast ftell code path X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org For ftell we flush the output buffer to ensure that we don't have anything lingering in our internal buffers. This is a very safe thing to do. However, with the dynamic size measurement that the dynamic vmstate description will bring this would turn out quite slow. Instead, we can fast path this specific measurement and just take the internal buffers into account when telling the kernel our position. I'm sure I overlooked some corner cases where this doesn't work, so instead of tuning the safe, existing version, this patch adds a fast variant of ftell that gets used by the dynamic vmstate description code which isn't critical when it fails. Signed-off-by: Alexander Graf Reviewed-by: Eric Blake --- v2 -> v3: - improve ftell_fast, now works with bdrv too --- include/migration/qemu-file.h | 1 + migration/qemu-file.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/migration/qemu-file.h b/include/migration/qemu-file.h index d843c00..a923cec 100644 --- a/include/migration/qemu-file.h +++ b/include/migration/qemu-file.h @@ -121,6 +121,7 @@ QEMUFile *qemu_bufopen(const char *mode, QEMUSizedBuffer *input); int qemu_get_fd(QEMUFile *f); int qemu_fclose(QEMUFile *f); int64_t qemu_ftell(QEMUFile *f); +int64_t qemu_ftell_fast(QEMUFile *f); void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size); void qemu_put_byte(QEMUFile *f, int v); /* diff --git a/migration/qemu-file.c b/migration/qemu-file.c index edc2830..e66e557 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -452,6 +452,22 @@ int qemu_get_byte(QEMUFile *f) return result; } +int64_t qemu_ftell_fast(QEMUFile *f) +{ + int64_t ret = f->pos; + int i; + + if (f->ops->writev_buffer) { + for (i = 0; i < f->iovcnt; i++) { + ret += f->iov[i].iov_len; + } + } else { + ret += f->buf_index; + } + + return ret; +} + int64_t qemu_ftell(QEMUFile *f) { qemu_fflush(f);