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