]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/kern/clock.h
xnu-3248.40.184.tar.gz
[apple/xnu.git] / osfmk / kern / clock.h
index b96848a084ff1efdc5d6722ef28e3b0bf6aee1b3..8918ca3c16b71097f09b27e0a656c0ca73f4d8ee 100644 (file)
@@ -1,16 +1,19 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2008 Apple Inc. All rights reserved.
  *
- * @APPLE_LICENSE_HEADER_START@
- * 
- * Copyright (c) 1999-2003 Apple Computer, Inc.  All Rights Reserved.
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
  * 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
- * file.
+ * 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
  * Please see the License for the specific language governing rights and
  * limitations under the License.
  * 
- * @APPLE_LICENSE_HEADER_END@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
  */
 /*
  * @OSF_COPYRIGHT@
  */
 /*
- *     File:           kern/clock.h
- *     Purpose:        Data structures for the kernel alarm clock
- *                     facility. This file is used only by kernel
- *                     level clock facility routines.
  */
 
 #ifndef        _KERN_CLOCK_H_
 #define        _KERN_CLOCK_H_
 
-#include <mach/message.h>
+#include <stdint.h>
+#include <mach/mach_types.h>
 #include <mach/clock_types.h>
+#include <mach/message.h>
 #include <mach/mach_time.h>
 
-#include <sys/appleapiopts.h>
+#include <kern/kern_types.h>
 
-#ifdef __APPLE_API_PRIVATE
+#include <sys/cdefs.h>
 
-#ifdef MACH_KERNEL_PRIVATE
+#ifdef __LP64__
 
-#include <ipc/ipc_port.h>
+typedef unsigned long          clock_sec_t;
+typedef unsigned int           clock_usec_t, clock_nsec_t;
 
-/*
- * Actual clock alarm structure. Used for user clock_sleep() and
- * clock_alarm() calls. Alarms are allocated from the alarm free
- * list and entered in time priority order into the active alarm
- * chain of the target clock.
- */
-struct alarm {
-       struct  alarm   *al_next;               /* next alarm in chain */
-       struct  alarm   *al_prev;               /* previous alarm in chain */
-       int                             al_status;              /* alarm status */
-       mach_timespec_t al_time;                /* alarm time */
-       struct {                                /* message alarm data */
-               int                             type;           /* alarm type */
-               ipc_port_t              port;           /* alarm port */
-               mach_msg_type_name_t
-                                               port_type;      /* alarm port type */
-               struct  clock   *clock;         /* alarm clock */
-               void                    *data;          /* alarm data */
-       } al_alrm;
-#define al_type                al_alrm.type
-#define al_port                al_alrm.port
-#define al_port_type   al_alrm.port_type
-#define al_clock       al_alrm.clock
-#define al_data                al_alrm.data
-       long                    al_seqno;               /* alarm sequence number */
-};
-typedef struct alarm   alarm_data_t;
+#else  /* __LP64__ */
+
+typedef uint32_t                       clock_sec_t;
+typedef uint32_t                       clock_usec_t, clock_nsec_t;
 
