All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-help] Problem with gettimeofday
@ 2009-12-10  9:36 Soboljew, Patrick
  2009-12-10 10:41 ` Gilles Chanteperdrix
  0 siblings, 1 reply; 4+ messages in thread
From: Soboljew, Patrick @ 2009-12-10  9:36 UTC (permalink / raw)
  To: xenomai


Hello all,

I have a problem concering the system time in xenomai 2.4.9.1 kernel
2.6.30. The framework I use calls gettimeofday() to get the absolute
system time which is then passed to pthread_cond_timedwait. The problem
is that when I add for example 1ms wait time the pthread_cond_timedwait
waits much longer. I've checked /proc/xenomai/sched and I can see that
the timeout is far too large. So I wrote a small test program to isolate
the problem. I compared the results (only the seconds which is enough to
show the problem) and there is a huge difference.

On my system (Intel Core2, 1,6 GHz) the output of the test program shows
the following output:
Time1: 1260437136
Time2: 1145908535

The curious thing is: I have a vmware image with a xenomai kernel (same
version). The problem cannot be reproduced here. 

Anybody an idea?

Thanks for your help,
Patrick Soboljew



============= Example Code begin ==============
#include <pthread.h>
#include <sys/mman.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>

void SetupRtThread()
{
    int RetVal = 0;
    struct sched_param SParam;
    SParam.sched_priority = 1;
    int Policy = SCHED_FIFO;
    if ((RetVal = pthread_setschedparam(pthread_self(), Policy,
&SParam)) != 0)
    {
        printf("pthread_setschedparam: %s", strerror(RetVal));
        exit(RetVal);
    }
}


int main (int /*argc*/, char** /*argv[]*/)
{
    mlockall(MCL_CURRENT | MCL_FUTURE);
    SetupRtThread();

    printf("1\n");

    timeval Time1;
    if (gettimeofday(&Time1,0) != 0)
    {
        fprintf(stderr, "Error gettimeofday\n");
        return -1;
    }

    timespec Time2;
    if (clock_gettime(CLOCK_REALTIME, &Time2) != 0)
    {
        fprintf(stderr, "Error clock_gettime");
        return -1;
    }
    printf("Time1: %ld\n", Time1.tv_sec);
    printf("Time2: %ld\n", Time2.tv_sec);

    return 0;
}
============= Example Code end ==============


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

end of thread, other threads:[~2009-12-10 13:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-10  9:36 [Xenomai-help] Problem with gettimeofday Soboljew, Patrick
2009-12-10 10:41 ` Gilles Chanteperdrix
2009-12-10 12:34   ` Soboljew, Patrick
2009-12-10 13:35     ` Gilles Chanteperdrix

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.