summaryrefslogtreecommitdiff
path: root/usr/src/cmd/mdb
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/cmd/mdb')
-rw-r--r--usr/src/cmd/mdb/common/mdb/mdb_ks.h8
-rw-r--r--usr/src/cmd/mdb/common/modules/conf/mapfile-extern2
-rw-r--r--usr/src/cmd/mdb/common/modules/genunix/genunix.c68
-rw-r--r--usr/src/cmd/mdb/common/modules/genunix/net.c3
-rw-r--r--usr/src/cmd/mdb/common/modules/idm/idm.c14
-rw-r--r--usr/src/cmd/mdb/common/modules/ip/ip.c4
-rw-r--r--usr/src/cmd/mdb/common/modules/mdb_ks/mdb_ks.c79
-rw-r--r--usr/src/cmd/mdb/common/modules/nca/nca.c21
8 files changed, 138 insertions, 61 deletions
diff --git a/usr/src/cmd/mdb/common/mdb/mdb_ks.h b/usr/src/cmd/mdb/common/mdb/mdb_ks.h
index 3ea1343492..9d48535161 100644
--- a/usr/src/cmd/mdb/common/mdb/mdb_ks.h
+++ b/usr/src/cmd/mdb/common/mdb/mdb_ks.h
@@ -19,15 +19,13 @@
* CDDL HEADER END
*/
/*
- * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _MDB_KS_H
#define _MDB_KS_H
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#include <sys/types.h>
#include <sys/int_types.h>
#include <sys/stream.h>
@@ -67,6 +65,9 @@ extern int mdb_cpu2cpuid(uintptr_t);
extern int mdb_cpuset_find(uintptr_t);
+extern hrtime_t mdb_gethrtime(void);
+extern int64_t mdb_get_lbolt(void);
+
/*
* Returns a pointer to the top of the soft state struct for the instance
* specified, given the address of the global soft state pointer and size
@@ -91,7 +92,6 @@ extern int mdb_get_soft_state_byname(char *, uint_t, uintptr_t *, void *,
*/
extern char *mdb_ddi_pathname(uintptr_t, char *, size_t);
-
/*
* MDB Kernel STREAMS Subsystem:
*
diff --git a/usr/src/cmd/mdb/common/modules/conf/mapfile-extern b/usr/src/cmd/mdb/common/modules/conf/mapfile-extern
index 4fc9613e1f..84f8426ef7 100644
--- a/usr/src/cmd/mdb/common/modules/conf/mapfile-extern
+++ b/usr/src/cmd/mdb/common/modules/conf/mapfile-extern
@@ -93,6 +93,8 @@
mdb_gelf_destroy = EXTERN;
mdb_gelf_sect_by_name = EXTERN;
mdb_gelf_sect_load = EXTERN;
+ mdb_gethrtime = EXTERN;
+ mdb_get_lbolt = EXTERN;
mdb_inc_indent = EXTERN;
mdb_io_destroy = EXTERN;
mdb_iob_clrflags = EXTERN;
diff --git a/usr/src/cmd/mdb/common/modules/genunix/genunix.c b/usr/src/cmd/mdb/common/modules/genunix/genunix.c
index e6fe3f7dcf..1687c34809 100644
--- a/usr/src/cmd/mdb/common/modules/genunix/genunix.c
+++ b/usr/src/cmd/mdb/common/modules/genunix/genunix.c
@@ -3083,7 +3083,6 @@ cpu_walk_step(mdb_walk_state_t *wsp)
typedef struct cpuinfo_data {
intptr_t cid_cpu;
- uintptr_t cid_lbolt;
uintptr_t **cid_ithr;
char cid_print_head;
char cid_print_thr;
@@ -3210,13 +3209,8 @@ cpuinfo_walk_cpu(uintptr_t addr, const cpu_t *cpu, cpuinfo_data_t *cid)
cpu->cpu_kprunrun ? "yes" : "no");
if (cpu->cpu_last_swtch) {
- clock_t lbolt;
-
- if (mdb_vread(&lbolt, sizeof (lbolt), cid->cid_lbolt) == -1) {
- mdb_warn("failed to read lbolt at %p", cid->cid_lbolt);
- return (WALK_ERR);
- }
- mdb_printf("t-%-4d ", lbolt - cpu->cpu_last_swtch);
+ mdb_printf("t-%-4d ",
+ (clock_t)mdb_get_lbolt() - cpu->cpu_last_swtch);
} else {
mdb_printf("%-6s ", "-");
}
@@ -3395,8 +3389,6 @@ cpuinfo(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
{
uint_t verbose = FALSE;
cpuinfo_data_t cid;
- GElf_Sym sym;
- clock_t lbolt;
cid.cid_print_ithr = FALSE;
cid.cid_print_thr = FALSE;
@@ -3435,26 +3427,6 @@ cpuinfo(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
}
}
- if (mdb_lookup_by_name("panic_lbolt", &sym) == -1) {
- mdb_warn("failed to find panic_lbolt");
- return (DCMD_ERR);
- }
-
- cid.cid_lbolt = (uintptr_t)sym.st_value;
-
- if (mdb_vread(&lbolt, sizeof (lbolt), cid.cid_lbolt) == -1) {
- mdb_warn("failed to read panic_lbolt");
- return (DCMD_ERR);
- }
-
- if (lbolt == 0) {
- if (mdb_lookup_by_name("lbolt", &sym) == -1) {
- mdb_warn("failed to find lbolt");
- return (DCMD_ERR);
- }
- cid.cid_lbolt = (uintptr_t)sym.st_value;
- }
-
if (mdb_walk("cpu", (mdb_walk_cb_t)cpuinfo_walk_cpu, &cid) == -1) {
mdb_warn("can't walk cpus");
return (DCMD_ERR);
@@ -4175,6 +4147,41 @@ panicinfo(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
return (DCMD_OK);
}
+/*
+ * ::time dcmd, which will print a hires timestamp of when we entered the
+ * debugger, or the lbolt value if used with the -l option.
+ *
+ */
+/*ARGSUSED*/
+static int
+time(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
+{
+ uint_t opt_lbolt = FALSE;
+
+ if (mdb_getopts(argc, argv, 'l', MDB_OPT_SETBITS, TRUE, &opt_lbolt,
+ NULL) != argc)
+ return (DCMD_USAGE);
+
+ if (opt_lbolt)
+ mdb_printf("%ld\n", mdb_get_lbolt());
+ else
+ mdb_printf("%lld\n", mdb_gethrtime());
+
+ return (DCMD_OK);
+}
+
+void
+time_help(void)
+{
+ mdb_printf("Prints the system time in nanoseconds.\n\n"
+ "::time will return the timestamp at which we dropped into, if "
+ "called from, kmdb(1); the core dump's high resolution time if "
+ "inspecting one; or the running hires time if we're inspecting "
+ "a live system.\n\n"
+ "Switches:\n"
+ " -l prints the number of clock ticks since system boot\n");
+}
+
static const mdb_dcmd_t dcmds[] = {
/* from genunix.c */
@@ -4216,6 +4223,7 @@ static const mdb_dcmd_t dcmds[] = {
"print sysevent subclass list", sysevent_subclass_list},
{ "system", NULL, "print contents of /etc/system file", sysfile },
{ "task", NULL, "display kernel task(s)", task },
+ { "time", "[-l]", "display system time", time, time_help },
{ "vnode2path", ":[-F]", "vnode address to pathname", vnode2path },
{ "vnode2smap", ":[offset]", "translate vnode to smap", vnode2smap },
{ "whereopen", ":", "given a vnode, dumps procs which have it open",
diff --git a/usr/src/cmd/mdb/common/modules/genunix/net.c b/usr/src/cmd/mdb/common/modules/genunix/net.c
index 23d6202fff..3f5f54059b 100644
--- a/usr/src/cmd/mdb/common/modules/genunix/net.c
+++ b/usr/src/cmd/mdb/common/modules/genunix/net.c
@@ -1559,8 +1559,7 @@ dladm_show_bridge(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
if (argc == 1)
args->name = argv[0].a_un.a_str;
- if (mdb_readvar(&args->lbolt,
- mdb_prop_postmortem ? "panic_lbolt" : "lbolt") == -1) {
+ if ((args->lbolt = mdb_get_lbolt()) == -1) {
mdb_warn("failed to read lbolt");
goto err;
}
diff --git a/usr/src/cmd/mdb/common/modules/idm/idm.c b/usr/src/cmd/mdb/common/modules/idm/idm.c
index fc8ea6fe1f..add67eac36 100644
--- a/usr/src/cmd/mdb/common/modules/idm/idm.c
+++ b/usr/src/cmd/mdb/common/modules/idm/idm.c
@@ -23,7 +23,9 @@
* Use is subject to license terms.
*/
-#include <sys/mdb_modapi.h>
+#include <mdb/mdb_modapi.h>
+#include <mdb/mdb_ks.h>
+
#include <sys/cpuvar.h>
#include <sys/conf.h>
#include <sys/file.h>
@@ -2284,7 +2286,6 @@ iscsi_isns_targets(iscsi_dcmd_ctrl_t *idc)
static int
iscsi_isns_servers_cb(uintptr_t addr, const void *walker_data, void *data)
{
- GElf_Sym sym;
iscsit_isns_svr_t server;
char server_addr[PORTAL_STR_LEN];
struct sockaddr_storage *ss;
@@ -2297,15 +2298,8 @@ iscsi_isns_servers_cb(uintptr_t addr, const void *walker_data, void *data)
return (WALK_ERR);
}
- if (mdb_lookup_by_name("lbolt", &sym) == -1) {
- mdb_warn("failed to find symbol 'lbolt'");
- return (DCMD_ERR);
- }
-
- if (mdb_vread(&lbolt, sizeof (clock_t), sym.st_value) !=
- sizeof (clock_t)) {
+ if ((lbolt = (clock_t)mdb_get_lbolt()) == -1)
return (WALK_ERR);
- }
mdb_printf("iSNS server %p:\n", addr);
mdb_inc_indent(4);
diff --git a/usr/src/cmd/mdb/common/modules/ip/ip.c b/usr/src/cmd/mdb/common/modules/ip/ip.c
index da94942eae..800e46552a 100644
--- a/usr/src/cmd/mdb/common/modules/ip/ip.c
+++ b/usr/src/cmd/mdb/common/modules/ip/ip.c
@@ -1621,8 +1621,8 @@ th_trace(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
} else {
thw.thw_match = B_TRUE;
thw.thw_matchkey = addr;
- if (mdb_readvar(&thw.thw_lbolt,
- mdb_prop_postmortem ? "panic_lbolt" : "lbolt") == -1) {
+
+ if ((thw.thw_lbolt = (clock_t)mdb_get_lbolt()) == -1) {
mdb_warn("failed to read lbolt");
return (DCMD_ERR);
}
diff --git a/usr/src/cmd/mdb/common/modules/mdb_ks/mdb_ks.c b/usr/src/cmd/mdb/common/modules/mdb_ks/mdb_ks.c
index fec3ff52e0..37051e60bf 100644
--- a/usr/src/cmd/mdb/common/modules/mdb_ks/mdb_ks.c
+++ b/usr/src/cmd/mdb/common/modules/mdb_ks/mdb_ks.c
@@ -52,6 +52,7 @@
#include <sys/refstr_impl.h>
#include <sys/cpuvar.h>
#include <sys/dlpi.h>
+#include <sys/clock_impl.h>
#include <errno.h>
#include <vm/seg_vn.h>
@@ -1585,3 +1586,81 @@ mdb_dlpi_prim(int prim)
default: return (NULL);
}
}
+
+/*
+ * mdb_gethrtime() returns the hires system time. This will be the timestamp at
+ * which we dropped into, if called from, kmdb(1); the core dump's hires time
+ * if inspecting one; or the running system's hires time if we're inspecting
+ * a live kernel.
+ */
+hrtime_t
+mdb_gethrtime(void)
+{
+ uintptr_t ptr;
+ lbolt_info_t lbi;
+ hrtime_t ts;
+
+#ifdef _KMDB
+ if (mdb_readvar(&ptr, "lb_info") == -1)
+ return (0);
+
+ if (mdb_vread(&lbi, sizeof (lbolt_info_t), ptr) !=
+ sizeof (lbolt_info_t))
+ return (0);
+
+ ts = lbi.lbi_debug_ts;
+#else
+ if (mdb_prop_postmortem) {
+ if (mdb_readvar(&ptr, "lb_info") == -1)
+ return (0);
+
+ if (mdb_vread(&lbi, sizeof (lbolt_info_t), ptr) !=
+ sizeof (lbolt_info_t))
+ return (0);
+
+ ts = lbi.lbi_debug_ts;
+ } else {
+ ts = gethrtime();
+ }
+#endif
+ return (ts);
+}
+
+/*
+ * mdb_get_lbolt() returns the number of clock ticks since system boot.
+ * Depending on the context in which it's called, the value will be derived
+ * from different sources per mdb_gethrtime(). If inspecting a panicked
+ * system, the routine returns the 'panic_lbolt64' variable from the core file.
+ */
+int64_t
+mdb_get_lbolt(void)
+{
+ lbolt_info_t lbi;
+ uintptr_t ptr;
+ int64_t pl;
+ hrtime_t ts;
+ int nsec;
+
+ if (mdb_readvar(&pl, "panic_lbolt64") != -1 && pl > 0)
+ return (pl);
+
+ /*
+ * Load the time spent in kmdb, if any.
+ */
+ if (mdb_readvar(&ptr, "lb_info") == -1)
+ return (0);
+
+ if (mdb_vread(&lbi, sizeof (lbolt_info_t), ptr) !=
+ sizeof (lbolt_info_t))
+ return (0);
+
+ if ((ts = mdb_gethrtime()) <= 0)
+ return (0);
+
+ if (mdb_readvar(&nsec, "nsec_per_tick") == -1 || nsec == 0) {
+ mdb_warn("failed to read 'nsec_per_tick'");
+ return (-1);
+ }
+
+ return ((ts/nsec) - lbi.lbi_debug_time);
+}
diff --git a/usr/src/cmd/mdb/common/modules/nca/nca.c b/usr/src/cmd/mdb/common/modules/nca/nca.c
index fa0afc5d37..e10a42e0aa 100644
--- a/usr/src/cmd/mdb/common/modules/nca/nca.c
+++ b/usr/src/cmd/mdb/common/modules/nca/nca.c
@@ -2,9 +2,8 @@
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
@@ -20,12 +19,10 @@
* CDDL HEADER END
*/
/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
-#pragma ident "%Z%%M% %I% %E% SMI"
-
/*
* NCA mdb module. Provides a collection of dcmds and walkers that
* operate on core NCA data structures. Dependencies on NCA internals
@@ -465,10 +462,8 @@ nca_timer(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
return (DCMD_ERR);
}
- if (mdb_readvar(&lbolt, "lbolt") == -1) {
- mdb_warn("cannot read symbol lbolt");
+ if ((lbolt = (clock_t)mdb_get_lbolt()) == -1)
return (DCMD_ERR);
- }
mdb_printf("%0*p %0*p", NCA_ADDR_WIDTH, addr, NCA_ADDR_WIDTH, ti.ep);
mdb_inc_indent(24);
@@ -537,7 +532,7 @@ nca_node(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
return (DCMD_USAGE);
if (mdb_getopts(argc, argv, 'v', MDB_OPT_SETBITS, TRUE, &verbose,
- 'r', MDB_OPT_SETBITS, TRUE, &request, 'p', NULL) != argc)
+ 'r', MDB_OPT_SETBITS, TRUE, &request, 'p', NULL) != argc)
return (DCMD_USAGE);
if (!DCMD_HDRSPEC(flags) && verbose)
@@ -545,9 +540,9 @@ nca_node(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
if (DCMD_HDRSPEC(flags) || verbose) {
mdb_printf("%<u>%-*s %4s %5s %8s %-*s %-*s %-*s %-*s%</u>\n",
- NCA_ADDR_WIDTH, "ADDR", "REF", "STATE", "DATASIZE",
- NCA_ADDR_WIDTH, "SQUEUE", NCA_ADDR_WIDTH, "REQUEST",
- NCA_ADDR_WIDTH, "PLRUN", NCA_ADDR_WIDTH, "VLRUN");
+ NCA_ADDR_WIDTH, "ADDR", "REF", "STATE", "DATASIZE",
+ NCA_ADDR_WIDTH, "SQUEUE", NCA_ADDR_WIDTH, "REQUEST",
+ NCA_ADDR_WIDTH, "PLRUN", NCA_ADDR_WIDTH, "VLRUN");
}
if (mdb_vread(&node, sizeof (node_t), addr) == -1) {