-/* alarm status */
-#define ALARM_FREE     0               /* alarm is on free list */
-#define        ALARM_SLEEP     1               /* active clock_sleep() */
-#define ALARM_CLOCK    2               /* active clock_alarm() */
-#define ALARM_DONE     4               /* alarm has expired */
+#endif /* __LP64__ */
+
+#ifdef MACH_KERNEL_PRIVATE
+
+#include <kern/queue.h>
 
 /*
  * Clock operations list structure. Contains vectors to machine
- * dependent clock routines. The routines c_config, c_init, and
- * c_gettime must be implemented for every clock device.
+ * dependent clock routines.
  */
 struct clock_ops {
        int             (*c_config)(void);              /* configuration */
@@ -94,37 +72,22 @@ struct      clock_ops {
        kern_return_t   (*c_gettime)(   /* get time */
                                mach_timespec_t                 *cur_time);
 
-       kern_return_t   (*c_settime)(   /* set time */
-                               mach_timespec_t                 *clock_time);
-
        kern_return_t   (*c_getattr)(   /* get attributes */
                                clock_flavor_t                  flavor,
                                clock_attr_t                    attr,
                                mach_msg_type_number_t  *count);
-
-       kern_return_t   (*c_setattr)(   /* set attributes */
-                               clock_flavor_t                  flavor,
-                               clock_attr_t                    attr,
-                               mach_msg_type_number_t  count);
-
-       void            (*c_setalrm)(           /* set next alarm */
-                               mach_timespec_t                 *alarm_time);
 };
 typedef struct clock_ops       *clock_ops_t;
 typedef struct clock_ops       clock_ops_data_t;
 
 /*
  * Actual clock object data structure. Contains the machine
- * dependent operations list, clock operations ports, and a
- * chain of pending alarms.
+ * dependent operations list and clock operation ports.
  */
 struct clock {
        clock_ops_t                     cl_ops;                 /* operations list */
        struct ipc_port         *cl_service;    /* service port */
        struct ipc_port         *cl_control;    /* control port */
-       struct  {                                                       /* alarm chain head */
-               struct alarm    *al_next;
-       } cl_alarm;
 };
 typedef struct clock           clock_data_t;
 
@@ -132,95 +95,104 @@ typedef struct clock              clock_data_t;
  * Configure the clock system.
  */
 extern void            clock_config(void);
+extern void            clock_oldconfig(void);
+
 /*
  * Initialize the clock system.
  */
 extern void            clock_init(void);
+extern void            clock_oldinit(void);
+
+extern void            clock_timebase_init(void);
 
 /*
  * Initialize the clock ipc service facility.
  */
 extern void            clock_service_create(void);
 
-/*
- * Service clock alarm interrupts. Called from machine dependent
- * layer at splclock(). The clock_id argument specifies the clock,
- * and the clock_time argument gives that clock's current time.
- */
-extern void            clock_alarm_intr(
-                                       clock_id_t              clock_id,
-                                       mach_timespec_t *clock_time);
+extern void                    clock_gettimeofday_set_commpage(
+                                               uint64_t                                abstime,
+                                               uint64_t                                epoch,
+                                               uint64_t                                offset,
+                                               clock_sec_t                             *secs,
+                                               clock_usec_t                    *microsecs);
 
-extern kern_return_t   clock_sleep_internal(
-                                                       clock_t                 clock,
-                                                       sleep_type_t    sleep_type,
-                                                       mach_timespec_t *sleep_time);
+extern void                    machine_delay_until(uint64_t interval,
+                                               uint64_t                deadline);
 
-typedef void           (*clock_timer_func_t)(
-                                               uint64_t                        timestamp);
+extern uint32_t                hz_tick_interval;
 
-extern void                    clock_set_timer_func(
-                                               clock_timer_func_t      func);
+extern void            nanotime_to_absolutetime(
+                                       clock_sec_t             secs,
+                                       clock_nsec_t    nanosecs,
+                                       uint64_t                *result);
 
-extern void                    clock_set_timer_deadline(
-                                               uint64_t                        deadline);
+#endif /* MACH_KERNEL_PRIVATE */
 
-extern void                    mk_timebase_info(
-                                               uint32_t                        *delta,
-                                               uint32_t                        *abs_to_ns_numer,
-                                               uint32_t                        *abs_to_ns_denom,
-                                               uint32_t                        *proc_to_abs_numer,
-                                               uint32_t                        *proc_to_abs_denom);
+__BEGIN_DECLS
 
-extern void                    clock_adjust_calendar(
-                                               clock_res_t                     nsec);
+#ifdef XNU_KERNEL_PRIVATE
 
-extern mach_timespec_t
-                                       clock_get_calendar_offset(void);
+extern void                    clock_adjtime(
+                                               long            *secs,
+                                               int                     *microsecs);
 
-#endif /* MACH_KERNEL_PRIVATE */
+extern void                    clock_initialize_calendar(void);
 
-extern void                    clock_set_calendar_value(
-                                               mach_timespec_t         value);
+extern void                    clock_wakeup_calendar(void);
 
-extern int64_t         clock_set_calendar_adjtime(
-                                               int64_t                         total,
-                                               uint32_t                        delta);
+extern void                    clock_gettimeofday(
+                                               clock_sec_t                     *secs,
+                                               clock_usec_t            *microsecs);
 
-extern void                    clock_initialize_calendar(void);
+extern void                    clock_set_calendar_microtime(
+                                               clock_sec_t                     secs,
+                                               clock_usec_t            microsecs);
 
-#endif /* __APPLE_API_PRIVATE */
+extern void                    clock_get_boottime_nanotime(
+                                               clock_sec_t                     *secs,
+                                               clock_nsec_t            *nanosecs);
 
-#ifdef __APPLE_API_UNSTABLE
+extern void                    absolutetime_to_microtime(
+                                               uint64_t                        abstime,
+                                               clock_sec_t                     *secs,
+                                               clock_usec_t            *microsecs);
 
-#define MACH_TIMESPEC_SEC_MAX          (0 - 1)
-#define MACH_TIMESPEC_NSEC_MAX         (NSEC_PER_SEC - 1)
+extern void                    clock_deadline_for_periodic_event(
+                                               uint64_t                        interval,
+                                               uint64_t                        abstime,
+                                               uint64_t                        *deadline);
 
-#define MACH_TIMESPEC_MAX      ((mach_timespec_t) {                            \
-                                                                       MACH_TIMESPEC_SEC_MAX,          \
-                                                                       MACH_TIMESPEC_NSEC_MAX } )
-#define MACH_TIMESPEC_ZERO     ((mach_timespec_t) { 0, 0 } )
+#if    CONFIG_DTRACE
 
