From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935399AbcJRRbC (ORCPT ); Tue, 18 Oct 2016 13:31:02 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:57712 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935113AbcJRRaz (ORCPT ); Tue, 18 Oct 2016 13:30:55 -0400 Date: Tue, 18 Oct 2016 19:30:46 +0200 From: Peter Zijlstra To: Steven Rostedt Cc: Sergey Senozhatsky , Petr Mladek , Andrew Morton , Jan Kara , Tejun Heo , Calvin Owens , Thomas Gleixner , Mel Gorman , Ingo Molnar , linux-kernel@vger.kernel.org Subject: Re: [PATCH 3/3] early_printk: Add simple serialization to early_vprintk() Message-ID: <20161018173046.GB3102@twins.programming.kicks-ass.net> References: <20161018170830.405990950@infradead.org> <20161018171513.734367391@infradead.org> <20161018131951.707f320e@gandalf.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20161018131951.707f320e@gandalf.local.home> User-Agent: Mutt/1.5.23.1 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 18, 2016 at 01:19:51PM -0400, Steven Rostedt wrote: > > hehe, I have the exact same patch for my -rt work. > > +static int early_printk_cpu = -1; > > + > > static int early_vprintk(const char *fmt, va_list args) > > { > > + int n, cpu, old; > > char buf[512]; > > + > > + cpu = get_cpu(); > > + for (;;) { > > + old = cmpxchg(&early_printk_cpu, -1, cpu); > > + if (old == -1 || old == cpu) > > + break; Looking at this again, we really should not spin using cmpxchg(), that thrashes the cacheline. The below is slightly better spinning... then again, this isn't performance code. --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -376,10 +376,16 @@ static int early_vprintk(const char *fmt cpu = get_cpu(); for (;;) { - old = cmpxchg(&early_printk_cpu, -1, cpu); - if (old == -1 || old == cpu) + old = READ_ONCE(early_printk_cpu); + if (old == cpu) break; + if (old == -1) { + old = cmpxchg(&early_printk_cpu, -1, cpu); + if (old == -1 || old == cpu) + break; + } + cpu_relax(); }