I am using wiringPi library to process interrupts in C++ on a RaspberryPi 3. Using a logic analyzer on the GPIO pins I find that latency from GPIO edge to my ISR being called varies from about 45 to 70 us. I would like it faster but my application can tolerate this latency, but occasionally (about once a ms) latency increases to over 150 us and rarely to over 1 ms causing me to lose events. Most often the delay is before my ISR is called but occasionally it is in the middle of my ISR (my ISR usually takes about 4 us).
I assume that the processes involved are being preempted by something running at higher priority. I have tried running using the highest read-time priority and this does not seem to make a difference. I am guessing that the preemption is something in the kernel and that the only solution would be to write a kernel module which I had hoped to avoid.
Does anyone know what might be causing this? I see it when even when no other user processes are running. Will I still have this issue in even in kernel space? I do not need many of the standard services on a Pi (bluetooth, WiFi, HDMI, ...) and wonder if one of them preempts and by removing one of them I can avoid this.
To be a little more specific, my ISR toggles another GPIO at the beginning and again at the end so that I can see its lifetime on my logic analyzer. The interrupts I am handling are nearly perfectly periodic but on different runs vary from 600-16000 times a second.