xref: /titanic_52/usr/src/uts/common/sys/modhash_impl.h (revision bdfc6d18da790deeec2e0eb09c625902defe2498)
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  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_MODHASH_IMPL_H
28 #define	_SYS_MODHASH_IMPL_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 /*
33  * Internal details for the kernel's generic hash implementation.
34  */
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 #ifdef _KERNEL
41 
42 #include <sys/ksynch.h>
43 #include <sys/modhash.h>
44 
45 struct mod_hash_entry {
46 	mod_hash_key_t mhe_key;			/* stored hash key	*/
47 	mod_hash_val_t mhe_val;			/* stored hash value	*/
48 	struct mod_hash_entry *mhe_next;	/* next item in chain	*/
49 };
50 
51 struct mod_hash_stat {
52 	ulong_t mhs_hit;	/* tried a 'find' and it succeeded */
53 	ulong_t mhs_miss;	/* tried a 'find' but it failed */
54 	ulong_t mhs_coll;	/* occur when insert fails because of dup's */
55 	ulong_t mhs_nelems;	/* total number of stored key/value pairs */
56 	ulong_t mhs_nomem;	/* number of times kmem_alloc failed */
57 };
58 
59 struct mod_hash {
60 	krwlock_t	mh_contents;	/* lock protecting contents */
61 	char		*mh_name;	/* hash name */
62 	int		mh_sleep;	/* kmem_alloc flag */
63 	size_t		mh_nchains;	/* # of elements in mh_entries */
64 
65 	/* key and val destructor */
66 	void    (*mh_kdtor)(mod_hash_key_t);
67 	void    (*mh_vdtor)(mod_hash_val_t);
68 
69 	/* key comparator */
70 	int	(*mh_keycmp)(mod_hash_key_t, mod_hash_key_t);
71 
72 	/* hash algorithm, and algorithm-private data */
73 	uint_t  (*mh_hashalg)(void *, mod_hash_key_t);
74 	void    *mh_hashalg_data;
75 
76 	struct mod_hash	*mh_next;	/* next hash in list */
77 
78 	struct mod_hash_stat mh_stat;
79 
80 	struct mod_hash_entry *mh_entries[1];
81 };
82 
83 /*
84  * MH_SIZE()
85  * 	Compute the size of a mod_hash_t, in bytes, given the number of
86  * 	elements it contains.
87  */
88 #define	MH_SIZE(n) \
89 	(sizeof (mod_hash_t) + ((n) - 1) * (sizeof (struct mod_hash_entry *)))
90 
91 /*
92  * Module initialization; called once.
93  */
94 void mod_hash_init(void);
95 
96 #endif /* _KERNEL */
97 
98 #ifdef __cplusplus
99 }
100 #endif
101 
102 #endif /* _SYS_MODHASH_IMPL_H */
103