Re: catching abrupt time changes

2001-05-17 Thread John Polstra

In article <[EMAIL PROTECTED]>,
Brad Huntting  <[EMAIL PROTECTED]> wrote:
> 
> Suppose I'm a (root) process:  I have an appointment in exactly
> one hour.  I call select() and specify a timeout of 3600 seconds,
> trusting that the system will wake me up just in time.  But
> unbeknownst to me someone sets the clock back 10 minutes while I'm
> asleep (using settimeofday(), not adjtime()).  When select() returns
> I find that I'm 10 minutes late!
> 
> My question is:
> 
>   How can I arrange to be notified when someone and makes a
>   corse change to the system clock?

This may be more work than you want to do, but ...

You could add a new kqueue event which is generated when the system
time is stepped.  Then you could do your sleeping with kevent().

John
-- 
  John Polstra   [EMAIL PROTECTED]
  John D. Polstra & Co., Inc.Seattle, Washington USA
  "Disappointment is a good sign of basic intelligence."  -- Chögyam Trungpa


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message



Re: catching abrupt time changes

2001-05-17 Thread Brad Huntting


> The usual platform-independent way to do this is to have a thread
> that monitors the system clock. It wakes up every, say, 2 seconds
> and makes sure the clock is where it expects it. If the clock isn't
> what it expects, it does whatever you need to do in that case.

> I fear, however, that this is yet another technique that won't work
> properly with user-space threading. I fear that the clock thread's
> sleep function will be virtualize into something that won't sleep
> for the right amount of time if the system clock is changed. Does
> anyone know which sleep function to use to avoid this - or if there
> is one?

Unfortunately, this is exactly what I'm trying fix.  I want cron to
_stop_ waking up every 60 seconds.  If cron has nothing to do for
5 days, it should sleep for 5 days.  And if everything on the system
is sleeping for 5 days and the kernel knows this, then mabey we
can hibernate the system for 5 days.

I know theres allot more to this than just cron (network stuff etc).


brad

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message



catching abrupt time changes

2001-05-17 Thread Brad Huntting


Suppose I'm a (root) process:  I have an appointment in exactly
one hour.  I call select() and specify a timeout of 3600 seconds,
trusting that the system will wake me up just in time.  But
unbeknownst to me someone sets the clock back 10 minutes while I'm
asleep (using settimeofday(), not adjtime()).  When select() returns
I find that I'm 10 minutes late!

My question is:

How can I arrange to be notified when someone and makes a
corse change to the system clock?

One idea I had was to generate a klog message for each call to
settimeofday().  This would put the information in syslog, and I
could simply add /dev/klog to the list of file descriptors in it's
select() call (there will be lots of false alarms, but that's
probably not a problem for this application).

Another idea was to add a new minor device to klog that just logs
calls to settimeofday().  Could this be generalized?

Alternately such a device file could be put in /proc (smells like
a Linux solution).

Or perhaps I could select() for "read" or "err" conditions on
/kern/time (from kernfs).

Any thoughts?


brad


P.S.  The application in question is a new schedular for cron/at
that can sleep between jobs.  This would seem to be a good first
step toward better laptop power management.


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message