How to debug realtime interrupt latency
Hi,
Let me introduce myself and what I'm working on. I'm a software engineer working on the real time acquisition and control system of the Virgo interferometer: https://en.wikipedia.org/wiki/Virgo_interferometer . This system is currently based on RTAI 5.2, which allows us to implement control loop up to 50 kHz. Data are exchanged using optical links of in-house PCIe boards. These boards are synchronized using a distributed clock. Each iteration of the control loop is triggered by an interrupt generated by the PCIe board. From the interrupt handler, we are calling a list of computational functions running in user space.
I'm currently evaluating Xenomai 3 as a replacement of RTAI 5.2. The first step consist in measuring the interrupt latency. During our tests, one of our machines shown bigger worst case latencies than the RTAI 5.2 based platform running on the same hardware, or even than the same Xenomai 3.1 based platform running on a different hardware. That is why I'm looking for advice on how to debug interrupt latency.
Here is my 3 setups:
CentOS 7 + Linux 4.14.111 + RTAI 5.2 on Dell PowerEdge R630 Intel(R) Xeon(R) CPU E5-2623 v3 @ 3.00GHz CentOS 7 + Linux 4.14.111 + Xenomai 3.1 on Dell PowerEdge R630 Intel(R) Xeon(R) CPU E5-2623 v3 @ 3.00GHz CentOS 7 + Linux 4.14.111 + Xenomai 3.1 on DELL PowerEdge T740 Intel(R) Xeon(R) Gold 5222 CPU @ 3.80GHz
Except for the kernel, all the systems run the same OS (NFS mounted root file system).
The interrupt latency measurements are in this figure: http://emmanuel.pacaud.free.fr/partage/interrupt-latencies.png
All the systems have irqaffinity=0 and isolcpus=1,2,3. The affinity of the real time interrupt is set to 1.
The real time interrupt is installed using rt_request_irq/rt_assign_irq on RTAI, and xnintr_init/xnintr_affinity on Xenomai.
The interrupt latency is measured using the in-house PCIe board (a time register is latched when the board emit an interrupt, and a current time register is read at the beginning of the interrupt handler).
What would explain the latency distribution on the DELL R630 + Xenomai compared to RTAI on the same machine, or to itself on the other machine ?
Does Xenomai perform some other tasks before the real time interrupt handler is called ?
Is there a way in Xenomai to measure the interrupt latency from the moment the kernel is awaken by an interrupt signal and the moment Xenomai calls the installed interrupt handler ?
Thanks,
Emmanuel.
Quoted 52 lines
-----Original Message-----
From: Emmanuel Pacaud <[email protected]>
Sent: Monday, September 19, 2022 5:41 PM
To: [email protected]
Subject: How to debug realtime interrupt latencyHi,
Let me introduce myself and what I'm working on. I'm a software engineer working on the real time acquisition and control system of the Virgo interferometer:
https://en.wikipedia.org/wiki/Virgo_interferometer . This system is currently based on RTAI 5.2, which allows us to implement control loop up to 50 kHz. Data are exchanged using optical links of in-house PCIe boards. These boards are synchronized using a distributed clock. Each iteration of the control loop is triggered by an interrupt generated by the PCIe board. From the interrupt handler, we are calling a list of computational functions running in user space.I'm currently evaluating Xenomai 3 as a replacement of RTAI 5.2. The first step consist in measuring the interrupt latency. During our tests, one of our machines shown bigger worst case latencies than the RTAI 5.2 based platform running on the same hardware, or even than the same Xenomai 3.1 based platform running on a different hardware. That is why I'm looking for advice on how to debug interrupt latency.
Here is my 3 setups:
CentOS 7 + Linux 4.14.111 + RTAI 5.2 on Dell PowerEdge R630 Intel(R) Xeon(R) CPU E5-2623 v3 @ 3.00GHz
CentOS 7 + Linux 4.14.111 + Xenomai 3.1 on Dell PowerEdge R630 Intel(R) Xeon(R) CPU E5-2623 v3 @ 3.00GHz
CentOS 7 + Linux 4.14.111 + Xenomai 3.1 on DELL PowerEdge T740 Intel(R) Xeon(R) Gold 5222 CPU @ 3.80GHzExcept for the kernel, all the systems run the same OS (NFS mounted root file system).
The interrupt latency measurements are in this figure:
http://emmanuel.pacaud.free.fr/partage/interrupt-latencies.pngAll the systems have irqaffinity=0 and isolcpus=1,2,3. The affinity of the real time interrupt is set to 1.
The real time interrupt is installed using rt_request_irq/rt_assign_irq on RTAI, and xnintr_init/xnintr_affinity on Xenomai.
The interrupt latency is measured using the in-house PCIe board (a time register is latched when the board emit an interrupt, and a current time register is read at the beginning of the interrupt handler).
Quoted 3 lines
What would explain the latency distribution on the DELL R630 + Xenomai compared to RTAI on the same machine, or to itself on the other machine ?
Is that possible that some interrupts have not been triggered as expected?
You may enable /sys/kernel/debug/tracing/events/cobalt_core/cobalt_irq_entry & cobalt_irq_exit events to debug such issue.
Quoted 2 lines
Does Xenomai perform some other tasks before the real time interrupt handler is called ?
I do not think there is other tasks can cause such 10us +delay before xenomai real time interrupt handler on your platform unless other real time interrupt handler occupy cpu with irq off.
Quoted 9 lines
Is there a way in Xenomai to measure the interrupt latency from the moment the kernel is awaken by an interrupt signal and the moment Xenomai calls the installed interrupt handler ?
Thanks,
Emmanuel.
Hi,
Thanks for your answer.
Quoted 5 lines · Hongzhan
Quoted 3 lines
What would explain the latency distribution on the DELL R630 + Xenomai compared to RTAI on the same machine, or to itself on the other machine ?
Is that possible that some interrupts have not been triggered as expected?
I guess it is something I have to check, but it is very unlikely. We are very confident in the PCIe boards we are using for ten years now.
Quoted 2 lines
You may enable
/sys/kernel/debug/tracing/events/cobalt_core/cobalt_irq_entry&cobalt_irq_exitevents to debug such issue.
Ok, thanks. I'll give t a try.
Quoted 5 lines
Quoted 2 lines
Does Xenomai perform some other tasks before the real time interrupt handler is called ?
I do not think there is other tasks can cause such 10us +delay before xenomai real time interrupt handler on your platform unless other real time interrupt handler occupy cpu with irq off.
I have only installed one real time interrupt, but my understanding is Xenomai has its own timer related timer interrupts.
``` pacaud on xxx in ~ ❯ cat /proc/xenomai/irq IRQ CPU0 CPU1 CPU2 CPU3 69: 0 6541955561 0 0 tolm 4352: 0 0 0 0 [sync] 4353: 0 1 1 1 [reschedule] 4354: 0 1 1 1 [timer-ipi] 4355: 616197140 6762902 6915380 6915224 [timer/0] 4419: 0 0 0 0 [virtual] ```
Are these interrupts supposed to be constant time ?
Cheers,
Emmanuel.
Quoted 56 lines
-----Original Message-----
From: Emmanuel Pacaud <[email protected]>
Sent: Wednesday, September 21, 2022 1:30 PM
To: Chen, Hongzhan <[email protected]>
Cc: [email protected]
Subject: RE: How to debug realtime interrupt latencyHi,
Thanks for your answer.
Quoted 8 lines · Hongzhan
Quoted 5 lines
What would explain the latency distribution on the DELL R630 + Xenomai
compared to RTAI on the same machine, or to itself on the other machine
?Is that possible that some interrupts have not been triggered as expected?
I guess it is something I have to check, but it is very unlikely. We are very confident in the PCIe boards we are using for ten years now.
Quoted 3 lines
You may enable
/sys/kernel/debug/tracing/events/cobalt_core/cobalt_irq_entry&cobalt_irq_exitevents to debug such issue.Ok, thanks. I'll give t a try.
Quoted 7 lines
Quoted 2 lines
Does Xenomai perform some other tasks before the real time interrupt handler is called ?
I do not think there is other tasks can cause such 10us +delay before xenomai real time interrupt
handler on your platform unless other real time interrupt handler occupy cpu with irq off.I have only installed one real time interrupt, but my understanding is Xenomai has its own timer related timer interrupts.
``` pacaud on xxx in ~ ❯ cat /proc/xenomai/irq IRQ CPU0 CPU1 CPU2 CPU3 69: 0 6541955561 0 0 tolm 4352: 0 0 0 0 [sync] 4353: 0 1 1 1 [reschedule] 4354: 0 1 1 1 [timer-ipi] 4355: 616197140 6762902 6915380 6915224 [timer/0] 4419: 0 0 0 0 [virtual] ```
Quoted 1 line
Are these interrupts supposed to be constant time ?
It is not constant time but have little jitter. Xenomai timer interrupt handler would not cause such 10us+ large
delay per my understanding. You can try latency test case which Xenomai project itself have(/usr/lib/xenomai/testsuite/latency,depending on your installing) on your platform to check latency value which includes timer interrupt handle latency and Xenomai schedule latency.
Regards
Hongzhan Chen
Quoted 5 lines
Cheers,
Emmanuel.
Quoted 3 lines · Hongzhan
It is not constant time but have little jitter. Xenomai timer interrupt handler would not cause such 10us+ large
delay per my understanding. You can try latency test case which Xenomai project itselfhave(/usr/lib/xenomai/testsuite/latency,depending on your installing)on your platform to check latency value which includes timer interrupt handle latency and Xenomai schedule latency.
Thanks for the infos.
Cheers,
Emmanuel.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 9 lines · Adam Vaughan
Good luck finding the cause Emmanuel!! These things can be so difficult and time consuming to debug.
It’s a totally different platform (Raspberry Pi, years ago), but here’s an example real-time latency debug that was ultimately traced to the DRAM refresh initialization in closed source firmware drivers:
https://github.com/raspberrypi/firmware/issues/497
It may help to use an oscilloscope in infinite persistence on your signals like the above link. The oscilloscope also helped find bugs in the USB driver affecting latency back then for me.
I hope your root cause is easier to find! 🤞
Maintaining our real time stack for 16 years now, I had my share of tedious latency issue debugging :) I hope I will find the root of this one.
Cheers,
Emmanuel.
Quoted 38 lines · Emmanuel Pacaud
Hi,
Let me introduce myself and what I'm working on. I'm a software engineer working on the real time acquisition and control system of the Virgo interferometer:
https://en.wikipedia.org/wiki/Virgo_interferometer . This system is currently based on RTAI 5.2, which allows us to implement control loop up to 50 kHz. Data are exchanged using optical links of in-house PCIe boards. These boards are synchronized using a distributed clock. Each iteration of the control loop is triggered by an interrupt generated by the PCIe board. From the interrupt handler, we are calling a list of computational functions running in user space.I'm currently evaluating Xenomai 3 as a replacement of RTAI 5.2. The first step consist in measuring the interrupt latency. During our tests, one of our machines shown bigger worst case latencies than the RTAI 5.2 based platform running on the same hardware, or even than the same Xenomai 3.1 based platform running on a different hardware. That is why I'm looking for advice on how to debug interrupt latency.
Here is my 3 setups:
CentOS 7 + Linux 4.14.111 + RTAI 5.2 on Dell PowerEdge R630 Intel(R) Xeon(R) CPU E5-2623 v3 @ 3.00GHz
CentOS 7 + Linux 4.14.111 + Xenomai 3.1 on Dell PowerEdge R630 Intel(R) Xeon(R) CPU E5-2623 v3 @ 3.00GHz
CentOS 7 + Linux 4.14.111 + Xenomai 3.1 on DELL PowerEdge T740 Intel(R) Xeon(R) Gold 5222 CPU @ 3.80GHzExcept for the kernel, all the systems run the same OS (NFS mounted root file system).
The interrupt latency measurements are in this figure:
http://emmanuel.pacaud.free.fr/partage/interrupt-latencies.pngAll the systems have irqaffinity=0 and isolcpus=1,2,3. The affinity of the real time interrupt is set to 1.
Quoted 8 lines
The real time interrupt is installed using rt_request_irq/rt_assign_irq on RTAI, and xnintr_init/xnintr_affinity on Xenomai.
The interrupt latency is measured using the in-house PCIe board (a time register is latched when the board emit an interrupt, and a current time register is read at the beginning of the interrupt handler).
Which is the frequency of the timer event in this test case?
Quoted 3 lines
What would explain the latency distribution on the DELL R630 + Xenomai compared to RTAI on the same machine, or to itself on the other machine ?
Hard to say ATM. 10-15 µs could be explained by significantly more cache misses, e.g. after a driver for a graphic adapter has issued wbinvd. Or simply due to more convoluted code paths running the ISR. I understand the test environment between RTAI 5.2 and Xenomai 3.1 does not change, so cache invalidation from the kernel should bite the same way though. Longer IRQ masking is another reason obviously, which is often a function of cache behavior during some interrupt-free section.
Quoted 2 lines
Does Xenomai perform some other tasks before the real time interrupt handler is called ?
No unrelated housekeeping stuff is performed, only IRQ related work is involved upon receipt.
Quoted 4 lines
Is there a way in Xenomai to measure the interrupt latency from the moment the kernel is awaken by an interrupt signal and the moment Xenomai calls the installed interrupt handler ?
As Hongzhan already mentioned, you may want to get some figures from the 'latency' program [1], specifically using the '-t2' option, which measures the IRQ-to-ISR delay in kernel space (excluding any additional latency brought by switching user contexts). This should be equivalent to your current test case, barring the event generator and clock source.
The I-pipe has a built-in tracer (CONFIG_IPIPE_TRACE); running 'latency' with the -f option would get you a snapshot of the active code path before the worst-case figure was measured.
Question: are you stuck with 4.14, or could you upgrade to the 5.x kernel series? (4.x is EOL here, we moved away from the legacy I-pipe to Dovetail [2] with Xenomai 3.2).
[1]
https://xenomai.org/documentation/xenomai-3/html/man1/latency/index.html
[2] https://evlproject.org/dovetail/
Signature · 1 line
Philippe.
Quoted 55 lines · Philippe Gerum
Quoted 38 lines · Emmanuel Pacaud
Hi,
Let me introduce myself and what I'm working on. I'm a software engineer working on the real time acquisition and control system of the Virgo interferometer:
https://en.wikipedia.org/wiki/Virgo_interferometer . This system is currently based on RTAI 5.2, which allows us to implement control loop up to 50 kHz. Data are exchanged using optical links of in-house PCIe boards. These boards are synchronized using a distributed clock. Each iteration of the control loop is triggered by an interrupt generated by the PCIe board. From the interrupt handler, we are calling a list of computational functions running in user space.I'm currently evaluating Xenomai 3 as a replacement of RTAI 5.2. The first step consist in measuring the interrupt latency. During our tests, one of our machines shown bigger worst case latencies than the RTAI 5.2 based platform running on the same hardware, or even than the same Xenomai 3.1 based platform running on a different hardware. That is why I'm looking for advice on how to debug interrupt latency.
Here is my 3 setups:
CentOS 7 + Linux 4.14.111 + RTAI 5.2 on Dell PowerEdge R630 Intel(R) Xeon(R) CPU E5-2623 v3 @ 3.00GHz
CentOS 7 + Linux 4.14.111 + Xenomai 3.1 on Dell PowerEdge R630 Intel(R) Xeon(R) CPU E5-2623 v3 @ 3.00GHz
CentOS 7 + Linux 4.14.111 + Xenomai 3.1 on DELL PowerEdge T740 Intel(R) Xeon(R) Gold 5222 CPU @ 3.80GHzExcept for the kernel, all the systems run the same OS (NFS mounted root file system).
The interrupt latency measurements are in this figure:
http://emmanuel.pacaud.free.fr/partage/interrupt-latencies.pngAll the systems have irqaffinity=0 and isolcpus=1,2,3. The affinity of the real time interrupt is set to 1.
Quoted 8 lines
The real time interrupt is installed using rt_request_irq/rt_assign_irq on RTAI, and xnintr_init/xnintr_affinity on Xenomai.
The interrupt latency is measured using the in-house PCIe board (a time register is latched when the board emit an interrupt, and a current time register is read at the beginning of the interrupt handler).Which is the frequency of the timer event in this test case?
Quoted 3 lines
What would explain the latency distribution on the DELL R630 + Xenomai compared to RTAI on the same machine, or to itself on the other machine ?
Quoted 8 lines
Hard to say ATM. 10-15 µs could be explained by significantly more cache misses, e.g. after a driver for a graphic adapter has issued wbinvd. Or simply due to more convoluted code paths running the ISR. I understand the test environment between RTAI 5.2 and Xenomai 3.1 does not change, so cache invalidation from the kernel should bite the same way though. Longer IRQ masking is another reason obviously, which is often a function of cache behavior during some interrupt-free section.
NOTE: There is a known source of jitter with the Xenomai 3.x series when it comes to dealing with the core timer (which should apply to RTAI as well IIRC), which is related to the single-lock model: beyond 4-6 cores (x86, less with ARM-based SoCs), the lack of SMP scalability this model causes may induce higher latency. To mitigate this, you would need to restrict the set of CPUs allowed to deal with real-time business, using the supported_cpus kernel argument, so that other CPUs do not attempt to grab that single lock as they catch Xenomai timer events uselessly.
Since your test case does not involve the core timer, but rather a common PCI device, this locking should not bite until the rescheduling procedure is called at the end of the ISR though (per-IRQ locking applies to device interrupts until then, not the ugly big lock).
Signature · 1 line
Philippe.
Hi Philippe,
Quoted 2 lines · Philippe Gerum
Emmanuel Pacaud <[email protected]> writes:
...
Quoted 11 lines
Quoted 9 lines
The real time interrupt is installed using rt_request_irq/rt_assign_irq on RTAI, and
xnintr_init/xnintr_affinity
on Xenomai.
The interrupt latency is measured using the in-house PCIe board (a time register is latched when the board emit an interrupt, and a current time register is read at the beginning of the interrupt handler).Which is the frequency of the timer event in this test case?
The PCIe board send an interrupt at 10kHz.
Quoted 11 lines
Quoted 4 lines
What would explain the latency distribution on the DELL R630 +
Xenomai
compared to RTAI on the same machine, or to itself on the other machine ?Hard to say ATM. 10-15 µs could be explained by significantly more cache misses, e.g. after a driver for a graphic adapter has issued wbinvd. Or simply due to more convoluted code paths running the ISR. I understand the test environment between RTAI 5.2 and Xenomai 3.1 does not change, so cache invalidation from the kernel should bite the same way though.
The environnements are the same, as well as the kernel configurations (except for the RTAI and Xenomai specific configuration obviously). So yes, we should have seen the same behaviour using RTAI.
Quoted 2 lines
Longer IRQ masking is another reason obviously, which is often a
function of cache behavior during some interrupt-free section.
Do you mean there could be some interrupt masking done from the non real time part of the kernel ?
Quoted 5 lines
Quoted 2 lines
Does Xenomai perform some other tasks before the real time interrupt handler is called ?
No unrelated housekeeping stuff is performed, only IRQ related work is involved upon receipt.
Ok.
Quoted 11 lines
Quoted 4 lines
Is there a way in Xenomai to measure the interrupt latency from the moment the kernel is awaken by an interrupt signal and the moment Xenomai calls the installed interrupt handler ?
As Hongzhan already mentioned, you may want to get some figures from the 'latency' program [1], specifically using the '-t2' option, which measures the IRQ-to-ISR delay in kernel space (excluding any additional latency brought by switching user contexts). This should be equivalent to your current test case, barring the event generator and clock source.
Quoted 3 lines
The I-pipe has a built-in tracer (
CONFIG_IPIPE_TRACE); running 'latency' with the -f option would get you a snapshot of the active code path before the worst-case figure was measured.
Thanks for the infos.
Quoted 3 lines
Question: are you stuck with 4.14, or could you upgrade to the 5.x kernel series? (4.x is EOL here, we moved away from the legacy I-pipe to Dovetail [2] with Xenomai 3.2).
For the time being it would be better if I could stay with 4.14, as it looks like the 5.X kernel series requires a gcc version more recent that what is provided by our standard base OS (Centos7) . But I will definitely test Xenomai 3 with dovetail.
Thanks again,
Emmanuel.
Quoted 47 lines
-----Original Message-----
From: Emmanuel Pacaud <[email protected]>
Sent: Wednesday, September 21, 2022 9:37 PM
To: Philippe Gerum <[email protected]>
Cc: [email protected]
Subject: Re: How to debug realtime interrupt latencyHi Philippe,
Quoted 2 lines · Philippe Gerum
Emmanuel Pacaud <[email protected]> writes:
...
Quoted 11 lines
Quoted 9 lines
The real time interrupt is installed using rt_request_irq/rt_assign_irq on RTAI, and
xnintr_init/xnintr_affinity
on Xenomai.
The interrupt latency is measured using the in-house PCIe board (a time register is latched when the board emit an interrupt, and a current time register is read at the beginning of the interrupt handler).Which is the frequency of the timer event in this test case?
The PCIe board send an interrupt at 10kHz.
Quoted 5 lines
Quoted 4 lines
What would explain the latency distribution on the DELL R630 +
Xenomai
compared to RTAI on the same machine, or to itself on the other machine ?Quoted 8 lines
Hard to say ATM. 10-15 µs could be explained by significantly more cache
misses, e.g. after a driver for a graphic adapter has issued wbinvd. Or
simply due to more convoluted code paths running the ISR. I understand the test environment between RTAI 5.2 and Xenomai 3.1 does not change, so cache invalidation from the kernel should bite the same way though.The environnements are the same, as well as the kernel configurations (except for the RTAI and Xenomai specific configuration obviously). So yes, we should have seen the same behaviour using RTAI.
Quoted 5 lines
Quoted 2 lines
Longer IRQ masking is another reason obviously, which is often a
function of cache behavior during some interrupt-free section.Do you mean there could be some interrupt masking done from the non real time part of the kernel ?
Theoretically, non real time part cannot mask physical interrupt to cpu after enabling Xenomai because of the interrupt virtualization mechanism implemented by I-PIPE in xenomai 3.1. That means it should not be related to virtual masking done from non real time part.
Regards
Hongzhan Chen
Quoted 45 lines
Quoted 6 lines
Quoted 3 lines
Does Xenomai perform some other tasks before the real time interrupt handler is called ?
No unrelated housekeeping stuff is performed, only IRQ related work is involved upon receipt.
Ok.
Quoted 14 lines
Quoted 4 lines
Is there a way in Xenomai to measure the interrupt latency from the moment the kernel is awaken by an interrupt signal and the moment Xenomai calls the installed interrupt handler ?
As Hongzhan already mentioned, you may want to get some figures from the
'latency' program [1], specifically using the '-t2' option, which measures the IRQ-to-ISR delay in kernel space (excluding any additional
latency brought by switching user contexts). This should be equivalent to your current test case, barring the event generator and clock source.Quoted 4 lines
The I-pipe has a built-in tracer (
CONFIG_IPIPE_TRACE); running 'latency'
with the -f option would get you a snapshot of the active code path before the worst-case figure was measured.Thanks for the infos.
Quoted 4 lines
Question: are you stuck with 4.14, or could you upgrade to the 5.x kernel series? (4.x is EOL here, we moved away from the legacy I-pipe to
Dovetail [2] with Xenomai 3.2).For the time being it would be better if I could stay with 4.14, as it looks like the 5.X kernel series requires a gcc version more recent that what is provided by our standard base OS (Centos7) . But I will definitely test Xenomai 3 with dovetail.
Thanks again,
Emmanuel.