Skip to contentSkip to conversation

Priority inversion

Xenomai-help ROSSIER Daniel 4 participants 14 messages Jul 20, 2006 – Jul 21, 2006

lore
Share & tools
lore
#0 lore raw

Hi all,

Attached, another tricky piece of code.

We actually try to exhibit a priority inversion by using the semaphore (which does not implement the priority inheritance protocol).

We have the three following tasks:

- meteoDataAcquisition: acquiring the mutex, spinning 10ms, releasing the mutex / priority 1 / delayed at 18ms, and then activated with a frequency of 1000 ms from its first activation (so normally, more or less activated at 1018, 2018, 3018, etc.)

- busManagement: acquiring the mutex, spinning 5 ms, releasing the mutex / priority 10 / period of 20 ms.
- comHandling: just spinning 10ms, period of 20 ms.

So, the worst case would be when the meteoDataAcquisition acquired the mutex right before the busManagement, so we can say that the highest priority task will be delayed of 10ms at the worst; we put an alarm of 30ms, then no alarm will raise up; and indeed, it works like that.

Doing the same stuff with the semaphore - just change WITH_MUTEX to 0 - should theoretically lead to an alarm since the comHandling will take the hand, delaying the busManagement over 30ms. Here comes the problem: if we leave the alarm at 30ms, the alarm raises up, as expected. But, if we change the alarm to 31ms, there is no alarm anymore... and we do not understand why? Normally we should see some alarms for some values from 31 to 35ms, since comHandling spins during 10ms. Mytery...

