All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai] rt_task_sleep_until() miss release point?
@ 2014-11-06 15:24 ZIV-Alberto Ozalla Cantabrana
  2014-11-06 15:37 ` Gilles Chanteperdrix
  0 siblings, 1 reply; 9+ messages in thread
From: ZIV-Alberto Ozalla Cantabrana @ 2014-11-06 15:24 UTC (permalink / raw)
  To: xenomai

Hi all,

enclosed you will find two examples:

  *   rt_task_sleep_until() missing release point, and
  *   rt_task_sleep_until() working fine.

In the first example:

Current time: t1=4205571 ms - Calculated next release point: t2= 4205572 ms
Real release: t3=4205574 ms

Many Thanks
Alberto Ozalla

Simplest example that shows the issue:
________________________________
static RT_TASK Test_Task_descriptor;

static void Test_Task(void *arg)
{
    RTIME t1, t2;
    rt_task_set_mode(0, 0, NULL);

    while(1) {

        t1 = rt_timer_tsc();
        t2 = t1 + 24000;        // 24000 tsc = 1 ms

        cu_log(CU_LOG_ERR, "t1(%lld)-t2(%lld)", rt_timer_tsc2ns(t1), rt_timer_tsc2ns(t2));
        rt_task_sleep_until(rt_timer_tsc2ns(t2));
        cu_log(CU_LOG_ERR, "t3(%lld)", rt_timer_tsc2ns(rt_timer_tsc()));
    }
}

void main(void)
{
    ...
    // Real-time function creation.
       if (int err = rt_task_create(&Test_Task_descriptor, "Test_Task", 0, 79, 0)) {
             cu_log(CU_LOG_ERR, "Error creating Test_Task (%d)", err);
         }

     // Real-time function started.
       if(rt_task_start(&Test_Task_descriptor, &Test_Task, NULL)) {
             cu_log(CU_LOG_ERR, "Error starting Test_Task");
       }
     ...
}

Log traces:

t1(4205571256580)-t2(4205572256580) ns
t3(4205574861288)
t1(4205575085163)-t2(4205576 085163)
t3(4205578686872)
t1(4205578899038)-t2(4205579 899038)
t3(4205582499538)
t1(4205582839455)-t2(4205583 839455)
t3(4205586444497)
t1(4205586669455)-t2(4205587 669455)
t3(4205590273872)
________________________________
Additional data:

Xenomai 2.6.4
Linux version 3.14.17 (gcc version 4.7.3 (GCC) )
#1 SMP 20<6>kernel: [    0.000000] CPU: ARMv7 Processor [413fc082] revision 2 (ARMv7), cr=10c5387d
2000/01/03,02:42:00  kern.info kernel: [    0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
2000/01/03,02:42:00  kern.info kernel: [    0.000000] Machine model: TI AM335x BeagleBone
2000/01/03,02:42:00  kern.info kernel: [    0.000000] CPU: All CPU(s) started in SVC mode.
2000/01/03,02:42:00  kern.info kernel: [    0.000000] AM335X ES2.1 (sgx neon )
________________________________
In the other hand, this example works fine:

static void Test_Task(void *arg)
{
    rt_task_set_mode(0, 0, NULL);

    RTIME t1, t2;

    while(1) {
        t1 = rt_timer_read();
        t2 = t1 + 1000000;        //  1 ms

        cu_log(CU_LOG_ERR, "t1(%lld)-t2(%lld)", t1, t2);
        rt_task_sleep_until(t2);
        cu_log(CU_LOG_ERR, "t3(%lld)", rt_timer_read());
    }
}

t1(564272 373824)-t2(564273 373824)
t3(564273 387783)
________________________________
Many Thanks
Alberto Ozalla

CG DISCLAIMER: This email contains confidential information. It is intended exclusively for the addressees. If you are not an addressee, you must not store, transmit or disclose its contents. Instead please notify the sender immediately; and permanently delete this e-mail from your computer systems. We have taken reasonable precautions to ensure that no viruses are present. However, you must check this email and the attachments, for viruses. We accept no liability whatsoever, for any detriment caused by any transmitted virus.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Xenomai] rt_task_sleep_until() miss release point?
  2014-11-06 15:24 [Xenomai] rt_task_sleep_until() miss release point? ZIV-Alberto Ozalla Cantabrana
@ 2014-11-06 15:37 ` Gilles Chanteperdrix
  2014-11-06 15:52   ` ZIV-Alberto Ozalla Cantabrana
  0 siblings, 1 reply; 9+ messages in thread
From: Gilles Chanteperdrix @ 2014-11-06 15:37 UTC (permalink / raw)
  To: ZIV-Alberto Ozalla Cantabrana; +Cc: xenomai

On Thu, Nov 06, 2014 at 03:24:08PM +0000, ZIV-Alberto Ozalla Cantabrana wrote:
> Hi all,
> 
> enclosed you will find two examples:
> 
>   *   rt_task_sleep_until() missing release point, and
>   *   rt_task_sleep_until() working fine.
> 
> In the first example:
> 
> Current time: t1=4205571 ms - Calculated next release point: t2= 4205572 ms
> Real release: t3=4205574 ms
> 
> Many Thanks
> Alberto Ozalla
> 
> Simplest example that shows the issue:

When you post an example, please post a "self contained" one, i.e.
one that can be compiled and run without:
- any missing code or ellipses
- references to functions not contained in the code or xenomai
librairies, such as cu_log.

> #1 SMP 20<6>kernel: [    0.000000] CPU: ARMv7 Processor [413fc082] revision 2 (ARMv7), cr=10c5387d

You do not need CONFIG_SMP on an uniprocessor, this adds some
overhead. The overhead is mitigated on Xenomai 3, but not on xenomai
2.x.

-- 
					    Gilles.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Xenomai] rt_task_sleep_until() miss release point?
  2014-11-06 15:37 ` Gilles Chanteperdrix
