Skip to contentSkip to conversation

issue with cobalt/timer: avoid periodic timer drift

Xenomai Matthias Schneider 3 participants 12 messages Jul 6, 2014

lore
Share & tools
lore
#0 lore raw

Hi all,

commit

2014-06-02 c20fceb147e337e2379b29ecd81b943318c7fbc7 (patch) cobalt/timer: avoid periodic timer drift

seems to cause an endless kernel loop in one of my freertos demos. The issue does not occur when reverting this commit.

Investigating the issue, can see the following:

#0 0xc00ba45c in mach_arm_nodiv_llimd (rhs_integ=<optimized out>, frac=<optimized out>, op=<optimized out>) at arch/arm/xenomai/include/asm/xenomai/uapi/arith.h:120
#1 xnclock_core_ns_to_ticks (ns=0) at kernel/xenomai/clock.c:52
#2 0xc00baf34 in xnclock_ns_to_ticks (clock=<optimized out>, ns=<optimized out>)
    at include/xenomai/cobalt/kernel/clock.h:204

#3  xntimer_update_date (timer=0xde706518) at include/xenomai/cobalt/kernel/timer.h:268
#4  xnclock_tick (clock=0xc06b1138 <nkclock>) at kernel/xenomai/clock.c:644
#5  0xc00bcbcc in xnintr_core_clock_handler () at kernel/xenomai/intr.c:121
#6  0xc0095a98 in dispatch_irq_head (irq=<optimized out>) at kernel/ipipe/core.c:1179

This seems to be the endless loop:
642 do {
643      timer->periodic_ticks += interval_ticks;
644      xntimer_update_date(timer);
645 } while (xntimerh_date(&timer->aplink) < now + clock->gravity);

gdb) info locals
timerq = 0xdebdae98
now = 4257712977
interval_ticks = 0
timer = 0xde706518
delta = <optimized out>
h = 0xde706518

(gdb) print *timer
$1 = {
  aplink = {
    link = {
      next = 0x100100,
      prev = 0x200200
    },
    key = 0,
    prio = 999999999
  },
  adjlink = {
    next = 0x0 <__vectors_start>,
    prev = 0x0 <__vectors_start>
  },
  status = 1,
  interval = 0,
  interval_ns = 0,
  periodic_ticks = 0,
  start_date = 0,
  pexpect_ticks = 0,
  sched = 0xc06b1610 <nksched>,
  handler = 0xc00c7dc4 <timeout_handler>, name = "CREATOR", '\000' <repeats 24 times>, handler_name = 0xc05ad429 "timeout_handler", next_stat = {
    next = 0xde706624,
    prev = 0xde705c24
  },
  scheduled = {
    counter = 3
  },
  fired = {
    counter = 1
  }
}
(gdb) print *clock
$2 = {
  wallclock_offset = 200209,
  resolution = 1,
  gravity = 140,
  name = 0xc05ac815 "coreclk",
  timerdata = 0xdebdae98,
  id = -1,
  vfile = {
    entry = {
      pde = 0xde1b8700,
      file = 0x0 <__vectors_start>, lockops = 0xc06b2c20 <xnvfile_nucleus_lock>, refcnt = 0,
      private = 0xc06b1138 <nkclock>
    },
    privsz = 4,
    datasz = 104,
    tag = 0xc06b117c <nkclock+68>,
    ops = 0xc06b1120 <vfile_clock_ops>
  },
  revtag = {
    rev = 36
  },
  statq = {
    next = 0xc06b18d4 <nksched+708>,
    prev = 0xde706e24
  },
  nrtimers = 24
}

Does anyone see right away what is going on wrong
or shall I continue investigating the issue?

Regards,
Matthias

#1 lore raw
Quoted 103 lines · Matthias Schneider

Hi all,

commit

2014-06-02 c20fceb147e337e2379b29ecd81b943318c7fbc7 (patch) cobalt/timer: avoid periodic timer drift

seems to cause an endless kernel loop in one of my freertos demos. The issue does not occur when reverting this commit.

Investigating the issue, can see the following:

#0 0xc00ba45c in mach_arm_nodiv_llimd (rhs_integ=<optimized out>, frac=<optimized out>, op=<optimized out>)
at arch/arm/xenomai/include/asm/xenomai/uapi/arith.h:120
#1 xnclock_core_ns_to_ticks (ns=0) at kernel/xenomai/clock.c:52
#2 0xc00baf34 in xnclock_ns_to_ticks (clock=<optimized out>, ns=<optimized out>)
at include/xenomai/cobalt/kernel/clock.h:204

#3  xntimer_update_date (timer=0xde706518) at include/xenomai/cobalt/kernel/timer.h:268
#4  xnclock_tick (clock=0xc06b1138 <nkclock>) at kernel/xenomai/clock.c:644
#5  0xc00bcbcc in xnintr_core_clock_handler () at kernel/xenomai/intr.c:121
#6  0xc0095a98 in dispatch_irq_head (irq=<optimized out>) at kernel/ipipe/core.c:1179

