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