From owner-freebsd-hackers@FreeBSD.ORG Sat Apr 17 12:15:52 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 95A47106564A for ; Sat, 17 Apr 2010 12:15:52 +0000 (UTC) (envelope-from avg@icyb.net.ua) Received: from citadel.icyb.net.ua (citadel.icyb.net.ua [212.40.38.140]) by mx1.freebsd.org (Postfix) with ESMTP id DC7208FC18 for ; Sat, 17 Apr 2010 12:15:51 +0000 (UTC) Received: from porto.topspin.kiev.ua (porto-e.starpoint.kiev.ua [212.40.38.100]) by citadel.icyb.net.ua (8.8.8p3/ICyb-2.3exp) with ESMTP id PAA16390 for ; Sat, 17 Apr 2010 15:15:50 +0300 (EEST) (envelope-from avg@icyb.net.ua) Received: from localhost.topspin.kiev.ua ([127.0.0.1]) by porto.topspin.kiev.ua with esmtp (Exim 4.34 (FreeBSD)) id 1O36w9-000EHf-Ti for freebsd-hackers@freebsd.org; Sat, 17 Apr 2010 15:15:49 +0300 Message-ID: <4BC9A674.2050705@icyb.net.ua> Date: Sat, 17 Apr 2010 15:15:48 +0300 From: Andriy Gapon User-Agent: Thunderbird 2.0.0.24 (X11/20100321) MIME-Version: 1.0 To: freebsd-hackers@freebsd.org X-Enigmail-Version: 0.96.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Subject: towards fixing intermingled dmesg X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 17 Apr 2010 12:15:52 -0000 Here is a simple extension of msgbuf_addchar that is supposed to allow to put N characters consecutively into msgbuf. The idea is very simple: atomically forward msg_wseq by N and then copy characters into the reserved space. Could you please check if this is implemented correctly and if it would actually work the way I expect? There is still a harder issue of actually plugging this routine into subr_prf.c :-) --- a/sys/kern/subr_msgbuf.c +++ b/sys/kern/subr_msgbuf.c @@ -131,6 +131,26 @@ msgbuf_addchar(struct msgbuf *mbp, int c) mbp->msg_ptr[pos] = c; } +void +msgbuf_addchars(struct msgbuf *mbp, const char *s, const int n) +{ + u_int new_seq, pos, seq; + int c, i; + + do { + seq = mbp->msg_wseq; + new_seq = MSGBUF_SEQNORM(mbp, seq + n); + } while (atomic_cmpset_rel_int(&mbp->msg_wseq, seq, new_seq) == 0); + + for (i = 0; i < n; i++) { + pos = MSGBUF_SEQ_TO_POS(mbp, seq + i); + c = s[i]; + atomic_add_int(&mbp->msg_cksum, (u_int)(u_char)c - + (u_int)(u_char)mbp->msg_ptr[pos]); + mbp->msg_ptr[pos] = c; + } +} + /* * Read and mark as read a character from a message buffer. * Returns the character, or -1 if no characters are available. -- Andriy Gapon