xref: /illumos-gate/usr/src/cmd/fm/fmd/common/fmd_time.h (revision 2a8bcb4efb45d99ac41c94a75c396b362c414f7f)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_FMD_TIME_H
28 #define	_FMD_TIME_H
29 
30 #include <sys/types.h>
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 typedef struct fmd_timeval {
37 	uint64_t ftv_sec;	/* seconds since gettimeofday(3C) Epoch */
38 	uint64_t ftv_nsec;	/* nanoseconds past value of ftv_sec */
39 } fmd_timeval_t;
40 
41 typedef struct fmd_timeops {
42 	void *(*fto_init)(void);
43 	void (*fto_fini)(void *);
44 	int (*fto_gettimeofday)(struct timeval *, void *);
45 	hrtime_t (*fto_gethrtime)(void);
46 	void (*fto_addhrtime)(hrtime_t);
47 	void (*fto_waithrtime)(hrtime_t);
48 	void (*fto_waitcancel)(pthread_t);
49 } fmd_timeops_t;
50 
51 typedef struct fmd_timesim {
52 	pthread_mutex_t fts_lock; /* lock protecting contents of fmd_timesim */
53 	pthread_cond_t fts_cv;	/* condition variable for timerq wait */
54 	hrtime_t fts_tod;	/* time-of-day nsec corresponding to hrt=0 */
55 	hrtime_t fts_hrt;	/* hrtime clock in simulated universe */
56 	uint_t fts_cancel;	/* count of pending fto_waitcancel()s */
57 } fmd_timesim_t;
58 
59 extern const fmd_timeops_t fmd_timeops_native;
60 extern const fmd_timeops_t fmd_timeops_simulated;
61 
62 extern void fmd_time_gettimeofday(struct timeval *);
63 extern hrtime_t fmd_time_gethrtime(void);
64 extern void fmd_time_addhrtime(hrtime_t);
65 extern void fmd_time_waithrtime(hrtime_t);
66 extern void fmd_time_waitcancel(pthread_t);
67 extern void fmd_time_sync(fmd_timeval_t *, hrtime_t *, uint_t);
68 
69 extern void fmd_time_hrt2tod(hrtime_t, const fmd_timeval_t *,
70     hrtime_t, fmd_timeval_t *);
71 
72 extern void fmd_time_tod2hrt(hrtime_t, const fmd_timeval_t *,
73     const fmd_timeval_t *, hrtime_t *);
74 
75 extern hrtime_t fmd_time_ena2hrt(hrtime_t, uint64_t);
76 
77 #ifdef	__cplusplus
78 }
79 #endif
80 
81 #endif	/* _FMD_TIME_H */
82