libc: add clock_settime() system call.
This also adds the sys_settime() kernel call which allows for the adjusting of the clock named realtime in the kernel. The existing sys_stime() function is still needed for a separate job (setting the boottime). The boottime is set in the readclock driver. The sys_settime() interface is meant to be flexible and will support both clock_settime() and adjtime() when adjtime() is implemented later. settimeofday() was adjusted to use the clock_settime() interface. One side note discovered during testing: uptime(1) (part of the last(1)), uses wtmp to determine boottime (not Minix's times(2)). This leads `uptime` to report odd results when you set the time to a time prior to boottime. This isn't a new bug introduced by my changes. It's been there for a while.
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
* loop, there are several other minor entry points:
|
||||
* 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
|
||||
* get_monotonic: get monotonic time since boot in clock ticks
|
||||
* set_timer: set a watchdog timer (+)
|
||||
* reset_timer: reset a watchdog timer (+)
|
||||
@@ -167,6 +168,13 @@ clock_t get_realtime(void)
|
||||
return(realtime);
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* set_realtime *
|
||||
*===========================================================================*/
|
||||
void set_realtime(clock_t newrealtime)
|
||||
{
|
||||
realtime = newrealtime;
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* get_monotonic *
|
||||
|
||||
@@ -16,6 +16,7 @@ struct timer;
|
||||
|
||||
/* clock.c */
|
||||
clock_t get_realtime(void);
|
||||
void set_realtime(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);
|
||||
|
||||
@@ -235,6 +235,7 @@ void system_init(void)
|
||||
map(SYS_TIMES, do_times); /* get uptime and process times */
|
||||
map(SYS_SETALARM, do_setalarm); /* schedule a synchronous alarm */
|
||||
map(SYS_STIME, do_stime); /* set the boottime */
|
||||
map(SYS_SETTIME, do_settime); /* set the system time (realtime) */
|
||||
map(SYS_VTIMER, do_vtimer); /* set or retrieve a virtual timer */
|
||||
|
||||
/* System control. */
|
||||
|
||||
@@ -164,6 +164,7 @@ int do_setalarm(struct proc * caller, message *m_ptr);
|
||||
#endif
|
||||
|
||||
int do_stime(struct proc * caller, message *m_ptr);
|
||||
int do_settime(struct proc * caller, message *m_ptr);
|
||||
|
||||
int do_vtimer(struct proc * caller, message *m_ptr);
|
||||
#if ! USE_VTIMER
|
||||
|
||||
@@ -13,6 +13,7 @@ SRCS+= \
|
||||
do_times.c \
|
||||
do_setalarm.c \
|
||||
do_stime.c \
|
||||
do_settime.c \
|
||||
do_vtimer.c \
|
||||
do_irqctl.c \
|
||||
do_copy.c \
|
||||
|
||||
43
kernel/system/do_settime.c
Normal file
43
kernel/system/do_settime.c
Normal file
@@ -0,0 +1,43 @@
|
||||
/* The kernel call implemented in this file:
|
||||
* m_type: SYS_SETTIME
|
||||
*
|
||||
* The parameters for this kernel call are:
|
||||
* m4_l2: T_SETTIME_NOW
|
||||
* m4_l3: T_CLOCK_ID
|
||||
* m4_l4: T_TIME_SEC
|
||||
* m4_l5: T_TIME_NSEC
|
||||
*/
|
||||
|
||||
#include "kernel/system.h"
|
||||
#include <minix/endpoint.h>
|
||||
#include <time.h>
|
||||
|
||||
/*===========================================================================*
|
||||
* do_settime *
|
||||
*===========================================================================*/
|
||||
int do_settime(struct proc * caller, message * m_ptr)
|
||||
{
|
||||
clock_t newclock;
|
||||
time_t timediff;
|
||||
|
||||
if (m_ptr->T_CLOCK_ID != CLOCK_REALTIME) /* only realtime can change */
|
||||
return EINVAL;
|
||||
|
||||
/* prevent a negative value for realtime */
|
||||
if (m_ptr->T_TIME_SEC <= boottime) {
|
||||
/* boottime was likely wrong, try to correct it. */
|
||||
boottime = m_ptr->T_TIME_SEC;
|
||||
set_realtime(1);
|
||||
return(OK);
|
||||
}
|
||||
|
||||
/* calculate the new value of realtime in ticks */
|
||||
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) */
|
||||
|
||||
return(OK);
|
||||
}
|
||||
Reference in New Issue
Block a user