@ 2014-11-06 15:52   ` ZIV-Alberto Ozalla Cantabrana
  2014-11-06 15:55     ` Gilles Chanteperdrix
  0 siblings, 1 reply; 9+ messages in thread
From: ZIV-Alberto Ozalla Cantabrana @ 2014-11-06 15:52 UTC (permalink / raw)
  To: gilles.chanteperdrix; +Cc: xenomai

Hi all,

Sorry about missing references to function cu_log().
You can omit cu_log calls (It is like printf).
There are in place to see where the log traces are taken.

Regards
Alberto
On 06/11/14 16:37, Gilles Chanteperdrix wrote:
> On Thu, Nov 06, 2014 at 03:24:08PM +0000, ZIV-Alberto Ozalla Cantabrana wrote:
>> Hi all,
>>
>> enclosed you will find two examples:
>>
>>    *   rt_task_sleep_until() missing release point, and
>>    *   rt_task_sleep_until() working fine.
>>
>> In the first example:
>>
>> Current time: t1=4205571 ms - Calculated next release point: t2= 4205572 ms
>> Real release: t3=4205574 ms
>>
>> Many Thanks
>> Alberto Ozalla
>>
>> Simplest example that shows the issue:
> When you post an example, please post a "self contained" one, i.e.
> one that can be compiled and run without:
> - any missing code or ellipses
> - references to functions not contained in the code or xenomai
> librairies, such as cu_log.
>
>> #1 SMP 20<6>kernel: [    0.000000] CPU: ARMv7 Processor [413fc082] revision 2 (ARMv7), cr=10c5387d
> You do not need CONFIG_SMP on an uniprocessor, this adds some
> overhead. The overhead is mitigated on Xenomai 3, but not on xenomai
> 2.x.
>

-- 
Saludos,
Alberto Ozalla


