Skip to content

Commit

Permalink
7299 want dnlc walker for mdb
Browse files Browse the repository at this point in the history
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Gordon Ross <gordon.w.ross@gmail.com>
Approved by: Richard Lowe <richlowe@richlowe.net>
  • Loading branch information
pfmooney authored and rmustacc committed Aug 26, 2016
1 parent 1f61d36 commit 39f030b
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 1 deletion.
3 changes: 2 additions & 1 deletion usr/src/cmd/mdb/common/modules/genunix/Makefile.files
Expand Up @@ -21,7 +21,7 @@
#
# Copyright 2011 Nexenta Systems, Inc. All rights reserved.
# Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2013, Joyent, Inc. All rights reserved.
# Copyright 2016 Joyent, Inc.
# Copyright (c) 2013 by Delphix. All rights reserved.
#

Expand All @@ -44,6 +44,7 @@ GENUNIX_SRCS = \
ddi_periodic.c \
devinfo.c \
dist.c \
dnlc.c \
findstack.c \
findstack_subr.c \
fm.c \
Expand Down
104 changes: 104 additions & 0 deletions usr/src/cmd/mdb/common/modules/genunix/dnlc.c
@@ -0,0 +1,104 @@
/*
* This file and its contents are supplied under the terms of the
* Common Development and Distribution License ("CDDL"), version 1.0.
* You may only use this file in accordance with the terms of version
* 1.0 of the CDDL.
*
* A full copy of the text of the CDDL should have accompanied this
* source. A copy of the CDDL is also available via the Internet at
* http://www.illumos.org/license/CDDL.
*/

/*
* Copyright 2016 Joyent, Inc.
*/

#include "dnlc.h"

#include <mdb/mdb_modapi.h>
#include <sys/dnlc.h>

typedef struct dnlc_walk {
int dw_hashsz;
int dw_index;
uintptr_t dw_hash;
uintptr_t dw_head;
} dnlc_walk_t;


int
dnlc_walk_init(mdb_walk_state_t *wsp)
{
dnlc_walk_t *dwp;

if (wsp->walk_addr != NULL) {
mdb_warn("dnlc walk doesn't support global walks\n");
return (WALK_ERR);
}

dwp = mdb_zalloc(sizeof (dnlc_walk_t), UM_SLEEP);
if (mdb_readvar(&dwp->dw_hashsz, "nc_hashsz") == -1 ||
dwp->dw_hashsz <= 0) {
mdb_warn("failed to read 'nc_hashsz'\n");
mdb_free(dwp, sizeof (dnlc_walk_t));
return (WALK_ERR);
}
if (dwp->dw_hashsz <= 0) {
mdb_warn("invalid 'nc_hashsz' value\n");
mdb_free(dwp, sizeof (dnlc_walk_t));
return (WALK_ERR);
}
if (mdb_readvar(&dwp->dw_hash, "nc_hash") == -1) {
mdb_warn("failed to read 'nc_hash'\n");
mdb_free(dwp, sizeof (dnlc_walk_t));
return (WALK_ERR);
}

wsp->walk_data = dwp;
return (WALK_NEXT);
}

int
dnlc_walk_step(mdb_walk_state_t *wsp)
{
dnlc_walk_t *dwp = wsp->walk_data;
nc_hash_t hash;
uintptr_t result, addr = wsp->walk_addr;

next:
while (addr == dwp->dw_head || addr == NULL) {
if (dwp->dw_index >= dwp->dw_hashsz) {
return (WALK_DONE);
}
dwp->dw_head = dwp->dw_hash +
(sizeof (nc_hash_t) * dwp->dw_index);
if (mdb_vread(&hash, sizeof (hash), dwp->dw_head) == -1) {
mdb_warn("failed to read nc_hash_t at %#lx",
dwp->dw_hash);
return (WALK_ERR);
}
dwp->dw_index++;
addr = (uintptr_t)hash.hash_next;
}

result = addr;
if (mdb_vread(&addr, sizeof (uintptr_t), addr) == -1) {
/*
* This entry may have become bogus since acquiring the address
* from its neighbor. Continue on if that is the case.
*/
addr = NULL;
goto next;
}
wsp->walk_addr = addr;

return (wsp->walk_callback(result, &result, wsp->walk_cbdata));
}

void
dnlc_walk_fini(mdb_walk_state_t *wsp)
{
dnlc_walk_t *dwp = wsp->walk_data;

mdb_free(dwp, sizeof (dnlc_walk_t));
}
33 changes: 33 additions & 0 deletions usr/src/cmd/mdb/common/modules/genunix/dnlc.h
@@ -0,0 +1,33 @@
/*
* This file and its contents are supplied under the terms of the
* Common Development and Distribution License ("CDDL"), version 1.0.
* You may only use this file in accordance with the terms of version
* 1.0 of the CDDL.
*
* A full copy of the text of the CDDL should have accompanied this
* source. A copy of the CDDL is also available via the Internet at
* http://www.illumos.org/license/CDDL.
*/

/*
* Copyright 2016 Joyent, Inc.
*/

#ifndef _MDB_DNLC_H
#define _MDB_DNLC_H

#include <mdb/mdb_modapi.h>

#ifdef __cplusplus
extern "C" {
#endif

extern int dnlc_walk_init(mdb_walk_state_t *);
extern int dnlc_walk_step(mdb_walk_state_t *);
extern void dnlc_walk_fini(mdb_walk_state_t *);

#ifdef __cplusplus
}
#endif

#endif /* _MDB_DNLC_H */
3 changes: 3 additions & 0 deletions usr/src/cmd/mdb/common/modules/genunix/genunix.c
Expand Up @@ -74,6 +74,7 @@
#include "damap.h"
#include "ddi_periodic.h"
#include "devinfo.h"
#include "dnlc.h"
#include "findstack.h"
#include "fm.h"
#include "gcore.h"
Expand Down Expand Up @@ -4301,6 +4302,8 @@ static const mdb_walker_t walkers[] = {
{ "callout_table", "walk callout table array", callout_table_walk_init,
callout_table_walk_step, callout_table_walk_fini },
{ "cpu", "walk cpu structures", cpu_walk_init, cpu_walk_step },
{ "dnlc", "walk dnlc entries",
dnlc_walk_init, dnlc_walk_step, dnlc_walk_fini },
{ "ereportq_dump", "walk list of ereports in dump error queue",
ereportq_dump_walk_init, ereportq_dump_walk_step, NULL },
{ "ereportq_pend", "walk list of ereports in pending error queue",
Expand Down

0 comments on commit 39f030b

Please sign in to comment.