2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_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 License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
34 * All Rights Reserved.
36 * Permission to use, copy, modify and distribute this software and its
37 * documentation is hereby granted, provided that both the copyright
38 * notice and this permission notice appear in all copies of the
39 * software, derivative works or modified versions, and any portions
40 * thereof, and that both notices appear in supporting documentation.
42 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
43 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
44 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
46 * Carnegie Mellon requests users of this software to return to
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
57 #include <mach_ldebug.h>
60 #include <mach/kern_return.h>
61 #include <mach/mach_host_server.h>
62 #include <mach_debug/lockgroup_info.h>
64 #include <kern/locks.h>
65 #include <kern/misc_protos.h>
66 #include <kern/kalloc.h>
67 #include <kern/thread.h>
68 #include <kern/processor.h>
69 #include <kern/sched_prim.h>
70 #include <kern/debug.h>
74 #include <sys/kdebug.h>
76 #define LCK_MTX_SLEEP_CODE 0
77 #define LCK_MTX_SLEEP_DEADLINE_CODE 1
78 #define LCK_MTX_LCK_WAIT_CODE 2
79 #define LCK_MTX_UNLCK_WAKEUP_CODE 3
82 static queue_head_t lck_grp_queue
;
83 static unsigned int lck_grp_cnt
;
85 decl_mutex_data(static,lck_grp_lock
)
87 lck_grp_attr_t LockDefaultGroupAttr
;
88 lck_grp_t LockCompatGroup
;
89 lck_attr_t LockDefaultLckAttr
;
92 * Routine: lck_mod_init
99 queue_init(&lck_grp_queue
);
100 mutex_init(&lck_grp_lock
, 0);
102 lck_grp_attr_setdefault( &LockDefaultGroupAttr
);
103 lck_grp_init( &LockCompatGroup
, "Compatibility APIs", LCK_GRP_ATTR_NULL
);
104 lck_attr_setdefault(&LockDefaultLckAttr
);
108 * Routine: lck_grp_attr_alloc_init
112 lck_grp_attr_alloc_init(
115 lck_grp_attr_t
*attr
;
117 if ((attr
= (lck_grp_attr_t
*)kalloc(sizeof(lck_grp_attr_t
))) != 0)
118 lck_grp_attr_setdefault(attr
);
125 * Routine: lck_grp_attr_setdefault
129 lck_grp_attr_setdefault(
130 lck_grp_attr_t
*attr
)
132 if (LcksOpts
& enaLkStat
)
133 attr
->grp_attr_val
= LCK_GRP_ATTR_STAT
;
135 attr
->grp_attr_val
= 0;
140 * Routine: lck_grp_attr_setstat
144 lck_grp_attr_setstat(
145 lck_grp_attr_t
*attr
)
147 (void)hw_atomic_or((uint32_t *)&attr
->grp_attr_val
, LCK_GRP_ATTR_STAT
);
152 * Routine: lck_grp_attr_free
157 lck_grp_attr_t
*attr
)
159 kfree(attr
, sizeof(lck_grp_attr_t
));
164 * Routine: lck_grp_alloc_init
169 const char* grp_name
,
170 lck_grp_attr_t
*attr
)
174 if ((grp
= (lck_grp_t
*)kalloc(sizeof(lck_grp_t
))) != 0)
175 lck_grp_init(grp
, grp_name
, attr
);
182 * Routine: lck_grp_init
188 const char* grp_name
,
189 lck_grp_attr_t
*attr
)
191 bzero((void *)grp
, sizeof(lck_grp_t
));
193 (void) strncpy(grp
->lck_grp_name
, grp_name
, LCK_GRP_MAX_NAME
);
195 if (attr
!= LCK_GRP_ATTR_NULL
)
196 grp
->lck_grp_attr
= attr
->grp_attr_val
;
197 else if (LcksOpts
& enaLkStat
)
198 grp
->lck_grp_attr
= LCK_GRP_ATTR_STAT
;
200 grp
->lck_grp_attr
= LCK_ATTR_NONE
;
202 grp
->lck_grp_refcnt
= 1;
204 mutex_lock(&lck_grp_lock
);
205 enqueue_tail(&lck_grp_queue
, (queue_entry_t
)grp
);
207 mutex_unlock(&lck_grp_lock
);
213 * Routine: lck_grp_free
220 mutex_lock(&lck_grp_lock
);
222 (void)remque((queue_entry_t
)grp
);
223 mutex_unlock(&lck_grp_lock
);
224 lck_grp_deallocate(grp
);
229 * Routine: lck_grp_reference
236 (void)hw_atomic_add((uint32_t *)(&grp
->lck_grp_refcnt
), 1);
241 * Routine: lck_grp_deallocate
248 if (hw_atomic_sub((uint32_t *)(&grp
->lck_grp_refcnt
), 1) == 0)
249 kfree(grp
, sizeof(lck_grp_t
));
253 * Routine: lck_grp_lckcnt_incr
261 unsigned int *lckcnt
;
265 lckcnt
= &grp
->lck_grp_spincnt
;
268 lckcnt
= &grp
->lck_grp_mtxcnt
;
271 lckcnt
= &grp
->lck_grp_rwcnt
;
274 return panic("lck_grp_lckcnt_incr(): invalid lock type: %d\n", lck_type
);
277 (void)hw_atomic_add((uint32_t *)lckcnt
, 1);
281 * Routine: lck_grp_lckcnt_decr
289 unsigned int *lckcnt
;
293 lckcnt
= &grp
->lck_grp_spincnt
;
296 lckcnt
= &grp
->lck_grp_mtxcnt
;
299 lckcnt
= &grp
->lck_grp_rwcnt
;
302 return panic("lck_grp_lckcnt_decr(): invalid lock type: %d\n", lck_type
);
305 (void)hw_atomic_sub((uint32_t *)lckcnt
, 1);
309 * Routine: lck_attr_alloc_init
318 if ((attr
= (lck_attr_t
*)kalloc(sizeof(lck_attr_t
))) != 0)
319 lck_attr_setdefault(attr
);
326 * Routine: lck_attr_setdefault
334 if (LcksOpts
& enaLkDeb
)
335 attr
->lck_attr_val
= LCK_ATTR_DEBUG
;
337 attr
->lck_attr_val
= LCK_ATTR_NONE
;
339 attr
->lck_attr_val
= LCK_ATTR_DEBUG
;
346 * Routine: lck_attr_setdebug
352 (void)hw_atomic_or((uint32_t *)&attr
->lck_attr_val
, LCK_ATTR_DEBUG
);
357 * Routine: lck_attr_rw_shared_priority
360 lck_attr_rw_shared_priority(
363 (void)hw_atomic_or((uint32_t *)&attr
->lck_attr_val
, LCK_ATTR_RW_SHARED_PRIORITY
);
368 * Routine: lck_attr_free
374 kfree(attr
, sizeof(lck_attr_t
));
379 * Routine: lck_spin_sleep
384 lck_sleep_action_t lck_sleep_action
,
386 wait_interrupt_t interruptible
)
390 if ((lck_sleep_action
& ~LCK_SLEEP_MASK
) != 0)
391 panic("Invalid lock sleep action %x\n", lck_sleep_action
);
393 res
= assert_wait(event
, interruptible
);
394 if (res
== THREAD_WAITING
) {
395 lck_spin_unlock(lck
);
396 res
= thread_block(THREAD_CONTINUE_NULL
);
397 if (!(lck_sleep_action
& LCK_SLEEP_UNLOCK
))
401 if (lck_sleep_action
& LCK_SLEEP_UNLOCK
)
402 lck_spin_unlock(lck
);
409 * Routine: lck_spin_sleep_deadline
412 lck_spin_sleep_deadline(
414 lck_sleep_action_t lck_sleep_action
,
416 wait_interrupt_t interruptible
,
421 if ((lck_sleep_action
& ~LCK_SLEEP_MASK
) != 0)
422 panic("Invalid lock sleep action %x\n", lck_sleep_action
);
424 res
= assert_wait_deadline(event
, interruptible
, deadline
);
425 if (res
== THREAD_WAITING
) {
426 lck_spin_unlock(lck
);
427 res
= thread_block(THREAD_CONTINUE_NULL
);
428 if (!(lck_sleep_action
& LCK_SLEEP_UNLOCK
))
432 if (lck_sleep_action
& LCK_SLEEP_UNLOCK
)
433 lck_spin_unlock(lck
);
440 * Routine: lck_mtx_sleep
445 lck_sleep_action_t lck_sleep_action
,
447 wait_interrupt_t interruptible
)
451 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_SLEEP_CODE
) | DBG_FUNC_START
,
452 (int)lck
, (int)lck_sleep_action
, (int)event
, (int)interruptible
, 0);
454 if ((lck_sleep_action
& ~LCK_SLEEP_MASK
) != 0)
455 panic("Invalid lock sleep action %x\n", lck_sleep_action
);
457 res
= assert_wait(event
, interruptible
);
458 if (res
== THREAD_WAITING
) {
460 res
= thread_block(THREAD_CONTINUE_NULL
);
461 if (!(lck_sleep_action
& LCK_SLEEP_UNLOCK
))
465 if (lck_sleep_action
& LCK_SLEEP_UNLOCK
)
468 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_SLEEP_CODE
) | DBG_FUNC_END
, (int)res
, 0, 0, 0, 0);
475 * Routine: lck_mtx_sleep_deadline
478 lck_mtx_sleep_deadline(
480 lck_sleep_action_t lck_sleep_action
,
482 wait_interrupt_t interruptible
,
487 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_SLEEP_DEADLINE_CODE
) | DBG_FUNC_START
,
488 (int)lck
, (int)lck_sleep_action
, (int)event
, (int)interruptible
, 0);
490 if ((lck_sleep_action
& ~LCK_SLEEP_MASK
) != 0)
491 panic("Invalid lock sleep action %x\n", lck_sleep_action
);
493 res
= assert_wait_deadline(event
, interruptible
, deadline
);
494 if (res
== THREAD_WAITING
) {
496 res
= thread_block(THREAD_CONTINUE_NULL
);
497 if (!(lck_sleep_action
& LCK_SLEEP_UNLOCK
))
501 if (lck_sleep_action
& LCK_SLEEP_UNLOCK
)
504 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_SLEEP_DEADLINE_CODE
) | DBG_FUNC_END
, (int)res
, 0, 0, 0, 0);
510 * Routine: lck_mtx_lock_wait
512 * Invoked in order to wait on contention.
514 * Called with the interlock locked and
515 * returns it unlocked.
522 thread_t self
= current_thread();
525 spl_t s
= splsched();
527 if (lck
->lck_mtx_tag
!= LCK_MTX_TAG_INDIRECT
)
530 mutex
= &lck
->lck_mtx_ptr
->lck_mtx
;
532 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_LCK_WAIT_CODE
) | DBG_FUNC_START
, (int)lck
, (int)holder
, 0, 0, 0);
534 priority
= self
->sched_pri
;
535 if (priority
< self
->priority
)
536 priority
= self
->priority
;
537 if (priority
> MINPRI_KERNEL
)
538 priority
= MINPRI_KERNEL
;
540 if (priority
< BASEPRI_DEFAULT
)
541 priority
= BASEPRI_DEFAULT
;
544 if (mutex
->lck_mtx_pri
== 0)
545 holder
->promotions
++;
546 if (holder
->priority
< MINPRI_KERNEL
) {
547 holder
->sched_mode
|= TH_MODE_PROMOTED
;
548 if ( mutex
->lck_mtx_pri
< priority
&&
549 holder
->sched_pri
< priority
) {
550 KERNEL_DEBUG_CONSTANT(
551 MACHDBG_CODE(DBG_MACH_SCHED
,MACH_PROMOTE
) | DBG_FUNC_NONE
,
552 holder
->sched_pri
, priority
, (int)holder
, (int)lck
, 0);
554 set_sched_pri(holder
, priority
);
557 thread_unlock(holder
);
560 if (mutex
->lck_mtx_pri
< priority
)
561 mutex
->lck_mtx_pri
= priority
;
562 if (self
->pending_promoter
[self
->pending_promoter_index
] == NULL
) {
563 self
->pending_promoter
[self
->pending_promoter_index
] = mutex
;
564 mutex
->lck_mtx_waiters
++;
567 if (self
->pending_promoter
[self
->pending_promoter_index
] != mutex
) {
568 self
->pending_promoter
[++self
->pending_promoter_index
] = mutex
;
569 mutex
->lck_mtx_waiters
++;
572 assert_wait((event_t
)(((unsigned int*)lck
)+((sizeof(lck_mtx_t
)-1)/sizeof(unsigned int))), THREAD_UNINT
);
573 lck_mtx_ilk_unlock(mutex
);
575 thread_block(THREAD_CONTINUE_NULL
);
577 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_LCK_WAIT_CODE
) | DBG_FUNC_END
, 0, 0, 0, 0, 0);
581 * Routine: lck_mtx_lock_acquire
583 * Invoked on acquiring the mutex when there is
586 * Returns the current number of waiters.
588 * Called with the interlock locked.
591 lck_mtx_lock_acquire(
594 thread_t thread
= current_thread();
597 if (lck
->lck_mtx_tag
!= LCK_MTX_TAG_INDIRECT
)
600 mutex
= &lck
->lck_mtx_ptr
->lck_mtx
;
602 if (thread
->pending_promoter
[thread
->pending_promoter_index
] == mutex
) {
603 thread
->pending_promoter
[thread
->pending_promoter_index
] = NULL
;
604 if (thread
->pending_promoter_index
> 0)
605 thread
->pending_promoter_index
--;
606 mutex
->lck_mtx_waiters
--;
609 if (mutex
->lck_mtx_waiters
> 0) {
610 integer_t priority
= mutex
->lck_mtx_pri
;
611 spl_t s
= splsched();
614 thread
->promotions
++;
615 if (thread
->priority
< MINPRI_KERNEL
) {
616 thread
->sched_mode
|= TH_MODE_PROMOTED
;
617 if (thread
->sched_pri
< priority
) {
618 KERNEL_DEBUG_CONSTANT(
619 MACHDBG_CODE(DBG_MACH_SCHED
,MACH_PROMOTE
) | DBG_FUNC_NONE
,
620 thread
->sched_pri
, priority
, 0, (int)lck
, 0);
622 set_sched_pri(thread
, priority
);
625 thread_unlock(thread
);
629 mutex
->lck_mtx_pri
= 0;
631 return (mutex
->lck_mtx_waiters
);
635 * Routine: lck_mtx_unlock_wakeup
637 * Invoked on unlock when there is contention.
639 * Called with the interlock locked.
642 lck_mtx_unlock_wakeup (
646 thread_t thread
= current_thread();
649 if (lck
->lck_mtx_tag
!= LCK_MTX_TAG_INDIRECT
)
652 mutex
= &lck
->lck_mtx_ptr
->lck_mtx
;
655 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_UNLCK_WAKEUP_CODE
) | DBG_FUNC_START
, (int)lck
, (int)holder
, 0, 0, 0);
657 if (thread
!= holder
)
658 panic("lck_mtx_unlock_wakeup: mutex %x holder %x\n", mutex
, holder
);
660 if (thread
->promotions
> 0) {
661 spl_t s
= splsched();
664 if ( --thread
->promotions
== 0 &&
665 (thread
->sched_mode
& TH_MODE_PROMOTED
) ) {
666 thread
->sched_mode
&= ~TH_MODE_PROMOTED
;
667 if (thread
->sched_mode
& TH_MODE_ISDEPRESSED
) {
668 KERNEL_DEBUG_CONSTANT(
669 MACHDBG_CODE(DBG_MACH_SCHED
,MACH_DEMOTE
) | DBG_FUNC_NONE
,
670 thread
->sched_pri
, DEPRESSPRI
, 0, (int)lck
, 0);
672 set_sched_pri(thread
, DEPRESSPRI
);
675 if (thread
->priority
< thread
->sched_pri
) {
676 KERNEL_DEBUG_CONSTANT(
677 MACHDBG_CODE(DBG_MACH_SCHED
,MACH_DEMOTE
) |
679 thread
->sched_pri
, thread
->priority
,
683 compute_priority(thread
, FALSE
);
686 thread_unlock(thread
);
689 assert(mutex
->lck_mtx_waiters
> 0);
690 thread_wakeup_one((event_t
)(((unsigned int*)lck
)+(sizeof(lck_mtx_t
)-1)/sizeof(unsigned int)));
692 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_UNLCK_WAKEUP_CODE
) | DBG_FUNC_END
, 0, 0, 0, 0, 0);
696 * Routine: mutex_pause
698 * Called by former callers of simple_lock_pause().
704 wait_result_t wait_result
;
706 wait_result
= assert_wait_timeout((event_t
)mutex_pause
, THREAD_UNINT
, 1, 1000*NSEC_PER_USEC
);
707 assert(wait_result
== THREAD_WAITING
);
709 wait_result
= thread_block(THREAD_CONTINUE_NULL
);
710 assert(wait_result
== THREAD_TIMED_OUT
);
714 * Routine: lck_rw_sleep
719 lck_sleep_action_t lck_sleep_action
,
721 wait_interrupt_t interruptible
)
724 lck_rw_type_t lck_rw_type
;
726 if ((lck_sleep_action
& ~LCK_SLEEP_MASK
) != 0)
727 panic("Invalid lock sleep action %x\n", lck_sleep_action
);
729 res
= assert_wait(event
, interruptible
);
730 if (res
== THREAD_WAITING
) {
731 lck_rw_type
= lck_rw_done(lck
);
732 res
= thread_block(THREAD_CONTINUE_NULL
);
733 if (!(lck_sleep_action
& LCK_SLEEP_UNLOCK
)) {
734 if (!(lck_sleep_action
& (LCK_SLEEP_SHARED
|LCK_SLEEP_EXCLUSIVE
)))
735 lck_rw_lock(lck
, lck_rw_type
);
736 else if (lck_sleep_action
& LCK_SLEEP_EXCLUSIVE
)
737 lck_rw_lock_exclusive(lck
);
739 lck_rw_lock_shared(lck
);
743 if (lck_sleep_action
& LCK_SLEEP_UNLOCK
)
744 (void)lck_rw_done(lck
);
751 * Routine: lck_rw_sleep_deadline
754 lck_rw_sleep_deadline(
756 lck_sleep_action_t lck_sleep_action
,
758 wait_interrupt_t interruptible
,
762 lck_rw_type_t lck_rw_type
;
764 if ((lck_sleep_action
& ~LCK_SLEEP_MASK
) != 0)
765 panic("Invalid lock sleep action %x\n", lck_sleep_action
);
767 res
= assert_wait_deadline(event
, interruptible
, deadline
);
768 if (res
== THREAD_WAITING
) {
769 lck_rw_type
= lck_rw_done(lck
);
770 res
= thread_block(THREAD_CONTINUE_NULL
);
771 if (!(lck_sleep_action
& LCK_SLEEP_UNLOCK
)) {
772 if (!(lck_sleep_action
& (LCK_SLEEP_SHARED
|LCK_SLEEP_EXCLUSIVE
)))
773 lck_rw_lock(lck
, lck_rw_type
);
774 else if (lck_sleep_action
& LCK_SLEEP_EXCLUSIVE
)
775 lck_rw_lock_exclusive(lck
);
777 lck_rw_lock_shared(lck
);
781 if (lck_sleep_action
& LCK_SLEEP_UNLOCK
)
782 (void)lck_rw_done(lck
);
790 lockgroup_info_array_t
*lockgroup_infop
,
791 mach_msg_type_number_t
*lockgroup_infoCntp
)
793 lockgroup_info_t
*lockgroup_info_base
;
794 lockgroup_info_t
*lockgroup_info
;
795 vm_offset_t lockgroup_info_addr
;
796 vm_size_t lockgroup_info_size
;
803 if (host
== HOST_NULL
)
804 return KERN_INVALID_HOST
;
806 mutex_lock(&lck_grp_lock
);
808 lockgroup_info_size
= round_page(lck_grp_cnt
* sizeof *lockgroup_info
);
809 kr
= kmem_alloc_pageable(ipc_kernel_map
,
810 &lockgroup_info_addr
, lockgroup_info_size
);
811 if (kr
!= KERN_SUCCESS
) {
812 mutex_unlock(&lck_grp_lock
);
816 lockgroup_info_base
= (lockgroup_info_t
*) lockgroup_info_addr
;
817 lck_grp
= (lck_grp_t
*)queue_first(&lck_grp_queue
);
818 lockgroup_info
= lockgroup_info_base
;
820 for (i
= 0; i
< lck_grp_cnt
; i
++) {
822 lockgroup_info
->lock_spin_cnt
= lck_grp
->lck_grp_spincnt
;
823 lockgroup_info
->lock_spin_util_cnt
= lck_grp
->lck_grp_stat
.lck_grp_spin_stat
.lck_grp_spin_util_cnt
;
824 lockgroup_info
->lock_spin_held_cnt
= lck_grp
->lck_grp_stat
.lck_grp_spin_stat
.lck_grp_spin_held_cnt
;
825 lockgroup_info
->lock_spin_miss_cnt
= lck_grp
->lck_grp_stat
.lck_grp_spin_stat
.lck_grp_spin_miss_cnt
;
826 lockgroup_info
->lock_spin_held_max
= lck_grp
->lck_grp_stat
.lck_grp_spin_stat
.lck_grp_spin_held_max
;
827 lockgroup_info
->lock_spin_held_cum
= lck_grp
->lck_grp_stat
.lck_grp_spin_stat
.lck_grp_spin_held_cum
;
829 lockgroup_info
->lock_mtx_cnt
= lck_grp
->lck_grp_mtxcnt
;
830 lockgroup_info
->lock_mtx_util_cnt
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_util_cnt
;
831 lockgroup_info
->lock_mtx_held_cnt
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_held_cnt
;
832 lockgroup_info
->lock_mtx_miss_cnt
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_miss_cnt
;
833 lockgroup_info
->lock_mtx_wait_cnt
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_wait_cnt
;
834 lockgroup_info
->lock_mtx_held_max
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_held_max
;
835 lockgroup_info
->lock_mtx_held_cum
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_held_cum
;
836 lockgroup_info
->lock_mtx_wait_max
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_wait_max
;
837 lockgroup_info
->lock_mtx_wait_cum
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_wait_cum
;
839 lockgroup_info
->lock_rw_cnt
= lck_grp
->lck_grp_rwcnt
;
840 lockgroup_info
->lock_rw_util_cnt
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_util_cnt
;
841 lockgroup_info
->lock_rw_held_cnt
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_held_cnt
;
842 lockgroup_info
->lock_rw_miss_cnt
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_miss_cnt
;
843 lockgroup_info
->lock_rw_wait_cnt
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_wait_cnt
;
844 lockgroup_info
->lock_rw_held_max
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_held_max
;
845 lockgroup_info
->lock_rw_held_cum
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_held_cum
;
846 lockgroup_info
->lock_rw_wait_max
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_wait_max
;
847 lockgroup_info
->lock_rw_wait_cum
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_wait_cum
;
849 (void) strncpy(lockgroup_info
->lockgroup_name
,lck_grp
->lck_grp_name
, LOCKGROUP_MAX_NAME
);
851 lck_grp
= (lck_grp_t
*)(queue_next((queue_entry_t
)(lck_grp
)));
855 *lockgroup_infoCntp
= lck_grp_cnt
;
856 mutex_unlock(&lck_grp_lock
);
858 used
= (*lockgroup_infoCntp
) * sizeof *lockgroup_info
;
860 if (used
!= lockgroup_info_size
)
861 bzero((char *) lockgroup_info
, lockgroup_info_size
- used
);
863 kr
= vm_map_copyin(ipc_kernel_map
, (vm_map_address_t
)lockgroup_info_addr
,
864 (vm_map_size_t
)lockgroup_info_size
, TRUE
, ©
);
865 assert(kr
== KERN_SUCCESS
);
867 *lockgroup_infop
= (lockgroup_info_t
*) copy
;
869 return(KERN_SUCCESS
);
873 * Compatibility module
876 extern lck_rw_t
*lock_alloc_EXT( boolean_t can_sleep
, unsigned short tag0
, unsigned short tag1
);
877 extern void lock_done_EXT(lck_rw_t
*lock
);
878 extern void lock_free_EXT(lck_rw_t
*lock
);
879 extern void lock_init_EXT(lck_rw_t
*lock
, boolean_t can_sleep
, unsigned short tag0
, unsigned short tag1
);
880 extern void lock_read_EXT(lck_rw_t
*lock
);
881 extern boolean_t
lock_read_to_write_EXT(lck_rw_t
*lock
);
882 extern void lock_write_EXT(lck_rw_t
*lock
);
883 extern void lock_write_to_read_EXT(lck_rw_t
*lock
);
884 extern wait_result_t
thread_sleep_lock_write_EXT(
885 event_t event
, lck_rw_t
*lock
, wait_interrupt_t interruptible
);
887 extern lck_mtx_t
*mutex_alloc_EXT(unsigned short tag
);
888 extern void mutex_free_EXT(lck_mtx_t
*mutex
);
889 extern void mutex_init_EXT(lck_mtx_t
*mutex
, unsigned short tag
);
890 extern void mutex_lock_EXT(lck_mtx_t
*mutex
);
891 extern boolean_t
mutex_try_EXT(lck_mtx_t
*mutex
);
892 extern void mutex_unlock_EXT(lck_mtx_t
*mutex
);
893 extern wait_result_t
thread_sleep_mutex_EXT(
894 event_t event
, lck_mtx_t
*mutex
, wait_interrupt_t interruptible
);
895 extern wait_result_t
thread_sleep_mutex_deadline_EXT(
896 event_t event
, lck_mtx_t
*mutex
, uint64_t deadline
, wait_interrupt_t interruptible
);
898 extern void usimple_lock_EXT(lck_spin_t
*lock
);
899 extern void usimple_lock_init_EXT(lck_spin_t
*lock
, unsigned short tag
);
900 extern unsigned int usimple_lock_try_EXT(lck_spin_t
*lock
);
901 extern void usimple_unlock_EXT(lck_spin_t
*lock
);
902 extern wait_result_t
thread_sleep_usimple_lock_EXT(event_t event
, lck_spin_t
*lock
, wait_interrupt_t interruptible
);
906 __unused boolean_t can_sleep
,
907 __unused
unsigned short tag0
,
908 __unused
unsigned short tag1
)
910 return( lck_rw_alloc_init( &LockCompatGroup
, LCK_ATTR_NULL
));
917 (void) lck_rw_done(lock
);
924 lck_rw_free(lock
, &LockCompatGroup
);
930 __unused boolean_t can_sleep
,
931 __unused
unsigned short tag0
,
932 __unused
unsigned short tag1
)
934 lck_rw_init(lock
, &LockCompatGroup
, LCK_ATTR_NULL
);
941 lck_rw_lock_shared( lock
);
945 lock_read_to_write_EXT(
948 return( lck_rw_lock_shared_to_exclusive(lock
));
955 lck_rw_lock_exclusive(lock
);
959 lock_write_to_read_EXT(
962 lck_rw_lock_exclusive_to_shared(lock
);
966 thread_sleep_lock_write_EXT(
969 wait_interrupt_t interruptible
)
971 return( lck_rw_sleep(lock
, LCK_SLEEP_EXCLUSIVE
, event
, interruptible
));
976 __unused
unsigned short tag
)
978 return(lck_mtx_alloc_init(&LockCompatGroup
, LCK_ATTR_NULL
));
985 lck_mtx_free(mutex
, &LockCompatGroup
);
991 __unused
unsigned short tag
)
993 lck_mtx_init(mutex
, &LockCompatGroup
, LCK_ATTR_NULL
);
1000 lck_mtx_lock(mutex
);
1007 return(lck_mtx_try_lock(mutex
));
1014 lck_mtx_unlock(mutex
);
1018 thread_sleep_mutex_EXT(
1021 wait_interrupt_t interruptible
)
1023 return( lck_mtx_sleep(mutex
, LCK_SLEEP_DEFAULT
, event
, interruptible
));
1027 thread_sleep_mutex_deadline_EXT(
1031 wait_interrupt_t interruptible
)
1033 return( lck_mtx_sleep_deadline(mutex
, LCK_SLEEP_DEFAULT
, event
, interruptible
, deadline
));
1040 lck_spin_lock(lock
);
1044 usimple_lock_init_EXT(
1046 __unused
unsigned short tag
)
1048 lck_spin_init(lock
, &LockCompatGroup
, LCK_ATTR_NULL
);
1052 usimple_lock_try_EXT(
1055 return(lck_spin_try_lock(lock
));
1062 lck_spin_unlock(lock
);
1066 thread_sleep_usimple_lock_EXT(
1069 wait_interrupt_t interruptible
)
1071 return( lck_spin_sleep(lock
, LCK_SLEEP_DEFAULT
, event
, interruptible
));