linux-um archives
 help / color / mirror / Atom feed
* [uml-devel] RFC: lossless printk
@ 2004-04-01  7:25 Werner Almesberger
  2004-04-01 10:58 ` Henrik Nordstrom
       [not found] ` <Pine.LNX.4.58.0404010149580.13832@gradall.private.brainfood.com>
  0 siblings, 2 replies; 9+ messages in thread
From: Werner Almesberger @ 2004-04-01  7:25 UTC (permalink / raw)
  To: user-mode-linux-devel

The non-blocking console of UML silenty drops printks if they would
block. This is a tad annoying if you want to record all of them in
a file, e.g. if you're using UML for automated regression tests.

The patch below optionally makes printks pause and retry until they
succeed. Note that printk.c does the serialization for us, so
there's no need to lock again.

Not sure if this should really be a config option, or it it
shouldn't be enabled by default. I've been using this for a while
in a slightly more limited form, and it never seemed to get in the
way such that I'd prefer the original, "lossy" printk.

- Werner

---------------------------------- cut here -----------------------------------

--- linux-2.6.4-orig/arch/um/Kconfig_char	Wed Mar 10 23:55:26 2004
+++ linux-2.6.4/arch/um/Kconfig_char	Wed Mar 31 22:18:21 2004
@@ -5,6 +5,14 @@
 	bool
 	default y
 
+config LOSSLESS_STDIO_CONSOLE
+	bool "Lossless standard output console"
+	depends on STDIO_CONSOLE
+	help
+	When console output goes to standard output, retry write operations
+	that would block. This is particularly useful when recording the
+	output of a UML system in a file.
+
 config SSL
 	bool "Virtual serial line"
 	help
--- linux-2.6.4-orig/arch/um/drivers/Makefile	Tue Mar 16 03:11:43 2004
+++ linux-2.6.4/arch/um/drivers/Makefile	Wed Mar 31 22:17:18 2004
@@ -41,13 +41,14 @@
 obj-$(CONFIG_UML_WATCHDOG) += harddog.o
 obj-$(CONFIG_BLK_DEV_COW) += cow_kern.o
 obj-$(CONFIG_BLK_DEV_COW_COMMON) += cow_user.o
+obj-$(CONFIG_LOSSLESS_STDIO_CONSOLE) += console_user.o
 
 obj-y += stdio_console.o $(CHAN_OBJS)
 
 USER_SINGLE_OBJS = $(foreach f,$(patsubst %.o,%,$(obj-y) $(obj-m)),$($(f)-objs))
 
 USER_OBJS := $(filter %_user.o,$(obj-y) $(obj-m) $(USER_SINGLE_OBJS)) fd.o \
-	null.o pty.o tty.o xterm.o
+	null.o pty.o tty.o xterm.o console_user.o
 USER_OBJS := $(foreach file,$(USER_OBJS),$(obj)/$(file))
 
 $(USER_OBJS) : %.o: %.c
--- linux-2.6.4-orig/arch/um/drivers/stdio_console.c	Tue Mar 16 03:11:43 2004
+++ linux-2.6.4/arch/um/drivers/stdio_console.c	Wed Mar 31 22:16:59 2004
@@ -194,6 +194,11 @@
 static void console_write(struct console *console, const char *string, 
 			  unsigned len)
 {
+#ifdef CONFIG_LOSSLESS_STDIO_CONSOLE
+	void lossless_stdio_console_write(const char *string,unsigned len);
+
+	lossless_stdio_console_write(string,len);
+#else
 	struct line *line = &vts[console->index];
 
 	if(con_init_done)
@@ -201,6 +206,7 @@
 	console_write_chan(&line->chan_list, string, len);
 	if(con_init_done)
 		up(&line->sem);
+#endif
 }
 
 static struct tty_driver *console_device(struct console *c, int *index)
--- /dev/null	Fri Dec 12 23:38:58 2003
+++ linux-2.6.4/arch/um/drivers/console_user.c	Thu Apr  1 04:15:28 2004
@@ -0,0 +1,53 @@
+/*
+ * arch/um/drivers/console_user.c - Lossless console driver using write(2)
+ *
+ * Written 2003,2004 by Werner Almesberger
+ */
+
+
+#include <stdlib.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <errno.h>
+
+
+/*
+ * UML makes the console non-blocking. And indeed, even when stdout is
+ * redirected to a file, we may occasionally get EAGAIN, and lose a message or
+ * ten. This console write function just retries the write, without affecting
+ * other users of the console.
+ */
+
+
+void lossless_stdio_console_write(const char *string,unsigned len)
+{
+	const char *p;
+	int wrote;
+
+	for (p = string; len; p += wrote) {
+		while (1) {
+			int n;
+
+			wrote = write(1,p,len);
+			if (wrote >= 0)
+				break;
+
+			if (errno == EAGAIN) {
+				usleep(100000); /* nap for 100ms */
+				continue;
+			}
+
+			/*
+			 * We're in trouble. Try to get the message out with
+			 * our dying breath, then expire.
+			 */
+			for (n = errno; n; n--)
+				write(2,"#",1);
+
+			/* doesn't really do much, but try to die anyway */
+			abort();
+		}
+		len -= wrote;
+	}
+}

-- 
  _________________________________________________________________________
 / Werner Almesberger, Buenos Aires, Argentina     werner@almesberger.net /
/_http://www.almesberger.net/____________________________________________/


-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
_______________________________________________
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2004-04-02 20:21 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-04-01  7:25 [uml-devel] RFC: lossless printk Werner Almesberger
2004-04-01 10:58 ` Henrik Nordstrom
2004-04-01 15:36   ` Werner Almesberger
2004-04-01 17:42     ` Henrik Nordstrom
2004-04-01 18:28       ` Werner Almesberger
2004-04-01 20:36         ` Henrik Nordstrom
     [not found] ` <Pine.LNX.4.58.0404010149580.13832@gradall.private.brainfood.com>
2004-04-01 11:30   ` Werner Almesberger
2004-04-01 11:48     ` Henrik Nordstrom
2004-04-02 20:19       ` Werner Almesberger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox