Changeset View
Changeset View
Standalone View
Standalone View
sys/compat/linuxkpi/common/include/linux/timer.h
Show All 30 Lines | |||||
#ifndef _LINUX_TIMER_H_ | #ifndef _LINUX_TIMER_H_ | ||||
#define _LINUX_TIMER_H_ | #define _LINUX_TIMER_H_ | ||||
#include <linux/types.h> | #include <linux/types.h> | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/kernel.h> | #include <sys/kernel.h> | ||||
#include <sys/callout.h> | #include <sys/callout.h> | ||||
#include <sys/lock.h> | |||||
#include <sys/mutex.h> | |||||
struct timer_list { | struct timer_list { | ||||
struct callout callout; | struct callout callout; | ||||
struct mtx mtx; | |||||
union { | union { | ||||
void (*function) (unsigned long); /* < v4.15 */ | void (*function) (unsigned long); /* < v4.15 */ | ||||
void (*function_415) (struct timer_list *); | void (*function_415) (struct timer_list *); | ||||
}; | }; | ||||
unsigned long data; | unsigned long data; | ||||
int expires; | int expires; | ||||
}; | }; | ||||
extern unsigned long linux_timer_hz_mask; | extern unsigned long linux_timer_hz_mask; | ||||
#define TIMER_IRQSAFE 0x0001 | #define TIMER_IRQSAFE 0x0001 | ||||
#define from_timer(var, arg, field) \ | #define from_timer(var, arg, field) \ | ||||
container_of(arg, typeof(*(var)), field) | container_of(arg, typeof(*(var)), field) | ||||
/* | |||||
* Avoid witness enrollment with MTX_NOWITNESS flag to not leak this | |||||
* data on free() as Linux timers do not have destructors. | |||||
*/ | |||||
#define timer_setup(timer, func, flags) do { \ | #define timer_setup(timer, func, flags) do { \ | ||||
CTASSERT(((flags) & ~TIMER_IRQSAFE) == 0); \ | CTASSERT(((flags) & ~TIMER_IRQSAFE) == 0); \ | ||||
(timer)->function_415 = (func); \ | (timer)->function_415 = (func); \ | ||||
(timer)->data = (unsigned long)(timer); \ | (timer)->data = (unsigned long)(timer); \ | ||||
mtx_init(&(timer)->mtx, "lnxtimer", NULL, \ | |||||
MTX_DEF | MTX_NEW | MTX_NOWITNESS); \ | |||||
callout_init(&(timer)->callout, 1); \ | callout_init(&(timer)->callout, 1); \ | ||||
} while (0) | } while (0) | ||||
#define setup_timer(timer, func, dat) do { \ | #define setup_timer(timer, func, dat) do { \ | ||||
(timer)->function = (func); \ | (timer)->function = (func); \ | ||||
(timer)->data = (dat); \ | (timer)->data = (dat); \ | ||||
mtx_init(&(timer)->mtx, "lnxtimer", NULL, \ | |||||
MTX_DEF | MTX_NEW | MTX_NOWITNESS); \ | |||||
callout_init(&(timer)->callout, 1); \ | callout_init(&(timer)->callout, 1); \ | ||||
} while (0) | } while (0) | ||||
#define __setup_timer(timer, func, dat, flags) do { \ | #define __setup_timer(timer, func, dat, flags) do { \ | ||||
CTASSERT(((flags) & ~TIMER_IRQSAFE) == 0); \ | CTASSERT(((flags) & ~TIMER_IRQSAFE) == 0); \ | ||||
setup_timer(timer, func, dat); \ | setup_timer(timer, func, dat); \ | ||||
} while (0) | } while (0) | ||||
#define init_timer(timer) do { \ | #define init_timer(timer) do { \ | ||||
(timer)->function = NULL; \ | (timer)->function = NULL; \ | ||||
(timer)->data = 0; \ | (timer)->data = 0; \ | ||||
mtx_init(&(timer)->mtx, "lnxtimer", NULL, \ | |||||
MTX_DEF | MTX_NEW | MTX_NOWITNESS); \ | |||||
callout_init(&(timer)->callout, 1); \ | callout_init(&(timer)->callout, 1); \ | ||||
} while (0) | } while (0) | ||||
extern void mod_timer(struct timer_list *, int); | extern void mod_timer(struct timer_list *, int); | ||||
extern void add_timer(struct timer_list *); | extern void add_timer(struct timer_list *); | ||||
extern void add_timer_on(struct timer_list *, int cpu); | extern void add_timer_on(struct timer_list *, int cpu); | ||||
extern int del_timer(struct timer_list *); | extern int del_timer(struct timer_list *); | ||||
extern int del_timer_sync(struct timer_list *); | |||||
#define del_timer_sync(timer) (void)callout_drain(&(timer)->callout) | |||||
#define timer_pending(timer) callout_pending(&(timer)->callout) | #define timer_pending(timer) callout_pending(&(timer)->callout) | ||||
#define round_jiffies(j) \ | #define round_jiffies(j) \ | ||||
((int)(((j) + linux_timer_hz_mask) & ~linux_timer_hz_mask)) | ((int)(((j) + linux_timer_hz_mask) & ~linux_timer_hz_mask)) | ||||
#define round_jiffies_relative(j) round_jiffies(j) | #define round_jiffies_relative(j) round_jiffies(j) | ||||
#define round_jiffies_up(j) round_jiffies(j) | #define round_jiffies_up(j) round_jiffies(j) | ||||
#define round_jiffies_up_relative(j) round_jiffies_up(j) | #define round_jiffies_up_relative(j) round_jiffies_up(j) | ||||
#endif /* _LINUX_TIMER_H_ */ | #endif /* _LINUX_TIMER_H_ */ |