* [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
* Re: [Xenomai-help] Problem with gettimeofday
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
0 siblings, 1 reply; 4+ messages in thread
From: Gilles Chanteperdrix @ 2009-12-10 10:41 UTC (permalink / raw)
To: Soboljew, Patrick; +Cc: xenomai
Soboljew, Patrick wrote:
> 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?
You should be using clock_gettime(CLOCK_REALTIME). In case you insist on
using gettimeofday, see:
http://www.xenomai.org/index.php/Porting_POSIX_applications_to_Xenomai#Timing_services.
--
Gilles
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Xenomai-help] Problem with gettimeofday
2009-12-10 10:41 ` Gilles Chanteperdrix
@ 2009-12-10 12:34 ` Soboljew, Patrick
2009-12-10 13:35 ` Gilles Chanteperdrix
0 siblings, 1 reply; 4+ messages in thread
From: Soboljew, Patrick @ 2009-12-10 12:34 UTC (permalink / raw)
To: Gilles Chanteperdrix; +Cc: xenomai
> -----Ursprüngliche Nachricht-----
> Von: Gilles Chanteperdrix [mailto:gilles.chanteperdrix@xenomai.org
> Gesendet: Donnerstag, 10. Dezember 2009 11:42
> An: Soboljew, Patrick
> Cc: xenomai@xenomai.org
> Betreff: Re: [Xenomai-help] Problem with gettimeofday
>
> Soboljew, Patrick wrote:
> > 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?
>
> You should be using clock_gettime(CLOCK_REALTIME). In case
> you insist on using gettimeofday, see:
>
> http://www.xenomai.org/index.php/Porting_POSIX_applications_to
> _Xenomai#Timing_services.
It's not me who insists on that call but this framework :). But thanks for your help. The solution thats provided with the link would help I think. I was also interested what things can cause the difference between both functions on real hardware and in the vmware image e.g. kernel config parameters.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Xenomai-help] Problem with gettimeofday
2009-12-10 12:34 ` Soboljew, Patrick
@ 2009-12-10 13:35 ` Gilles Chanteperdrix
0 siblings, 0 replies; 4+ messages in thread
From: Gilles Chanteperdrix @ 2009-12-10 13:35 UTC (permalink / raw)
To: Soboljew, Patrick; +Cc: xenomai
Soboljew, Patrick wrote:
>>> Anybody an idea?
>> You should be using clock_gettime(CLOCK_REALTIME). In case you
>> insist on using gettimeofday, see:
>>
>> http://www.xenomai.org/index.php/Porting_POSIX_applications_to_Xenomai#Timing_services.
>
> It's not me who insists on that call but this framework :). But
> thanks for your help. The solution thats provided with the link would
> help I think. I was also interested what things can cause the
> difference between both functions on real hardware and in the vmware
> image e.g. kernel config parameters.
Xenomai keeps synchronized with Linux, if Linux uses the same
clocksource as xenomai i.e. the tsc, if it does not update the wallclock
time after the boot, and if it does not use NTP.
--
Gilles
^ 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.