xref: /titanic_50/usr/src/cmd/fm/fmd/common/fmd_eventq.h (revision 880d797826457b77414b37d531cc3e1aa166ecbe)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
23  */
24 
25 #ifndef	_FMD_EVENTQ_H
26 #define	_FMD_EVENTQ_H
27 
28 #include <pthread.h>
29 
30 #ifdef	__cplusplus
31 extern "C" {
32 #endif
33 
34 #include <fmd_event.h>
35 #include <fmd_list.h>
36 
37 typedef struct fmd_eventqstat {
38 	fmd_stat_t eqs_dispatched;	/* total events dispatched to queue */
39 	fmd_stat_t eqs_dequeued;	/* total events dequeued by consumer */
40 	fmd_stat_t eqs_prdequeued;	/* total protocol events dequeued */
41 	fmd_stat_t eqs_dropped;		/* total events dropped by queue */
42 	fmd_stat_t eqs_wcnt;		/* count of events waiting on queue */
43 	fmd_stat_t eqs_wtime;		/* total wait time (pre-dispatch) */
44 	fmd_stat_t eqs_wlentime;	/* total wait length * time product */
45 	fmd_stat_t eqs_wlastupdate;	/* hrtime of last wait queue update */
46 	fmd_stat_t eqs_dtime;		/* total dispatch time */
47 	fmd_stat_t eqs_dlastupdate;	/* hrtime of last dispatch */
48 } fmd_eventqstat_t;
49 
50 typedef struct fmd_eventqelem {
51 	fmd_list_t eqe_list;		/* linked-list prev/next pointers */
52 	fmd_event_t *eqe_event;		/* pointer to event */
53 } fmd_eventqelem_t;
54 
55 struct fmd_module;			/* see <fmd_module.h> */
56 
57 typedef struct fmd_eventq {
58 	pthread_mutex_t eq_lock;	/* lock protecting queue contents */
59 	pthread_cond_t eq_cv;		/* condition variable for waiters */
60 	fmd_list_t eq_list;		/* list head/tail pointers for queue */
61 	struct fmd_module *eq_mod;	/* module associated with this queue */
62 	pthread_mutex_t *eq_stats_lock;	/* lock that protects eq_stats */
63 	fmd_eventqstat_t *eq_stats;	/* statistics associated with queue */
64 	uint_t eq_limit;		/* limit on number of queue elements */
65 	uint_t eq_size;			/* number of elements on queue */
66 	uint_t eq_flags;		/* flags for abort and suspend */
67 	id_t eq_sgid;			/* subscription group id for dispq */
68 } fmd_eventq_t;
69 
70 #define	FMD_EVENTQ_ABORT	0x1	/* return NULL from fmd_eventq_delete */
71 #define	FMD_EVENTQ_SUSPEND	0x2	/* suspend in fmd_eventq_delete */
72 
73 extern fmd_eventq_t *fmd_eventq_create(struct fmd_module *,
74     fmd_eventqstat_t *, pthread_mutex_t *, uint_t);
75 extern void fmd_eventq_destroy(fmd_eventq_t *);
76 extern void fmd_eventq_insert_at_head(fmd_eventq_t *, fmd_event_t *);
77 extern void fmd_eventq_insert_at_time(fmd_eventq_t *, fmd_event_t *);
78 extern fmd_event_t *fmd_eventq_delete(fmd_eventq_t *);
79 extern void fmd_eventq_done(fmd_eventq_t *);
80 extern void fmd_eventq_cancel(fmd_eventq_t *, uint_t, void *);
81 extern void fmd_eventq_suspend(fmd_eventq_t *);
82 extern void fmd_eventq_resume(fmd_eventq_t *);
83 extern void fmd_eventq_abort(fmd_eventq_t *);
84 extern void fmd_eventq_drop_topo(fmd_eventq_t *);
85 
86 #ifdef	__cplusplus
87 }
88 #endif
89 
90 #endif	/* _FMD_EVENTQ_H */
91