From patchwork Thu May 7 17:51:35 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 469752 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 5504C140283 for ; Fri, 8 May 2015 03:52:14 +1000 (AEST) Received: from localhost ([::1]:52364 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YqPxy-00028Z-9D for incoming@patchwork.ozlabs.org; Thu, 07 May 2015 13:52:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36983) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YqPxZ-0000ZE-7c for qemu-devel@nongnu.org; Thu, 07 May 2015 13:51:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YqPxT-0003Rl-71 for qemu-devel@nongnu.org; Thu, 07 May 2015 13:51:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37146) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YqPxS-0003RU-Uc for qemu-devel@nongnu.org; Thu, 07 May 2015 13:51:39 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t47Hpb75013693 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 7 May 2015 13:51:37 -0400 Received: from scv.usersys.redhat.com (vpn-62-103.rdu2.redhat.com [10.10.62.103]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t47Hpa0G019927; Thu, 7 May 2015 13:51:37 -0400 From: John Snow To: qemu-devel@nongnu.org Date: Thu, 7 May 2015 13:51:35 -0400 Message-Id: <1431021095-7558-2-git-send-email-jsnow@redhat.com> In-Reply-To: <1431021095-7558-1-git-send-email-jsnow@redhat.com> References: <1431021095-7558-1-git-send-email-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: John Snow , armbru@redhat.com Subject: [Qemu-devel] [PATCH 1/1] qtest: pre-buffer hex nibs 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 Instead of converting each byte one-at-a-time and then sending each byte over the wire, use sprintf() to pre-compute all of the hex nibs into a single buffer, then send the entire buffer all at once. This gives a moderate speed boost to memread() and memwrite() functions. Signed-off-by: John Snow Reviewed-by: Markus Armbruster --- qtest.c | 11 +++++++---- tests/libqtest.c | 8 +++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/qtest.c b/qtest.c index c4999c3..d4e931f 100644 --- a/qtest.c +++ b/qtest.c @@ -414,6 +414,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; + char *enc; g_assert(words[1] && words[2]); addr = strtoull(words[1], NULL, 0); @@ -422,14 +423,16 @@ 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]); + sprintf(&enc[i * 2], "%02x", data[i]); } - qtest_send(chr, "\n"); + + 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..e5188e0 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -730,13 +730,15 @@ void qtest_memwrite(QTestState *s, uint64_t addr, const void *data, size_t size) { const uint8_t *ptr = data; size_t i; + char *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]); + sprintf(&enc[i * 2], "%02x", ptr[i]); } - qtest_sendf(s, "\n"); + + 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)