summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Bendebury <vbendeb@chromium.org>2020-03-10 17:31:19 -0700
committerCommit Bot <commit-bot@chromium.org>2020-03-11 19:58:46 +0000
commitc34880f460e6aee75550ef105f1c8aabc3089a68 (patch)
treeb8d5f71d1e002759ac9bdd19089e806b03896d2d
parentb9e7a77609549e7d7a52c79d4f291e558cd0139e (diff)
downloadchrome-ec-c34880f460e6aee75550ef105f1c8aabc3089a68.tar.gz
system: avoid printing one character at a time
With the upcoming transition to handling console traffic in packet mode it is very expensive to be shipping one character at a time, each character results in sending a packet of 16 or so bytes. This patch modifies print_build_string() such that it splits the long build version string into manageable substrings and prints them instead of printing one character at a time. BRANCH=cr50, cr50-mp BUG=b:149964350 TEST=built a Cr50 image, verified that build string is printed as expected. Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Change-Id: I743205932892b0f14c161ade5ea856a658fb26e6 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2097444 Reviewed-by: Mary Ruthven <mruthven@chromium.org>
-rw-r--r--common/system.c48
1 files changed, 35 insertions, 13 deletions
diff --git a/common/system.c b/common/system.c
index 61ef4882fc..036de2235e 100644
--- a/common/system.c
+++ b/common/system.c
@@ -27,6 +27,7 @@
#include "mpu.h"
#endif
#include "panic.h"
+#include "shared_mem.h"
#include "sysjump.h"
#include "system.h"
#include "task.h"
@@ -1016,15 +1017,19 @@ DECLARE_CONSOLE_COMMAND(hibernate, command_hibernate,
static void print_build_string(void)
{
const char *full_build_string;
- const char *p;
+ char *p;
char symbol;
+ char *next;
+ int index;
+ size_t len;
int seen_colonv;
ccprintf("Build: ");
full_build_string = system_get_build_info();
+ len = strlen(full_build_string);
/* 50 characters or less, will fit into the terminal line. */
- if (strlen(full_build_string) < 50) {
+ if (len < 50) {
ccprintf("%s\n", full_build_string);
return;
}
@@ -1034,24 +1039,41 @@ static void print_build_string(void)
* space (this is where the main version ends), and then on each space
* after the ":v" substring, this is where subcomponent versions are
* separated.
+ *
+ * To avoid invoking ccprintf() for one character at a time let's
+ * create a mutable copy and modify it to print in multiple lines.
*/
- p = full_build_string;
+ if (shared_mem_acquire(len + 1, &p) != EC_SUCCESS) {
+ /*
+ * Should never happen, but if it does let's
+ * just print it in single line.
+ */
+ ccprintf("%s\n", full_build_string);
+ return;
+ }
+
+ memcpy(p, full_build_string, len + 1);
+ next = p;
+ index = 0;
seen_colonv = 1;
- symbol = *p++;
- while (symbol) {
+ do {
+ symbol = next[index++];
if ((symbol == ' ') && seen_colonv) {
+ next[index - 1] = '\0';
seen_colonv = 0;
/* Indent each line under 'Build: ' */
- ccprintf("\n ");
- } else {
- if ((symbol == ':') && (*p == 'v'))
- seen_colonv = 1;
- ccprintf("%c", symbol);
+ ccprintf("%s\n ", next);
+ next += index;
+ index = 0;
+ continue;
}
- symbol = *p++;
- }
- ccprintf("\n");
+ if ((symbol == ':') && (next[index] == 'v'))
+ seen_colonv = 1;
+ } while (symbol);
+ ccprintf("%s\n", next);
+
+ shared_mem_release(p);
}
static int command_version(int argc, char **argv)