Main Page | Report this Page
Linux Forum Index  »  Linux Development - Applications  »  clock_gettime CLOCK_MONOTONIC replacing...
Page 1 of 1    

clock_gettime CLOCK_MONOTONIC replacing...

Author Message
Simone F....
Posted: Thu Sep 03, 2009 6:30 am
Guest
hi all,
I need to replace calls to clock_gettime( CLOCK_MONOTONIC, ... ) because
on my old installation the CLOCK_MONOTONIC macro is not defined. Is
there a way to achieve something comparable?

Thank you in advance
 
Loïc Domaigné...
Posted: Thu Sep 03, 2009 6:30 am
Guest
Hallo,

Quote:
I need to replace calls to clock_gettime( CLOCK_MONOTONIC, ... )
because on my old installation the CLOCK_MONOTONIC macro is not
defined. Is there a way to achieve something comparable?

If you have kernel support for clock_gettime, you could work around
missing glibc support by doing the syscalls directly, see syscall(2)/
_syscall(2). Otherwise, you will have to use gettimeofday.

If you don't have any kernel support, it will be difficult to get
monotonic clock... Especially gettimeofday() & co. are subject to time
change (e.g. NTP etc).

Cheers,
Loïc
--
My Blog: http://www.domaigne.com/blog

"Hardware: The parts of a computer system that can be kicked." --
Jeff Pesis
 
Rainer Weikusat...
Posted: Thu Sep 03, 2009 7:39 am
Guest
"Simone F." <psycho_78 at (no spam) libero.it> writes:
Quote:
I need to replace calls to clock_gettime( CLOCK_MONOTONIC, ... )
because on my old installation the CLOCK_MONOTONIC macro is not
defined. Is there a way to achieve something comparable?

If you have kernel support for clock_gettime, you could work around
missing glibc support by doing the syscalls directly, see syscall(2)/
_syscall(2). Otherwise, you will have to use gettimeofday.
 
David Schwartz...
Posted: Mon Sep 07, 2009 9:11 pm
Guest
On Sep 3, 5:30 am, "Simone F." <psycho... at (no spam) libero.it> wrote:
Quote:
hi all,
I need to replace calls to clock_gettime( CLOCK_MONOTONIC, ... ) because
on my old installation the CLOCK_MONOTONIC macro is not defined. Is
there a way to achieve something comparable?

Thank you in advance

It depends on exactly what your requirements are. Your system's
equivalent of 'uptime' may be the best solution.

DS
 
Simone F....
Posted: Tue Sep 08, 2009 4:36 am
Guest
David Schwartz ha scritto:
Quote:
On Sep 3, 5:30 am, "Simone F." <psycho... at (no spam) libero.it> wrote:
hi all,
I need to replace calls to clock_gettime( CLOCK_MONOTONIC, ... ) because
on my old installation the CLOCK_MONOTONIC macro is not defined. Is
there a way to achieve something comparable?

Thank you in advance

It depends on exactly what your requirements are. Your system's
equivalent of 'uptime' may be the best solution.

DS

I need a wall-time clock that 1) it's not dependant upon the system's
datetime for a server application -for calculating timeouts- and 2) has
at least 10 ms precision.
 
Rainer Weikusat...
Posted: Tue Sep 08, 2009 4:55 am
Guest
"Simone F." <psycho_78 at (no spam) libero.it> writes:
Quote:
David Schwartz ha scritto:
On Sep 3, 5:30 am, "Simone F." <psycho... at (no spam) libero.it> wrote:
hi all,
I need to replace calls to clock_gettime( CLOCK_MONOTONIC, ... ) because
on my old installation the CLOCK_MONOTONIC macro is not defined. Is
there a way to achieve something comparable?

Thank you in advance

It depends on exactly what your requirements are. Your system's
equivalent of 'uptime' may be the best solution.

[...]

Quote:
I need a wall-time clock that 1) it's not dependant upon the system's
datetime for a server application -for calculating timeouts- and 2)
has at least 10 ms precision.

As I already wrote: You or the person administering the system you are
using needs to get a clue about the intended purpose of clocks,
namely, to measure time intervals and not to provide pseudo-random
numbers.
 
Simone F....
Posted: Tue Sep 08, 2009 6:17 am
Guest
Rainer Weikusat ha scritto:

Quote:
As I already wrote: You or the person administering the system you are
using needs to get a clue about the intended purpose of clocks,
namely, to measure time intervals and not to provide pseudo-random
numbers.


Yes, I read your other message. The fact is that I have to ensure that
the application works correctly even if the person administering the
system does something wrong to the machine's datetime.
 
David Schwartz...
Posted: Tue Sep 08, 2009 11:12 am
Guest
On Sep 8, 3:36 am, "Simone F." <psycho... at (no spam) libero.it> wrote:

