Skip to contentSkip to conversation

interrupt service routine issue

Xenomai-help [email protected] 3 participants 9 messages Jan 28, 2009 – Jan 29, 2009

lore
Share & tools
lore
#0 lore raw

Dear experts

we are working on a systems with Ubuntu Linux 2.6.25.11 and Xenomai 2.4.4. The system has an Intel(R) Pentium(R) M processor 1.73GHz.
The Xenomai installation seems to be ok and also native application tests give right results.

We developed a RT application based on an ISA IRQ.

The application has two RT tasks created with rt_task_create. One task has maximum (99) priority waits and manages the IRQ waiting for it with an rt_intr_wait.
The other task has a lower priority and manages the communication with an external system using TCP/IP sockets.

The IRQ arrive every 1.6 msec and the interrupt service routine takes about 250 usec.
The issue is that sporadically happens that the interrupt service routine takes about 1.7 msec.

I have disabled the graphical interface and any other services that I thought unnecessary.

Any suggestion?
May be useful to rebuild the kernel with an updated Xenomai version? Linked to this message there is my .config file.

Thanks in advance

Stefano

(See attached file: .config)

#1 lore raw
Quoted 6 lines · [email protected] wrote:

Dear experts

we are working on a systems with Ubuntu Linux 2.6.25.11 and Xenomai 2.4.4. The system has an Intel(R) Pentium(R) M processor 1.73GHz.
The Xenomai installation seems to be ok and also native application tests give right results.

Are you sure about this ? To benchmark your system, you should let the latency test run for some time (say 24 hours), with a sustained load. I tend to like the "dohell" script to generate this load. What we could suspect here is SMI issues.

Quoted 9 lines

We developed a RT application based on an ISA IRQ.

The application has two RT tasks created with rt_task_create. One task has maximum (99) priority waits and manages the IRQ waiting for it with an rt_intr_wait.
The other task has a lower priority and manages the communication with an external system using TCP/IP sockets.

Quoted 6 lines

The IRQ arrive every 1.6 msec and the interrupt service routine takes about 250 usec.
The issue is that sporadically happens that the interrupt service routine takes about 1.7 msec.

From what I understand, your "interrupt service routine", is in fact a

Xenomai task which you expect to run in primary mode. Did you check whether it is always running in primary mode? You can ask Xenomai to send a signal to your thread if ever it switches to secondary mode, setting a special mode bit with rt_task_set_mode/pthread_set_mode_np, see online documentation.

Note that you should let your application run with this mode set, to see if it is indeed what causes the overrun. There are services (malloc comes to my mind) which will only cause a mode switch from time to time.

There are also unfortunately ways to have a primary mode thread wait for Linux without causing a mode switch. The typical example is a mutex shared between the two RT tasks, that the low priority task would take before calling a plain Linux services. The high priority task locking this mutex would in fact wait for Linux.

So, this mode bit is no silver bullet, your best option is careful code inspection.

Signature · 1 line
                                                 Gilles.
#2 lore raw

Thanks Gilles,

with your suggestion, setting the special mode bit T_WARNSW for the incriminated task, we found two critical functions that caused switches to secondary mode.

I report them for documentation:

1. We used mmap function used to map a file into memory. The access to the memory caused sometimes the switch to secondary mode.
2. A pthread_cond_signal call used to unlock a waiting task always generates the switch to secondary mode.

We have implemented the two functions in a lower priority thread and the issue was solved.
Thanks to your magic silver bullet!!

