From: Philippe Gerum <rpm@xenomai.org>
To: Hubert Talbot <Hubert.Talbot@domain.hid>
Cc: xenomai@xenomai.org
Subject: Re: [Xenomai-help] Rép. : Re: Rép. : Re: T_RRB
Date: Wed, 13 Feb 2008 15:31:52 +0100 [thread overview]
Message-ID: <47B2FF58.9060002@domain.hid> (raw)
In-Reply-To: <47B2B0D102000001001924EB@nwque-vm-gwia.criq.qc.ca>
Hubert Talbot wrote:
> Thanks for explanations. It's clearer now.
>
> But...
>
> In the following code (almost the same), there is one task that dies prematurely.
>
Use GDB to know why.
>
> //******************************************************************************
> #include <stdio.h>
>
> #include <sys/mman.h>
>
> #include <native/task.h>
>
> #include <native/timer.h>
>
> #include <native/sem.h>
>
>
> #define NBTASK 1
>
> #define NSEC 1
>
> #define USEC 1000
>
> #define MSEC 1000000
>
> #define SEC 1000000000LL
>
> #define PERIOD (10 * MSEC)
>
> RT_TASK tasks[NBTASK];
>
> RT_SEM sem;
>
> unsigned long counts[NBTASK];
>
>
>
> static inline unsigned tick_delta(RTIME t0, RTIME t1)
>
> {
> // return ((unsigned)(t1 - t0) * PERIOD) / SEC;
>
> return rt_timer_ticks2ns(t1 - t0) / SEC;
>
> }
>
>
>
> void my_sleep(int nSec, int taskID)
>
> {
>
> RTIME start_ticks, wait_ticks;
>
>
> // wait_ticks = (nSec * SEC) / PERIOD;
>
> wait_ticks = nSec * rt_timer_ns2ticks(SEC);
>
> start_ticks = rt_timer_read();
>
> while (rt_timer_read() - start_ticks <= wait_ticks)
> {
> counts[taskID]++;
> }
>
> }
>
>
>
> void task(void *arg)
>
> {
>
> int taskID = (int)(long)arg;
>
> RTIME start_date, end_date;
>
> RTIME start_ticks, wait_ticks;
>
>
>
> rt_task_slice(NULL, rt_timer_ns2ticks(PERIOD));
>
> rt_task_set_mode(0, T_RRB, 0);
>
> printf("task %d start...\n", taskID);
>
> rt_sem_p(&sem, TM_INFINITE);
>
>
>
> start_date = rt_timer_read();
> my_sleep(5, taskID);
> end_date = rt_timer_read();
>
>
>
> printf("task %d end (%u sec) --> %u\n", taskID, tick_delta(start_date, end_date), counts[taskID]);
>
> }
>
>
>
> int main(void)
>
> {
>
> int rc;
>
> int i;
>
> RTIME tv1, tv2;
>
>
> mlockall(MCL_CURRENT | MCL_FUTURE);
>
> memset(counts, 0, NBTASK * sizeof(unsigned long));
>
>
> rc = rt_timer_set_mode(1 * MSEC);
>
> if (rc != 0)
>
> {
>
> printf("failed to rt_timer_set_mode: %d\n", rc);
>
> return rc;
>
> }
>
> rt_sem_create(&sem, "sem", 0, S_FIFO);
>
>
>
> for (i = 0; i < NBTASK; i++)
>
> {
>
> char szTaskID[20];
>
> sprintf(szTaskID, "Task%02d", i);
>
> rt_task_create(&tasks[i],
>
> szTaskID,
>
> 4096,
>
> 99,
>
> T_JOINABLE);
>
> }
>
>
>
> tv1 = rt_timer_read();
>
>
> for (i = 0; i < NBTASK; i++)
>
> {
>
> RT_TASK_INFO info;
>
>
>
> rt_task_start(&tasks[i], &task, (void *)(long)i);
>
> }
>
>
> rt_sem_broadcast(&sem);
>
>
>
> for (i = 0; i < NBTASK; i++)
>
> {
>
> rt_task_join(&tasks[i]);
>
> printf("task %d count = %u\n", i, counts[i]);
>
> }
>
> tv2 = rt_timer_read();
>
> printf("****** total time: %u (sec)\n\n", tick_delta(tv1, tv2));
>
>
> rt_sem_delete(&sem);
>
> /*
> tv1 = rt_timer_read();
>
>
> my_sleep(10, 9);
>
> tv2 = rt_timer_read();
>
> printf("****** total time: %u (sec)\n\n", tick_delta(tv1, tv2));
>
> */
>
> return 0;
>
> }
>
> //******************************************************************************
>
>
> With...
>
> #define NBTASK 5
> ------------------------
>
>
> output is (task 2 died prematurely):
>
> task 0 start...
> task 1 start...
> task 2 start...
> task 3 start...
> task 4 start...
> task 0 end (5 sec) --> 4452399
> task 1 end (5 sec) --> 4456435
> task 3 end (5 sec) --> 4497016
> task 4 end (5 sec) --> 4513423
> task 0 count = 4452399
> task 1 count = 4456435
> task 2 count = 2687455
> task 3 count = 4497016
> task 4 count = 4513423
> ****** total time: 5 (sec)
>
> #define NBTASK 3
> ------------------------
>
>
> output is (task 2 died prematurely):
>
> task 0 start...
> task 1 start...
> task 2 start...
> task 0 end (5 sec) --> 8130524
> task 1 end (5 sec) --> 8140688
> task 0 count = 8130524
> task 1 count = 8140688
> task 2 count = 4211880
> ****** total time: 5 (sec)
>
> #define NBTASK 1
> ------------------------
>
>
> output is (task 0 died prematurely):
>
> task 0 start...
> task 0 count = 14200778
> ****** total time: 3 (sec)
>
>
> I think it's abnormal. Isn't it?
>
>
> Thanks
>
> Hubert
>
>
>
> _______________________________________________
> Xenomai-help mailing list
> Xenomai-help@domain.hid
> https://mail.gna.org/listinfo/xenomai-help
>
--
Philippe.
prev parent reply other threads:[~2008-02-13 14:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-13 13:56 [Xenomai-help] Rép. : Re: Rép. : Re: T_RRB Hubert Talbot
2008-02-13 14:31 ` Philippe Gerum [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=47B2FF58.9060002@domain.hid \
--to=rpm@xenomai.org \
--cc=Hubert.Talbot@domain.hid \
--cc=xenomai@xenomai.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.