From owner-freebsd-arch@FreeBSD.ORG Mon Aug 1 13:17:12 2011 Return-Path: Delivered-To: arch@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 18E59106566B for ; Mon, 1 Aug 2011 13:17:12 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from citadel.icyb.net.ua (citadel.icyb.net.ua [212.40.38.140]) by mx1.freebsd.org (Postfix) with ESMTP id 650E48FC12 for ; Mon, 1 Aug 2011 13:17:11 +0000 (UTC) Received: from odyssey.starpoint.kiev.ua (alpha-e.starpoint.kiev.ua [212.40.38.101]) by citadel.icyb.net.ua (8.8.8p3/ICyb-2.3exp) with ESMTP id QAA26447 for ; Mon, 01 Aug 2011 16:00:59 +0300 (EEST) (envelope-from avg@FreeBSD.org) Message-ID: <4E36A38A.20204@FreeBSD.org> Date: Mon, 01 Aug 2011 16:00:58 +0300 From: Andriy Gapon User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:5.0) Gecko/20110705 Thunderbird/5.0 MIME-Version: 1.0 To: arch@FreeBSD.org References: <4DEE37C6.8070303@FreeBSD.org> In-Reply-To: <4DEE37C6.8070303@FreeBSD.org> X-Enigmail-Version: 1.2pre X-Forwarded-Message-Id: <4DEE37C6.8070303@FreeBSD.org> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Cc: Subject: sketch of a design for lock-less and non-interleaved msgbuf X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 01 Aug 2011 13:17:12 -0000 Just so that it is not lost in /dev/null, maybe someone might find some useful bit in it. Please see in the forwarded message. -------- Original Message -------- Message-ID: <4DEE37C6.8070303@FreeBSD.org> Date: Tue, 07 Jun 2011 17:37:58 +0300 From: Andriy Gapon To: gibbs@FreeBSD.org CC: Kenneth D. Merry Subject: Re: svn commit: r222537 - in head/sys: kern sys References: <201105311729.p4VHTwrZ033296@svn.freebsd.org> <4DE5D72A.1020405@FreeBSD.org> <4DE66249.5070503@FreeBSD.org> In-Reply-To: <4DE66249.5070503@FreeBSD.org> on 01/06/2011 19:01 Justin T. Gibbs said the following: > On 6/1/11 12:07 AM, Andriy Gapon wrote: >> P.S. I have been thinking about fixing the problem in a different fashion, via >> reserving portions of dmesg buffer for a whole message using CAS: >> http://lists.freebsd.org/pipermail/freebsd-hackers/2010-April/031535.html > > This is actually where we started (although unfortunately independently > since neither Ken nor I saw your previous email). As you say in your > message form last April, integrating this type of strategy into the > message buffer code is problematic. You need to track the in-progress > writes (i.e. holes in the message buffer) so that only fully committed > data is printed. I'm sure this can be done with per-cpu data structures > and a heavy dose of atomic ops, but after an hour of discussion, we wound > up with a ton of complexity and little confidence our design was sound. I think that I have a solution for this. It's not trivial, of course, but is sufficiently straightforward. But I am not sure if it provides any advantage over the spinlock approach. Besides it's just for the message buffer and not for console printing. But, just in case, here is the description. We use a message buffer like today plus the CAS approach described above. Additionally we use another (smaller) buffer, which we can call a buffer of pointers or, more abstractly, a message queue. In principle this is the same as our message buffer, but instead of characters we put into it pointers to complete messages composed in the main message buffer. The pointers are appended to the message queue using atomic operations in exactly the same fashion as we currently add characters to the normal message buffer. So a consumer interested in complete messages should track the pointer buffer and get pointers to complete messages in the main message buffer. A consumer like a debugger may want to access the main message buffer directly to examine even incomplete messages, possibly intermixed with the previous contents in the case a wraparound of message buffer occurred at least once. BTW, this approach could remove a need for the temporary on-stack buffers enabled by PRINTF_BUFR_SIZE. -- Andriy Gapon