Add a new command, show lockstat, which shows statistics of locks
Currently the command shows the number of allocated locks. The command is useful only if LOCKDEBUG is enabled.
This commit is contained in:
parent
753e9171b0
commit
1d919413b1
|
@ -1,4 +1,4 @@
|
||||||
.\" $NetBSD: ddb.4,v 1.174 2018/02/19 10:31:53 wiz Exp $
|
.\" $NetBSD: ddb.4,v 1.175 2018/03/16 04:37:55 ozaki-r Exp $
|
||||||
.\"
|
.\"
|
||||||
.\" Copyright (c) 1997 - 2009 The NetBSD Foundation, Inc.
|
.\" Copyright (c) 1997 - 2009 The NetBSD Foundation, Inc.
|
||||||
.\" All rights reserved.
|
.\" All rights reserved.
|
||||||
|
@ -56,7 +56,7 @@
|
||||||
.\" any improvements or extensions that they make and grant Carnegie Mellon
|
.\" any improvements or extensions that they make and grant Carnegie Mellon
|
||||||
.\" the rights to redistribute these changes.
|
.\" the rights to redistribute these changes.
|
||||||
.\"
|
.\"
|
||||||
.Dd February 17, 2018
|
.Dd March 16, 2018
|
||||||
.Dt DDB 4
|
.Dt DDB 4
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
|
@ -650,6 +650,10 @@ Display information about a lock at
|
||||||
.Ar address .
|
.Ar address .
|
||||||
This command is useful only if a kernel is compiled with
|
This command is useful only if a kernel is compiled with
|
||||||
.Cd options LOCKDEBUG .
|
.Cd options LOCKDEBUG .
|
||||||
|
.It Ic show lockstat
|
||||||
|
Display information about statistics of locks.
|
||||||
|
This command is useful only if a kernel is compiled with
|
||||||
|
.Cd options LOCKDEBUG .
|
||||||
.It Ic show map Ns Oo Cm /f Oc Ar address
|
.It Ic show map Ns Oo Cm /f Oc Ar address
|
||||||
Print the vm_map at
|
Print the vm_map at
|
||||||
.Ar address .
|
.Ar address .
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: db_command.c,v 1.149 2018/03/04 07:14:50 mlelstv Exp $ */
|
/* $NetBSD: db_command.c,v 1.150 2018/03/16 04:37:55 ozaki-r Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1996, 1997, 1998, 1999, 2002, 2009 The NetBSD Foundation, Inc.
|
* Copyright (c) 1996, 1997, 1998, 1999, 2002, 2009 The NetBSD Foundation, Inc.
|
||||||
|
@ -60,7 +60,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
__KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.149 2018/03/04 07:14:50 mlelstv Exp $");
|
__KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.150 2018/03/16 04:37:55 ozaki-r Exp $");
|
||||||
|
|
||||||
#ifdef _KERNEL_OPT
|
#ifdef _KERNEL_OPT
|
||||||
#include "opt_aio.h"
|
#include "opt_aio.h"
|
||||||
|
@ -190,6 +190,7 @@ static void db_event_print_cmd(db_expr_t, bool, db_expr_t, const char *);
|
||||||
static void db_fncall(db_expr_t, bool, db_expr_t, const char *);
|
static void db_fncall(db_expr_t, bool, db_expr_t, const char *);
|
||||||
static void db_help_print_cmd(db_expr_t, bool, db_expr_t, const char *);
|
static void db_help_print_cmd(db_expr_t, bool, db_expr_t, const char *);
|
||||||
static void db_lock_print_cmd(db_expr_t, bool, db_expr_t, const char *);
|
static void db_lock_print_cmd(db_expr_t, bool, db_expr_t, const char *);
|
||||||
|
static void db_show_lockstat(db_expr_t, bool, db_expr_t, const char *);
|
||||||
static void db_mount_print_cmd(db_expr_t, bool, db_expr_t, const char *);
|
static void db_mount_print_cmd(db_expr_t, bool, db_expr_t, const char *);
|
||||||
static void db_mbuf_print_cmd(db_expr_t, bool, db_expr_t, const char *);
|
static void db_mbuf_print_cmd(db_expr_t, bool, db_expr_t, const char *);
|
||||||
static void db_map_print_cmd(db_expr_t, bool, db_expr_t, const char *);
|
static void db_map_print_cmd(db_expr_t, bool, db_expr_t, const char *);
|
||||||
|
@ -248,6 +249,9 @@ static const struct db_command db_show_cmds[] = {
|
||||||
"Print the files open by process at address",
|
"Print the files open by process at address",
|
||||||
"[/f] address", NULL) },
|
"[/f] address", NULL) },
|
||||||
{ DDB_ADD_CMD("lock", db_lock_print_cmd, 0,NULL,NULL,NULL) },
|
{ DDB_ADD_CMD("lock", db_lock_print_cmd, 0,NULL,NULL,NULL) },
|
||||||
|
{ DDB_ADD_CMD("lockstat",
|
||||||
|
db_show_lockstat, 0,
|
||||||
|
"Print statistics of locks", NULL, NULL) },
|
||||||
{ DDB_ADD_CMD("map", db_map_print_cmd, 0,
|
{ DDB_ADD_CMD("map", db_map_print_cmd, 0,
|
||||||
"Print the vm_map at address.", "[/f] address",NULL) },
|
"Print the vm_map at address.", "[/f] address",NULL) },
|
||||||
{ DDB_ADD_CMD("module", db_show_module_cmd, 0,
|
{ DDB_ADD_CMD("module", db_show_module_cmd, 0,
|
||||||
|
@ -1226,6 +1230,16 @@ db_lock_print_cmd(db_expr_t addr, bool have_addr,
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
db_show_lockstat(db_expr_t addr, bool have_addr,
|
||||||
|
db_expr_t count, const char *modif)
|
||||||
|
{
|
||||||
|
|
||||||
|
#ifdef _KERNEL /* XXX CRASH(8) */
|
||||||
|
lockdebug_show_lockstat(db_printf);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Call random function:
|
* Call random function:
|
||||||
* !expr(arg,arg,arg)
|
* !expr(arg,arg,arg)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: subr_lockdebug.c,v 1.60 2018/02/20 03:34:52 ozaki-r Exp $ */
|
/* $NetBSD: subr_lockdebug.c,v 1.61 2018/03/16 04:43:37 ozaki-r Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
|
* Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
|
||||||
|
@ -34,7 +34,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
__KERNEL_RCSID(0, "$NetBSD: subr_lockdebug.c,v 1.60 2018/02/20 03:34:52 ozaki-r Exp $");
|
__KERNEL_RCSID(0, "$NetBSD: subr_lockdebug.c,v 1.61 2018/03/16 04:43:37 ozaki-r Exp $");
|
||||||
|
|
||||||
#ifdef _KERNEL_OPT
|
#ifdef _KERNEL_OPT
|
||||||
#include "opt_ddb.h"
|
#include "opt_ddb.h"
|
||||||
|
@ -838,6 +838,56 @@ lockdebug_lock_print(void *addr, void (*pr)(const char *, ...))
|
||||||
(*pr)("Sorry, kernel not built with the LOCKDEBUG option.\n");
|
(*pr)("Sorry, kernel not built with the LOCKDEBUG option.\n");
|
||||||
#endif /* LOCKDEBUG */
|
#endif /* LOCKDEBUG */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
lockdebug_show_lockstat(void (*pr)(const char *, ...))
|
||||||
|
{
|
||||||
|
#ifdef LOCKDEBUG
|
||||||
|
lockdebug_t *ld;
|
||||||
|
void *_ld;
|
||||||
|
uint32_t n_null = 0;
|
||||||
|
uint32_t n_spin_mutex = 0;
|
||||||
|
uint32_t n_adaptive_mutex = 0;
|
||||||
|
uint32_t n_rwlock = 0;
|
||||||
|
uint32_t n_cv = 0;
|
||||||
|
uint32_t n_others = 0;
|
||||||
|
|
||||||
|
RB_TREE_FOREACH(_ld, &ld_rb_tree) {
|
||||||
|
ld = _ld;
|
||||||
|
if (ld->ld_lock == NULL) {
|
||||||
|
n_null++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (ld->ld_lockops->lo_type == LOCKOPS_CV) {
|
||||||
|
n_cv++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (ld->ld_lockops->lo_name[0] == 'M') {
|
||||||
|
if (ld->ld_lockops->lo_type == LOCKOPS_SLEEP)
|
||||||
|
n_adaptive_mutex++;
|
||||||
|
else
|
||||||
|
n_spin_mutex++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (ld->ld_lockops->lo_name[0] == 'R') {
|
||||||
|
n_rwlock++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
n_others++;
|
||||||
|
}
|
||||||
|
(*pr)(
|
||||||
|
"condvar: %u\n"
|
||||||
|
"spin mutex: %u\n"
|
||||||
|
"adaptive mutex: %u\n"
|
||||||
|
"rwlock: %u\n"
|
||||||
|
"null locks: %u\n"
|
||||||
|
"others: %u\n",
|
||||||
|
n_cv, n_spin_mutex, n_adaptive_mutex, n_rwlock,
|
||||||
|
n_null, n_others);
|
||||||
|
#else
|
||||||
|
(*pr)("Sorry, kernel not built with the LOCKDEBUG option.\n");
|
||||||
|
#endif /* LOCKDEBUG */
|
||||||
|
}
|
||||||
#endif /* DDB */
|
#endif /* DDB */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: lockdebug.h,v 1.16 2017/09/16 23:54:41 christos Exp $ */
|
/* $NetBSD: lockdebug.h,v 1.17 2018/03/16 04:37:55 ozaki-r Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
|
* Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
|
||||||
|
@ -58,6 +58,7 @@ void lockdebug_abort(const char *, size_t, const volatile void *,
|
||||||
|
|
||||||
void lockdebug_lock_print(void *, void (*)(const char *, ...)
|
void lockdebug_lock_print(void *, void (*)(const char *, ...)
|
||||||
__printflike(1, 2));
|
__printflike(1, 2));
|
||||||
|
void lockdebug_show_lockstat(void (*)(const char *, ...) __printflike(1, 2));
|
||||||
|
|
||||||
#ifdef LOCKDEBUG
|
#ifdef LOCKDEBUG
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue