* [Xenomai] Demo example of a simple periodic thread for Xenomai (Posix API)
@ 2015-08-21 18:53 Marc Le Douarain
2015-08-21 21:22 ` Gilles Chanteperdrix
0 siblings, 1 reply; 3+ messages in thread
From: Marc Le Douarain @ 2015-08-21 18:53 UTC (permalink / raw)
To: Xenomai
Hello eveybody,
As I haven't found a little example of a periodic thread written in Posix,
I've tried to do it.
Here you will find joined the demo files example.
It can be (cross-)compiled for :
- Standard Linux
- Xenomai 2
- Xenomai 3
In the Makefile, comment 2 lines MY_CFLAGS & MY_LDFLAGS to compile for
standard Linux.
Hope it can be helpfull for other people,
and many thanks for any comments or mistakes reports on it !
OUPPSS, JUST SEEN that XENOMAI version 3 is doing 'modes switches'... so
there is something bad! Any idea ?
Perhaps to include a basic example like this one in the "demo" directory
of Xenomai would be interesting!?
Best regards.
PS: I have beed disapointed at the start to discover no more
pthread_make_periodic_np() & pthread_wait_np() functions with Xenomai 3.
But finally now with a timerfd we can have the same sourcecode with
standard Linux, so not too bad ! ;-)
And also no more the "__XENO__" define, but also usefull for conditional
compilation, with the new "__COBALT__" !
-------------- next part --------------
A non-text attachment was scrubbed...
Name: demo_periodic_thread_posix.c
Type: text/x-csrc
Size: 4513 bytes
Desc: not available
URL: <http://xenomai.org/pipermail/xenomai/attachments/20150821/fabd6c48/attachment.c>
-------------- next part --------------
# MakeFile for demo of a simple periodic thread using Posix
# under 'standard' Linux
# and under Xenomai versions 2 and 3 using posix skin
# Marc Le Douarain, august 2015
#CROSS := arm-linux-gnueabi-
# For a 'standard' application...
MY_LDFLAGS = -lpthread
# Comment theses 2 lines for a 'standard' application...
MY_CFLAGS = `xeno-config --skin posix --cflags`
MY_LDFLAGS = `xeno-config --skin posix --ldflags`
CC := ${CROSS}gcc
all: demo_periodic_thread_posix
OBJS := demo_periodic_thread_posix.o
demo_periodic_thread_posix: ${OBJS}
${CC} -o $@ ${OBJS} $(MY_LDFLAGS)
clean:
-rm -f core ${OBJS} demo_periodic_thread_posix
demo_periodic_thread_posix.o: demo_periodic_thread_posix.c
${CC} -c $< -o $@ $(MY_CFLAGS)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Xenomai] Demo example of a simple periodic thread for Xenomai (Posix API)
2015-08-21 18:53 [Xenomai] Demo example of a simple periodic thread for Xenomai (Posix API) Marc Le Douarain
@ 2015-08-21 21:22 ` Gilles Chanteperdrix
2015-08-24 19:45 ` Marc Le Douarain
0 siblings, 1 reply; 3+ messages in thread
From: Gilles Chanteperdrix @ 2015-08-21 21:22 UTC (permalink / raw)
To: Marc Le Douarain; +Cc: Xenomai
On Fri, Aug 21, 2015 at 08:53:26PM +0200, Marc Le Douarain wrote:
> Hello eveybody,
>
> As I haven't found a little example of a periodic thread written in Posix,
> I've tried to do it.
>
> Here you will find joined the demo files example.
> It can be (cross-)compiled for :
> - Standard Linux
> - Xenomai 2
> - Xenomai 3
> In the Makefile, comment 2 lines MY_CFLAGS & MY_LDFLAGS to compile for
> standard Linux.
>
> Hope it can be helpfull for other people,
> and many thanks for any comments or mistakes reports on it !
> OUPPSS, JUST SEEN that XENOMAI version 3 is doing 'modes switches'... so
> there is something bad! Any idea ?
>
> Perhaps to include a basic example like this one in the "demo" directory of
> Xenomai would be interesting!?
>
> Best regards.
>
> PS: I have beed disapointed at the start to discover no more
> pthread_make_periodic_np() & pthread_wait_np() functions with
> Xenomai 3.
These functions were there to help porting legacy code from RTLinux,
they were not really meant to be used in new code.
> But
> finally now with a timerfd we can have the same sourcecode with standard
> Linux, so not too bad ! ;-)
> And also no more the "__XENO__" define, but also usefull for conditional
> compilation, with the new "__COBALT__" !
>
>
> -------------- next part --------------
> A non-text attachment was scrubbed...
> Name: demo_periodic_thread_posix.c
>
> (...)
>
> int CreatePosixTask( char * TaskName, int Priority, int StackSizeInKo, unsigned int PeriodMicroSecs, void * (*pTaskFunction)(void *) )
> {
> pthread_attr_t ThreadAttributes;
> pthread_attr_init(&ThreadAttributes);
> pthread_attr_setdetachstate(&ThreadAttributes, PTHREAD_CREATE_DETACHED /*PTHREAD_CREATE_JOINABLE*/);
> #if defined(__XENO__) || defined(__COBALT__)
> pthread_attr_setschedpolicy(&ThreadAttributes, SCHED_FIFO);
> struct sched_param paramA = { .sched_priority = Priority };
> pthread_attr_setschedparam(&ThreadAttributes, ¶mA);
A call to pthread_attr_setinheritsched is missing here. The default
for inheritsched is PTHREAD_INHERIT_SCHED, which means the new
thread inherits the main thread scheduling policy and priority,
which is usually SCHED_OTHER and 0 (unless you run the program with
chrt), in which case the newly created thread switches back to
secondary mode after every primary mode switch.
--
Gilles.
https://click-hack.org
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Xenomai] Demo example of a simple periodic thread for Xenomai (Posix API)
2015-08-21 21:22 ` Gilles Chanteperdrix
@ 2015-08-24 19:45 ` Marc Le Douarain
0 siblings, 0 replies; 3+ messages in thread
From: Marc Le Douarain @ 2015-08-24 19:45 UTC (permalink / raw)
To: Xenomai
Le 21/08/2015 23:22, Gilles Chanteperdrix a écrit :
> On Fri, Aug 21, 2015 at 08:53:26PM +0200, Marc Le Douarain wrote:
>> Hello eveybody,
>>
>> As I haven't found a little example of a periodic thread written in Posix,
>> I've tried to do it.
>>
>> Here you will find joined the demo files example.
>> It can be (cross-)compiled for :
>> - Standard Linux
>> - Xenomai 2
>> - Xenomai 3
>> In the Makefile, comment 2 lines MY_CFLAGS & MY_LDFLAGS to compile for
>> standard Linux.
>>
>> Hope it can be helpfull for other people,
>> and many thanks for any comments or mistakes reports on it !
>> OUPPSS, JUST SEEN that XENOMAI version 3 is doing 'modes switches'... so
>> there is something bad! Any idea ?
>>
>> Perhaps to include a basic example like this one in the "demo" directory of
>> Xenomai would be interesting!?
>>
>> Best regards.
>>
>> PS: I have beed disapointed at the start to discover no more
>> pthread_make_periodic_np() & pthread_wait_np() functions with
>> Xenomai 3.
> These functions were there to help porting legacy code from RTLinux,
> they were not really meant to be used in new code.
Started with it to have real-time under Linux a long time ago now ! ;-)
(but as many people I suppose, except too youngs...)
>> But
>> finally now with a timerfd we can have the same sourcecode with standard
>> Linux, so not too bad ! ;-)
>> And also no more the "__XENO__" define, but also usefull for conditional
>> compilation, with the new "__COBALT__" !
>>
>>
>> -------------- next part --------------
>> A non-text attachment was scrubbed...
>> Name: demo_periodic_thread_posix.c
>>
>> (...)
>>
>> int CreatePosixTask( char * TaskName, int Priority, int StackSizeInKo, unsigned int PeriodMicroSecs, void * (*pTaskFunction)(void *) )
>> {
>> pthread_attr_t ThreadAttributes;
>> pthread_attr_init(&ThreadAttributes);
>> pthread_attr_setdetachstate(&ThreadAttributes, PTHREAD_CREATE_DETACHED /*PTHREAD_CREATE_JOINABLE*/);
>> #if defined(__XENO__) || defined(__COBALT__)
>> pthread_attr_setschedpolicy(&ThreadAttributes, SCHED_FIFO);
>> struct sched_param paramA = { .sched_priority = Priority };
>> pthread_attr_setschedparam(&ThreadAttributes, ¶mA);
> A call to pthread_attr_setinheritsched is missing here. The default
> for inheritsched is PTHREAD_INHERIT_SCHED, which means the new
> thread inherits the main thread scheduling policy and priority,
> which is usually SCHED_OTHER and 0 (unless you run the program with
> chrt), in which case the newly created thread switches back to
> secondary mode after every primary mode switch.
>
Thanks for the tip,
modified my example (and also added some errors messages, seen stack
asked too little!), and now no more Modes SWitches under Xenomai 3, nice !
See files included.
Now, if time, I will be able to continue to test with an application a
little bigger on Xenomai 3 (ClassicLadder)...
Best regards.
Marc.
-------------- next part --------------
# MakeFile for demo of a simple periodic thread using Posix
# under 'standard' Linux
# and under Xenomai versions 2 and 3 using posix skin
# Marc Le Douarain, august 2015
#CROSS := arm-linux-gnueabi-
# For a 'standard' application...
MY_LDFLAGS = -lpthread
# Comment theses 2 lines for a 'standard' application...
MY_CFLAGS = `xeno-config --skin posix --cflags`
MY_LDFLAGS = `xeno-config --skin posix --ldflags`
CC := ${CROSS}gcc
all: demo_periodic_thread_posix
OBJS := demo_periodic_thread_posix.o
demo_periodic_thread_posix: ${OBJS}
${CC} -o $@ ${OBJS} $(MY_LDFLAGS)
clean:
-rm -f core ${OBJS} demo_periodic_thread_posix
demo_periodic_thread_posix.o: demo_periodic_thread_posix.c
${CC} -c $< -o $@ $(MY_CFLAGS)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: demo_periodic_thread_posix.c
Type: text/x-csrc
Size: 5597 bytes
Desc: not available
URL: <http://xenomai.org/pipermail/xenomai/attachments/20150824/cefcf519/attachment.c>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-08-24 19:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-21 18:53 [Xenomai] Demo example of a simple periodic thread for Xenomai (Posix API) Marc Le Douarain
2015-08-21 21:22 ` Gilles Chanteperdrix
2015-08-24 19:45 ` Marc Le Douarain
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.