-#define ADD_MACH_TIMESPEC_NSEC(t1, nsec)               \
-  do {                                                                                 \
-       (t1)->tv_nsec += (clock_res_t)(nsec);           \
-       if ((clock_res_t)(nsec) > 0 &&                          \
-                       (t1)->tv_nsec >= NSEC_PER_SEC) {        \
-               (t1)->tv_nsec -= NSEC_PER_SEC;                  \
-               (t1)->tv_sec += 1;                                              \
-       }                                                                                       \
-       else if ((clock_res_t)(nsec) < 0 &&                     \
-                                (t1)->tv_nsec < 0) {                   \
-               (t1)->tv_nsec += NSEC_PER_SEC;                  \
-               (t1)->tv_sec -= 1;                                              \
-       }                                                                                       \
-  } while (0)
+extern void                    clock_get_calendar_nanotime_nowait(
+                                               clock_sec_t                     *secs,
+                                               clock_nsec_t            *nanosecs);
+
+#endif /* CONFIG_DTRACE */
+
+#endif /* XNU_KERNEL_PRIVATE */
+
+extern void                    clock_get_calendar_microtime(
+                                               clock_sec_t                     *secs,
+                                               clock_usec_t            *microsecs);
 
-#endif /* __APPLE_API_UNSTABLE */
+extern void                    clock_get_calendar_absolute_and_microtime(
+                                               clock_sec_t                     *secs,
+                                               clock_usec_t            *microsecs,
+                                               uint64_t                *abstime);
 
-extern mach_timespec_t clock_get_system_value(void);
+extern void                    clock_get_calendar_nanotime(
+                                               clock_sec_t                     *secs,
+                                               clock_nsec_t            *nanosecs);
 
-extern mach_timespec_t clock_get_calendar_value(void);
+extern void                    clock_get_system_microtime(
+                                               clock_sec_t                     *secs,
+                                               clock_usec_t            *microsecs);
+
+extern void                    clock_get_system_nanotime(
+                                               clock_sec_t                     *secs,
+                                               clock_nsec_t            *nanosecs);
 
 extern void                            clock_timebase_info(
                                                        mach_timebase_info_t    info);
@@ -242,15 +214,6 @@ extern void                                clock_absolutetime_interval_to_deadline(
                                                        uint64_t                abstime,
                                                        uint64_t                *result);
 
-extern void                            clock_deadline_for_periodic_event(
-                                                       uint64_t                interval,
-                                                       uint64_t                abstime,
-                                                       uint64_t                *deadline);
-
-extern void                            clock_delay_for_interval(
-                                                       uint32_t                interval,
-                                                       uint32_t                scale_factor);
-
 extern void                            clock_delay_until(
                                                        uint64_t                deadline);
 
@@ -262,57 +225,68 @@ extern void             nanoseconds_to_absolutetime(
                                                        uint64_t                nanoseconds,
                                                        uint64_t                *result);
 
-#if            !defined(MACH_KERNEL_PRIVATE) && !defined(ABSOLUTETIME_SCALAR_TYPE)
+extern uint64_t mach_absolutetime_asleep;
+extern uint64_t mach_absolutetime_last_sleep;
+
+#ifdef KERNEL_PRIVATE
+
+/*
+ * Obsolete interfaces.
+ */
+
+#ifndef        __LP64__
 
-#include <libkern/OSBase.h>
+#define MACH_TIMESPEC_SEC_MAX          (0 - 1)
+#define MACH_TIMESPEC_NSEC_MAX         (NSEC_PER_SEC - 1)
 
