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_free
357 kfree(attr
, sizeof(lck_attr_t
));
362 * Routine: lck_spin_sleep
367 lck_sleep_action_t lck_sleep_action
,
369 wait_interrupt_t interruptible
)
373 if ((lck_sleep_action
& ~LCK_SLEEP_MASK
) != 0)
374 panic("Invalid lock sleep action %x\n", lck_sleep_action
);
376 res
= assert_wait(event
, interruptible
);
377 if (res
== THREAD_WAITING
) {
378 lck_spin_unlock(lck
);
379 res
= thread_block(THREAD_CONTINUE_NULL
);
380 if (!(lck_sleep_action
& LCK_SLEEP_UNLOCK
))
384 if (lck_sleep_action
& LCK_SLEEP_UNLOCK
)
385 lck_spin_unlock(lck
);
392 * Routine: lck_spin_sleep_deadline
395 lck_spin_sleep_deadline(
397 lck_sleep_action_t lck_sleep_action
,
399 wait_interrupt_t interruptible
,
404 if ((lck_sleep_action
& ~LCK_SLEEP_MASK
) != 0)
405 panic("Invalid lock sleep action %x\n", lck_sleep_action
);
407 res
= assert_wait_deadline(event
, interruptible
, deadline
);
408 if (res
== THREAD_WAITING
) {
409 lck_spin_unlock(lck
);
410 res
= thread_block(THREAD_CONTINUE_NULL
);
411 if (!(lck_sleep_action
& LCK_SLEEP_UNLOCK
))
415 if (lck_sleep_action
& LCK_SLEEP_UNLOCK
)
416 lck_spin_unlock(lck
);
423 * Routine: lck_mtx_sleep
428 lck_sleep_action_t lck_sleep_action
,
430 wait_interrupt_t interruptible
)
434 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_SLEEP_CODE
) | DBG_FUNC_START
,
435 (int)lck
, (int)lck_sleep_action
, (int)event
, (int)interruptible
, 0);
437 if ((lck_sleep_action
& ~LCK_SLEEP_MASK
) != 0)
438 panic("Invalid lock sleep action %x\n", lck_sleep_action
);
440 res
= assert_wait(event
, interruptible
);
441 if (res
== THREAD_WAITING
) {
443 res
= thread_block(THREAD_CONTINUE_NULL
);
444 if (!(lck_sleep_action
& LCK_SLEEP_UNLOCK
))
448 if (lck_sleep_action
& LCK_SLEEP_UNLOCK
)
451 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_SLEEP_CODE
) | DBG_FUNC_END
, (int)res
, 0, 0, 0, 0);
458 * Routine: lck_mtx_sleep_deadline
461 lck_mtx_sleep_deadline(
463 lck_sleep_action_t lck_sleep_action
,
465 wait_interrupt_t interruptible
,
470 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_SLEEP_DEADLINE_CODE
) | DBG_FUNC_START
,
471 (int)lck
, (int)lck_sleep_action
, (int)event
, (int)interruptible
, 0);
473 if ((lck_sleep_action
& ~LCK_SLEEP_MASK
) != 0)
474 panic("Invalid lock sleep action %x\n", lck_sleep_action
);
476 res
= assert_wait_deadline(event
, interruptible
, deadline
);
477 if (res
== THREAD_WAITING
) {
479 res
= thread_block(THREAD_CONTINUE_NULL
);
480 if (!(lck_sleep_action
& LCK_SLEEP_UNLOCK
))
484 if (lck_sleep_action
& LCK_SLEEP_UNLOCK
)
487 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_SLEEP_DEADLINE_CODE
) | DBG_FUNC_END
, (int)res
, 0, 0, 0, 0);
493 * Routine: lck_mtx_lock_wait
495 * Invoked in order to wait on contention.
497 * Called with the interlock locked and
498 * returns it unlocked.
505 thread_t self
= current_thread();
508 spl_t s
= splsched();
510 if (lck
->lck_mtx_tag
!= LCK_MTX_TAG_INDIRECT
)
513 mutex
= &lck
->lck_mtx_ptr
->lck_mtx
;
515 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_LCK_WAIT_CODE
) | DBG_FUNC_START
, (int)lck
, (int)holder
, 0, 0, 0);
517 priority
= self
->sched_pri
;
518 if (priority
< self
->priority
)
519 priority
= self
->priority
;
520 if (priority
> MINPRI_KERNEL
)
521 priority
= MINPRI_KERNEL
;
523 if (priority
< BASEPRI_DEFAULT
)
524 priority
= BASEPRI_DEFAULT
;
527 if (mutex
->lck_mtx_pri
== 0)
528 holder
->promotions
++;
529 if (holder
->priority
< MINPRI_KERNEL
) {
530 holder
->sched_mode
|= TH_MODE_PROMOTED
;
531 if ( mutex
->lck_mtx_pri
< priority
&&
532 holder
->sched_pri
< priority
) {
533 KERNEL_DEBUG_CONSTANT(
534 MACHDBG_CODE(DBG_MACH_SCHED
,MACH_PROMOTE
) | DBG_FUNC_NONE
,
535 holder
->sched_pri
, priority
, (int)holder
, (int)lck
, 0);
537 set_sched_pri(holder
, priority
);
540 thread_unlock(holder
);
543 if (mutex
->lck_mtx_pri
< priority
)
544 mutex
->lck_mtx_pri
= priority
;
545 if (self
->pending_promoter
[self
->pending_promoter_index
] == NULL
) {
546 self
->pending_promoter
[self
->pending_promoter_index
] = mutex
;
547 mutex
->lck_mtx_waiters
++;
550 if (self
->pending_promoter
[self
->pending_promoter_index
] != mutex
) {
551 self
->pending_promoter
[++self
->pending_promoter_index
] = mutex
;
552 mutex
->lck_mtx_waiters
++;
555 assert_wait((event_t
)(((unsigned int*)lck
)+((sizeof(lck_mtx_t
)-1)/sizeof(unsigned int))), THREAD_UNINT
);
556 lck_mtx_ilk_unlock(mutex
);
558 thread_block(THREAD_CONTINUE_NULL
);
560 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_LCK_WAIT_CODE
) | DBG_FUNC_END
, 0, 0, 0, 0, 0);
564 * Routine: lck_mtx_lock_acquire
566 * Invoked on acquiring the mutex when there is
569 * Returns the current number of waiters.
571 * Called with the interlock locked.
574 lck_mtx_lock_acquire(
577 thread_t thread
= current_thread();
580 if (lck
->lck_mtx_tag
!= LCK_MTX_TAG_INDIRECT
)
583 mutex
= &lck
->lck_mtx_ptr
->lck_mtx
;
585 if (thread
->pending_promoter
[thread
->pending_promoter_index
] == mutex
) {
586 thread
->pending_promoter
[thread
->pending_promoter_index
] = NULL
;
587 if (thread
->pending_promoter_index
> 0)
588 thread
->pending_promoter_index
--;
589 mutex
->lck_mtx_waiters
--;
592 if (mutex
->lck_mtx_waiters
> 0) {
593 integer_t priority
= mutex
->lck_mtx_pri
;
594 spl_t s
= splsched();
597 thread
->promotions
++;
598 if (thread
->priority
< MINPRI_KERNEL
) {
599 thread
->sched_mode
|= TH_MODE_PROMOTED
;
600 if (thread
->sched_pri
< priority
) {
601 KERNEL_DEBUG_CONSTANT(
602 MACHDBG_CODE(DBG_MACH_SCHED
,MACH_PROMOTE
) | DBG_FUNC_NONE
,
603 thread
->sched_pri
, priority
, 0, (int)lck
, 0);
605 set_sched_pri(thread
, priority
);
608 thread_unlock(thread
);
612 mutex
->lck_mtx_pri
= 0;
614 return (mutex
->lck_mtx_waiters
);
618 * Routine: lck_mtx_unlock_wakeup
620 * Invoked on unlock when there is contention.
622 * Called with the interlock locked.
625 lck_mtx_unlock_wakeup (
629 thread_t thread
= current_thread();
632 if (lck
->lck_mtx_tag
!= LCK_MTX_TAG_INDIRECT
)
635 mutex
= &lck
->lck_mtx_ptr
->lck_mtx
;
638 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_UNLCK_WAKEUP_CODE
) | DBG_FUNC_START
, (int)lck
, (int)holder
, 0, 0, 0);
640 if (thread
!= holder
)
641 panic("lck_mtx_unlock_wakeup: mutex %x holder %x\n", mutex
, holder
);
643 if (thread
->promotions
> 0) {
644 spl_t s
= splsched();
647 if ( --thread
->promotions
== 0 &&
648 (thread
->sched_mode
& TH_MODE_PROMOTED
) ) {
649 thread
->sched_mode
&= ~TH_MODE_PROMOTED
;
650 if (thread
->sched_mode
& TH_MODE_ISDEPRESSED
) {
651 KERNEL_DEBUG_CONSTANT(
652 MACHDBG_CODE(DBG_MACH_SCHED
,MACH_DEMOTE
) | DBG_FUNC_NONE
,
653 thread
->sched_pri
, DEPRESSPRI
, 0, (int)lck
, 0);
655 set_sched_pri(thread
, DEPRESSPRI
);
658 if (thread
->priority
< thread
->sched_pri
) {
659 KERNEL_DEBUG_CONSTANT(
660 MACHDBG_CODE(DBG_MACH_SCHED
,MACH_DEMOTE
) |
662 thread
->sched_pri
, thread
->priority
,
666 compute_priority(thread
, FALSE
);
669 thread_unlock(thread
);
672 assert(mutex
->lck_mtx_waiters
> 0);
673 thread_wakeup_one((event_t
)(((unsigned int*)lck
)+(sizeof(lck_mtx_t
)-1)/sizeof(unsigned int)));
675 KERNEL_DEBUG(MACHDBG_CODE(DBG_MACH_LOCKS
, LCK_MTX_UNLCK_WAKEUP_CODE
) | DBG_FUNC_END
, 0, 0, 0, 0, 0);
679 * Routine: mutex_pause
681 * Called by former callers of simple_lock_pause().
687 wait_result_t wait_result
;
689 wait_result
= assert_wait_timeout((event_t
)mutex_pause
, THREAD_UNINT
, 1, 1000*NSEC_PER_USEC
);
690 assert(wait_result
== THREAD_WAITING
);
692 wait_result
= thread_block(THREAD_CONTINUE_NULL
);
693 assert(wait_result
== THREAD_TIMED_OUT
);
697 * Routine: lck_rw_sleep
702 lck_sleep_action_t lck_sleep_action
,
704 wait_interrupt_t interruptible
)
707 lck_rw_type_t lck_rw_type
;
709 if ((lck_sleep_action
& ~LCK_SLEEP_MASK
) != 0)
710 panic("Invalid lock sleep action %x\n", lck_sleep_action
);
712 res
= assert_wait(event
, interruptible
);
713 if (res
== THREAD_WAITING
) {
714 lck_rw_type
= lck_rw_done(lck
);
715 res
= thread_block(THREAD_CONTINUE_NULL
);
716 if (!(lck_sleep_action
& LCK_SLEEP_UNLOCK
)) {
717 if (!(lck_sleep_action
& (LCK_SLEEP_SHARED
|LCK_SLEEP_EXCLUSIVE
)))
718 lck_rw_lock(lck
, lck_rw_type
);
719 else if (lck_sleep_action
& LCK_SLEEP_EXCLUSIVE
)
720 lck_rw_lock_exclusive(lck
);
722 lck_rw_lock_shared(lck
);
726 if (lck_sleep_action
& LCK_SLEEP_UNLOCK
)
727 (void)lck_rw_done(lck
);
734 * Routine: lck_rw_sleep_deadline
737 lck_rw_sleep_deadline(
739 lck_sleep_action_t lck_sleep_action
,
741 wait_interrupt_t interruptible
,
745 lck_rw_type_t lck_rw_type
;
747 if ((lck_sleep_action
& ~LCK_SLEEP_MASK
) != 0)
748 panic("Invalid lock sleep action %x\n", lck_sleep_action
);
750 res
= assert_wait_deadline(event
, interruptible
, deadline
);
751 if (res
== THREAD_WAITING
) {
752 lck_rw_type
= lck_rw_done(lck
);
753 res
= thread_block(THREAD_CONTINUE_NULL
);
754 if (!(lck_sleep_action
& LCK_SLEEP_UNLOCK
)) {
755 if (!(lck_sleep_action
& (LCK_SLEEP_SHARED
|LCK_SLEEP_EXCLUSIVE
)))
756 lck_rw_lock(lck
, lck_rw_type
);
757 else if (lck_sleep_action
& LCK_SLEEP_EXCLUSIVE
)
758 lck_rw_lock_exclusive(lck
);
760 lck_rw_lock_shared(lck
);
764 if (lck_sleep_action
& LCK_SLEEP_UNLOCK
)
765 (void)lck_rw_done(lck
);
773 lockgroup_info_array_t
*lockgroup_infop
,
774 mach_msg_type_number_t
*lockgroup_infoCntp
)
776 lockgroup_info_t
*lockgroup_info_base
;
777 lockgroup_info_t
*lockgroup_info
;
778 vm_offset_t lockgroup_info_addr
;
779 vm_size_t lockgroup_info_size
;
786 if (host
== HOST_NULL
)
787 return KERN_INVALID_HOST
;
789 mutex_lock(&lck_grp_lock
);
791 lockgroup_info_size
= round_page(lck_grp_cnt
* sizeof *lockgroup_info
);
792 kr
= kmem_alloc_pageable(ipc_kernel_map
,
793 &lockgroup_info_addr
, lockgroup_info_size
);
794 if (kr
!= KERN_SUCCESS
) {
795 mutex_unlock(&lck_grp_lock
);
799 lockgroup_info_base
= (lockgroup_info_t
*) lockgroup_info_addr
;
800 lck_grp
= (lck_grp_t
*)queue_first(&lck_grp_queue
);
801 lockgroup_info
= lockgroup_info_base
;
803 for (i
= 0; i
< lck_grp_cnt
; i
++) {
805 lockgroup_info
->lock_spin_cnt
= lck_grp
->lck_grp_spincnt
;
806 lockgroup_info
->lock_spin_util_cnt
= lck_grp
->lck_grp_stat
.lck_grp_spin_stat
.lck_grp_spin_util_cnt
;
807 lockgroup_info
->lock_spin_held_cnt
= lck_grp
->lck_grp_stat
.lck_grp_spin_stat
.lck_grp_spin_held_cnt
;
808 lockgroup_info
->lock_spin_miss_cnt
= lck_grp
->lck_grp_stat
.lck_grp_spin_stat
.lck_grp_spin_miss_cnt
;
809 lockgroup_info
->lock_spin_held_max
= lck_grp
->lck_grp_stat
.lck_grp_spin_stat
.lck_grp_spin_held_max
;
810 lockgroup_info
->lock_spin_held_cum
= lck_grp
->lck_grp_stat
.lck_grp_spin_stat
.lck_grp_spin_held_cum
;
812 lockgroup_info
->lock_mtx_cnt
= lck_grp
->lck_grp_mtxcnt
;
813 lockgroup_info
->lock_mtx_util_cnt
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_util_cnt
;
814 lockgroup_info
->lock_mtx_held_cnt
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_held_cnt
;
815 lockgroup_info
->lock_mtx_miss_cnt
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_miss_cnt
;
816 lockgroup_info
->lock_mtx_wait_cnt
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_wait_cnt
;
817 lockgroup_info
->lock_mtx_held_max
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_held_max
;
818 lockgroup_info
->lock_mtx_held_cum
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_held_cum
;
819 lockgroup_info
->lock_mtx_wait_max
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_wait_max
;
820 lockgroup_info
->lock_mtx_wait_cum
= lck_grp
->lck_grp_stat
.lck_grp_mtx_stat
.lck_grp_mtx_wait_cum
;
822 lockgroup_info
->lock_rw_cnt
= lck_grp
->lck_grp_rwcnt
;
823 lockgroup_info
->lock_rw_util_cnt
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_util_cnt
;
824 lockgroup_info
->lock_rw_held_cnt
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_held_cnt
;
825 lockgroup_info
->lock_rw_miss_cnt
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_miss_cnt
;
826 lockgroup_info
->lock_rw_wait_cnt
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_wait_cnt
;
827 lockgroup_info
->lock_rw_held_max
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_held_max
;
828 lockgroup_info
->lock_rw_held_cum
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_held_cum
;
829 lockgroup_info
->lock_rw_wait_max
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_wait_max
;
830 lockgroup_info
->lock_rw_wait_cum
= lck_grp
->lck_grp_stat
.lck_grp_rw_stat
.lck_grp_rw_wait_cum
;
832 (void) strncpy(lockgroup_info
->lockgroup_name
,lck_grp
->lck_grp_name
, LOCKGROUP_MAX_NAME
);
834 lck_grp
= (lck_grp_t
*)(queue_next((queue_entry_t
)(lck_grp
)));
838 *lockgroup_infoCntp
= lck_grp_cnt
;
839 mutex_unlock(&lck_grp_lock
);
841 used
= (*lockgroup_infoCntp
) * sizeof *lockgroup_info
;
843 if (used
!= lockgroup_info_size
)
844 bzero((char *) lockgroup_info
, lockgroup_info_size
- used
);
846 kr
= vm_map_copyin(ipc_kernel_map
, (vm_map_address_t
)lockgroup_info_addr
,
847 (vm_map_size_t
)lockgroup_info_size
, TRUE
, ©
);
848 assert(kr
== KERN_SUCCESS
);
850 *lockgroup_infop
= (lockgroup_info_t
*) copy
;
852 return(KERN_SUCCESS
);
856 * Compatibility module
859 extern lck_rw_t
*lock_alloc_EXT( boolean_t can_sleep
, unsigned short tag0
, unsigned short tag1
);
860 extern void lock_done_EXT(lck_rw_t
*lock
);
861 extern void lock_free_EXT(lck_rw_t
*lock
);
862 extern void lock_init_EXT(lck_rw_t
*lock
, boolean_t can_sleep
, unsigned short tag0
, unsigned short tag1
);
863 extern void lock_read_EXT(lck_rw_t
*lock
);
864 extern boolean_t
lock_read_to_write_EXT(lck_rw_t
*lock
);
865 extern void lock_write_EXT(lck_rw_t
*lock
);
866 extern void lock_write_to_read_EXT(lck_rw_t
*lock
);
867 extern wait_result_t
thread_sleep_lock_write_EXT(
868 event_t event
, lck_rw_t
*lock
, wait_interrupt_t interruptible
);
870 extern lck_mtx_t
*mutex_alloc_EXT(unsigned short tag
);
871 extern void mutex_free_EXT(lck_mtx_t
*mutex
);
872 extern void mutex_init_EXT(lck_mtx_t
*mutex
, unsigned short tag
);
873 extern void mutex_lock_EXT(lck_mtx_t
*mutex
);
874 extern boolean_t
mutex_try_EXT(lck_mtx_t
*mutex
);
875 extern void mutex_unlock_EXT(lck_mtx_t
*mutex
);
876 extern wait_result_t
thread_sleep_mutex_EXT(
877 event_t event
, lck_mtx_t
*mutex
, wait_interrupt_t interruptible
);
878 extern wait_result_t
thread_sleep_mutex_deadline_EXT(
879 event_t event
, lck_mtx_t
*mutex
, uint64_t deadline
, wait_interrupt_t interruptible
);
881 extern void usimple_lock_EXT(lck_spin_t
*lock
);
882 extern void usimple_lock_init_EXT(lck_spin_t
*lock
, unsigned short tag
);
883 extern unsigned int usimple_lock_try_EXT(lck_spin_t
*lock
);
884 extern void usimple_unlock_EXT(lck_spin_t
*lock
);
885 extern wait_result_t
thread_sleep_usimple_lock_EXT(event_t event
, lck_spin_t
*lock
, wait_interrupt_t interruptible
);
889 __unused boolean_t can_sleep
,
890 __unused
unsigned short tag0
,
891 __unused
unsigned short tag1
)
893 return( lck_rw_alloc_init( &LockCompatGroup
, LCK_ATTR_NULL
));
900 (void) lck_rw_done(lock
);
907 lck_rw_free(lock
, &LockCompatGroup
);
913 __unused boolean_t can_sleep
,
914 __unused
unsigned short tag0
,
915 __unused
unsigned short tag1
)
917 lck_rw_init(lock
, &LockCompatGroup
, LCK_ATTR_NULL
);
924 lck_rw_lock_shared( lock
);
928 lock_read_to_write_EXT(
931 return( lck_rw_lock_shared_to_exclusive(lock
));
938 lck_rw_lock_exclusive(lock
);
942 lock_write_to_read_EXT(
945 lck_rw_lock_exclusive_to_shared(lock
);
949 thread_sleep_lock_write_EXT(
952 wait_interrupt_t interruptible
)
954 return( lck_rw_sleep(lock
, LCK_SLEEP_EXCLUSIVE
, event
, interruptible
));
959 __unused
unsigned short tag
)
961 return(lck_mtx_alloc_init(&LockCompatGroup
, LCK_ATTR_NULL
));
968 lck_mtx_free(mutex
, &LockCompatGroup
);
974 __unused
unsigned short tag
)
976 lck_mtx_init(mutex
, &LockCompatGroup
, LCK_ATTR_NULL
);
990 return(lck_mtx_try_lock(mutex
));
997 lck_mtx_unlock(mutex
);
1001 thread_sleep_mutex_EXT(
1004 wait_interrupt_t interruptible
)
1006 return( lck_mtx_sleep(mutex
, LCK_SLEEP_DEFAULT
, event
, interruptible
));
1010 thread_sleep_mutex_deadline_EXT(
1014 wait_interrupt_t interruptible
)
1016 return( lck_mtx_sleep_deadline(mutex
, LCK_SLEEP_DEFAULT
, event
, interruptible
, deadline
));
1023 lck_spin_lock(lock
);
1027 usimple_lock_init_EXT(
1029 __unused
unsigned short tag
)
1031 lck_spin_init(lock
, &LockCompatGroup
, LCK_ATTR_NULL
);
1035 usimple_lock_try_EXT(
1038 lck_spin_try_lock(lock
);
1045 lck_spin_unlock(lock
);
1049 thread_sleep_usimple_lock_EXT(
1052 wait_interrupt_t interruptible
)
1054 return( lck_spin_sleep(lock
, LCK_SLEEP_DEFAULT
, event
, interruptible
));