X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/d7e50217d7adf6e52786a38bcaa4cd698cb9a79e..8ad349bb6ed4a0be06e34c92be0d98b92e078db4:/osfmk/kern/timer.h diff --git a/osfmk/kern/timer.h b/osfmk/kern/timer.h index 776fb5d76..c9096cb99 100644 --- a/osfmk/kern/timer.h +++ b/osfmk/kern/timer.h @@ -1,26 +1,31 @@ /* * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. * - * @APPLE_LICENSE_HEADER_START@ + * @APPLE_LICENSE_OSREFERENCE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. The rights granted to you under the + * License may not be used to create, or enable the creation or + * redistribution of, unlawful or unlicensed copies of an Apple operating + * system, or to circumvent, violate, or enable the circumvention or + * violation of, any terms of an Apple operating system software license + * agreement. + * + * Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and * limitations under the License. - * - * @APPLE_LICENSE_HEADER_END@ + * + * @APPLE_LICENSE_OSREFERENCE_HEADER_END@ */ /* * @OSF_COPYRIGHT@ @@ -56,176 +61,91 @@ #ifndef _KERN_TIMER_H_ #define _KERN_TIMER_H_ -#include #include -#include #include -#if STAT_TIME -/* - * Statistical timer definitions - use microseconds in timer, seconds - * in high unit field. No adjustment needed to convert to time_value_t - * as a result. Service timers once an hour. - */ - -#define TIMER_RATE 1000000 -#define TIMER_HIGH_UNIT TIMER_RATE -#undef TIMER_ADJUST - -#else /* STAT_TIME */ -/* - * Machine dependent definitions based on hardware support. - */ - -#include - -#endif /* STAT_TIME */ - /* - * Definitions for accurate timers. high_bits_check is a copy of - * high_bits that allows reader to verify that values read are ok. + * Definitions for high resolution timers. A check + * word on the high portion allows atomic updates. */ struct timer { - unsigned low_bits; - unsigned high_bits; - unsigned high_bits_check; - unsigned tstamp; + uint32_t low_bits; + uint32_t high_bits; + uint32_t high_bits_check; +#if !STAT_TIME + uint32_t tstamp; +#endif /* STAT_TIME */ }; -typedef struct timer timer_data_t; -typedef struct timer *timer_t; - -/* - * Mask to check if low_bits is in danger of overflowing - */ - -#define TIMER_LOW_FULL 0x80000000 +typedef struct timer timer_data_t, *timer_t; /* - * Kernel timers and current timer array. [Exported] + * Exported kernel interface to timers */ -extern timer_t current_timer[NCPUS]; -extern timer_data_t kernel_timer[NCPUS]; - -/* - * save structure for timer readings. This is used to save timer - * readings for elapsed time computations. - */ +#if STAT_TIME -struct timer_save { - unsigned low; - unsigned high; -}; +#include -typedef struct timer_save timer_save_data_t, *timer_save_t; +/* Advance a timer by the specified amount */ +#define TIMER_BUMP(timer, ticks) \ +MACRO_BEGIN \ + uint32_t old_low, low; \ + \ + old_low = (timer)->low_bits; \ + low = old_low + (ticks); \ + if (low < old_low) \ + timer_update((timer), (timer)->high_bits + 1, low); \ + else \ + (timer)->low_bits = low; \ +MACRO_END -/* - * Exported kernel interface to timers - */ +#define timer_switch(tstamp, new_timer) +#define timer_event(tstamp, new_timer) -#if STAT_TIME -#define start_timer(timer) -#define timer_switch(timer) #else /* STAT_TIME */ -/* Start timer for this cpu */ -extern void start_timer( - timer_t timer); -/* Switch to a new timer */ +/* Update the current timer and start a new one */ extern void timer_switch( - timer_t new_timer); -#endif /* STAT_TIME */ - -/* Initialize timer module */ -extern void init_timers(void); - -/* - * Initializes a single timer. - */ -extern void timer_init( - timer_t this_timer); + uint32_t tstamp, + timer_t new_timer); -/* Normalize timer value */ -extern void timer_normalize( - timer_t timer); +#define TIMER_BUMP(timer, ticks) -/* Read value of timer into tv */ -extern void timer_read( - timer_t timer, - time_value_t *tv); +#endif /* STAT_TIME */ -/* Read thread times */ -extern void thread_read_times( - thread_t thread, - time_value_t *user_time_p, - time_value_t *system_time_p); +/* Initialize a timer */ +extern void timer_init( + timer_t timer); -/* Compute timer difference */ -extern unsigned timer_delta( - timer_t timer, - timer_save_t save); +/* Update a saved timer value and return delta to current value */ +extern uint64_t timer_delta( + timer_t timer, + uint64_t *save); -#if STAT_TIME -/* - * Macro to bump timer values. - */ -#define timer_bump(timer, usec) \ -MACRO_BEGIN \ - (timer)->low_bits += usec; \ - if ((timer)->low_bits & TIMER_LOW_FULL) { \ - timer_normalize(timer); \ - } \ -MACRO_END - -#else /* STAT_TIME */ /* * Exported hardware interface to timers */ -/* Time trap entry */ -extern void time_trap_uentry( - unsigned ts); -/* Time trap exit */ -extern void time_trap_uexit( - unsigned ts); +/* Read timer value */ +extern uint64_t timer_grab( + timer_t timer); -/* Time interrupt entry */ -extern timer_t time_int_entry( - unsigned ts, - timer_t new_timer); +/* Update timer value */ +extern void timer_update( + timer_t timer, + uint32_t new_high, + uint32_t new_low); -/* Time interrrupt exit */ -extern void time_int_exit( - unsigned ts, - timer_t old_timer); +#if !STAT_TIME -#endif /* STAT_TIME */ - -/* - * TIMER_DELTA finds the difference between a timer and a saved value, - * and updates the saved value. Look at high_bits check field after - * reading low because that's the first written by a normalize - * operation; this isn't necessary for current usage because - * this macro is only used when the timer can't be normalized: - * thread is not running, or running thread calls it on itself at - * splsched(). - */ +/* Update the current timer at an event */ +extern void timer_event( + uint32_t tstamp, + timer_t new_timer); -#define TIMER_DELTA(timer, save, result) \ -MACRO_BEGIN \ - register unsigned temp; \ - \ - temp = (timer).low_bits; \ - if ((save).high != (timer).high_bits_check) { \ - result += timer_delta(&(timer), &(save)); \ - } \ - else { \ - result += temp - (save).low; \ - (save).low = temp; \ - } \ -MACRO_END +#endif /* STAT_TIME */ #endif /* _KERN_TIMER_H_ */