Thread wake up from IRQ latency

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
__nemo__
Posts: 3
Joined: Wed Jun 29, 2016 11:39 pm

Thread wake up from IRQ latency

Post by __nemo__ »

Hi,

I have custom SPI slave device (CPLD) which notifies me about new data through external interrupt. The problem is that I have very limited time interval to react and begin the transfer (about 5us).

I tried to resume suspended thread from external interrupt callback (EXT driver) as shown in the following example. But It takes at least 10us (with -O2 and no OS debug for 24MHz stm32l152xx MCU). Am I doing something wrong? Is there any way to reduce this thread wake up latency?
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Thread wake up from IRQ latency

Post by Giovanni »

Hi,

How do you measure it? 10uS is a lot, probably it is caused by the low clock frequency. Suspend/resume is about the fastest method.

How are you measuning? using a GPIO? if so try measuring various points:
- ISR trigger.
- Where resume is called.
- Where the thread exits from suspend.

This way we can see where time is lost.

Anyway possible solutions are:
- Increase clock frequency.
- Use -O3 for critical parts.
- Execute critical code from ISR and then resume the thread.
- Use the "simplified priority handling" option, see chcore_v7m.h file. This makes kernel a bit faster.
- Disable unused features in chconf.h, this also can speed up some kernel operations.

Giovanni
__nemo__
Posts: 3
Joined: Wed Jun 29, 2016 11:39 pm

Re: Thread wake up from IRQ latency

Post by __nemo__ »

Yes, I am measuring using a GPIO with a logic analyzer. I cannot use clock frequency other than 24MHz because it will screw up MCO frequency.

So, assuming the TX notifier pin up as zero time starting point
    tx notifier up - 0us
    IRQ beginning - 2.7
    IRQ after calling resume - 4.5
    thread wake up - 10
- measured at O3 with following configuration and code. I have tried "simplified priority handling" without luck.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Thread wake up from IRQ latency

Post by Giovanni »

Hi,

You could use the MCO divider and up frequency up to 32MHz.

Giovanni
__nemo__
Posts: 3
Joined: Wed Jun 29, 2016 11:39 pm

Re: Thread wake up from IRQ latency

Post by __nemo__ »

It seems impossible to have 32MHz SYSCLK and keep 48MHz for USB and 24MHz for MCU =(.
So the only way is to initiate transfer within ISR via CMSIS?
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Thread wake up from IRQ latency

Post by Giovanni »

Hi,

What is the problem starting a transfer directly from the ISR? what driver are you using for that? SPI? the SPI driver supports starting a transfer from ISR: spiStartxxxxxI().

Giovanni
Post Reply