Skip to contentSkip to conversation

RT, nonRT communication

Xenomai-help Patrick 5 participants 17 messages Oct 30, 2007 – Nov 12, 2007

lore
Share & tools
lore

Patrick

author
#0 lore raw

Ok, so if I understand I can't use a pthread_mutex between the main thread and a rt_task ?
If I want use pthread_mutex between another pthread and a rt_task, must the pthred be running with SCHED_OTHER ? This value is the default value for pthread !

Thank's

-----Message d'origine-----
De : Gilles Chanteperdrix [mailto:[email protected] Envoyé : mardi, 30. octobre 2007 10:52
À : Patrick
Cc : [email protected]
Objet : Re: [Xenomai-help] TR: RT, nonRT communication

Quoted 10 lines · Patrick

Hi,

Is it possible to share a pthread_mutex between a rt task and a linux pthread ?

No, it is not possible

Quoted 2 lines

My two tasks must share resources and I must protect them against

concurrent

Quoted 4 lines

access.

If pthread_mutex is not the correct way to do it can you tell me how to achieve this ?

The way to handle these border line cases is to make your linux pthread a xenomai thread running with the SCHED_OTHER scheduling policy. Note that the main thread already has this property.

Signature · 1 line
                                               Gilles Chanteperdrix
#1 lore raw
Quoted 29 lines · Patrick
Quoted 29 lines

-----Message d'origine-----
De: Gilles Chanteperdrix [mailto:[email protected]] Envoyé: mardi, 30. octobre 2007 10:52
À: Patrick
Cc: [email protected]
Objet: Re: [Xenomai-help] TR: RT, nonRT communication

Quoted 10 lines · Patrick

Hi,

Is it possible to share a pthread_mutex between a rt task and a linux pthread ?

No, it is not possible

Quoted 2 lines

My two tasks must share resources and I must protect them against

concurrent

Quoted 4 lines

access.

If pthread_mutex is not the correct way to do it can you tell me how to achieve this ?

Quoted 6 lines
Quoted 4 lines

The way to handle these border line cases is to make your linux pthread a xenomai thread running with the SCHED_OTHER scheduling policy. Note that the main thread already has this property.

Ok, so if I understand I can't use a pthread_mutex between the main thread and a rt_task ?

You CAN use a xenomai pthread_mutex between the main thread and a rt_task, the main thread is a xenomai thread running with the SCHED_OTHER scheduling policy.

Quoted 3 lines

If I want use pthread_mutex between another pthread and a rt_task, must the pthred be running with SCHED_OTHER ? This value is the default value for pthread !

The pthread must be a xenomai posix skin thread running with the SCHED_OTHER policy. You can achieve this by creating this pthread with xenomai wrapped pthread_create, or by setting its policy (assuming the thread was created with the non wrapped pthread_create, i.e. __real_pthread_create) with xenomai wrapped pthread_setschedparam.

In other words, if you use Xenomai wrapped functions, everything should be fine. Things become tricky when you decide to use __real_* functions.

Signature · 1 line
                                               Gilles Chanteperdrix
#2 lore raw
Quoted 44 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Gilles Chanteperdrix
Sent: mardi 30 octobre 2007 14:30
To: Patrick
Cc: [email protected]
Subject: Re: [Xenomai-help] RT, nonRT communication

Quoted 12 lines · Patrick
Quoted 12 lines

-----Message d'origine-----
De: Gilles Chanteperdrix [mailto:[email protected]] Envoyé: mardi, 30. octobre 2007 10:52
À: Patrick
Cc: [email protected]
Objet: Re: [Xenomai-help] TR: RT, nonRT communication

Quoted 4 lines · Patrick
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Hi,

Is it possible to share a pthread_mutex between a rt task and a

linux

Quoted 10 lines
Quoted 10 lines
Quoted 1 line

pthread ?

No, it is not possible

Quoted 2 lines

My two tasks must share resources and I must protect them against

concurrent

Quoted 3 lines

access.

If pthread_mutex is not the correct way to do it can you tell me

how to

Quoted 6 lines
Quoted 6 lines
Quoted 1 line

achieve this ?

The way to handle these border line cases is to make your linux pthread a xenomai thread running with the SCHED_OTHER scheduling policy. Note that the main thread already has this property.

Quoted 8 lines
Quoted 1 line

Ok, so if I understand I can't use a pthread_mutex between the main

thread

Quoted 1 line

and a rt_task ?

You CAN use a xenomai pthread_mutex between the main thread and a rt_task, the main thread is a xenomai thread running with the SCHED_OTHER scheduling policy.

I guess there is a misunderstanding of "main thread" here. The main thread should actually not be a xenomai thread since it belongs to a non-RT application. Patrick is actually using the Qt framework on a PXA device which of course is not a RT-domain application. The thing is that the Qt application should somehow retrieve some data issued from RT-application. Currently the Qt application is starting a Xenomai thread - by doing an extern "c" invokation from Qt - and the data list is shared between the main (qt-)thread (non-RT) and the Xenomai thread; that's why Patrick wanted to use a mutex. But indeed, as far as I know, it will be not possible to do that since the waiting queues on sync objects as mutex are managed differently (dealing with linux threads on the one hand, with Xenomai threads on the other hand) between the RT and non-RT domains. So the question would be: how can data be exchanged in a safe way between a non-RT domain and a RT-domain?

Quoted 16 lines
Quoted 1 line

If I want use pthread_mutex between another pthread and a rt_task,

must the

Quoted 1 line

pthred be running with SCHED_OTHER ? This value is the default value

for

Quoted 1 line

pthread !

The pthread must be a xenomai posix skin thread running with the SCHED_OTHER policy. You can achieve this by creating this pthread with xenomai wrapped pthread_create, or by setting its policy (assuming the thread was created with the non wrapped pthread_create, i.e. __real_pthread_create) with xenomai wrapped pthread_setschedparam.

In other words, if you use Xenomai wrapped functions, everything should be fine. Things become tricky when you decide to use __real_* functions.

Quoted 7 lines

--
Gilles Chanteperdrix

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

Daniel

#3 lore raw
Quoted 46 lines · ROSSIER Daniel
Quoted 46 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Gilles Chanteperdrix
Sent: mardi 30 octobre 2007 14:30
To: Patrick
Cc: [email protected]
Subject: Re: [Xenomai-help] RT, nonRT communication

Quoted 12 lines · Patrick
Quoted 12 lines

-----Message d'origine-----
De: Gilles Chanteperdrix [mailto:[email protected]] Envoyé: mardi, 30. octobre 2007 10:52
À: Patrick
Cc: [email protected]
Objet: Re: [Xenomai-help] TR: RT, nonRT communication

Quoted 4 lines · Patrick
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Hi,

Is it possible to share a pthread_mutex between a rt task and a

linux

Quoted 10 lines
Quoted 10 lines
Quoted 1 line

pthread ?

No, it is not possible

Quoted 2 lines

My two tasks must share resources and I must protect them against

concurrent

Quoted 3 lines

access.

If pthread_mutex is not the correct way to do it can you tell me

how to

Quoted 7 lines
Quoted 6 lines
Quoted 1 line

achieve this ?

The way to handle these border line cases is to make your linux pthread a xenomai thread running with the SCHED_OTHER scheduling policy. Note that the main thread already has this property.

Ok, so if I understand I can't use a pthread_mutex between the main

thread

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

and a rt_task ?

You CAN use a xenomai pthread_mutex between the main thread and a rt_task, the main thread is a xenomai thread running with the SCHED_OTHER scheduling policy.

I guess there is a misunderstanding of "main thread" here. The main thread should actually not be a xenomai thread since it belongs to a non-RT application. Patrick is actually using the Qt framework on a PXA device which of course is not a RT-domain application. The thing is that the Qt application should somehow retrieve some data issued from RT-application. Currently the Qt application is starting a Xenomai thread - by doing an extern "c" invokation from Qt - and the data list is shared between the main (qt-)thread (non-RT) and the Xenomai thread; that's why Patrick wanted to use a mutex. But indeed, as far as I know, it will be not possible to do that since the waiting queues on sync objects as mutex are managed differently (dealing with linux threads on the one hand, with Xenomai threads on the other hand) between the RT and non-RT domains. So the question would be: how can data be exchanged in a safe way between a non-RT domain and a RT-domain?

As soon as you compile your application with the flags returned by xeno-config --posix-cflags and xeno-config --posix-ldflags, it really becomes an RT application where all threads are real-time threads. The only way to create a non real-time thread in such an application is by calling __real_pthread_create.

Signature · 1 line
					    Gilles Chanteperdrix.
author
#4 lore raw

Hello,

Do I have to use --posix-cflags and --posix-ldflags together with the --xeno-cflags and --xeno-ldflags or are they exclusive?

Patrick

-----Message d'origine-----
De : Gilles Chanteperdrix [mailto:[email protected] Envoyé : mercredi, 31. octobre 2007 09:44
À : ROSSIER Daniel
Cc : Patrick; [email protected]
Objet : RE: [Xenomai-help] RT, nonRT communication

[...]

As soon as you compile your application with the flags returned by xeno-config --posix-cflags and xeno-config --posix-ldflags, it really becomes an RT application where all threads are real-time threads. The only way to create a non real-time thread in such an application is by calling __real_pthread_create.

Signature · 1 line
					    Gilles Chanteperdrix.
author
#5 lore raw

I have tried to compile my QT application with --posix-cflags and --posix-ldflags but without success. I have a compilation error in syscall.h :

/usr/xenomai/include/asm/xenomai/syscall.h:235: error: expected primary-expression before ‘.’ Token

I think it's because QT is C++ application so it uses g++ and not gcc. And Xenomai is not intended to be compiled with C++ compiler.

Patrick

-----Message d'origine-----
De : [email protected] [mailto:[email protected]] De la part de Patrick
Envoyé : jeudi, 1. novembre 2007 11:04
À : 'Gilles Chanteperdrix'; [email protected]
Objet : Re: [Xenomai-help] RT, nonRT communication

Hello,

Do I have to use --posix-cflags and --posix-ldflags together with the --xeno-cflags and --xeno-ldflags or are they exclusive?

Patrick

-----Message d'origine-----
De : Gilles Chanteperdrix [mailto:[email protected] Envoyé : mercredi, 31. octobre 2007 09:44
À : ROSSIER Daniel
Cc : Patrick; [email protected]
Objet : RE: [Xenomai-help] RT, nonRT communication

[...]

As soon as you compile your application with the flags returned by xeno-config --posix-cflags and xeno-config --posix-ldflags, it really becomes an RT application where all threads are real-time threads. The only way to create a non real-time thread in such an application is by calling __real_pthread_create.

Signature · 7 lines
					    Gilles Chanteperdrix.


_______________________________________________
Xenomai-help mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-help
#6 lore raw
Quoted 9 lines · Patrick

I have tried to compile my QT application with --posix-cflags and --posix-ldflags but without success. I have a compilation error in syscall.h :

/usr/xenomai/include/asm/xenomai/syscall.h:235: error: expected primary-expression before ‘.’ Token

I think it's because QT is C++ application so it uses g++ and not gcc. And Xenomai is not intended to be compiled with C++ compiler.

It _is_ intended and _is_ being used with C++. This doesn't exclude regressions or arch-specific bugs in the headers though. What version, what arch are you using? Can you post the full (related) compiler output?

Jan

author
#7 lore raw

Ok. I use Xenomai 2.4-rc4 with adeos 1.7-06 for arm with 2.6.20 kernel. And the compiler output:

/usr/local/qtopiarm/bin/qmake -unix -o Makefile gui.pro arm-linux-gnueabi-g++ -c -pipe -O2 -Wall -W -D_REENTRANT -D_GNU_SOURCE -D_REENTRANT -D__XENO__ -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/qtopiarm/mkspecs/qws/linux-arm-g++ -I. -I/usr/local/qtopiarm/include/QtCore -I/usr/local/qtopiarm/include/QtCore -I/usr/local/qtopiarm/include/QtNetwork -I/usr/local/qtopiarm/include/QtNetwork -I/usr/local/qtopiarm/include/QtGui -I/usr/local/qtopiarm/include/QtGui -I/usr/local/qtopiarm/include -I. -I/usr/xenomai/include -I/usr/xenomai/include/posix -Iprotlib -I. -I. -o main.o main.cpp
/usr/xenomai/include/asm/xenomai/syscall.h:235: error: expected primary-expression before ‘.’ token
make: *** [main.o] Erreur 1

Thanks

Patrick

-----Message d'origine-----
De : [email protected] [mailto:[email protected] Envoyé : jeudi, 1. novembre 2007 12:23
À : Patrick
Cc : 'Gilles Chanteperdrix'; [email protected] Objet : Re: [Xenomai-help] RT, nonRT communication

Quoted 2 lines · Patrick

I have tried to compile my QT application with --posix-cflags and --posix-ldflags but without success. I have a compilation error in

syscall.h

Quoted 7 lines

:

/usr/xenomai/include/asm/xenomai/syscall.h:235: error: expected primary-expression before ‘.’ Token

I think it's because QT is C++ application so it uses g++ and not gcc. And Xenomai is not intended to be compiled with C++ compiler.

It _is_ intended and _is_ being used with C++. This doesn't exclude regressions or arch-specific bugs in the headers though. What version, what arch are you using? Can you post the full (related) compiler output?

Jan

author
#8 lore raw

Hi all,

I found what was causing the problem (compiling with g++), it's simply that the struct initialization is not g++ compatible :

 __attribute__((weak)) struct __xn_tscinfo __xn_tscinfo = {
         .type = -1

};

should be :

__attribute__((weak)) struct __xn_tscinfo __xn_tscinfo = {
         type : -1

};

I tested this with g++ and gcc versions 4.1.2 and it compiles correctly.

Patrick

-----Message d'origine-----
De : [email protected] [mailto:[email protected]] De la part de Patrick
Envoyé : jeudi, 1. novembre 2007 13:33
À : [email protected]
Cc : [email protected]
Objet : Re: [Xenomai-help] RT, nonRT communication

Ok. I use Xenomai 2.4-rc4 with adeos 1.7-06 for arm with 2.6.20 kernel. And the compiler output:

/usr/local/qtopiarm/bin/qmake -unix -o Makefile gui.pro arm-linux-gnueabi-g++ -c -pipe -O2 -Wall -W -D_REENTRANT -D_GNU_SOURCE -D_REENTRANT -D__XENO__ -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/qtopiarm/mkspecs/qws/linux-arm-g++ -I. -I/usr/local/qtopiarm/include/QtCore -I/usr/local/qtopiarm/include/QtCore -I/usr/local/qtopiarm/include/QtNetwork -I/usr/local/qtopiarm/include/QtNetwork -I/usr/local/qtopiarm/include/QtGui -I/usr/local/qtopiarm/include/QtGui -I/usr/local/qtopiarm/include -I. -I/usr/xenomai/include -I/usr/xenomai/include/posix -Iprotlib -I. -I. -o main.o main.cpp
/usr/xenomai/include/asm/xenomai/syscall.h:235: error: expected primary-expression before ‘.’ token
make: *** [main.o] Erreur 1

Thanks

Patrick

-----Message d'origine-----
De : [email protected] [mailto:[email protected] Envoyé : jeudi, 1. novembre 2007 12:23
À : Patrick
Cc : 'Gilles Chanteperdrix'; [email protected] Objet : Re: [Xenomai-help] RT, nonRT communication

Quoted 2 lines · Patrick

I have tried to compile my QT application with --posix-cflags and --posix-ldflags but without success. I have a compilation error in

syscall.h

Quoted 7 lines

:

/usr/xenomai/include/asm/xenomai/syscall.h:235: error: expected primary-expression before ‘.’ Token

I think it's because QT is C++ application so it uses g++ and not gcc. And Xenomai is not intended to be compiled with C++ compiler.

It _is_ intended and _is_ being used with C++. This doesn't exclude regressions or arch-specific bugs in the headers though. What version, what arch are you using? Can you post the full (related) compiler output?

Jan

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

#9 lore raw
Quoted 9 lines · Patrick

Hi all,

I found what was causing the problem (compiling with g++), it's simply that the struct initialization is not g++ compatible :

 __attribute__((weak)) struct __xn_tscinfo __xn_tscinfo = {
         .type = -1

};

Quoted 7 lines

should be :

__attribute__((weak)) struct __xn_tscinfo __xn_tscinfo = {
         type : -1

};

I tested this with g++ and gcc versions 4.1.2 and it compiles correctly.

...but is fragile, if we are not trying to initialize the structure first member, g++ says:
sorry, unimplemented: non-trivial designated initializers not supported

So, we are better off do it the C++ way.

Signature · 1 line
					    Gilles Chanteperdrix.
author
#10 lore raw
In reply to Jan Kiszka

Hi,

I have another error when I try to compile Xenomai with g++ :

/usr/xenomai/include/native/task.h:292: error: expected ‘,’ or ‘...’ before ‘protected’

I have tried to include this file with and without extern "C" but the issue is the same.

Do you have an idea ?

Thanks in advance

Patrick

-----Message d'origine-----
De : [email protected] [mailto:[email protected] Envoyé : jeudi, 1. novembre 2007 12:23
À : Patrick
Cc : 'Gilles Chanteperdrix'; [email protected] Objet : Re: [Xenomai-help] RT, nonRT communication

Quoted 9 lines
Quoted 2 lines · Patrick

I have tried to compile my QT application with --posix-cflags and --posix-ldflags but without success. I have a compilation error in

syscall.h

Quoted 5 lines

:

/usr/xenomai/include/asm/xenomai/syscall.h:235: error: expected primary-expression before ‘.’ Token

Quoted 9 lines
Quoted 2 lines

I think it's because QT is C++ application so it uses g++ and not gcc. And Xenomai is not intended to be compiled with C++ compiler.

It _is_ intended and _is_ being used with C++. This doesn't exclude regressions or arch-specific bugs in the headers though. What version, what arch are you using? Can you post the full (related) compiler output?

Jan

Ok. I use Xenomai 2.4-rc4 with adeos 1.7-06 for arm with 2.6.20 kernel.

#11 lore raw
Quoted 5 lines · Patrick

Hi,

I have another error when I try to compile Xenomai with g++ :

Quoted 7 lines

/usr/xenomai/include/native/task.h:292: error: expected ',' or '...' before 'protected'

I have tried to include this file with and without extern "C" but the issue is the same.

Do you have an idea ?

Please post some example code that we can compile, because simply #including <native/task.h> in a C++ program works here.

Signature · 1 line
                                               Gilles Chanteperdrix
#12 lore raw
In reply to Patrick
Quoted 6 lines · Patrick

Hi,

I have another error when I try to compile Xenomai with g++ :

/usr/xenomai/include/native/task.h:292: error: expected ‘,’ or ‘...’ before ‘protected’

There is no "protected" text pattern in that file, not even in Xenomai files task.h includes.

Are you sure that you do not drag in some third-party preprocessor definition that replaces something happened to be used in Xenomai headers? Try g++ with "-E" to check what the compiler tries to crunch (or post a simple test case as Gilles requested).

Jan

#13 lore raw
In reply to Patrick
Quoted 9 lines · Patrick

-----Message d'origine-----
De : Gilles Chanteperdrix [mailto:[email protected]] Envoyé : mercredi, 31. octobre 2007 09:44
À : ROSSIER Daniel
Cc : Patrick; [email protected]
Objet : RE: [Xenomai-help] RT, nonRT communication

[...]

Quoted 9 lines
Quoted 5 lines

As soon as you compile your application with the flags returned by xeno-config --posix-cflags and xeno-config --posix-ldflags, it really becomes an RT application where all threads are real-time threads. The only way to create a non real-time thread in such an application is by calling __real_pthread_create.

Do I have to use --posix-cflags and --posix-ldflags together with the --xeno-cflags and --xeno-ldflags or are they exclusive?

--posix-*flags is for compilation for the posix skin, --xeno-*flags is for compilation for other skins. You can use them together if your application uses the posix skin at the same time as another skin.

Signature · 1 line
					    Gilles Chanteperdrix.
author
#14 lore raw
In reply to Gilles Chanteperdrix
Quoted 9 lines

[...]
As soon as you compile your application with the flags returned by xeno-config --posix-cflags and xeno-config --posix-ldflags, it really becomes an RT application where all threads are real-time threads. The only way to create a non real-time thread in such an application is by calling __real_pthread_create.

Gilles Chanteperdrix.

Hi all,

What is the (default) priority of RT pthreads in comparison with native rt_task ?

Thanks in advance

Patrick

#15 lore raw
Quoted 8 lines · Patrick
Quoted 8 lines

[...]
As soon as you compile your application with the flags returned by xeno-config --posix-cflags and xeno-config --posix-ldflags, it really becomes an RT application where all threads are real-time threads. The only way to create a non real-time thread in such an application is by calling __real_pthread_create.

Quoted 7 lines
Quoted 1 line

Gilles Chanteperdrix.

Hi all,

What is the (default) priority of RT pthreads in comparison with native rt_task ?

The default scheduling of RT pthreads is SCHED_OTHER, which means that their priority is 0. This makes them suitable mostly for non real-time duties. native rt_task have no default priority, since passing a priority to rt_task_create is mandatory, but you can create them with a null priority as well if you like.

Signature · 1 line
					    Gilles Chanteperdrix.
#16 lore raw
In reply to ROSSIER Daniel
Quoted 17 lines · ROSSIER Daniel

.....

I guess there is a misunderstanding of "main thread" here. The main thread should actually not be a xenomai thread since it belongs to a non-RT application. Patrick is actually using the Qt framework on a PXA device which of course is not a RT-domain application. The thing is that the Qt application should somehow retrieve some data issued from RT-application. Currently the Qt application is starting a Xenomai thread - by doing an extern "c" invokation from Qt - and the data list is shared between the main (qt-)thread (non-RT) and the Xenomai thread; that's why Patrick wanted to use a mutex. But indeed, as far as I know, it will be not possible to do that since the waiting queues on sync objects as mutex are managed differently (dealing with linux threads on the one hand, with Xenomai threads on the other hand) between the RT and non-RT domains. So the question would be: how can data be exchanged in a safe way between a non-RT domain and a RT-domain?

We are using Posix message queues and/or shared memory.

Works for either way.

Best regards,

Daniel.