Quote:
I need a wall-time clock that 1) it's not dependant upon the system's
datetime for a server application -for calculating timeouts- and 2) has
at least 10 ms precision.

Using a wall time clock for calculating timeouts is idiotic. Why would
you want to do that? You should be using an elapsed time clock (from
an arbitrary starting point) to do that.

Your requirements seem to be internally conflicting. For example, what
should happen if the system's best guess of actual wall time does in
fact go back ten seconds?

DS
 
David Schwartz...
Posted: Tue Sep 08, 2009 11:13 am
Guest
On Sep 8, 5:17 am, "Simone F." <psycho... at (no spam) libero.it> wrote:

Quote:
Yes, I read your other message. The fact is that I have to ensure that
the application works correctly even if the person administering the
system does something wrong to the machine's datetime.

What are the requirements for the application to work correctly? You
may need to construct your own clock to your specific requirements.

DS
 
David Schwartz...
Posted: Tue Sep 08, 2009 2:19 pm
Guest
On Sep 8, 2:24 pm, Rainer Weikusat <rweiku... at (no spam) mssgmbh.com> wrote:

Quote:
Your requirements seem to be internally conflicting. For example, what
should happen if the system's best guess of actual wall time does in
fact go back ten seconds?

That's extraordinary simple: I go to the superior of the person who
configured this, say something like 'sorry, but I need the walltime
clock to work' and this is going to solve the problem. Actually, going
to the person itself used to be sufficient up to now. After all, the
internet isn't exactly a new phenomenon.

"The car blew up because it ran out of gas."

"Simple fix, when the car is low on gas, fill the tank up. Don't let
it go empty."

Nope, sorry. Cars shouldn't blow up because they run out of gas, even
though it's possible to never run a car out of gas.

DS
 
Rainer Weikusat...
Posted: Tue Sep 08, 2009 3:24 pm
Guest
David Schwartz <davids at (no spam) webmaster.com> writes:
Quote:
On Sep 8, 3:36 am, "Simone F." <psycho... at (no spam) libero.it> wrote:
I need a wall-time clock that 1) it's not dependant upon the system's
datetime for a server application -for calculating timeouts- and 2) has
at least 10 ms precision.

Using a wall time clock for calculating timeouts is idiotic.

Using your PRNG as clock would be idiotic. But that hasn't stopped
billions of people from successfully using their watches in order to
coordinate independent actions based on a common reference
time and the fact that 'a minute from now' will be 'a minute from now'
(within the accuracy limits of the oscillator) and not 'two minutes
in the past because the clock was off'.

[...]

Quote:
Your requirements seem to be internally conflicting. For example, what
should happen if the system's best guess of actual wall time does in
fact go back ten seconds?

That's extraordinary simple: I go to the superior of the person who
configured this, say something like 'sorry, but I need the walltime
clock to work' and this is going to solve the problem. Actually, going
to the person itself used to be sufficient up to now. After all, the
internet isn't exactly a new phenomenon.
 
Simone F....
Posted: Wed Sep 09, 2009 12:26 am
Guest
David Schwartz ha scritto:
Quote:
On Sep 8, 3:36 am, "Simone F." <psycho... at (no spam) libero.it> wrote:

I need a wall-time clock that 1) it's not dependant upon the system's
datetime for a server application -for calculating timeouts- and 2) has
at least 10 ms precision.

Using a wall time clock for calculating timeouts is idiotic. Why would
you want to do that? You should be using an elapsed time clock (from
an arbitrary starting point) to do that.


Yes, my fault: english is not my mother language and I may not be
expressing correctly what are my requirements, sorry again.

Let's see if I can made myself clear with some source code. Actually, I
have a callback that's invoked "many times" per second, but I don't know
how much times. That's what I would like to do inside it:

void Object::callback() {
timespec now_ts;
clock_gettime( CLOCK_MONOTONIC, &now_ts );
if( now_ts - this->_last_stored_ts > TIMEOUT ) {
this->timeoutElapsed();
swap( now_ts, this->_last_stored_ts );
}
}

so, if the system datetime is changed, the timeout is still correctly
evaluated.

Now, the problem is that my target system doesn't support
CLOCK_MONOTONIC macro and clock(3) returns the processor time used by
the program.

Rainer is correct when he says that if NTP is working correctly, I could
-i.e.- change CLOCK_MONOTONIC with CLOCK_REALTIME, but -as for
requirements- I can't assume that NTP is working/configured correctly.
And no, I'm not writing the requirements :-)

Quote:
Your requirements seem to be internally conflicting. For example, what
should happen if the system's best guess of actual wall time does in
fact go back ten seconds?


Hope that the previous example clarifies this.
 
 
Page 1 of 1    
All times are GMT - 5 Hours
The time now is Fri Dec 04, 2009 12:33 am