xref: /illumos-gate/usr/src/cmd/fm/fmd/common/fmd_time.h (revision 8b80e8cb6855118d46f605e91b5ed4ce83417395)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/types.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 typedef struct fmd_timeval {
39 	uint64_t ftv_sec;	/* seconds since gettimeofday(3C) Epoch */
40 	uint64_t ftv_nsec;	/* nanoseconds past value of ftv_sec */
41 } fmd_timeval_t;
42 
43 typedef struct fmd_timeops {
44 	void *(*fto_init)(void);
45 	void (*fto_fini)(void *);
46 	int (*fto_gettimeofday)(struct timeval *, void *);
47 	hrtime_t (*fto_gethrtime)(void);
48 	void (*fto_addhrtime)(hrtime_t);
49 	void (*fto_waithrtime)(hrtime_t);
50 	void (*fto_waitcancel)(pthread_t);
51 } fmd_timeops_t;
52 
53 typedef struct fmd_timesim {
54 	pthread_mutex_t fts_lock; /* lock protecting contents of fmd_timesim */
55 	pthread_cond_t fts_cv;	/* condition variable for timerq wait */
56 	hrtime_t fts_tod;	/* time-of-day nsec corresponding to hrt=0 */
57 	hrtime_t fts_hrt;	/* hrtime clock in simulated universe */
58 	uint_t fts_cancel;	/* count of pending fto_waitcancel()s */
59 } fmd_timesim_t;
60 
61 extern const fmd_timeops_t fmd_timeops_native;
62 extern const fmd_timeops_t fmd_timeops_simulated;
63 
64 extern void fmd_time_gettimeofday(struct timeval *);
65 extern hrtime_t fmd_time_gethrtime(void);
66 extern void fmd_time_addhrtime(hrtime_t);
67 extern void fmd_time_waithrtime(hrtime_t);
68 extern void fmd_time_waitcancel(pthread_t);
69 extern void fmd_time_sync(fmd_timeval_t *, hrtime_t *, uint_t);
70 
71 extern void fmd_time_hrt2tod(hrtime_t, const fmd_timeval_t *,
72     hrtime_t, fmd_timeval_t *);
73 
74 extern void fmd_time_tod2hrt(hrtime_t, const fmd_timeval_t *,
75     const fmd_timeval_t *, hrtime_t *);
76 
77 extern hrtime_t fmd_time_ena2hrt(hrtime_t, uint64_t);
78 
79 #ifdef	__cplusplus
80 }
81 #endif
82 
83 #endif	/* _FMD_TIME_H */
84