Changeset View
Changeset View
Standalone View
Standalone View
head/sys/kern/subr_witness.c
Show First 20 Lines • Show All 2,533 Lines • ▼ Show 20 Lines | |||||
DB_SHOW_COMMAND(witness, db_witness_display) | DB_SHOW_COMMAND(witness, db_witness_display) | ||||
{ | { | ||||
witness_ddb_display(db_printf); | witness_ddb_display(db_printf); | ||||
} | } | ||||
#endif | #endif | ||||
static int | static void | ||||
sysctl_debug_witness_badstacks(SYSCTL_HANDLER_ARGS) | sbuf_print_witness_badstacks(struct sbuf *sb) | ||||
{ | { | ||||
struct witness_lock_order_data *data1, *data2, *tmp_data1, *tmp_data2; | struct witness_lock_order_data *data1, *data2, *tmp_data1, *tmp_data2; | ||||
struct witness *tmp_w1, *tmp_w2, *w1, *w2; | struct witness *tmp_w1, *tmp_w2, *w1, *w2; | ||||
struct sbuf *sb; | |||||
u_int w_rmatrix1, w_rmatrix2; | u_int w_rmatrix1, w_rmatrix2; | ||||
int error, generation, i, j; | int generation, i, j; | ||||
tmp_data1 = NULL; | tmp_data1 = NULL; | ||||
tmp_data2 = NULL; | tmp_data2 = NULL; | ||||
tmp_w1 = NULL; | tmp_w1 = NULL; | ||||
tmp_w2 = NULL; | tmp_w2 = NULL; | ||||
if (witness_watch < 1) { | |||||
error = SYSCTL_OUT(req, w_notrunning, sizeof(w_notrunning)); | |||||
return (error); | |||||
} | |||||
if (witness_cold) { | |||||
error = SYSCTL_OUT(req, w_stillcold, sizeof(w_stillcold)); | |||||
return (error); | |||||
} | |||||
error = 0; | |||||
sb = sbuf_new(NULL, NULL, badstack_sbuf_size, SBUF_AUTOEXTEND); | |||||
if (sb == NULL) | |||||
return (ENOMEM); | |||||
/* Allocate and init temporary storage space. */ | /* Allocate and init temporary storage space. */ | ||||
tmp_w1 = malloc(sizeof(struct witness), M_TEMP, M_WAITOK | M_ZERO); | tmp_w1 = malloc(sizeof(struct witness), M_TEMP, M_WAITOK | M_ZERO); | ||||
tmp_w2 = malloc(sizeof(struct witness), M_TEMP, M_WAITOK | M_ZERO); | tmp_w2 = malloc(sizeof(struct witness), M_TEMP, M_WAITOK | M_ZERO); | ||||
tmp_data1 = malloc(sizeof(struct witness_lock_order_data), M_TEMP, | tmp_data1 = malloc(sizeof(struct witness_lock_order_data), M_TEMP, | ||||
M_WAITOK | M_ZERO); | M_WAITOK | M_ZERO); | ||||
tmp_data2 = malloc(sizeof(struct witness_lock_order_data), M_TEMP, | tmp_data2 = malloc(sizeof(struct witness_lock_order_data), M_TEMP, | ||||
M_WAITOK | M_ZERO); | M_WAITOK | M_ZERO); | ||||
▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Lines | restart: | ||||
} | } | ||||
mtx_unlock_spin(&w_mtx); | mtx_unlock_spin(&w_mtx); | ||||
/* Free temporary storage space. */ | /* Free temporary storage space. */ | ||||
free(tmp_data1, M_TEMP); | free(tmp_data1, M_TEMP); | ||||
free(tmp_data2, M_TEMP); | free(tmp_data2, M_TEMP); | ||||
free(tmp_w1, M_TEMP); | free(tmp_w1, M_TEMP); | ||||
free(tmp_w2, M_TEMP); | free(tmp_w2, M_TEMP); | ||||
} | |||||
static int | |||||
sysctl_debug_witness_badstacks(SYSCTL_HANDLER_ARGS) | |||||
{ | |||||
struct sbuf *sb; | |||||
int error; | |||||
if (witness_watch < 1) { | |||||
error = SYSCTL_OUT(req, w_notrunning, sizeof(w_notrunning)); | |||||
return (error); | |||||
} | |||||
if (witness_cold) { | |||||
error = SYSCTL_OUT(req, w_stillcold, sizeof(w_stillcold)); | |||||
return (error); | |||||
} | |||||
error = 0; | |||||
sb = sbuf_new(NULL, NULL, badstack_sbuf_size, SBUF_AUTOEXTEND); | |||||
if (sb == NULL) | |||||
return (ENOMEM); | |||||
sbuf_print_witness_badstacks(sb); | |||||
sbuf_finish(sb); | sbuf_finish(sb); | ||||
error = SYSCTL_OUT(req, sbuf_data(sb), sbuf_len(sb) + 1); | error = SYSCTL_OUT(req, sbuf_data(sb), sbuf_len(sb) + 1); | ||||
sbuf_delete(sb); | sbuf_delete(sb); | ||||
return (error); | return (error); | ||||
} | } | ||||
#ifdef DDB | |||||
static int | |||||
sbuf_db_printf_drain(void *arg __unused, const char *data, int len) | |||||
{ | |||||
return (db_printf("%.*s", len, data)); | |||||
} | |||||
DB_SHOW_COMMAND(badstacks, db_witness_badstacks) | |||||
{ | |||||
struct sbuf sb; | |||||
char buffer[128]; | |||||
sbuf_new(&sb, buffer, sizeof(buffer), SBUF_FIXEDLEN); | |||||
sbuf_set_drain(&sb, sbuf_db_printf_drain, NULL); | |||||
sbuf_print_witness_badstacks(&sb); | |||||
sbuf_finish(&sb); | |||||
} | |||||
#endif | |||||
static int | static int | ||||
sysctl_debug_witness_channel(SYSCTL_HANDLER_ARGS) | sysctl_debug_witness_channel(SYSCTL_HANDLER_ARGS) | ||||
{ | { | ||||
static const struct { | static const struct { | ||||
enum witness_channel channel; | enum witness_channel channel; | ||||
const char *name; | const char *name; | ||||
} channels[] = { | } channels[] = { | ||||
▲ Show 20 Lines • Show All 326 Lines • Show Last 20 Lines |