This seems to be the endless loop:
642 do {
643 timer->periodic_ticks += interval_ticks;
644 xntimer_update_date(timer);
645 } while (xntimerh_date(&timer->aplink) < now + clock->gravity);

gdb) info locals
timerq = 0xdebdae98
now = 4257712977
interval_ticks = 0
timer = 0xde706518
delta = <optimized out>
h = 0xde706518

(gdb) print *timer

$1 = {
   aplink = {
     link = {
       next = 0x100100,
       prev = 0x200200
     },
     key = 0,
     prio = 999999999
   },
   adjlink = {
     next = 0x0 <__vectors_start>,
     prev = 0x0 <__vectors_start>
   },
   status = 1,
   interval = 0,
   interval_ns = 0,
   periodic_ticks = 0,
   start_date = 0,
   pexpect_ticks = 0,
   sched = 0xc06b1610 <nksched>,
   handler = 0xc00c7dc4 <timeout_handler>,
   name = "CREATOR", '\000' <repeats 24 times>,
   handler_name = 0xc05ad429 "timeout_handler",
   next_stat = {
     next = 0xde706624,
     prev = 0xde705c24
   },
   scheduled = {
     counter = 3
   },
   fired = {
     counter = 1
   }
}
(gdb) print *clock
$2 = {
   wallclock_offset = 200209,
   resolution = 1,
   gravity = 140,
   name = 0xc05ac815 "coreclk",
   timerdata = 0xdebdae98,
   id = -1,
   vfile = {
     entry = {
       pde = 0xde1b8700,
       file = 0x0 <__vectors_start>,
       lockops = 0xc06b2c20 <xnvfile_nucleus_lock>,
       refcnt = 0,
       private = 0xc06b1138 <nkclock>
     },
     privsz = 4,
     datasz = 104,
     tag = 0xc06b117c <nkclock+68>,
     ops = 0xc06b1120 <vfile_clock_ops>
   },
   revtag = {
     rev = 36
   },
   statq = {
     next = 0xc06b18d4 <nksched+708>,
     prev = 0xde706e24
   },
   nrtimers = 24
}
Quoted 3 lines

Does anyone see right away what is going on wrong
or shall I continue investigating the issue?

Assuming timer->interval_ns can't be null as the timer is deemed periodic, there must be something wrong with how the elapsed count of periodic ticks is tracked. Gilles will likely have a look at this when time allows.

Signature · 1 line
Philippe.
#2 lore raw
In reply to Matthias Schneider
Quoted 99 lines · Matthias Schneider

Hi all,

commit

2014-06-02 c20fceb147e337e2379b29ecd81b943318c7fbc7 (patch) cobalt/timer: avoid periodic timer drift

seems to cause an endless kernel loop in one of my freertos demos. The issue does not occur when reverting this commit.

Investigating the issue, can see the following:

#0 0xc00ba45c in mach_arm_nodiv_llimd (rhs_integ=<optimized out>, frac=<optimized out>, op=<optimized out>)
at arch/arm/xenomai/include/asm/xenomai/uapi/arith.h:120
#1 xnclock_core_ns_to_ticks (ns=0) at kernel/xenomai/clock.c:52
#2 0xc00baf34 in xnclock_ns_to_ticks (clock=<optimized out>, ns=<optimized out>)
at include/xenomai/cobalt/kernel/clock.h:204

#3  xntimer_update_date (timer=0xde706518) at include/xenomai/cobalt/kernel/timer.h:268
#4  xnclock_tick (clock=0xc06b1138 <nkclock>) at kernel/xenomai/clock.c:644
#5  0xc00bcbcc in xnintr_core_clock_handler () at kernel/xenomai/intr.c:121
#6  0xc0095a98 in dispatch_irq_head (irq=<optimized out>) at kernel/ipipe/core.c:1179

This seems to be the endless loop:
642 do {
643 timer->periodic_ticks += interval_ticks;
644 xntimer_update_date(timer);
645 } while (xntimerh_date(&timer->aplink) < now + clock->gravity);

gdb) info locals
timerq = 0xdebdae98
now = 4257712977
interval_ticks = 0
timer = 0xde706518
delta = <optimized out>
h = 0xde706518

