xref: /illumos-gate/usr/src/compat/bhyve/sys/callout.h (revision a92282e44f968185a6bba094d1e5fece2da819cf)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2014 Pluribus Networks Inc.
14  * Copyright 2018 Joyent, Inc.
15  * Copyright 2020 Oxide Computer Company
16  */
17 
18 #ifndef _COMPAT_FREEBSD_SYS_CALLOUT_H_
19 #define	_COMPAT_FREEBSD_SYS_CALLOUT_H_
20 
21 #include <sys/cyclic.h>
22 
23 struct callout {
24 	cyclic_id_t	c_cyc_id;
25 	hrtime_t	c_target;
26 	hrtime_t	c_fired;
27 	void		(*c_func)(void *);
28 	void		*c_arg;
29 };
30 
31 #define	C_ABSOLUTE		0x0200	/* event time is absolute. */
32 
33 /* Callout considered active if t_target has not been zeroed */
34 #define	callout_active(c)	((c)->c_target != 0)
35 #define	callout_deactivate(c)	((c)->c_target = 0)
36 
37 /*
38  * If a callout is rescheduled (into the future) while its handler is running,
39  * it will be able to detect the pending invocation by the target time being
40  * greater than the time at which the handler was fired.
41  *
42  * This is only valid when checked from the callout handler, which is the only
43  * place where it is used by bhyve today.
44  */
45 #define	callout_pending(c)	((c)->c_target > (c)->c_fired)
46 
47 void	vmm_glue_callout_init(struct callout *c, int mpsafe);
48 int	vmm_glue_callout_reset_sbt(struct callout *c, sbintime_t sbt,
49     sbintime_t pr, void (*func)(void *), void *arg, int flags);
50 int	vmm_glue_callout_stop(struct callout *c);
51 int	vmm_glue_callout_drain(struct callout *c);
52 
53 /* illumos-custom function for resource locality optimization */
54 void	vmm_glue_callout_localize(struct callout *c);
55 
56 static __inline void
57 callout_init(struct callout *c, int mpsafe)
58 {
59 	vmm_glue_callout_init(c, mpsafe);
60 }
61 
62 static __inline int
63 callout_stop(struct callout *c)
64 {
65 	return (vmm_glue_callout_stop(c));
66 }
67 
68 static __inline int
69 callout_drain(struct callout *c)
70 {
71 	return (vmm_glue_callout_drain(c));
72 }
73 
74 static __inline int
75 callout_reset_sbt(struct callout *c, sbintime_t sbt, sbintime_t pr,
76     void (*func)(void *), void *arg, int flags)
77 {
78 	return (vmm_glue_callout_reset_sbt(c, sbt, pr, func, arg, flags));
79 }
80 
81 
82 #endif	/* _COMPAT_FREEBSD_SYS_CALLOUT_H_ */
83