CG DISCLAIMER: This email contains confidential information. It is intended exclusively for the addressees. If you are not an addressee, you must not store, transmit or disclose its contents. Instead please notify the sender immediately; and permanently delete this e-mail from your computer systems. We have taken reasonable precautions to ensure that no viruses are present. However, you must check this email and the attachments, for viruses. We accept no liability whatsoever, for any detriment caused by any transmitted virus.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Xenomai] rt_task_sleep_until() miss release point?
  2014-11-06 15:52   ` ZIV-Alberto Ozalla Cantabrana
@ 2014-11-06 15:55     ` Gilles Chanteperdrix
  2014-11-06 16:46       ` ZIV-Alberto Ozalla Cantabrana
  0 siblings, 1 reply; 9+ messages in thread
From: Gilles Chanteperdrix @ 2014-11-06 15:55 UTC (permalink / raw)
  To: ZIV-Alberto Ozalla Cantabrana; +Cc: xenomai

On Thu, Nov 06, 2014 at 03:52:45PM +0000, ZIV-Alberto Ozalla Cantabrana wrote:
> Hi all,
> 
> Sorry about missing references to function cu_log().
> You can omit cu_log calls (It is like printf).

The problem is that printf will cause a switch to secondary mode,
which you do not want to happen. So, please rewrite your example
using functions from xenomai libraries, test it again, and see if
printf is not the problem.

-- 
					    Gilles.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Xenomai] rt_task_sleep_until() miss release point?
  2014-11-06 15:55     ` Gilles Chanteperdrix
@ 2014-11-06 16:46       ` ZIV-Alberto Ozalla Cantabrana
  2014-11-06 20:22         ` Philippe Gerum
  2014-11-07  9:42         ` Philippe Gerum
  0 siblings, 2 replies; 9+ messages in thread
From: ZIV-Alberto Ozalla Cantabrana @ 2014-11-06 16:46 UTC (permalink / raw)
  To: gilles.chanteperdrix; +Cc: xenomai

Hi,

These are the simplest examples:
There are no MSW for Test_Task.
The goal is to increment counter_ms each millisecond.

Given that:
1000000 nanoseconds = 24000 tsc.
1 tsc = 41 ns

RT_TASK Test_Task_descriptor;
volatile unsigned long long counter_ms;

void Test_Task(void *arg)
{
    rt_task_set_mode(0, 0, NULL);

    RTIME t1, t2;
    counter_ms = 0;

    while(1) {
        t1 = rt_timer_tsc();
        t2 = t1 + 24000;        // 24000 tsc = 1 ms
        rt_task_sleep_until(rt_timer_tsc2ns(t2));
        counter_ms++;
    }
}

void main ()
{
    // Real-time function creation.
    if (int err = rt_task_create(&Test_Task_descriptor, "Test_Task", 0, 79, 0)) {
        cu_log(CU_LOG_ERR, "Error creating Test_Task (%d)", err);
    }

    // Real-time function started.
    if(rt_task_start(&Test_Task_descriptor, &Test_Task, NULL)) {
        cu_log(CU_LOG_ERR, "Error starting Test_Task");
    }

    while (1) {

            unsigned long long before = counter_ms;
            usleep(1000000);    // 1 second.
            printf( "Miliseconds = %llu", (counter_ms - before));
    }
}

Output of printf:

Miliseconds = 264>>>Fail . It should be 1000 ms.
Miliseconds = 263
...
________________________________
This example works fine:

void Test_Task(void *arg)
{
    rt_task_set_mode(0, 0, NULL);
    RTIME t1, t2;
    counter_ms = 0;

    while(1) {
         t1 = rt_timer_read();
         t2 = t1 + 1000000;        //  1 ms
        rt_task_sleep_until(t2);
        counter_ms++;
    }
}

Output of printf:

Miliseconds = 989
Miliseconds = 991
...
Many thanks.
Alberto

On 06/11/14 16:55, Gilles Chanteperdrix wrote:

On Thu, Nov 06, 2014 at 03:52:45PM +0000, ZIV-Alberto Ozalla Cantabrana wrote:


Hi all,

Sorry about missing references to function cu_log().
You can omit cu_log calls (It is like printf).



The problem is that printf will cause a switch to secondary mode,
which you do not want to happen. So, please rewrite your example
using functions from xenomai libraries, test it again, and see if
printf is not the problem.




--
Saludos,
Alberto Ozalla

CG DISCLAIMER: This email contains confidential information. It is intended exclusively for the addressees. If you are not an addressee, you must not store, transmit or disclose its contents. Instead please notify the sender immediately; and permanently delete this e-mail from your computer systems. We have taken reasonable precautions to ensure that no viruses are present. However, you must check this email and the attachments, for viruses. We accept no liability whatsoever, for any detriment caused by any transmitted virus.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Xenomai] rt_task_sleep_until() miss release point?
  2014-11-06 16:46       ` ZIV-Alberto Ozalla Cantabrana