(gdb) print *timer
$1 = {

  aplink = {
    link = {
      next = 0x100100, 
      prev = 0x200200
    }, 
    key = 0, 
    prio = 999999999
  }, 
  adjlink = {
    next = 0x0 <__vectors_start>, 
    prev = 0x0 <__vectors_start>
  }, 
  status = 1, 
  interval = 0, 
  interval_ns = 0, 
  periodic_ticks = 0, 
  start_date = 0, 
  pexpect_ticks = 0, 
  sched = 0xc06b1610 <nksched>, 
  handler = 0xc00c7dc4 <timeout_handler>, 
  name = "CREATOR", '\000' <repeats 24 times>, 
  handler_name = 0xc05ad429 "timeout_handler", 
  next_stat = {
    next = 0xde706624, 
    prev = 0xde705c24

},
scheduled = {
counter = 3
},
fired = {
counter = 1
}
}
(gdb) print *clock
$2 = {
wallclock_offset = 200209,
resolution = 1,
gravity = 140,
name = 0xc05ac815 "coreclk",
timerdata = 0xdebdae98,
id = -1,

  vfile = {
    entry = {
      pde = 0xde1b8700, 
      file = 0x0 <__vectors_start>, 
      lockops = 0xc06b2c20 <xnvfile_nucleus_lock>, 
      refcnt = 0, 
      private = 0xc06b1138 <nkclock>
    }, 
    privsz = 4, 
    datasz = 104, 
    tag = 0xc06b117c <nkclock+68>, 
    ops = 0xc06b1120 <vfile_clock_ops>
  }, 
  revtag = {
    rev = 36
  }, 
  statq = {
    next = 0xc06b18d4 <nksched+708>, 
    prev = 0xde706e24
Quoted 6 lines

},
nrtimers = 24
}

Does anyone see right away what is going on wrong
or shall I continue investigating the issue?

You seem to have created a periodic timer with a null period. Could you post a sample code allowing to reproduce this issue?

Signature · 1 line
                                                                Gilles.
#3 lore raw

----- Original Message -----

Quoted 117 lines

From: Gilles Chanteperdrix <[email protected]>
To: Matthias Schneider <[email protected]>; "[email protected]" <[email protected]> Cc:
Sent: Sunday, July 6, 2014 5:01 PM
Subject: Re: [Xenomai] issue with cobalt/timer: avoid periodic timer drift

Quoted 7 lines · Matthias Schneider

Hi all,

commit

2014-06-02 c20fceb147e337e2379b29ecd81b943318c7fbc7 (patch) cobalt/timer: avoid periodic timer drift

Quoted 7 lines

seems to cause an endless kernel loop in one of my freertos demos. The issue does not occur when reverting this commit.

Investigating the issue, can see the following:

#0  0xc00ba45c in mach_arm_nodiv_llimd (rhs_integ=<optimized out>,

frac=<optimized out>, op=<optimized out>)

Quoted 3 lines
     at arch/arm/xenomai/include/asm/xenomai/uapi/arith.h:120
 #1  xnclock_core_ns_to_ticks (ns=0) at kernel/xenomai/clock.c:52
 #2  0xc00baf34 in xnclock_ns_to_ticks (clock=<optimized out>, 

ns=<optimized out>)

Quoted 2 lines
     at include/xenomai/cobalt/kernel/clock.h:204
 #3  xntimer_update_date (timer=0xde706518) at 

include/xenomai/cobalt/kernel/timer.h:268

Quoted 1 line

#4  xnclock_tick (clock=0xc06b1138 <nkclock>) at

kernel/xenomai/clock.c:644

Quoted 2 lines

#5  0xc00bcbcc in xnintr_core_clock_handler () at kernel/xenomai/intr.c:121 #6  0xc0095a98 in dispatch_irq_head (irq=<optimized out>) at

kernel/ipipe/core.c:1179

Quoted 6 lines

This seems to be the endless loop:
642                    do {
643      timer->periodic_ticks += interval_ticks;
644      xntimer_update_date(timer);
645                    } while (xntimerh_date(&timer->aplink) <

now + clock->gravity);

Quoted 75 lines

gdb) info locals
timerq = 0xdebdae98
now = 4257712977
interval_ticks = 0
timer = 0xde706518
delta = <optimized out>
h = 0xde706518

(gdb) print *timer
$1 = {
  aplink = {
    link = {
      next = 0x100100,
      prev = 0x200200
    },
    key = 0,
    prio = 999999999
  },
  adjlink = {
    next = 0x0 <__vectors_start>,
    prev = 0x0 <__vectors_start>
  },
  status = 1,
  interval = 0,
  interval_ns = 0,
  periodic_ticks = 0,
  start_date = 0,
  pexpect_ticks = 0,
  sched = 0xc06b1610 <nksched>,
  handler = 0xc00c7dc4 <timeout_handler>, name = "CREATOR", '\000' <repeats 24 times>, handler_name = 0xc05ad429 "timeout_handler", next_stat = {
    next = 0xde706624,
    prev = 0xde705c24
  },
  scheduled = {
    counter = 3
  },
  fired = {
    counter = 1
  }
}
(gdb) print *clock
$2 = {
  wallclock_offset = 200209,
  resolution = 1,
  gravity = 140,
  name = 0xc05ac815 "coreclk",
  timerdata = 0xdebdae98,
  id = -1,
  vfile = {
    entry = {
      pde = 0xde1b8700,
      file = 0x0 <__vectors_start>, lockops = 0xc06b2c20 <xnvfile_nucleus_lock>, refcnt = 0,
      private = 0xc06b1138 <nkclock>
    },
    privsz = 4,
    datasz = 104,
    tag = 0xc06b117c <nkclock+68>,
    ops = 0xc06b1120 <vfile_clock_ops>
  },
  revtag = {
    rev = 36
  },
  statq = {
    next = 0xc06b18d4 <nksched+708>,
    prev = 0xde706e24
  },
  nrtimers = 24
}