Normally, the task meteoDataAcquisition is aperiodic, and activated on the basis of an IRQ. In order to simulate that, we put the task with a delay of 18ms (yes, that's the reason of 18 ;-)), activated each second (therefore causing the priority inversion systematically). But nothing happens! the system runs, but no alarm raises up with

Many many thanks for your great help!

Daniel

#1 lore raw
Quoted 11 lines · ROSSIER Daniel

Hi all,

Attached, another tricky piece of code.

We actually try to exhibit a priority inversion by using the semaphore (which does not implement the priority inheritance protocol).

We have the three following tasks:

- meteoDataAcquisition: acquiring the mutex, spinning 10ms, releasing the mutex / priority 1 / delayed at 18ms, and then activated with a frequency of 1000 ms from its first activation (so normally, more or less activated at 1018, 2018, 3018, etc.)

Quoted 8 lines

- busManagement: acquiring the mutex, spinning 5 ms, releasing the mutex / priority 10 / period of 20 ms.
- comHandling: just spinning 10ms, period of 20 ms.

So, the worst case would be when the meteoDataAcquisition acquired the mutex right before the busManagement, so we can say that the highest priority task will be delayed of 10ms at the worst; we put an alarm of 30ms, then no alarm will raise up; and indeed, it works like that.

Doing the same stuff with the semaphore - just change WITH_MUTEX to 0 - should theoretically lead to an alarm since the comHandling will take the hand, delaying the busManagement over 30ms. Here comes the problem: if we leave the alarm at 30ms, the alarm raises up, as expected. But, if we change the alarm to 31ms, there is no alarm anymore... and we do not understand why? Normally we should see some alarms for some values from 31 to 35ms, since comHandling spins during 10ms. Mytery...

Normally, the task meteoDataAcquisition is aperiodic, and activated on the basis of an IRQ. In order to simulate that, we put the task with a delay of 18ms (yes, that's the reason of 18 ;-)), activated each second (therefore causing the priority inversion systematically). But nothing happens! the system runs, but no alarm raises up with

With some help from the simulator,
http://download.gna.org/xenomai/screenshots/simulator.png
here is the timeline of your example:

[sys_date*] [task] [alarm_setup*]
0 com
10 bus 15
18 mto
20 bus 35
loop:
20 com
40 bus 45
45 com
60 bus 65
65 com
80 bus 85
85 com
100 bus 105
105 com
118 mto
120 bus 135
jump loop

(*) system and alarm setup dates are expressed in relative ticks since the application startup.

Given that there is never more than 30 ticks between two alarm setups in this timeline (i.e. between ticks #105 and #135), the result you got looks correct.

Signature · 1 line
Philippe.
#2 lore raw

Hi Philippe,

Quoted 46 lines

-----Message d'origine-----
De : Philippe Gerum [mailto:[email protected]]
Envoyé : jeudi, 20. juillet 2006 22:50
À : ROSSIER Daniel
Cc : [email protected]
Objet : Re: [Xenomai-help] Priority inversion

Quoted 6 lines · ROSSIER Daniel

Hi all,

Attached, another tricky piece of code.

We actually try to exhibit a priority inversion by using the semaphore

(which does not implement the priority inheritance protocol).

Quoted 4 lines

We have the three following tasks:

- meteoDataAcquisition: acquiring the mutex, spinning 10ms, releasing

the mutex / priority 1 / delayed at 18ms, and then activated with a frequency of 1000 ms from its first activation (so normally, more or less activated at 1018, 2018, 3018, etc.)

Quoted 2 lines

- busManagement: acquiring the mutex, spinning 5 ms, releasing the mutex

/ priority 10 / period of 20 ms.

Quoted 3 lines

- comHandling: just spinning 10ms, period of 20 ms.

So, the worst case would be when the meteoDataAcquisition acquired the

mutex right before the busManagement, so we can say that the highest priority task will be delayed of 10ms at the worst; we put an alarm of 30ms, then no alarm will raise up; and indeed, it works like that.

Quoted 2 lines

Doing the same stuff with the semaphore - just change WITH_MUTEX to 0 -

should theoretically lead to an alarm since the comHandling will take the hand, delaying the busManagement over 30ms. Here comes the problem: if we leave the alarm at 30ms, the alarm raises up, as expected. But, if we change the alarm to 31ms, there is no alarm anymore... and we do not understand why? Normally we should see some alarms for some values from 31 to 35ms, since comHandling spins during 10ms. Mytery...

Quoted 2 lines

Normally, the task meteoDataAcquisition is aperiodic, and activated on

the basis of an IRQ. In order to simulate that, we put the task with a delay of 18ms (yes, that's the reason of 18 ;-)), activated each second (therefore causing the priority inversion systematically). But nothing happens! the system runs, but no alarm raises up with

Quoted 7 lines

With some help from the simulator,
http://download.gna.org/xenomai/screenshots/simulator.png
here is the timeline of your example:

[sys_date*] [task] [alarm_setup*]
0 com
10 bus 15

Given that the bus prio is 10, and com prio is 5, why the bus doesn't interrupt the com task right after its start in the init_module. I can imagine that the com task has a bit time to execute some instructions, but never spending more than 1-2ms before the bus starts. Is there a problem in the pod initialization?

Quoted 5 lines

18 mto
20 bus 35
loop:
20 com
40 bus 45

This behaviour is not correct. The task mto holds the mutex when prempted by the bus; the bus is using the same mutex and should not be able to run anymore, giving the hand to the mto task in case of mutex, or giving the hand to the the com, using the sema.

Well actually, we found this morning something very strange. It seems that the mutex/sema can be acquired twice, before releasing it! We simply added a printk() at the beginning of the critical section (with timestamp), and noticed that two P(), or two mutex_lock() were performed before the release.

We think that there is an issue with the use of TM_INFINITE as argument in the locking functions. We didn't test any other args.

Quoted 14 lines

45 com
60 bus 65
65 com
80 bus 85
85 com
100 bus 105
105 com
118 mto
120 bus 135
jump loop

(*) system and alarm setup dates are expressed in relative ticks since the application startup.

Quoted 7 lines

Given that there is never more than 30 ticks between two alarm setups in this timeline (i.e. between ticks #105 and #135), the result you got looks correct.

--
Philippe.

Daniel

#3 lore raw
Quoted 53 lines · ROSSIER Daniel

Hi Philippe,

Quoted 50 lines

-----Message d'origine-----
De : Philippe Gerum [mailto:[email protected]]
Envoyé : jeudi, 20. juillet 2006 22:50
À : ROSSIER Daniel
Cc : [email protected]
Objet : Re: [Xenomai-help] Priority inversion

Quoted 6 lines · ROSSIER Daniel

Hi all,

Attached, another tricky piece of code.

We actually try to exhibit a priority inversion by using the semaphore

(which does not implement the priority inheritance protocol).

Quoted 4 lines

We have the three following tasks:

- meteoDataAcquisition: acquiring the mutex, spinning 10ms, releasing

the mutex / priority 1 / delayed at 18ms, and then activated with a frequency of 1000 ms from its first activation (so normally, more or less activated at 1018, 2018, 3018, etc.)

Quoted 2 lines

- busManagement: acquiring the mutex, spinning 5 ms, releasing the mutex

/ priority 10 / period of 20 ms.

Quoted 3 lines

- comHandling: just spinning 10ms, period of 20 ms.

So, the worst case would be when the meteoDataAcquisition acquired the

mutex right before the busManagement, so we can say that the highest priority task will be delayed of 10ms at the worst; we put an alarm of 30ms, then no alarm will raise up; and indeed, it works like that.

Quoted 2 lines

Doing the same stuff with the semaphore - just change WITH_MUTEX to 0 -

should theoretically lead to an alarm since the comHandling will take the hand, delaying the busManagement over 30ms. Here comes the problem: if we leave the alarm at 30ms, the alarm raises up, as expected. But, if we change the alarm to 31ms, there is no alarm anymore... and we do not understand why? Normally we should see some alarms for some values from 31 to 35ms, since comHandling spins during 10ms. Mytery...

Quoted 2 lines

Normally, the task meteoDataAcquisition is aperiodic, and activated on

the basis of an IRQ. In order to simulate that, we put the task with a delay of 18ms (yes, that's the reason of 18 ;-)), activated each second (therefore causing the priority inversion systematically). But nothing happens! the system runs, but no alarm raises up with

With some help from the simulator,
http://download.gna.org/xenomai/screenshots/simulator.png
here is the timeline of your example:

Quoted 6 lines
Quoted 3 lines

[sys_date*] [task] [alarm_setup*]
0 com
10 bus 15

Given that the bus prio is 10, and com prio is 5, why the bus doesn't interrupt the com task right after its start in the init_module. I can imagine that the com task has a bit time to execute some instructions, but never spending more than 1-2ms before the bus starts. Is there a problem in the pod initialization?

Precisely because the task underlying the init_module() routine has a lower priority than the com task, so there is no way for the bus task to be started by the init context before the com task relinquishes the CPU by calling rt_task_wait_period(). The scheduling is then:

init (pri -1)
start com
com (pri 5)
spin
wait_period
init (pri -1)
start bus
bus (pri 10)

Quoted 8 lines
Quoted 5 lines

18 mto
20 bus 35
loop:
20 com
40 bus 45

This behaviour is not correct. The task mto holds the mutex when prempted by the bus; the bus is using the same mutex and should not be able to run anymore, giving the hand to the mto task in case of mutex, or giving the hand to the the com, using the sema.

Nope, the mto task has reached rt_task_wait_period() when the bus task resumes, so the sema4 is free. You should really try running your example over the event-driven simulator, it would be much easier for you to grasp the actual dynamics of this quite tricky code. Even if you don't trust the simulator a priori, you could just analyze what it says the behaviour of your application is, and make your opinion. I've tracked it a few times already, and so far, everything is ok.

Quoted 2 lines

Well actually, we found this morning something very strange. It seems that the mutex/sema can be acquired twice, before releasing it! We simply added a printk() at the beginning of the critical section (with timestamp), and noticed that two P(), or two mutex_lock() were performed before the release.

Nothing strange here: native API mutexes are recursive by construction. Other threads but the current owner would block trying to acquire it. As for the timestamps, how do you obtain them?

Quoted 27 lines

We think that there is an issue with the use of TM_INFINITE as argument in the locking functions. We didn't test any other args.

Quoted 14 lines

45 com
60 bus 65
65 com
80 bus 85
85 com
100 bus 105
105 com
118 mto
120 bus 135
jump loop

(*) system and alarm setup dates are expressed in relative ticks since the application startup.

Quoted 7 lines

Given that there is never more than 30 ticks between two alarm setups in this timeline (i.e. between ticks #105 and #135), the result you got looks correct.

--
Philippe.

Daniel

Signature · 1 line
Philippe.
#4 lore raw
Quoted 111 lines

-----Message d'origine-----
De : Philippe Gerum [mailto:[email protected]]
Envoyé : vendredi, 21. juillet 2006 11:11
À : ROSSIER Daniel
Cc : [email protected]
Objet : RE: [Xenomai-help] Priority inversion

Quoted 17 lines · ROSSIER Daniel

Hi Philippe,

Quoted 14 lines

-----Message d'origine-----
De : Philippe Gerum [mailto:[email protected]]
Envoyé : jeudi, 20. juillet 2006 22:50
À : ROSSIER Daniel
Cc : [email protected]
Objet : Re: [Xenomai-help] Priority inversion

Quoted 6 lines · ROSSIER Daniel

Hi all,

Attached, another tricky piece of code.

We actually try to exhibit a priority inversion by using the

semaphore

Quoted 5 lines
Quoted 5 lines

(which does not implement the priority inheritance protocol).

Quoted 4 lines

We have the three following tasks:

- meteoDataAcquisition: acquiring the mutex, spinning 10ms,

releasing

Quoted 2 lines
Quoted 2 lines

the mutex / priority 1 / delayed at 18ms, and then activated with a frequency of 1000 ms from its first activation (so normally, more or

less

Quoted 3 lines
Quoted 3 lines

activated at 1018, 2018, 3018, etc.)

Quoted 2 lines

- busManagement: acquiring the mutex, spinning 5 ms, releasing the

mutex

Quoted 4 lines
Quoted 4 lines

/ priority 10 / period of 20 ms.

Quoted 3 lines

- comHandling: just spinning 10ms, period of 20 ms.

So, the worst case would be when the meteoDataAcquisition acquired

the

Quoted 5 lines
Quoted 5 lines

mutex right before the busManagement, so we can say that the highest priority task will be delayed of 10ms at the worst; we put an alarm of 30ms, then no alarm will raise up; and indeed, it works like that.

Quoted 2 lines

Doing the same stuff with the semaphore - just change WITH_MUTEX to

0 -

Quoted 1 line
Quoted 1 line

should theoretically lead to an alarm since the comHandling will take

the

Quoted 1 line
Quoted 1 line

hand, delaying the busManagement over 30ms. Here comes the problem: if

we

Quoted 3 lines
Quoted 3 lines

leave the alarm at 30ms, the alarm raises up, as expected. But, if we change the alarm to 31ms, there is no alarm anymore... and we do not understand why? Normally we should see some alarms for some values

from 31

Quoted 3 lines
Quoted 3 lines

to 35ms, since comHandling spins during 10ms. Mytery...

Quoted 2 lines

Normally, the task meteoDataAcquisition is aperiodic, and activated

on

Quoted 2 lines
Quoted 2 lines

the basis of an IRQ. In order to simulate that, we put the task with a delay of 18ms (yes, that's the reason of 18 ;-)), activated each

second

Quoted 7 lines
Quoted 7 lines

(therefore causing the priority inversion systematically). But nothing happens! the system runs, but no alarm raises up with

With some help from the simulator,
http://download.gna.org/xenomai/screenshots/simulator.png
here is the timeline of your example:

Quoted 5 lines
Quoted 3 lines

[sys_date*] [task] [alarm_setup*]
0 com
10 bus 15

Given that the bus prio is 10, and com prio is 5, why the bus doesn't

interrupt the com task right after its start in the init_module. I can imagine that the com task has a bit time to execute some instructions, but never spending more than 1-2ms before the bus starts. Is there a problem in the pod initialization?

Quoted 1 line

Precisely because the task underlying the init_module() routine has a lower priority than the com task, so there is no way for the bus task to be started by the init context before the com task relinquishes the CPU by calling rt_task_wait_period(). The scheduling is then:

init (pri -1)
start com
com (pri 5)
spin
wait_period
init (pri -1)
start bus
bus (pri 10)

Quoted 7 lines
Quoted 5 lines

18 mto
20 bus 35
loop:
20 com
40 bus 45

This behaviour is not correct. The task mto holds the mutex when

prempted by the bus; the bus is using the same mutex and should not be able to run anymore, giving the hand to the mto task in case of mutex, or giving the hand to the the com, using the sema.

Quoted 1 line
Quoted 7 lines

Nope, the mto task has reached rt_task_wait_period() when the bus task resumes, so the sema4 is free. You should really try running your example over the event-driven simulator, it would be much easier for you to grasp the actual dynamics of this quite tricky code. Even if you don't trust the simulator a priori, you could just analyze what it says the behaviour of your application is, and make your opinion. I've tracked it a few times already, and so far, everything is ok.

Ok; I've no problem with an event-driven simulation. We actually did it using Cheddar scheduling simulation tool (see attachement), and the behaviour does not correspond with what happens in Xenomai. A closer look to the meteo task shows that it spins during 10ms. So, I do not see how it can reach the rt_task_wait_period() after 2 ms as shown in your simulation result.

Nevertheless, we are now setting up Xenoscope in order to have a clean simulation environment as you advice.

Quoted 10 lines
Quoted 2 lines

Well actually, we found this morning something very strange. It seems

that the mutex/sema can be acquired twice, before releasing it! We simply added a printk() at the beginning of the critical section (with timestamp), and noticed that two P(), or two mutex_lock() were performed before the release.

Quoted 1 line

Nothing strange here: native API mutexes are recursive by construction. Other threads but the current owner would block trying to acquire it.

Exactly. In our case, there are two different tasks (bus and mto) which can acquire the mutex (no recursion). The traces showed us that the lock was acquired by the two different tasks without any release in between.

Quoted 1 line

As for the timestamps, how do you obtain them?

Simply using rt_timer_read() to make sure that printk() doesn't interleave the traces.

Quoted 28 lines
Quoted 2 lines

We think that there is an issue with the use of TM_INFINITE as argument

in the locking functions. We didn't test any other args.

Quoted 11 lines
Quoted 11 lines

45 com
60 bus 65
65 com
80 bus 85
85 com
100 bus 105
105 com
118 mto
120 bus 135
jump loop

Quoted 4 lines
Quoted 4 lines

(*) system and alarm setup dates are expressed in relative ticks since the application startup.

Given that there is never more than 30 ticks between two alarm setups

in

Quoted 9 lines
Quoted 6 lines

this timeline (i.e. between ticks #105 and #135), the result you got looks correct.

--
Philippe.

Quoted 5 lines
Quoted 2 lines

Daniel

--
Philippe.

Daniel

#5 lore raw

My apologies. Please ignore my previous mail.
Indeed, we made a bad analysis. The mutex seems to be released; we still have the problem, but it might be at the spin() level.

We're now investigating further.
Daniel

Quoted 206 lines

-----Message d'origine-----
De : [email protected] [mailto:[email protected]] De la part de ROSSIER Daniel
Envoyé : vendredi, 21. juillet 2006 13:56
À : [email protected]
Cc : [email protected]
Objet : RE: [Xenomai-help] Priority inversion

Quoted 37 lines

-----Message d'origine-----
De : Philippe Gerum [mailto:[email protected]]
Envoyé : vendredi, 21. juillet 2006 11:11
À : ROSSIER Daniel
Cc : [email protected]
Objet : RE: [Xenomai-help] Priority inversion

Quoted 17 lines · ROSSIER Daniel

Hi Philippe,

Quoted 14 lines

-----Message d'origine-----
De : Philippe Gerum [mailto:[email protected]]
Envoyé : jeudi, 20. juillet 2006 22:50
À : ROSSIER Daniel
Cc : [email protected]
Objet : Re: [Xenomai-help] Priority inversion

Quoted 6 lines · ROSSIER Daniel

Hi all,

Attached, another tricky piece of code.

We actually try to exhibit a priority inversion by using the

semaphore

Quoted 5 lines
Quoted 5 lines

(which does not implement the priority inheritance protocol).

Quoted 4 lines

We have the three following tasks:

- meteoDataAcquisition: acquiring the mutex, spinning 10ms,

releasing

Quoted 2 lines
Quoted 2 lines

the mutex / priority 1 / delayed at 18ms, and then activated with a frequency of 1000 ms from its first activation (so normally, more or

less

Quoted 2 lines
Quoted 2 lines

activated at 1018, 2018, 3018, etc.)

Quoted 1 line
Quoted 9 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

- busManagement: acquiring the mutex, spinning 5 ms, releasing the

mutex

Quoted 4 lines
Quoted 4 lines

/ priority 10 / period of 20 ms.

Quoted 3 lines

- comHandling: just spinning 10ms, period of 20 ms.

So, the worst case would be when the meteoDataAcquisition acquired

the

Quoted 2 lines
Quoted 2 lines

mutex right before the busManagement, so we can say that the highest priority task will be delayed of 10ms at the worst; we put an alarm

of

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

30ms, then no alarm will raise up; and indeed, it works like that.

Quoted 2 lines

Doing the same stuff with the semaphore - just change WITH_MUTEX

to

Quoted 2 lines

0 -

Quoted 1 line
Quoted 1 line

should theoretically lead to an alarm since the comHandling will

take

Quoted 2 lines

the

Quoted 1 line
Quoted 1 line

hand, delaying the busManagement over 30ms. Here comes the problem:

if

Quoted 2 lines

we

Quoted 1 line
Quoted 1 line

leave the alarm at 30ms, the alarm raises up, as expected. But, if

we

Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

change the alarm to 31ms, there is no alarm anymore... and we do not understand why? Normally we should see some alarms for some values

from 31

Quoted 3 lines
Quoted 3 lines

to 35ms, since comHandling spins during 10ms. Mytery...

Quoted 2 lines

Normally, the task meteoDataAcquisition is aperiodic, and

activated

Quoted 2 lines

on

Quoted 1 line
Quoted 1 line

the basis of an IRQ. In order to simulate that, we put the task with

a

Quoted 3 lines
Quoted 1 line
Quoted 1 line

delay of 18ms (yes, that's the reason of 18 ;-)), activated each

second

Quoted 1 line
Quoted 1 line

(therefore causing the priority inversion systematically). But

nothing

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

happens! the system runs, but no alarm raises up with

With some help from the simulator,
http://download.gna.org/xenomai/screenshots/simulator.png
here is the timeline of your example:

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

[sys_date*] [task] [alarm_setup*]
0 com
10 bus 15

Given that the bus prio is 10, and com prio is 5, why the bus doesn't

interrupt the com task right after its start in the init_module. I can imagine that the com task has a bit time to execute some instructions,

but

Quoted 24 lines

never spending more than 1-2ms before the bus starts. Is there a problem in the pod initialization?

Quoted 1 line

Precisely because the task underlying the init_module() routine has a lower priority than the com task, so there is no way for the bus task to be started by the init context before the com task relinquishes the CPU by calling rt_task_wait_period(). The scheduling is then:

init (pri -1)
start com
com (pri 5)
spin
wait_period
init (pri -1)
start bus
bus (pri 10)

Quoted 6 lines
Quoted 5 lines

18 mto
20 bus 35
loop:
20 com
40 bus 45

Quoted 3 lines
Quoted 1 line

This behaviour is not correct. The task mto holds the mutex when

prempted by the bus; the bus is using the same mutex and should not be able to run anymore, giving the hand to the mto task in case of mutex,

or

Quoted 10 lines

giving the hand to the the com, using the sema.

Quoted 1 line

Nope, the mto task has reached rt_task_wait_period() when the bus task resumes, so the sema4 is free. You should really try running your example over the event-driven simulator, it would be much easier for you to grasp the actual dynamics of this quite tricky code. Even if you don't trust the simulator a priori, you could just analyze what it says the behaviour of your application is, and make your opinion. I've tracked it a few times already, and so far, everything is ok.

Ok; I've no problem with an event-driven simulation. We actually did it using Cheddar scheduling simulation tool (see attachement), and the behaviour does not correspond with what happens in Xenomai.
A closer look to the meteo task shows that it spins during 10ms. So, I do not see how it can reach the rt_task_wait_period() after 2 ms as shown in your simulation result.

Nevertheless, we are now setting up Xenoscope in order to have a clean simulation environment as you advice.

Quoted 3 lines
Quoted 2 lines

Well actually, we found this morning something very strange. It seems

that the mutex/sema can be acquired twice, before releasing it! We

simply

Quoted 7 lines

added a printk() at the beginning of the critical section (with timestamp), and noticed that two P(), or two mutex_lock() were performed before the release.

Quoted 1 line

Nothing strange here: native API mutexes are recursive by construction. Other threads but the current owner would block trying to acquire it.

Exactly. In our case, there are two different tasks (bus and mto) which can acquire the mutex (no recursion). The traces showed us that the lock was acquired by the two different tasks without any release in between.

Quoted 1 line

As for the timestamps, how do you obtain them?

Simply using rt_timer_read() to make sure that printk() doesn't interleave the traces.

Quoted 2 lines
Quoted 2 lines

We think that there is an issue with the use of TM_INFINITE as

argument

Quoted 13 lines

in the locking functions. We didn't test any other args.

Quoted 12 lines
Quoted 12 lines

45 com
60 bus 65
65 com
80 bus 85
85 com
100 bus 105
105 com
118 mto
120 bus 135
jump loop

(*) system and alarm setup dates are expressed in relative ticks

since

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

the application startup.

Given that there is never more than 30 ticks between two alarm

setups

Quoted 10 lines

in

Quoted 9 lines
Quoted 6 lines

this timeline (i.e. between ticks #105 and #135), the result you got looks correct.

--
Philippe.

Quoted 5 lines
Quoted 2 lines

Daniel

--
Philippe.

Daniel

#6 lore raw
Quoted 1 line · On Fri, 21 Jul 2006 14:12:47 +0200 "ROSSIER Daniel"…

but it might be at the spin() level.

I have observed that the behaviour of rt_timer_spin() does not fit with the expected behaviour as described in the doxygened comment: its actual awakening time do not increase when it is preempted.

According to the code in timer.c (using 2.1.2) the wakening time seems to be computed once for all at the beginning of the function call.

Am I right?

Daniel

Signature · 4 lines
      Daniel SIMON    Projet POP ART  INRIA Rhone-Alpes
ZIRST, 655 avenue de l'Europe, 38330 MONTBONNOT SAINT MARTIN, FRANCE 
 [email protected] Phone:(33)476615328 Fax:(33)476615252
	 http://pop-art.inrialpes.fr/people/simon/
#7 lore raw
Quoted 5 lines · Daniel Simon
Quoted 1 line · On Fri, 21 Jul 2006 14:12:47 +0200 "ROSSIER Daniel"…

but it might be at the spin() level.

Quoted 8 lines

I have observed that the behaviour of rt_timer_spin() does not fit with the expected behaviour as described in the doxygened comment: its actual awakening time do not increase when it is preempted.

According to the code in timer.c (using 2.1.2) the wakening time seems to be computed once for all at the beginning of the function call.

Am I right?

Partially. The doc doesn't claim that the time during preemption will get added to your requested spin time. Depending on how long you got preempted, the delay /may/ be longer (until the preemption actually ends). Anyway, this could explain some misunderstandings in this tricky scenario here.

[There is actually one undocumented issue of rt_timer_spin: if the task is migrated to another CPU during spin, the end time will not match the new timebase. So, one should not forget to pin such spinning tasks to one CPU first when running on SMP.]

Jan

#8 lore raw
Quoted 21 lines · Jan Kiszka
Quoted 5 lines · Daniel Simon
Quoted 1 line · On Fri, 21 Jul 2006 14:12:47 +0200 "ROSSIER Daniel"…

but it might be at the spin() level.

Quoted 8 lines

I have observed that the behaviour of rt_timer_spin() does not fit with the expected behaviour as described in the doxygened comment: its actual awakening time do not increase when it is preempted.

According to the code in timer.c (using 2.1.2) the wakening time seems to be computed once for all at the beginning of the function call.

Am I right?

Partially. The doc doesn't claim that the time during preemption will get added to your requested spin time. Depending on how long you got preempted, the delay /may/ be longer (until the preemption actually ends). Anyway, this could explain some misunderstandings in this tricky scenario here.

Quoted 5 lines

[There is actually one undocumented issue of rt_timer_spin: if the task is migrated to another CPU during spin, the end time will not match the new timebase. So, one should not forget to pin such spinning tasks to one CPU first when running on SMP.]

Fortunately, this scenario cannot happen, since migration is always a self-targeted action, i.e. tasks can only request migration for themselves, Xenomai never ever forcibly migrates RT threads on its own decision. So if the task spins, it can't request any migration. If the migration comes first, then the spinning occurs on the target CPU, so this is still a non-issue.

Quoted 6 lines

Jan

_______________________________________________
Xenomai-help mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-help

Signature · 1 line
Philippe.
#9 lore raw
In reply to Daniel Simon
Quoted 5 lines · Daniel Simon
Quoted 1 line · On Fri, 21 Jul 2006 14:12:47 +0200 "ROSSIER Daniel"…

but it might be at the spin() level.

Quoted 9 lines

I have observed that the behaviour of rt_timer_spin() does not fit with the expected behaviour as described in the doxygened comment: its actual awakening time do not increase when it is preempted.

According to the code in timer.c (using 2.1.2) the wakening time seems to be computed once for all at the beginning of the function call.

Am I right?

Yes. But nothing is said in the documentation about the determination of the end spinning time, so the doc is right; what it says is that your task is going to wait for a certain count of nanoseconds, as seen from its own POV, it does not say that only cycles spent in actual spinning wait on behalf of the caller should be accounted for. Fact is that the task will have waited for a certain amount of time before returning, what has occurred in the rest of the system during that period is irrelevant to the purpose of rt_task_spin().

I guess that your interpretation of the behaviour of your application has been wrong due to the non-cumulative aspect of rt_timer_spin(), i.e. a first spinning interrupted by a second one will exit immediately upon return if the initial end time has been reached, because of the second spin time. But in any case, this is an expected behaviour.

Quoted 2 lines

Daniel

Signature · 1 line
Philippe.
#10 lore raw
Quoted 34 lines

-----Message d'origine-----
De : [email protected] [mailto:[email protected]] De la part de Philippe Gerum
Envoyé : vendredi, 21. juillet 2006 15:16
À : Daniel Simon
Cc : [email protected]
Objet : Re: [Xenomai-help] Priority inversion

Quoted 5 lines · Daniel Simon
Quoted 1 line · On Fri, 21 Jul 2006 14:12:47 +0200 "ROSSIER Daniel"…

but it might be at the spin() level.

Quoted 9 lines

I have observed that the behaviour of rt_timer_spin() does not fit with the expected behaviour as described in the doxygened comment: its actual awakening time do not increase when it is preempted.

According to the code in timer.c (using 2.1.2) the wakening time seems to be computed once for all at the beginning of the function call.

Am I right?

Yes. But nothing is said in the documentation about the determination of the end spinning time, so the doc is right; what it says is that your task is going to wait for a certain count of nanoseconds, as seen from its own POV, it does not say that only cycles spent in actual spinning wait on behalf of the caller should be accounted for. Fact is that the task will have waited for a certain amount of time before returning, what has occurred in the rest of the system during that period is irrelevant to the purpose of rt_task_spin().

Quoted 5 lines

I guess that your interpretation of the behaviour of your application has been wrong due to the non-cumulative aspect of rt_timer_spin(), i.e. a first spinning interrupted by a second one will exit immediately upon return if the initial end time has been reached, because of the second spin time. But in any case, this is an expected behaviour.

Yes, that's definitively the point; and again, sorry for the mishap with the mutex/sema, which actually perfectly works :-)

Back to rt_timer_spin(), in other words, does it mean that there is a kind of global counter used by this function that evolves over the different tasks when rt_timer_spin() is used, or something like this (no notion of virtual task time)?

Quoted 12 lines
Quoted 3 lines

Daniel

--
Philippe.

_______________________________________________
Xenomai-help mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-help

#11 lore raw
Quoted 52 lines

-----Message d'origine-----
De : [email protected] [mailto:[email protected]] De la part de ROSSIER Daniel
Envoyé : vendredi, 21. juillet 2006 15:40
À : [email protected]; Daniel Simon
Cc : [email protected]
Objet : RE: [Xenomai-help] Priority inversion

Quoted 2 lines

-----Message d'origine-----
De : [email protected] [mailto:[email protected]]

De

Quoted 6 lines

la part de Philippe Gerum
Envoyé : vendredi, 21. juillet 2006 15:16
À : Daniel Simon
Cc : [email protected]
Objet : Re: [Xenomai-help] Priority inversion

Quoted 7 lines
Quoted 6 lines · Daniel Simon
Quoted 1 line · On Fri, 21 Jul 2006 14:12:47 +0200 "ROSSIER Daniel"…

but it might be at the spin() level.

I have observed that the behaviour of rt_timer_spin() does not fit

with

Quoted 1 line
Quoted 1 line

the expected behaviour as described in the doxygened comment: its

actual

Quoted 17 lines
Quoted 7 lines

awakening time do not increase when it is preempted.

According to the code in timer.c (using 2.1.2) the wakening time seems to be computed once for all at the beginning of the function call.

Am I right?

Yes. But nothing is said in the documentation about the determination of the end spinning time, so the doc is right; what it says is that your task is going to wait for a certain count of nanoseconds, as seen from its own POV, it does not say that only cycles spent in actual spinning wait on behalf of the caller should be accounted for. Fact is that the task will have waited for a certain amount of time before returning, what has occurred in the rest of the system during that period is irrelevant to the purpose of rt_task_spin().

Quoted 5 lines

I guess that your interpretation of the behaviour of your application has been wrong due to the non-cumulative aspect of rt_timer_spin(), i.e. a first spinning interrupted by a second one will exit immediately upon return if the initial end time has been reached, because of the second spin time. But in any case, this is an expected behaviour.

Quoted 7 lines

Yes, that's definitively the point; and again, sorry for the mishap with the mutex/sema, which actually perfectly works :-)

Back to rt_timer_spin(), in other words, does it mean that there is a kind of global counter used by this function that evolves over the different tasks when rt_timer_spin() is used, or something like this (no notion of virtual task time)?

An additional point: if we replace rt_timer_spin(n) by looping n times rt_timer_spin(1), the behaviour of this tricky application is correct!

Quoted 18 lines
Quoted 9 lines
Quoted 4 lines

Daniel

--
Philippe.

Quoted 4 lines

_______________________________________________
Xenomai-help mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-help

_______________________________________________
Xenomai-help mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-help

#12 lore raw
In reply to ROSSIER Daniel
Quoted 39 lines · ROSSIER Daniel
Quoted 33 lines

-----Message d'origine-----
De : [email protected] [mailto:[email protected]] De la part de Philippe Gerum
Envoyé : vendredi, 21. juillet 2006 15:16
À : Daniel Simon
Cc : [email protected]
Objet : Re: [Xenomai-help] Priority inversion

Quoted 5 lines · Daniel Simon
Quoted 1 line · On Fri, 21 Jul 2006 14:12:47 +0200 "ROSSIER Daniel"…

but it might be at the spin() level.

Quoted 9 lines

I have observed that the behaviour of rt_timer_spin() does not fit with the expected behaviour as described in the doxygened comment: its actual awakening time do not increase when it is preempted.

According to the code in timer.c (using 2.1.2) the wakening time seems to be computed once for all at the beginning of the function call.

Am I right?

Yes. But nothing is said in the documentation about the determination of the end spinning time, so the doc is right; what it says is that your task is going to wait for a certain count of nanoseconds, as seen from its own POV, it does not say that only cycles spent in actual spinning wait on behalf of the caller should be accounted for. Fact is that the task will have waited for a certain amount of time before returning, what has occurred in the rest of the system during that period is irrelevant to the purpose of rt_task_spin().

Quoted 5 lines

I guess that your interpretation of the behaviour of your application has been wrong due to the non-cumulative aspect of rt_timer_spin(), i.e. a first spinning interrupted by a second one will exit immediately upon return if the initial end time has been reached, because of the second spin time. But in any case, this is an expected behaviour.

Quoted 4 lines

Yes, that's definitively the point; and again, sorry for the mishap with the mutex/sema, which actually perfectly works :-)

Back to rt_timer_spin(), in other words, does it mean that there is a kind of global counter used by this function that evolves over the different tasks when rt_timer_spin() is used, or something like this (no notion of virtual task time)?

rt_task_spin() relies on the free running counter provided by the hw platform, e.g. the TSC on x86. Therefore, on x86 this value is local to the current CPU, but global to any thread executed by this CPU. rt_task_spin() is basically aimed at providing fine grained and short delays for synchronizing with hardware ops without involving any rescheduling.

Xenomai only use real time references, never virtual ones. However, runtime accounting data are available since v2.2, giving the percentage of CPU used by any given task (see /proc/xenomai/stat), which is the only virtual time information available so far, but never used to specify timings though.

Quoted 12 lines
Quoted 12 lines
Quoted 3 lines

Daniel

--
Philippe.

_______________________________________________
Xenomai-help mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-help

Signature · 1 line
Philippe.
#13 lore raw
In reply to ROSSIER Daniel
Quoted 118 lines · ROSSIER Daniel
Quoted 110 lines

-----Message d'origine-----
De : Philippe Gerum [mailto:[email protected]]
Envoyé : vendredi, 21. juillet 2006 11:11
À : ROSSIER Daniel
Cc : [email protected]
Objet : RE: [Xenomai-help] Priority inversion

Quoted 17 lines · ROSSIER Daniel

Hi Philippe,

Quoted 14 lines

-----Message d'origine-----
De : Philippe Gerum [mailto:[email protected]]
Envoyé : jeudi, 20. juillet 2006 22:50
À : ROSSIER Daniel
Cc : [email protected]
Objet : Re: [Xenomai-help] Priority inversion

Quoted 6 lines · ROSSIER Daniel

Hi all,

Attached, another tricky piece of code.

We actually try to exhibit a priority inversion by using the

semaphore

Quoted 5 lines
Quoted 5 lines

(which does not implement the priority inheritance protocol).

Quoted 4 lines

We have the three following tasks:

- meteoDataAcquisition: acquiring the mutex, spinning 10ms,

releasing

Quoted 2 lines
Quoted 2 lines

the mutex / priority 1 / delayed at 18ms, and then activated with a frequency of 1000 ms from its first activation (so normally, more or

less

Quoted 3 lines
Quoted 3 lines

activated at 1018, 2018, 3018, etc.)

Quoted 2 lines

- busManagement: acquiring the mutex, spinning 5 ms, releasing the

mutex

Quoted 4 lines
Quoted 4 lines

/ priority 10 / period of 20 ms.

Quoted 3 lines

- comHandling: just spinning 10ms, period of 20 ms.

So, the worst case would be when the meteoDataAcquisition acquired

the

Quoted 5 lines
Quoted 5 lines

mutex right before the busManagement, so we can say that the highest priority task will be delayed of 10ms at the worst; we put an alarm of 30ms, then no alarm will raise up; and indeed, it works like that.

Quoted 2 lines

Doing the same stuff with the semaphore - just change WITH_MUTEX to

0 -

Quoted 1 line
Quoted 1 line

should theoretically lead to an alarm since the comHandling will take

the

Quoted 1 line
Quoted 1 line

hand, delaying the busManagement over 30ms. Here comes the problem: if

we

Quoted 3 lines
Quoted 3 lines

leave the alarm at 30ms, the alarm raises up, as expected. But, if we change the alarm to 31ms, there is no alarm anymore... and we do not understand why? Normally we should see some alarms for some values

from 31

Quoted 3 lines
Quoted 3 lines

to 35ms, since comHandling spins during 10ms. Mytery...

Quoted 2 lines

Normally, the task meteoDataAcquisition is aperiodic, and activated

on

Quoted 2 lines
Quoted 2 lines

the basis of an IRQ. In order to simulate that, we put the task with a delay of 18ms (yes, that's the reason of 18 ;-)), activated each

second

Quoted 7 lines
Quoted 7 lines

(therefore causing the priority inversion systematically). But nothing happens! the system runs, but no alarm raises up with

With some help from the simulator,
http://download.gna.org/xenomai/screenshots/simulator.png
here is the timeline of your example:

Quoted 5 lines
Quoted 3 lines

[sys_date*] [task] [alarm_setup*]
0 com
10 bus 15

Given that the bus prio is 10, and com prio is 5, why the bus doesn't

interrupt the com task right after its start in the init_module. I can imagine that the com task has a bit time to execute some instructions, but never spending more than 1-2ms before the bus starts. Is there a problem in the pod initialization?

Quoted 1 line

Precisely because the task underlying the init_module() routine has a lower priority than the com task, so there is no way for the bus task to be started by the init context before the com task relinquishes the CPU by calling rt_task_wait_period(). The scheduling is then:

init (pri -1)
start com
com (pri 5)
spin
wait_period
init (pri -1)
start bus
bus (pri 10)

Quoted 7 lines
Quoted 5 lines

18 mto
20 bus 35
loop:
20 com
40 bus 45

This behaviour is not correct. The task mto holds the mutex when

prempted by the bus; the bus is using the same mutex and should not be able to run anymore, giving the hand to the mto task in case of mutex, or giving the hand to the the com, using the sema.

Quoted 1 line
Quoted 7 lines

Nope, the mto task has reached rt_task_wait_period() when the bus task resumes, so the sema4 is free. You should really try running your example over the event-driven simulator, it would be much easier for you to grasp the actual dynamics of this quite tricky code. Even if you don't trust the simulator a priori, you could just analyze what it says the behaviour of your application is, and make your opinion. I've tracked it a few times already, and so far, everything is ok.

Quoted 3 lines

Ok; I've no problem with an event-driven simulation. We actually did it using Cheddar scheduling simulation tool (see attachement), and the behaviour does not correspond with what happens in Xenomai. A closer look to the meteo task shows that it spins during 10ms. So, I do not see how it can reach the rt_task_wait_period() after 2 ms as shown in your simulation result.

Part of the problem is likely that you are using a tick-based time reference, which is not precise enough for the kind of analysis you want to do; using aperiodic timing would be much better.

Quoted 13 lines

Nevertheless, we are now setting up Xenoscope in order to have a clean simulation environment as you advice.

Quoted 10 lines
Quoted 2 lines

Well actually, we found this morning something very strange. It seems

that the mutex/sema can be acquired twice, before releasing it! We simply added a printk() at the beginning of the critical section (with timestamp), and noticed that two P(), or two mutex_lock() were performed before the release.

Quoted 1 line

Nothing strange here: native API mutexes are recursive by construction. Other threads but the current owner would block trying to acquire it.

Quoted 8 lines

Exactly. In our case, there are two different tasks (bus and mto) which can acquire the mutex (no recursion). The traces showed us that the lock was acquired by the two different tasks without any release in between.

Quoted 1 line

As for the timestamps, how do you obtain them?

Simply using rt_timer_read() to make sure that printk() doesn't interleave the traces.

rt_timer_read() returns periodic ticks (i.e. jiffies) in periodic mode, so there is no way you can infere the order of execution of two close events. Use rt_timer_tsc() instead as the timestamping source.

Quoted 36 lines
Quoted 28 lines
Quoted 2 lines

We think that there is an issue with the use of TM_INFINITE as argument

in the locking functions. We didn't test any other args.

Quoted 11 lines
Quoted 11 lines

45 com
60 bus 65
65 com
80 bus 85
85 com
100 bus 105
105 com
118 mto
120 bus 135
jump loop

Quoted 4 lines
Quoted 4 lines

(*) system and alarm setup dates are expressed in relative ticks since the application startup.

Given that there is never more than 30 ticks between two alarm setups

in

Quoted 9 lines
Quoted 6 lines

this timeline (i.e. between ticks #105 and #135), the result you got looks correct.

--
Philippe.

Quoted 5 lines
Quoted 2 lines

Daniel

--
Philippe.

Daniel

Signature · 1 line
Philippe.