POSIX timers doesn'r work when I change my system clock backward

POSIX timers doesn'r work when I change my system clock backward

Post by ssk_marri.. » Tue, 20 Dec 2005 00:37:55



I'm using POSIX timers in our application.We generate interrupts at the
freq of 200 milli seconds. Everything works fine as for as the system
time is same. When I change the system time 30 min forward the
interrupts generated by the timer doesn't get disturbed. But when the
system time moved backward by 30 min from the current time, the
interrupts doesn't get triggered till the 30 min gets elapsed from the
current time.

We use SUN solaris 8. Any information or suggestion on this topic is
highly apprciated.
We use the clock as CLOCK_REALTIME and generate SIGUSR1 signal to
handle the interrupts.

Thanks in advance.

Shiva

 
 
 

POSIX timers doesn'r work when I change my system clock backward

Post by ba.. » Tue, 20 Dec 2005 08:12:09



> I'm using POSIX timers in our application.We generate interrupts at the
> freq of 200 milli seconds. Everything works fine as for as the system
> time is same. When I change the system time 30 min forward the
> interrupts generated by the timer doesn't get disturbed. But when the
> system time moved backward by 30 min from the current time, the
> interrupts doesn't get triggered till the 30 min gets elapsed from the
> current time.

> We use SUN solaris 8. Any information or suggestion on this topic is
> highly apprciated.
> We use the clock as CLOCK_REALTIME and generate SIGUSR1 signal to
> handle the interrupts.

This is why time travel isn't recommended.  Seriously, the behavior you
want (keep interrupting regardless of time change) is exactly what
someone
else doesn't want (interrupt only N times in 24 hours, for example).

If you want rational time behavior, don't set the time; use adjtime or
NTP
which gradually adjusts the time of day.

- Bart

 
 
 

POSIX timers doesn'r work when I change my system clock backward

Post by ssk_marri.. » Tue, 20 Dec 2005 23:09:41


Is there anyway to take care in the POSIX timers? Everything works fine
with current time and the time move forwarded. The ticks doen't get
generated when we change the time to backwards.

Is this a known bug in POSIX timers? Do I need to take care something
with flags.

-Shiva

 
 
 

POSIX timers doesn'r work when I change my system clock backward

Post by Brian Utterbac » Wed, 21 Dec 2005 02:49:47



> Is there anyway to take care in the POSIX timers? Everything works fine
> with current time and the time move forwarded. The ticks doen't get
> generated when we change the time to backwards.

> Is this a known bug in POSIX timers? Do I need to take care something
> with flags.

> -Shiva

It is unfortunate that the timers in Solaris are such no matter what
behavior you are looking for from them, in the wake of a system clock
time step, you are going to be disappointed. There are two kinds of
behavior that the setitimer call is designed to deliver. The first is
to deliver an interrupt each time a certain interval passes. The
second is to deliver an interval at a certain time, say every minute,
on the minute.

In the first case, you probably do not want the timer to even notice
system clock changes. If you asked for "once each second", the
invariant you most likely want is that this current interrupt comes
one second after the last and one second before the next.

On the other hand, if you want "each minute, on the minute", you do
want the interrupt to be adjusted by the system clock.

However, in Solaris you get both and neither. If the clock is stepped
ahead by, say, one hour, the next interrupt will arrive at a time
that would have been the correct time before the clock stepped,
but the next interrupt will arrive at the correct time based on
the new system time.

So, suppose you wanted once each minute without regard to the
system clock, or once each minute, on the minute. Now suppose
that the clock is set backwards 5 minutes at 12:03:30. This is
when the interrupts would be delivered:

Wallclock       Interval between this
                 and the previous interrupt.
11:59           60
12:00           60
12:01           60
12:02           60
12:03           60
   ( 12:03:30, clock set back 5 minutes to 11:58:30 )
11:59           60
12:05           300

So, if you wanted timer to fire each minute, you just got
300 seconds of no firing. If you wanted the timer to fire
each minute, on the minute, you just got number 11:59 twice.

What is really needed is for Solaris to split these two
types out and do the "right" thing for each of them.

I actually got involved with this problem because NTP
has the same problem! It uses setitimer to set up the
polling intervals, and it would stop polling when the
clock stepped backwards. However, we were able to solve
the problem for NTP, because, unlike other applications,
it knew when the clock stepped backwards, since it is
doing the stepping. We just stepped the clock and then
re-established the timer.
--
blu

"Having them stolen may become our distribution model..."
Nicolas Negroponte on the Hundred Dollar Laptop.
----------------------------------------------------------------------
Brian Utterback - OP/N1 RPE, Sun Microsystems, Inc.
Ph:877-259-7345, Em:brian.utterback-at-ess-you-enn-dot-kom

 
 
 

POSIX timers doesn'r work when I change my system clock backward

Post by ssk_marri.. » Wed, 21 Dec 2005 21:36:58


Blu,

Thanks for your reply.
The timer which I created running is running in an user space area. In
NTP we can detect easily the time is either moved forward/backward,
because you are the one going to set the system clock. In user space
area, how do we identify the system time has changed to either +/- min
to the current time. Is there any callback functions available to
register with OS, so that this shall notify when there is any change.Or
I need to spawn a thread to monitor the time change.

Pl provide some info or the best way to detect the system time change

Thanks in advance
Shiva

 
 
 

POSIX timers doesn'r work when I change my system clock backward

Post by Brian Utterbac » Fri, 23 Dec 2005 03:13:12



> Blu,

> Thanks for your reply.
> The timer which I created running is running in an user space area. In
> NTP we can detect easily the time is either moved forward/backward,
> because you are the one going to set the system clock. In user space
> area, how do we identify the system time has changed to either +/- min
> to the current time. Is there any callback functions available to
> register with OS, so that this shall notify when there is any change.Or
> I need to spawn a thread to monitor the time change.

> Pl provide some info or the best way to detect the system time change

> Thanks in advance
> Shiva

Alas, I know of no way to do this. There is no way to be notified
when the clock changes. The only way I can think of to do this is
to double check the expected system with the actual system time
each and every time the timers fires.

--
blu

"Having them stolen may become our distribution model..."
Nicolas Negroponte on the Hundred Dollar Laptop.
----------------------------------------------------------------------
Brian Utterback - OP/N1 RPE, Sun Microsystems, Inc.
Ph:877-259-7345, Em:brian.utterback-at-ess-you-enn-dot-kom

 
 
 

POSIX timers doesn'r work when I change my system clock backward

Post by Stefaan A Eeckel » Fri, 30 Dec 2005 08:32:48


On 19 Dec 2005 06:09:41 -0800


> Is there anyway to take care in the POSIX timers? Everything works
> fine with current time and the time move forwarded. The ticks doen't
> get generated when we change the time to backwards.

The real question is: why are you changing the system time?

--
Stefaan
--
As complexity rises, precise statements lose meaning,
and meaningful statements lose precision. -- Lotfi Zadeh