Quoted 6 lines
Quoted 2 lines

Does anyone see right away what is going on wrong or shall I continue investigating the issue?

You seem to have created a periodic timer with a null period. Could you post a sample code allowing to reproduce this issue?

This happens in most of my freertos apps (e.g. demo, etc.). However, I have not put any effort in narrowing the problem down, in the hope the problem would be deductible from the kernel state. Maybe you could give a few hints where a periodic timer could come into play? In the freertos skin there are only tasks, queues and semaphores, so I am not creating any periodic timer explicitly. Are there occasiosn when periodic timers are being created implicitly using the three primitives mentioned above? Or can I configure an intelligent breakpoint to catch the creation of a periodic timer?

Regards,
Matthias

#4 lore raw
Quoted 5 lines · Matthias Schneider
Quoted 3 lines

You seem to have created a periodic timer with a null period. Could you post a sample code allowing to reproduce this issue?

Quoted 9 lines

This happens in most of my freertos apps (e.g. demo, etc.). However, I have not put any effort in narrowing the problem down, in the hope the problem would be deductible from the kernel state. Maybe you could give a few hints where a periodic timer could come into play? In the freertos skin there are only tasks, queues and semaphores, so I am not creating any periodic timer explicitly. Are there occasiosn when periodic timers are being created implicitly using the three primitives mentioned above? Or can I configure an intelligent breakpoint to catch the creation of a periodic timer?

Maybe you could put a breakpoint to see where xntimer_start is called?

Signature · 1 line
                                                                Gilles.
#5 lore raw

----- Original Message -----

Quoted 22 lines

From: Gilles Chanteperdrix <[email protected]>
To: Matthias Schneider <[email protected]>; "[email protected]" <[email protected]> Cc:
Sent: Sunday, July 6, 2014 6:09 PM
Subject: Re: [Xenomai] issue with cobalt/timer: avoid periodic timer drift

Quoted 5 lines · Matthias Schneider
Quoted 3 lines

You seem to have created a periodic timer with a null period. Could you post a sample code allowing to reproduce this issue?

Quoted 9 lines

This happens in most of my freertos apps (e.g. demo, etc.). However, I have not put any effort in narrowing the problem down, in the hope the problem would be deductible from the kernel state. Maybe you could give a few hints where a periodic timer could come into play? In the freertos skin there are only tasks, queues and semaphores, so I am not creating any periodic timer explicitly. Are there occasiosn when periodic timers are being created implicitly using the three primitives mentioned above? Or can I configure an intelligent breakpoint to catch the creation of a periodic timer?

Quoted 1 line

Maybe you could put a breakpoint to see where xntimer_start is called?

I have already had the idea, unfortunately it seems to be called all the time:

#0  xntimer_start (timer=0xc06b7628 <nksched+24>, value=405804, interval=interval@entry=0, mode=mode@entry=XN_RELATIVE) at kernel/xenomai/timer.c:104
#1  0xc00ca504 in program_htick_shot (delay=<optimized out>, cdev=<optimized out>) at kernel/xenomai/timer.c:572
#2  0xc007407c in clockevents_program_event (dev=0xc06a65c0 <clockevent_gpt>, expires=..., force=force@entry=false) at kernel/time/clockevents.c:269
#3  0xc0074a54 in tick_program_event (expires=..., force=force@entry=0) at kernel/time/tick-oneshot.c:31
#4  0xc0050974 in hrtimer_interrupt (dev=<optimized out>) at kernel/hrtimer.c:1360

Any other idea?

#6 lore raw

----- Original Message -----

Quoted 55 lines

From: Matthias Schneider <[email protected]>
To: Gilles Chanteperdrix <[email protected]>; "[email protected]" <[email protected]> Cc:
Sent: Sunday, July 6, 2014 6:31 PM
Subject: Re: [Xenomai] issue with cobalt/timer: avoid periodic timer drift

----- Original Message -----

Quoted 2 lines

From: Gilles Chanteperdrix <[email protected]>
To: Matthias Schneider <[email protected]>;

"[email protected]" <[email protected]>

Quoted 6 lines

Cc:
Sent: Sunday, July 6, 2014 6:09 PM
Subject: Re: [Xenomai] issue with cobalt/timer: avoid periodic timer drift

Quoted 1 line · Matthias Schneider
Quoted 1 line

  You seem to have created a periodic timer with a null period.

Could you

Quoted 14 lines
Quoted 4 lines
Quoted 2 lines

  post a sample code allowing to reproduce this issue?

