Skip Navigation Links | |
Exit Print View | |
man pages section 9: DDI and DKI Kernel Functions Oracle Solaris 11 Information Library |
csx_AccessConfigurationRegister(9F)
csx_Parse_CISTPL_BYTEORDER(9F)
csx_Parse_CISTPL_CFTABLE_ENTRY(9F)
csx_Parse_CISTPL_DEVICEGEO(9F)
csx_Parse_CISTPL_DEVICEGEO_A(9F)
csx_Parse_CISTPL_DEVICE_OA(9F)
csx_Parse_CISTPL_DEVICE_OC(9F)
csx_Parse_CISTPL_LINKTARGET(9F)
csx_Parse_CISTPL_LONGLINK_A(9F)
csx_Parse_CISTPL_LONGLINK_C(9F)
csx_Parse_CISTPL_LONGLINK_MFC(9F)
ddi_get_soft_iblock_cookie(9F)
ddi_intr_get_supported_types(9F)
ddi_prop_lookup_byte_array(9F)
ddi_prop_lookup_int64_array(9F)
ddi_prop_lookup_string_array(9F)
ddi_prop_update_byte_array(9F)
ddi_prop_update_int64_array(9F)
ddi_prop_update_string_array(9F)
ldi_prop_lookup_byte_array(9F)
ldi_prop_lookup_int64_array(9F)
ldi_prop_lookup_string_array(9F)
mac_prop_info_set_default_link_flowctrl(9F)
mac_prop_info_set_default_str(9F)
mac_prop_info_set_default_uint8(9F)
mac_prop_info_set_range_uint32(9F)
net_event_notify_unregister(9F)
net_instance_notify_register(9F)
net_instance_notify_unregister(9F)
net_instance_protocol_unregister(9F)
net_protocol_notify_register(9F)
nvlist_lookup_boolean_array(9F)
nvlist_lookup_boolean_value(9F)
nvlist_lookup_nvlist_array(9F)
nvlist_lookup_string_array(9F)
nvlist_lookup_uint16_array(9F)
nvlist_lookup_uint32_array(9F)
nvlist_lookup_uint64_array(9F)
nvpair_value_boolean_array(9F)
pci_plist_lookup_int16_array(9F)
pci_plist_lookup_int32_array(9F)
pci_plist_lookup_int64_array(9F)
pci_plist_lookup_int8_array(9F)
pci_plist_lookup_string_array(9F)
pci_plist_lookup_uint16_array(9F)
pci_plist_lookup_uint32_array(9F)
pci_plist_lookup_uint64_array(9F)
pci_plist_lookup_uint8_array(9F)
scsi_get_device_type_scsi_options(9F)
scsi_get_device_type_string(9F)
scsi_sense_cmdspecific_uint64(9F)
usb_get_current_frame_number(9F)
usb_get_max_pkts_per_isoc_request(9F)
usb_pipe_get_max_bulk_transfer_size(9F)
usb_pipe_stop_intr_polling(9F)
usb_pipe_stop_isoc_polling(9F)
- mutual exclusion lock routines
#include <sys/ksynch.h> void mutex_init(kmutex_t *mp, char *name, kmutex_type_t type, void *arg);
void mutex_destroy(kmutex_t *mp);
void mutex_enter(kmutex_t *mp);
void mutex_exit(kmutex_t *mp);
int mutex_owned(kmutex_t *mp);
int mutex_tryenter(kmutex_t *mp);
Solaris DDI specific (Solaris DDI).
Pointer to a kernel mutex lock (kmutex_t).
Descriptive string. This is obsolete and should be NULL. (Non-NULL strings are legal, but they are a waste of kernel memory.)
Type of mutex lock.
Type-specific argument for initialization routine.
A mutex enforces a policy of mutual exclusion. Only one thread at a time may hold a particular mutex. Threads trying to lock a held mutex will block until the mutex is unlocked.
Mutexes are strictly bracketing and may not be recursively locked, meaning that mutexes should be exited in the opposite order they were entered, and cannot be reentered before exiting.
mutex_init() initializes a mutex. It is an error to initialize a mutex more than once.
The type argument specifies the type of mutex lock. The basic mutex type is MUTEX_ADAPTIVE, which is expected to be used in almost all of the kernel. MUTEX_SPIN provides interrupt blocking and must be used in interrupt handlers above LOCK_LEVEL. The iblock cookie argument to mutex_init() encodes the interrupt level to block. The iblock cookie must be NULL for adaptive locks.
MUTEX_DEFAULT is the type usually specified (except in drivers) to mutex_init(). It is identical to MUTEX_ADAPTIVE.
MUTEX_DRIVER is always used by drivers. mutex_init() converts this to either MUTEX_ADAPTIVE or MUTEX_SPIN, depending on the iblock cookie.
The arg argument provides type-specific information for a given variant type of mutex. When mutex_init() is called for driver mutexes, if the mutex is used by the interrupt handler, the arg should be the interrupt priority returned from ddi_intr_get_pri(9F) or ddi_intr_get_softint_pri(9F). Note that arg should be the value of the interrupt priority cast by calling the DDI_INTR_PRI macro. If the mutex is never used inside an interrupt handler, the argument should be NULL.
mutex_enter() is used to acquire a mutex. If the mutex is already held, then the caller blocks. After returning, the calling thread is the owner of the mutex. If the mutex is already held by the calling thread, a panic ensues.
mutex_owned() should only be used in ASSERT() and may be enforced by not being defined unless the preprocessor symbol DEBUG is defined. Its return value is non-zero if the current thread (or, if that cannot be determined, at least some thread) holds the mutex pointed to by mp.
mutex_tryenter() is very similar to mutex_enter() except that it doesn't block when the mutex is already held. mutex_tryenter() returns non-zero when it acquired the mutex and 0 when the mutex is already held.
mutex_exit() releases a mutex and will unblock another thread if any are blocked on the mutex.
mutex_destroy() releases any resources that might have been allocated by mutex_init(). mutex_destroy() must be called before freeing the memory containing the mutex, and should be called with the mutex unheld (not owned by any thread). The caller must be sure that no other thread attempts to use the mutex.
mutex_tryenter() returns a non-zero value on success and zero on failure.
mutex_owned() returns a non-zero value if the calling thread currently holds the mutex pointed to by mp, or when that cannot be determined, if any thread holds the mutex. Otherwise mutex_owned() returns zero.
These functions can be called from user, kernel, or high-level interrupt context, except for mutex_init() and mutex_destroy(), which can be called from user or kernel context only.
Example 1 Initializing a Mutex
A driver might do this to initialize a mutex that is part of its unit structure and used in its interrupt routine:
ddi_intr_get_pri(hdlp, &pri); mutex_init(&un->un_lock, NULL, MUTEX_DRIVER, DDI_INTR_PRI(pri)); ddi_intr_add_handler(hdlp, xxintr, (caddr_t)un, NULL);
Example 2 Calling a Routine with a Lock
A routine that expects to be called with a certain lock held might have the following ASSERT:
xxstart(struct xxunit *un) { ASSERT(mutex_owned(&un->un_lock)); ...
lockstat(1M), lockstat(7D), Intro(9F), condvar(9F), ddi_intr_alloc(9F), ddi_intr_add_handler(9F), ddi_intr_get_pri(9F), ddi_intr_get_softint_pri(9F), rwlock(9F), semaphore(9F)
Compiling with _LOCKTEST or _MPSTATS defined has no effect. To gather lock statistics, see lockstat(1M). Mutex statistics can be gathered on the fly, without rebooting or recompiling the kernel, via the lockstat(7D) driver.
The address of a kmutex_t lock must be aligned on an 8-byte boundary for 64-bit kernels, or a 4-byte boundary for 32-bit kernels. Violation of this requirement will result in undefined behavior, including, but not limited to, failure of mutual exclusion or a system panic.
To write scalable, responsive drivers that do not hang, panic or deadlock the system, follow these guidelines:
|