--- Gnu-Mach/kern/mach_clock.c 2020/09/02 04:36:57 1.1.1.1 +++ Gnu-Mach/kern/mach_clock.c 2020/09/02 04:47:38 1.1.1.5 @@ -27,15 +27,14 @@ * the rights to redistribute these changes. */ /* - * File: clock_prim.c + * File: mach_clock.c * Author: Avadis Tevanian, Jr. * Date: 1986 * * Clock primitives. */ -#include -#include -#include + +#include #include #include @@ -44,27 +43,28 @@ #include #include #include "cpu_number.h" +#include #include #include -#include +#include #include +#include #include #include #include -#include #include +#include +#include #include #include #include /* HZ */ #include +#include #if MACH_PCSAMPLE #include #endif - -void softclock(); /* forward */ - int hz = HZ; /* number of ticks per second */ int tick = (1000000 / HZ); /* number of usec per tick */ time_value_t time = { 0, 0 }; /* time since bootup (uncorrected) */ @@ -89,7 +89,7 @@ int bigadj = 1000000; /* adjust 10*tick * } while (secs != mtime->check_seconds); * to read the time correctly. (On a multiprocessor this assumes * that processors see each other's writes in the correct order. - * We may have to insert fence operations.) + * We have to insert write fence operations.) FIXME */ mapped_time_value_t *mtime = 0; @@ -98,7 +98,9 @@ mapped_time_value_t *mtime = 0; MACRO_BEGIN \ if (mtime != 0) { \ mtime->check_seconds = (time)->seconds; \ + asm volatile("":::"memory"); \ mtime->microseconds = (time)->microseconds; \ + asm volatile("":::"memory"); \ mtime->seconds = (time)->seconds; \ } \ MACRO_END @@ -118,13 +120,13 @@ timer_elt_data_t timer_head; /* ordered * the accuracy of the hardware clock. * */ -void clock_interrupt(usec, usermode, basepri) - register int usec; /* microseconds per tick */ - boolean_t usermode; /* executing user code */ - boolean_t basepri; /* at base priority */ +void clock_interrupt( + int usec, /* microseconds per tick */ + boolean_t usermode, /* executing user code */ + boolean_t basepri) /* at base priority */ { - register int my_cpu = cpu_number(); - register thread_t thread = current_thread(); + int my_cpu = cpu_number(); + thread_t thread = current_thread(); counter(c_clock_ticks++); counter(c_threads_total += c_threads_current); @@ -141,14 +143,13 @@ void clock_interrupt(usec, usermode, bas else { timer_bump(&thread->system_timer, usec); } -#endif STAT_TIME +#endif /* STAT_TIME */ /* * Increment the CPU time statistics. */ { - extern void thread_quantum_update(); /* in priority.c */ - register int state; + int state; if (usermode) state = CPU_STATE_USER; @@ -167,7 +168,7 @@ void clock_interrupt(usec, usermode, bas thread_quantum_update(my_cpu, thread, 1, state); } -#if MACH_SAMPLE +#if MACH_PCSAMPLE /* * Take a sample of pc for the user if required. * This had better be MP safe. It might be interesting @@ -184,8 +185,8 @@ void clock_interrupt(usec, usermode, bas */ if (my_cpu == master_cpu) { - register spl_t s; - register timer_elt_t telt; + spl_t s; + timer_elt_t telt; boolean_t needsoft = FALSE; #if TS_FORMAT == 1 @@ -193,7 +194,7 @@ void clock_interrupt(usec, usermode, bas * Increment the tick count for the timestamping routine. */ ts_tick_count++; -#endif TS_FORMAT == 1 +#endif /* TS_FORMAT == 1 */ /* * Update the tick count since bootup, and handle @@ -218,7 +219,7 @@ void clock_interrupt(usec, usermode, bas time_value_add_usec(&time, usec); } else { - register int delta; + int delta; if (timedelta < 0) { delta = usec - tickdelta; @@ -233,7 +234,7 @@ void clock_interrupt(usec, usermode, bas update_mapped_time(&time); /* - * Schedule soft-interupt for timeout if needed + * Schedule soft-interrupt for timeout if needed */ if (needsoft) { if (basepri) { @@ -269,15 +270,15 @@ void clock_interrupt(usec, usermode, bas * and corrupts it. */ -void softclock() +void softclock(void) { /* * Handle timeouts. */ spl_t s; - register timer_elt_t telt; - register int (*fcn)(); - register char *param; + timer_elt_t telt; + void (*fcn)( void * param ); + void *param; while (TRUE) { s = splsched(); @@ -308,12 +309,12 @@ void softclock() * telt timer element. Function and param are already set. * interval time-out interval, in hz. */ -void set_timeout(telt, interval) - register timer_elt_t telt; /* already loaded */ - register unsigned int interval; +void set_timeout( + timer_elt_t telt, /* already loaded */ + unsigned int interval) { spl_t s; - register timer_elt_t next; + timer_elt_t next; s = splsched(); simple_lock(&timer_lock); @@ -338,8 +339,7 @@ void set_timeout(telt, interval) splx(s); } -boolean_t reset_timeout(telt) - register timer_elt_t telt; +boolean_t reset_timeout(timer_elt_t telt) { spl_t s; @@ -359,7 +359,7 @@ boolean_t reset_timeout(telt) } } -void init_timeout() +void init_timeout(void) { simple_lock_init(&timer_lock); queue_init(&timer_head.chain); @@ -369,11 +369,24 @@ void init_timeout() } /* + * Record a timestamp in STAMP. + */ +void +record_time_stamp (time_value_t *stamp) +{ + do { + stamp->seconds = mtime->seconds; + stamp->microseconds = mtime->microseconds; + } while (stamp->seconds != mtime->check_seconds); +} + + +/* * Read the time. */ kern_return_t host_get_time(host, current_time) - host_t host; + const host_t host; time_value_t *current_time; /* OUT */ { if (host == HOST_NULL) @@ -392,7 +405,7 @@ host_get_time(host, current_time) */ kern_return_t host_set_time(host, new_time) - host_t host; + const host_t host; time_value_t new_time; { spl_t s; @@ -407,7 +420,7 @@ host_set_time(host, new_time) thread_bind(current_thread(), master_processor); if (current_processor() != master_processor) thread_block((void (*)) 0); -#endif NCPUS > 1 +#endif /* NCPUS > 1 */ s = splhigh(); time = new_time; @@ -420,7 +433,7 @@ host_set_time(host, new_time) * Switch off the master CPU. */ thread_bind(current_thread(), PROCESSOR_NULL); -#endif NCPUS > 1 +#endif /* NCPUS > 1 */ return (KERN_SUCCESS); } @@ -430,7 +443,7 @@ host_set_time(host, new_time) */ kern_return_t host_adjust_time(host, new_adjustment, old_adjustment) - host_t host; + const host_t host; time_value_t new_adjustment; time_value_t *old_adjustment; /* OUT */ { @@ -448,7 +461,7 @@ host_adjust_time(host, new_adjustment, o thread_bind(current_thread(), master_processor); if (current_processor() != master_processor) thread_block((void (*)) 0); -#endif NCPUS > 1 +#endif /* NCPUS > 1 */ s = splclock(); @@ -469,35 +482,35 @@ host_adjust_time(host, new_adjustment, o splx(s); #if NCPUS > 1 thread_bind(current_thread(), PROCESSOR_NULL); -#endif NCPUS > 1 +#endif /* NCPUS > 1 */ *old_adjustment = oadj; return (KERN_SUCCESS); } -void mapable_time_init() +void mapable_time_init(void) { if (kmem_alloc_wired(kernel_map, (vm_offset_t *) &mtime, PAGE_SIZE) != KERN_SUCCESS) panic("mapable_time_init"); - bzero((char *)mtime, PAGE_SIZE); + memset(mtime, 0, PAGE_SIZE); update_mapped_time(&time); } -int timeopen() +int timeopen(dev_t dev, int flag, io_req_t ior) { return(0); } -int timeclose() +void timeclose(dev_t dev, int flag) { - return(0); + return; } /* * Compatibility for device drivers. * New code should use set_timeout/reset_timeout and private timers. - * These code can't use a zone to allocate timers, because + * These code can't use a cache to allocate timers, because * it can be called from interrupt handlers. */ @@ -512,13 +525,13 @@ timer_elt_data_t timeout_timers[NTIMERS] * param: parameter to pass to function * interval: timeout interval, in hz. */ -void timeout(fcn, param, interval) - int (*fcn)(/* char * param */); - char * param; - int interval; +void timeout( + void (*fcn)(void *param), + void * param, + int interval) { spl_t s; - register timer_elt_t elt; + timer_elt_t elt; s = splsched(); simple_lock(&timer_lock); @@ -541,11 +554,11 @@ void timeout(fcn, param, interval) * and removed. */ boolean_t untimeout(fcn, param) - register int (*fcn)(); - register char * param; + void (*fcn)( void * param ); + const void * param; { spl_t s; - register timer_elt_t elt; + timer_elt_t elt; s = splsched(); simple_lock(&timer_lock);