Quoted 9 lines

  This happens in most of my freertos apps (e.g. demo, etc.). However, I have not put any effort in narrowing the problem down, in the hope the problem would be deductible from the kernel state. Maybe you could give a few hints where a periodic timer could come into play? In the freertos skin there are only tasks, queues and semaphores, so I am not creating any periodic timer explicitly. Are there occasiosn when periodic timers are being created implicitly using the three primitives mentioned above? Or can I configure an intelligent breakpoint to catch the creation of a periodic timer?

Quoted 1 line

Maybe you could put a breakpoint to see where xntimer_start is called?

I have already had the idea, unfortunately it seems to be called all the time:

#0  xntimer_start (timer=0xc06b7628 <nksched+24>, value=405804, interval=interval@entry=0, mode=mode@entry=XN_RELATIVE) at kernel/xenomai/timer.c:104
#1  0xc00ca504 in program_htick_shot (delay=<optimized out>, cdev=<optimized out>) at kernel/xenomai/timer.c:572
#2  0xc007407c in clockevents_program_event (dev=0xc06a65c0 <clockevent_gpt>, expires=..., force=force@entry=false) at kernel/time/clockevents.c:269
#3  0xc0074a54 in tick_program_event (expires=..., force=force@entry=0) at kernel/time/tick-oneshot.c:31
#4  0xc0050974 in hrtimer_interrupt (dev=<optimized out>) at kernel/hrtimer.c:1360

Quoted 1 line

Any other idea?

By the way, how can I deduce it was a periodic timer?

status seems to be 0x1 (XNTIMER_DEQUEUED), but not 0x4(XNTIMER_PERIODIC) Also, all the other timer values seem to indicate that

 if (interval != XN_INFINITE) { timer->interval_ns = interval;
  timer->interval = xnclock_ns_to_ticks(clock, interval); timer->periodic_ticks = 0;
  timer->start_date = date;
  timer->pexpect_ticks = 0;
  timer->status |= XNTIMER_PERIODIC;
 }

was never being used for that timer...

Matthias

#7 lore raw
Quoted 74 lines · Matthias Schneider

----- Original Message -----

Quoted 55 lines

From: Matthias Schneider <[email protected]>
To: Gilles Chanteperdrix <[email protected]>; "[email protected]" <[email protected]> Cc:
Sent: Sunday, July 6, 2014 6:31 PM
Subject: Re: [Xenomai] issue with cobalt/timer: avoid periodic timer drift

----- Original Message -----

Quoted 2 lines

From: Gilles Chanteperdrix <[email protected]>
To: Matthias Schneider <[email protected]>;

"[email protected]" <[email protected]>

Quoted 6 lines

Cc:
Sent: Sunday, July 6, 2014 6:09 PM
Subject: Re: [Xenomai] issue with cobalt/timer: avoid periodic timer drift

Quoted 1 line · Matthias Schneider
Quoted 1 line

You seem to have created a periodic timer with a null period.

Could you

Quoted 14 lines
Quoted 4 lines
Quoted 2 lines

post a sample code allowing to reproduce this issue?

Quoted 9 lines

This happens in most of my freertos apps (e.g. demo, etc.). However, I have not put any effort in narrowing the problem down, in the hope the problem would be deductible from the kernel state. Maybe you could give a few hints where a periodic timer could come into play? In the freertos skin there are only tasks, queues and semaphores, so I am not creating any periodic timer explicitly. Are there occasiosn when periodic timers are being created implicitly using the three primitives mentioned above? Or can I configure an intelligent breakpoint to catch the creation of a periodic timer?

Quoted 1 line

Maybe you could put a breakpoint to see where xntimer_start is called?

I have already had the idea, unfortunately it seems to be called all the time:

#0 xntimer_start (timer=0xc06b7628 <nksched+24>, value=405804, interval=interval@entry=0, mode=mode@entry=XN_RELATIVE) at kernel/xenomai/timer.c:104
#1 0xc00ca504 in program_htick_shot (delay=<optimized out>, cdev=<optimized out>) at kernel/xenomai/timer.c:572
#2 0xc007407c in clockevents_program_event (dev=0xc06a65c0 <clockevent_gpt>, expires=..., force=force@entry=false) at kernel/time/clockevents.c:269
#3 0xc0074a54 in tick_program_event (expires=..., force=force@entry=0) at kernel/time/tick-oneshot.c:31
#4 0xc0050974 in hrtimer_interrupt (dev=<optimized out>) at kernel/hrtimer.c:1360

Quoted 1 line

Any other idea?

By the way, how can I deduce it was a periodic timer?

status seems to be 0x1 (XNTIMER_DEQUEUED), but not 0x4(XNTIMER_PERIODIC) Also, all the other timer values seem to indicate that

if (interval != XN_INFINITE) {
timer->interval_ns = interval;
timer->interval = xnclock_ns_to_ticks(clock, interval); timer->periodic_ticks = 0;
timer->start_date = date;
timer->pexpect_ticks = 0;
timer->status |= XNTIMER_PERIODIC;
}

Quoted 1 line

was never being used for that timer...

You mean for the timer where you hit the breakpoint, or for the timer which has the bug?

Signature · 1 line
                                                                Gilles.
