xref: /illumos-gate/usr/src/cmd/fm/fmd/common/fmd_eventq.h (revision 2a417b23)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*2a417b23SRobert Johnston  * Common Development and Distribution License (the "License").
6*2a417b23SRobert Johnston  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*2a417b23SRobert Johnston  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate  */
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate #ifndef	_FMD_EVENTQ_H
267c478bd9Sstevel@tonic-gate #define	_FMD_EVENTQ_H
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #include <pthread.h>
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
317c478bd9Sstevel@tonic-gate extern "C" {
327c478bd9Sstevel@tonic-gate #endif
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #include <fmd_event.h>
357c478bd9Sstevel@tonic-gate #include <fmd_list.h>
367c478bd9Sstevel@tonic-gate 
37d9638e54Smws typedef struct fmd_eventqstat {
38d9638e54Smws 	fmd_stat_t eqs_dispatched;	/* total events dispatched to queue */
39d9638e54Smws 	fmd_stat_t eqs_dequeued;	/* total events dequeued by consumer */
40d9638e54Smws 	fmd_stat_t eqs_prdequeued;	/* total protocol events dequeued */
41d9638e54Smws 	fmd_stat_t eqs_dropped;		/* total events dropped by queue */
42d9638e54Smws 	fmd_stat_t eqs_wcnt;		/* count of events waiting on queue */
43d9638e54Smws 	fmd_stat_t eqs_wtime;		/* total wait time (pre-dispatch) */
44d9638e54Smws 	fmd_stat_t eqs_wlentime;	/* total wait length * time product */
45d9638e54Smws 	fmd_stat_t eqs_wlastupdate;	/* hrtime of last wait queue update */
46d9638e54Smws 	fmd_stat_t eqs_dtime;		/* total dispatch time */
47d9638e54Smws 	fmd_stat_t eqs_dlastupdate;	/* hrtime of last dispatch */
48d9638e54Smws } fmd_eventqstat_t;
49d9638e54Smws 
507c478bd9Sstevel@tonic-gate typedef struct fmd_eventqelem {
517c478bd9Sstevel@tonic-gate 	fmd_list_t eqe_list;		/* linked-list prev/next pointers */
527c478bd9Sstevel@tonic-gate 	fmd_event_t *eqe_event;		/* pointer to event */
537c478bd9Sstevel@tonic-gate } fmd_eventqelem_t;
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate struct fmd_module;			/* see <fmd_module.h> */
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate typedef struct fmd_eventq {
587c478bd9Sstevel@tonic-gate 	pthread_mutex_t eq_lock;	/* lock protecting queue contents */
597c478bd9Sstevel@tonic-gate 	pthread_cond_t eq_cv;		/* condition variable for waiters */
607c478bd9Sstevel@tonic-gate 	fmd_list_t eq_list;		/* list head/tail pointers for queue */
617c478bd9Sstevel@tonic-gate 	struct fmd_module *eq_mod;	/* module associated with this queue */
62d9638e54Smws 	pthread_mutex_t *eq_stats_lock;	/* lock that protects eq_stats */
63d9638e54Smws 	fmd_eventqstat_t *eq_stats;	/* statistics associated with queue */
647c478bd9Sstevel@tonic-gate 	uint_t eq_limit;		/* limit on number of queue elements */
657c478bd9Sstevel@tonic-gate 	uint_t eq_size;			/* number of elements on queue */
66d9638e54Smws 	uint_t eq_flags;		/* flags for abort and suspend */
67d9638e54Smws 	id_t eq_sgid;			/* subscription group id for dispq */
687c478bd9Sstevel@tonic-gate } fmd_eventq_t;
697c478bd9Sstevel@tonic-gate 
70d9638e54Smws #define	FMD_EVENTQ_ABORT	0x1	/* return NULL from fmd_eventq_delete */
71d9638e54Smws #define	FMD_EVENTQ_SUSPEND	0x2	/* suspend in fmd_eventq_delete */
72d9638e54Smws 
73d9638e54Smws extern fmd_eventq_t *fmd_eventq_create(struct fmd_module *,
74d9638e54Smws     fmd_eventqstat_t *, pthread_mutex_t *, uint_t);
757c478bd9Sstevel@tonic-gate extern void fmd_eventq_destroy(fmd_eventq_t *);
767c478bd9Sstevel@tonic-gate extern void fmd_eventq_insert_at_head(fmd_eventq_t *, fmd_event_t *);
777c478bd9Sstevel@tonic-gate extern void fmd_eventq_insert_at_time(fmd_eventq_t *, fmd_event_t *);
787c478bd9Sstevel@tonic-gate extern fmd_event_t *fmd_eventq_delete(fmd_eventq_t *);
79d9638e54Smws extern void fmd_eventq_done(fmd_eventq_t *);
807c478bd9Sstevel@tonic-gate extern void fmd_eventq_cancel(fmd_eventq_t *, uint_t, void *);
81d9638e54Smws extern void fmd_eventq_suspend(fmd_eventq_t *);
82d9638e54Smws extern void fmd_eventq_resume(fmd_eventq_t *);
837c478bd9Sstevel@tonic-gate extern void fmd_eventq_abort(fmd_eventq_t *);
84*2a417b23SRobert Johnston extern void fmd_eventq_drop_topo(fmd_eventq_t *);
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
877c478bd9Sstevel@tonic-gate }
887c478bd9Sstevel@tonic-gate #endif
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate #endif	/* _FMD_EVENTQ_H */
91