From 00499bb97b4a661f328ed4bed0deed3cadbaba12 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Tue, 2 Aug 2016 20:30:52 +0200 Subject: [PATCH] add IO lock to get nicer output messages --- hermit/kernel/syscall.c | 3 +++ hermit/libkern/printf.c | 12 +++++++++++- hermit/libkern/stdio.c | 12 +++++------- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/hermit/kernel/syscall.c b/hermit/kernel/syscall.c index f3d74181d..1788933e7 100644 --- a/hermit/kernel/syscall.c +++ b/hermit/kernel/syscall.c @@ -45,6 +45,7 @@ //TODO: don't use one big kernel lock to comminicate with all proxies static spinlock_t lwip_lock = SPINLOCK_INIT; +extern spinlock_irqsave_t stdio_lock; extern int32_t isle; extern int32_t possible_isles; extern volatile int libc_sd; @@ -191,8 +192,10 @@ ssize_t sys_write(int fd, const char* buf, size_t len) { spinlock_unlock(&lwip_lock); + spinlock_irqsave_lock(&stdio_lock); for(i=0; i +#include /* HermitCore use only the 64bit version */ #define __64BIT__ @@ -75,6 +76,8 @@ static char const hex2ascii_data[] = "0123456789abcdefghijklmnopqrstuvwxyz"; /* Max number conversion buffer length: a u_quad_t in base 2, plus NUL byte. */ #define MAXNBUF (sizeof(intmax_t) * NBBY + 1) +extern spinlock_irqsave_t stdio_lock; + /* * Put a NUL-terminated ASCII number (base <= 36) in a buffer in reverse * order; return an optional length and a pointer to the last character @@ -150,12 +153,16 @@ int kvprintf(char const *fmt, void (*func) (int, void *), void *arg, int radix, if (radix < 2 || radix > 36) radix = 10; + spinlock_irqsave_lock(&stdio_lock); + for (;;) { padc = ' '; width = 0; while ((ch = (u_char) * fmt++) != '%' || stop) { - if (ch == '\0') + if (ch == '\0') { + spinlock_irqsave_unlock(&stdio_lock); return (retval); + } PCHAR(ch); } percent = fmt - 1; @@ -449,6 +456,9 @@ int kvprintf(char const *fmt, void (*func) (int, void *), void *arg, int radix, break; } } + + spinlock_irqsave_unlock(&stdio_lock); + #undef PCHAR } diff --git a/hermit/libkern/stdio.c b/hermit/libkern/stdio.c index dcd7ed83e..8c4eee2a4 100644 --- a/hermit/libkern/stdio.c +++ b/hermit/libkern/stdio.c @@ -36,9 +36,7 @@ #include static atomic_int32_t kmsg_counter = ATOMIC_INIT(-1); -#ifdef CONFIG_VGA -static spinlock_irqsave_t vga_lock = SPINLOCK_IRQSAVE_INIT; -#endif +spinlock_irqsave_t stdio_lock = SPINLOCK_IRQSAVE_INIT; /* Workaround for a compiler bug. gcc 5.1 seems to ignore this array, if we defined it as as static array. At least it is as static array not part of @@ -72,9 +70,7 @@ int kputchar(int c) if (is_single_kernel()) { #ifdef CONFIG_VGA - spinlock_irqsave_lock(&vga_lock); vga_putchar(c); - spinlock_irqsave_unlock(&vga_lock); #else uart_putchar(c); #endif @@ -87,6 +83,8 @@ int kputs(const char *str) { int pos, i, len = strlen(str); + spinlock_irqsave_lock(&stdio_lock); + for(i=0; i