chSysPolledDelay not looping with high level optimisation Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
User avatar
alex31
Posts: 374
Joined: Fri May 25, 2012 10:23 am
Location: toulouse, france
Has thanked: 38 times
Been thanked: 61 times
Contact:

chSysPolledDelay not looping with high level optimisation  Topic is solved

Postby alex31 » Thu Apr 29, 2021 9:48 am

Hello,

I have a problem with recent version of gcc (10.x and above (11.x) if I compile with -Ofast and lto (gcc10) and even with -Os and lto (gcc11)

Don't really understand the problem, but the loop exits early, so chSysPolledDelay does not wait for the desired time.

If I a add dummy variable setting in the loop like :

Code: Select all

static volatile uint32_t dummyCnt=0U;
void chSysPolledDelayX(rtcnt_t cycles) {
  rtcnt_t start = chSysGetRealtimeCounterX();
  rtcnt_t end  = start + cycles;

  while (chSysIsCounterWithinX(chSysGetRealtimeCounterX(), start, end)) {
    dummyCnt++;
  }
}


the problem is resolved (of course that is not a fix, just a clue to search for proper way of fixing)

I also tried to see the assembly output with compiler explorer, but with my limited arm ISA knowledge, i don't spot any obvious compiler issue in the generated code :
assembly output

edit 1/
can see the effect in the timing of driving pins in a big project, but not able to reproduce the problem with a small example, keep searching ...

Alexandre

User avatar
alex31
Posts: 374
Joined: Fri May 25, 2012 10:23 am
Location: toulouse, france
Has thanked: 38 times
Been thanked: 61 times
Contact:

Re: chSysPolledDelay not looping with high level optimisation

Postby alex31 » Thu Apr 29, 2021 1:56 pm

Still no able to reproduce the problem with a simple example, so it's probably a side effect in my app, not a compiler problem, so
consider this post useless for now.

Sorry for the noise.

A.

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: chSysPolledDelay not looping with high level optimisation

Postby Giovanni » Thu Apr 29, 2021 2:05 pm

Code: Select all

volatile rtcnt_t CYCCNT = 1000U;

rtcnt_t chSysGetRealtimeCounterX() {
    return CYCCNT;
}


CYCCNT should be an HW counter, why is it a variable in your example?

Giovanni

User avatar
alex31
Posts: 374
Joined: Fri May 25, 2012 10:23 am
Location: toulouse, france
Has thanked: 38 times
Been thanked: 61 times
Contact:

Re: chSysPolledDelay not looping with high level optimisation

Postby alex31 » Thu Apr 29, 2021 3:06 pm

Hi,

It would have been too complicated to compile chibios within compiler explorer, so I have simulated the hardware counter with a volatile variable to see what the compiler does. In fact, I have dig a little bit, and I am able to fix the problem with a

Code: Select all

asm volatile("": : :"memory")
between polledDelay and the reading of a pin (for the record, the problem is with the community hd44780 lcd library when compiled with Ofast).


Alexandre


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 20 guests