All of lore.kernel.org
 help / color / mirror / Atom feed
From: ZIV-Alberto Ozalla Cantabrana <alberto.ozalla@cgglobal.com>
To: "gilles.chanteperdrix@xenomai.org" <gilles.chanteperdrix@xenomai.org>
Cc: "xenomai@xenomai.org" <xenomai@xenomai.org>
Subject: Re: [Xenomai] rt_task_sleep_until() miss release point?
Date: Thu, 6 Nov 2014 16:46:08 +0000	[thread overview]
Message-ID: <545BA5D0.7010907@cgglobal.com> (raw)
In-Reply-To: <20141106155503.GD30908@sisyphus.hd.free.fr>

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.

  reply	other threads:[~2014-11-06 16:46 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

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=545BA5D0.7010907@cgglobal.com \
    --to=alberto.ozalla@cgglobal.com \
    --cc=gilles.chanteperdrix@xenomai.org \
    --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.