So far, putpacket() sent every char on its own. Instead, we can accumulate
a buffer and write that out over TCP/IP at once, vastly reducing overhead.
>From 843624a2f41a5d31e1e79d5b9be0c7da01f81644 Mon Sep 17 00:00:00 2001
From: Martin Hofmann <martin.hofm...@studium.uni-erlangen.de>
Date: Fri, 14 Mar 2014 16:06:45 +0100
Subject: [PATCH] Speed up putpacket() function
So far, putpacket() sent every char on its own. Instead, we can accumulate
a buffer and write that out over TCP/IP at once, vastly reducing overhead.
---
avarice/src/remote.cc | 59 ++++++++++++++++++++++++++++++++++++---------------
1 file changed, 42 insertions(+), 17 deletions(-)
diff --git a/avarice/src/remote.cc b/avarice/src/remote.cc
index a3884ee..529b376 100644
--- a/avarice/src/remote.cc
+++ b/avarice/src/remote.cc
@@ -527,30 +527,55 @@ static char *getpacket(int &len)
}
}
+/**
+ * Write the string outBuffer to GDB, without adding checksums etc.
+ *
+ * outBuffer must be \0-terminated!
+ */
+static void putstring(const char *outBuffer)
+{
+ int ret;
+ int sent = 0;
+ int msgLength = strlen(outBuffer);
+
+ do {
+ ret = write(gdbFileDescriptor, outBuffer, msgLength - sent);
+
+ if ((ret != msgLength - sent) && (ret >= 0)) {
+ outBuffer += ret;
+ sent += ret;
+ waitForGdbOutput();
+ }
+
+ if (errno != EAGAIN && ret < 0) {
+ throw jtag_exception();
+ }
+ } while (sent < msgLength && getDebugChar() != '+');
+}
+
/** Send packet 'buffer' to gdb. Adds $, # and checksum wrappers. **/
static void putpacket(char *buffer)
{
- unsigned char checksum;
- int count;
+ unsigned char checksum = 0;
char ch;
+ char outBuffer[BUFMAX + 4]; // +4 for $, # and 2 Byte checksum
+ int ret;
+ int count = 0;
- // $<packet info>#<checksum>.
- do
+ for(int count = 0; (count < BUFMAX) && (ch = buffer[count]); count++)
{
- putDebugChar('$');
- checksum = 0;
- count = 0;
+ checksum += ch;
+ }
- while((ch = buffer[count]))
- {
- putDebugChar(ch);
- checksum += ch;
- count += 1;
- }
- putDebugChar('#');
- putDebugChar(hexchars[checksum >> 4]);
- putDebugChar(hexchars[checksum % 16]);
- } while(getDebugChar() != '+'); // wait for the ACK
+ // $<packet info>#<checksum>.
+ ret = snprintf(outBuffer, sizeof(outBuffer), "$%s#%c%c", buffer,
+ hexchars[checksum >> 4], hexchars[checksum % 16]);
+
+ if (ret < 0) {
+ throw jtag_exception();
+ }
+
+ putstring(outBuffer);
}
/** Set remcomOutBuffer to "ok" response */
--
1.9.0
------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
avarice-user mailing list
avarice-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/avarice-user