@ 2014-11-06 20:22         ` Philippe Gerum
  2014-11-07  9:25           ` ZIV-Alberto Ozalla Cantabrana
  2014-11-07  9:42         ` Philippe Gerum
  1 sibling, 1 reply; 9+ messages in thread
From: Philippe Gerum @ 2014-11-06 20:22 UTC (permalink / raw)
  To: alberto.ozalla, gilles.chanteperdrix; +Cc: xenomai

On 11/06/2014 05:46 PM, ZIV-Alberto Ozalla Cantabrana wrote:
> Hi,
> 
> These are the simplest examples:
> There are no MSW for Test_Task.
> The goal is to increment counter_ms each millisecond.
> 
> Given that:
> 1000000 nanoseconds = 24000 tsc.
> 1 tsc = 41 ns
> 

Is rt_timer_ns2tsc(1000000) actually returning 24000 on your platform?

> void Test_Task(void *arg)
> {
>    rt_task_set_mode(0, 0, NULL);

This is useless and not recommended. A newly created task always starts
in primary mode.

>     while (1) {
> 
>             unsigned long long before = counter_ms;
>             usleep(1000000);    // 1 second.

Although this would rather cause higher count values, this non-rt main
using a non-rt sleep service won't give you an accurate delay for the
measurement.

-- 
Philippe.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Xenomai] rt_task_sleep_until() miss release point?
  2014-11-06 20:22         ` Philippe Gerum
@ 2014-11-07  9:25           ` ZIV-Alberto Ozalla Cantabrana
  2014-11-07  9:37             ` Gilles Chanteperdrix
  0 siblings, 1 reply; 9+ messages in thread
From: ZIV-Alberto Ozalla Cantabrana @ 2014-11-07  9:25 UTC (permalink / raw)
  To: rpm; +Cc: xenomai


