Page 1 of 1

Thread wake up from IRQ latency

Posted: Wed Jun 29, 2016 11:54 pm
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?

Re: Thread wake up from IRQ latency

Posted: Thu Jun 30, 2016 8:34 am
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

Re: Thread wake up from IRQ latency

Posted: Fri Jul 01, 2016 2:21 am
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.

Re: Thread wake up from IRQ latency

Posted: Fri Jul 01, 2016 8:06 am
by Giovanni
Hi,

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

Giovanni

Re: Thread wake up from IRQ latency

Posted: Fri Jul 01, 2016 10:56 am
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?

Re: Thread wake up from IRQ latency

Posted: Fri Jul 01, 2016 11:19 am
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