xref: /titanic_50/usr/src/uts/common/sys/lwpchan_impl.h (revision da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0)
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 1997-2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_LCHAN_IMPL_H
28 #define	_SYS_LCHAN_IMPL_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #define	LWPCHAN_CVPOOL	0
37 #define	LWPCHAN_MPPOOL	1
38 
39 #define	LWPCHAN_INITIAL_BITS	2	/* 4 hash buckets */
40 #define	LWPCHAN_MAX_BITS	10	/* 1024 hash buckets */
41 
42 /*
43  * An lwpchan entry translates a process-shared lwp sync object's
44  * virtual address into its logical address, an lwpchan, previously
45  * computed via as_getmemid().
46  */
47 typedef struct lwpchan_entry {
48 	caddr_t lwpchan_addr;		/* virtual address */
49 	uint16_t lwpchan_type;		/* sync object type field */
50 	uint16_t lwpchan_pool;		/* LWPCHAN_CVPOOL/LWPCHAN_MPPOOL */
51 	lwpchan_t lwpchan_lwpchan;	/* unique logical address */
52 	struct lwpchan_entry *lwpchan_next;	/* hash chain */
53 } lwpchan_entry_t;
54 
55 /*
56  * Hash bucket head.  The mutex protects the consistency of the hash chain.
57  * Also, p->p_lcp cannot be changed while any one hash bucket lock is held.
58  * (The resizing thread must acquire all of the hash bucket locks.)
59  */
60 typedef struct lwpchan_hashbucket {
61 	kmutex_t lwpchan_lock;
62 	lwpchan_entry_t *lwpchan_chain;
63 } lwpchan_hashbucket_t;
64 
65 /*
66  * Each process maintains a cache of lwpchan translations for sync objects
67  * (lwp_mutex_t, lwp_cond_t, lwp_sema_t) that are shared between processes.
68  * The lwpchan cache is a hash table used to look up previously-computed
69  * lwpchan_t's by process virtual address.  We keep this cache because we
70  * believe that as_getmemid() is slow and we only need to call it once,
71  * then remember the results.  The hashing function is very simple, and
72  * assumes an even distribution of sync objects within the process's
73  * address space.  When hash chains become too long, the cache is resized
74  * on the fly.  The cache is freed when the process exits or execs.
75  */
76 typedef struct lwpchan_data {
77 	uint_t	lwpchan_bits;		/* number of bits */
78 	uint_t	lwpchan_size;		/* 1 << lwpchan_bits */
79 	uint_t	lwpchan_mask;		/* lwpchan_size - 1 */
80 	uint_t	lwpchan_entries;	/* number of entries in the cache */
81 	lwpchan_hashbucket_t *lwpchan_cache;
82 	struct lwpchan_data *lwpchan_next_data;
83 } lwpchan_data_t;
84 
85 /*
86  * exported functions
87  */
88 void lwpchan_delete_mapping(proc_t *, caddr_t start, caddr_t end);
89 void lwpchan_destroy_cache(int);
90 
91 #ifdef	__cplusplus
92 }
93 #endif
94 
95 #endif	/* _SYS_LCHAN_IMPL_H */
96