fifoObject internal bug Topic is solved

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

fifoObject internal bug  Topic is solved

Postby alex31 » Fri Dec 22, 2023 5:39 pm

using chibios 21.11.x with lasts updates

I have occurrence of error using fifoObject api when I stress it a bit
where internal assert fails in chGuardedPoolAllocI (called by chFifoTakeObjectI) :

Code: Select all

  chDbgAssert(chSemGetCounterI(&gmp->sem) >= (cnt_t)0, // ** gdb show that gmp->sem = -1 **
                "semaphore out of sync");

To trigger the bug, I have
° a sender thread that does regular but slow pace take(TIME_INFINITE)
° ISR that does takeI->sendI at high rate (so most of the time takeI return null so no sendI are made)
° a receiver thread that receive(TIME_INFINITE) in infinite loop, but is speed limited by I/O

it seems that this condition trigger the bug :
°the sender thread is blocked on the take(TIME_INFINITE)
°the receiver thread return an object
°at the same time and ISR does a takeI

problem occurs in a C++ library, but I can write a small C program that exhibit behavior if it helps.
I have checked that it's not a stack overflow.

Alexandre

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

Re: fifoObject internal bug

Postby Giovanni » Fri Dec 22, 2023 9:13 pm

Hi,

What is the priority of the IRQ?

Giovanni

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

Re: fifoObject internal bug

Postby alex31 » Fri Dec 22, 2023 11:42 pm

That's a good question, I use GPTD5 and

Code: Select all

#define STM32_IRQ_TIM5_PRIORITY             7


So it seems that it's more that 2 so it should be OK

A.

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

Re: fifoObject internal bug

Postby Giovanni » Sat Dec 23, 2023 7:42 am

Hi,

Could you try the following?

Code: Select all

static inline void *chGuardedPoolAllocI(guarded_memory_pool_t *gmp) {
  void *p;

  if (chSemGetCounterI(&gmp->sem) > (cnt_t)0) {

    chSemFastWaitI(&gmp->sem);
    p = chPoolAllocI(&gmp->pool);
  }
  else {
    p = NULL;
  }

  return p;
}


Giovanni

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

Re: fifoObject internal bug

Postby alex31 » Sat Dec 23, 2023 9:11 am

beautiful, works flawlessly.

You have resolved a race condition with a patch that also make the code shorter, that's fine !
Alexandre

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

Re: fifoObject internal bug

Postby Giovanni » Sat Dec 23, 2023 12:37 pm

Thanks, I will commit this to all branches.

Giovanni

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

Re: fifoObject internal bug

Postby Giovanni » Tue Dec 26, 2023 12:50 pm

Hi,

Fixed as 1277.

Giovanni


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 4 guests