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_free
365 kfree(attr
, sizeof(lck_attr_t
));
370 * Routine: lck_spin_sleep
375 lck_sleep_action_t lck_sleep_action
,
377 wait_interrupt_t interruptible
)
381 if ((lck_sleep_action
& ~LCK_SLEEP_MASK
) != 0)
382 panic("Invalid lock sleep action %x\n", lck_sleep_action
);
384 res
= assert_wait(event
, interruptible
);
385 if (res
== THREAD_WAITING
) {
386 lck_spin_unlock(lck
);
387 res
= thread_block(THREAD_CONTINUE_NULL
);
388 if (!(lck_sleep_action
& LCK_SLEEP_UNLOCK
))
392 if (lck_sleep_action
& LCK_SLEEP_UNLOCK
)
393 lck_spin_unlock(lck
);
400 * Routine: lck_spin_sleep_deadline
403 lck_spin_sleep_deadline(
405 lck_sleep_action_t lck_sleep_action
,
407 wait_interrupt_t interruptible
,
412 if ((lck_sleep_action
& ~LCK_SLEEP_MASK
) != 0)
413 panic("Invalid lock sleep action %x\n", lck_sleep_action
);
415 res
= assert_wait_deadline(event
, interruptible
, deadline
);
416 if (res
== THREAD_WAITING
) {
417 lck_spin_unlock(lck
);
418 res
= thread_block(THREAD_CONTINUE_NULL
);
419 if (!(lck_sleep_action
& LCK_SLEEP_UNLOCK
))
423 if (lck_sleep_action
& LCK_SLEEP_UNLOCK
)
424 lck_spin_unlock(lck
);
431 * Routine: lck_mtx_sleep
436 lck_sleep_action_t lck_sleep_action
,
438 wait_interrupt_t interruptible
)
442 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_SLEEP_CODE
) | DBG_FUNC_START
,
443 (int)lck
, (int)lck_sleep_action
, (int)event
, (int)interruptible
, 0);
445 if ((lck_sleep_action
& ~LCK_SLEEP_MASK
) != 0)
446 panic("Invalid lock sleep action %x\n", lck_sleep_action
);
448 res
= assert_wait(event
, interruptible
);
449 if (res
== THREAD_WAITING
) {
451 res
= thread_block(THREAD_CONTINUE_NULL
);
452 if (!(lck_sleep_action
& LCK_SLEEP_UNLOCK
))
456 if (lck_sleep_action
& LCK_SLEEP_UNLOCK
)
459 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_SLEEP_CODE
) | DBG_FUNC_END
, (int)res
, 0, 0, 0, 0);
466 * Routine: lck_mtx_sleep_deadline
469 lck_mtx_sleep_deadline(
471 lck_sleep_action_t lck_sleep_action
,
473 wait_interrupt_t interruptible
,
478 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_SLEEP_DEADLINE_CODE
) | DBG_FUNC_START
,
479 (int)lck
, (int)lck_sleep_action
, (int)event
, (int)interruptible
, 0);
481 if ((lck_sleep_action
& ~LCK_SLEEP_MASK
) != 0)
482 panic("Invalid lock sleep action %x\n", lck_sleep_action
);
484 res
= assert_wait_deadline(event
, interruptible
, deadline
);
485 if (res
== THREAD_WAITING
) {
487 res
= thread_block(THREAD_CONTINUE_NULL
);
488 if (!(lck_sleep_action
& LCK_SLEEP_UNLOCK
))
492 if (lck_sleep_action
& LCK_SLEEP_UNLOCK
)
495 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_SLEEP_DEADLINE_CODE
) | DBG_FUNC_END
, (int)res
, 0, 0, 0, 0);
501 * Routine: lck_mtx_lock_wait
503 * Invoked in order to wait on contention.
505 * Called with the interlock locked and
506 * returns it unlocked.
513 thread_t self
= current_thread();
516 spl_t s
= splsched();
518 if (lck
->lck_mtx_tag
!= LCK_MTX_TAG_INDIRECT
)
521 mutex
= &lck
->lck_mtx_ptr
->lck_mtx
;
523 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_LCK_WAIT_CODE
) | DBG_FUNC_START
, (int)lck
, (int)holder
, 0, 0, 0);
525 priority
= self
->sched_pri
;
526 if (priority
< self
->priority
)
527 priority
= self
->priority
;
528 if (priority
> MINPRI_KERNEL
)
529 priority
= MINPRI_KERNEL
;
531 if (priority
< BASEPRI_DEFAULT
)
532 priority
= BASEPRI_DEFAULT
;
535 if (mutex
->lck_mtx_pri
== 0)
536 holder
->promotions
++;
537 if (holder
->priority
< MINPRI_KERNEL
) {
538 holder
->sched_mode
|= TH_MODE_PROMOTED
;
539 if ( mutex
->lck_mtx_pri
< priority
&&
540 holder
->sched_pri
< priority
) {
541 KERNEL_DEBUG_CONSTANT(
542 MACHDBG_CODE(DBG_MACH_SCHED
,MACH_PROMOTE
) | DBG_FUNC_NONE
,
543 holder
->sched_pri
, priority
, (int)holder
, (int)lck
, 0);
545 set_sched_pri(holder
, priority
);
548 thread_unlock(holder
);
551 if (mutex
->lck_mtx_pri
< priority
)
552 mutex
->lck_mtx_pri
= priority
;
553 if (self
->pending_promoter
[self
->pending_promoter_index
] == NULL
) {
554 self
->pending_promoter
[self
->pending_promoter_index
] = mutex
;
555 mutex
->lck_mtx_waiters
++;
558 if (self
->pending_promoter
[self
->pending_promoter_index
] != mutex
) {
559 self
->pending_promoter
[++self
->pending_promoter_index
] = mutex
;
560 mutex
->lck_mtx_waiters
++;
563 assert_wait((event_t
)(((unsigned int*)lck
)+((sizeof(lck_mtx_t
)-1)/sizeof(unsigned int))), THREAD_UNINT
);
564 lck_mtx_ilk_unlock(mutex
);
566 thread_block(THREAD_CONTINUE_NULL
);
568 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_LCK_WAIT_CODE
) | DBG_FUNC_END
, 0, 0, 0, 0, 0);
572 * Routine: lck_mtx_lock_acquire
574 * Invoked on acquiring the mutex when there is
577 * Returns the current number of waiters.
579 * Called with the interlock locked.
582 lck_mtx_lock_acquire(
585 thread_t thread
= current_thread();
588 if (lck
->lck_mtx_tag
!= LCK_MTX_TAG_INDIRECT
)
591 mutex
= &lck
->lck_mtx_ptr
->lck_mtx
;
593 if (thread
->pending_promoter
[thread
->pending_promoter_index
] == mutex
) {
594 thread
->pending_promoter
[thread
->pending_promoter_index
] = NULL
;
595 if (thread
->pending_promoter_index
> 0)
596 thread
->pending_promoter_index
--;
597 mutex
->lck_mtx_waiters
--;
600 if (mutex
->lck_mtx_waiters
> 0) {
601 integer_t priority
= mutex
->lck_mtx_pri
;
602 spl_t s
= splsched();
605 thread
->promotions
++;
606 if (thread
->priority
< MINPRI_KERNEL
) {
607 thread
->sched_mode
|= TH_MODE_PROMOTED
;
608 if (thread
->sched_pri
< priority
) {
609 KERNEL_DEBUG_CONSTANT(
610 MACHDBG_CODE(DBG_MACH_SCHED
,MACH_PROMOTE
) | DBG_FUNC_NONE
,
611 thread
->sched_pri
, priority
, 0, (int)lck
, 0);
613 set_sched_pri(thread
, priority
);
616 thread_unlock(thread
);
620 mutex
->lck_mtx_pri
= 0;
622 return (mutex
->lck_mtx_waiters
);
626 * Routine: lck_mtx_unlock_wakeup
628 * Invoked on unlock when there is contention.
630 * Called with the interlock locked.
633 lck_mtx_unlock_wakeup (
637 thread_t thread
= current_thread();
640 if (lck
->lck_mtx_tag
!= LCK_MTX_TAG_INDIRECT
)
643 mutex
= &lck
->lck_mtx_ptr
->lck_mtx
;
646 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_UNLCK_WAKEUP_CODE
) | DBG_FUNC_START
, (int)lck
, (int)holder
, 0, 0, 0);
648 if (thread
!= holder
)
649 panic("lck_mtx_unlock_wakeup: mutex %x holder %x\n", mutex
, holder
);
651 if (thread
->promotions
> 0) {
652 spl_t s
= splsched();
655 if ( --thread
->promotions
== 0 &&
656 (thread
->sched_mode
& TH_MODE_PROMOTED
) ) {
657 thread
->sched_mode
&= ~TH_MODE_PROMOTED
;
658 if (thread
->sched_mode
& TH_MODE_ISDEPRESSED
) {
659 KERNEL_DEBUG_CONSTANT(
660 MACHDBG_CODE(DBG_MACH_SCHED
,MACH_DEMOTE
) | DBG_FUNC_NONE
,
661 thread
->sched_pri
, DEPRESSPRI
, 0, (int)lck
, 0);
663 set_sched_pri(thread
, DEPRESSPRI
);
666 if (thread
->priority
< thread
->sched_pri
) {
667 KERNEL_DEBUG_CONSTANT(
668 MACHDBG_CODE(DBG_MACH_SCHED
,MACH_DEMOTE
) |
670 thread
->sched_pri
, thread
->priority
,
674 compute_priority(thread
, FALSE
);
677 thread_unlock(thread
);
680 assert(mutex
->lck_mtx_waiters
> 0);
681 thread_wakeup_one((event_t
)(((unsigned int*)lck
)+(sizeof(lck_mtx_t
)-1)/sizeof(unsigned int)));
683 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_UNLCK_WAKEUP_CODE
) | DBG_FUNC_END
, 0, 0, 0, 0, 0);
687 * Routine: mutex_pause
689 * Called by former callers of simple_lock_pause().
695 wait_result_t wait_result
;
697 wait_result
= assert_wait_timeout((event_t
)mutex_pause
, THREAD_UNINT
, 1, 1000*NSEC_PER_USEC
);
698 assert(wait_result
== THREAD_WAITING
);
700 wait_result
= thread_block(THREAD_CONTINUE_NULL
);
701 assert(wait_result
== THREAD_TIMED_OUT
);
705 * Routine: lck_rw_sleep
710 lck_sleep_action_t lck_sleep_action
,
712 wait_interrupt_t interruptible
)
715 lck_rw_type_t lck_rw_type
;
717 if ((lck_sleep_action
& ~LCK_SLEEP_MASK
) != 0)
718 panic("Invalid lock sleep action %x\n", lck_sleep_action
);
720 res
= assert_wait(event
, interruptible
);
721 if (res
== THREAD_WAITING
) {
722 lck_rw_type
= lck_rw_done(lck
);
723 res
= thread_block(THREAD_CONTINUE_NULL
);
724 if (!(lck_sleep_action
& LCK_SLEEP_UNLOCK
)) {
725 if (!(lck_sleep_action
& (LCK_SLEEP_SHARED
|LCK_SLEEP_EXCLUSIVE
)))
726 lck_rw_lock(lck
, lck_rw_type
);
727 else if (lck_sleep_action
& LCK_SLEEP_EXCLUSIVE
)
728 lck_rw_lock_exclusive(lck
);
730 lck_rw_lock_shared(lck
);
734 if (lck_sleep_action
& LCK_SLEEP_UNLOCK
)
735 (void)lck_rw_done(lck
);
742 * Routine: lck_rw_sleep_deadline
745 lck_rw_sleep_deadline(
747 lck_sleep_action_t lck_sleep_action
,
749 wait_interrupt_t interruptible
,
753 lck_rw_type_t lck_rw_type
;
755 if ((lck_sleep_action
& ~LCK_SLEEP_MASK
) != 0)
756 panic("Invalid lock sleep action %x\n", lck_sleep_action
);
758 res
= assert_wait_deadline(event
, interruptible
, deadline
);
759 if (res
== THREAD_WAITING
) {
760 lck_rw_type
= lck_rw_done(lck
);
761 res
= thread_block(THREAD_CONTINUE_NULL
);
762 if (!(lck_sleep_action
& LCK_SLEEP_UNLOCK
)) {
763 if (!(lck_sleep_action
& (LCK_SLEEP_SHARED
|LCK_SLEEP_EXCLUSIVE
)))
764 lck_rw_lock(lck
, lck_rw_type
);
765 else if (lck_sleep_action
& LCK_SLEEP_EXCLUSIVE
)
766 lck_rw_lock_exclusive(lck
);
768 lck_rw_lock_shared(lck
);
772 if (lck_sleep_action
& LCK_SLEEP_UNLOCK
)
773 (void)lck_rw_done(lck
);
781 lockgroup_info_array_t
*lockgroup_infop
,
782 mach_msg_type_number_t
*lockgroup_infoCntp
)
784 lockgroup_info_t
*lockgroup_info_base
;
785 lockgroup_info_t
*lockgroup_info
;
786 vm_offset_t lockgroup_info_addr
;
787 vm_size_t lockgroup_info_size
;
794 if (host
== HOST_NULL
)
795 return KERN_INVALID_HOST
;
797 mutex_lock(&lck_grp_lock
);
799 lockgroup_info_size
= round_page(lck_grp_cnt
* sizeof *lockgroup_info
);
800 kr
= kmem_alloc_pageable(ipc_kernel_map
,
801 &lockgroup_info_addr
, lockgroup_info_size
);
802 if (kr
!= KERN_SUCCESS
) {
803 mutex_unlock(&lck_grp_lock
);
807 lockgroup_info_base
= (lockgroup_info_t
*) lockgroup_info_addr
;
808 lck_grp
= (lck_grp_t
*)queue_first(&lck_grp_queue
);
809 lockgroup_info
= lockgroup_info_base
;
811 for (i
= 0; i
< lck_grp_cnt
; i
++) {
813 lockgroup_info
->lock_spin_cnt
= lck_grp
->lck_grp_spincnt
;
814 lockgroup_info
->lock_spin_util_cnt
= lck_grp
->lck_grp_stat
.lck_grp_spin_stat
.lck_grp_spin_util_cnt
;
815 lockgroup_info
->lock_spin_held_cnt
= lck_grp
->lck_grp_stat
.lck_grp_spin_stat
.lck_grp_spin_held_cnt
;
816 lockgroup_info
->lock_spin_miss_cnt
= lck_grp
->lck_grp_stat
.lck_grp_spin_stat
.lck_grp_spin_miss_cnt
;
817 lockgroup_info
->lock_spin_held_max
= lck_grp
->lck_grp_stat
.lck_grp_spin_stat
.lck_grp_spin_held_max
;
818 lockgroup_info
->lock_spin_held_cum
= lck_grp
->lck_grp_stat
.lck_grp_spin_stat
.lck_grp_spin_held_cum
;
820 lockgroup_info
->lock_mtx_cnt
= lck_grp
->lck_grp_mtxcnt
;
821 lockgroup_info
->lock_mtx_util_cnt
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_util_cnt
;
822 lockgroup_info
->lock_mtx_held_cnt
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_held_cnt
;
823 lockgroup_info
->lock_mtx_miss_cnt
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_miss_cnt
;
824 lockgroup_info
->lock_mtx_wait_cnt
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_wait_cnt
;
825 lockgroup_info
->lock_mtx_held_max
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_held_max
;
826 lockgroup_info
->lock_mtx_held_cum
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_held_cum
;
827 lockgroup_info
->lock_mtx_wait_max
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_wait_max
;
828 lockgroup_info
->lock_mtx_wait_cum
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_wait_cum
;
830 lockgroup_info
->lock_rw_cnt
= lck_grp
->lck_grp_rwcnt
;
831 lockgroup_info
->lock_rw_util_cnt
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_util_cnt
;
832 lockgroup_info
->lock_rw_held_cnt
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_held_cnt
;
833 lockgroup_info
->lock_rw_miss_cnt
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_miss_cnt
;
834 lockgroup_info
->lock_rw_wait_cnt
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_wait_cnt
;
835 lockgroup_info
->lock_rw_held_max
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_held_max
;
836 lockgroup_info
->lock_rw_held_cum
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_held_cum
;
837 lockgroup_info
->lock_rw_wait_max
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_wait_max
;
838 lockgroup_info
->lock_rw_wait_cum
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_wait_cum
;
840 (void) strncpy(lockgroup_info
->lockgroup_name
,lck_grp
->lck_grp_name
, LOCKGROUP_MAX_NAME
);
842 lck_grp
= (lck_grp_t
*)(queue_next((queue_entry_t
)(lck_grp
)));
846 *lockgroup_infoCntp
= lck_grp_cnt
;
847 mutex_unlock(&lck_grp_lock
);
849 used
= (*lockgroup_infoCntp
) * sizeof *lockgroup_info
;
851 if (used
!= lockgroup_info_size
)
852 bzero((char *) lockgroup_info
, lockgroup_info_size
- used
);
854 kr
= vm_map_copyin(ipc_kernel_map
, (vm_map_address_t
)lockgroup_info_addr
,
855 (vm_map_size_t
)lockgroup_info_size
, TRUE
, ©
);
856 assert(kr
== KERN_SUCCESS
);
858 *lockgroup_infop
= (lockgroup_info_t
*) copy
;
860 return(KERN_SUCCESS
);
864 * Compatibility module
867 extern lck_rw_t
*lock_alloc_EXT( boolean_t can_sleep
, unsigned short tag0
, unsigned short tag1
);
868 extern void lock_done_EXT(lck_rw_t
*lock
);
869 extern void lock_free_EXT(lck_rw_t
*lock
);
870 extern void lock_init_EXT(lck_rw_t
*lock
, boolean_t can_sleep
, unsigned short tag0
, unsigned short tag1
);
871 extern void lock_read_EXT(lck_rw_t
*lock
);
872 extern boolean_t
lock_read_to_write_EXT(lck_rw_t
*lock
);
873 extern void lock_write_EXT(lck_rw_t
*lock
);
874 extern void lock_write_to_read_EXT(lck_rw_t
*lock
);
875 extern wait_result_t
thread_sleep_lock_write_EXT(
876 event_t event
, lck_rw_t
*lock
, wait_interrupt_t interruptible
);
878 extern lck_mtx_t
*mutex_alloc_EXT(unsigned short tag
);
879 extern void mutex_free_EXT(lck_mtx_t
*mutex
);
880 extern void mutex_init_EXT(lck_mtx_t
*mutex
, unsigned short tag
);
881 extern void mutex_lock_EXT(lck_mtx_t
*mutex
);
882 extern boolean_t
mutex_try_EXT(lck_mtx_t
*mutex
);
883 extern void mutex_unlock_EXT(lck_mtx_t
*mutex
);
884 extern wait_result_t
thread_sleep_mutex_EXT(
885 event_t event
, lck_mtx_t
*mutex
, wait_interrupt_t interruptible
);
886 extern wait_result_t
thread_sleep_mutex_deadline_EXT(
887 event_t event
, lck_mtx_t
*mutex
, uint64_t deadline
, wait_interrupt_t interruptible
);
889 extern void usimple_lock_EXT(lck_spin_t
*lock
);
890 extern void usimple_lock_init_EXT(lck_spin_t
*lock
, unsigned short tag
);
891 extern unsigned int usimple_lock_try_EXT(lck_spin_t
*lock
);
892 extern void usimple_unlock_EXT(lck_spin_t
*lock
);
893 extern wait_result_t
thread_sleep_usimple_lock_EXT(event_t event
, lck_spin_t
*lock
, wait_interrupt_t interruptible
);
897 __unused boolean_t can_sleep
,
898 __unused
unsigned short tag0
,
899 __unused
unsigned short tag1
)
901 return( lck_rw_alloc_init( &LockCompatGroup
, LCK_ATTR_NULL
));
908 (void) lck_rw_done(lock
);
915 lck_rw_free(lock
, &LockCompatGroup
);
921 __unused boolean_t can_sleep
,
922 __unused
unsigned short tag0
,
923 __unused
unsigned short tag1
)
925 lck_rw_init(lock
, &LockCompatGroup
, LCK_ATTR_NULL
);
932 lck_rw_lock_shared( lock
);
936 lock_read_to_write_EXT(
939 return( lck_rw_lock_shared_to_exclusive(lock
));
946 lck_rw_lock_exclusive(lock
);
950 lock_write_to_read_EXT(
953 lck_rw_lock_exclusive_to_shared(lock
);
957 thread_sleep_lock_write_EXT(
960 wait_interrupt_t interruptible
)
962 return( lck_rw_sleep(lock
, LCK_SLEEP_EXCLUSIVE
, event
, interruptible
));
967 __unused
unsigned short tag
)
969 return(lck_mtx_alloc_init(&LockCompatGroup
, LCK_ATTR_NULL
));
976 lck_mtx_free(mutex
, &LockCompatGroup
);
982 __unused
unsigned short tag
)
984 lck_mtx_init(mutex
, &LockCompatGroup
, LCK_ATTR_NULL
);
998 return(lck_mtx_try_lock(mutex
));
1005 lck_mtx_unlock(mutex
);
1009 thread_sleep_mutex_EXT(
1012 wait_interrupt_t interruptible
)
1014 return( lck_mtx_sleep(mutex
, LCK_SLEEP_DEFAULT
, event
, interruptible
));
1018 thread_sleep_mutex_deadline_EXT(
1022 wait_interrupt_t interruptible
)
1024 return( lck_mtx_sleep_deadline(mutex
, LCK_SLEEP_DEFAULT
, event
, interruptible
, deadline
));
1031 lck_spin_lock(lock
);
1035 usimple_lock_init_EXT(
1037 __unused
unsigned short tag
)
1039 lck_spin_init(lock
, &LockCompatGroup
, LCK_ATTR_NULL
);
1043 usimple_lock_try_EXT(
1046 lck_spin_try_lock(lock
);
1053 lck_spin_unlock(lock
);
1057 thread_sleep_usimple_lock_EXT(
1060 wait_interrupt_t interruptible
)
1062 return( lck_spin_sleep(lock
, LCK_SLEEP_DEFAULT
, event
, interruptible
));