-#define clock_get_uptime(a)            \
-       clock_get_uptime(__OSAbsoluteTimePtr(a))
+#define MACH_TIMESPEC_MAX      ((mach_timespec_t) {                            \
+                                                                       MACH_TIMESPEC_SEC_MAX,          \
+                                                                       MACH_TIMESPEC_NSEC_MAX } )
+#define MACH_TIMESPEC_ZERO     ((mach_timespec_t) { 0, 0 } )
 
-#define clock_interval_to_deadline(a, b, c)            \
-       clock_interval_to_deadline((a), (b), __OSAbsoluteTimePtr(c))
+#define ADD_MACH_TIMESPEC_NSEC(t1, nsec)               \
+  do {                                                                                 \
+       (t1)->tv_nsec += (clock_res_t)(nsec);           \
+       if ((clock_res_t)(nsec) > 0 &&                          \
+                       (t1)->tv_nsec >= NSEC_PER_SEC) {        \
+               (t1)->tv_nsec -= NSEC_PER_SEC;                  \
+               (t1)->tv_sec += 1;                                              \
+       }                                                                                       \
+       else if ((clock_res_t)(nsec) < 0 &&                     \
+                                (t1)->tv_nsec < 0) {                   \
+               (t1)->tv_nsec += NSEC_PER_SEC;                  \
+               (t1)->tv_sec -= 1;                                              \
+       }                                                                                       \
+  } while (0)
 
-#define clock_interval_to_absolutetime_interval(a, b, c)       \
-       clock_interval_to_absolutetime_interval((a), (b), __OSAbsoluteTimePtr(c))
+#include <Availability.h>
 
-#define clock_absolutetime_interval_to_deadline(a, b)  \
-       clock_absolutetime_interval_to_deadline(__OSAbsoluteTime(a), __OSAbsoluteTimePtr(b))
+/* Use mach_absolute_time() */
+extern mach_timespec_t clock_get_system_value(void) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_8, __IPHONE_2_0, __IPHONE_6_0);
 
-#define clock_deadline_for_periodic_event(a, b, c)     \
-       clock_deadline_for_periodic_event(__OSAbsoluteTime(a), __OSAbsoluteTime(b), __OSAbsoluteTimePtr(c))
+extern mach_timespec_t clock_get_calendar_value(void) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_8, __IPHONE_2_0, __IPHONE_6_0);
 
-#define clock_delay_until(a)   \
-       clock_delay_until(__OSAbsoluteTime(a))
+#else  /* __LP64__ */
 
-#define absolutetime_to_nanoseconds(a, b)      \
-       absolutetime_to_nanoseconds(__OSAbsoluteTime(a), (b))
+#ifdef XNU_KERNEL_PRIVATE
 
-#define nanoseconds_to_absolutetime(a, b)      \
-       nanoseconds_to_absolutetime((a), __OSAbsoluteTimePtr(b))
+#define MACH_TIMESPEC_ZERO     ((mach_timespec_t) { 0, 0 } )
 
-#define AbsoluteTime_to_scalar(x)      (*(uint64_t *)(x))
+#endif /* XNU_KERNEL_PRIVATE */
 
-/* t1 < = > t2 */
-#define CMP_ABSOLUTETIME(t1, t2)                               \
-       (AbsoluteTime_to_scalar(t1) >                           \
-               AbsoluteTime_to_scalar(t2)? (int)+1 :   \
-        (AbsoluteTime_to_scalar(t1) <                          \
-               AbsoluteTime_to_scalar(t2)? (int)-1 : 0))
+#endif /* __LP64__ */
 
-/* t1 += t2 */
-#define ADD_ABSOLUTETIME(t1, t2)                               \
-       (AbsoluteTime_to_scalar(t1) +=                          \
-                               AbsoluteTime_to_scalar(t2))
+extern void                            delay_for_interval(
+                                                       uint32_t                interval,
+                                                       uint32_t                scale_factor);
 
-/* t1 -= t2 */
-#define SUB_ABSOLUTETIME(t1, t2)                               \
-       (AbsoluteTime_to_scalar(t1) -=                          \
-                               AbsoluteTime_to_scalar(t2))
+extern void                            delay_for_interval_with_leeway(
+                                                       uint32_t                interval,
+                                                       uint32_t                leeway,
+                                                       uint32_t                scale_factor);
 
-#define ADD_ABSOLUTETIME_TICKS(t1, ticks)              \
-       (AbsoluteTime_to_scalar(t1) +=                          \
-                                               (int32_t)(ticks))
+#endif /* KERNEL_PRIVATE */
 
-#endif
+__END_DECLS
 
 #endif /* _KERN_CLOCK_H_ */