Skip to content

Commit

Permalink
xen-console: Optimize console_display_thrd
Browse files Browse the repository at this point in the history
Optimize console_display_thrd by removing the inner loop that copies
data from the console buffer to the output buffer. Instead, calculate
the size of the data to be copied and print it in one go.

Signed-off-by: Mykyta Poturai <[email protected]>
  • Loading branch information
Deedone committed Apr 15, 2024
1 parent 514e14f commit cbd5195
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions xen-console-srv/src/xen_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,8 @@ static void console_display_thrd(void *p1, void *p2, void *p3)
ARG_UNUSED(p3);
struct xen_domain_console *console = p1;
const struct shell *shell = p2;
/* Buffer input a little */
char buf[32];
int read;
size_t buf_pos, prod_buf_pos;
int size;

shell_info(shell, "Attached to a domain console");

Expand All @@ -387,19 +386,18 @@ static void console_display_thrd(void *p1, void *p2, void *p3)
}

while (console->int_cons < console->int_prod) {
read = 0;
memset(buf, 0, sizeof(buf));

/* TODO: There is a room for optimization.... */
while (console->int_cons < console->int_prod &&
read < sizeof(buf) - 1) {
size_t buf_pos = (console->int_cons++) &
(XEN_CONSOLE_BUFFER_SZ - 1);
buf[read++] = console->int_buf[buf_pos];
}
if (read) {
shell_fprintf(shell, SHELL_NORMAL, "%s", buf);
buf_pos = (console->int_cons) &
(XEN_CONSOLE_BUFFER_SZ - 1);
prod_buf_pos = (console->int_prod) &
(XEN_CONSOLE_BUFFER_SZ - 1);
if (buf_pos < prod_buf_pos) {
size = prod_buf_pos - buf_pos;
} else {
size = XEN_CONSOLE_BUFFER_SZ - buf_pos;
}
shell_fprintf(shell, SHELL_NORMAL, "%.*s", size,
&console->int_buf[buf_pos]);
console->int_cons += size;
}
k_mutex_unlock(&console->lock);
}
Expand Down

0 comments on commit cbd5195

Please sign in to comment.