Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753922AbbFDK7R (ORCPT ); Thu, 4 Jun 2015 06:59:17 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:41720 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753892AbbFDK7F (ORCPT ); Thu, 4 Jun 2015 06:59:05 -0400 Date: Thu, 4 Jun 2015 12:58:55 +0200 From: Peter Zijlstra To: Kirill Tkhai Cc: "umgwanakikbuti@gmail.com" , "mingo@elte.hu" , "ktkhai@parallels.com" , "rostedt@goodmis.org" , "tglx@linutronix.de" , "juri.lelli@gmail.com" , "pang.xunlei@linaro.org" , "oleg@redhat.com" , "wanpeng.li@linux.intel.com" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH 8/9] hrtimer: Allow hrtimer::function() to free the timer Message-ID: <20150604105855.GU18673@twins.programming.kicks-ass.net> References: <20150603132903.203333087@infradead.org> <20150603134023.156059118@infradead.org> <214021433348760@web25g.yandex.ru> <20150603211324.GC3644@twins.programming.kicks-ass.net> <2134411433408823@web8j.yandex.ru> <20150604104902.GH3644@twins.programming.kicks-ass.net> <20150604105537.GT18673@twins.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150604105537.GT18673@twins.programming.kicks-ass.net> User-Agent: Mutt/1.5.21 (2012-12-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2177 Lines: 63 On Thu, Jun 04, 2015 at 12:55:37PM +0200, Peter Zijlstra wrote: > On Thu, Jun 04, 2015 at 12:49:02PM +0200, Peter Zijlstra wrote: > > Needs more comments at the very least, its fully of trickery. > > > > @@ -1118,10 +1125,16 @@ static void __run_hrtimer(struct hrtimer > > enum hrtimer_restart (*fn)(struct hrtimer *); > > int restart; > > > > - WARN_ON(!irqs_disabled()); > > + lockdep_assert_held(&cpu_base->lock); > > > > debug_deactivate(timer); > > - base->running = timer; > > + cpu_base->running = timer; > > + > > + /* > > + * separate the ->running assignment from the ->state assignment > > + */ > > + write_seqcount_begin(&cpu_base->seq); > > Maybe these need to be raw_write_seqcount_latch().. I'm properly confusing my self, so let me write a little more detail; I didn't think it needed the double wmb because: [S] running = timer; [S] seq++; WMB [S] state = INACTIVE I don't think it matters if we re-order the first two stores, since at that point ->state is still ENQUEUED and we're good. Similar for the case below, you can flip the seq increment and the ->running clear, but at that time ->state should already be ENQUEUED again (if indeed the timer got re-armed), otherwise its not active anymore. > > __remove_hrtimer(timer, base, HRTIMER_STATE_INACTIVE, 0); > > timer_stats_account_hrtimer(timer); > > fn = timer->function; > > @@ -1150,8 +1163,13 @@ static void __run_hrtimer(struct hrtimer > > !(timer->state & HRTIMER_STATE_ENQUEUED)) > > enqueue_hrtimer(timer, base); > > > > - WARN_ON_ONCE(base->running != timer); > > - base->running = NULL; > > + /* > > + * separate the ->running assignment from the ->state assignment > > + */ > > + write_seqcount_end(&cpu_base->seq); > > + > > + WARN_ON_ONCE(cpu_base->running != timer); > > + cpu_base->running = NULL; > > } > > > > static void __hrtimer_run_queues(struct hrtimer_cpu_base *cpu_base, ktime_t now) -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/