From: Alexander Graf <agraf@suse.de>
To: qemu-devel@nongnu.org
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
Date: Thu, 22 Jan 2015 15:01:38 +0100 [thread overview]
Message-ID: <1421935300-8579-3-git-send-email-agraf@suse.de> (raw)
In-Reply-To: <1421935300-8579-1-git-send-email-agraf@suse.de>
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 <agraf@suse.de>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
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);
--
1.7.12.4
next prev parent reply other threads:[~2015-01-22 14:01 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-22 14:01 [Qemu-devel] [PATCH v4 0/4] Migration Deciphering aid Alexander Graf
2015-01-22 14:01 ` [Qemu-devel] [PATCH v4 1/4] QJSON: Add JSON writer Alexander Graf
2015-01-22 14:01 ` Alexander Graf [this message]
2015-01-22 14:01 ` [Qemu-devel] [PATCH v4 3/4] migration: Append JSON description of migration stream Alexander Graf
2015-01-22 14:01 ` [Qemu-devel] [PATCH v4 4/4] Add migration stream analyzation script Alexander Graf
2015-02-04 9:35 ` Amit Shah
2015-02-04 10:24 ` [Qemu-devel] [PATCH v4 0/4] Migration Deciphering aid Amit Shah
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1421935300-8579-3-git-send-email-agraf@suse.de \
--to=agraf@suse.de \
--cc=afaerber@suse.de \
--cc=alex.bennee@linaro.org \
--cc=amit.shah@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.