2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
34 * Mach Operating System
35 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
36 * All Rights Reserved.
38 * Permission to use, copy, modify and distribute this software and its
39 * documentation is hereby granted, provided that both the copyright
40 * notice and this permission notice appear in all copies of the
41 * software, derivative works or modified versions, and any portions
42 * thereof, and that both notices appear in supporting documentation.
44 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
45 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
46 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
48 * Carnegie Mellon requests users of this software to return to
50 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
51 * School of Computer Science
52 * Carnegie Mellon University
53 * Pittsburgh PA 15213-3890
55 * any improvements or extensions that they make and grant Carnegie Mellon
56 * the rights to redistribute these changes.
59 #include <mach_ldebug.h>
62 #include <mach/kern_return.h>
63 #include <mach/mach_host_server.h>
64 #include <mach_debug/lockgroup_info.h>
66 #include <kern/locks.h>
67 #include <kern/misc_protos.h>
68 #include <kern/kalloc.h>
69 #include <kern/thread.h>
70 #include <kern/processor.h>
71 #include <kern/sched_prim.h>
72 #include <kern/debug.h>
76 #include <sys/kdebug.h>
78 #define LCK_MTX_SLEEP_CODE 0
79 #define LCK_MTX_SLEEP_DEADLINE_CODE 1
80 #define LCK_MTX_LCK_WAIT_CODE 2
81 #define LCK_MTX_UNLCK_WAKEUP_CODE 3
84 static queue_head_t lck_grp_queue
;
85 static unsigned int lck_grp_cnt
;
87 decl_mutex_data(static,lck_grp_lock
)
89 lck_grp_attr_t LockDefaultGroupAttr
;
90 lck_grp_t LockCompatGroup
;
91 lck_attr_t LockDefaultLckAttr
;
94 * Routine: lck_mod_init
101 queue_init(&lck_grp_queue
);
102 mutex_init(&lck_grp_lock
, 0);
104 lck_grp_attr_setdefault( &LockDefaultGroupAttr
);
105 lck_grp_init( &LockCompatGroup
, "Compatibility APIs", LCK_GRP_ATTR_NULL
);
106 lck_attr_setdefault(&LockDefaultLckAttr
);
110 * Routine: lck_grp_attr_alloc_init
114 lck_grp_attr_alloc_init(
117 lck_grp_attr_t
*attr
;
119 if ((attr
= (lck_grp_attr_t
*)kalloc(sizeof(lck_grp_attr_t
))) != 0)
120 lck_grp_attr_setdefault(attr
);
127 * Routine: lck_grp_attr_setdefault
131 lck_grp_attr_setdefault(
132 lck_grp_attr_t
*attr
)
134 if (LcksOpts
& enaLkStat
)
135 attr
->grp_attr_val
= LCK_GRP_ATTR_STAT
;
137 attr
->grp_attr_val
= 0;
142 * Routine: lck_grp_attr_setstat
146 lck_grp_attr_setstat(
147 lck_grp_attr_t
*attr
)
149 (void)hw_atomic_or((uint32_t *)&attr
->grp_attr_val
, LCK_GRP_ATTR_STAT
);
154 * Routine: lck_grp_attr_free
159 lck_grp_attr_t
*attr
)
161 kfree(attr
, sizeof(lck_grp_attr_t
));
166 * Routine: lck_grp_alloc_init
171 const char* grp_name
,
172 lck_grp_attr_t
*attr
)
176 if ((grp
= (lck_grp_t
*)kalloc(sizeof(lck_grp_t
))) != 0)
177 lck_grp_init(grp
, grp_name
, attr
);
184 * Routine: lck_grp_init
190 const char* grp_name
,
191 lck_grp_attr_t
*attr
)
193 bzero((void *)grp
, sizeof(lck_grp_t
));
195 (void) strncpy(grp
->lck_grp_name
, grp_name
, LCK_GRP_MAX_NAME
);
197 if (attr
!= LCK_GRP_ATTR_NULL
)
198 grp
->lck_grp_attr
= attr
->grp_attr_val
;
199 else if (LcksOpts
& enaLkStat
)
200 grp
->lck_grp_attr
= LCK_GRP_ATTR_STAT
;
202 grp
->lck_grp_attr
= LCK_ATTR_NONE
;
204 grp
->lck_grp_refcnt
= 1;
206 mutex_lock(&lck_grp_lock
);
207 enqueue_tail(&lck_grp_queue
, (queue_entry_t
)grp
);
209 mutex_unlock(&lck_grp_lock
);
215 * Routine: lck_grp_free
222 mutex_lock(&lck_grp_lock
);
224 (void)remque((queue_entry_t
)grp
);
225 mutex_unlock(&lck_grp_lock
);
226 lck_grp_deallocate(grp
);
231 * Routine: lck_grp_reference
238 (void)hw_atomic_add((uint32_t *)(&grp
->lck_grp_refcnt
), 1);
243 * Routine: lck_grp_deallocate
250 if (hw_atomic_sub((uint32_t *)(&grp
->lck_grp_refcnt
), 1) == 0)
251 kfree(grp
, sizeof(lck_grp_t
));
255 * Routine: lck_grp_lckcnt_incr
263 unsigned int *lckcnt
;
267 lckcnt
= &grp
->lck_grp_spincnt
;
270 lckcnt
= &grp
->lck_grp_mtxcnt
;
273 lckcnt
= &grp
->lck_grp_rwcnt
;
276 return panic("lck_grp_lckcnt_incr(): invalid lock type: %d\n", lck_type
);
279 (void)hw_atomic_add((uint32_t *)lckcnt
, 1);
283 * Routine: lck_grp_lckcnt_decr
291 unsigned int *lckcnt
;
295 lckcnt
= &grp
->lck_grp_spincnt
;
298 lckcnt
= &grp
->lck_grp_mtxcnt
;
301 lckcnt
= &grp
->lck_grp_rwcnt
;
304 return panic("lck_grp_lckcnt_decr(): invalid lock type: %d\n", lck_type
);
307 (void)hw_atomic_sub((uint32_t *)lckcnt
, 1);
311 * Routine: lck_attr_alloc_init
320 if ((attr
= (lck_attr_t
*)kalloc(sizeof(lck_attr_t
))) != 0)
321 lck_attr_setdefault(attr
);
328 * Routine: lck_attr_setdefault
336 if (LcksOpts
& enaLkDeb
)
337 attr
->lck_attr_val
= LCK_ATTR_DEBUG
;
339 attr
->lck_attr_val
= LCK_ATTR_NONE
;
341 attr
->lck_attr_val
= LCK_ATTR_DEBUG
;
348 * Routine: lck_attr_setdebug
354 (void)hw_atomic_or((uint32_t *)&attr
->lck_attr_val
, LCK_ATTR_DEBUG
);
359 * Routine: lck_attr_rw_shared_priority
362 lck_attr_rw_shared_priority(
365 (void)hw_atomic_or((uint32_t *)&attr
->lck_attr_val
, LCK_ATTR_RW_SHARED_PRIORITY
);
370 * Routine: lck_attr_free
376 kfree(attr
, sizeof(lck_attr_t
));
381 * Routine: lck_spin_sleep
386 lck_sleep_action_t lck_sleep_action
,
388 wait_interrupt_t interruptible
)
392 if ((lck_sleep_action
& ~LCK_SLEEP_MASK
) != 0)
393 panic("Invalid lock sleep action %x\n", lck_sleep_action
);
395 res
= assert_wait(event
, interruptible
);
396 if (res
== THREAD_WAITING
) {
397 lck_spin_unlock(lck
);
398 res
= thread_block(THREAD_CONTINUE_NULL
);
399 if (!(lck_sleep_action
& LCK_SLEEP_UNLOCK
))
403 if (lck_sleep_action
& LCK_SLEEP_UNLOCK
)
404 lck_spin_unlock(lck
);
411 * Routine: lck_spin_sleep_deadline
414 lck_spin_sleep_deadline(
416 lck_sleep_action_t lck_sleep_action
,
418 wait_interrupt_t interruptible
,
423 if ((lck_sleep_action
& ~LCK_SLEEP_MASK
) != 0)
424 panic("Invalid lock sleep action %x\n", lck_sleep_action
);
426 res
= assert_wait_deadline(event
, interruptible
, deadline
);
427 if (res
== THREAD_WAITING
) {
428 lck_spin_unlock(lck
);
429 res
= thread_block(THREAD_CONTINUE_NULL
);
430 if (!(lck_sleep_action
& LCK_SLEEP_UNLOCK
))
434 if (lck_sleep_action
& LCK_SLEEP_UNLOCK
)
435 lck_spin_unlock(lck
);
442 * Routine: lck_mtx_sleep
447 lck_sleep_action_t lck_sleep_action
,
449 wait_interrupt_t interruptible
)
453 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_SLEEP_CODE
) | DBG_FUNC_START
,
454 (int)lck
, (int)lck_sleep_action
, (int)event
, (int)interruptible
, 0);
456 if ((lck_sleep_action
& ~LCK_SLEEP_MASK
) != 0)
457 panic("Invalid lock sleep action %x\n", lck_sleep_action
);
459 res
= assert_wait(event
, interruptible
);
460 if (res
== THREAD_WAITING
) {
462 res
= thread_block(THREAD_CONTINUE_NULL
);
463 if (!(lck_sleep_action
& LCK_SLEEP_UNLOCK
))
467 if (lck_sleep_action
& LCK_SLEEP_UNLOCK
)
470 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_SLEEP_CODE
) | DBG_FUNC_END
, (int)res
, 0, 0, 0, 0);
477 * Routine: lck_mtx_sleep_deadline
480 lck_mtx_sleep_deadline(
482 lck_sleep_action_t lck_sleep_action
,
484 wait_interrupt_t interruptible
,
489 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_SLEEP_DEADLINE_CODE
) | DBG_FUNC_START
,
490 (int)lck
, (int)lck_sleep_action
, (int)event
, (int)interruptible
, 0);
492 if ((lck_sleep_action
& ~LCK_SLEEP_MASK
) != 0)
493 panic("Invalid lock sleep action %x\n", lck_sleep_action
);
495 res
= assert_wait_deadline(event
, interruptible
, deadline
);
496 if (res
== THREAD_WAITING
) {
498 res
= thread_block(THREAD_CONTINUE_NULL
);
499 if (!(lck_sleep_action
& LCK_SLEEP_UNLOCK
))
503 if (lck_sleep_action
& LCK_SLEEP_UNLOCK
)
506 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_SLEEP_DEADLINE_CODE
) | DBG_FUNC_END
, (int)res
, 0, 0, 0, 0);
512 * Routine: lck_mtx_lock_wait
514 * Invoked in order to wait on contention.
516 * Called with the interlock locked and
517 * returns it unlocked.
524 thread_t self
= current_thread();
527 spl_t s
= splsched();
529 if (lck
->lck_mtx_tag
!= LCK_MTX_TAG_INDIRECT
)
532 mutex
= &lck
->lck_mtx_ptr
->lck_mtx
;
534 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_LCK_WAIT_CODE
) | DBG_FUNC_START
, (int)lck
, (int)holder
, 0, 0, 0);
536 priority
= self
->sched_pri
;
537 if (priority
< self
->priority
)
538 priority
= self
->priority
;
539 if (priority
> MINPRI_KERNEL
)
540 priority
= MINPRI_KERNEL
;
542 if (priority
< BASEPRI_DEFAULT
)
543 priority
= BASEPRI_DEFAULT
;
546 if (mutex
->lck_mtx_pri
== 0)
547 holder
->promotions
++;
548 if (holder
->priority
< MINPRI_KERNEL
) {
549 holder
->sched_mode
|= TH_MODE_PROMOTED
;
550 if ( mutex
->lck_mtx_pri
< priority
&&
551 holder
->sched_pri
< priority
) {
552 KERNEL_DEBUG_CONSTANT(
553 MACHDBG_CODE(DBG_MACH_SCHED
,MACH_PROMOTE
) | DBG_FUNC_NONE
,
554 holder
->sched_pri
, priority
, (int)holder
, (int)lck
, 0);
556 set_sched_pri(holder
, priority
);
559 thread_unlock(holder
);
562 if (mutex
->lck_mtx_pri
< priority
)
563 mutex
->lck_mtx_pri
= priority
;
564 if (self
->pending_promoter
[self
->pending_promoter_index
] == NULL
) {
565 self
->pending_promoter
[self
->pending_promoter_index
] = mutex
;
566 mutex
->lck_mtx_waiters
++;
569 if (self
->pending_promoter
[self
->pending_promoter_index
] != mutex
) {
570 self
->pending_promoter
[++self
->pending_promoter_index
] = mutex
;
571 mutex
->lck_mtx_waiters
++;
574 assert_wait((event_t
)(((unsigned int*)lck
)+((sizeof(lck_mtx_t
)-1)/sizeof(unsigned int))), THREAD_UNINT
);
575 lck_mtx_ilk_unlock(mutex
);
577 thread_block(THREAD_CONTINUE_NULL
);
579 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_LCK_WAIT_CODE
) | DBG_FUNC_END
, 0, 0, 0, 0, 0);
583 * Routine: lck_mtx_lock_acquire
585 * Invoked on acquiring the mutex when there is
588 * Returns the current number of waiters.
590 * Called with the interlock locked.
593 lck_mtx_lock_acquire(
596 thread_t thread
= current_thread();
599 if (lck
->lck_mtx_tag
!= LCK_MTX_TAG_INDIRECT
)
602 mutex
= &lck
->lck_mtx_ptr
->lck_mtx
;
604 if (thread
->pending_promoter
[thread
->pending_promoter_index
] == mutex
) {
605 thread
->pending_promoter
[thread
->pending_promoter_index
] = NULL
;
606 if (thread
->pending_promoter_index
> 0)
607 thread
->pending_promoter_index
--;
608 mutex
->lck_mtx_waiters
--;
611 if (mutex
->lck_mtx_waiters
> 0) {
612 integer_t priority
= mutex
->lck_mtx_pri
;
613 spl_t s
= splsched();
616 thread
->promotions
++;
617 if (thread
->priority
< MINPRI_KERNEL
) {
618 thread
->sched_mode
|= TH_MODE_PROMOTED
;
619 if (thread
->sched_pri
< priority
) {
620 KERNEL_DEBUG_CONSTANT(
621 MACHDBG_CODE(DBG_MACH_SCHED
,MACH_PROMOTE
) | DBG_FUNC_NONE
,
622 thread
->sched_pri
, priority
, 0, (int)lck
, 0);
624 set_sched_pri(thread
, priority
);
627 thread_unlock(thread
);
631 mutex
->lck_mtx_pri
= 0;
633 return (mutex
->lck_mtx_waiters
);
637 * Routine: lck_mtx_unlock_wakeup
639 * Invoked on unlock when there is contention.
641 * Called with the interlock locked.
644 lck_mtx_unlock_wakeup (
648 thread_t thread
= current_thread();
651 if (lck
->lck_mtx_tag
!= LCK_MTX_TAG_INDIRECT
)
654 mutex
= &lck
->lck_mtx_ptr
->lck_mtx
;
657 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_UNLCK_WAKEUP_CODE
) | DBG_FUNC_START
, (int)lck
, (int)holder
, 0, 0, 0);
659 if (thread
!= holder
)
660 panic("lck_mtx_unlock_wakeup: mutex %x holder %x\n", mutex
, holder
);
662 if (thread
->promotions
> 0) {
663 spl_t s
= splsched();
666 if ( --thread
->promotions
== 0 &&
667 (thread
->sched_mode
& TH_MODE_PROMOTED
) ) {
668 thread
->sched_mode
&= ~TH_MODE_PROMOTED
;
669 if (thread
->sched_mode
& TH_MODE_ISDEPRESSED
) {
670 KERNEL_DEBUG_CONSTANT(
671 MACHDBG_CODE(DBG_MACH_SCHED
,MACH_DEMOTE
) | DBG_FUNC_NONE
,
672 thread
->sched_pri
, DEPRESSPRI
, 0, (int)lck
, 0);
674 set_sched_pri(thread
, DEPRESSPRI
);
677 if (thread
->priority
< thread
->sched_pri
) {
678 KERNEL_DEBUG_CONSTANT(
679 MACHDBG_CODE(DBG_MACH_SCHED
,MACH_DEMOTE
) |
681 thread
->sched_pri
, thread
->priority
,
685 compute_priority(thread
, FALSE
);
688 thread_unlock(thread
);
691 assert(mutex
->lck_mtx_waiters
> 0);
692 thread_wakeup_one((event_t
)(((unsigned int*)lck
)+(sizeof(lck_mtx_t
)-1)/sizeof(unsigned int)));
694 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_UNLCK_WAKEUP_CODE
) | DBG_FUNC_END
, 0, 0, 0, 0, 0);
698 * Routine: mutex_pause
700 * Called by former callers of simple_lock_pause().
706 wait_result_t wait_result
;
708 wait_result
= assert_wait_timeout((event_t
)mutex_pause
, THREAD_UNINT
, 1, 1000*NSEC_PER_USEC
);
709 assert(wait_result
== THREAD_WAITING
);
711 wait_result
= thread_block(THREAD_CONTINUE_NULL
);
712 assert(wait_result
== THREAD_TIMED_OUT
);
716 * Routine: lck_rw_sleep
721 lck_sleep_action_t lck_sleep_action
,
723 wait_interrupt_t interruptible
)
726 lck_rw_type_t lck_rw_type
;
728 if ((lck_sleep_action
& ~LCK_SLEEP_MASK
) != 0)
729 panic("Invalid lock sleep action %x\n", lck_sleep_action
);
731 res
= assert_wait(event
, interruptible
);
732 if (res
== THREAD_WAITING
) {
733 lck_rw_type
= lck_rw_done(lck
);
734 res
= thread_block(THREAD_CONTINUE_NULL
);
735 if (!(lck_sleep_action
& LCK_SLEEP_UNLOCK
)) {
736 if (!(lck_sleep_action
& (LCK_SLEEP_SHARED
|LCK_SLEEP_EXCLUSIVE
)))
737 lck_rw_lock(lck
, lck_rw_type
);
738 else if (lck_sleep_action
& LCK_SLEEP_EXCLUSIVE
)
739 lck_rw_lock_exclusive(lck
);
741 lck_rw_lock_shared(lck
);
745 if (lck_sleep_action
& LCK_SLEEP_UNLOCK
)
746 (void)lck_rw_done(lck
);
753 * Routine: lck_rw_sleep_deadline
756 lck_rw_sleep_deadline(
758 lck_sleep_action_t lck_sleep_action
,
760 wait_interrupt_t interruptible
,
764 lck_rw_type_t lck_rw_type
;
766 if ((lck_sleep_action
& ~LCK_SLEEP_MASK
) != 0)
767 panic("Invalid lock sleep action %x\n", lck_sleep_action
);
769 res
= assert_wait_deadline(event
, interruptible
, deadline
);
770 if (res
== THREAD_WAITING
) {
771 lck_rw_type
= lck_rw_done(lck
);
772 res
= thread_block(THREAD_CONTINUE_NULL
);
773 if (!(lck_sleep_action
& LCK_SLEEP_UNLOCK
)) {
774 if (!(lck_sleep_action
& (LCK_SLEEP_SHARED
|LCK_SLEEP_EXCLUSIVE
)))
775 lck_rw_lock(lck
, lck_rw_type
);
776 else if (lck_sleep_action
& LCK_SLEEP_EXCLUSIVE
)
777 lck_rw_lock_exclusive(lck
);
779 lck_rw_lock_shared(lck
);
783 if (lck_sleep_action
& LCK_SLEEP_UNLOCK
)
784 (void)lck_rw_done(lck
);
792 lockgroup_info_array_t
*lockgroup_infop
,
793 mach_msg_type_number_t
*lockgroup_infoCntp
)
795 lockgroup_info_t
*lockgroup_info_base
;
796 lockgroup_info_t
*lockgroup_info
;
797 vm_offset_t lockgroup_info_addr
;
798 vm_size_t lockgroup_info_size
;
805 if (host
== HOST_NULL
)
806 return KERN_INVALID_HOST
;
808 mutex_lock(&lck_grp_lock
);
810 lockgroup_info_size
= round_page(lck_grp_cnt
* sizeof *lockgroup_info
);
811 kr
= kmem_alloc_pageable(ipc_kernel_map
,
812 &lockgroup_info_addr
, lockgroup_info_size
);
813 if (kr
!= KERN_SUCCESS
) {
814 mutex_unlock(&lck_grp_lock
);
818 lockgroup_info_base
= (lockgroup_info_t
*) lockgroup_info_addr
;
819 lck_grp
= (lck_grp_t
*)queue_first(&lck_grp_queue
);
820 lockgroup_info
= lockgroup_info_base
;
822 for (i
= 0; i
< lck_grp_cnt
; i
++) {
824 lockgroup_info
->lock_spin_cnt
= lck_grp
->lck_grp_spincnt
;
825 lockgroup_info
->lock_spin_util_cnt
= lck_grp
->lck_grp_stat
.lck_grp_spin_stat
.lck_grp_spin_util_cnt
;
826 lockgroup_info
->lock_spin_held_cnt
= lck_grp
->lck_grp_stat
.lck_grp_spin_stat
.lck_grp_spin_held_cnt
;
827 lockgroup_info
->lock_spin_miss_cnt
= lck_grp
->lck_grp_stat
.lck_grp_spin_stat
.lck_grp_spin_miss_cnt
;
828 lockgroup_info
->lock_spin_held_max
= lck_grp
->lck_grp_stat
.lck_grp_spin_stat
.lck_grp_spin_held_max
;
829 lockgroup_info
->lock_spin_held_cum
= lck_grp
->lck_grp_stat
.lck_grp_spin_stat
.lck_grp_spin_held_cum
;
831 lockgroup_info
->lock_mtx_cnt
= lck_grp
->lck_grp_mtxcnt
;
832 lockgroup_info
->lock_mtx_util_cnt
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_util_cnt
;
833 lockgroup_info
->lock_mtx_held_cnt
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_held_cnt
;
834 lockgroup_info
->lock_mtx_miss_cnt
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_miss_cnt
;
835 lockgroup_info
->lock_mtx_wait_cnt
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_wait_cnt
;
836 lockgroup_info
->lock_mtx_held_max
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_held_max
;
837 lockgroup_info
->lock_mtx_held_cum
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_held_cum
;
838 lockgroup_info
->lock_mtx_wait_max
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_wait_max
;
839 lockgroup_info
->lock_mtx_wait_cum
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_wait_cum
;
841 lockgroup_info
->lock_rw_cnt
= lck_grp
->lck_grp_rwcnt
;
842 lockgroup_info
->lock_rw_util_cnt
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_util_cnt
;
843 lockgroup_info
->lock_rw_held_cnt
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_held_cnt
;
844 lockgroup_info
->lock_rw_miss_cnt
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_miss_cnt
;
845 lockgroup_info
->lock_rw_wait_cnt
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_wait_cnt
;
846 lockgroup_info
->lock_rw_held_max
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_held_max
;
847 lockgroup_info
->lock_rw_held_cum
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_held_cum
;
848 lockgroup_info
->lock_rw_wait_max
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_wait_max
;
849 lockgroup_info
->lock_rw_wait_cum
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_wait_cum
;
851 (void) strncpy(lockgroup_info
->lockgroup_name
,lck_grp
->lck_grp_name
, LOCKGROUP_MAX_NAME
);
853 lck_grp
= (lck_grp_t
*)(queue_next((queue_entry_t
)(lck_grp
)));
857 *lockgroup_infoCntp
= lck_grp_cnt
;
858 mutex_unlock(&lck_grp_lock
);
860 used
= (*lockgroup_infoCntp
) * sizeof *lockgroup_info
;
862 if (used
!= lockgroup_info_size
)
863 bzero((char *) lockgroup_info
, lockgroup_info_size
- used
);
865 kr
= vm_map_copyin(ipc_kernel_map
, (vm_map_address_t
)lockgroup_info_addr
,
866 (vm_map_size_t
)lockgroup_info_size
, TRUE
, ©
);
867 assert(kr
== KERN_SUCCESS
);
869 *lockgroup_infop
= (lockgroup_info_t
*) copy
;
871 return(KERN_SUCCESS
);
875 * Compatibility module
878 extern lck_rw_t
*lock_alloc_EXT( boolean_t can_sleep
, unsigned short tag0
, unsigned short tag1
);
879 extern void lock_done_EXT(lck_rw_t
*lock
);
880 extern void lock_free_EXT(lck_rw_t
*lock
);
881 extern void lock_init_EXT(lck_rw_t
*lock
, boolean_t can_sleep
, unsigned short tag0
, unsigned short tag1
);
882 extern void lock_read_EXT(lck_rw_t
*lock
);
883 extern boolean_t
lock_read_to_write_EXT(lck_rw_t
*lock
);
884 extern void lock_write_EXT(lck_rw_t
*lock
);
885 extern void lock_write_to_read_EXT(lck_rw_t
*lock
);
886 extern wait_result_t
thread_sleep_lock_write_EXT(
887 event_t event
, lck_rw_t
*lock
, wait_interrupt_t interruptible
);
889 extern lck_mtx_t
*mutex_alloc_EXT(unsigned short tag
);
890 extern void mutex_free_EXT(lck_mtx_t
*mutex
);
891 extern void mutex_init_EXT(lck_mtx_t
*mutex
, unsigned short tag
);
892 extern void mutex_lock_EXT(lck_mtx_t
*mutex
);
893 extern boolean_t
mutex_try_EXT(lck_mtx_t
*mutex
);
894 extern void mutex_unlock_EXT(lck_mtx_t
*mutex
);
895 extern wait_result_t
thread_sleep_mutex_EXT(
896 event_t event
, lck_mtx_t
*mutex
, wait_interrupt_t interruptible
);
897 extern wait_result_t
thread_sleep_mutex_deadline_EXT(
898 event_t event
, lck_mtx_t
*mutex
, uint64_t deadline
, wait_interrupt_t interruptible
);
900 extern void usimple_lock_EXT(lck_spin_t
*lock
);
901 extern void usimple_lock_init_EXT(lck_spin_t
*lock
, unsigned short tag
);
902 extern unsigned int usimple_lock_try_EXT(lck_spin_t
*lock
);
903 extern void usimple_unlock_EXT(lck_spin_t
*lock
);
904 extern wait_result_t
thread_sleep_usimple_lock_EXT(event_t event
, lck_spin_t
*lock
, wait_interrupt_t interruptible
);
908 __unused boolean_t can_sleep
,
909 __unused
unsigned short tag0
,
910 __unused
unsigned short tag1
)
912 return( lck_rw_alloc_init( &LockCompatGroup
, LCK_ATTR_NULL
));
919 (void) lck_rw_done(lock
);
926 lck_rw_free(lock
, &LockCompatGroup
);
932 __unused boolean_t can_sleep
,
933 __unused
unsigned short tag0
,
934 __unused
unsigned short tag1
)
936 lck_rw_init(lock
, &LockCompatGroup
, LCK_ATTR_NULL
);
943 lck_rw_lock_shared( lock
);
947 lock_read_to_write_EXT(
950 return( lck_rw_lock_shared_to_exclusive(lock
));
957 lck_rw_lock_exclusive(lock
);
961 lock_write_to_read_EXT(
964 lck_rw_lock_exclusive_to_shared(lock
);
968 thread_sleep_lock_write_EXT(
971 wait_interrupt_t interruptible
)
973 return( lck_rw_sleep(lock
, LCK_SLEEP_EXCLUSIVE
, event
, interruptible
));
978 __unused
unsigned short tag
)
980 return(lck_mtx_alloc_init(&LockCompatGroup
, LCK_ATTR_NULL
));
987 lck_mtx_free(mutex
, &LockCompatGroup
);
993 __unused
unsigned short tag
)
995 lck_mtx_init(mutex
, &LockCompatGroup
, LCK_ATTR_NULL
);
1002 lck_mtx_lock(mutex
);
1009 return(lck_mtx_try_lock(mutex
));
1016 lck_mtx_unlock(mutex
);
1020 thread_sleep_mutex_EXT(
1023 wait_interrupt_t interruptible
)
1025 return( lck_mtx_sleep(mutex
, LCK_SLEEP_DEFAULT
, event
, interruptible
));
1029 thread_sleep_mutex_deadline_EXT(
1033 wait_interrupt_t interruptible
)
1035 return( lck_mtx_sleep_deadline(mutex
, LCK_SLEEP_DEFAULT
, event
, interruptible
, deadline
));
1042 lck_spin_lock(lock
);
1046 usimple_lock_init_EXT(
1048 __unused
unsigned short tag
)
1050 lck_spin_init(lock
, &LockCompatGroup
, LCK_ATTR_NULL
);
1054 usimple_lock_try_EXT(
1057 return(lck_spin_try_lock(lock
));
1064 lck_spin_unlock(lock
);
1068 thread_sleep_usimple_lock_EXT(
1071 wait_interrupt_t interruptible
)
1073 return( lck_spin_sleep(lock
, LCK_SLEEP_DEFAULT
, event
, interruptible
));