From owner-svn-src-head@FreeBSD.ORG Mon Mar 19 00:36:33 2012 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 98F06106566B; Mon, 19 Mar 2012 00:36:33 +0000 (UTC) (envelope-from eadler@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 844DB8FC0A; Mon, 19 Mar 2012 00:36:33 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q2J0aXjA042503; Mon, 19 Mar 2012 00:36:33 GMT (envelope-from eadler@svn.freebsd.org) Received: (from eadler@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q2J0aXUT042500; Mon, 19 Mar 2012 00:36:33 GMT (envelope-from eadler@svn.freebsd.org) Message-Id: <201203190036.q2J0aXUT042500@svn.freebsd.org> From: Eitan Adler Date: Mon, 19 Mar 2012 00:36:33 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r233135 - in head/sys: kern sys X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Mar 2012 00:36:33 -0000 Author: eadler Date: Mon Mar 19 00:36:32 2012 New Revision: 233135 URL: http://svn.freebsd.org/changeset/base/233135 Log: - Clean up timestamps in msgbuf code. The timestamps should now be inserted after the priority token thus cleaning up the output. - Remove the needless double internal do_add_char function. - Resolve a possible deadlock if interrupts are disabled and getnanotime is called Reviewed by: bde kmacy, avg, sbruno (various versions) Approved by: cperciva MFC after: 2 weeks Modified: head/sys/kern/subr_msgbuf.c head/sys/sys/msgbuf.h Modified: head/sys/kern/subr_msgbuf.c ============================================================================== --- head/sys/kern/subr_msgbuf.c Mon Mar 19 00:07:10 2012 (r233134) +++ head/sys/kern/subr_msgbuf.c Mon Mar 19 00:36:32 2012 (r233135) @@ -49,7 +49,8 @@ static u_int msgbuf_cksum(struct msgbuf *mbp); /* - * + * Timestamps in msgbuf are useful when trying to diagnose when core dumps + * or other actions occured. */ static int msgbuf_show_timestamp = 0; SYSCTL_INT(_kern, OID_AUTO, msgbuf_show_timestamp, CTLFLAG_RW | CTLFLAG_TUN, @@ -143,49 +144,20 @@ msgbuf_getcount(struct msgbuf *mbp) * * The caller should hold the message buffer spinlock. */ -static inline void -__msgbuf_do_addchar(struct msgbuf * const mbp, u_int * const seq, const int c) + +static void +msgbuf_do_addchar(struct msgbuf * const mbp, u_int * const seq, const int c) { u_int pos; /* Make sure we properly wrap the sequence number. */ pos = MSGBUF_SEQ_TO_POS(mbp, *seq); - - mbp->msg_cksum += (u_int)c - + mbp->msg_cksum += (u_int)(u_char)c - (u_int)(u_char)mbp->msg_ptr[pos]; - mbp->msg_ptr[pos] = c; - *seq = MSGBUF_SEQNORM(mbp, *seq + 1); } -static inline void -msgbuf_do_addchar(struct msgbuf * const mbp, u_int * const seq, const int c) -{ - - if (msgbuf_show_timestamp && - (mbp->msg_flags & MSGBUF_NEXT_NEW_LINE) != 0) { - char buf[32]; - char const *bufp; - struct timespec ts; - int err; - - getnanouptime(&ts); - err = snprintf(buf, sizeof (buf), "[%jd.%ld] ", - (intmax_t)ts.tv_sec, ts.tv_nsec / 1000); - - for (bufp = buf; *bufp != '\0'; bufp++) - __msgbuf_do_addchar(mbp, seq, *bufp); - - mbp->msg_flags &= ~MSGBUF_NEXT_NEW_LINE; - } - - __msgbuf_do_addchar(mbp, seq, c); - - if (c == '\n') - mbp->msg_flags |= MSGBUF_NEXT_NEW_LINE; -} - /* * Append a character to a message buffer. */ @@ -213,7 +185,8 @@ msgbuf_addstr(struct msgbuf *mbp, int pr u_int seq; size_t len, prefix_len; char prefix[MAXPRIBUF]; - int nl, i; + char buf[32]; + int nl, i, j, needtime; len = strlen(str); prefix_len = 0; @@ -250,6 +223,7 @@ msgbuf_addstr(struct msgbuf *mbp, int pr mbp->msg_flags &= ~MSGBUF_NEEDNL; } + needtime = 1; for (i = 0; i < len; i++) { /* * If we just had a newline, and the priority is not -1 @@ -263,6 +237,16 @@ msgbuf_addstr(struct msgbuf *mbp, int pr msgbuf_do_addchar(mbp, &seq, prefix[j]); } + if (msgbuf_show_timestamp && needtime == 1 && + (mbp->msg_flags & MSGBUF_NEEDNL) == 0) { + + snprintf(buf, sizeof(buf), "[%jd] ", + (intmax_t)time_uptime); + for (j = 0; buf[j] != '\0'; j++) + msgbuf_do_addchar(mbp, &seq, buf[j]); + needtime = 0; + } + /* * Don't copy carriage returns if the caller requested * filtering. Modified: head/sys/sys/msgbuf.h ============================================================================== --- head/sys/sys/msgbuf.h Mon Mar 19 00:07:10 2012 (r233134) +++ head/sys/sys/msgbuf.h Mon Mar 19 00:36:32 2012 (r233135) @@ -46,9 +46,8 @@ struct msgbuf { u_int msg_cksum; /* checksum of contents */ u_int msg_seqmod; /* range for sequence numbers */ int msg_lastpri; /* saved priority value */ - u_int msg_flags; -#define MSGBUF_NEEDNL 0x01 /* set when newline needed */ -#define MSGBUF_NEXT_NEW_LINE 0x02 + u_int msg_flags; +#define MSGBUF_NEEDNL 0x01 /* set when newline needed */ struct mtx msg_lock; /* mutex to protect the buffer */ };