xref: /titanic_50/usr/src/cmd/fm/fmd/common/fmd_ustat.h (revision 24fe0b3bf671e123467ce1df0b67cadd3614c8e4)
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 http://www.opensolaris.org/os/licensing.
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 /*
24  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
25  * Use is subject to license terms.
26  */
27 
28 #ifndef	_FMD_USTAT_H
29 #define	_FMD_USTAT_H
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"
32 
33 #include <pthread.h>
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 #include <fmd_api.h>
40 #include <fmd_list.h>
41 
42 typedef struct fmd_ustat_snap {
43 	fmd_stat_t *uss_buf;		/* array of statistic data */
44 	uint_t uss_len;			/* length of uss_buf array */
45 } fmd_ustat_snap_t;
46 
47 typedef struct fmd_ustat_chunk {
48 	fmd_list_t usc_list;		/* linked list next/prev pointers */
49 	fmd_stat_t *usc_base;		/* base of chunk allocation */
50 	uint_t usc_len;			/* number of stat structs in chunk */
51 	uint_t usc_refs;		/* reference count on chunk */
52 } fmd_ustat_chunk_t;
53 
54 typedef struct fmd_ustat_elem {
55 	struct fmd_ustat_elem *use_next; /* pointer to next statistic in hash */
56 	const fmd_stat_t *use_stat;	/* pointer to statistic data storage */
57 	fmd_ustat_chunk_t *use_chunk;	/* pointer to alloc chunk (or NULL) */
58 } fmd_ustat_elem_t;
59 
60 typedef struct fmd_ustat {
61 	pthread_rwlock_t us_lock;	/* lock protecting ustat collection */
62 	fmd_list_t us_chunks;		/* linked list of allocation chunks */
63 	fmd_ustat_elem_t **us_hash;	/* hash bucket array of stat elements */
64 	uint_t us_hashlen;		/* length of us_hash bucket array */
65 	uint_t us_nelems;		/* number of elements in collection */
66 } fmd_ustat_t;
67 
68 extern fmd_ustat_t *fmd_ustat_create(void);
69 extern void fmd_ustat_destroy(fmd_ustat_t *);
70 extern int fmd_ustat_snapshot(fmd_ustat_t *, fmd_ustat_snap_t *);
71 
72 #define	FMD_USTAT_NOALLOC	0x0	/* fmd should use caller's memory */
73 #define	FMD_USTAT_ALLOC		0x1	/* fmd should allocate stats memory */
74 #define	FMD_USTAT_VALIDATE	0x2	/* fmd should validate stat names */
75 
76 #if FMD_STAT_NOALLOC != FMD_USTAT_NOALLOC
77 #error "FMD_STAT_NOALLOC must match FMD_USTAT_NOALLOC"
78 #endif
79 
80 #if FMD_STAT_ALLOC != FMD_USTAT_ALLOC
81 #error "FMD_STAT_ALLOC must match FMD_USTAT_ALLOC"
82 #endif
83 
84 extern fmd_stat_t *fmd_ustat_insert(fmd_ustat_t *,
85     uint_t, uint_t, fmd_stat_t *, fmd_stat_t **);
86 
87 extern void fmd_ustat_delete(fmd_ustat_t *, uint_t, fmd_stat_t *);
88 extern void fmd_ustat_delete_references(fmd_ustat_t *);
89 
90 #ifdef	__cplusplus
91 }
92 #endif
93 
94 #endif	/* _FMD_USTAT_H */
95