summaryrefslogtreecommitdiff
path: root/usr/src/uts/common/sys/ddi_periodic.h
blob: 0af46e5c01d2d7d3520e3769fecffc32a8570642 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
 * This file and its contents are supplied under the terms of the
 * Common Development and Distribution License ("CDDL"), version 1.0.
 * You may only use this file in accordance with the terms of version
 * 1.0 of the CDDL.
 *
 * A full copy of the text of the CDDL should have accompanied this
 * source.  A copy of the CDDL is also available via the Internet at
 * http://www.illumos.org/license/CDDL.
 */
/*
 * Copyright (c) 2013, Joyent, Inc.  All rights reserved.
 */

#ifndef	_SYS_DDI_PERIODIC_H
#define	_SYS_DDI_PERIODIC_H

#include <sys/list.h>
#include <sys/taskq_impl.h>
#include <sys/cyclic.h>

#ifdef	__cplusplus
extern "C" {
#endif

#ifdef _KERNEL

/*
 * Opaque handle type for i_timeout() and i_untimeout().
 */
typedef struct __timeout *timeout_t;

typedef enum ddi_periodic_flags {
	DPF_DISPATCHED = 0x01,
	DPF_EXECUTING = 0x02,
	DPF_CANCELLED = 0x04
} ddi_periodic_flags_t;

/*
 * Each instance of this structure represents a single periodic handler
 * registered through ddi_periodic_add(9F).
 */
typedef struct ddi_periodic_impl {
	struct list_node dpr_link; /* protected by periodics_lock */
	struct list_node dpr_softint_link; /* only used when DPF_DISPATCHED */
	id_t dpr_id;
	hrtime_t dpr_interval;

	kmutex_t dpr_lock;
	kcondvar_t dpr_cv;
	ddi_periodic_flags_t dpr_flags;
	uint_t dpr_level; /* 0 <= dpr_level <= 10 */
	taskq_ent_t dpr_taskq_ent; /* only used for level of 0 */
	uint64_t dpr_fire_count;
	kthread_t *dpr_thread;

	cyclic_id_t dpr_cyclic_id;

	void (*dpr_handler)(void *);
	void *dpr_arg;
} ddi_periodic_impl_t;

/*
 * Internal implementation functions for the DDI periodic interface.
 */
void ddi_periodic_init(void);
void ddi_periodic_fini(void);
void ddi_periodic_softintr(int level);
timeout_t i_timeout(void (*)(void *), void *, hrtime_t, int);
void i_untimeout(timeout_t);

#endif	/* _KERNEL */

#ifdef	__cplusplus
}
#endif

#endif	/* _SYS_DDI_PERIODIC_H */