Priority order violation - Asserion fails Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
fotis
Posts: 32
Joined: Mon Apr 04, 2016 7:04 pm
Has thanked: 1 time
Been thanked: 1 time

Priority order violation - Asserion fails  Topic is solved

Postby fotis » Wed Jan 31, 2018 11:00 pm

Hi,

I have a assertion failing in Chibios code, and I am trying to troubleshoot it.

The check condition is the following:

Code: Select all

  /* The following condition can be triggered by the use of i-class functions
     in a critical section not followed by a chSchResceduleS(), this means
     that the current thread has a lower priority than the next thread in
     the ready list.*/
  chDbgAssert((ch.rlist.queue.next == (thread_t *)&ch.rlist.queue) ||
              (ch.rlist.current->prio >= ch.rlist.queue.next->prio),
              "priority order violation");



What I would expect is that somewhere, in my thread(?) code there is a missing call to chSchResceduleS().

As I understand from the documentation, I only need to call chSchResceduleS() after a call to an I-class function, when in thread code. I have triple-checked that this is NOT my problem. In fact, I reproduce this issue without even a single call to an I-class function!

Are there any other cases of needing to call chSchResceduleS()? Are there any other causes of failure for this assertion, apart from what is written in the comment? Any other way to troubleshoot this?

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Priority order violation - Asserion fails

Postby Giovanni » Wed Jan 31, 2018 11:05 pm

Hi,

Explore upward your stack trace, it will likely point to the problem. Post it here if in doubt.

Where is that chSysUnlock() called from?

Giovanni

fotis
Posts: 32
Joined: Mon Apr 04, 2016 7:04 pm
Has thanked: 1 time
Been thanked: 1 time

Re: Priority order violation - Asserion fails

Postby fotis » Wed Jan 31, 2018 11:07 pm

As a hint:

The thread that has higher priority and gets "neglected" is a very simple one. It just blinks an LED, and feeds the watchdog.

The code of the thread is the following:

Code: Select all

void status_th(void __attribute__ ((__unused__)) * arg)
{
   while(1)
   {
      //Feed the watchdog timer.
      SoftWatchdog_tick();

      //Blink the status LED.
      Led_tick(&statusLed);

      chThdSleep(MS2ST(STATUS_LOOP_TIME));
   }
}



From the above it is clear that this thread gets in a waiting state due to a call to chThdSleep(MS2ST(STATUS_LOOP_TIME)). No semaphores, events etc, that may need rescheduling, or may cause priority-inversion etc...

I would expect this thread to run without problems, due to the SysTick timer handler. This thread is either sleeping, or running. Each time the systick timer handler is executed, the system ticks counter is incremented, and a reschedule takes place.

How it is possible for this thread to finish its sleep (due to expiration of the delay STATUS_LOOP_TIME, as counted by systick timer, and not get executed, in favor of a lower priority thread?

fotis
Posts: 32
Joined: Mon Apr 04, 2016 7:04 pm
Has thanked: 1 time
Been thanked: 1 time

Re: Priority order violation - Asserion fails

Postby fotis » Wed Jan 31, 2018 11:19 pm

The assertion fails when another thread (of a lower priority), manipulates a mutex (either locks it or unlocks it).

If by stack trace you mean the functions call stack, as displayed in Eclipse debug view, there is nothing suspicious there. If you mean anything else, please explain me where to find it.

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Priority order violation - Asserion fails

Postby Giovanni » Wed Jan 31, 2018 11:24 pm

When a very simple piece of code does not seem to do what it is supposed to do then, probably, you are looking at the wrong thing.

Similar loops are in all demos and simply work, see blinker threads.

This could help: http://www.chibios.org/dokuwiki/doku.ph ... ebug_guide

Giovanni

fotis
Posts: 32
Joined: Mon Apr 04, 2016 7:04 pm
Has thanked: 1 time
Been thanked: 1 time

Re: Priority order violation - Asserion fails

Postby fotis » Tue Jun 26, 2018 6:52 pm

Hi,

this still bugs me. I couldn't get a solution, and then I left it due to lack of free time.

No I am back at it. I tried again to track this down with no luck.

Can you please provide me some info on how to get a stack trace, and upload it here?

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Priority order violation - Asserion fails

Postby Giovanni » Wed Jun 27, 2018 10:41 am

It depends on the debugger you are using, is it Eclipse? if so then it is the box in the upper left corner of the debugger view.

Giovanni

fotis
Posts: 32
Joined: Mon Apr 04, 2016 7:04 pm
Has thanked: 1 time
Been thanked: 1 time

Re: Priority order violation - Asserion fails

Postby fotis » Wed Jun 27, 2018 6:33 pm

I have checked this multiple times, but it didn't help me.

Either way, in case it is helpful for you, here you are.

Image

steved
Posts: 823
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 135 times

Re: Priority order violation - Asserion fails

Postby steved » Wed Jun 27, 2018 8:48 pm

Assuming that's lwIp you're running, I have a vague recollection of a similar problem. In my case it was down to insufficient stack allocation for one of the tasks; a networking-related one IIRC.
(The Chibi plugin for Eclipse will show you stack usage)

Note that you can actually use the debugger to see the states of variables at any point in the execution stack, just by highlighting the relevant level - that can sometimes give clues.

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Priority order violation - Asserion fails

Postby Giovanni » Wed Jun 27, 2018 9:08 pm

The problem could be originated in another place, are you using any I-class API (those whose name ends with an "I") from thread context?

Giovanni


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 8 guests