libc: add adjtime() system call.
Implement the adjtime() system call and add a test for it to test69. Additionally, install the adjtime.2 and clock_*.2 man pages.
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
* clock_stop: called just before MINIX shutdown
|
||||
* get_realtime: get wall time since boot in clock ticks
|
||||
* set_realtime: set wall time since boot in clock ticks
|
||||
* set_adjtime_delta: set the number of ticks to adjust realtime
|
||||
* get_monotonic: get monotonic time since boot in clock ticks
|
||||
* set_timer: set a watchdog timer (+)
|
||||
* reset_timer: reset a watchdog timer (+)
|
||||
@@ -63,6 +64,11 @@ static clock_t monotonic = 0;
|
||||
*/
|
||||
static clock_t realtime = 0;
|
||||
|
||||
/* Number of ticks to adjust realtime by. A negative value implies slowing
|
||||
* down realtime, a positive value implies speeding it up.
|
||||
*/
|
||||
static clock_t adjtime_delta = 0;
|
||||
|
||||
/*
|
||||
* The boot processor's timer interrupt handler. In addition to non-boot cpus
|
||||
* it keeps real time and notifies the clock task if need be.
|
||||
@@ -90,7 +96,17 @@ int timer_int_handler(void)
|
||||
|
||||
if (cpu_is_bsp(cpuid)) {
|
||||
monotonic++;
|
||||
realtime++;
|
||||
|
||||
/* if adjtime_delta has ticks remaining, apply one to realtime.
|
||||
* limit changes to every other interrupt.
|
||||
*/
|
||||
if (adjtime_delta != 0 && monotonic & 0x1) {
|
||||
/* go forward or stay behind */
|
||||
realtime += (adjtime_delta > 0) ? 2 : 0;
|
||||
adjtime_delta += (adjtime_delta > 0) ? -1 : +1;
|
||||
} else {
|
||||
realtime++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Update user and system accounting times. Charge the current process
|
||||
@@ -176,6 +192,14 @@ void set_realtime(clock_t newrealtime)
|
||||
realtime = newrealtime;
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* set_adjtime_delta *
|
||||
*===========================================================================*/
|
||||
void set_adjtime_delta(clock_t ticks)
|
||||
{
|
||||
adjtime_delta = ticks;
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* get_monotonic *
|
||||
*===========================================================================*/
|
||||
|
||||
@@ -17,6 +17,7 @@ struct timer;
|
||||
/* clock.c */
|
||||
clock_t get_realtime(void);
|
||||
void set_realtime(clock_t);
|
||||
void set_adjtime_delta(clock_t);
|
||||
clock_t get_monotonic(void);
|
||||
void set_timer(struct timer *tp, clock_t t, tmr_func_t f);
|
||||
void reset_timer(struct timer *tp);
|
||||
|
||||
@@ -17,12 +17,20 @@
|
||||
*===========================================================================*/
|
||||
int do_settime(struct proc * caller, message * m_ptr)
|
||||
{
|
||||
clock_t newclock;
|
||||
clock_t newclock, ticks;
|
||||
time_t timediff;
|
||||
|
||||
if (m_ptr->T_CLOCK_ID != CLOCK_REALTIME) /* only realtime can change */
|
||||
return EINVAL;
|
||||
|
||||
if (m_ptr->T_SETTIME_NOW == 0) { /* user just wants to adjtime() */
|
||||
/* convert delta value from seconds and nseconds to ticks */
|
||||
ticks = (m_ptr->T_TIME_SEC * system_hz) +
|
||||
(m_ptr->T_TIME_NSEC/(1000000000/system_hz));
|
||||
set_adjtime_delta(ticks);
|
||||
return(OK);
|
||||
} /* else user wants to set the time */
|
||||
|
||||
/* prevent a negative value for realtime */
|
||||
if (m_ptr->T_TIME_SEC <= boottime) {
|
||||
/* boottime was likely wrong, try to correct it. */
|
||||
@@ -35,9 +43,7 @@ int do_settime(struct proc * caller, message * m_ptr)
|
||||
timediff = m_ptr->T_TIME_SEC - boottime;
|
||||
newclock = (timediff*system_hz) + (m_ptr->T_TIME_NSEC/(1000000000/system_hz));
|
||||
|
||||
if (m_ptr->T_SETTIME_NOW) {
|
||||
set_realtime(newclock);
|
||||
} /* else used adjtime() method (to be implemented) */
|
||||
set_realtime(newclock);
|
||||
|
||||
return(OK);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user