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_free
363 kfree(attr
, sizeof(lck_attr_t
));
368 * Routine: lck_spin_sleep
373 lck_sleep_action_t lck_sleep_action
,
375 wait_interrupt_t interruptible
)
379 if ((lck_sleep_action
& ~LCK_SLEEP_MASK
) != 0)
380 panic("Invalid lock sleep action %x\n", lck_sleep_action
);
382 res
= assert_wait(event
, interruptible
);
383 if (res
== THREAD_WAITING
) {
384 lck_spin_unlock(lck
);
385 res
= thread_block(THREAD_CONTINUE_NULL
);
386 if (!(lck_sleep_action
& LCK_SLEEP_UNLOCK
))
390 if (lck_sleep_action
& LCK_SLEEP_UNLOCK
)
391 lck_spin_unlock(lck
);
398 * Routine: lck_spin_sleep_deadline
401 lck_spin_sleep_deadline(
403 lck_sleep_action_t lck_sleep_action
,
405 wait_interrupt_t interruptible
,
410 if ((lck_sleep_action
& ~LCK_SLEEP_MASK
) != 0)
411 panic("Invalid lock sleep action %x\n", lck_sleep_action
);
413 res
= assert_wait_deadline(event
, interruptible
, deadline
);
414 if (res
== THREAD_WAITING
) {
415 lck_spin_unlock(lck
);
416 res
= thread_block(THREAD_CONTINUE_NULL
);
417 if (!(lck_sleep_action
& LCK_SLEEP_UNLOCK
))
421 if (lck_sleep_action
& LCK_SLEEP_UNLOCK
)
422 lck_spin_unlock(lck
);
429 * Routine: lck_mtx_sleep
434 lck_sleep_action_t lck_sleep_action
,
436 wait_interrupt_t interruptible
)
440 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_SLEEP_CODE
) | DBG_FUNC_START
,
441 (int)lck
, (int)lck_sleep_action
, (int)event
, (int)interruptible
, 0);
443 if ((lck_sleep_action
& ~LCK_SLEEP_MASK
) != 0)
444 panic("Invalid lock sleep action %x\n", lck_sleep_action
);
446 res
= assert_wait(event
, interruptible
);
447 if (res
== THREAD_WAITING
) {
449 res
= thread_block(THREAD_CONTINUE_NULL
);
450 if (!(lck_sleep_action
& LCK_SLEEP_UNLOCK
))
454 if (lck_sleep_action
& LCK_SLEEP_UNLOCK
)
457 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_SLEEP_CODE
) | DBG_FUNC_END
, (int)res
, 0, 0, 0, 0);
464 * Routine: lck_mtx_sleep_deadline
467 lck_mtx_sleep_deadline(
469 lck_sleep_action_t lck_sleep_action
,
471 wait_interrupt_t interruptible
,
476 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_SLEEP_DEADLINE_CODE
) | DBG_FUNC_START
,
477 (int)lck
, (int)lck_sleep_action
, (int)event
, (int)interruptible
, 0);
479 if ((lck_sleep_action
& ~LCK_SLEEP_MASK
) != 0)
480 panic("Invalid lock sleep action %x\n", lck_sleep_action
);
482 res
= assert_wait_deadline(event
, interruptible
, deadline
);
483 if (res
== THREAD_WAITING
) {
485 res
= thread_block(THREAD_CONTINUE_NULL
);
486 if (!(lck_sleep_action
& LCK_SLEEP_UNLOCK
))
490 if (lck_sleep_action
& LCK_SLEEP_UNLOCK
)
493 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_SLEEP_DEADLINE_CODE
) | DBG_FUNC_END
, (int)res
, 0, 0, 0, 0);
499 * Routine: lck_mtx_lock_wait
501 * Invoked in order to wait on contention.
503 * Called with the interlock locked and
504 * returns it unlocked.
511 thread_t self
= current_thread();
514 spl_t s
= splsched();
516 if (lck
->lck_mtx_tag
!= LCK_MTX_TAG_INDIRECT
)
519 mutex
= &lck
->lck_mtx_ptr
->lck_mtx
;
521 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_LCK_WAIT_CODE
) | DBG_FUNC_START
, (int)lck
, (int)holder
, 0, 0, 0);
523 priority
= self
->sched_pri
;
524 if (priority
< self
->priority
)
525 priority
= self
->priority
;
526 if (priority
> MINPRI_KERNEL
)
527 priority
= MINPRI_KERNEL
;
529 if (priority
< BASEPRI_DEFAULT
)
530 priority
= BASEPRI_DEFAULT
;
533 if (mutex
->lck_mtx_pri
== 0)
534 holder
->promotions
++;
535 if (holder
->priority
< MINPRI_KERNEL
) {
536 holder
->sched_mode
|= TH_MODE_PROMOTED
;
537 if ( mutex
->lck_mtx_pri
< priority
&&
538 holder
->sched_pri
< priority
) {
539 KERNEL_DEBUG_CONSTANT(
540 MACHDBG_CODE(DBG_MACH_SCHED
,MACH_PROMOTE
) | DBG_FUNC_NONE
,
541 holder
->sched_pri
, priority
, (int)holder
, (int)lck
, 0);
543 set_sched_pri(holder
, priority
);
546 thread_unlock(holder
);
549 if (mutex
->lck_mtx_pri
< priority
)
550 mutex
->lck_mtx_pri
= priority
;
551 if (self
->pending_promoter
[self
->pending_promoter_index
] == NULL
) {
552 self
->pending_promoter
[self
->pending_promoter_index
] = mutex
;
553 mutex
->lck_mtx_waiters
++;
556 if (self
->pending_promoter
[self
->pending_promoter_index
] != mutex
) {
557 self
->pending_promoter
[++self
->pending_promoter_index
] = mutex
;
558 mutex
->lck_mtx_waiters
++;
561 assert_wait((event_t
)(((unsigned int*)lck
)+((sizeof(lck_mtx_t
)-1)/sizeof(unsigned int))), THREAD_UNINT
);
562 lck_mtx_ilk_unlock(mutex
);
564 thread_block(THREAD_CONTINUE_NULL
);
566 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_LCK_WAIT_CODE
) | DBG_FUNC_END
, 0, 0, 0, 0, 0);
570 * Routine: lck_mtx_lock_acquire
572 * Invoked on acquiring the mutex when there is
575 * Returns the current number of waiters.
577 * Called with the interlock locked.
580 lck_mtx_lock_acquire(
583 thread_t thread
= current_thread();
586 if (lck
->lck_mtx_tag
!= LCK_MTX_TAG_INDIRECT
)
589 mutex
= &lck
->lck_mtx_ptr
->lck_mtx
;
591 if (thread
->pending_promoter
[thread
->pending_promoter_index
] == mutex
) {
592 thread
->pending_promoter
[thread
->pending_promoter_index
] = NULL
;
593 if (thread
->pending_promoter_index
> 0)
594 thread
->pending_promoter_index
--;
595 mutex
->lck_mtx_waiters
--;
598 if (mutex
->lck_mtx_waiters
> 0) {
599 integer_t priority
= mutex
->lck_mtx_pri
;
600 spl_t s
= splsched();
603 thread
->promotions
++;
604 if (thread
->priority
< MINPRI_KERNEL
) {
605 thread
->sched_mode
|= TH_MODE_PROMOTED
;
606 if (thread
->sched_pri
< priority
) {
607 KERNEL_DEBUG_CONSTANT(
608 MACHDBG_CODE(DBG_MACH_SCHED
,MACH_PROMOTE
) | DBG_FUNC_NONE
,
609 thread
->sched_pri
, priority
, 0, (int)lck
, 0);
611 set_sched_pri(thread
, priority
);
614 thread_unlock(thread
);
618 mutex
->lck_mtx_pri
= 0;
620 return (mutex
->lck_mtx_waiters
);
624 * Routine: lck_mtx_unlock_wakeup
626 * Invoked on unlock when there is contention.
628 * Called with the interlock locked.
631 lck_mtx_unlock_wakeup (
635 thread_t thread
= current_thread();
638 if (lck
->lck_mtx_tag
!= LCK_MTX_TAG_INDIRECT
)
641 mutex
= &lck
->lck_mtx_ptr
->lck_mtx
;
644 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_UNLCK_WAKEUP_CODE
) | DBG_FUNC_START
, (int)lck
, (int)holder
, 0, 0, 0);
646 if (thread
!= holder
)
647 panic("lck_mtx_unlock_wakeup: mutex %x holder %x\n", mutex
, holder
);
649 if (thread
->promotions
> 0) {
650 spl_t s
= splsched();
653 if ( --thread
->promotions
== 0 &&
654 (thread
->sched_mode
& TH_MODE_PROMOTED
) ) {
655 thread
->sched_mode
&= ~TH_MODE_PROMOTED
;
656 if (thread
->sched_mode
& TH_MODE_ISDEPRESSED
) {
657 KERNEL_DEBUG_CONSTANT(
658 MACHDBG_CODE(DBG_MACH_SCHED
,MACH_DEMOTE
) | DBG_FUNC_NONE
,
659 thread
->sched_pri
, DEPRESSPRI
, 0, (int)lck
, 0);
661 set_sched_pri(thread
, DEPRESSPRI
);
664 if (thread
->priority
< thread
->sched_pri
) {
665 KERNEL_DEBUG_CONSTANT(
666 MACHDBG_CODE(DBG_MACH_SCHED
,MACH_DEMOTE
) |
668 thread
->sched_pri
, thread
->priority
,
672 compute_priority(thread
, FALSE
);
675 thread_unlock(thread
);
678 assert(mutex
->lck_mtx_waiters
> 0);
679 thread_wakeup_one((event_t
)(((unsigned int*)lck
)+(sizeof(lck_mtx_t
)-1)/sizeof(unsigned int)));
681 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_UNLCK_WAKEUP_CODE
) | DBG_FUNC_END
, 0, 0, 0, 0, 0);
685 * Routine: mutex_pause
687 * Called by former callers of simple_lock_pause().
693 wait_result_t wait_result
;
695 wait_result
= assert_wait_timeout((event_t
)mutex_pause
, THREAD_UNINT
, 1, 1000*NSEC_PER_USEC
);
696 assert(wait_result
== THREAD_WAITING
);
698 wait_result
= thread_block(THREAD_CONTINUE_NULL
);
699 assert(wait_result
== THREAD_TIMED_OUT
);
703 * Routine: lck_rw_sleep
708 lck_sleep_action_t lck_sleep_action
,
710 wait_interrupt_t interruptible
)
713 lck_rw_type_t lck_rw_type
;
715 if ((lck_sleep_action
& ~LCK_SLEEP_MASK
) != 0)
716 panic("Invalid lock sleep action %x\n", lck_sleep_action
);
718 res
= assert_wait(event
, interruptible
);
719 if (res
== THREAD_WAITING
) {
720 lck_rw_type
= lck_rw_done(lck
);
721 res
= thread_block(THREAD_CONTINUE_NULL
);
722 if (!(lck_sleep_action
& LCK_SLEEP_UNLOCK
)) {
723 if (!(lck_sleep_action
& (LCK_SLEEP_SHARED
|LCK_SLEEP_EXCLUSIVE
)))
724 lck_rw_lock(lck
, lck_rw_type
);
725 else if (lck_sleep_action
& LCK_SLEEP_EXCLUSIVE
)
726 lck_rw_lock_exclusive(lck
);
728 lck_rw_lock_shared(lck
);
732 if (lck_sleep_action
& LCK_SLEEP_UNLOCK
)
733 (void)lck_rw_done(lck
);
740 * Routine: lck_rw_sleep_deadline
743 lck_rw_sleep_deadline(
745 lck_sleep_action_t lck_sleep_action
,
747 wait_interrupt_t interruptible
,
751 lck_rw_type_t lck_rw_type
;
753 if ((lck_sleep_action
& ~LCK_SLEEP_MASK
) != 0)
754 panic("Invalid lock sleep action %x\n", lck_sleep_action
);
756 res
= assert_wait_deadline(event
, interruptible
, deadline
);
757 if (res
== THREAD_WAITING
) {
758 lck_rw_type
= lck_rw_done(lck
);
759 res
= thread_block(THREAD_CONTINUE_NULL
);
760 if (!(lck_sleep_action
& LCK_SLEEP_UNLOCK
)) {
761 if (!(lck_sleep_action
& (LCK_SLEEP_SHARED
|LCK_SLEEP_EXCLUSIVE
)))
762 lck_rw_lock(lck
, lck_rw_type
);
763 else if (lck_sleep_action
& LCK_SLEEP_EXCLUSIVE
)
764 lck_rw_lock_exclusive(lck
);
766 lck_rw_lock_shared(lck
);
770 if (lck_sleep_action
& LCK_SLEEP_UNLOCK
)
771 (void)lck_rw_done(lck
);
779 lockgroup_info_array_t
*lockgroup_infop
,
780 mach_msg_type_number_t
*lockgroup_infoCntp
)
782 lockgroup_info_t
*lockgroup_info_base
;
783 lockgroup_info_t
*lockgroup_info
;
784 vm_offset_t lockgroup_info_addr
;
785 vm_size_t lockgroup_info_size
;
792 if (host
== HOST_NULL
)
793 return KERN_INVALID_HOST
;
795 mutex_lock(&lck_grp_lock
);
797 lockgroup_info_size
= round_page(lck_grp_cnt
* sizeof *lockgroup_info
);
798 kr
= kmem_alloc_pageable(ipc_kernel_map
,
799 &lockgroup_info_addr
, lockgroup_info_size
);
800 if (kr
!= KERN_SUCCESS
) {
801 mutex_unlock(&lck_grp_lock
);
805 lockgroup_info_base
= (lockgroup_info_t
*) lockgroup_info_addr
;
806 lck_grp
= (lck_grp_t
*)queue_first(&lck_grp_queue
);
807 lockgroup_info
= lockgroup_info_base
;
809 for (i
= 0; i
< lck_grp_cnt
; i
++) {
811 lockgroup_info
->lock_spin_cnt
= lck_grp
->lck_grp_spincnt
;
812 lockgroup_info
->lock_spin_util_cnt
= lck_grp
->lck_grp_stat
.lck_grp_spin_stat
.lck_grp_spin_util_cnt
;
813 lockgroup_info
->lock_spin_held_cnt
= lck_grp
->lck_grp_stat
.lck_grp_spin_stat
.lck_grp_spin_held_cnt
;
814 lockgroup_info
->lock_spin_miss_cnt
= lck_grp
->lck_grp_stat
.lck_grp_spin_stat
.lck_grp_spin_miss_cnt
;
815 lockgroup_info
->lock_spin_held_max
= lck_grp
->lck_grp_stat
.lck_grp_spin_stat
.lck_grp_spin_held_max
;
816 lockgroup_info
->lock_spin_held_cum
= lck_grp
->lck_grp_stat
.lck_grp_spin_stat
.lck_grp_spin_held_cum
;
818 lockgroup_info
->lock_mtx_cnt
= lck_grp
->lck_grp_mtxcnt
;
819 lockgroup_info
->lock_mtx_util_cnt
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_util_cnt
;
820 lockgroup_info
->lock_mtx_held_cnt
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_held_cnt
;
821 lockgroup_info
->lock_mtx_miss_cnt
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_miss_cnt
;
822 lockgroup_info
->lock_mtx_wait_cnt
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_wait_cnt
;
823 lockgroup_info
->lock_mtx_held_max
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_held_max
;
824 lockgroup_info
->lock_mtx_held_cum
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_held_cum
;
825 lockgroup_info
->lock_mtx_wait_max
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_wait_max
;
826 lockgroup_info
->lock_mtx_wait_cum
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_wait_cum
;
828 lockgroup_info
->lock_rw_cnt
= lck_grp
->lck_grp_rwcnt
;
829 lockgroup_info
->lock_rw_util_cnt
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_util_cnt
;
830 lockgroup_info
->lock_rw_held_cnt
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_held_cnt
;
831 lockgroup_info
->lock_rw_miss_cnt
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_miss_cnt
;
832 lockgroup_info
->lock_rw_wait_cnt
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_wait_cnt
;
833 lockgroup_info
->lock_rw_held_max
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_held_max
;
834 lockgroup_info
->lock_rw_held_cum
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_held_cum
;
835 lockgroup_info
->lock_rw_wait_max
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_wait_max
;
836 lockgroup_info
->lock_rw_wait_cum
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_wait_cum
;
838 (void) strncpy(lockgroup_info
->lockgroup_name
,lck_grp
->lck_grp_name
, LOCKGROUP_MAX_NAME
);
840 lck_grp
= (lck_grp_t
*)(queue_next((queue_entry_t
)(lck_grp
)));
844 *lockgroup_infoCntp
= lck_grp_cnt
;
845 mutex_unlock(&lck_grp_lock
);
847 used
= (*lockgroup_infoCntp
) * sizeof *lockgroup_info
;
849 if (used
!= lockgroup_info_size
)
850 bzero((char *) lockgroup_info
, lockgroup_info_size
- used
);
852 kr
= vm_map_copyin(ipc_kernel_map
, (vm_map_address_t
)lockgroup_info_addr
,
853 (vm_map_size_t
)lockgroup_info_size
, TRUE
, ©
);
854 assert(kr
== KERN_SUCCESS
);
856 *lockgroup_infop
= (lockgroup_info_t
*) copy
;
858 return(KERN_SUCCESS
);
862 * Compatibility module
865 extern lck_rw_t
*lock_alloc_EXT( boolean_t can_sleep
, unsigned short tag0
, unsigned short tag1
);
866 extern void lock_done_EXT(lck_rw_t
*lock
);
867 extern void lock_free_EXT(lck_rw_t
*lock
);
868 extern void lock_init_EXT(lck_rw_t
*lock
, boolean_t can_sleep
, unsigned short tag0
, unsigned short tag1
);
869 extern void lock_read_EXT(lck_rw_t
*lock
);
870 extern boolean_t
lock_read_to_write_EXT(lck_rw_t
*lock
);
871 extern void lock_write_EXT(lck_rw_t
*lock
);
872 extern void lock_write_to_read_EXT(lck_rw_t
*lock
);
873 extern wait_result_t
thread_sleep_lock_write_EXT(
874 event_t event
, lck_rw_t
*lock
, wait_interrupt_t interruptible
);
876 extern lck_mtx_t
*mutex_alloc_EXT(unsigned short tag
);
877 extern void mutex_free_EXT(lck_mtx_t
*mutex
);
878 extern void mutex_init_EXT(lck_mtx_t
*mutex
, unsigned short tag
);
879 extern void mutex_lock_EXT(lck_mtx_t
*mutex
);
880 extern boolean_t
mutex_try_EXT(lck_mtx_t
*mutex
);
881 extern void mutex_unlock_EXT(lck_mtx_t
*mutex
);
882 extern wait_result_t
thread_sleep_mutex_EXT(
883 event_t event
, lck_mtx_t
*mutex
, wait_interrupt_t interruptible
);
884 extern wait_result_t
thread_sleep_mutex_deadline_EXT(
885 event_t event
, lck_mtx_t
*mutex
, uint64_t deadline
, wait_interrupt_t interruptible
);
887 extern void usimple_lock_EXT(lck_spin_t
*lock
);
888 extern void usimple_lock_init_EXT(lck_spin_t
*lock
, unsigned short tag
);
889 extern unsigned int usimple_lock_try_EXT(lck_spin_t
*lock
);
890 extern void usimple_unlock_EXT(lck_spin_t
*lock
);
891 extern wait_result_t
thread_sleep_usimple_lock_EXT(event_t event
, lck_spin_t
*lock
, wait_interrupt_t interruptible
);
895 __unused boolean_t can_sleep
,
896 __unused
unsigned short tag0
,
897 __unused
unsigned short tag1
)
899 return( lck_rw_alloc_init( &LockCompatGroup
, LCK_ATTR_NULL
));
906 (void) lck_rw_done(lock
);
913 lck_rw_free(lock
, &LockCompatGroup
);
919 __unused boolean_t can_sleep
,
920 __unused
unsigned short tag0
,
921 __unused
unsigned short tag1
)
923 lck_rw_init(lock
, &LockCompatGroup
, LCK_ATTR_NULL
);
930 lck_rw_lock_shared( lock
);
934 lock_read_to_write_EXT(
937 return( lck_rw_lock_shared_to_exclusive(lock
));
944 lck_rw_lock_exclusive(lock
);
948 lock_write_to_read_EXT(
951 lck_rw_lock_exclusive_to_shared(lock
);
955 thread_sleep_lock_write_EXT(
958 wait_interrupt_t interruptible
)
960 return( lck_rw_sleep(lock
, LCK_SLEEP_EXCLUSIVE
, event
, interruptible
));
965 __unused
unsigned short tag
)
967 return(lck_mtx_alloc_init(&LockCompatGroup
, LCK_ATTR_NULL
));
974 lck_mtx_free(mutex
, &LockCompatGroup
);
980 __unused
unsigned short tag
)
982 lck_mtx_init(mutex
, &LockCompatGroup
, LCK_ATTR_NULL
);
996 return(lck_mtx_try_lock(mutex
));
1003 lck_mtx_unlock(mutex
);
1007 thread_sleep_mutex_EXT(
1010 wait_interrupt_t interruptible
)
1012 return( lck_mtx_sleep(mutex
, LCK_SLEEP_DEFAULT
, event
, interruptible
));
1016 thread_sleep_mutex_deadline_EXT(
1020 wait_interrupt_t interruptible
)
1022 return( lck_mtx_sleep_deadline(mutex
, LCK_SLEEP_DEFAULT
, event
, interruptible
, deadline
));
1029 lck_spin_lock(lock
);
1033 usimple_lock_init_EXT(
1035 __unused
unsigned short tag
)
1037 lck_spin_init(lock
, &LockCompatGroup
, LCK_ATTR_NULL
);
1041 usimple_lock_try_EXT(
1044 lck_spin_try_lock(lock
);
1051 lck_spin_unlock(lock
);
1055 thread_sleep_usimple_lock_EXT(
1058 wait_interrupt_t interruptible
)
1060 return( lck_spin_sleep(lock
, LCK_SLEEP_DEFAULT
, event
, interruptible
));