From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Ogness Subject: Re: [RFC PATCH v1 07/25] printk-rb: add functionality required by printk Date: Wed, 13 Feb 2019 10:20:07 +0100 Message-ID: <87k1i411vc.fsf@linutronix.de> References: <20190212143003.48446-1-john.ogness@linutronix.de> <20190212143003.48446-8-john.ogness@linutronix.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: In-Reply-To: (Linus Torvalds's message of "Tue, 12 Feb 2019 09:15:36 -0800") Sender: linux-kernel-owner@vger.kernel.org To: Linus Torvalds Cc: Linux List Kernel Mailing , Peter Zijlstra , Petr Mladek , Sergey Senozhatsky , Steven Rostedt , Daniel Wang , Andrew Morton , Greg Kroah-Hartman , Alan Cox , Jiri Slaby , Peter Feiner , linux-serial@vger.kernel.org, Sergey Senozhatsky List-Id: linux-serial@vger.kernel.org On 2019-02-12, Linus Torvalds wrote: > On Tue, Feb 12, 2019 at 6:30 AM John Ogness wrote: >> >> + while (atomic_long_read(&rb->lost)) { >> + atomic_long_dec(&rb->lost); >> + rb->seq++; >> + } > > This looks like crazy garbage. It's neither atomic nor sane. It works because because only 1 context on a single CPU can hit that loop. But yes, it is crazy. > Why isn't it something like > > if (atomic_long_read(&rb->lost)) { > long lost = atomic_xchg(&rb->lost, 0); > rb->seq += lost; > } > > instead? Yes, it should be like you suggest. Thanks. John Ogness