10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*5295Srandyf * Common Development and Distribution License (the "License"). 6*5295Srandyf * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*5295Srandyf * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate #include <sys/param.h> 290Sstevel@tonic-gate #include <sys/t_lock.h> 300Sstevel@tonic-gate #include <sys/types.h> 310Sstevel@tonic-gate #include <sys/time.h> 320Sstevel@tonic-gate #include <sys/sysmacros.h> 330Sstevel@tonic-gate #include <sys/systm.h> 340Sstevel@tonic-gate #include <sys/cpuvar.h> 350Sstevel@tonic-gate #include <sys/user.h> 360Sstevel@tonic-gate #include <sys/proc.h> 370Sstevel@tonic-gate #include <sys/callb.h> 380Sstevel@tonic-gate #include <sys/kmem.h> 390Sstevel@tonic-gate #include <sys/cmn_err.h> 400Sstevel@tonic-gate #include <sys/swap.h> 410Sstevel@tonic-gate #include <sys/vmsystm.h> 420Sstevel@tonic-gate #include <sys/class.h> 430Sstevel@tonic-gate #include <sys/debug.h> 440Sstevel@tonic-gate #include <sys/thread.h> 450Sstevel@tonic-gate #include <sys/kobj.h> 460Sstevel@tonic-gate #include <sys/ddi.h> /* for delay() */ 470Sstevel@tonic-gate #include <sys/taskq.h> /* For TASKQ_NAMELEN */ 480Sstevel@tonic-gate 490Sstevel@tonic-gate #define CB_MAXNAME TASKQ_NAMELEN 500Sstevel@tonic-gate 510Sstevel@tonic-gate /* 520Sstevel@tonic-gate * The callb mechanism provides generic event scheduling/echoing. 530Sstevel@tonic-gate * A callb function is registered and called on behalf of the event. 540Sstevel@tonic-gate */ 550Sstevel@tonic-gate typedef struct callb { 560Sstevel@tonic-gate struct callb *c_next; /* next in class or on freelist */ 570Sstevel@tonic-gate kthread_id_t c_thread; /* ptr to caller's thread struct */ 580Sstevel@tonic-gate char c_flag; /* info about the callb state */ 590Sstevel@tonic-gate uchar_t c_class; /* this callb's class */ 600Sstevel@tonic-gate kcondvar_t c_done_cv; /* signal callb completion */ 610Sstevel@tonic-gate boolean_t (*c_func)(); /* cb function: returns true if ok */ 620Sstevel@tonic-gate void *c_arg; /* arg to c_func */ 630Sstevel@tonic-gate char c_name[CB_MAXNAME+1]; /* debug:max func name length */ 640Sstevel@tonic-gate } callb_t; 650Sstevel@tonic-gate 660Sstevel@tonic-gate /* 670Sstevel@tonic-gate * callb c_flag bitmap definitions 680Sstevel@tonic-gate */ 690Sstevel@tonic-gate #define CALLB_FREE 0x0 700Sstevel@tonic-gate #define CALLB_TAKEN 0x1 710Sstevel@tonic-gate #define CALLB_EXECUTING 0x2 720Sstevel@tonic-gate 730Sstevel@tonic-gate /* 740Sstevel@tonic-gate * Basic structure for a callb table. 750Sstevel@tonic-gate * All callbs are organized into different class groups described 760Sstevel@tonic-gate * by ct_class array. 770Sstevel@tonic-gate * The callbs within a class are single-linked and normally run by a 780Sstevel@tonic-gate * serial execution. 790Sstevel@tonic-gate */ 800Sstevel@tonic-gate typedef struct callb_table { 810Sstevel@tonic-gate kmutex_t ct_lock; /* protect all callb states */ 820Sstevel@tonic-gate callb_t *ct_freelist; /* free callb structures */ 830Sstevel@tonic-gate int ct_busy; /* != 0 prevents additions */ 840Sstevel@tonic-gate kcondvar_t ct_busy_cv; /* to wait for not busy */ 850Sstevel@tonic-gate int ct_ncallb; /* num of callbs allocated */ 860Sstevel@tonic-gate callb_t *ct_first_cb[NCBCLASS]; /* ptr to 1st callb in a class */ 870Sstevel@tonic-gate } callb_table_t; 880Sstevel@tonic-gate 890Sstevel@tonic-gate int callb_timeout_sec = CPR_KTHREAD_TIMEOUT_SEC; 900Sstevel@tonic-gate 910Sstevel@tonic-gate static callb_id_t callb_add_common(boolean_t (*)(void *, int), 920Sstevel@tonic-gate void *, int, char *, kthread_id_t); 930Sstevel@tonic-gate 940Sstevel@tonic-gate static callb_table_t callb_table; /* system level callback table */ 950Sstevel@tonic-gate static callb_table_t *ct = &callb_table; 960Sstevel@tonic-gate static kmutex_t callb_safe_mutex; 970Sstevel@tonic-gate callb_cpr_t callb_cprinfo_safe = { 980Sstevel@tonic-gate &callb_safe_mutex, CALLB_CPR_ALWAYS_SAFE, 0, 0, 0 }; 990Sstevel@tonic-gate 1000Sstevel@tonic-gate /* 1010Sstevel@tonic-gate * Init all callb tables in the system. 1020Sstevel@tonic-gate */ 1030Sstevel@tonic-gate void 1040Sstevel@tonic-gate callb_init() 1050Sstevel@tonic-gate { 1060Sstevel@tonic-gate callb_table.ct_busy = 0; /* mark table open for additions */ 1070Sstevel@tonic-gate mutex_init(&callb_safe_mutex, NULL, MUTEX_DEFAULT, NULL); 1080Sstevel@tonic-gate mutex_init(&callb_table.ct_lock, NULL, MUTEX_DEFAULT, NULL); 1090Sstevel@tonic-gate } 1100Sstevel@tonic-gate 1110Sstevel@tonic-gate /* 1120Sstevel@tonic-gate * callout_add() is called to register func() be called later. 1130Sstevel@tonic-gate */ 1140Sstevel@tonic-gate static callb_id_t 1150Sstevel@tonic-gate callb_add_common(boolean_t (*func)(void *arg, int code), 1160Sstevel@tonic-gate void *arg, int class, char *name, kthread_id_t t) 1170Sstevel@tonic-gate { 1180Sstevel@tonic-gate callb_t *cp; 1190Sstevel@tonic-gate 1200Sstevel@tonic-gate ASSERT(class < NCBCLASS); 1210Sstevel@tonic-gate 1220Sstevel@tonic-gate mutex_enter(&ct->ct_lock); 1230Sstevel@tonic-gate while (ct->ct_busy) 1240Sstevel@tonic-gate cv_wait(&ct->ct_busy_cv, &ct->ct_lock); 1250Sstevel@tonic-gate if ((cp = ct->ct_freelist) == NULL) { 1260Sstevel@tonic-gate ct->ct_ncallb++; 1270Sstevel@tonic-gate cp = (callb_t *)kmem_zalloc(sizeof (callb_t), KM_SLEEP); 1280Sstevel@tonic-gate } 1290Sstevel@tonic-gate ct->ct_freelist = cp->c_next; 1300Sstevel@tonic-gate cp->c_thread = t; 1310Sstevel@tonic-gate cp->c_func = func; 1320Sstevel@tonic-gate cp->c_arg = arg; 1330Sstevel@tonic-gate cp->c_class = (uchar_t)class; 1340Sstevel@tonic-gate cp->c_flag |= CALLB_TAKEN; 1350Sstevel@tonic-gate #ifdef DEBUG 1360Sstevel@tonic-gate if (strlen(name) > CB_MAXNAME) 1370Sstevel@tonic-gate cmn_err(CE_WARN, "callb_add: name of callback function '%s' " 1380Sstevel@tonic-gate "too long -- truncated to %d chars", 1390Sstevel@tonic-gate name, CB_MAXNAME); 1400Sstevel@tonic-gate #endif 1410Sstevel@tonic-gate (void) strncpy(cp->c_name, name, CB_MAXNAME); 1420Sstevel@tonic-gate cp->c_name[CB_MAXNAME] = '\0'; 1430Sstevel@tonic-gate 1440Sstevel@tonic-gate /* 1450Sstevel@tonic-gate * Insert the new callb at the head of its class list. 1460Sstevel@tonic-gate */ 1470Sstevel@tonic-gate cp->c_next = ct->ct_first_cb[class]; 1480Sstevel@tonic-gate ct->ct_first_cb[class] = cp; 1490Sstevel@tonic-gate 1500Sstevel@tonic-gate mutex_exit(&ct->ct_lock); 1510Sstevel@tonic-gate return ((callb_id_t)cp); 1520Sstevel@tonic-gate } 1530Sstevel@tonic-gate 1540Sstevel@tonic-gate /* 1550Sstevel@tonic-gate * The default function to add an entry to the callback table. Since 1560Sstevel@tonic-gate * it uses curthread as the thread identifier to store in the table, 1570Sstevel@tonic-gate * it should be used for the normal case of a thread which is calling 1580Sstevel@tonic-gate * to add ITSELF to the table. 1590Sstevel@tonic-gate */ 1600Sstevel@tonic-gate callb_id_t 1610Sstevel@tonic-gate callb_add(boolean_t (*func)(void *arg, int code), 1620Sstevel@tonic-gate void *arg, int class, char *name) 1630Sstevel@tonic-gate { 1640Sstevel@tonic-gate return (callb_add_common(func, arg, class, name, curthread)); 1650Sstevel@tonic-gate } 1660Sstevel@tonic-gate 1670Sstevel@tonic-gate /* 1680Sstevel@tonic-gate * A special version of callb_add() above for use by threads which 1690Sstevel@tonic-gate * might be adding an entry to the table on behalf of some other 1700Sstevel@tonic-gate * thread (for example, one which is constructed but not yet running). 1710Sstevel@tonic-gate * In this version the thread id is an argument. 1720Sstevel@tonic-gate */ 1730Sstevel@tonic-gate callb_id_t 1740Sstevel@tonic-gate callb_add_thread(boolean_t (*func)(void *arg, int code), 1750Sstevel@tonic-gate void *arg, int class, char *name, kthread_id_t t) 1760Sstevel@tonic-gate { 1770Sstevel@tonic-gate return (callb_add_common(func, arg, class, name, t)); 1780Sstevel@tonic-gate } 1790Sstevel@tonic-gate 1800Sstevel@tonic-gate /* 1810Sstevel@tonic-gate * callout_delete() is called to remove an entry identified by id 1820Sstevel@tonic-gate * that was originally placed there by a call to callout_add(). 1830Sstevel@tonic-gate * return -1 if fail to delete a callb entry otherwise return 0. 1840Sstevel@tonic-gate */ 1850Sstevel@tonic-gate int 1860Sstevel@tonic-gate callb_delete(callb_id_t id) 1870Sstevel@tonic-gate { 1880Sstevel@tonic-gate callb_t **pp; 1890Sstevel@tonic-gate callb_t *me = (callb_t *)id; 1900Sstevel@tonic-gate 1910Sstevel@tonic-gate mutex_enter(&ct->ct_lock); 1920Sstevel@tonic-gate 1930Sstevel@tonic-gate for (;;) { 1940Sstevel@tonic-gate pp = &ct->ct_first_cb[me->c_class]; 1950Sstevel@tonic-gate while (*pp != NULL && *pp != me) 1960Sstevel@tonic-gate pp = &(*pp)->c_next; 1970Sstevel@tonic-gate 1980Sstevel@tonic-gate #ifdef DEBUG 1990Sstevel@tonic-gate if (*pp != me) { 2000Sstevel@tonic-gate cmn_err(CE_WARN, "callb delete bogus entry 0x%p", 2010Sstevel@tonic-gate (void *)me); 2020Sstevel@tonic-gate mutex_exit(&ct->ct_lock); 2030Sstevel@tonic-gate return (-1); 2040Sstevel@tonic-gate } 2050Sstevel@tonic-gate #endif /* DEBUG */ 2060Sstevel@tonic-gate 2070Sstevel@tonic-gate /* 2080Sstevel@tonic-gate * It is not allowed to delete a callb in the middle of 2090Sstevel@tonic-gate * executing otherwise, the callb_execute() will be confused. 2100Sstevel@tonic-gate */ 2110Sstevel@tonic-gate if (!(me->c_flag & CALLB_EXECUTING)) 2120Sstevel@tonic-gate break; 2130Sstevel@tonic-gate 2140Sstevel@tonic-gate cv_wait(&me->c_done_cv, &ct->ct_lock); 2150Sstevel@tonic-gate } 2160Sstevel@tonic-gate /* relink the class list */ 2170Sstevel@tonic-gate *pp = me->c_next; 2180Sstevel@tonic-gate 2190Sstevel@tonic-gate /* clean up myself and return the free callb to the head of freelist */ 2200Sstevel@tonic-gate me->c_flag = CALLB_FREE; 2210Sstevel@tonic-gate me->c_next = ct->ct_freelist; 2220Sstevel@tonic-gate ct->ct_freelist = me; 2230Sstevel@tonic-gate 2240Sstevel@tonic-gate mutex_exit(&ct->ct_lock); 2250Sstevel@tonic-gate return (0); 2260Sstevel@tonic-gate } 2270Sstevel@tonic-gate 2280Sstevel@tonic-gate /* 2290Sstevel@tonic-gate * class: indicates to execute all callbs in the same class; 2300Sstevel@tonic-gate * code: optional argument for the callb functions. 2310Sstevel@tonic-gate * return: = 0: success 2320Sstevel@tonic-gate * != 0: ptr to string supplied when callback was registered 2330Sstevel@tonic-gate */ 2340Sstevel@tonic-gate void * 2350Sstevel@tonic-gate callb_execute_class(int class, int code) 2360Sstevel@tonic-gate { 2370Sstevel@tonic-gate callb_t *cp; 2380Sstevel@tonic-gate void *ret = NULL; 2390Sstevel@tonic-gate 2400Sstevel@tonic-gate ASSERT(class < NCBCLASS); 2410Sstevel@tonic-gate 2420Sstevel@tonic-gate mutex_enter(&ct->ct_lock); 2430Sstevel@tonic-gate 2440Sstevel@tonic-gate for (cp = ct->ct_first_cb[class]; 2450Sstevel@tonic-gate cp != NULL && ret == 0; cp = cp->c_next) { 2460Sstevel@tonic-gate while (cp->c_flag & CALLB_EXECUTING) 2470Sstevel@tonic-gate cv_wait(&cp->c_done_cv, &ct->ct_lock); 2480Sstevel@tonic-gate /* 2490Sstevel@tonic-gate * cont if the callb is deleted while we're sleeping 2500Sstevel@tonic-gate */ 2510Sstevel@tonic-gate if (cp->c_flag == CALLB_FREE) 2520Sstevel@tonic-gate continue; 2530Sstevel@tonic-gate cp->c_flag |= CALLB_EXECUTING; 2540Sstevel@tonic-gate 2550Sstevel@tonic-gate #ifdef CALLB_DEBUG 2560Sstevel@tonic-gate printf("callb_execute: name=%s func=%p arg=%p\n", 257*5295Srandyf cp->c_name, (void *)cp->c_func, (void *)cp->c_arg); 2580Sstevel@tonic-gate #endif /* CALLB_DEBUG */ 2590Sstevel@tonic-gate 2600Sstevel@tonic-gate mutex_exit(&ct->ct_lock); 2610Sstevel@tonic-gate /* If callback function fails, pass back client's name */ 2620Sstevel@tonic-gate if (!(*cp->c_func)(cp->c_arg, code)) 2630Sstevel@tonic-gate ret = cp->c_name; 2640Sstevel@tonic-gate mutex_enter(&ct->ct_lock); 2650Sstevel@tonic-gate 2660Sstevel@tonic-gate cp->c_flag &= ~CALLB_EXECUTING; 2670Sstevel@tonic-gate cv_broadcast(&cp->c_done_cv); 2680Sstevel@tonic-gate } 2690Sstevel@tonic-gate mutex_exit(&ct->ct_lock); 2700Sstevel@tonic-gate return (ret); 2710Sstevel@tonic-gate } 2720Sstevel@tonic-gate 2730Sstevel@tonic-gate /* 2740Sstevel@tonic-gate * callers make sure no recursive entries to this func. 2750Sstevel@tonic-gate * dp->cc_lockp is registered by callb_add to protect callb_cpr_t structure. 2760Sstevel@tonic-gate * 2770Sstevel@tonic-gate * When calling to stop a kernel thread (code == CB_CODE_CPR_CHKPT) we 2780Sstevel@tonic-gate * use a cv_timedwait() in case the kernel thread is blocked. 2790Sstevel@tonic-gate * 2800Sstevel@tonic-gate * Note that this is a generic callback handler for daemon CPR and 2810Sstevel@tonic-gate * should NOT be changed to accommodate any specific requirement in a daemon. 2820Sstevel@tonic-gate * Individual daemons that require changes to the handler shall write 2830Sstevel@tonic-gate * callback routines in their own daemon modules. 2840Sstevel@tonic-gate */ 2850Sstevel@tonic-gate boolean_t 2860Sstevel@tonic-gate callb_generic_cpr(void *arg, int code) 2870Sstevel@tonic-gate { 2880Sstevel@tonic-gate callb_cpr_t *cp = (callb_cpr_t *)arg; 2890Sstevel@tonic-gate clock_t ret = 0; /* assume success */ 2900Sstevel@tonic-gate 2910Sstevel@tonic-gate mutex_enter(cp->cc_lockp); 2920Sstevel@tonic-gate 2930Sstevel@tonic-gate switch (code) { 2940Sstevel@tonic-gate case CB_CODE_CPR_CHKPT: 2950Sstevel@tonic-gate cp->cc_events |= CALLB_CPR_START; 296*5295Srandyf #ifdef CPR_NOT_THREAD_SAFE 2970Sstevel@tonic-gate while (!(cp->cc_events & CALLB_CPR_SAFE)) 2980Sstevel@tonic-gate /* cv_timedwait() returns -1 if it times out. */ 2990Sstevel@tonic-gate if ((ret = cv_timedwait(&cp->cc_callb_cv, 3000Sstevel@tonic-gate cp->cc_lockp, 3010Sstevel@tonic-gate lbolt + callb_timeout_sec * hz)) == -1) 3020Sstevel@tonic-gate break; 303*5295Srandyf #endif 3040Sstevel@tonic-gate break; 3050Sstevel@tonic-gate 3060Sstevel@tonic-gate case CB_CODE_CPR_RESUME: 3070Sstevel@tonic-gate cp->cc_events &= ~CALLB_CPR_START; 3080Sstevel@tonic-gate cv_signal(&cp->cc_stop_cv); 3090Sstevel@tonic-gate break; 3100Sstevel@tonic-gate } 3110Sstevel@tonic-gate mutex_exit(cp->cc_lockp); 3120Sstevel@tonic-gate return (ret != -1); 3130Sstevel@tonic-gate } 3140Sstevel@tonic-gate 3150Sstevel@tonic-gate /* 3160Sstevel@tonic-gate * The generic callback function associated with kernel threads which 3170Sstevel@tonic-gate * are always considered safe. 3180Sstevel@tonic-gate */ 3190Sstevel@tonic-gate /* ARGSUSED */ 3200Sstevel@tonic-gate boolean_t 3210Sstevel@tonic-gate callb_generic_cpr_safe(void *arg, int code) 3220Sstevel@tonic-gate { 3230Sstevel@tonic-gate return (B_TRUE); 3240Sstevel@tonic-gate } 3250Sstevel@tonic-gate /* 3260Sstevel@tonic-gate * Prevent additions to callback table. 3270Sstevel@tonic-gate */ 3280Sstevel@tonic-gate void 3290Sstevel@tonic-gate callb_lock_table(void) 3300Sstevel@tonic-gate { 3310Sstevel@tonic-gate mutex_enter(&ct->ct_lock); 3320Sstevel@tonic-gate ASSERT(ct->ct_busy == 0); 3330Sstevel@tonic-gate ct->ct_busy = 1; 3340Sstevel@tonic-gate mutex_exit(&ct->ct_lock); 3350Sstevel@tonic-gate } 3360Sstevel@tonic-gate 3370Sstevel@tonic-gate /* 3380Sstevel@tonic-gate * Allow additions to callback table. 3390Sstevel@tonic-gate */ 3400Sstevel@tonic-gate void 3410Sstevel@tonic-gate callb_unlock_table(void) 3420Sstevel@tonic-gate { 3430Sstevel@tonic-gate mutex_enter(&ct->ct_lock); 3440Sstevel@tonic-gate ASSERT(ct->ct_busy != 0); 3450Sstevel@tonic-gate ct->ct_busy = 0; 3460Sstevel@tonic-gate cv_broadcast(&ct->ct_busy_cv); 3470Sstevel@tonic-gate mutex_exit(&ct->ct_lock); 3480Sstevel@tonic-gate } 3490Sstevel@tonic-gate 3500Sstevel@tonic-gate /* 3510Sstevel@tonic-gate * Return a boolean value indicating whether a particular kernel thread is 3520Sstevel@tonic-gate * stopped in accordance with the cpr callback protocol. If returning 3530Sstevel@tonic-gate * false, also return a pointer to the thread name via the 2nd argument. 3540Sstevel@tonic-gate */ 3550Sstevel@tonic-gate boolean_t 3560Sstevel@tonic-gate callb_is_stopped(kthread_id_t tp, caddr_t *thread_name) 3570Sstevel@tonic-gate { 3580Sstevel@tonic-gate callb_t *cp; 3590Sstevel@tonic-gate boolean_t ret_val; 3600Sstevel@tonic-gate 3610Sstevel@tonic-gate mutex_enter(&ct->ct_lock); 3620Sstevel@tonic-gate 3630Sstevel@tonic-gate for (cp = ct->ct_first_cb[CB_CL_CPR_DAEMON]; 3640Sstevel@tonic-gate cp != NULL && tp != cp->c_thread; cp = cp->c_next) 3650Sstevel@tonic-gate ; 3660Sstevel@tonic-gate 3670Sstevel@tonic-gate ret_val = (cp != NULL); 3680Sstevel@tonic-gate if (ret_val) { 3690Sstevel@tonic-gate /* 3700Sstevel@tonic-gate * We found the thread in the callback table and have 3710Sstevel@tonic-gate * provisionally set the return value to true. Now 3720Sstevel@tonic-gate * see if it is marked "safe" and is sleeping or stopped. 3730Sstevel@tonic-gate */ 3740Sstevel@tonic-gate callb_cpr_t *ccp = (callb_cpr_t *)cp->c_arg; 3750Sstevel@tonic-gate 3760Sstevel@tonic-gate *thread_name = cp->c_name; /* in case not stopped */ 3770Sstevel@tonic-gate mutex_enter(ccp->cc_lockp); 3780Sstevel@tonic-gate 3790Sstevel@tonic-gate if (ccp->cc_events & CALLB_CPR_SAFE) { 3800Sstevel@tonic-gate int retry; 3810Sstevel@tonic-gate 3820Sstevel@tonic-gate mutex_exit(ccp->cc_lockp); 3830Sstevel@tonic-gate for (retry = 0; retry < CALLB_MAX_RETRY; retry++) { 3840Sstevel@tonic-gate thread_lock(tp); 3850Sstevel@tonic-gate if (tp->t_state & (TS_SLEEP | TS_STOPPED)) { 3860Sstevel@tonic-gate thread_unlock(tp); 3870Sstevel@tonic-gate break; 3880Sstevel@tonic-gate } 3890Sstevel@tonic-gate thread_unlock(tp); 3900Sstevel@tonic-gate delay(CALLB_THREAD_DELAY); 3910Sstevel@tonic-gate } 3920Sstevel@tonic-gate ret_val = retry < CALLB_MAX_RETRY; 3930Sstevel@tonic-gate } else { 3940Sstevel@tonic-gate ret_val = 3950Sstevel@tonic-gate (ccp->cc_events & CALLB_CPR_ALWAYS_SAFE) != 0; 3960Sstevel@tonic-gate mutex_exit(ccp->cc_lockp); 3970Sstevel@tonic-gate } 3980Sstevel@tonic-gate } else { 3990Sstevel@tonic-gate /* 4000Sstevel@tonic-gate * Thread not found in callback table. Make the best 4010Sstevel@tonic-gate * attempt to identify the thread in the error message. 4020Sstevel@tonic-gate */ 4030Sstevel@tonic-gate ulong_t offset; 4040Sstevel@tonic-gate char *sym = kobj_getsymname((uintptr_t)tp->t_startpc, 4050Sstevel@tonic-gate &offset); 4060Sstevel@tonic-gate 4070Sstevel@tonic-gate *thread_name = sym ? sym : "*unknown*"; 4080Sstevel@tonic-gate } 4090Sstevel@tonic-gate 4100Sstevel@tonic-gate mutex_exit(&ct->ct_lock); 4110Sstevel@tonic-gate return (ret_val); 4120Sstevel@tonic-gate } 413