17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5daa03c95Sraf  * Common Development and Distribution License (the "License").
6daa03c95Sraf  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
21daa03c95Sraf 
227c478bd9Sstevel@tonic-gate /*
23*c242ec1bSRoger A. Faulkner  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef	_SYS_LCHAN_IMPL_H
287c478bd9Sstevel@tonic-gate #define	_SYS_LCHAN_IMPL_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
317c478bd9Sstevel@tonic-gate extern "C" {
327c478bd9Sstevel@tonic-gate #endif
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #define	LWPCHAN_CVPOOL	0
357c478bd9Sstevel@tonic-gate #define	LWPCHAN_MPPOOL	1
367c478bd9Sstevel@tonic-gate 
37daa03c95Sraf #define	LWPCHAN_INITIAL_BITS	2	/* initially: 4 hash buckets */
38daa03c95Sraf #define	LWPCHAN_MAX_BITS	16	/* finally: up to 64K hash buckets */
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate /*
417c478bd9Sstevel@tonic-gate  * An lwpchan entry translates a process-shared lwp sync object's
427c478bd9Sstevel@tonic-gate  * virtual address into its logical address, an lwpchan, previously
437c478bd9Sstevel@tonic-gate  * computed via as_getmemid().
447c478bd9Sstevel@tonic-gate  */
457c478bd9Sstevel@tonic-gate typedef struct lwpchan_entry {
467c478bd9Sstevel@tonic-gate 	caddr_t lwpchan_addr;		/* virtual address */
47*c242ec1bSRoger A. Faulkner 	caddr_t lwpchan_uaddr;		/* address of lock registration */
487c478bd9Sstevel@tonic-gate 	uint16_t lwpchan_type;		/* sync object type field */
497c478bd9Sstevel@tonic-gate 	uint16_t lwpchan_pool;		/* LWPCHAN_CVPOOL/LWPCHAN_MPPOOL */
507c478bd9Sstevel@tonic-gate 	lwpchan_t lwpchan_lwpchan;	/* unique logical address */
517c478bd9Sstevel@tonic-gate 	struct lwpchan_entry *lwpchan_next;	/* hash chain */
527c478bd9Sstevel@tonic-gate } lwpchan_entry_t;
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate /*
557c478bd9Sstevel@tonic-gate  * Hash bucket head.  The mutex protects the consistency of the hash chain.
567c478bd9Sstevel@tonic-gate  * Also, p->p_lcp cannot be changed while any one hash bucket lock is held.
577c478bd9Sstevel@tonic-gate  * (The resizing thread must acquire all of the hash bucket locks.)
587c478bd9Sstevel@tonic-gate  */
597c478bd9Sstevel@tonic-gate typedef struct lwpchan_hashbucket {
607c478bd9Sstevel@tonic-gate 	kmutex_t lwpchan_lock;
617c478bd9Sstevel@tonic-gate 	lwpchan_entry_t *lwpchan_chain;
627c478bd9Sstevel@tonic-gate } lwpchan_hashbucket_t;
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate /*
657c478bd9Sstevel@tonic-gate  * Each process maintains a cache of lwpchan translations for sync objects
667c478bd9Sstevel@tonic-gate  * (lwp_mutex_t, lwp_cond_t, lwp_sema_t) that are shared between processes.
677c478bd9Sstevel@tonic-gate  * The lwpchan cache is a hash table used to look up previously-computed
687c478bd9Sstevel@tonic-gate  * lwpchan_t's by process virtual address.  We keep this cache because we
697c478bd9Sstevel@tonic-gate  * believe that as_getmemid() is slow and we only need to call it once,
707c478bd9Sstevel@tonic-gate  * then remember the results.  The hashing function is very simple, and
717c478bd9Sstevel@tonic-gate  * assumes an even distribution of sync objects within the process's
727c478bd9Sstevel@tonic-gate  * address space.  When hash chains become too long, the cache is resized
737c478bd9Sstevel@tonic-gate  * on the fly.  The cache is freed when the process exits or execs.
747c478bd9Sstevel@tonic-gate  */
757c478bd9Sstevel@tonic-gate typedef struct lwpchan_data {
767c478bd9Sstevel@tonic-gate 	uint_t	lwpchan_bits;		/* number of bits */
777c478bd9Sstevel@tonic-gate 	uint_t	lwpchan_size;		/* 1 << lwpchan_bits */
787c478bd9Sstevel@tonic-gate 	uint_t	lwpchan_mask;		/* lwpchan_size - 1 */
797c478bd9Sstevel@tonic-gate 	uint_t	lwpchan_entries;	/* number of entries in the cache */
807c478bd9Sstevel@tonic-gate 	lwpchan_hashbucket_t *lwpchan_cache;
817c478bd9Sstevel@tonic-gate 	struct lwpchan_data *lwpchan_next_data;
827c478bd9Sstevel@tonic-gate } lwpchan_data_t;
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate /*
857c478bd9Sstevel@tonic-gate  * exported functions
867c478bd9Sstevel@tonic-gate  */
877c478bd9Sstevel@tonic-gate void lwpchan_delete_mapping(proc_t *, caddr_t start, caddr_t end);
887c478bd9Sstevel@tonic-gate void lwpchan_destroy_cache(int);
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
917c478bd9Sstevel@tonic-gate }
927c478bd9Sstevel@tonic-gate #endif
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate #endif	/* _SYS_LCHAN_IMPL_H */
95