Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 31 May 2011 17:29:58 +0000 (UTC)
From:      "Kenneth D. Merry" <ken@FreeBSD.org>
To:        cvs-src-old@freebsd.org
Subject:   cvs commit: src/sys/kern subr_msgbuf.c subr_prf.c src/sys/sys msgbuf.h
Message-ID:  <201105311730.p4VHUiCe034048@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
ken         2011-05-31 17:29:58 UTC

  FreeBSD src repository

  Modified files:
    sys/kern             subr_msgbuf.c subr_prf.c 
    sys/sys              msgbuf.h 
  Log:
  SVN rev 222537 on 2011-05-31 17:29:58Z by ken
  
  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
  
  Revision  Changes    Path
  1.4       +170 -17   src/sys/kern/subr_msgbuf.c
  1.142     +124 -33   src/sys/kern/subr_prf.c
  1.31      +14 -7     src/sys/sys/msgbuf.h



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201105311730.p4VHUiCe034048>