On 06/11/14 21:22, Philippe Gerum wrote:
> On 11/06/2014 05:46 PM, ZIV-Alberto Ozalla Cantabrana wrote:
>> Hi,
>>
>> These are the simplest examples:
>> There are no MSW for Test_Task.
>> The goal is to increment counter_ms each millisecond.
>>
>> Given that:
>> 1000000 nanoseconds = 24000 tsc.
>> 1 tsc = 41 ns
>>
> Is rt_timer_ns2tsc(1000000) actually returning 24000 on your platform?
> Yes.
>> void Test_Task(void *arg)
>> {
>>     rt_task_set_mode(0, 0, NULL);
> This is useless and not recommended. A newly created task always starts
> in primary mode.
>
> Ok. I will delete it.
>>      while (1) {
>>
>>              unsigned long long before = counter_ms;
>>              usleep(1000000);    // 1 second.
> Although this would rather cause higher count values, this non-rt main
> using a non-rt sleep service won't give you an accurate delay for the
> measurement.
>
> It is only an example.

-- 
Saludos,
Alberto Ozalla


CG DISCLAIMER: This email contains confidential information. It is intended exclusively for the addressees. If you are not an addressee, you must not store, transmit or disclose its contents. Instead please notify the sender immediately; and permanently delete this e-mail from your computer systems. We have taken reasonable precautions to ensure that no viruses are present. However, you must check this email and the attachments, for viruses. We accept no liability whatsoever, for any detriment caused by any transmitted virus.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Xenomai] rt_task_sleep_until() miss release point?
  2014-11-07  9:25           ` ZIV-Alberto Ozalla Cantabrana
@ 2014-11-07  9:37             ` Gilles Chanteperdrix
  0 siblings, 0 replies; 9+ messages in thread
From: Gilles Chanteperdrix @ 2014-11-07  9:37 UTC (permalink / raw)
  To: ZIV-Alberto Ozalla Cantabrana; +Cc: xenomai

On Fri, Nov 07, 2014 at 09:25:21AM +0000, ZIV-Alberto Ozalla Cantabrana wrote:
> 
> On 06/11/14 21:22, Philippe Gerum wrote:
> > On 11/06/2014 05:46 PM, ZIV-Alberto Ozalla Cantabrana wrote:
> >> Hi,
> >>
> >> These are the simplest examples:
> >> There are no MSW for Test_Task.
> >> The goal is to increment counter_ms each millisecond.
> >>
> >> Given that:
> >> 1000000 nanoseconds = 24000 tsc.
> >> 1 tsc = 41 ns
> >>
> > Is rt_timer_ns2tsc(1000000) actually returning 24000 on your platform?
> > Yes.
> >> void Test_Task(void *arg)
> >> {
> >>     rt_task_set_mode(0, 0, NULL);
> > This is useless and not recommended. A newly created task always starts
> > in primary mode.
> >
> > Ok. I will delete it.
> >>      while (1) {
> >>
> >>              unsigned long long before = counter_ms;
> >>              usleep(1000000);    // 1 second.
> > Although this would rather cause higher count values, this non-rt main
> > using a non-rt sleep service won't give you an accurate delay for the
> > measurement.
> >
> > It is only an example.

The problem is that so far, you have not been able to provide a
correct example which provides a proof of what you are saying. It
does not mean that what you say is wrong, just that we have reasons
to doubt it.

Anyway, I do not think you can assume that
rt_timer_tsc2ns(rt_timer_tsc()) is the same thing as
rt_timer_read(), I would say the first is equivalent to POSIX
CLOCK_MONOTONIC whereas the second is equivalent to CLOCK_REALTIME,
so, there is an offset between the two.

What rt_task_sleep_until expects, is what rt_timer_read() returns

To check that, right after the call to rt_task_sleep_until, call
rt_timer_read (and not rt_timer_tsc), and see if it is near t2. You
can use rt_printf in a real-time task to avoid switches to secondary
mode.

Also, are you running the native skin timer in periodic or aperiodic
mode?

-- 
					    Gilles.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Xenomai] rt_task_sleep_until() miss release point?
  2014-11-06 16:46       ` ZIV-Alberto Ozalla Cantabrana
  2014-11-06 20:22         ` Philippe Gerum
@ 2014-11-07  9:42         ` Philippe Gerum
  1 sibling, 0 replies; 9+ messages in thread
From: Philippe Gerum @ 2014-11-07  9:42 UTC (permalink / raw)
  To: alberto.ozalla, gilles.chanteperdrix; +Cc: xenomai

On 11/06/2014 05:46 PM, ZIV-Alberto Ozalla Cantabrana wrote:
> Hi,
> 
> These are the simplest examples:
> There are no MSW for Test_Task.
> The goal is to increment counter_ms each millisecond.
> 
> Given that:
> 1000000 nanoseconds = 24000 tsc.
> 1 tsc = 41 ns
> 
> RT_TASK Test_Task_descriptor;
> volatile unsigned long long counter_ms;
> 
> void Test_Task(void *arg)
> {
>     rt_task_set_mode(0, 0, NULL);
> 
>     RTIME t1, t2;
>     counter_ms = 0;
> 
>     while(1) {
>         t1 = rt_timer_tsc();
>         t2 = t1 + 24000;        // 24000 tsc = 1 ms
>         rt_task_sleep_until(rt_timer_tsc2ns(t2));

rt_task_sleep_until() refers to the real-time clock for applying delays,
i.e. adjusted with the wallclock offset. You can't pass it a value based
on the monotonic clock. This is why using timevals based on
rt_timer_read() works, but using rt_timer_tsc() doesn't.

-- 
Philippe.


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-11-07  9:42 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-06 15:24 [Xenomai] rt_task_sleep_until() miss release point? ZIV-Alberto Ozalla Cantabrana
2014-11-06 15:37 ` Gilles Chanteperdrix
2014-11-06 15:52   ` ZIV-Alberto Ozalla Cantabrana
2014-11-06 15:55     ` Gilles Chanteperdrix
2014-11-06 16:46       ` ZIV-Alberto Ozalla Cantabrana
2014-11-06 20:22         ` Philippe Gerum
2014-11-07  9:25           ` ZIV-Alberto Ozalla Cantabrana
2014-11-07  9:37             ` Gilles Chanteperdrix
2014-11-07  9:42         ` Philippe Gerum

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.