#8 lore raw

----- Original Message -----

Quoted 95 lines

From: Gilles Chanteperdrix <[email protected]>
To: Matthias Schneider <[email protected]>; "[email protected]" <[email protected]> Cc:
Sent: Sunday, July 6, 2014 6:44 PM
Subject: Re: [Xenomai] issue with cobalt/timer: avoid periodic timer drift

Quoted 4 lines · Matthias Schneider

----- Original Message -----

Quoted 2 lines

From: Matthias Schneider <[email protected]>
To: Gilles Chanteperdrix <[email protected]>;

"[email protected]" <[email protected]>

Quoted 3 lines
Quoted 3 lines

Cc:
Sent: Sunday, July 6, 2014 6:31 PM
Subject: Re: [Xenomai] issue with cobalt/timer: avoid periodic timer

drift

Quoted 8 lines
Quoted 8 lines

----- Original Message -----

Quoted 1 line

  From: Gilles Chanteperdrix

<[email protected]>

Quoted 5 lines
Quoted 5 lines
Quoted 1 line

  To: Matthias Schneider <[email protected]>;

"[email protected]" <[email protected]>

Quoted 3 lines

  Cc:
  Sent: Sunday, July 6, 2014 6:09 PM
  Subject: Re: [Xenomai] issue with cobalt/timer: avoid periodic

timer drift

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines · Matthias Schneider
Quoted 1 line
Quoted 1 line

  You seem to have created a periodic timer with a null

period.

Quoted 6 lines
Quoted 6 lines

Could you

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

  post a sample code allowing to reproduce this issue?

  This happens in most of my freertos apps (e.g. demo, etc.).

However,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

  I have not put any effort in narrowing the problem down, in

the hope

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

  the problem would be deductible from the kernel state. Maybe

you could

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

  give a few hints where a periodic timer could come into play?

In the

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

  freertos skin there are only tasks, queues and semaphores, so

I

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

  am not creating any periodic timer explicitly. Are there

occasiosn

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

  when periodic timers are being created implicitly using the

three

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

  primitives mentioned above? Or can I configure an intelligent breakpoint to catch the creation of a periodic timer?

  Maybe you could put a breakpoint to see where xntimer_start is

called?

Quoted 5 lines
Quoted 5 lines

I have already had the idea, unfortunately it seems to be called all the time:

Quoted 9 lines
Quoted 9 lines

#0  xntimer_start (timer=0xc06b7628 <nksched+24>, value=405804, interval=interval@entry=0, mode=mode@entry=XN_RELATIVE) at kernel/xenomai/timer.c:104
#1  0xc00ca504 in program_htick_shot (delay=<optimized out>, cdev=<optimized out>) at kernel/xenomai/timer.c:572
#2  0xc007407c in clockevents_program_event (dev=0xc06a65c0 <clockevent_gpt>, expires=..., force=force@entry=false) at kernel/time/clockevents.c:269
#3  0xc0074a54 in tick_program_event (expires=..., force=force@entry=0)

at

Quoted 21 lines
Quoted 5 lines

kernel/time/tick-oneshot.c:31
#4  0xc0050974 in hrtimer_interrupt (dev=<optimized out>) at kernel/hrtimer.c:1360

Any other idea?

By the way, how can I deduce it was a periodic timer?

status seems to be 0x1 (XNTIMER_DEQUEUED), but not 0x4(XNTIMER_PERIODIC) Also, all the other timer values seem to indicate that

  if (interval != XN_INFINITE) { timer->interval_ns = interval;
  timer->interval = xnclock_ns_to_ticks(clock, interval); timer->periodic_ticks = 0;
  timer->start_date = date;
  timer->pexpect_ticks = 0;
  timer->status |= XNTIMER_PERIODIC;
  }

Quoted 4 lines
Quoted 1 line

was never being used for that timer...

You mean for the timer where you hit the breakpoint, or for the timer which has the bug?

I assumed that if I would have create a periodic timer, status would at least have been or'ed with 0x4. However, as can be seen in my initial post, the status value of the timer causing the problem was 1. Thats why I asked how you deduced that it was a periodic timer with a period of 0.

Matthias

#9 lore raw
Quoted 102 lines · Matthias Schneider

----- Original Message -----

Quoted 97 lines

From: Gilles Chanteperdrix <[email protected]>
To: Matthias Schneider <[email protected]>; "[email protected]" <[email protected]> Cc:
Sent: Sunday, July 6, 2014 6:44 PM
Subject: Re: [Xenomai] issue with cobalt/timer: avoid periodic timer drift

Quoted 4 lines · Matthias Schneider

----- Original Message -----

Quoted 2 lines

From: Matthias Schneider <[email protected]>
To: Gilles Chanteperdrix <[email protected]>;

"[email protected]" <[email protected]>

Quoted 3 lines
Quoted 3 lines

Cc:
Sent: Sunday, July 6, 2014 6:31 PM
Subject: Re: [Xenomai] issue with cobalt/timer: avoid periodic timer

