xref: /illumos-gate/usr/src/uts/common/sys/lwpchan_impl.h (revision 48edc7cf07b5dccc3ad84bf2dafe4150bd666d60)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2009 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 #ifdef	__cplusplus
31 extern "C" {
32 #endif
33 
34 #define	LWPCHAN_CVPOOL	0
35 #define	LWPCHAN_MPPOOL	1
36 
37 #define	LWPCHAN_INITIAL_BITS	2	/* initially: 4 hash buckets */
38 #define	LWPCHAN_MAX_BITS	16	/* finally: up to 64K hash buckets */
39 
40 /*
41  * An lwpchan entry translates a process-shared lwp sync object's
42  * virtual address into its logical address, an lwpchan, previously
43  * computed via as_getmemid().
44  */
45 typedef struct lwpchan_entry {
46 	caddr_t lwpchan_addr;		/* virtual address */
47 	caddr_t lwpchan_uaddr;		/* address of lock registration */
48 	uint16_t lwpchan_type;		/* sync object type field */
49 	uint16_t lwpchan_pool;		/* LWPCHAN_CVPOOL/LWPCHAN_MPPOOL */
50 	lwpchan_t lwpchan_lwpchan;	/* unique logical address */
51 	struct lwpchan_entry *lwpchan_next;	/* hash chain */
52 } lwpchan_entry_t;
53 
54 /*
55  * Hash bucket head.  The mutex protects the consistency of the hash chain.
56  * Also, p->p_lcp cannot be changed while any one hash bucket lock is held.
57  * (The resizing thread must acquire all of the hash bucket locks.)
58  */
59 typedef struct lwpchan_hashbucket {
60 	kmutex_t lwpchan_lock;
61 	lwpchan_entry_t *lwpchan_chain;
62 } lwpchan_hashbucket_t;
63 
64 /*
65  * Each process maintains a cache of lwpchan translations for sync objects
66  * (lwp_mutex_t, lwp_cond_t, lwp_sema_t) that are shared between processes.
67  * The lwpchan cache is a hash table used to look up previously-computed
68  * lwpchan_t's by process virtual address.  We keep this cache because we
69  * believe that as_getmemid() is slow and we only need to call it once,
70  * then remember the results.  The hashing function is very simple, and
71  * assumes an even distribution of sync objects within the process's
72  * address space.  When hash chains become too long, the cache is resized
73  * on the fly.  The cache is freed when the process exits or execs.
74  */
75 typedef struct lwpchan_data {
76 	uint_t	lwpchan_bits;		/* number of bits */
77 	uint_t	lwpchan_size;		/* 1 << lwpchan_bits */
78 	uint_t	lwpchan_mask;		/* lwpchan_size - 1 */
79 	uint_t	lwpchan_entries;	/* number of entries in the cache */
80 	lwpchan_hashbucket_t *lwpchan_cache;
81 	struct lwpchan_data *lwpchan_next_data;
82 } lwpchan_data_t;
83 
84 /*
85  * exported functions
86  */
87 void lwpchan_delete_mapping(proc_t *, caddr_t start, caddr_t end);
88 void lwpchan_destroy_cache(int);
89 
90 #ifdef	__cplusplus
91 }
92 #endif
93 
94 #endif	/* _SYS_LCHAN_IMPL_H */
95