To stress my application I have found a DoHell script by Ingo Molnar
(http://marc.info/?l=linux-kernel&m=111947618802722&w=2) but it is uncompleted. Can you send your DoHell script?

Thanks in advance

Stefano

Gilles
Chanteperdrix
<gilles.chanteper To
[email protected]> [email protected]
cc
28/01/2009 14:38 "[email protected]"
<[email protected]>
Subject
Re: [Xenomai-help] interrupt service routine issue

Quoted 3 lines · [email protected] wrote:

Dear experts

we are working on a systems with Ubuntu Linux 2.6.25.11 and Xenomai

2.4.4.

Quoted 3 lines

The system has an Intel(R) Pentium(R) M processor 1.73GHz. The Xenomai installation seems to be ok and also native application tests give right results.

Are you sure about this ? To benchmark your system, you should let the latency test run for some time (say 24 hours), with a sustained load. I tend to like the "dohell" script to generate this load. What we could suspect here is SMI issues.

Quoted 5 lines

We developed a RT application based on an ISA IRQ.

The application has two RT tasks created with rt_task_create. One task has maximum (99) priority waits and manages the IRQ waiting for

it

Quoted 5 lines

with an rt_intr_wait.
The other task has a lower priority and manages the communication with an external system using TCP/IP sockets.

The IRQ arrive every 1.6 msec and the interrupt service routine takes

about

Quoted 5 lines

250 usec.
The issue is that sporadically happens that the interrupt service routine takes about 1.7 msec.

From what I understand, your "interrupt service routine", is in fact a

Xenomai task which you expect to run in primary mode. Did you check whether it is always running in primary mode? You can ask Xenomai to send a signal to your thread if ever it switches to secondary mode, setting a special mode bit with rt_task_set_mode/pthread_set_mode_np, see online documentation.

Note that you should let your application run with this mode set, to see if it is indeed what causes the overrun. There are services (malloc comes to my mind) which will only cause a mode switch from time to time.

There are also unfortunately ways to have a primary mode thread wait for Linux without causing a mode switch. The typical example is a mutex shared between the two RT tasks, that the low priority task would take before calling a plain Linux services. The high priority task locking this mutex would in fact wait for Linux.

So, this mode bit is no silver bullet, your best option is careful code inspection.

--
Gilles.

#3 lore raw
Quoted 10 lines · [email protected] wrote:

Thanks Gilles,

with your suggestion, setting the special mode bit T_WARNSW for the incriminated task, we found two critical functions that caused switches to secondary mode.

I report them for documentation:

1. We used mmap function used to map a file into memory. The access to the memory caused sometimes the switch to secondary mode.

damn, this should not happen, we use mlockall and some additional tricks in the I-pipe patch to avoid that.

Quoted 2 lines

2. A pthread_cond_signal call used to unlock a waiting task always generates the switch to secondary mode.

if it is Linux's pthread_cond_signal, this is normal, if this is Xenomai's pthread_cond_signal, then we have a problem.

Quoted 8 lines

We have implemented the two functions in a lower priority thread and the issue was solved.
Thanks to your magic silver bullet!!

To stress my application I have found a DoHell script by Ingo Molnar
(http://marc.info/?l=linux-kernel&m=111947618802722&w=2) but it is uncompleted. Can you send your DoHell script?

I am afraid it is much the same. I have ltp installed in /ltp and do:

#! /bin/sh

mount | grep -q sda1 || mount /dev/sda1 /mnt
modprobe rtc-cmos

dortc() {
    chrt -f 98 -p `pidof 'IRQ 8'`
    /bin/rtc_wakeup -f 8192 -t 100000
}

run40() {
while true; do ./runalltests.sh -x 40; done
}

while true; do dd if=/dev/zero of=/mnt/bigfile bs=1024000 count=100; done & while true; do killall hackbench; sleep 5; done &
while true; do /ltp/testcases/bin/hackbench 20; done &
( cd /ltp; run40; ) &
ping -l 100000 -q -s 10 -f 192.168.0.5 &
while true; do ls -lR / > /dev/null 2>&1; done &
dortc &

Signature · 1 line
                                                 Gilles.
#4 lore raw
Quoted 7 lines · Gilles Chanteperdrix
Quoted 6 lines · [email protected] wrote:

Thanks Gilles,

with your suggestion, setting the special mode bit T_WARNSW for the incriminated task, we found two critical functions that caused switches to secondary mode.

Quoted 7 lines
Quoted 4 lines

I report them for documentation:

1. We used mmap function used to map a file into memory. The access to the memory caused sometimes the switch to secondary mode.

damn, this should not happen, we use mlockall and some additional tricks in the I-pipe patch to avoid that.

Mmmh, I don't think we can cure (/wrt RT) access to memory mapped files. That's just the same no-go for RT threads as other Linux I/O.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
#5 lore raw
Quoted 10 lines · Jan Kiszka
Quoted 9 lines · Gilles Chanteperdrix
Quoted 8 lines · [email protected] wrote:

Thanks Gilles,

with your suggestion, setting the special mode bit T_WARNSW for the incriminated task, we found two critical functions that caused switches to secondary mode.

I report them for documentation:

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

1. We used mmap function used to map a file into memory. The access to the memory caused sometimes the switch to secondary mode.

damn, this should not happen, we use mlockall and some additional tricks in the I-pipe patch to avoid that.

Mmmh, I don't think we can cure (/wrt RT) access to memory mapped files. That's just the same no-go for RT threads as other Linux I/O.

Well, normally, with mlockall, if you call mmap, the whole file is loaded in memory. Of course, if there are "holes" in your file, a write to the file will cause a fault.

Signature · 1 line
                                                 Gilles.
#6 lore raw
In reply to Gilles Chanteperdrix
Quoted 2 lines

if it is Linux's pthread_cond_signal, this is normal, if this is Xenomai's pthread_cond_signal, then we have a problem.

How can I verify this point?

Gilles
Chanteperdrix
<gilles.chanteper To
[email protected]> [email protected]
cc
29/01/2009 16:39 "[email protected]"
<[email protected]>
Subject
Re: [Xenomai-help] interrupt service routine issue

Quoted 4 lines · [email protected] wrote:

Thanks Gilles,

with your suggestion, setting the special mode bit T_WARNSW for the incriminated task, we found two critical functions that caused switches

to

Quoted 5 lines

secondary mode.

I report them for documentation:

1. We used mmap function used to map a file into memory. The access to

the

Quoted 1 line

memory caused sometimes the switch to secondary mode.

damn, this should not happen, we use mlockall and some additional tricks in the I-pipe patch to avoid that.

Quoted 2 lines

2. A pthread_cond_signal call used to unlock a waiting task always generates the switch to secondary mode.

if it is Linux's pthread_cond_signal, this is normal, if this is Xenomai's pthread_cond_signal, then we have a problem.

Quoted 8 lines

We have implemented the two functions in a lower priority thread and the issue was solved.
Thanks to your magic silver bullet!!

To stress my application I have found a DoHell script by Ingo Molnar
(http://marc.info/?l=linux-kernel&m=111947618802722&w=2) but it is uncompleted. Can you send your DoHell script?

I am afraid it is much the same. I have ltp installed in /ltp and do:

#! /bin/sh

mount | grep -q sda1 || mount /dev/sda1 /mnt
modprobe rtc-cmos

dortc() {
    chrt -f 98 -p `pidof 'IRQ 8'`
    /bin/rtc_wakeup -f 8192 -t 100000
}

run40() {
while true; do ./runalltests.sh -x 40; done
}

while true; do dd if=/dev/zero of=/mnt/bigfile bs=1024000 count=100; done & while true; do killall hackbench; sleep 5; done &
while true; do /ltp/testcases/bin/hackbench 20; done &
( cd /ltp; run40; ) &
ping -l 100000 -q -s 10 -f 192.168.0.5 &
while true; do ls -lR / > /dev/null 2>&1; done &
dortc &

--
Gilles.

#7 lore raw
Quoted 4 lines · [email protected] wrote:
Quoted 2 lines

if it is Linux's pthread_cond_signal, this is normal, if this is Xenomai's pthread_cond_signal, then we have a problem.

How can I verify this point?

Well, you know if you compile for Xenomai posix skin or not.

Signature · 1 line
                                                 Gilles.