drift

Quoted 8 lines
Quoted 8 lines

----- Original Message -----

Quoted 1 line

From: Gilles Chanteperdrix

<[email protected]>

Quoted 5 lines
Quoted 5 lines
Quoted 1 line

To: Matthias Schneider <[email protected]>;

"[email protected]" <[email protected]>

Quoted 3 lines

Cc:
Sent: Sunday, July 6, 2014 6:09 PM
Subject: Re: [Xenomai] issue with cobalt/timer: avoid periodic

timer drift

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines · Matthias Schneider
Quoted 1 line
Quoted 1 line

You seem to have created a periodic timer with a null

period.

Quoted 6 lines
Quoted 6 lines

Could you

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

post a sample code allowing to reproduce this issue?

This happens in most of my freertos apps (e.g. demo, etc.).

However,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

I have not put any effort in narrowing the problem down, in

the hope

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

the problem would be deductible from the kernel state. Maybe

you could

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

give a few hints where a periodic timer could come into play?

In the

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

freertos skin there are only tasks, queues and semaphores, so

I

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

am not creating any periodic timer explicitly. Are there

occasiosn

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

when periodic timers are being created implicitly using the

three

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

primitives mentioned above? Or can I configure an intelligent breakpoint to catch the creation of a periodic timer?

Maybe you could put a breakpoint to see where xntimer_start is

called?

Quoted 5 lines
Quoted 5 lines

I have already had the idea, unfortunately it seems to be called all the time:

Quoted 9 lines
Quoted 9 lines

#0 xntimer_start (timer=0xc06b7628 <nksched+24>, value=405804, interval=interval@entry=0, mode=mode@entry=XN_RELATIVE) at kernel/xenomai/timer.c:104
#1 0xc00ca504 in program_htick_shot (delay=<optimized out>, cdev=<optimized out>) at kernel/xenomai/timer.c:572
#2 0xc007407c in clockevents_program_event (dev=0xc06a65c0 <clockevent_gpt>, expires=..., force=force@entry=false) at kernel/time/clockevents.c:269
#3 0xc0074a54 in tick_program_event (expires=..., force=force@entry=0)

at

Quoted 22 lines
Quoted 5 lines

kernel/time/tick-oneshot.c:31
#4 0xc0050974 in hrtimer_interrupt (dev=<optimized out>) at kernel/hrtimer.c:1360

Any other idea?

By the way, how can I deduce it was a periodic timer?

status seems to be 0x1 (XNTIMER_DEQUEUED), but not 0x4(XNTIMER_PERIODIC) Also, all the other timer values seem to indicate that

  if (interval != XN_INFINITE) {
   timer->interval_ns = interval;
   timer->interval = xnclock_ns_to_ticks(clock, interval);
   timer->periodic_ticks = 0;
   timer->start_date = date;
   timer->pexpect_ticks = 0;
   timer->status |= XNTIMER_PERIODIC;
  }

was never being used for that timer...

Quoted 8 lines
Quoted 2 lines

You mean for the timer where you hit the breakpoint, or for the timer which has the bug?

I assumed that if I would have create a periodic timer, status would at least have been or'ed with 0x4. However, as can be seen in my initial post, the status value of the timer causing the problem was 1. Thats why I asked how you deduced that it was a periodic timer with a period of 0.

Because normally the loop is made for periodic timers. Are you running inside gdb?

Signature · 1 line
                                                                Gilles.
#10 lore raw
In reply to Matthias Schneider
Quoted 23 lines · Matthias Schneider

Hi all,

commit

2014-06-02 c20fceb147e337e2379b29ecd81b943318c7fbc7 (patch) cobalt/timer: avoid periodic timer drift

seems to cause an endless kernel loop in one of my freertos demos. The issue does not occur when reverting this commit.

Investigating the issue, can see the following:

#0 0xc00ba45c in mach_arm_nodiv_llimd (rhs_integ=<optimized out>, frac=<optimized out>, op=<optimized out>)
at arch/arm/xenomai/include/asm/xenomai/uapi/arith.h:120
#1 xnclock_core_ns_to_ticks (ns=0) at kernel/xenomai/clock.c:52
#2 0xc00baf34 in xnclock_ns_to_ticks (clock=<optimized out>, ns=<optimized out>)
at include/xenomai/cobalt/kernel/clock.h:204

#3  xntimer_update_date (timer=0xde706518) at include/xenomai/cobalt/kernel/timer.h:268
#4  xnclock_tick (clock=0xc06b1138 <nkclock>) at kernel/xenomai/clock.c:644
#5  0xc00bcbcc in xnintr_core_clock_handler () at kernel/xenomai/intr.c:121
#6  0xc0095a98 in dispatch_irq_head (irq=<optimized out>) at kernel/ipipe/core.c:1179
Quoted 5 lines

This seems to be the endless loop:
642 do {
643 timer->periodic_ticks += interval_ticks;
644 xntimer_update_date(timer);
645 } while (xntimerh_date(&timer->aplink) < now + clock->gravity);

