Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Add a new command, show lockstat, which shows statistics of ...



details:   https://anonhg.NetBSD.org/src/rev/9741d41eb7b3
branches:  trunk
changeset: 831193:9741d41eb7b3
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Fri Mar 16 04:37:55 2018 +0000

description:
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.

diffstat:

 share/man/man4/ddb.4      |   8 +++++-
 sys/ddb/db_command.c      |  18 +++++++++++++-
 sys/kern/subr_lockdebug.c |  54 +++++++++++++++++++++++++++++++++++++++++++++-
 sys/sys/lockdebug.h       |   3 +-
 4 files changed, 76 insertions(+), 7 deletions(-)

diffs (174 lines):

diff -r 8a62643e17b4 -r 9741d41eb7b3 share/man/man4/ddb.4
--- a/share/man/man4/ddb.4      Fri Mar 16 03:19:38 2018 +0000
+++ b/share/man/man4/ddb.4      Fri Mar 16 04:37:55 2018 +0000
@@ -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.
 .\" All rights reserved.
@@ -56,7 +56,7 @@
 .\" any improvements or extensions that they make and grant Carnegie Mellon
 .\" the rights to redistribute these changes.
 .\"
-.Dd February 17, 2018
+.Dd March 16, 2018
 .Dt DDB 4
 .Os
 .Sh NAME
@@ -650,6 +650,10 @@
 .Ar address .
 This command is useful only if a kernel is compiled with
 .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
 Print the vm_map at
 .Ar address .
diff -r 8a62643e17b4 -r 9741d41eb7b3 sys/ddb/db_command.c
--- a/sys/ddb/db_command.c      Fri Mar 16 03:19:38 2018 +0000
+++ b/sys/ddb/db_command.c      Fri Mar 16 04:37:55 2018 +0000
@@ -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.
@@ -60,7 +60,7 @@
  */
 
 #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
 #include "opt_aio.h"
@@ -190,6 +190,7 @@
 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_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_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 *);
@@ -248,6 +249,9 @@
            "Print the files open by process at address",
            "[/f] address", 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,
            "Print the vm_map at address.", "[/f] address",NULL) },
        { DDB_ADD_CMD("module", db_show_module_cmd,     0,
@@ -1226,6 +1230,16 @@
 #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:
  * !expr(arg,arg,arg)
diff -r 8a62643e17b4 -r 9741d41eb7b3 sys/kern/subr_lockdebug.c
--- a/sys/kern/subr_lockdebug.c Fri Mar 16 03:19:38 2018 +0000
+++ b/sys/kern/subr_lockdebug.c Fri Mar 16 04:37:55 2018 +0000
@@ -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.
@@ -34,7 +34,7 @@
  */
 
 #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
 #include "opt_ddb.h"
@@ -838,6 +838,56 @@
        (*pr)("Sorry, kernel not built with the LOCKDEBUG option.\n");
 #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 */
 
 /*
diff -r 8a62643e17b4 -r 9741d41eb7b3 sys/sys/lockdebug.h
--- a/sys/sys/lockdebug.h       Fri Mar 16 03:19:38 2018 +0000
+++ b/sys/sys/lockdebug.h       Fri Mar 16 04:37:55 2018 +0000
@@ -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.
@@ -58,6 +58,7 @@
 
 void   lockdebug_lock_print(void *, void (*)(const char *, ...)
     __printflike(1, 2));
+void   lockdebug_show_lockstat(void (*)(const char *, ...) __printflike(1, 2));
 
 #ifdef LOCKDEBUG
 



Home | Main Index | Thread Index | Old Index