Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753220AbbFHOET (ORCPT ); Mon, 8 Jun 2015 10:04:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34306 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753066AbbFHOEP (ORCPT ); Mon, 8 Jun 2015 10:04:15 -0400 Date: Mon, 8 Jun 2015 16:03:14 +0200 From: Oleg Nesterov To: Peter Zijlstra 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: <20150608140314.GA13168@redhat.com> 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.18 (2008-05-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2863 Lines: 81 On 06/08, Peter Zijlstra wrote: > > On Mon, Jun 08, 2015 at 12:33:17AM +0200, Oleg Nesterov wrote: > > static inline bool hrtimer_active(const struct timer *timer) > { > return timer->state != HRTIMER_STATE_INACTIVE || > timer->base->cpu_base->running == timer; > } > > Is that is can indeed return false falsely. Yes sure, this is obviously buggy. But again, only because "false falsely" is wrong. OK, I see other emails from you, lets discuss this problem there. > > > + } while (read_seqcount_retry(&cpu_base->seq, seq) || > > > + cpu_base != READ_ONCE(timer->base->cpu_base)); > > > > Why do we need to re-check >cpu_base? > > Because each CPU's cpu_base has independent seq numbers, so if the timer > migrates, the seq numbers might align just so that we fail to detect > change, even though there was -- extremely unlikely, but possible. Of course. However. I am not sure, but it seems to me that a) seq numbers can't really help exactly because we ran read the wrong base, and b) we can rely on QUEUED check. I'll send another email, but see also below. > > 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. > > I must ask for a little clarification; is this the simple: > > ->function() > hrtimer_forward_now(&self, timeout); > return HRTIMER_RESTART; > > Or something that 'randomly' calls: > > hrtimer_start() on a timer? The latter, > Because for the latter this isn't currently true for the same reason as > you give here: > > > 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 Ah, indeed, I misread this code. So the code is already buggy. > > 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. Yes. If we know that the timer always rearns itself then hrtimer_active() must be always true. A "random" hrtimer_start() on this timer must not create an "inactive" window. So we should probably fix this in any case. And migrate_hrtimer_list() too. And (it seems) this can help to simplify hrtimer_inactive(). Oleg. -- 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/