Jan Kiszka : cobalt/timer: Make xntimer_get_overruns robust against stopped timers
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 34 lines · git repository hosting
Module: xenomai-jki Branch: for-forge Commit: 8e6d76e07af74056f6cb4d8cfb192485d07732f7 URL: http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=8e6d76e07af74056f6cb4d8cfb192485d07732f7Author: Jan Kiszka <[email protected]> Date: Wed Feb 24 21:44:41 2016 +0100cobalt/timer: Make
xntimer_get_overrunsrobust against stopped timers
xntimer_get_overrunsmight be called on meanwhile stopped timers, specifically bycobalt_timer_deliver. We crash if we try to dequeue a stopped timer, and we should not restart it as well.Signed-off-by Jan Kiszka <[email protected]>---
kernel/cobalt/timer.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)kernel/cobalt/timer.c +0
-5@@ -602,13 +602,15 @@ unsigned long long xntimer_get_overruns(struct xntimer *timer, xnticks_t now) overruns =xnarch_div64 (delta, period); timer->pexpect_ticks += overruns; - q =xntimer_percpu_queue (timer); -xntimer_dequeue (timer, q); -while (xntimerh_date (&timer->aplink) < now) { - timer->periodic_ticks++; -xntimer_update_date (timer);
kernel/cobalt/timer.c unsigned long long xntimer_get_overruns(struct xntimer *timer, xnticks_t now) · line 611
Quoted 10 lines
kernel/cobalt/timer.c +8
-1+if (xntimer_running_p (timer)) { + q =xntimer_percpu_queue (timer); +xntimer_dequeue (timer, q); +while (xntimerh_date (&timer->aplink) < now) { + timer->periodic_ticks++; +xntimer_update_date (timer); + } +xntimer_enqueue_and_program (timer, q); } -xntimer_enqueue_and_program (timer, q);
This looks wrong. xntimer_get_overruns should not be called on a stopped timer. We want the caller to return an error if called on a stopped timer, not the condition being silently ignored.
Signature · 2 lines
Gilles. https://click-hack.org
Quoted 41 lines · Gilles Chanteperdrix
Quoted 40 lines · git repository hosting
Module: xenomai-jki Branch: for-forge Commit: 8e6d76e07af74056f6cb4d8cfb192485d07732f7 URL: http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=8e6d76e07af74056f6cb4d8cfb192485d07732f7Author: Jan Kiszka <[email protected]> Date: Wed Feb 24 21:44:41 2016 +0100cobalt/timer: Make
xntimer_get_overrunsrobust against stopped timers
xntimer_get_overrunsmight be called on meanwhile stopped timers, specifically bycobalt_timer_deliver. We crash if we try to dequeue a stopped timer, and we should not restart it as well.Signed-off-by Jan Kiszka <[email protected]>---
kernel/cobalt/timer.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)kernel/cobalt/timer.c +6
-5@@ -602,13 +602,15 @@ unsigned long long xntimer_get_overruns(struct xntimer *timer, xnticks_t now) overruns =xnarch_div64 (delta, period); timer->pexpect_ticks += overruns; - q =xntimer_percpu_queue (timer); -xntimer_dequeue (timer, q); -while (xntimerh_date (&timer->aplink) < now) { - timer->periodic_ticks++; -xntimer_update_date (timer); +if (xntimer_running_p (timer)) { + q =xntimer_percpu_queue (timer); +xntimer_dequeue (timer, q); +while (xntimerh_date (&timer->aplink) < now) { + timer->periodic_ticks++; +xntimer_update_date (timer);
Quoted 8 lines
kernel/cobalt/timer.c unsigned long long xntimer_get_overruns(struct xntimer *timer, xnticks_t now) · line 611
Quoted 4 lines
kernel/cobalt/timer.c +2
-1+ } +xntimer_enqueue_and_program (timer, q); } -xntimer_enqueue_and_program (timer, q);This looks wrong.
xntimer_get_overrunsshould not be called on a stopped timer. We want the caller to return an error if called on a stopped timer, not the condition being silently ignored.
The pattern that should trigger this (only tried with custom clocks so far):
- let a periodic timer send a signal
- block the signal so that it is queued
- stop the timer (timer_settime(0))
- process the signal (sigwait)
I don't see why the latter call should fail and not retrieve the queued signals.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA ITP SES-DE Corporate Competence Center Embedded Linux
Quoted 53 lines · Jan Kiszka
Quoted 41 lines · Gilles Chanteperdrix
Quoted 40 lines · git repository hosting
Module: xenomai-jki Branch: for-forge Commit: 8e6d76e07af74056f6cb4d8cfb192485d07732f7 URL: http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=8e6d76e07af74056f6cb4d8cfb192485d07732f7Author: Jan Kiszka <[email protected]> Date: Wed Feb 24 21:44:41 2016 +0100cobalt/timer: Make
xntimer_get_overrunsrobust against stopped timers
xntimer_get_overrunsmight be called on meanwhile stopped timers, specifically bycobalt_timer_deliver. We crash if we try to dequeue a stopped timer, and we should not restart it as well.Signed-off-by Jan Kiszka <[email protected]>---
kernel/cobalt/timer.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)kernel/cobalt/timer.c +6
-5@@ -602,13 +602,15 @@ unsigned long long xntimer_get_overruns(struct xntimer *timer, xnticks_t now) overruns =xnarch_div64 (delta, period); timer->pexpect_ticks += overruns; - q =xntimer_percpu_queue (timer); -xntimer_dequeue (timer, q); -while (xntimerh_date (&timer->aplink) < now) { - timer->periodic_ticks++; -xntimer_update_date (timer); +if (xntimer_running_p (timer)) { + q =xntimer_percpu_queue (timer); +xntimer_dequeue (timer, q); +while (xntimerh_date (&timer->aplink) < now) { + timer->periodic_ticks++; +xntimer_update_date (timer);Quoted 8 lines
kernel/cobalt/timer.c unsigned long long xntimer_get_overruns(struct xntimer *timer, xnticks_t now) · line 611
Quoted 4 lines
kernel/cobalt/timer.c +2
-1+ } +xntimer_enqueue_and_program (timer, q); } -xntimer_enqueue_and_program (timer, q);This looks wrong.
xntimer_get_overrunsshould not be called on a stopped timer. We want the caller to return an error if called on a stopped timer, not the condition being silently ignored.The pattern that should trigger this (only tried with custom clocks so far):
Quoted 7 lines
- let a periodic timer send a signal
- block the signal so that it is queued
- stop the timer (timer_settime(0))
- process the signal (sigwait)I don't see why the latter call should fail and not retrieve the queued signals.
Ok, but with your patch periodic_ticks no longer gets incremented in that case, which looks wrong to me.
Signature · 2 lines
Gilles. https://click-hack.org
Quoted 59 lines · Gilles Chanteperdrix
Quoted 58 lines · Jan Kiszka
Quoted 41 lines · Gilles Chanteperdrix
Quoted 40 lines · git repository hosting
Module: xenomai-jki Branch: for-forge Commit: 8e6d76e07af74056f6cb4d8cfb192485d07732f7 URL: http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=8e6d76e07af74056f6cb4d8cfb192485d07732f7Author: Jan Kiszka <[email protected]> Date: Wed Feb 24 21:44:41 2016 +0100cobalt/timer: Make
xntimer_get_overrunsrobust against stopped timers
xntimer_get_overrunsmight be called on meanwhile stopped timers, specifically bycobalt_timer_deliver. We crash if we try to dequeue a stopped timer, and we should not restart it as well.Signed-off-by Jan Kiszka <[email protected]>---
kernel/cobalt/timer.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)kernel/cobalt/timer.c +6
-5@@ -602,13 +602,15 @@ unsigned long long xntimer_get_overruns(struct xntimer *timer, xnticks_t now) overruns =xnarch_div64 (delta, period); timer->pexpect_ticks += overruns; - q =xntimer_percpu_queue (timer); -xntimer_dequeue (timer, q); -while (xntimerh_date (&timer->aplink) < now) { - timer->periodic_ticks++; -xntimer_update_date (timer); +if (xntimer_running_p (timer)) { + q =xntimer_percpu_queue (timer); +xntimer_dequeue (timer, q); +while (xntimerh_date (&timer->aplink) < now) { + timer->periodic_ticks++; +xntimer_update_date (timer);Quoted 8 lines
kernel/cobalt/timer.c unsigned long long xntimer_get_overruns(struct xntimer *timer, xnticks_t now) · line 611
Quoted 4 lines
kernel/cobalt/timer.c +2
-1+ } +xntimer_enqueue_and_program (timer, q); } -xntimer_enqueue_and_program (timer, q);This looks wrong.
xntimer_get_overrunsshould not be called on a stopped timer. We want the caller to return an error if called on a stopped timer, not the condition being silently ignored.The pattern that should trigger this (only tried with custom clocks so far):
- let a periodic timer send a signal
- block the signal so that it is queued
- stop the timer (timer_settime(0))
- process the signal (sigwait)
Quoted 6 lines
Quoted 2 lines
I don't see why the latter call should fail and not retrieve the queued signals.
Ok, but with your patch
periodic_ticksno longer gets incremented in that case, which looks wrong to me.
To my understanding, we are only interested in the overruns in case of stopped timer. Isn't periodic_ticks reset again start?
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA ITP SES-DE Corporate Competence Center Embedded Linux
Quoted 63 lines · Jan Kiszka
Quoted 62 lines · Gilles Chanteperdrix
Quoted 60 lines · Jan Kiszka
Quoted 41 lines · Gilles Chanteperdrix
Quoted 40 lines · git repository hosting
Module: xenomai-jki Branch: for-forge Commit: 8e6d76e07af74056f6cb4d8cfb192485d07732f7 URL: http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=8e6d76e07af74056f6cb4d8cfb192485d07732f7Author: Jan Kiszka <[email protected]> Date: Wed Feb 24 21:44:41 2016 +0100cobalt/timer: Make
xntimer_get_overrunsrobust against stopped timers
xntimer_get_overrunsmight be called on meanwhile stopped timers, specifically bycobalt_timer_deliver. We crash if we try to dequeue a stopped timer, and we should not restart it as well.Signed-off-by Jan Kiszka <[email protected]>---
kernel/cobalt/timer.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)kernel/cobalt/timer.c +6
-5@@ -602,13 +602,15 @@ unsigned long long xntimer_get_overruns(struct xntimer *timer, xnticks_t now) overruns =xnarch_div64 (delta, period); timer->pexpect_ticks += overruns; - q =xntimer_percpu_queue (timer); -xntimer_dequeue (timer, q); -while (xntimerh_date (&timer->aplink) < now) { - timer->periodic_ticks++; -xntimer_update_date (timer); +if (xntimer_running_p (timer)) { + q =xntimer_percpu_queue (timer); +xntimer_dequeue (timer, q); +while (xntimerh_date (&timer->aplink) < now) { + timer->periodic_ticks++; +xntimer_update_date (timer);Quoted 8 lines
kernel/cobalt/timer.c unsigned long long xntimer_get_overruns(struct xntimer *timer, xnticks_t now) · line 611
Quoted 4 lines
kernel/cobalt/timer.c +2
-1+ } +xntimer_enqueue_and_program (timer, q); } -xntimer_enqueue_and_program (timer, q);This looks wrong.
xntimer_get_overrunsshould not be called on a stopped timer. We want the caller to return an error if called on a stopped timer, not the condition being silently ignored.The pattern that should trigger this (only tried with custom clocks so far):
- let a periodic timer send a signal
- block the signal so that it is queued
- stop the timer (timer_settime(0))
- process the signal (sigwait)I don't see why the latter call should fail and not retrieve the queued signals.
Quoted 6 lines
Quoted 3 lines
Ok, but with your patch
periodic_ticksno longer gets incremented in that case, which looks wrong to me.To my understanding, we are only interested in the overruns in case of stopped timer. Isn't
periodic_ticksreset again start?
I am not sure I understand your sentence. Both the POSIX timer interface and the Linux timerfd interface keep track of the overruns at each tick, so no, we are interested in the overruns for every tick.
The aim of this piece of code is to prevent xntimer_get_overruns to account twice for the same overrun. I am not sure I understand well enough the problem you are trying to avoid to know if yes or no, the date should be incremented, but it seems simple to keep the part that increments timer->perdiodic_ticks and only make the unqueue/requeue code conditional.
Signature · 2 lines
Gilles. https://click-hack.org
Quoted 76 lines · Gilles Chanteperdrix
Quoted 63 lines · Jan Kiszka
Quoted 62 lines · Gilles Chanteperdrix
Quoted 60 lines · Jan Kiszka
Quoted 41 lines · Gilles Chanteperdrix
Quoted 40 lines · git repository hosting
Module: xenomai-jki Branch: for-forge Commit: 8e6d76e07af74056f6cb4d8cfb192485d07732f7 URL: http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=8e6d76e07af74056f6cb4d8cfb192485d07732f7Author: Jan Kiszka <[email protected]> Date: Wed Feb 24 21:44:41 2016 +0100cobalt/timer: Make
xntimer_get_overrunsrobust against stopped timers
xntimer_get_overrunsmight be called on meanwhile stopped timers, specifically bycobalt_timer_deliver. We crash if we try to dequeue a stopped timer, and we should not restart it as well.Signed-off-by Jan Kiszka <[email protected]>---
kernel/cobalt/timer.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)kernel/cobalt/timer.c +6
-5@@ -602,13 +602,15 @@ unsigned long long xntimer_get_overruns(struct xntimer *timer, xnticks_t now) overruns =xnarch_div64 (delta, period); timer->pexpect_ticks += overruns; - q =xntimer_percpu_queue (timer); -xntimer_dequeue (timer, q); -while (xntimerh_date (&timer->aplink) < now) { - timer->periodic_ticks++; -xntimer_update_date (timer); +if (xntimer_running_p (timer)) { + q =xntimer_percpu_queue (timer); +xntimer_dequeue (timer, q); +while (xntimerh_date (&timer->aplink) < now) { + timer->periodic_ticks++; +xntimer_update_date (timer);Quoted 8 lines
kernel/cobalt/timer.c unsigned long long xntimer_get_overruns(struct xntimer *timer, xnticks_t now) · line 611
Quoted 4 lines
kernel/cobalt/timer.c +2
-1+ } +xntimer_enqueue_and_program (timer, q); } -xntimer_enqueue_and_program (timer, q);This looks wrong.
xntimer_get_overrunsshould not be called on a stopped timer. We want the caller to return an error if called on a stopped timer, not the condition being silently ignored.The pattern that should trigger this (only tried with custom clocks so far):
- let a periodic timer send a signal
- block the signal so that it is queued
- stop the timer (timer_settime(0))
- process the signal (sigwait)I don't see why the latter call should fail and not retrieve the queued signals.
Quoted 6 lines
Quoted 3 lines
Ok, but with your patch
periodic_ticksno longer gets incremented in that case, which looks wrong to me.To my understanding, we are only interested in the overruns in case of stopped timer. Isn't
periodic_ticksreset again start?I am not sure I understand your sentence. Both the POSIX timer interface and the Linux timerfd interface keep track of the overruns at each tick, so no, we are interested in the overruns for every tick.
Quoted 6 lines
The aim of this piece of code is to prevent
xntimer_get_overrunsto account twice for the same overrun. I am not sure I understand well enough the problem you are trying to avoid to know if yes or no, the date should be incremented, but it seems simple to keep the part that incrementstimer->perdiodic_ticksand only make the unqueue/requeue code conditional.
The timer is stopped in the case the change covers, so periodic_ticks plays no role any more until the timer is restart - in which case periodic_ticks is reset anyway.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA ITP SES-DE Corporate Competence Center Embedded Linux
Quoted 84 lines · Jan Kiszka
Quoted 76 lines · Gilles Chanteperdrix
Quoted 63 lines · Jan Kiszka
Quoted 62 lines · Gilles Chanteperdrix
Quoted 60 lines · Jan Kiszka
Quoted 41 lines · Gilles Chanteperdrix
Quoted 40 lines · git repository hosting
Module: xenomai-jki Branch: for-forge Commit: 8e6d76e07af74056f6cb4d8cfb192485d07732f7 URL: http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=8e6d76e07af74056f6cb4d8cfb192485d07732f7Author: Jan Kiszka <[email protected]> Date: Wed Feb 24 21:44:41 2016 +0100cobalt/timer: Make
xntimer_get_overrunsrobust against stopped timers
xntimer_get_overrunsmight be called on meanwhile stopped timers, specifically bycobalt_timer_deliver. We crash if we try to dequeue a stopped timer, and we should not restart it as well.Signed-off-by Jan Kiszka <[email protected]>---
kernel/cobalt/timer.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)kernel/cobalt/timer.c +6
-5@@ -602,13 +602,15 @@ unsigned long long xntimer_get_overruns(struct xntimer *timer, xnticks_t now) overruns =xnarch_div64 (delta, period); timer->pexpect_ticks += overruns; - q =xntimer_percpu_queue (timer); -xntimer_dequeue (timer, q); -while (xntimerh_date (&timer->aplink) < now) { - timer->periodic_ticks++; -xntimer_update_date (timer); +if (xntimer_running_p (timer)) { + q =xntimer_percpu_queue (timer); +xntimer_dequeue (timer, q); +while (xntimerh_date (&timer->aplink) < now) { + timer->periodic_ticks++; +xntimer_update_date (timer);Quoted 8 lines
kernel/cobalt/timer.c unsigned long long xntimer_get_overruns(struct xntimer *timer, xnticks_t now) · line 611
Quoted 4 lines
kernel/cobalt/timer.c +2
-1+ } +xntimer_enqueue_and_program (timer, q); } -xntimer_enqueue_and_program (timer, q);This looks wrong.
xntimer_get_overrunsshould not be called on a stopped timer. We want the caller to return an error if called on a stopped timer, not the condition being silently ignored.The pattern that should trigger this (only tried with custom clocks so far):
- let a periodic timer send a signal
- block the signal so that it is queued
- stop the timer (timer_settime(0))
- process the signal (sigwait)I don't see why the latter call should fail and not retrieve the queued signals.
Quoted 6 lines
Quoted 3 lines
Ok, but with your patch
periodic_ticksno longer gets incremented in that case, which looks wrong to me.To my understanding, we are only interested in the overruns in case of stopped timer. Isn't
periodic_ticksreset again start?I am not sure I understand your sentence. Both the POSIX timer interface and the Linux timerfd interface keep track of the overruns at each tick, so no, we are interested in the overruns for every tick.
Quoted 6 lines
The aim of this piece of code is to prevent
xntimer_get_overrunsto account twice for the same overrun. I am not sure I understand well enough the problem you are trying to avoid to know if yes or no, the date should be incremented, but it seems simple to keep the part that incrementstimer->perdiodic_ticksand only make the unqueue/requeue code conditional.
Quoted 3 lines
The timer is stopped in the case the change covers, so
periodic_ticksplays no role any more until the timer is restart - in which caseperiodic_ticksis reset anyway.
I am OK with the patch.
Signature · 2 lines
Gilles. https://click-hack.org
Quoted 85 lines · Gilles Chanteperdrix
Quoted 84 lines · Jan Kiszka
Quoted 82 lines · Gilles Chanteperdrix
Quoted 63 lines · Jan Kiszka
Quoted 62 lines · Gilles Chanteperdrix
Quoted 60 lines · Jan Kiszka
Quoted 41 lines · Gilles Chanteperdrix
Quoted 40 lines · git repository hosting
Module: xenomai-jki Branch: for-forge Commit: 8e6d76e07af74056f6cb4d8cfb192485d07732f7 URL: http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=8e6d76e07af74056f6cb4d8cfb192485d07732f7Author: Jan Kiszka <[email protected]> Date: Wed Feb 24 21:44:41 2016 +0100cobalt/timer: Make
xntimer_get_overrunsrobust against stopped timers
xntimer_get_overrunsmight be called on meanwhile stopped timers, specifically bycobalt_timer_deliver. We crash if we try to dequeue a stopped timer, and we should not restart it as well.Signed-off-by Jan Kiszka <[email protected]>---
kernel/cobalt/timer.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)kernel/cobalt/timer.c +6
-5@@ -602,13 +602,15 @@ unsigned long long xntimer_get_overruns(struct xntimer *timer, xnticks_t now) overruns =xnarch_div64 (delta, period); timer->pexpect_ticks += overruns; - q =xntimer_percpu_queue (timer); -xntimer_dequeue (timer, q); -while (xntimerh_date (&timer->aplink) < now) { - timer->periodic_ticks++; -xntimer_update_date (timer); +if (xntimer_running_p (timer)) { + q =xntimer_percpu_queue (timer); +xntimer_dequeue (timer, q); +while (xntimerh_date (&timer->aplink) < now) { + timer->periodic_ticks++; +xntimer_update_date (timer);Quoted 8 lines
kernel/cobalt/timer.c unsigned long long xntimer_get_overruns(struct xntimer *timer, xnticks_t now) · line 611
Quoted 4 lines
kernel/cobalt/timer.c +2
-1+ } +xntimer_enqueue_and_program (timer, q); } -xntimer_enqueue_and_program (timer, q);This looks wrong.
xntimer_get_overrunsshould not be called on a stopped timer. We want the caller to return an error if called on a stopped timer, not the condition being silently ignored.The pattern that should trigger this (only tried with custom clocks so far):
- let a periodic timer send a signal
- block the signal so that it is queued
- stop the timer (timer_settime(0))
- process the signal (sigwait)I don't see why the latter call should fail and not retrieve the queued signals.
Quoted 6 lines
Quoted 3 lines
Ok, but with your patch
periodic_ticksno longer gets incremented in that case, which looks wrong to me.To my understanding, we are only interested in the overruns in case of stopped timer. Isn't
periodic_ticksreset again start?I am not sure I understand your sentence. Both the POSIX timer interface and the Linux timerfd interface keep track of the overruns at each tick, so no, we are interested in the overruns for every tick.
The aim of this piece of code is to prevent
xntimer_get_overrunsto account twice for the same overrun. I am not sure I understand well enough the problem you are trying to avoid to know if yes or no, the date should be incremented, but it seems simple to keep the part that incrementstimer->perdiodic_ticksand only make the unqueue/requeue code conditional.
Quoted 6 lines
Quoted 3 lines
The timer is stopped in the case the change covers, so
periodic_ticksplays no role any more until the timer is restart - in which caseperiodic_ticksis reset anyway.I am OK with the patch.
Thanks for the thorough review!
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA ITP SES-DE Corporate Competence Center Embedded Linux