From: John Snow <jsnow@redhat.com>
To: qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, John Snow <jsnow@redhat.com>, afaerber@suse.de
Subject: [Qemu-devel] [PATCH v3 4/5] qtest: precompute hex nibs
Date: Tue, 5 May 2015 18:22:57 -0400 [thread overview]
Message-ID: <1430864578-22072-5-git-send-email-jsnow@redhat.com> (raw)
In-Reply-To: <1430864578-22072-1-git-send-email-jsnow@redhat.com>
Instead of letting printf and friends do this for us
one byte at a time, fill a buffer ourselves and then
send the entire buffer in one go.
This gives a moderate speed improvement over the old
method.
Signed-off-by: John Snow <jsnow@redhat.com>
---
qtest.c | 20 ++++++++++++++++----
tests/libqtest.c | 17 ++++++++++++++---
2 files changed, 30 insertions(+), 7 deletions(-)
diff --git a/qtest.c b/qtest.c
index c1a0493..383f9ed 100644
--- a/qtest.c
+++ b/qtest.c
@@ -157,6 +157,8 @@ static bool qtest_opened;
* NUM=0 even though it is remapped to GSI 2).
*/
+static const char *hex = "0123456789abcdef";
+
static int hex2nib(char ch)
{
if (ch >= '0' && ch <= '9') {
@@ -170,6 +172,12 @@ static int hex2nib(char ch)
}
}
+static inline void byte2hex(uint8_t byte, uint8_t *out)
+{
+ *out++ = hex[byte >> 4];
+ *out = hex[byte & 0x0F];
+}
+
static void qtest_get_time(qemu_timeval *tv)
{
qemu_gettimeofday(tv);
@@ -414,6 +422,7 @@ static void qtest_process_command(CharDriverState *chr, gchar **words)
} else if (strcmp(words[0], "read") == 0) {
uint64_t addr, len, i;
uint8_t *data;
+ uint8_t *enc;
g_assert(words[1] && words[2]);
addr = strtoull(words[1], NULL, 0);
@@ -422,14 +431,17 @@ static void qtest_process_command(CharDriverState *chr, gchar **words)
data = g_malloc(len);
cpu_physical_memory_read(addr, data, len);
- qtest_send_prefix(chr);
- qtest_send(chr, "OK 0x");
+ enc = g_malloc(2 * len + 1);
for (i = 0; i < len; i++) {
- qtest_sendf(chr, "%02x", data[i]);
+ byte2hex(data[i], &enc[i * 2]);
}
- qtest_send(chr, "\n");
+ enc[2 * len] = '\0';
+
+ qtest_send_prefix(chr);
+ qtest_sendf(chr, "OK 0x%s\n", enc);
g_free(data);
+ g_free(enc);
} else if (strcmp(words[0], "b64read") == 0) {
uint64_t addr, len;
uint8_t *data;
diff --git a/tests/libqtest.c b/tests/libqtest.c
index 055aad6..1b246c9 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -651,6 +651,8 @@ uint64_t qtest_readq(QTestState *s, uint64_t addr)
return qtest_read(s, "readq", addr);
}
+static const char *hex = "0123456789abcdef";
+
static int hex2nib(char ch)
{
if (ch >= '0' && ch <= '9') {
@@ -664,6 +666,12 @@ static int hex2nib(char ch)
}
}
+static inline void byte2hex(uint8_t byte, uint8_t *out)
+{
+ *out++ = hex[byte >> 4];
+ *out = hex[byte & 0x0f];
+}
+
void qtest_memread(QTestState *s, uint64_t addr, void *data, size_t size)
{
uint8_t *ptr = data;
@@ -730,13 +738,16 @@ void qtest_memwrite(QTestState *s, uint64_t addr, const void *data, size_t size)
{
const uint8_t *ptr = data;
size_t i;
+ uint8_t *enc = g_malloc(2 * size + 1);
- qtest_sendf(s, "write 0x%" PRIx64 " 0x%zx 0x", addr, size);
for (i = 0; i < size; i++) {
- qtest_sendf(s, "%02x", ptr[i]);
+ byte2hex(ptr[i], &enc[i * 2]);
}
- qtest_sendf(s, "\n");
+ enc[2 * size] = '\0';
+
+ qtest_sendf(s, "write 0x%" PRIx64 " 0x%zx 0x%s\n", addr, size, enc);
qtest_rsp(s, 0);
+ g_free(enc);
}
void qtest_memset(QTestState *s, uint64_t addr, uint8_t pattern, size_t size)
--
2.1.0
next prev parent reply other threads:[~2015-05-05 22:23 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-05 22:22 [Qemu-devel] [PATCH v3 0/5] qtest: base64 r/w and faster memset John Snow
2015-05-05 22:22 ` [Qemu-devel] [PATCH v3 1/5] qtest: allow arbitrarily long sends John Snow
2015-05-05 23:22 ` Eric Blake
2015-05-05 23:35 ` John Snow
2015-05-05 22:22 ` [Qemu-devel] [PATCH v3 2/5] qtest: Add base64 encoded read/write John Snow
2015-05-05 22:22 ` [Qemu-devel] [PATCH v3 3/5] qtest: add memset to qtest protocol John Snow
2015-05-05 22:22 ` John Snow [this message]
2015-05-06 6:25 ` [Qemu-devel] [PATCH v3 4/5] qtest: precompute hex nibs Markus Armbruster
2015-05-06 14:12 ` John Snow
2015-05-06 15:19 ` Markus Armbruster
2015-05-06 16:18 ` John Snow
2015-05-07 6:13 ` Markus Armbruster
2015-05-07 17:52 ` John Snow
2015-05-07 20:27 ` Eric Blake
2015-05-08 6:25 ` Markus Armbruster
2015-05-08 16:22 ` John Snow
2015-05-08 19:47 ` Eric Blake
2015-05-05 22:22 ` [Qemu-devel] [PATCH v3 5/5] libqos/ahci: Swap memread/write with bufread/write John Snow
2015-05-06 14:56 ` [Qemu-devel] [PATCH v3 0/5] qtest: base64 r/w and faster memset Paolo Bonzini
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=1430864578-22072-5-git-send-email-jsnow@redhat.com \
--to=jsnow@redhat.com \
--cc=afaerber@suse.de \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).