clock_realtime.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
static clock_backend_t clock_realtime;
static int
{
return (0);
}
/*
* We normally won't execute this path; libc will see CLOCK_REALTIME and
* fast trap directly into gethrestime().
*/
static int
{
return (0);
}
static int
{
return (0);
}
static void
clock_realtime_fire(void *arg)
{
int cnt2nth;
/*
* First call into the timer subsystem to get the signal going.
*/
timer_fire(it);
mutex_enter(&p->p_lock);
if (!timerspecisset(interval)) {
*tidp = 0;
} else {
/*
* If this is an interval timer, we need to determine a time
* at which to go off in the future. In the event that the
* clock has been adjusted, we want to find our new interval
* relatively quickly (and we don't want to simply take the
* current time and add the interval; it would lead to
* unnecessary jitter in the timer). We therefore take steps
* from the time we expected to go off into the future;
* if the resulting time is still in the past, then we double
* our step size and continue. Once the resulting time is
* in the future, we subtract our last step, change our step
* size back to the original interval, and repeat until we
* can get to a valid, future timeout in one step. This
* assures that we will get the minimum, valid timeout
* value in a reasonable amount of wall time.
*/
for (;;) {
interval2nth = *interval;
/*
* We put a floor on interval2nth at nsec_per_tick.
* If we don't do this, and the interval is shorter
* than the time required to run through this logic,
* we'll never catch up to the current time (which
* is a moving target).
*/
if (interval2nth.tv_sec == 0 &&
gethrestime(&now);
break;
}
if (cnt2nth == 0)
break;
}
}
mutex_exit(&p->p_lock);
}
/*
* See the block comment in clock_realtime_timer_settime(), below.
*/
static void
clock_realtime_fire_first(void *arg)
{
gethrestime(&now);
/*
* We went off too early. We'll go to bed for one more tick,
* regardless of the actual difference; if the difference
* is greater than one tick, then we must have seen an adjtime.
*/
mutex_enter(&p->p_lock);
mutex_exit(&p->p_lock);
return;
}
}
/*ARGSUSED*/
static int
{
return (0);
}
static int
const struct itimerspec *when)
{
gethrestime(&now);
mutex_enter(&p->p_lock);
*tidp = 0;
mutex_exit(&p->p_lock);
mutex_enter(&p->p_lock);
}
/*
* The timeout has been removed; it is safe to update it_itime.
*/
if (!(flags & TIMER_ABSTIME))
/*
* gethrestime() works by reading hres_last_tick, and
* adding in the current time delta (that is, the amount of
* time which has passed since the last tick of the clock).
* As a result, the time returned in "now", above, represents
* an hrestime sometime after lbolt was last bumped.
* The "ticks" we've been returned from timespectohz(), then,
* reflects the number of times the clock will tick between
* "now" and our desired execution time.
*
* However, when we call into realtime_timeout(), below,
* "ticks" will be interpreted against lbolt. That is,
* if we specify 1 tick, we will be registering a callout
* for the next tick of the clock -- which may occur in
* less than (1 / hz) seconds. More generally, we are
* registering a callout for "ticks" of the clock, which
* may be less than ("ticks" / hz) seconds (but not more than
* (1 / hz) seconds less). In other words, we may go off
* early.
*
* This is only a problem for the initial firing of the
* timer, so we have the initial firing go through a
* different handler which implements a nanosleep-esque
* algorithm.
*/
}
mutex_exit(&p->p_lock);
return (0);
}
static int
{
/*
* We always keep it_itime up to date, so we just need to snapshot
* the time under p_lock, and clean it up.
*/
mutex_enter(&p->p_lock);
gethrestime(&now);
mutex_exit(&p->p_lock);
return (0);
/*
* If this timer should have already gone off, set it_value
* to 0.
*/
} else {
}
return (0);
}
static int
{
mutex_enter(&p->p_lock);
*tidp = 0;
mutex_exit(&p->p_lock);
mutex_enter(&p->p_lock);
}
mutex_exit(&p->p_lock);
return (0);
}
/*ARGSUSED*/
void
{
}
void
{
/*
* For binary compatibility with old statically linked
* applications, we make the behavior of __CLOCK_REALTIME0
* the same as CLOCK_REALTIME.
*/
}