Skip to contentSkip to conversation

rt_task_sleep_until() miss release point?

Xenomai ZIV-Alberto Ozalla Cantabrana 3 participants 9 messages Nov 6, 2014 – Nov 7, 2014

lore
Share & tools
lore
#0 lore raw

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.

#1 lore raw
Quoted 9 lines · ZIV-Alberto Ozalla Cantabrana

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:

Quoted 7 lines

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.

Quoted 1 line

#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.

Signature · 1 line
					    Gilles.
#2 lore raw

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

Quoted 28 lines · Gilles Chanteperdrix
Quoted 9 lines · ZIV-Alberto Ozalla Cantabrana

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:

Quoted 7 lines

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.

Quoted 1 line

#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.

Signature · 5 lines
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.
#3 lore raw
Quoted 4 lines · ZIV-Alberto Ozalla Cantabrana

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.

Signature · 1 line
					    Gilles.
#4 lore raw

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.

#5 lore raw
Quoted 10 lines · ZIV-Alberto Ozalla Cantabrana

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?

Quoted 3 lines

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.

Quoted 4 lines
    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.

Signature · 1 line
Philippe.
#6 lore raw
Quoted 29 lines · Philippe Gerum
Quoted 10 lines · ZIV-Alberto Ozalla Cantabrana

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.

Quoted 3 lines

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.

Quoted 4 lines
     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.

Signature · 5 lines
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.
#7 lore raw
Quoted 24 lines · ZIV-Alberto Ozalla Cantabrana
Quoted 22 lines · Philippe Gerum
Quoted 10 lines · ZIV-Alberto Ozalla Cantabrana

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.

Quoted 3 lines

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.

Quoted 2 lines
     while (1) {
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
             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?

Signature · 1 line
					    Gilles.
#8 lore raw
In reply to ZIV-Alberto Ozalla Cantabrana
Quoted 14 lines · ZIV-Alberto Ozalla Cantabrana

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)

Quoted 10 lines
{
    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.

Signature · 1 line
Philippe.