I do not really understand how interval_ticks can be 0, but please try the following patch:

kernel/cobalt/clock.c +4 -5
index a578f89..1107f7a 100644
@@ -619,10 +619,9 @@ void xnclock_tick(struct xnclock *clock)
 			 * wait for 250 ms for the user to continue
 			 * program execution.
 			 */
-			if (timer->interval_ns > 250000000)
-				goto advance;
-			interval_ticks = 250000000 /
-				(unsigned)timer->interval_ns;
+			xntimerh_date(&timer->aplink) +=
+				xnclock_ns_to_ticks(xntimer_clock(timer),
+						250000000);
 			goto requeue;
 		}
 	fire:
@@ -638,11 +637,11 @@ void xnclock_tick(struct xnclock *clock)
 			continue;
 	advance:
 		interval_ticks = 1;
-	requeue:
 		do {
 			timer->periodic_ticks += interval_ticks;
 			xntimer_update_date(timer);
 		} while (xntimerh_date(&timer->aplink) < now + clock->gravity);
+	requeue:
 #ifdef CONFIG_SMP
 		/*
 		 * Make sure to pick the right percpu queue, in case
Signature · 1 line
                                                                Gilles.
#11 lore raw

----- Original Message -----

Quoted 70 lines

From: Gilles Chanteperdrix <[email protected]>
To: Matthias Schneider <[email protected]>; "[email protected]" <[email protected]> Cc:
Sent: Sunday, July 6, 2014 7:04 PM
Subject: Re: [Xenomai] issue with cobalt/timer: avoid periodic timer drift

Quoted 7 lines · Matthias Schneider

Hi all,

commit

2014-06-02 c20fceb147e337e2379b29ecd81b943318c7fbc7 (patch) cobalt/timer: avoid periodic timer drift

Quoted 7 lines

seems to cause an endless kernel loop in one of my freertos demos. The issue does not occur when reverting this commit.

Investigating the issue, can see the following:

#0  0xc00ba45c in mach_arm_nodiv_llimd (rhs_integ=<optimized out>,

frac=<optimized out>, op=<optimized out>)

Quoted 3 lines
     at arch/arm/xenomai/include/asm/xenomai/uapi/arith.h:120
 #1  xnclock_core_ns_to_ticks (ns=0) at kernel/xenomai/clock.c:52
 #2  0xc00baf34 in xnclock_ns_to_ticks (clock=<optimized out>, 

ns=<optimized out>)

Quoted 2 lines
     at include/xenomai/cobalt/kernel/clock.h:204
 #3  xntimer_update_date (timer=0xde706518) at 

include/xenomai/cobalt/kernel/timer.h:268

Quoted 1 line

#4  xnclock_tick (clock=0xc06b1138 <nkclock>) at

kernel/xenomai/clock.c:644

Quoted 2 lines

#5  0xc00bcbcc in xnintr_core_clock_handler () at kernel/xenomai/intr.c:121 #6  0xc0095a98 in dispatch_irq_head (irq=<optimized out>) at

kernel/ipipe/core.c:1179

Quoted 6 lines

This seems to be the endless loop:
642                    do {
643      timer->periodic_ticks += interval_ticks;
644      xntimer_update_date(timer);
645                    } while (xntimerh_date(&timer->aplink) <

now + clock->gravity);

I do not really understand how interval_ticks can be 0, but please try the following patch:

kernel/cobalt/clock.c +3 -4
index a578f89..1107f7a 100644
@@ -619,10 +619,9 @@ void xnclock_tick(struct xnclock *clock)
              * wait for 250 ms for the user to continue
              * program execution.
              */
-            if (timer->interval_ns > 250000000)
-                goto advance;
-            interval_ticks = 250000000 /
-                (unsigned)timer->interval_ns;
+            xntimerh_date(&timer->aplink) +=
+                xnclock_ns_to_ticks(xntimer_clock(timer),
+                        250000000);
             goto requeue;
         }

    fire:

kernel/cobalt/clock.c +0 -0
@@ -638,11 +637,11 @@ void xnclock_tick(struct xnclock *clock)
             continue;

    advance:
        interval_ticks = 1;
-    requeue:

Quoted 10 lines

        do {
            timer->periodic_ticks += interval_ticks; xntimer_update_date(timer);
        } while (xntimerh_date(&timer->aplink) < now + clock->gravity);
+    requeue:
#ifdef CONFIG_SMP
        /*
        * Make sure to pick the right percpu queue, in case

Hi Gilles,

thanks for the quick fix, it seems to resolve my problem. Yes, in fact I was used gdb when the issues occured.

Considering I entered the

if (unlikely(atomic_read(&nkclklk) > 0))
[...]
code path, a series of division by zeroes I had without a sensible backtrace could also be explained (I was under the impression that it is possible to get a backtrace of a division by zero exception on arm for some time now, but it seems not to have worked for me).

Regards,
Matthias