public inbox for linux-rt-users@vger.kernel.org
 help / color / mirror / Atom feed
* Problem with hrtimer_cancel() does not cancel timer
@ 2017-02-17 22:15 Alexander Gerasiov
  2017-02-21 14:15 ` Dmitry
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Alexander Gerasiov @ 2017-02-17 22:15 UTC (permalink / raw)
  To: linux-rt-users; +Cc: zlobin_d

Hello folks,

I met some problem with preempt version of kernel 4.4.

I have hrtimer which runs callback, it forwards time and returns
HRTIMER_RESTART. Very common scheme. When I stop the routine I call
hrtimer_cancel(). It should wait for callback completion if any and
unqueue any future timers.

But suddenly I noticed, that sometimes hrtimer's routine continue to
work and work after hrtimer_cancel(). It could be reproduced with simple
test:

Start hrtimer.
In callback increase counter and restart.
In the other thread cancel timer, save counter, sleep, check that
counter is not changed, restart timer, repeat.
Here is sample module:
https://gist.github.com/gerasiov/010e6c2cb96fd891c1802facf816fe84

It works OK on v3.10.74-rt79 with PREEMPL FULL.
It works OK on v4.4.47-rt59 with preempt patch but PREEMPT NONE.
But on 4.4 (tested on v4.4.47-rt59 and v4.4.32-rt43) with PREEMPT FULL
it fails: counter continue to increase (BUG_ON() line 45 hits), that
means that hrtimer continue to work after cancel(). And I must say,
that this is not single iteration, it continues to work in cycle.

It was reproduced on i386 SMP box.
kernel config:
https://github.com/redlab-i/linux/blob/v4.4.47-rt59-stand2/.config

Do anyone have any ideas where could be the problem? Or may be I missed
something in my research?

-- 
Best regards,
 Alexander Gerasiov

 Contacts:
 e-mail: gq@cs.msu.su  Homepage: http://gerasiov.net  Skype: gerasiov
 PGP fingerprint: 04B5 9D90 DF7C C2AB CD49  BAEA CA87 E9E8 2AAC 33F1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Problem with hrtimer_cancel() does not cancel timer
  2017-02-17 22:15 Problem with hrtimer_cancel() does not cancel timer Alexander Gerasiov
@ 2017-02-21 14:15 ` Dmitry
  2017-02-28 13:02 ` Alexander Gerasiov
  2017-03-01 15:01 ` Sebastian Andrzej Siewior
  2 siblings, 0 replies; 6+ messages in thread
From: Dmitry @ 2017-02-21 14:15 UTC (permalink / raw)
  To: Alexander Gerasiov; +Cc: linux-rt-users

On v4.9.11-rt9 with PREEMPT FULL this test also fails.

On Sat, 18 Feb 2017 01:15:22 +0300
Alexander Gerasiov <gq@cs.msu.su> wrote:

> Hello folks,
> 
> I met some problem with preempt version of kernel 4.4.
> 
> I have hrtimer which runs callback, it forwards time and returns
> HRTIMER_RESTART. Very common scheme. When I stop the routine I call
> hrtimer_cancel(). It should wait for callback completion if any and
> unqueue any future timers.
> 
> But suddenly I noticed, that sometimes hrtimer's routine continue to
> work and work after hrtimer_cancel(). It could be reproduced with
> simple test:
> 
> Start hrtimer.
> In callback increase counter and restart.
> In the other thread cancel timer, save counter, sleep, check that
> counter is not changed, restart timer, repeat.
> Here is sample module:
> https://gist.github.com/gerasiov/010e6c2cb96fd891c1802facf816fe84
> 
> It works OK on v3.10.74-rt79 with PREEMPL FULL.
> It works OK on v4.4.47-rt59 with preempt patch but PREEMPT NONE.
> But on 4.4 (tested on v4.4.47-rt59 and v4.4.32-rt43) with PREEMPT FULL
> it fails: counter continue to increase (BUG_ON() line 45 hits), that
> means that hrtimer continue to work after cancel(). And I must say,
> that this is not single iteration, it continues to work in cycle.
> 
> It was reproduced on i386 SMP box.
> kernel config:
> https://github.com/redlab-i/linux/blob/v4.4.47-rt59-stand2/.config
> 
> Do anyone have any ideas where could be the problem? Or may be I
> missed something in my research?
> 

