Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752911AbbFHORb (ORCPT ); Mon, 8 Jun 2015 10:17:31 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:35987 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750762AbbFHORW (ORCPT ); Mon, 8 Jun 2015 10:17:22 -0400 Date: Mon, 8 Jun 2015 16:17:09 +0200 From: Peter Zijlstra To: Oleg Nesterov Cc: umgwanakikbuti@gmail.com, mingo@elte.hu, ktkhai@parallels.com, rostedt@goodmis.org, tglx@linutronix.de, juri.lelli@gmail.com, pang.xunlei@linaro.org, wanpeng.li@linux.intel.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH 08/14] hrtimer: Allow hrtimer::function() to free the timer Message-ID: <20150608141709.GX18673@twins.programming.kicks-ass.net> References: <20150605084836.364306429@infradead.org> <20150605085205.723058588@infradead.org> <20150607223317.GA5193@redhat.com> <20150608091417.GM19282@twins.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150608091417.GM19282@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: 3452 Lines: 97 On Mon, Jun 08, 2015 at 11:14:17AM +0200, Peter Zijlstra wrote: > On Mon, Jun 08, 2015 at 12:33:17AM +0200, Oleg Nesterov wrote: > > And I think there is a problem. Consider a timer TIMER which always > > rearms itself using some "default" timeout. > > > > In this case __hrtimer_start_range_ns(&TIMER, ...) must preserve > > hrtimer_active(&TIMER) == T. By definition, and currently this is > > true. > > > > After this patch this is no longer true (afaics). If the timer is > > pending but not running, __hrtimer_start_range_ns()->remove_hrtimer() > > will clear ENQUEUED first, then set it again in enqueue_hrtimer(). > > That is so even with the current code; the current code uses: > > hrtimer->state & CALLBACK > > for __remove_hrtimer(.state). In the above case of a pending timer, > that's 0 aka. HRTIMER_STATE_INACTIVE. > > > This means that hrtimer_active() returns false in between. And note > > that it doesn't matter if the timer changes its ->base or not, so > > that 2nd cpu_base above can't help. > > > > I think that __hrtimer_start_range_ns() should preserve ENQUEUED > > like migrate_hrtimer_list() should do (see the previous email). > > I tend to agree, but I think its a pre-existing problem, not one > introduced by my proposed patch. Something like this would fix that I think. It fully preserves timer->state over hrtimer_start_range_ns(). --- kernel/time/hrtimer.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -891,10 +891,10 @@ static void __remove_hrtimer(struct hrti * remove hrtimer, called with base lock held */ static inline int -remove_hrtimer(struct hrtimer *timer, struct hrtimer_clock_base *base) +remove_hrtimer(struct hrtimer *timer, struct hrtimer_clock_base *base, bool restart) { if (hrtimer_is_queued(timer)) { - unsigned long state; + unsigned long state = timer->state; int reprogram; /* @@ -908,12 +908,15 @@ remove_hrtimer(struct hrtimer *timer, st debug_deactivate(timer); timer_stats_hrtimer_clear_start_info(timer); reprogram = base->cpu_base == this_cpu_ptr(&hrtimer_bases); - /* - * We must preserve the CALLBACK state flag here, - * otherwise we could move the timer base in - * switch_hrtimer_base. - */ - state = timer->state & HRTIMER_STATE_CALLBACK; + + if (!restart) { + /* + * We must preserve the CALLBACK state flag here, + * otherwise we could move the timer base in + * switch_hrtimer_base. + */ + state &= HRTIMER_STATE_CALLBACK; + } __remove_hrtimer(timer, base, state, reprogram); return 1; } @@ -938,7 +941,7 @@ void hrtimer_start_range_ns(struct hrtim base = lock_hrtimer_base(timer, &flags); /* Remove an active timer from the queue: */ - remove_hrtimer(timer, base); + remove_hrtimer(timer, base, true); if (mode & HRTIMER_MODE_REL) { tim = ktime_add_safe(tim, base->get_time()); @@ -1007,7 +1010,7 @@ int hrtimer_try_to_cancel(struct hrtimer base = lock_hrtimer_base(timer, &flags); if (!hrtimer_callback_running(timer)) - ret = remove_hrtimer(timer, base); + ret = remove_hrtimer(timer, base, false); unlock_hrtimer_base(timer, &flags); -- 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/