Page 1 of 1

chVTSetI infinite loop

Posted: Wed May 08, 2013 2:15 am
by russian
I am not yet sure how I got there, but my app gets into an infinite loop inside chVTSetI.

So, I have a piece of code

Code: Select all

   if (offset == 0) {
      xxx;
      return;
   }

   chSysLockFromIsr();
   chVTSetI(&signal->signalTimer, offset, &outCallback, signal);
   chSysUnlockFromIsr();
   }

(actually, there is a parameter check time != TIME_IMMEDIATE anyway)
and sometimes my code was hanging. Debugger showed an infinite loop inside chVTSetI, I have added an asserting an it did fail!

Code: Select all

  while (p->vt_time < time) {
     int isOk = p->vt_time!=0 || p!=p->vt_next;
     chDbgCheck(isOk, "timer constraint");
     if(!isOk)
        break;
    time -= p->vt_time;
    p = p->vt_next;
  }

putput:

Code: Select all

FATAL "timer constraint"()

I use 2.4.3 and I have some DBG checks enabled:
CH_DBG_ENABLE_ASSERTS=1
CH_DBG_ENABLE_CHECKS=1
CH_DBG_SYSTEM_STATE_CHECK=1
CH_DBG_ENABLE_STACK_CHECK=1

Would this be considered a bug in ChibiOS that I can get in such a state? Any hints on how I could have broken the internal constraint?

Re: chVTSetI infinite loop

Posted: Wed May 08, 2013 8:18 am
by Giovanni
Probably you thy to set a timer which is already active, this destroys the list of timers.

You have to do:

Code: Select all

lock
if timer_is armed
  reset_timer
set_timer
unlock


Giovanni

Re: chVTSetI infinite loop

Posted: Thu May 09, 2013 3:07 am
by russian
Looks like this has fixed the issue, thank you!

If that's the constraint of this method please consider adding this check into chVTSetI? On the other hand, it's impossible to protect from everything...

PS: another tiny comment in this area - the @brief for chDbgPanic method says 'Prints a panic message on the console' - but does it in fact prints anything? I did not find any references to dbg_panic_msg field, is it simply a variable for use via debugger?

Re: chVTSetI infinite loop

Posted: Thu May 09, 2013 8:06 am
by Giovanni
Hi,

This is scheduled for 3.0, I don't to break the API for the current version.

Giovanni

Re: chVTSetI infinite loop

Posted: Thu May 09, 2013 1:29 pm
by steved
Giovanni wrote:Hi,

This is scheduled for 3.0, I don't to break the API for the current version.

Giovanni

Could it be achieved with a new function retriggerTimer()?

Or, better still, createOrRetriggerTimer()?

(I often have a need for the retriggerTimer() function - mainly for comms timeouts and the like)

Re: chVTSetI infinite loop

Posted: Thu May 09, 2013 1:34 pm
by Giovanni
This could be a good idea but I need to finalize 2.6.0, the next step is 3.0.0 anyway.

Giovanni