xref: /onnv-gate/usr/src/uts/common/sys/lwpchan_impl.h (revision 7063:18df916522d6)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7063Sraf  * Common Development and Distribution License (the "License").
6*7063Sraf  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
21*7063Sraf 
220Sstevel@tonic-gate /*
23*7063Sraf  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #ifndef	_SYS_LCHAN_IMPL_H
280Sstevel@tonic-gate #define	_SYS_LCHAN_IMPL_H
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #ifdef	__cplusplus
330Sstevel@tonic-gate extern "C" {
340Sstevel@tonic-gate #endif
350Sstevel@tonic-gate 
360Sstevel@tonic-gate #define	LWPCHAN_CVPOOL	0
370Sstevel@tonic-gate #define	LWPCHAN_MPPOOL	1
380Sstevel@tonic-gate 
39*7063Sraf #define	LWPCHAN_INITIAL_BITS	2	/* initially: 4 hash buckets */
40*7063Sraf #define	LWPCHAN_MAX_BITS	16	/* finally: up to 64K hash buckets */
410Sstevel@tonic-gate 
420Sstevel@tonic-gate /*
430Sstevel@tonic-gate  * An lwpchan entry translates a process-shared lwp sync object's
440Sstevel@tonic-gate  * virtual address into its logical address, an lwpchan, previously
450Sstevel@tonic-gate  * computed via as_getmemid().
460Sstevel@tonic-gate  */
470Sstevel@tonic-gate typedef struct lwpchan_entry {
480Sstevel@tonic-gate 	caddr_t lwpchan_addr;		/* virtual address */
490Sstevel@tonic-gate 	uint16_t lwpchan_type;		/* sync object type field */
500Sstevel@tonic-gate 	uint16_t lwpchan_pool;		/* LWPCHAN_CVPOOL/LWPCHAN_MPPOOL */
510Sstevel@tonic-gate 	lwpchan_t lwpchan_lwpchan;	/* unique logical address */
520Sstevel@tonic-gate 	struct lwpchan_entry *lwpchan_next;	/* hash chain */
530Sstevel@tonic-gate } lwpchan_entry_t;
540Sstevel@tonic-gate 
550Sstevel@tonic-gate /*
560Sstevel@tonic-gate  * Hash bucket head.  The mutex protects the consistency of the hash chain.
570Sstevel@tonic-gate  * Also, p->p_lcp cannot be changed while any one hash bucket lock is held.
580Sstevel@tonic-gate  * (The resizing thread must acquire all of the hash bucket locks.)
590Sstevel@tonic-gate  */
600Sstevel@tonic-gate typedef struct lwpchan_hashbucket {
610Sstevel@tonic-gate 	kmutex_t lwpchan_lock;
620Sstevel@tonic-gate 	lwpchan_entry_t *lwpchan_chain;
630Sstevel@tonic-gate } lwpchan_hashbucket_t;
640Sstevel@tonic-gate 
650Sstevel@tonic-gate /*
660Sstevel@tonic-gate  * Each process maintains a cache of lwpchan translations for sync objects
670Sstevel@tonic-gate  * (lwp_mutex_t, lwp_cond_t, lwp_sema_t) that are shared between processes.
680Sstevel@tonic-gate  * The lwpchan cache is a hash table used to look up previously-computed
690Sstevel@tonic-gate  * lwpchan_t's by process virtual address.  We keep this cache because we
700Sstevel@tonic-gate  * believe that as_getmemid() is slow and we only need to call it once,
710Sstevel@tonic-gate  * then remember the results.  The hashing function is very simple, and
720Sstevel@tonic-gate  * assumes an even distribution of sync objects within the process's
730Sstevel@tonic-gate  * address space.  When hash chains become too long, the cache is resized
740Sstevel@tonic-gate  * on the fly.  The cache is freed when the process exits or execs.
750Sstevel@tonic-gate  */
760Sstevel@tonic-gate typedef struct lwpchan_data {
770Sstevel@tonic-gate 	uint_t	lwpchan_bits;		/* number of bits */
780Sstevel@tonic-gate 	uint_t	lwpchan_size;		/* 1 << lwpchan_bits */
790Sstevel@tonic-gate 	uint_t	lwpchan_mask;		/* lwpchan_size - 1 */
800Sstevel@tonic-gate 	uint_t	lwpchan_entries;	/* number of entries in the cache */
810Sstevel@tonic-gate 	lwpchan_hashbucket_t *lwpchan_cache;
820Sstevel@tonic-gate 	struct lwpchan_data *lwpchan_next_data;
830Sstevel@tonic-gate } lwpchan_data_t;
840Sstevel@tonic-gate 
850Sstevel@tonic-gate /*
860Sstevel@tonic-gate  * exported functions
870Sstevel@tonic-gate  */
880Sstevel@tonic-gate void lwpchan_delete_mapping(proc_t *, caddr_t start, caddr_t end);
890Sstevel@tonic-gate void lwpchan_destroy_cache(int);
900Sstevel@tonic-gate 
910Sstevel@tonic-gate #ifdef	__cplusplus
920Sstevel@tonic-gate }
930Sstevel@tonic-gate #endif
940Sstevel@tonic-gate 
950Sstevel@tonic-gate #endif	/* _SYS_LCHAN_IMPL_H */
96