From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752524AbbE1Hy0 (ORCPT ); Thu, 28 May 2015 03:54:26 -0400 Received: from cantor2.suse.de ([195.135.220.15]:50683 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751415AbbE1HyT (ORCPT ); Thu, 28 May 2015 03:54:19 -0400 Date: Thu, 28 May 2015 09:54:14 +0200 (CEST) From: Jiri Kosina To: Andrew Morton cc: Petr Mladek , Frederic Weisbecker , Steven Rostedt , Dave Anderson , "Paul E. McKenney" , Kay Sievers , Michal Hocko , Jan Kara , linux-kernel@vger.kernel.org, Wang Long , peifeiyue@huawei.com, dzickus@redhat.com, morgan.wang@huawei.com, sasha.levin@oracle.com Subject: Re: [PATCH 02/10] printk: Try harder to get logbuf_lock on NMI In-Reply-To: <20150527161409.c1c37d25af1c09c340bd04a3@linux-foundation.org> Message-ID: References: <1432557993-20458-1-git-send-email-pmladek@suse.cz> <1432557993-20458-3-git-send-email-pmladek@suse.cz> <20150527161409.c1c37d25af1c09c340bd04a3@linux-foundation.org> User-Agent: Alpine 2.00 (LNX 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 27 May 2015, Andrew Morton wrote: > > +static int try_logbuf_lock_in_nmi(void) > > +{ > > + u64 start_time, current_time; > > + int this_cpu = smp_processor_id(); > > + > > + /* no way if we are already locked on this CPU */ > > + if (logbuf_cpu == this_cpu) > > + return 0; > > + > > + /* try hard to get the lock but do not wait forever */ > > + start_time = cpu_clock(this_cpu); > > + current_time = start_time; > > + while (current_time - start_time < TRY_LOCKBUF_LOCK_MAX_DELAY_NS) { > > + if (raw_spin_trylock(&logbuf_lock)) > > + return 1; > > + cpu_relax(); > > + current_time = cpu_clock(this_cpu); > > + } > > (Looks at the read_seqcount_retry() in > kernel/time/sched_clock.c:sched_clock()) > > Running cpu_clock() in NMI context seems a generally bad idea. Umm, why? Requirement for it to be NMI-safe is explicitly documented. See the corresponding section in Documentation/timers/timekeeping.txt. -- Jiri Kosina SUSE Labs