Kenneth D. Merry d42a4eb507 Fix apparent garbage in the message buffer.
While we have had a fix in place (options PRINTF_BUFR_SIZE=128) to fix
scrambled console output, the message buffer and syslog were still getting
log messages one character at a time.  While all of the characters still
made it into the log (courtesy of atomic operations), they were often
interleaved when there were multiple threads writing to the buffer at the
same time.

This fixes message buffer accesses to use buffering logic as well, so that
strings that are less than PRINTF_BUFR_SIZE will be put into the message
buffer atomically.  So now dmesg output should look the same as console
output.

subr_msgbuf.c:		Convert most message buffer calls to use a new spin
			lock instead of atomic variables in some places.

			Add a new routine, msgbuf_addstr(), that adds a
			NUL-terminated string to a message buffer.  This
			takes a priority argument, which allows us to
			eliminate some races (at least in the the string
			at a time case) that are present in the
			implementation of msglogchar().  (dangling and
			lastpri are static variables, and are subject to
			races when multiple callers are present.)

			msgbuf_addstr() also allows the caller to request
			that carriage returns be stripped out of the
			string.  This matches the behavior of msglogchar(),
			but in testing so far it doesn't appear that any
			newlines are being stripped out.  So the carriage
			return removal functionality may be a candidate
			for removal later on if further analysis shows
			that it isn't necessary.

subr_prf.c:		Add a new msglogstr() routine that calls
			msgbuf_logstr().

			Rename putcons() to putbuf().  This now handles
			buffered output to the message log as well as
			the console.  Also, remove the logic in putcons()
			(now putbuf()) that added a carriage return before
			a newline.  The console path was the only path that
			needed it, and cnputc() (called by cnputs())
			already adds a carriage return.  So this
			duplication resulted in kernel-generated console
			output lines ending in '\r''\r''\n'.

			Refactor putchar() to handle the new buffering
			scheme.

			Add buffering to log().

			Change log_console() to use msglogstr() instead of
			msglogchar().  Don't add extra newlines by default
			in log_console().  Hide that behavior behind a
			tunable/sysctl (kern.log_console_add_linefeed) for
			those who would like the old behavior.  The old
			behavior led to the insertion of extra newlines
			for log output for programs that print out a
			string, and then a trailing newline on a separate
			write.  (This is visible with dmesg -a.)

msgbuf.h:		Add a prototype for msgbuf_addstr().

			Add three new fields to struct msgbuf, msg_needsnl,
			msg_lastpri and msg_lock.  The first two are needed
			for log message functionality previously handled
			by msglogchar().  (Which is still active if
			buffering isn't enabled.)

			Include sys/lock.h and sys/mutex.h for the new
			mutex.

Reviewed by:	gibbs
2011-05-31 17:29:58 +00:00
..
2009-11-28 23:50:48 +00:00
2010-12-22 05:01:52 +00:00
2009-12-14 22:47:09 +00:00
2010-12-31 18:07:16 +00:00
2009-01-01 02:08:56 +00:00
2009-01-01 02:08:56 +00:00
2011-04-04 17:39:30 +00:00
2010-09-28 03:24:53 +00:00
2010-07-24 14:23:06 +00:00
2009-05-09 19:01:24 +00:00
2009-09-19 17:56:26 +00:00
2010-08-19 11:31:03 +00:00
2011-01-23 12:44:17 +00:00
2008-09-22 10:37:02 +00:00
2011-05-19 17:22:48 +00:00
2008-07-23 16:44:20 +00:00
2010-11-12 15:30:49 +00:00
2011-05-05 02:35:25 +00:00
2011-04-18 16:32:47 +00:00
2011-04-18 16:32:47 +00:00
2011-04-18 16:32:47 +00:00
2009-11-28 23:50:48 +00:00
2010-04-20 17:57:43 +00:00
2009-03-01 04:57:23 +00:00
2010-01-04 20:59:52 +00:00
2009-09-06 09:39:40 +00:00
2009-08-23 08:04:40 +00:00