-- 
Best regards,
 Dmitry Zlobin

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Problem with hrtimer_cancel() does not cancel timer
  2017-02-17 22:15 Problem with hrtimer_cancel() does not cancel timer Alexander Gerasiov
  2017-02-21 14:15 ` Dmitry
@ 2017-02-28 13:02 ` Alexander Gerasiov
  2017-03-01 15:01 ` Sebastian Andrzej Siewior
  2 siblings, 0 replies; 6+ messages in thread
From: Alexander Gerasiov @ 2017-02-28 13:02 UTC (permalink / raw)
  To: linux-rt-users; +Cc: zlobin_d

Hello Alexander,

On Sat, 18 Feb 2017 01:15:22 +0300
Alexander Gerasiov <gq@cs.msu.su> wrote:

> Hello folks,
> 
> I met some problem with preempt version of kernel 4.4.
> 
> I have hrtimer which runs callback, it forwards time and returns
> HRTIMER_RESTART. Very common scheme. When I stop the routine I call
> hrtimer_cancel(). It should wait for callback completion if any and
> unqueue any future timers.
> 
> But suddenly I noticed, that sometimes hrtimer's routine continue to
> work and work after hrtimer_cancel(). It could be reproduced with
> simple test:

So guys, did anybody reproduce this problem?
If no, could you provide more info on your config?
If yes, do anyone work on the problem or we need to deal with it
ourselves?




-- 
Best regards,
 Alexander Gerasiov

 Contacts:
 e-mail: gq@cs.msu.su  Homepage: http://gerasiov.net  Skype: gerasiov
 PGP fingerprint: 04B5 9D90 DF7C C2AB CD49  BAEA CA87 E9E8 2AAC 33F1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Problem with hrtimer_cancel() does not cancel timer
  2017-02-17 22:15 Problem with hrtimer_cancel() does not cancel timer Alexander Gerasiov
  2017-02-21 14:15 ` Dmitry
  2017-02-28 13:02 ` Alexander Gerasiov
@ 2017-03-01 15:01 ` Sebastian Andrzej Siewior
  2017-03-01 23:48   ` Alexander Gerasiov
  2 siblings, 1 reply; 6+ messages in thread
From: Sebastian Andrzej Siewior @ 2017-03-01 15:01 UTC (permalink / raw)
  To: Alexander Gerasiov; +Cc: linux-rt-users, zlobin_d

On 2017-02-18 01:15:22 [+0300], Alexander Gerasiov wrote:
> Hello folks,
Hi,

> I met some problem with preempt version of kernel 4.4.
> 
> I have hrtimer which runs callback, it forwards time and returns
> HRTIMER_RESTART. Very common scheme. When I stop the routine I call
> hrtimer_cancel(). It should wait for callback completion if any and
> unqueue any future timers.

Could you please check if the hunk here fixes the problem you see?

diff --git a/include/linux/hrtimer.h b/include/linux/hrtimer.h
--- a/include/linux/hrtimer.h
+++ b/include/linux/hrtimer.h
@@ -455,7 +455,10 @@ static inline int hrtimer_is_queued(struct hrtimer *timer)
  */
 static inline int hrtimer_callback_running(const struct hrtimer *timer)
 {
-	return timer->base->cpu_base->running == timer;
+	if ((timer->base->cpu_base->running == timer) ||
+	    (timer->base->cpu_base->running_soft == timer))
+		return 1;
+	return 0;
 }
 
 /* Forward a hrtimer so it expires after now: */

Sebastian

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Problem with hrtimer_cancel() does not cancel timer
  2017-03-01 15:01 ` Sebastian Andrzej Siewior
@ 2017-03-01 23:48   ` Alexander Gerasiov
  2017-03-02  8:19     ` Sebastian Andrzej Siewior
  0 siblings, 1 reply; 6+ messages in thread
From: Alexander Gerasiov @ 2017-03-01 23:48 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior; +Cc: linux-rt-users, zlobin_d

Hello Sebastian,

On Wed, 1 Mar 2017 16:01:04 +0100
Sebastian Andrzej Siewior <bigeasy@linutronix.de> wrote:

> On 2017-02-18 01:15:22 [+0300], Alexander Gerasiov wrote:
> > Hello folks,  
> Hi,
> 
> > I met some problem with preempt version of kernel 4.4.
> > 
> > I have hrtimer which runs callback, it forwards time and returns
> > HRTIMER_RESTART. Very common scheme. When I stop the routine I call
> > hrtimer_cancel(). It should wait for callback completion if any and
> > unqueue any future timers.  
> 
> Could you please check if the hunk here fixes the problem you see?

Great! Looks like the problem is solved.

When submitting patch to git, take a note, that not only 4.4 is
affected. I'm quite sure, that 4.1 was affected too when I tested it and
Dmitry comfirmed 4.9 is also broken.

-- 
Best regards,
 Alexander Gerasiov

 Contacts:
 e-mail: gq@cs.msu.su  Homepage: http://gerasiov.net  Skype: gerasiov
 PGP fingerprint: 04B5 9D90 DF7C C2AB CD49  BAEA CA87 E9E8 2AAC 33F1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Problem with hrtimer_cancel() does not cancel timer
  2017-03-01 23:48   ` Alexander Gerasiov
@ 2017-03-02  8:19     ` Sebastian Andrzej Siewior
  0 siblings, 0 replies; 6+ messages in thread
From: Sebastian Andrzej Siewior @ 2017-03-02  8:19 UTC (permalink / raw)
  To: Alexander Gerasiov; +Cc: linux-rt-users, zlobin_d

On 2017-03-02 02:48:08 [+0300], Alexander Gerasiov wrote:
> Hello Sebastian,
Hi Alexander,

> Great! Looks like the problem is solved.

Thanks for the confirmation.

> When submitting patch to git, take a note, that not only 4.4 is
> affected. I'm quite sure, that 4.1 was affected too when I tested it and
> Dmitry comfirmed 4.9 is also broken.

I am going to push it to v4.9 and Steven will pull into v4.4 while doing
his regular stable updates. v4.8 is probably also affected but that one
is no longer maintained.

Sebastian

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-03-02  9:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-17 22:15 Problem with hrtimer_cancel() does not cancel timer Alexander Gerasiov
2017-02-21 14:15 ` Dmitry
2017-02-28 13:02 ` Alexander Gerasiov
2017-03-01 15:01 ` Sebastian Andrzej Siewior
2017-03-01 23:48   ` Alexander Gerasiov
2017-03-02  8:19     ` Sebastian Andrzej Siewior

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox