Re: Error "Jumps" in long time tests

Paolo Mantegazza <[email protected]>
Newsgroups gmane.linux.real-time.rtai
Message-ID <VI1PR06MB147110B92C67DD6EF5C75C6990060@VI1PR06MB1471.eurprd06.prod.outlook.com>
Please have a look at the attachment.  It does not support your claims. I let you check what you could have done wrong.
You should also notice that your test case is nothing but the nth latency checker. You could have avoided loosing time
by simply going to testsuite/user/latency/latency.c, set the period to 25000000 and let it run for hours.
Since I do not see the inclusion of rtai_posix.h, there are chances that you linked in the LInux posix lib, so that the use of your mutexes was not in real time.
Nonetheless, I cannot be sure of that because what was linked in it could depend on your making way.
If you want to use posix apis in hard real time I suggest you to follow what attached and have it made with  something like this:
RENAME = $(shell rtai-config --posix-wrap)
 $(CC) $(LXRT_CFLAGS) -o ...................... $(RENAME) $(LXRT_LDFLAGS) -llxrt

You sent me C++ but I changed it in palin C, as usual. 

Paolo.
_______________________________________
From: Jonas Schulze [[email protected]]
Sent: Tuesday, November 24, 2015 8:34 AM
To: Paolo Mantegazza; [email protected]
Subject: AW: AW: AW: [Rtai] Error "Jumps" in long time tests

Hi,

attached is my code stripped down to its core. I verified the jumps again with some long time runs over the weekend. 10 hours test, starting at 20 microsecs and jumping to 2100 microsecs (see attached PNG).

Best Regards
Jonas

---------------------------
Jonas Schulze, M. Sc.
Technische Universität Darmstadt
Flugsysteme und Regelungstechnik
Otto-Berndt Straße 2
64287 Darmstadt, Germany

Tel.:      +49(0)6151/16-21077
Fax:      +49(0)6151/16-21050
E-Mail: [email protected]<mailto:[email protected]>
URL:     www.fsr.tu-darmstadt.de<http://www.fsr.tu-darmstadt.de/>



Von: Paolo Mantegazza [mailto:[email protected]]
Gesendet: 20 November 2015 15:27
An: Jonas Schulze; [email protected]
Betreff: Re: AW: AW: [Rtai] Error "Jumps" in long time tests

On 11/20/2015 03:08 PM, Jonas Schulze wrote:
No Im actually using rt_start_timer(0), as I read it in an example code my program is based on.

The I've to wait for your code to check your problem hands on.
Paolo

Jonas

---------------------------
Jonas Schulze, M. Sc.
Technische Universität Darmstadt
Flugsysteme und Regelungstechnik
Otto-Berndt Straße 2
64287 Darmstadt, Germany

Tel.:      +49(0)6151/16-21077
Fax:      +49(0)6151/16-21050
E-Mail: [email protected]<mailto:[email protected]>
URL:     www.fsr.tu-darmstadt.de<http://www.fsr.tu-darmstadt.de>



Von: Paolo Mantegazza [mailto:[email protected]]
Gesendet: 20 November 2015 15:06
An: Jonas Schulze; [email protected]<mailto:[email protected]>
Betreff: Re: AW: [Rtai] Error "Jumps" in long time tests

On 11/20/2015 02:24 PM, Jonas Schulze wrote:
Hi Paolo,

the machine has following futures:

                • Gigabyte GA-MA78GPM Motherboard
                • AMD Athlon X-2 Dualcore  4450e
                • 2GB RAM

Im using RTAI 4.1 on a 3.16 kernel.

Not sure about the meaning of “UP-SMP”…

Thanks for your offer to send you the program, but I need to strip it down a bit so you don’t have to deal with my unnecessary messy code. That may take until next week.


Meanwhile I've guessed that in your code there is likely a line similar to this: start_rt_timer(nano2count(25000000)).
Am I right?
Paolo



Best Regard
Jonas

---------------------------
Jonas Schulze, M. Sc.
Technische Universität Darmstadt
Flugsysteme und Regelungstechnik
Otto-Berndt Straße 2
64287 Darmstadt, Germany

Tel.:      +49(0)6151/16-21077
Fax:      +49(0)6151/16-21050
E-Mail: [email protected]<mailto:[email protected]>
URL:     www.fsr.tu-darmstadt.de<http://www.fsr.tu-darmstadt.de>



Von: Paolo Mantegazza [mailto:[email protected]]
Gesendet: 20 November 2015 14:06
An: Jonas Schulze; [email protected]<mailto:[email protected]>
Betreff: Re: [Rtai] Error "Jumps" in long time tests

Machine type and features? UP-SMP? RTAI version? If before RTAI-4.0: hardware timer (start_rt_timer) in oneshot or periodic mode?
If the program is simple and arch neutral, could you send it to me?

Paolo

On 11/20/2015 01:42 PM, Jonas Schulze wrote:
Hi all,

Im currently testing RTAI on several machines to determine which one is best suitable for my purposes. To do so, I have have a simple program that runs two concurrent loops, one in soft real time and one in hard realtime. The realtime task is running in a specific periodic time (0.025 sec currently) and terminates after a user specified end of iterations. In every realtime loop I check the time it was called (using rt_get_time_ns) and compare it to the last time it was called to determine the error that was made with respect to the defined period.

Now I did tests running the program for two hours and ten hours. In both tests there are distinctive times where the error “jumps” to a higher value (from one iteration to the next), it is not increasing constantly. In between the jumps, the error varies only within small values.

To give you an idea here are some rough error values. There was no other load on the system than the test program and Ubuntu running, no internet connection:

Two hour test, system was fresh booted:
+-20 microsec until minute 4 -> Jump
+-40 microsec unitl minute 14 -> Jump
+-60 microsec until minute 31 -> Jump
+-100 microsec until minute 62 -> Jump
+-200 microsec until end

Ten hour test (system was already running for 8 hours)
+1000/-700 microsc until minute 41 -> Jump
+1300/-1800 microsec until minute 5854 (9.7 hours) -> Jump
+3800/-2400 microsec until end

Is there anything that is causing those jumps in the error? Is it maybe some option I didn’t know about when compiling the kernel? Or is this a normal behaviour of RTAI?

Best Regards and thanks for any hints
Jonas





---------------------------
Jonas Schulze, M. Sc.
Technische Universität Darmstadt
Flugsysteme und Regelungstechnik
Otto-Berndt Straße 2
64287 Darmstadt, Germany

Tel.:      +49(0)6151/16-21077
Fax:      +49(0)6151/16-21050
E-Mail: [email protected]<mailto:[email protected]>
URL:     www.fsr.tu-darmstadt.de<http://www.fsr.tu-darmstadt.de>









_______________________________________________

Rtai mailing list

[email protected]<mailto:[email protected]>

https://mail.rtai.org/cgi-bin/mailman/listinfo/rtai

_______________________________________________
Rtai mailing list
[email protected]
https://mail.rtai.org/cgi-bin/mailman/listinfo/rtai
test.c (text/x-csrc, 3.8 KB)
#include <stdio.h>
#include <sys/mman.h>

#include "rtai_lxrt.h"
#include "rtai_msg.h"
#include "rtai_posix.h"

#define NLOOPS 10000

RT_TASK *sender, *receiver;
pthread_mutex_t my_mutex;
pthread_mutex_t my_mutex_2;

RTIME error_array[NLOOPS];

struct RT_MSG_SEND {
        double value1;
        double value2;
        double value3;
        int value4;
        double value5;
        double value6;
    };

struct RT_MSG_RETURN {
        double value1;
        double value2;
        double value3;
        double value4;
    };

struct RT_MSG_SEND   s2h_message;
struct RT_MSG_RETURN h2s_message;

void populate_structs(void)
{
    s2h_message.value1 = 78.8456;
    s2h_message.value2 = 78.4562;
    s2h_message.value3 = 488.4569;
    s2h_message.value4 = 7;
    s2h_message.value5 = 7894.456;
    s2h_message.value6 = 78.752;

    h2s_message.value1 = 25000.786;
    h2s_message.value2 = 78.4524;
    h2s_message.value3 = 250.487;
    h2s_message.value4 = 500.487;
}

int max_period_error;
#define PERIOD ((RTIME)25000000)
void *sender_fun(void *args)
{
    struct RT_MSG_SEND s2h_receive;
    RTIME old_time, new_time, sampling_interval = nano2count(PERIOD);
    int i = 0, period_error;
    int mutex_check = 0;
    int mutex_check_2 = 0;
    int mutex_fail_count = 0;
    int mutex_fail_count_2 = 0;

    sender = rt_thread_init(nam2num("SENDER"), 0, 0, SCHED_FIFO, 0xF);
    rt_make_hard_real_time();
    rt_task_make_periodic(sender, rt_get_time() + sampling_interval, sampling_interval);

    old_time = rt_get_time_ns();
    while (++i < NLOOPS) {

        //Compute period error
        new_time = rt_get_time_ns();
        period_error = PERIOD - (new_time - old_time);
        if (i > 10 && abs(period_error) > abs(max_period_error)) {
	     max_period_error = period_error;
        }
        old_time = new_time;

        mutex_check = pthread_mutex_trylock(&my_mutex);
        if (mutex_check == 0) {
            s2h_receive = s2h_message;
            pthread_mutex_unlock(&my_mutex);
        } else {
            ++mutex_fail_count;
        }
        mutex_check_2 = pthread_mutex_trylock(&my_mutex_2);
        if (mutex_check_2 == 0) {
            h2s_message.value1 = i;
            pthread_mutex_unlock(&my_mutex_2);
        } else {
            ++mutex_fail_count_2;
        }

        rt_task_wait_period();
    }

    rt_make_soft_real_time();
    rt_thread_delete(sender);
    return 0;
}

int main(void)
{
struct RT_MSG_RETURN h2s_receive;
int i = 0, echoed_max_period_error = 0;
int check_mutex = 0;
int check_mutex_2 = 0;
int mutex_fail_count = 0;
int mutex_fail_count_2 = 0;

rt_allow_nonroot_hrt();

pthread_mutex_init(&my_mutex,NULL);
pthread_mutex_init(&my_mutex_2,NULL);

populate_structs();

start_rt_timer(0);

receiver = rt_thread_init(nam2num("RECVR"), 1, 0, SCHED_FIFO, 0xF);
mlockall(MCL_CURRENT | MCL_FUTURE);
rt_thread_create((void *)sender_fun, NULL, 0);

rt_sleep(nano2count(25000000));
while(++i < NLOOPS){

    check_mutex = pthread_mutex_trylock(&my_mutex);
    if (check_mutex == 0) { 
        s2h_message.value4 = i;
        pthread_mutex_unlock(&my_mutex);
    } else {
        ++mutex_fail_count;
    }
    check_mutex_2 = pthread_mutex_trylock(&my_mutex_2);
    if (check_mutex_2 == 0) { 
        h2s_receive = h2s_message;
        pthread_mutex_unlock(&my_mutex_2);
    } else {
        ++mutex_fail_count_2;
    }

    //if not used this LINUX soft real time task will lock the machine, as it must be expected!
    rt_sleep(nano2count(25000000));
//    printf(">>> LOOP COUNT: %d, SIGNED MAX ABS PERIOD ERROR: %d.\n", i, period_error);
    if (abs(max_period_error) > abs(echoed_max_period_error)) {
	echoed_max_period_error = max_period_error;
	printf(">>> LOOP COUNT: %d, SIGNED MAX ABS PERIOD ERROR: %d.\n", i, echoed_max_period_error);
    }
}

pthread_mutex_destroy(&my_mutex);
pthread_mutex_destroy(&my_mutex_2);
rt_thread_delete(receiver);
stop_rt_timer();

return 0;
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.