* [Xenomai-help] Re: [Xenomai-core] aperiodic xenomai tasks
2006-09-26 15:41 mani bhatti
@ 2006-09-26 16:00 ` Jan Kiszka
0 siblings, 0 replies; 6+ messages in thread
From: Jan Kiszka @ 2006-09-26 16:00 UTC (permalink / raw)
To: mani bhatti; +Cc: xenomai
[-- Attachment #1: Type: text/plain, Size: 5587 bytes --]
mani bhatti wrote:
> Hi friends
> i want to create two aperiodic tasks .I have made a small example and created two tasks and set their priority equal.i have removed rt_task_setPeriodic function from the code but problem is that the task which is started first only it works and the second task which is started later never shows up.If some one tells me the cause of this problem i would be very grateful.The source code is given below.
First of all, please post such requests for help to the xenomai-help
list (I already changed the address in this reply). Xenomai-core is
intended for discussions about the internals of Xenomai.
>
> void zaehler1_task(void *cookie){
> int ret;
>
> // ************************* Xenomai-Krempel ********************************************************************
> // ret = rt_task_set_periodic(NULL, TM_NOW, rt_timer_ns2ticks(task_period_ns1));
> // if (ret) {
> // printf("error while set periodic, code %d\n",ret);
> // return;
> // }
> // ************************* Ende Xenomai-Krempel ****************************************************************
Well, by commenting out this "Xenomai-Krempel" (be careful, people on
these lists may understand German ;)), your real-time task below enters
an infinite loop without any delays (except for the printing).
rt_task_wait_period always fails if you do not switch periodic mode on.
Therefore, the second task never gets a chance to be started.
What was your motivation behind this? You need some clocking for the
real-time task, either periodical timer-driven or some explicit
rt_task_sleep, or you pend it on an external event (provided by a driver
or whatever).
>
>
> // ********************** Beginn des wiederholt ausgefuehrten Codes **********************************************
> while(!end){
> ret = rt_task_set_mode(0, T_PRIMARY, NULL);
> if (ret) {
> printf("error while rt_task_set_mode, code %d\n",ret);
> return;
> }
> ret = rt_task_wait_period();
> printf("T1:Start\n");
>
> if (ret) {
> // printf("error while rt_task_wait_period, code %d\n",ret);
> // return;
> }
> count1++;
>
> printf("T1:Ende:%d\n", count1);
>
> fflush(NULL);
> }
> // ********************** Ende des wiederholt ausgefuehrten Codes ***********************************************
> }
>
> void zaehler2_task(void *cookie){
> int ret;
> long ii;
> long jj;
> double a;
>
> // ************************* Xenomai-Krempel ********************************************************************
> // ret = rt_task_set_periodic(NULL, TM_NOW, rt_timer_ns2ticks(task_period_ns2));
> // if (ret) {
> // printf("error while set periodic, code %d\n",ret);
> // return;
> // }
> // ************************* Ende Xenomai-Krempel ****************************************************************
>
> // ********************** Beginn des wiederholt ausgefuehrten Codes **********************************************
> while(!end){
> ret = rt_task_set_mode(0, T_PRIMARY, NULL);
> if (ret) {
> printf("error while rt_task_set_mode, code %d\n",ret);
> return;
> }
> ret = rt_task_wait_period();
>
> printf("\t\tT2:Start\n");
>
> if (ret) {
> // printf("error while rt_task_wait_period, code %d\n",ret);
> // return;
> }
>
> // for(ii=0; ii<200; ii++) {
> // for(jj=0; jj<1000000; jj++) {
> // a = (double)ii * (double)jj;
> // }
> // }
>
> count2++;
> printf("\t\tT2:Ende:%d\n", count2++);
>
> fflush(NULL);
> }
> // ********************** Ende des wiederholt ausgefuehrten Codes **
>
>
> int main(int argc, char *argv[]) {
> int err, ret;
> printf("start\n");
> // install signal handler
> signal(SIGTERM, clean_exit);
> signal(SIGINT, clean_exit);
> // start timer
> ret = rt_timer_start(TM_ONESHOT);
> switch (ret) {
> case 0: printf("Mit dem Fahrrad nich inn ersten Wagen\n\n");
> break;
> case -EBUSY: printf("timer is running\n");
> break;
> case -ENOSYS: printf("can't start timer\n");
> return ret;
> }
>
> /* create zaehler1_task */
> err = rt_task_create(&zaehler1_task_ptr,"Zaehler_1",STACK_SIZE,STD_PRIO1,0);
> /* create zaehler2_task */
> err = rt_task_create(&zaehler2_task_ptr,"Zaehler_2",STACK_SIZE,STD_PRIO2,0);
>
> /* start zaehler1_task */
> err = rt_task_start(&zaehler1_task_ptr,&zaehler1_task,NULL);
>
> /* start zaehler2_task */
> err = rt_task_start(&zaehler2_task_ptr,&zaehler2_task,NULL);
>
> // wait for signal & return of signal handler
> pause();
> fflush(NULL);
> }
>
Jan
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 250 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Xenomai-help] Re: [Xenomai-core] aperiodic xenomai tasks
[not found] <20060927135543.26891.qmail@domain.hid>
@ 2006-09-27 14:34 ` Jan Kiszka
0 siblings, 0 replies; 6+ messages in thread
From: Jan Kiszka @ 2006-09-27 14:34 UTC (permalink / raw)
To: mani bhatti; +Cc: xenomai-help
[-- Attachment #1: Type: text/plain, Size: 1758 bytes --]
Two requests:
- please use "reply to all" in order to include everyone in this thread,
specifically the list itself
- cut quotes you do not comment on in your reply (helps to grab quickly
what you are referring to - and what not)
mani bhatti wrote:
> Hi Jan Kiszka
> Thanks a lot for your kind reply.Actually my motivation behind this
> question was that i wanted to have two tasks one of the task i want
> to make pariodic and schedule it after 1second and the second task i
> wanted to singnal only after my first task has completed its work so
> that second task completes its work and first task is scheduled
> again and second task signalled and so on.Because second task is
> signalled only when first task completes thats why i wanted to make
> it aperiodic and comment out that rt_task_set_periodic stuff but i am
> not still able to do it because in my case only task no 1 is
> scheduled and task 2 is not signalled at all.Actually i am a new bee
> to xenomai and have experience mostly with programming in C++ thats
> why i have only idea about threading in C++ and java which havent got
> functions like set periodic.If you please tell me how to realize
> above idea in Xenomai i would br very thankful to you.Thanks a lot
> again.
>
Your problem is actually independent of Xenomai. I think you should
first read some basics on interprocess communication. Quick hint
regarding your scenario:
http://en.wikipedia.org/wiki/Semaphore_%28programming%29
You will find related services in Xenomai as well. Also browsing through
the Xenomai doc what's available and then reading up what it is good for
can help to broaden the understanding, and this is essential for writing
real-time software.
Jan
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 250 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Xenomai-help] Re: [Xenomai-core] aperiodic xenomai tasks
[not found] <20060927151753.9409.qmail@domain.hid>
@ 2006-09-27 15:44 ` Jan Kiszka
2006-10-05 13:57 ` [Xenomai-help] Problem with Aperiodic " mani bhatti
2006-11-30 16:45 ` [Xenomai-help] porting to kernel 2.2 mani bhatti
0 siblings, 2 replies; 6+ messages in thread
From: Jan Kiszka @ 2006-09-27 15:44 UTC (permalink / raw)
To: mani bhatti; +Cc: xenomai-help
[-- Attachment #1: Type: text/plain, Size: 1097 bytes --]
mani bhatti wrote:
> Thanks Jan for your reply
> Actually the semaphore and mutexes stuff you have referred to i have
> already grounds for them.The only problem i have is please some body
> tell me that i dont want to make a thread periodic i,e i dont want to
> call a thread after periodic time interval i wanted it to make it
> aperiodic like threads in C++ are scheduled by scheduler byitself
This has nothing to do with C++, rather with the class library you are
used to.
> and sleep on waiting condition with out any specific time interval
> and wake only when signalled from pariodic thread. I hope you
> understand my point.Thanks a lot .
Let's try it differently:
thread_a()
{
rt_task_set_periodic(...);
while (1) {
rt_task_wait_period(NULL);
/* do some work */
if (I_should_trigger_thread_b)
rt_sem_v(&sem);
}
}
thread_b()
{
while (1) {
rt_sem_p(&sem, TM_INFINITE);
/* so some other work */
}
}
Again, read up what the services are exactly doing or you will be lost
once you have to modify things only slightly.
Jan
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 250 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Xenomai-help] Problem with Aperiodic xenomai tasks
2006-09-27 15:44 ` [Xenomai-help] Re: [Xenomai-core] aperiodic xenomai tasks Jan Kiszka
@ 2006-10-05 13:57 ` mani bhatti
2006-11-30 16:45 ` [Xenomai-help] porting to kernel 2.2 mani bhatti
1 sibling, 0 replies; 6+ messages in thread
From: mani bhatti @ 2006-10-05 13:57 UTC (permalink / raw)
To: xenomai-help
[-- Attachment #1: Type: text/plain, Size: 4240 bytes --]
HI
I want to have two tasks in xenomai the pariodic task and the non pariodic tasks which is signalled by the pariodic task.The problem is that if i make one thread pariodic and the other one non pariodic then the pariodic thread never runs after specific time period and only non pariodic thread appears .The code for tasks is given below.I would be very thankful if please some one figure out what wrong i am doing.Thanks
void zaehler1_task(void *cookie){
int ret;
ret = rt_task_set_periodic(NULL, TM_NOW, rt_timer_ns2ticks(task_period_ns1));
if (ret) {
printf("error while set periodic, code %d\n",ret);
return;
}
while(!end){
ret = rt_task_set_mode(0, T_RRB, NULL);
if (ret) {
printf("error while rt_task_set_mode, code %d\n",ret);
return;
}
ret = rt_task_wait_period();
printf("T1:Start\n");
if (ret) {
printf("error while rt_task_wait_period, code %d\n",ret);
return;
}
rt_mutex_lock(&threadmutex,TM_INFINITE);
count1++;
printf("T1:Ende:%d\n", count1);
if(count1==15)
{ rt_cond_signal(&cond); }
rt_mutex_unlock(&threadmutex);
}
}
void zaehler2_task(void *cookie){
int ret;
long ii;
long jj;
double a;
while(!end){
rt_mutex_lock(&threadmutex,TM_INFINITE);
rt_cond_wait(&cond,&threadmutex,TM_INFINITE);
printf("\t\tT2:Start\n");
count2++;
printf("\t\tT2:Ende:%d\n", count2++);
rt_mutex_unlock(&threadmutex);
}
}
int main(int argc, char *argv[]) {
int err, ret;
printf("start\n");
// install signal handler
signal(SIGTERM, clean_exit);
signal(SIGINT, clean_exit);
// start timer
ret = rt_timer_start(TM_ONESHOT);
switch (ret) {
case 0: printf("Mit dem Fahrrad nich inn ersten Wagen\n\n");
break;
case -EBUSY: printf("timer is running\n");
break;
case -ENOSYS: printf("can't start timer\n");
return ret;
}
rt_cond_create(&cond,NULL);
/* create zaehler1_task */
err = rt_task_create(&zaehler1_task_ptr,"Zaehler_1",STACK_SIZE,STD_PRIO1,0);
/* create zaehler2_task */
err = rt_task_create(&zaehler2_task_ptr,"Zaehler_2",STACK_SIZE,STD_PRIO2,0);
/* start zaehler1_task */
err = rt_task_start(&zaehler1_task_ptr,&zaehler1_task,NULL);
/* start zaehler2_task */
err = rt_task_start(&zaehler2_task_ptr,&zaehler2_task,NULL);
// wait for signal & return of signal handler
pause();
fflush(NULL);
return 0;
}
Jan Kiszka <jan.kiszka@domain.hid> wrote: mani bhatti wrote:
> Thanks Jan for your reply
> Actually the semaphore and mutexes stuff you have referred to i have
> already grounds for them.The only problem i have is please some body
> tell me that i dont want to make a thread periodic i,e i dont want to
> call a thread after periodic time interval i wanted it to make it
> aperiodic like threads in C++ are scheduled by scheduler byitself
This has nothing to do with C++, rather with the class library you are
used to.
> and sleep on waiting condition with out any specific time interval
> and wake only when signalled from pariodic thread. I hope you
> understand my point.Thanks a lot .
Let's try it differently:
thread_a()
{
rt_task_set_periodic(...);
while (1) {
rt_task_wait_period(NULL);
/* do some work */
if (I_should_trigger_thread_b)
rt_sem_v(&sem);
}
}
thread_b()
{
while (1) {
rt_sem_p(&sem, TM_INFINITE);
/* so some other work */
}
}
Again, read up what the services are exactly doing or you will be lost
once you have to modify things only slightly.
Jan
---------------------------------
How low will we go? Check out Yahoo! Messengers low PC-to-Phone call rates.
[-- Attachment #2: Type: text/html, Size: 7840 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Xenomai-help] Re: [Xenomai-core] aperiodic xenomai tasks
[not found] <20061005134524.92486.qmail@domain.hid>
@ 2006-10-05 15:24 ` Jan Kiszka
0 siblings, 0 replies; 6+ messages in thread
From: Jan Kiszka @ 2006-10-05 15:24 UTC (permalink / raw)
To: mani bhatti; +Cc: xenomai-help
[-- Attachment #1: Type: text/plain, Size: 410 bytes --]
mani bhatti wrote:
> HI
> I am grateful for the clarification of the concept.Again the problem is that if i make one thread pariodic and the other one non pariodic then the pariodic thread never runs and only non pariodic thread shows up the code for tasks is given below.I would be very thankful if you fifure out the problem.Thanks
Please post a full, compilable version of your test case.
Jan
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 250 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Xenomai-help] porting to kernel 2.2
2006-09-27 15:44 ` [Xenomai-help] Re: [Xenomai-core] aperiodic xenomai tasks Jan Kiszka
2006-10-05 13:57 ` [Xenomai-help] Problem with Aperiodic " mani bhatti
@ 2006-11-30 16:45 ` mani bhatti
1 sibling, 0 replies; 6+ messages in thread
From: mani bhatti @ 2006-11-30 16:45 UTC (permalink / raw)
To: xenomai-help
[-- Attachment #1.1: Type: text/plain, Size: 708 bytes --]
Hi all
Previously i was working with 2.1 version of xenomai kernel but now i have kernel 2.2 and my previous code flags me error about rt_task_wait_period() which i have fixed to rt_task_wait_period(NULL) and also gives me warning rt_start_time is deprecated and i have removed this line because in 2.2 system timer automatically starts but still by
rt_task_set_periodic gives error "system timer not stared" and my program exits due to return statement showing that peridodic mode is not set.i am attaching my code.Please figure out the problem and help me about the bug in program.Thanks all.
---------------------------------
Cheap Talk? Check out Yahoo! Messenger's low PC-to-Phone call rates.
[-- Attachment #1.2: Type: text/html, Size: 861 bytes --]
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 4248410318-doppel_task.c --]
[-- Type: text/x-csrc; name="doppel_task.c", Size: 4860 bytes --]
#include <math.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <sys/time.h>
#include <sys/io.h>
#include <sys/mman.h>
#include <native/task.h>
#include <native/queue.h>
#include <native/intr.h>
#define STACK_SIZE 8192
#define STD_PRIO1 2
#define STD_PRIO2 1
RT_TASK zaehler1_task_ptr;
RT_TASK zaehler2_task_ptr;
int count1 = 0;
int count2 = 0;
int i;
int end = 0;
// --s-ms-us-ns
RTIME task_period_ns1 = 1000000000llu;
RTIME task_period_ns2 = 10000000000llu;
void zaehler1_task(void *cookie){
int ret;
// ************************* Xenomai-Krempel ********************************************************************
ret = rt_task_set_periodic(NULL, TM_NOW, rt_timer_ns2ticks(task_period_ns1));
switch(-ret){
case EINVAL: printf("Task is not a task descriptor\n");
break;
case EIDRM: printf( "Task is a deleted task descriptor\n");
rt_task_sleep(50000); // wait 50us
break;
case ETIMEDOUT: printf("idate different from TM_INFINITE\n");
break;
case EWOULDBLOCK: printf("system timer not stared\n");
break;
case EPERM: printf("task is null\n");
break;
}
if (ret) {
printf("error while set periodic, code %d\n",ret);
return;
}
// ************************* Ende Xenomai-Krempel ****************************************************************
// ********************** Beginn des wiederholt ausgefuehrten Codes **********************************************
while(!end){
/*
ret = rt_task_set_mode(0, T_PRIMARY, NULL);
if (ret) {
printf("error while rt_task_set_mode, code %d\n",ret);
return;
}
*/
ret = rt_task_wait_period(NULL);
printf("T1:Start\n");
if (ret) {
printf("error while rt_task_wait_period, code %d\n",ret);
return;
}
count1++;
printf("T1:Ende:%d\n", count1);
fflush(NULL);
}
// ********************** Ende des wiederholt ausgefuehrten Codes ***********************************************
}
void zaehler2_task(void *cookie){
int ret;
long ii;
long jj;
double a;
unsigned long overrun;
// ************************* Xenomai-Krempel ********************************************************************
ret = rt_task_set_periodic(NULL, TM_NOW, rt_timer_ns2ticks(task_period_ns2));
if (ret) {
printf("error while set periodic, code %d\n",ret);
return;
}
// ************************* Ende Xenomai-Krempel ****************************************************************
// ********************** Beginn des wiederholt ausgefuehrten Codes **********************************************
while(!end){
/* ret = rt_task_set_mode(0, T_PRIMARY, NULL);
if (ret) {
printf("error while rt_task_set_mode, code %d\n",ret);
return;
}
*/
ret = rt_task_wait_period(NULL);
printf("\t\tT2:Start\n");
if (ret) {
printf("error while rt_task_wait_period, code %d\n",ret);
return;
}
for(ii=0; ii<200; ii++) {
for(jj=0; jj<1000000; jj++) {
a = (double)ii * (double)jj;
}
}
count2++;
printf("\t\tT2:Ende:%d\n", count2++);
fflush(NULL);
}
// ********************** Ende des wiederholt ausgefuehrten Codes ***********************************************
}
// signal-handler, to ensure clean exit on Ctrl-C
void clean_exit(int dummy) {
printf("cleanup\n");
end = 1;
rt_task_delete(&zaehler1_task_ptr);
rt_task_delete(&zaehler2_task_ptr);
printf("end\n");
}
int main(int argc, char *argv[]) {
int err, ret;
printf("start\n");
// install signal handler
signal(SIGTERM, clean_exit);
signal(SIGINT, clean_exit);
// start timer
//ret = rt_timer_start(TM_ONESHOT);
/* switch (ret) {
case 0: printf("Mit dem Fahrrad nich inn ersten Wagen\n\n");
break;
case -EBUSY: printf("timer is running\n");
break;
case -ENOSYS: printf("can't start timer\n");
return ret;
}
*/
/* create zaehler1_task */
err = rt_task_create(&zaehler1_task_ptr,"alpha",STACK_SIZE,STD_PRIO1,0);
/* create zaehler2_task */
err = rt_task_create(&zaehler2_task_ptr,"beta",STACK_SIZE,STD_PRIO2,0);
/* start zaehler1_task */
err = rt_task_start(&zaehler1_task_ptr,&zaehler1_task,NULL);
/* start zaehler2_task */
err = rt_task_start(&zaehler2_task_ptr,&zaehler2_task,NULL);
// wait for signal & return of signal handler
pause();
fflush(NULL);
return 0;
}
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2006-11-30 16:45 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20060927151753.9409.qmail@domain.hid>
2006-09-27 15:44 ` [Xenomai-help] Re: [Xenomai-core] aperiodic xenomai tasks Jan Kiszka
2006-10-05 13:57 ` [Xenomai-help] Problem with Aperiodic " mani bhatti
2006-11-30 16:45 ` [Xenomai-help] porting to kernel 2.2 mani bhatti
[not found] <20061005134524.92486.qmail@domain.hid>
2006-10-05 15:24 ` [Xenomai-help] Re: [Xenomai-core] aperiodic xenomai tasks Jan Kiszka
[not found] <20060927135543.26891.qmail@domain.hid>
2006-09-27 14:34 ` Jan Kiszka
2006-09-26 15:41 mani bhatti
2006-09-26 16:00 ` [Xenomai-help] " Jan Kiszka
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.