2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
28 * All Rights Reserved.
30 * Permission to use, copy, modify and distribute this software and its
31 * documentation is hereby granted, provided that both the copyright
32 * notice and this permission notice appear in all copies of the
33 * software, derivative works or modified versions, and any portions
34 * thereof, and that both notices appear in supporting documentation.
36 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
37 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
38 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
40 * Carnegie Mellon requests users of this software to return to
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
51 #include <mach_ldebug.h>
54 #include <mach/kern_return.h>
55 #include <mach/mach_host_server.h>
56 #include <mach_debug/lockgroup_info.h>
58 #include <kern/locks.h>
59 #include <kern/misc_protos.h>
60 #include <kern/kalloc.h>
61 #include <kern/thread.h>
62 #include <kern/processor.h>
63 #include <kern/sched_prim.h>
64 #include <kern/debug.h>
68 #include <sys/kdebug.h>
70 #define LCK_MTX_SLEEP_CODE 0
71 #define LCK_MTX_SLEEP_DEADLINE_CODE 1
72 #define LCK_MTX_LCK_WAIT_CODE 2
73 #define LCK_MTX_UNLCK_WAKEUP_CODE 3
76 static queue_head_t lck_grp_queue
;
77 static unsigned int lck_grp_cnt
;
79 decl_mutex_data(static,lck_grp_lock
)
81 lck_grp_attr_t LockDefaultGroupAttr
;
82 lck_grp_t LockCompatGroup
;
83 lck_attr_t LockDefaultLckAttr
;
86 * Routine: lck_mod_init
93 queue_init(&lck_grp_queue
);
94 mutex_init(&lck_grp_lock
, 0);
96 lck_grp_attr_setdefault( &LockDefaultGroupAttr
);
97 lck_grp_init( &LockCompatGroup
, "Compatibility APIs", LCK_GRP_ATTR_NULL
);
98 lck_attr_setdefault(&LockDefaultLckAttr
);
102 * Routine: lck_grp_attr_alloc_init
106 lck_grp_attr_alloc_init(
109 lck_grp_attr_t
*attr
;
111 if ((attr
= (lck_grp_attr_t
*)kalloc(sizeof(lck_grp_attr_t
))) != 0)
112 lck_grp_attr_setdefault(attr
);
119 * Routine: lck_grp_attr_setdefault
123 lck_grp_attr_setdefault(
124 lck_grp_attr_t
*attr
)
126 if (LcksOpts
& enaLkStat
)
127 attr
->grp_attr_val
= LCK_GRP_ATTR_STAT
;
129 attr
->grp_attr_val
= 0;
134 * Routine: lck_grp_attr_setstat
138 lck_grp_attr_setstat(
139 lck_grp_attr_t
*attr
)
141 (void)hw_atomic_or((uint32_t *)&attr
->grp_attr_val
, LCK_GRP_ATTR_STAT
);
146 * Routine: lck_grp_attr_free
151 lck_grp_attr_t
*attr
)
153 kfree(attr
, sizeof(lck_grp_attr_t
));
158 * Routine: lck_grp_alloc_init
163 const char* grp_name
,
164 lck_grp_attr_t
*attr
)
168 if ((grp
= (lck_grp_t
*)kalloc(sizeof(lck_grp_t
))) != 0)
169 lck_grp_init(grp
, grp_name
, attr
);
176 * Routine: lck_grp_init
182 const char* grp_name
,
183 lck_grp_attr_t
*attr
)
185 bzero((void *)grp
, sizeof(lck_grp_t
));
187 (void) strncpy(grp
->lck_grp_name
, grp_name
, LCK_GRP_MAX_NAME
);
189 if (attr
!= LCK_GRP_ATTR_NULL
)
190 grp
->lck_grp_attr
= attr
->grp_attr_val
;
191 else if (LcksOpts
& enaLkStat
)
192 grp
->lck_grp_attr
= LCK_GRP_ATTR_STAT
;
194 grp
->lck_grp_attr
= LCK_ATTR_NONE
;
196 grp
->lck_grp_refcnt
= 1;
198 mutex_lock(&lck_grp_lock
);
199 enqueue_tail(&lck_grp_queue
, (queue_entry_t
)grp
);
201 mutex_unlock(&lck_grp_lock
);
207 * Routine: lck_grp_free
214 mutex_lock(&lck_grp_lock
);
216 (void)remque((queue_entry_t
)grp
);
217 mutex_unlock(&lck_grp_lock
);
218 lck_grp_deallocate(grp
);
223 * Routine: lck_grp_reference
230 (void)hw_atomic_add((uint32_t *)(&grp
->lck_grp_refcnt
), 1);
235 * Routine: lck_grp_deallocate
242 if (hw_atomic_sub((uint32_t *)(&grp
->lck_grp_refcnt
), 1) == 0)
243 kfree(grp
, sizeof(lck_grp_t
));
247 * Routine: lck_grp_lckcnt_incr
255 unsigned int *lckcnt
;
259 lckcnt
= &grp
->lck_grp_spincnt
;
262 lckcnt
= &grp
->lck_grp_mtxcnt
;
265 lckcnt
= &grp
->lck_grp_rwcnt
;
268 return panic("lck_grp_lckcnt_incr(): invalid lock type: %d\n", lck_type
);
271 (void)hw_atomic_add((uint32_t *)lckcnt
, 1);
275 * Routine: lck_grp_lckcnt_decr
283 unsigned int *lckcnt
;
287 lckcnt
= &grp
->lck_grp_spincnt
;
290 lckcnt
= &grp
->lck_grp_mtxcnt
;
293 lckcnt
= &grp
->lck_grp_rwcnt
;
296 return panic("lck_grp_lckcnt_decr(): invalid lock type: %d\n", lck_type
);
299 (void)hw_atomic_sub((uint32_t *)lckcnt
, 1);
303 * Routine: lck_attr_alloc_init
312 if ((attr
= (lck_attr_t
*)kalloc(sizeof(lck_attr_t
))) != 0)
313 lck_attr_setdefault(attr
);
320 * Routine: lck_attr_setdefault
328 if (LcksOpts
& enaLkDeb
)
329 attr
->lck_attr_val
= LCK_ATTR_DEBUG
;
331 attr
->lck_attr_val
= LCK_ATTR_NONE
;
333 attr
->lck_attr_val
= LCK_ATTR_DEBUG
;
340 * Routine: lck_attr_setdebug
346 (void)hw_atomic_or((uint32_t *)&attr
->lck_attr_val
, LCK_ATTR_DEBUG
);
351 * Routine: lck_attr_rw_shared_priority
354 lck_attr_rw_shared_priority(
357 (void)hw_atomic_or((uint32_t *)&attr
->lck_attr_val
, LCK_ATTR_RW_SHARED_PRIORITY
);
362 * Routine: lck_attr_free
368 kfree(attr
, sizeof(lck_attr_t
));
373 * Routine: lck_spin_sleep
378 lck_sleep_action_t lck_sleep_action
,
380 wait_interrupt_t interruptible
)
384 if ((lck_sleep_action
& ~LCK_SLEEP_MASK
) != 0)
385 panic("Invalid lock sleep action %x\n", lck_sleep_action
);
387 res
= assert_wait(event
, interruptible
);
388 if (res
== THREAD_WAITING
) {
389 lck_spin_unlock(lck
);
390 res
= thread_block(THREAD_CONTINUE_NULL
);
391 if (!(lck_sleep_action
& LCK_SLEEP_UNLOCK
))
395 if (lck_sleep_action
& LCK_SLEEP_UNLOCK
)
396 lck_spin_unlock(lck
);
403 * Routine: lck_spin_sleep_deadline
406 lck_spin_sleep_deadline(
408 lck_sleep_action_t lck_sleep_action
,
410 wait_interrupt_t interruptible
,
415 if ((lck_sleep_action
& ~LCK_SLEEP_MASK
) != 0)
416 panic("Invalid lock sleep action %x\n", lck_sleep_action
);
418 res
= assert_wait_deadline(event
, interruptible
, deadline
);
419 if (res
== THREAD_WAITING
) {
420 lck_spin_unlock(lck
);
421 res
= thread_block(THREAD_CONTINUE_NULL
);
422 if (!(lck_sleep_action
& LCK_SLEEP_UNLOCK
))
426 if (lck_sleep_action
& LCK_SLEEP_UNLOCK
)
427 lck_spin_unlock(lck
);
434 * Routine: lck_mtx_sleep
439 lck_sleep_action_t lck_sleep_action
,
441 wait_interrupt_t interruptible
)
445 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_SLEEP_CODE
) | DBG_FUNC_START
,
446 (int)lck
, (int)lck_sleep_action
, (int)event
, (int)interruptible
, 0);
448 if ((lck_sleep_action
& ~LCK_SLEEP_MASK
) != 0)
449 panic("Invalid lock sleep action %x\n", lck_sleep_action
);
451 res
= assert_wait(event
, interruptible
);
452 if (res
== THREAD_WAITING
) {
454 res
= thread_block(THREAD_CONTINUE_NULL
);
455 if (!(lck_sleep_action
& LCK_SLEEP_UNLOCK
))
459 if (lck_sleep_action
& LCK_SLEEP_UNLOCK
)
462 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_SLEEP_CODE
) | DBG_FUNC_END
, (int)res
, 0, 0, 0, 0);
469 * Routine: lck_mtx_sleep_deadline
472 lck_mtx_sleep_deadline(
474 lck_sleep_action_t lck_sleep_action
,
476 wait_interrupt_t interruptible
,
481 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_SLEEP_DEADLINE_CODE
) | DBG_FUNC_START
,
482 (int)lck
, (int)lck_sleep_action
, (int)event
, (int)interruptible
, 0);
484 if ((lck_sleep_action
& ~LCK_SLEEP_MASK
) != 0)
485 panic("Invalid lock sleep action %x\n", lck_sleep_action
);
487 res
= assert_wait_deadline(event
, interruptible
, deadline
);
488 if (res
== THREAD_WAITING
) {
490 res
= thread_block(THREAD_CONTINUE_NULL
);
491 if (!(lck_sleep_action
& LCK_SLEEP_UNLOCK
))
495 if (lck_sleep_action
& LCK_SLEEP_UNLOCK
)
498 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_SLEEP_DEADLINE_CODE
) | DBG_FUNC_END
, (int)res
, 0, 0, 0, 0);
504 * Routine: lck_mtx_lock_wait
506 * Invoked in order to wait on contention.
508 * Called with the interlock locked and
509 * returns it unlocked.
516 thread_t self
= current_thread();
519 spl_t s
= splsched();
521 if (lck
->lck_mtx_tag
!= LCK_MTX_TAG_INDIRECT
)
524 mutex
= &lck
->lck_mtx_ptr
->lck_mtx
;
526 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_LCK_WAIT_CODE
) | DBG_FUNC_START
, (int)lck
, (int)holder
, 0, 0, 0);
528 priority
= self
->sched_pri
;
529 if (priority
< self
->priority
)
530 priority
= self
->priority
;
531 if (priority
> MINPRI_KERNEL
)
532 priority
= MINPRI_KERNEL
;
534 if (priority
< BASEPRI_DEFAULT
)
535 priority
= BASEPRI_DEFAULT
;
538 if (mutex
->lck_mtx_pri
== 0)
539 holder
->promotions
++;
540 if (holder
->priority
< MINPRI_KERNEL
) {
541 holder
->sched_mode
|= TH_MODE_PROMOTED
;
542 if ( mutex
->lck_mtx_pri
< priority
&&
543 holder
->sched_pri
< priority
) {
544 KERNEL_DEBUG_CONSTANT(
545 MACHDBG_CODE(DBG_MACH_SCHED
,MACH_PROMOTE
) | DBG_FUNC_NONE
,
546 holder
->sched_pri
, priority
, (int)holder
, (int)lck
, 0);
548 set_sched_pri(holder
, priority
);
551 thread_unlock(holder
);
554 if (mutex
->lck_mtx_pri
< priority
)
555 mutex
->lck_mtx_pri
= priority
;
556 if (self
->pending_promoter
[self
->pending_promoter_index
] == NULL
) {
557 self
->pending_promoter
[self
->pending_promoter_index
] = mutex
;
558 mutex
->lck_mtx_waiters
++;
561 if (self
->pending_promoter
[self
->pending_promoter_index
] != mutex
) {
562 self
->pending_promoter
[++self
->pending_promoter_index
] = mutex
;
563 mutex
->lck_mtx_waiters
++;
566 assert_wait((event_t
)(((unsigned int*)lck
)+((sizeof(lck_mtx_t
)-1)/sizeof(unsigned int))), THREAD_UNINT
);
567 lck_mtx_ilk_unlock(mutex
);
569 thread_block(THREAD_CONTINUE_NULL
);
571 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_LCK_WAIT_CODE
) | DBG_FUNC_END
, 0, 0, 0, 0, 0);
575 * Routine: lck_mtx_lock_acquire
577 * Invoked on acquiring the mutex when there is
580 * Returns the current number of waiters.
582 * Called with the interlock locked.
585 lck_mtx_lock_acquire(
588 thread_t thread
= current_thread();
591 if (lck
->lck_mtx_tag
!= LCK_MTX_TAG_INDIRECT
)
594 mutex
= &lck
->lck_mtx_ptr
->lck_mtx
;
596 if (thread
->pending_promoter
[thread
->pending_promoter_index
] == mutex
) {
597 thread
->pending_promoter
[thread
->pending_promoter_index
] = NULL
;
598 if (thread
->pending_promoter_index
> 0)
599 thread
->pending_promoter_index
--;
600 mutex
->lck_mtx_waiters
--;
603 if (mutex
->lck_mtx_waiters
> 0) {
604 integer_t priority
= mutex
->lck_mtx_pri
;
605 spl_t s
= splsched();
608 thread
->promotions
++;
609 if (thread
->priority
< MINPRI_KERNEL
) {
610 thread
->sched_mode
|= TH_MODE_PROMOTED
;
611 if (thread
->sched_pri
< priority
) {
612 KERNEL_DEBUG_CONSTANT(
613 MACHDBG_CODE(DBG_MACH_SCHED
,MACH_PROMOTE
) | DBG_FUNC_NONE
,
614 thread
->sched_pri
, priority
, 0, (int)lck
, 0);
616 set_sched_pri(thread
, priority
);
619 thread_unlock(thread
);
623 mutex
->lck_mtx_pri
= 0;
625 return (mutex
->lck_mtx_waiters
);
629 * Routine: lck_mtx_unlock_wakeup
631 * Invoked on unlock when there is contention.
633 * Called with the interlock locked.
636 lck_mtx_unlock_wakeup (
640 thread_t thread
= current_thread();
643 if (lck
->lck_mtx_tag
!= LCK_MTX_TAG_INDIRECT
)
646 mutex
= &lck
->lck_mtx_ptr
->lck_mtx
;
649 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_UNLCK_WAKEUP_CODE
) | DBG_FUNC_START
, (int)lck
, (int)holder
, 0, 0, 0);
651 if (thread
!= holder
)
652 panic("lck_mtx_unlock_wakeup: mutex %x holder %x\n", mutex
, holder
);
654 if (thread
->promotions
> 0) {
655 spl_t s
= splsched();
658 if ( --thread
->promotions
== 0 &&
659 (thread
->sched_mode
& TH_MODE_PROMOTED
) ) {
660 thread
->sched_mode
&= ~TH_MODE_PROMOTED
;
661 if (thread
->sched_mode
& TH_MODE_ISDEPRESSED
) {
662 KERNEL_DEBUG_CONSTANT(
663 MACHDBG_CODE(DBG_MACH_SCHED
,MACH_DEMOTE
) | DBG_FUNC_NONE
,
664 thread
->sched_pri
, DEPRESSPRI
, 0, (int)lck
, 0);
666 set_sched_pri(thread
, DEPRESSPRI
);
669 if (thread
->priority
< thread
->sched_pri
) {
670 KERNEL_DEBUG_CONSTANT(
671 MACHDBG_CODE(DBG_MACH_SCHED
,MACH_DEMOTE
) |
673 thread
->sched_pri
, thread
->priority
,
677 compute_priority(thread
, FALSE
);
680 thread_unlock(thread
);
683 assert(mutex
->lck_mtx_waiters
> 0);
684 thread_wakeup_one((event_t
)(((unsigned int*)lck
)+(sizeof(lck_mtx_t
)-1)/sizeof(unsigned int)));
686 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_UNLCK_WAKEUP_CODE
) | DBG_FUNC_END
, 0, 0, 0, 0, 0);
690 * Routine: mutex_pause
692 * Called by former callers of simple_lock_pause().
698 wait_result_t wait_result
;
700 wait_result
= assert_wait_timeout((event_t
)mutex_pause
, THREAD_UNINT
, 1, 1000*NSEC_PER_USEC
);
701 assert(wait_result
== THREAD_WAITING
);
703 wait_result
= thread_block(THREAD_CONTINUE_NULL
);
704 assert(wait_result
== THREAD_TIMED_OUT
);
708 * Routine: lck_rw_sleep
713 lck_sleep_action_t lck_sleep_action
,
715 wait_interrupt_t interruptible
)
718 lck_rw_type_t lck_rw_type
;
720 if ((lck_sleep_action
& ~LCK_SLEEP_MASK
) != 0)
721 panic("Invalid lock sleep action %x\n", lck_sleep_action
);
723 res
= assert_wait(event
, interruptible
);
724 if (res
== THREAD_WAITING
) {
725 lck_rw_type
= lck_rw_done(lck
);
726 res
= thread_block(THREAD_CONTINUE_NULL
);
727 if (!(lck_sleep_action
& LCK_SLEEP_UNLOCK
)) {
728 if (!(lck_sleep_action
& (LCK_SLEEP_SHARED
|LCK_SLEEP_EXCLUSIVE
)))
729 lck_rw_lock(lck
, lck_rw_type
);
730 else if (lck_sleep_action
& LCK_SLEEP_EXCLUSIVE
)
731 lck_rw_lock_exclusive(lck
);
733 lck_rw_lock_shared(lck
);
737 if (lck_sleep_action
& LCK_SLEEP_UNLOCK
)
738 (void)lck_rw_done(lck
);
745 * Routine: lck_rw_sleep_deadline
748 lck_rw_sleep_deadline(
750 lck_sleep_action_t lck_sleep_action
,
752 wait_interrupt_t interruptible
,
756 lck_rw_type_t lck_rw_type
;
758 if ((lck_sleep_action
& ~LCK_SLEEP_MASK
) != 0)
759 panic("Invalid lock sleep action %x\n", lck_sleep_action
);
761 res
= assert_wait_deadline(event
, interruptible
, deadline
);
762 if (res
== THREAD_WAITING
) {
763 lck_rw_type
= lck_rw_done(lck
);
764 res
= thread_block(THREAD_CONTINUE_NULL
);
765 if (!(lck_sleep_action
& LCK_SLEEP_UNLOCK
)) {
766 if (!(lck_sleep_action
& (LCK_SLEEP_SHARED
|LCK_SLEEP_EXCLUSIVE
)))
767 lck_rw_lock(lck
, lck_rw_type
);
768 else if (lck_sleep_action
& LCK_SLEEP_EXCLUSIVE
)
769 lck_rw_lock_exclusive(lck
);
771 lck_rw_lock_shared(lck
);
775 if (lck_sleep_action
& LCK_SLEEP_UNLOCK
)
776 (void)lck_rw_done(lck
);
784 lockgroup_info_array_t
*lockgroup_infop
,
785 mach_msg_type_number_t
*lockgroup_infoCntp
)
787 lockgroup_info_t
*lockgroup_info_base
;
788 lockgroup_info_t
*lockgroup_info
;
789 vm_offset_t lockgroup_info_addr
;
790 vm_size_t lockgroup_info_size
;
797 if (host
== HOST_NULL
)
798 return KERN_INVALID_HOST
;
800 mutex_lock(&lck_grp_lock
);
802 lockgroup_info_size
= round_page(lck_grp_cnt
* sizeof *lockgroup_info
);
803 kr
= kmem_alloc_pageable(ipc_kernel_map
,
804 &lockgroup_info_addr
, lockgroup_info_size
);
805 if (kr
!= KERN_SUCCESS
) {
806 mutex_unlock(&lck_grp_lock
);
810 lockgroup_info_base
= (lockgroup_info_t
*) lockgroup_info_addr
;
811 lck_grp
= (lck_grp_t
*)queue_first(&lck_grp_queue
);
812 lockgroup_info
= lockgroup_info_base
;
814 for (i
= 0; i
< lck_grp_cnt
; i
++) {
816 lockgroup_info
->lock_spin_cnt
= lck_grp
->lck_grp_spincnt
;
817 lockgroup_info
->lock_spin_util_cnt
= lck_grp
->lck_grp_stat
.lck_grp_spin_stat
.lck_grp_spin_util_cnt
;
818 lockgroup_info
->lock_spin_held_cnt
= lck_grp
->lck_grp_stat
.lck_grp_spin_stat
.lck_grp_spin_held_cnt
;
819 lockgroup_info
->lock_spin_miss_cnt
= lck_grp
->lck_grp_stat
.lck_grp_spin_stat
.lck_grp_spin_miss_cnt
;
820 lockgroup_info
->lock_spin_held_max
= lck_grp
->lck_grp_stat
.lck_grp_spin_stat
.lck_grp_spin_held_max
;
821 lockgroup_info
->lock_spin_held_cum
= lck_grp
->lck_grp_stat
.lck_grp_spin_stat
.lck_grp_spin_held_cum
;
823 lockgroup_info
->lock_mtx_cnt
= lck_grp
->lck_grp_mtxcnt
;
824 lockgroup_info
->lock_mtx_util_cnt
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_util_cnt
;
825 lockgroup_info
->lock_mtx_held_cnt
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_held_cnt
;
826 lockgroup_info
->lock_mtx_miss_cnt
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_miss_cnt
;
827 lockgroup_info
->lock_mtx_wait_cnt
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_wait_cnt
;
828 lockgroup_info
->lock_mtx_held_max
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_held_max
;
829 lockgroup_info
->lock_mtx_held_cum
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_held_cum
;
830 lockgroup_info
->lock_mtx_wait_max
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_wait_max
;
831 lockgroup_info
->lock_mtx_wait_cum
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_wait_cum
;
833 lockgroup_info
->lock_rw_cnt
= lck_grp
->lck_grp_rwcnt
;
834 lockgroup_info
->lock_rw_util_cnt
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_util_cnt
;
835 lockgroup_info
->lock_rw_held_cnt
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_held_cnt
;
836 lockgroup_info
->lock_rw_miss_cnt
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_miss_cnt
;
837 lockgroup_info
->lock_rw_wait_cnt
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_wait_cnt
;
838 lockgroup_info
->lock_rw_held_max
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_held_max
;
839 lockgroup_info
->lock_rw_held_cum
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_held_cum
;
840 lockgroup_info
->lock_rw_wait_max
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_wait_max
;
841 lockgroup_info
->lock_rw_wait_cum
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_wait_cum
;
843 (void) strncpy(lockgroup_info
->lockgroup_name
,lck_grp
->lck_grp_name
, LOCKGROUP_MAX_NAME
);
845 lck_grp
= (lck_grp_t
*)(queue_next((queue_entry_t
)(lck_grp
)));
849 *lockgroup_infoCntp
= lck_grp_cnt
;
850 mutex_unlock(&lck_grp_lock
);
852 used
= (*lockgroup_infoCntp
) * sizeof *lockgroup_info
;
854 if (used
!= lockgroup_info_size
)
855 bzero((char *) lockgroup_info
, lockgroup_info_size
- used
);
857 kr
= vm_map_copyin(ipc_kernel_map
, (vm_map_address_t
)lockgroup_info_addr
,
858 (vm_map_size_t
)lockgroup_info_size
, TRUE
, ©
);
859 assert(kr
== KERN_SUCCESS
);
861 *lockgroup_infop
= (lockgroup_info_t
*) copy
;
863 return(KERN_SUCCESS
);
867 * Compatibility module
870 extern lck_rw_t
*lock_alloc_EXT( boolean_t can_sleep
, unsigned short tag0
, unsigned short tag1
);
871 extern void lock_done_EXT(lck_rw_t
*lock
);
872 extern void lock_free_EXT(lck_rw_t
*lock
);
873 extern void lock_init_EXT(lck_rw_t
*lock
, boolean_t can_sleep
, unsigned short tag0
, unsigned short tag1
);
874 extern void lock_read_EXT(lck_rw_t
*lock
);
875 extern boolean_t
lock_read_to_write_EXT(lck_rw_t
*lock
);
876 extern void lock_write_EXT(lck_rw_t
*lock
);
877 extern void lock_write_to_read_EXT(lck_rw_t
*lock
);
878 extern wait_result_t
thread_sleep_lock_write_EXT(
879 event_t event
, lck_rw_t
*lock
, wait_interrupt_t interruptible
);
881 extern lck_mtx_t
*mutex_alloc_EXT(unsigned short tag
);
882 extern void mutex_free_EXT(lck_mtx_t
*mutex
);
883 extern void mutex_init_EXT(lck_mtx_t
*mutex
, unsigned short tag
);
884 extern void mutex_lock_EXT(lck_mtx_t
*mutex
);
885 extern boolean_t
mutex_try_EXT(lck_mtx_t
*mutex
);
886 extern void mutex_unlock_EXT(lck_mtx_t
*mutex
);
887 extern wait_result_t
thread_sleep_mutex_EXT(
888 event_t event
, lck_mtx_t
*mutex
, wait_interrupt_t interruptible
);
889 extern wait_result_t
thread_sleep_mutex_deadline_EXT(
890 event_t event
, lck_mtx_t
*mutex
, uint64_t deadline
, wait_interrupt_t interruptible
);
892 extern void usimple_lock_EXT(lck_spin_t
*lock
);
893 extern void usimple_lock_init_EXT(lck_spin_t
*lock
, unsigned short tag
);
894 extern unsigned int usimple_lock_try_EXT(lck_spin_t
*lock
);
895 extern void usimple_unlock_EXT(lck_spin_t
*lock
);
896 extern wait_result_t
thread_sleep_usimple_lock_EXT(event_t event
, lck_spin_t
*lock
, wait_interrupt_t interruptible
);
900 __unused boolean_t can_sleep
,
901 __unused
unsigned short tag0
,
902 __unused
unsigned short tag1
)
904 return( lck_rw_alloc_init( &LockCompatGroup
, LCK_ATTR_NULL
));
911 (void) lck_rw_done(lock
);
918 lck_rw_free(lock
, &LockCompatGroup
);
924 __unused boolean_t can_sleep
,
925 __unused
unsigned short tag0
,
926 __unused
unsigned short tag1
)
928 lck_rw_init(lock
, &LockCompatGroup
, LCK_ATTR_NULL
);
935 lck_rw_lock_shared( lock
);
939 lock_read_to_write_EXT(
942 return( lck_rw_lock_shared_to_exclusive(lock
));
949 lck_rw_lock_exclusive(lock
);
953 lock_write_to_read_EXT(
956 lck_rw_lock_exclusive_to_shared(lock
);
960 thread_sleep_lock_write_EXT(
963 wait_interrupt_t interruptible
)
965 return( lck_rw_sleep(lock
, LCK_SLEEP_EXCLUSIVE
, event
, interruptible
));
970 __unused
unsigned short tag
)
972 return(lck_mtx_alloc_init(&LockCompatGroup
, LCK_ATTR_NULL
));
979 lck_mtx_free(mutex
, &LockCompatGroup
);
985 __unused
unsigned short tag
)
987 lck_mtx_init(mutex
, &LockCompatGroup
, LCK_ATTR_NULL
);
1001 return(lck_mtx_try_lock(mutex
));
1008 lck_mtx_unlock(mutex
);
1012 thread_sleep_mutex_EXT(
1015 wait_interrupt_t interruptible
)
1017 return( lck_mtx_sleep(mutex
, LCK_SLEEP_DEFAULT
, event
, interruptible
));
1021 thread_sleep_mutex_deadline_EXT(
1025 wait_interrupt_t interruptible
)
1027 return( lck_mtx_sleep_deadline(mutex
, LCK_SLEEP_DEFAULT
, event
, interruptible
, deadline
));
1034 lck_spin_lock(lock
);
1038 usimple_lock_init_EXT(
1040 __unused
unsigned short tag
)
1042 lck_spin_init(lock
, &LockCompatGroup
, LCK_ATTR_NULL
);
1046 usimple_lock_try_EXT(
1049 return(lck_spin_try_lock(lock
));
1056 lck_spin_unlock(lock
);
1060 thread_sleep_usimple_lock_EXT(
1063 wait_interrupt_t interruptible
)
1065 return( lck_spin_sleep(lock
, LCK_SLEEP_DEFAULT
, event
, interruptible
));