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 void vmm_glue_callout_stop(struct callout *c); 49 void vmm_glue_callout_drain(struct callout *c); 50 51 /* illumos-custom function for resource locality optimization */ 52 void vmm_glue_callout_localize(struct callout *c); 53 54 static __inline void 55 callout_init(struct callout *c, int mpsafe) 56 { 57 vmm_glue_callout_init(c, mpsafe); 58 } 59 60 static __inline void 61 callout_stop(struct callout *c) 62 { 63 vmm_glue_callout_stop(c); 64 } 65 66 static __inline void 67 callout_drain(struct callout *c) 68 { 69 vmm_glue_callout_drain(c); 70 } 71 72 void callout_reset_hrtime(struct callout *c, hrtime_t target, 73 void (*func)(void *), void *arg, int flags); 74 75 uint64_t hrt_freq_count(hrtime_t interval, uint32_t freq); 76 hrtime_t hrt_freq_interval(uint32_t freq, uint64_t count); 77 78 #endif /* _COMPAT_FREEBSD_SYS_CALLOUT_H_ */ 79