RFC: lossless printk
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 -----------------------------------
arch/um/Kconfig_char +8 -0
@@ -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
arch/um/drivers/Makefile +2 -1
@@ -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
arch/um/drivers/stdio_console.c +6 -0
@@ -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)
arch/um/drivers/console_user.c new file +53 -0
53 lines not on this page · raw message
Signature · 14 lines
_________________________________________________________________________ / Werner Almesberger, Buenos Aires, Argentina [email protected] / /_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 [email protected] https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
arch/um/drivers/console_user.c line 34
Quoted 6 lines · Werner Almesberger
arch/um/drivers/console_user.c new file +6
-0+while (1 ) { +int n; + + wrote =write (1 ,p,len); +if (wrote >=0 ) +break ;
This won't work properly. What you need is something like:
if (wrote == len) break;
if (wrote >= 0) {
len -= wrote;
p += wrote;
}
if (wrote >= 0 || errno == EAGAIN) {
usleep(100000); /* nap for 100ms */
continue;
}arch/um/drivers/console_user.c line 49
Quoted 9 lines
arch/um/drivers/console_user.c new file +9
-0+/* +* 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 ();
Not sure about this.. should probably just drop the writes then and return an error. The console may have been hung up by various reasons, and I do not think this should kill the kernel.
Regards
Henrik
-------------------------------------------------------
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 [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
Quoted 1 line · Adam Heath
Don't define functions inline like that, place it in a header.
Of course. I just didn't want to touch yet another file for now. After all, that's just a first try to get feedback.
Quoted 2 lines
The code shouldn't retry forever. If the output is blocked for a long time, the kernel will become stalled.
Hmm, that's a tricky one. What's a good policy in this case ? Wait up to a fixed amount of time before continuing, and perhaps do the same thing on the next printk ? Stop retrying after one timeout ? Make all this configurable ?
Quoted 1 line
You also don't handle EINTR.
Good point. I actually never saw one happen, even though I have workloads that almost only printk.
Quoted 1 line
Are you converting errno to a list of hashes?
Yeah :-) I'll fix this. You hit it usually for EPIPE or the like.
Quoted 2 lines
And couldn't writing to stderr
have the same non-blocking problems?
Potentially yes. Not sure if it makes sense to try very hard to get that last message out, though.
- Werner
Signature · 14 lines
_________________________________________________________________________ / Werner Almesberger, Buenos Aires, Argentina [email protected] / /_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 [email protected] https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
Quoted 4 lines · Werner Almesberger
Hmm, that's a tricky one. What's a good policy in this case ? Wait up to a fixed amount of time before continuing, and perhaps do the same thing on the next printk ? Stop retrying after one timeout ? Make all this configurable ?
I would suggest using the standard serial console implementation as a template for how things should behave in such event..
Regards
Henrik
-------------------------------------------------------
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 [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
Quoted 1 line · Henrik Nordstrom
This won't work properly. What you need is something like:
Hmm, if the destination is "stuck", you should get ENOSPC or EAGAIN in the next iteration after a partial write. Someone may make us work particularly hard by only allowing only a few bytes at a time, but I'm not sure printk should worry about this.
Quoted 3 lines
Not sure about this.. should probably just drop the writes then and return an error. The console may have been hung up by various reasons, and I do not think this should kill the kernel.
Yes, that might be nicer.
- Werner
Signature · 14 lines
_________________________________________________________________________ / Werner Almesberger, Buenos Aires, Argentina [email protected] / /_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 [email protected] https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
Quoted 5 lines · Werner Almesberger
Quoted 1 line · Henrik Nordstrom
This won't work properly. What you need is something like:
Hmm, if the destination is "stuck", you should get ENOSPC or EAGAIN in the next iteration after a partial write.
Yes, but the problem was that you ignored the partial write as if it had not happened.. after a partial write you need to remember what you have wrote and not write these again. If not you get dublicated data.
Regards
Henrik
-------------------------------------------------------
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 [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
Quoted 3 lines · Henrik Nordstrom
Yes, but the problem was that you ignored the partial write as if it had not happened.. after a partial write you need to remember what you have wrote and not write these again. If not you get dublicated data.
Hmm, I don't see what you mean. If there's a complete or partial write, I break to the outer loop, which adjusts "len" and "p" by the amount written, and repeats until we're done.
- Werner
Signature · 14 lines
_________________________________________________________________________ / Werner Almesberger, Buenos Aires, Argentina [email protected] / /_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 [email protected] https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
Quoted 3 lines · Werner Almesberger
Hmm, I don't see what you mean. If there's a complete or partial write, I break to the outer loop, which adjusts "len" and "p" by the amount written, and repeats until we're done.
You are correct. It is just me being tired. Ignore that part of my message ;-)
Regards
Henrik
-------------------------------------------------------
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 [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
Quoted 2 lines · Henrik Nordstrom
I would suggest using the standard serial console implementation as a template for how things should behave in such event..
That seems to translate to "if you don't check for errors, you'll never have to worry about them" :-)
I'll just turn it off if it's anything but the non-fatal errnos.
- Werner
Signature · 14 lines
_________________________________________________________________________ / Werner Almesberger, Buenos Aires, Argentina [email protected] / /_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 [email protected] https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel