Skip to content

Commit

Permalink
OS-1367 need ptcumem
Browse files Browse the repository at this point in the history
  • Loading branch information
rmustacc committed Jul 16, 2012
1 parent c38b4b5 commit 84994e8
Show file tree
Hide file tree
Showing 37 changed files with 2,635 additions and 52 deletions.
33 changes: 33 additions & 0 deletions manifest
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# 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.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright (c) 2012, Joyent, Inc. All rights reserved.
#
# This lists all the files that illumos-joyent delivers as part of a build.
#
s bin=usr/bin
d boot 0755 root sys
d boot/acpi 0755 root sys
Expand Down Expand Up @@ -1205,6 +1230,8 @@ f lib/amd64/libtsol.so.2 0755 root bin
s lib/amd64/libtsol.so=libtsol.so.2
f lib/amd64/libumem.so.1 0755 root bin
s lib/amd64/libumem.so=libumem.so.1
f lib/amd64/libumem_trampoline.so.1 0755 root bin
s lib/amd64/libumem_trampoline.so=libumem_trampoline.so.1
f lib/amd64/libuuid.so.1 0755 root bin
s lib/amd64/libuuid.so=libuuid.so.1
f lib/amd64/libuutil.so.1 0755 root bin
Expand Down Expand Up @@ -1396,6 +1423,8 @@ f lib/libtsol.so.2 0755 root bin
s lib/libtsol.so=libtsol.so.2
f lib/libumem.so.1 0755 root bin
s lib/libumem.so=libumem.so.1
f lib/libumem_trampoline.so.1 0755 root bin
s lib/libumem_trampoline.so=libumem_trampoline.so.1
f lib/libuuid.so.1 0755 root bin
s lib/libuuid.so=libuuid.so.1
f lib/libuutil.so.1 0755 root bin
Expand Down Expand Up @@ -4946,6 +4975,8 @@ s usr/lib/amd64/libtsol.so=../../../lib/amd64/libtsol.so.2
s usr/lib/amd64/libtsol.so.2=../../../lib/amd64/libtsol.so.2
s usr/lib/amd64/libumem.so.1=../../../lib/amd64/libumem.so.1
s usr/lib/amd64/libumem.so=../../../lib/amd64/libumem.so.1
s usr/lib/amd64/libumem_trampoline.so.1=../../../lib/amd64/libumem_tramopline.so.1
s usr/lib/amd64/libumem_trampoline.so=../../../lib/amd64/libumem_tramopline.so.1
s usr/lib/amd64/libuuid.so.1=../../../lib/amd64/libuuid.so.1
s usr/lib/amd64/libuuid.so=../../../lib/amd64/libuuid.so.1
s usr/lib/amd64/libuutil.so.1=../../../lib/amd64/libuutil.so.1
Expand Down Expand Up @@ -6367,6 +6398,8 @@ s usr/lib/libtsol.so=../../lib/libtsol.so.2
s usr/lib/libtsol.so.2=../../lib/libtsol.so.2
s usr/lib/libumem.so.1=../../lib/libumem.so.1
s usr/lib/libumem.so=../../lib/libumem.so.1
s usr/lib/libumem_trampoline.so.1=../../lib/libumem_tramopline.so.1
s usr/lib/libumem_trampoline.so=../../lib/libumem_tramopline.so.1
f usr/lib/libunistat.so.1 0755 root bin
s usr/lib/libunistat.so=libunistat.so.1
s usr/lib/libuuid.so.1=../../lib/libuuid.so.1
Expand Down
9 changes: 9 additions & 0 deletions usr/src/cmd/mdb/common/modules/libc/libc.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
/*
* Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Copyright (c) 2012, Joyent, Inc. All rights reserved.
*/

#include <sys/mdb_modapi.h>
#include <mdb/mdb_whatis.h>
Expand Down Expand Up @@ -679,6 +682,12 @@ d_ulwp(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
prt_addr((void *)(addr + OFFSET(ul_spinlock)), 1),
prt_addr((void *)(addr + OFFSET(ul_fpuenv)), 0));

HD("tmem.size &tmem.roots");
mdb_printf(OFFSTR "%-21H %s\n",
OFFSET(ul_tmem),
ulwp.ul_tmem.tm_size,
prt_addr((void *)(addr + OFFSET(ul_tmem) + sizeof (size_t)), 0));

return (DCMD_OK);
}

Expand Down
197 changes: 183 additions & 14 deletions usr/src/cmd/mdb/common/modules/libumem/libumem.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
* Use is subject to license terms.
*/

/*
* Copyright (c) 2012, Joyent, Inc. All rights reserved.
*/

#include "umem.h"
#include <libproc.h>
#include <mdb/mdb_modapi.h>
Expand All @@ -34,6 +38,8 @@

#include <umem_impl.h>
#include <sys/vmem_impl_user.h>
#include <thr_uberdata.h>
#include <stdio.h>

#include "umem_pagesize.h"

Expand All @@ -44,24 +50,33 @@ typedef struct datafmt {
char *fmt;
} datafmt_t;

static datafmt_t ptcfmt[] = {
{ " ", "tid", "---", "%3u " },
{ " memory", " cached", "-------", "%7lH " },
{ " %", "cap", "---", "%3u " },
{ " %", NULL, "---", "%3u " },
{ NULL, NULL, NULL, NULL }
};

static datafmt_t umemfmt[] = {
{ "cache ", "name ",
"-------------------------", "%-25s " },
{ " buf", " size", "------", "%6u " },
{ " buf", "in use", "------", "%6u " },
{ " buf", " total", "------", "%6u " },
{ " memory", " in use", "---------", "%9u " },
{ " buf", " in use", "-------", "%7u " },
{ " buf", " in ptc", "-------", "%7s " },
{ " buf", " total", "-------", "%7u " },
{ " memory", " in use", "-------", "%7H " },
{ " alloc", " succeed", "---------", "%9u " },
{ "alloc", " fail", "-----", "%5llu " },
{ "alloc", " fail", "-----", "%5llu" },
{ NULL, NULL, NULL, NULL }
};

static datafmt_t vmemfmt[] = {
{ "vmem ", "name ",
"-------------------------", "%-*s " },
{ " memory", " in use", "---------", "%9llu " },
{ " memory", " total", "----------", "%10llu " },
{ " memory", " import", "---------", "%9llu " },
{ " memory", " in use", "---------", "%9H " },
{ " memory", " total", "----------", "%10H " },
{ " memory", " import", "---------", "%9H " },
{ " alloc", " succeed", "---------", "%9llu " },
{ "alloc", " fail", "-----", "%5llu " },
{ NULL, NULL, NULL, NULL }
Expand Down Expand Up @@ -105,14 +120,105 @@ typedef struct umastat_vmem {
int kv_fail;
} umastat_vmem_t;

/*ARGSUSED*/
static int
umastat_cache_nptc(uintptr_t addr, const umem_cache_t *cp, int *nptc)
{
if (!(cp->cache_flags & UMF_PTC))
return (WALK_NEXT);

(*nptc)++;
return (WALK_NEXT);
}

/*ARGSUSED*/
static int
umastat_cache_hdr(uintptr_t addr, const umem_cache_t *cp, void *ignored)
{
if (!(cp->cache_flags & UMF_PTC))
return (WALK_NEXT);

mdb_printf("%3d ", cp->cache_bufsize);
return (WALK_NEXT);
}

/*ARGSUSED*/
static int
umastat_lwp_ptc(uintptr_t addr, void *buf, int *nbufs)
{
(*nbufs)++;
return (WALK_NEXT);
}

/*ARGSUSED*/
static int
umastat_lwp_cache(uintptr_t addr, const umem_cache_t *cp, ulwp_t *ulwp)
{
char walk[60];
int nbufs = 0;

if (!(cp->cache_flags & UMF_PTC))
return (WALK_NEXT);

(void) snprintf(walk, sizeof (walk), "umem_ptc_%d", cp->cache_bufsize);

if (mdb_pwalk(walk, (mdb_walk_cb_t)umastat_lwp_ptc,
&nbufs, (uintptr_t)ulwp->ul_self) == -1) {
mdb_warn("unable to walk '%s'", walk);
return (WALK_ERR);
}

mdb_printf("%3d ", ulwp->ul_tmem.tm_size ?
(nbufs * cp->cache_bufsize * 100) / ulwp->ul_tmem.tm_size : 0);

return (WALK_NEXT);
}

/*ARGSUSED*/
static int
umastat_lwp(uintptr_t addr, const ulwp_t *ulwp, void *ignored)
{
size_t size;
datafmt_t *dfp = ptcfmt;

mdb_printf((dfp++)->fmt, ulwp->ul_lwpid);
mdb_printf((dfp++)->fmt, ulwp->ul_tmem.tm_size);

if (umem_readvar(&size, "umem_ptc_size") == -1) {
mdb_warn("unable to read 'umem_ptc_size'");
return (WALK_ERR);
}

mdb_printf((dfp++)->fmt, (ulwp->ul_tmem.tm_size * 100) / size);

if (mdb_walk("umem_cache",
(mdb_walk_cb_t)umastat_lwp_cache, (void *)ulwp) == -1) {
mdb_warn("can't walk 'umem_cache'");
return (WALK_ERR);
}

mdb_printf("\n");

return (WALK_NEXT);
}

/*ARGSUSED*/
static int
umastat_cache_ptc(uintptr_t addr, const void *ignored, int *nptc)
{
(*nptc)++;
return (WALK_NEXT);
}

static int
umastat_cache(uintptr_t addr, const umem_cache_t *cp, umastat_vmem_t **kvp)
{
umastat_vmem_t *kv;
datafmt_t *dfp = umemfmt;
char buf[10];
int magsize;

int avail, alloc, total;
int avail, alloc, total, nptc = 0;
size_t meminuse = (cp->cache_slab_create - cp->cache_slab_destroy) *
cp->cache_slabsize;

Expand All @@ -130,6 +236,21 @@ umastat_cache(uintptr_t addr, const umem_cache_t *cp, umastat_vmem_t **kvp)
(void) mdb_pwalk("umem_cpu_cache", cpu_avail, &avail, addr);
(void) mdb_pwalk("umem_slab_partial", slab_avail, &avail, addr);

if (cp->cache_flags & UMF_PTC) {
char walk[60];

(void) snprintf(walk, sizeof (walk),
"umem_ptc_%d", cp->cache_bufsize);

if (mdb_walk(walk,
(mdb_walk_cb_t)umastat_cache_ptc, &nptc) == -1) {
mdb_warn("unable to walk '%s'", walk);
return (WALK_ERR);
}

(void) snprintf(buf, sizeof (buf), "%d", nptc);
}

for (kv = *kvp; kv != NULL; kv = kv->kv_next) {
if (kv->kv_addr == (uintptr_t)cp->cache_arena)
goto out;
Expand All @@ -147,6 +268,7 @@ umastat_cache(uintptr_t addr, const umem_cache_t *cp, umastat_vmem_t **kvp)
mdb_printf((dfp++)->fmt, cp->cache_name);
mdb_printf((dfp++)->fmt, cp->cache_bufsize);
mdb_printf((dfp++)->fmt, total - avail);
mdb_printf((dfp++)->fmt, cp->cache_flags & UMF_PTC ? buf : "-");
mdb_printf((dfp++)->fmt, total);
mdb_printf((dfp++)->fmt, meminuse);
mdb_printf((dfp++)->fmt, alloc);
Expand All @@ -165,8 +287,8 @@ umastat_vmem_totals(uintptr_t addr, const vmem_t *v, umastat_vmem_t *kv)
if (kv == NULL || kv->kv_alloc == 0)
return (WALK_NEXT);

mdb_printf("Total [%s]%*s %6s %6s %6s %9u %9u %5u\n", v->vm_name,
17 - strlen(v->vm_name), "", "", "", "",
mdb_printf("Total [%s]%*s %6s %7s %7s %7s %7H %9u %5u\n", v->vm_name,
17 - strlen(v->vm_name), "", "", "", "", "",
kv->kv_meminuse, kv->kv_alloc, kv->kv_fail);

return (WALK_NEXT);
Expand Down Expand Up @@ -209,20 +331,67 @@ umastat(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
{
umastat_vmem_t *kv = NULL;
datafmt_t *dfp;
int nptc = 0, i;

if (argc != 0)
return (DCMD_USAGE);

/*
* We need to determine if we have any caches that have per-thread
* caching enabled.
*/
if (mdb_walk("umem_cache",
(mdb_walk_cb_t)umastat_cache_nptc, &nptc) == -1) {
mdb_warn("can't walk 'umem_cache'");
return (DCMD_ERR);
}

if (nptc) {
for (dfp = ptcfmt; dfp->hdr2 != NULL; dfp++)
mdb_printf("%s ", dfp->hdr1);

for (i = 0; i < nptc; i++)
mdb_printf("%s ", dfp->hdr1);

mdb_printf("\n");

for (dfp = ptcfmt; dfp->hdr2 != NULL; dfp++)
mdb_printf("%s ", dfp->hdr2);

if (mdb_walk("umem_cache",
(mdb_walk_cb_t)umastat_cache_hdr, NULL) == -1) {
mdb_warn("can't walk 'umem_cache'");
return (DCMD_ERR);
}

mdb_printf("\n");

for (dfp = ptcfmt; dfp->hdr2 != NULL; dfp++)
mdb_printf("%s ", dfp->dashes);

for (i = 0; i < nptc; i++)
mdb_printf("%s ", dfp->dashes);

mdb_printf("\n");

if (mdb_walk("ulwp", (mdb_walk_cb_t)umastat_lwp, NULL) == -1) {
mdb_warn("can't walk 'ulwp'");
return (DCMD_ERR);
}

mdb_printf("\n");
}

for (dfp = umemfmt; dfp->hdr1 != NULL; dfp++)
mdb_printf("%s ", dfp->hdr1);
mdb_printf("%s%s", dfp == umemfmt ? "" : " ", dfp->hdr1);
mdb_printf("\n");

for (dfp = umemfmt; dfp->hdr1 != NULL; dfp++)
mdb_printf("%s ", dfp->hdr2);
mdb_printf("%s%s", dfp == umemfmt ? "" : " ", dfp->hdr2);
mdb_printf("\n");

for (dfp = umemfmt; dfp->hdr1 != NULL; dfp++)
mdb_printf("%s ", dfp->dashes);
mdb_printf("%s%s", dfp == umemfmt ? "" : " ", dfp->dashes);
mdb_printf("\n");

if (mdb_walk("umem_cache", (mdb_walk_cb_t)umastat_cache, &kv) == -1) {
Expand All @@ -231,7 +400,7 @@ umastat(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
}

for (dfp = umemfmt; dfp->hdr1 != NULL; dfp++)
mdb_printf("%s ", dfp->dashes);
mdb_printf("%s%s", dfp == umemfmt ? "" : " ", dfp->dashes);
mdb_printf("\n");

if (mdb_walk("vmem", (mdb_walk_cb_t)umastat_vmem_totals, kv) == -1) {
Expand Down
Loading

0 comments on commit 84994e8

Please sign in to comment.