xref: /freebsd/sys/contrib/openzfs/cmd/zed/agents/fmd_serd.h (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or https://opensource.org/licenses/CDDL-1.0.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2016, Intel Corporation.
27  */
28 
29 #ifndef	_FMD_SERD_H
30 #define	_FMD_SERD_H
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #include <sys/list.h>
37 #include <sys/time.h>
38 
39 typedef struct fmd_serd_elem {
40 	list_node_t	se_list;	/* linked list forward/back pointers */
41 	hrtime_t	se_hrt;		/* upper bound on event hrtime */
42 } fmd_serd_elem_t;
43 
44 typedef struct fmd_serd_eng {
45 	char		*sg_name;	/* string name for this engine */
46 	struct fmd_serd_eng *sg_next;	/* next engine on hash chain */
47 	list_t		sg_list;	/* list of fmd_serd_elem_t's */
48 	uint_t		sg_count;	/* count of events in sg_list */
49 	uint_t		sg_flags;	/* engine flags (see below) */
50 	uint_t		sg_n;		/* engine N parameter (event count) */
51 	hrtime_t	sg_t;		/* engine T parameter (nanoseconds) */
52 } fmd_serd_eng_t;
53 
54 #define	FMD_SERD_FIRED	0x1		/* error rate has exceeded threshold */
55 #define	FMD_SERD_DIRTY	0x2		/* engine needs to be checkpointed */
56 
57 typedef void fmd_serd_eng_f(fmd_serd_eng_t *, void *);
58 
59 typedef struct fmd_serd_hash {
60 	fmd_serd_eng_t	**sh_hash;	/* hash bucket array for buffers */
61 	uint_t		sh_hashlen;	/* length of hash bucket array */
62 	uint_t		sh_count;	/* count of engines in hash */
63 } fmd_serd_hash_t;
64 
65 extern void fmd_serd_hash_create(fmd_serd_hash_t *);
66 extern void fmd_serd_hash_destroy(fmd_serd_hash_t *);
67 extern void fmd_serd_hash_apply(fmd_serd_hash_t *, fmd_serd_eng_f *, void *);
68 
69 extern fmd_serd_eng_t *fmd_serd_eng_insert(fmd_serd_hash_t *,
70     const char *, uint32_t, hrtime_t);
71 
72 extern fmd_serd_eng_t *fmd_serd_eng_lookup(fmd_serd_hash_t *, const char *);
73 extern void fmd_serd_eng_delete(fmd_serd_hash_t *, const char *);
74 
75 extern int fmd_serd_eng_record(fmd_serd_eng_t *, hrtime_t);
76 extern int fmd_serd_eng_fired(fmd_serd_eng_t *);
77 extern int fmd_serd_eng_empty(fmd_serd_eng_t *);
78 
79 extern void fmd_serd_eng_reset(fmd_serd_eng_t *);
80 extern void fmd_serd_eng_gc(fmd_serd_eng_t *, void *);
81 
82 #ifdef	__cplusplus
83 }
84 #endif
85 
86 #endif	/* _FMD_SERD_H */
87