Pull up the following revisions, requested by msaitoh in ticket #1697:

usr.sbin/tprof/tprof.8				1.16,1.22,1.25,1.29 via patch
	usr.sbin/tprof/tprof_analyze.c			1.4
	usr.sbin/tprof/arch/tprof_x86.c 		1.13-1.19
	sys/dev/tprof/tprof.c				1.23 via patch
	sys/dev/tprof/tprof_x86_amd.c			1.7-1.8 via patch
	sys/dev/tprof/tprof_x86_intel.c 		1.8 via patch

- Add AMD family 19h (zen3 and zen4) support.
- Add Intel Comet Lake support.
- Add support for Intel Skylake-X and Cascade Lake.
- Print the path that we failed to open on error.
- Use lowercase consistently for hexadecimal numbers.
- KNF
This commit is contained in:
martin 2023-08-01 17:34:32 +00:00
parent af56efbd87
commit 5d67f233e7
6 changed files with 835 additions and 377 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: tprof.c,v 1.14 2018/07/13 07:56:29 maxv Exp $ */
/* $NetBSD: tprof.c,v 1.14.6.1 2023/08/01 17:34:33 martin Exp $ */
/*-
* Copyright (c)2008,2009,2010 YAMAMOTO Takashi,
@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: tprof.c,v 1.14 2018/07/13 07:56:29 maxv Exp $");
__KERNEL_RCSID(0, "$NetBSD: tprof.c,v 1.14.6.1 2023/08/01 17:34:33 martin Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -178,7 +178,7 @@ tprof_worker(struct work *wk, void *dummy)
KASSERT(dummy == NULL);
/*
* get a per cpu buffer.
* Get a per cpu buffer.
*/
buf = tprof_buf_refresh();
@ -208,12 +208,11 @@ tprof_worker(struct work *wk, void *dummy)
tprof_stat.ts_dropbuf++;
}
mutex_exit(&tprof_lock);
if (buf) {
if (buf)
tprof_buf_free(buf);
}
if (!shouldstop) {
if (!shouldstop)
callout_schedule(&c->c_callout, hz);
}
}
static void
@ -239,9 +238,9 @@ tprof_stop1(void)
tprof_buf_t *old;
old = tprof_buf_switch(c, NULL);
if (old != NULL) {
if (old != NULL)
tprof_buf_free(old);
}
callout_destroy(&c->c_callout);
}
workqueue_destroy(tprof_wq);
@ -256,9 +255,8 @@ tprof_getinfo(struct tprof_info *info)
memset(info, 0, sizeof(*info));
info->ti_version = TPROF_VERSION;
if ((tb = tprof_backend) != NULL) {
if ((tb = tprof_backend) != NULL)
info->ti_ident = tb->tb_ops->tbo_ident();
}
}
static int
@ -351,9 +349,9 @@ tprof_stop(void)
mutex_enter(&tprof_lock);
tprof_running = false;
cv_broadcast(&tprof_reader_cv);
while (tprof_nworker > 0) {
while (tprof_nworker > 0)
cv_wait(&tprof_cv, &tprof_lock);
}
mutex_exit(&tprof_lock);
tprof_stop1();
@ -451,9 +449,8 @@ tprof_backend_register(const char *name, const tprof_backend_ops_t *ops,
{
tprof_backend_t *tb;
if (vers != TPROF_BACKEND_VERSION) {
if (vers != TPROF_BACKEND_VERSION)
return EINVAL;
}
mutex_enter(&tprof_startstop_lock);
tb = tprof_backend_lookup(name);
@ -504,9 +501,8 @@ tprof_backend_unregister(const char *name)
return EBUSY;
}
#if 1 /* XXX for now */
if (tprof_backend == tb) {
if (tprof_backend == tb)
tprof_backend = NULL;
}
#endif
LIST_REMOVE(tb, tb_list);
mutex_exit(&tprof_startstop_lock);
@ -522,9 +518,9 @@ static int
tprof_open(dev_t dev, int flags, int type, struct lwp *l)
{
if (minor(dev) != 0) {
if (minor(dev) != 0)
return EXDEV;
}
mutex_enter(&tprof_lock);
if (tprof_owner != NULL) {
mutex_exit(&tprof_lock);
@ -566,7 +562,7 @@ tprof_read(dev_t dev, struct uio *uio, int flags)
mutex_enter(&tprof_reader_lock);
while (uio->uio_resid > 0 && error == 0) {
/*
* take the first buffer from the list.
* Take the first buffer from the list.
*/
mutex_enter(&tprof_lock);
buf = STAILQ_FIRST(&tprof_list);
@ -588,7 +584,7 @@ tprof_read(dev_t dev, struct uio *uio, int flags)
mutex_exit(&tprof_lock);
/*
* copy it out.
* Copy it out.
*/
bytes = MIN(buf->b_used * sizeof(tprof_sample_t) -
tprof_reader_offset, uio->uio_resid);
@ -599,7 +595,7 @@ tprof_read(dev_t dev, struct uio *uio, int flags)
tprof_reader_offset += done;
/*
* if we didn't consume the whole buffer,
* If we didn't consume the whole buffer,
* put it back to the list.
*/
if (tprof_reader_offset <
@ -676,7 +672,7 @@ void
tprofattach(int nunits)
{
/* nothing */
/* Nothing */
}
MODULE(MODULE_CLASS_DRIVER, tprof, NULL);

View File

@ -1,4 +1,4 @@
/* $NetBSD: tprof_x86_amd.c,v 1.4.2.1 2019/10/12 14:34:45 martin Exp $ */
/* $NetBSD: tprof_x86_amd.c,v 1.4.2.2 2023/08/01 17:34:33 martin Exp $ */
/*
* Copyright (c) 2018 The NetBSD Foundation, Inc.
@ -56,7 +56,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: tprof_x86_amd.c,v 1.4.2.1 2019/10/12 14:34:45 martin Exp $");
__KERNEL_RCSID(0, "$NetBSD: tprof_x86_amd.c,v 1.4.2.2 2023/08/01 17:34:33 martin Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -166,7 +166,7 @@ tprof_amd_nmi(const struct trapframe *tf, void *dummy)
return 0;
}
/* record a sample */
/* Record a sample */
#if defined(__x86_64__)
tfi.tfi_pc = tf->tf_rip;
#else
@ -199,14 +199,14 @@ tprof_amd_ident(void)
{
struct cpu_info *ci = curcpu();
if (cpu_vendor != CPUVENDOR_AMD) {
if (cpu_vendor != CPUVENDOR_AMD)
return TPROF_IDENT_NONE;
}
switch (CPUID_TO_FAMILY(ci->ci_signature)) {
case 0x10:
case 0x15:
case 0x17:
case 0x19:
return TPROF_IDENT_AMD_GENERIC;
}
@ -218,9 +218,8 @@ tprof_amd_start(const tprof_param_t *param)
{
uint64_t xc;
if (tprof_amd_ident() == TPROF_IDENT_NONE) {
if (tprof_amd_ident() == TPROF_IDENT_NONE)
return ENOTSUP;
}
KASSERT(amd_nmi_handle == NULL);
amd_nmi_handle = nmi_establish(tprof_amd_nmi, NULL);

View File

@ -1,4 +1,4 @@
/* $NetBSD: tprof_x86_intel.c,v 1.3.2.1 2022/10/15 10:20:32 martin Exp $ */
/* $NetBSD: tprof_x86_intel.c,v 1.3.2.2 2023/08/01 17:34:33 martin Exp $ */
/*
* Copyright (c) 2018 The NetBSD Foundation, Inc.
@ -56,7 +56,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: tprof_x86_intel.c,v 1.3.2.1 2022/10/15 10:20:32 martin Exp $");
__KERNEL_RCSID(0, "$NetBSD: tprof_x86_intel.c,v 1.3.2.2 2023/08/01 17:34:33 martin Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -145,7 +145,7 @@ tprof_intel_nmi(const struct trapframe *tf, void *dummy)
return 0;
}
/* record a sample */
/* Record a sample */
#if defined(__x86_64__)
tfi.tfi_pc = tf->tf_rip;
#else
@ -154,10 +154,10 @@ tprof_intel_nmi(const struct trapframe *tf, void *dummy)
tfi.tfi_inkernel = tfi.tfi_pc >= VM_MIN_KERNEL_ADDRESS;
tprof_sample(NULL, &tfi);
/* reset counter */
/* Reset counter */
wrmsr(MSR_PERFCTR0, counter_reset_val);
/* unmask PMI */
/* Unmask PMI */
pcint = lapic_readreg(LAPIC_LVT_PCINT);
KASSERT((pcint & LAPIC_LVT_MASKED) != 0);
lapic_writereg(LAPIC_LVT_PCINT, pcint & ~LAPIC_LVT_MASKED);
@ -183,20 +183,18 @@ tprof_intel_ident(void)
{
uint32_t descs[4];
if (cpu_vendor != CPUVENDOR_INTEL) {
if (cpu_vendor != CPUVENDOR_INTEL)
return TPROF_IDENT_NONE;
}
if (cpuid_level < 0x0A) {
if (cpuid_level < 0x0a)
return TPROF_IDENT_NONE;
}
x86_cpuid(0x0A, descs);
if ((descs[0] & CPUID_PERF_VERSION) == 0) {
x86_cpuid(0x0a, descs);
if ((descs[0] & CPUID_PERF_VERSION) == 0)
return TPROF_IDENT_NONE;
}
if ((descs[0] & CPUID_PERF_NGPPC) == 0) {
if ((descs[0] & CPUID_PERF_NGPPC) == 0)
return TPROF_IDENT_NONE;
}
counter_bitwidth = __SHIFTOUT(descs[0], CPUID_PERF_NBWGPPC);
@ -208,9 +206,8 @@ tprof_intel_start(const tprof_param_t *param)
{
uint64_t xc;
if (tprof_intel_ident() == TPROF_IDENT_NONE) {
if (tprof_intel_ident() == TPROF_IDENT_NONE)
return ENOTSUP;
}
KASSERT(intel_nmi_handle == NULL);
intel_nmi_handle = nmi_establish(tprof_intel_nmi, NULL);

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
.\" $NetBSD: tprof.8,v 1.14.2.1 2019/10/12 14:34:45 martin Exp $
.\" $NetBSD: tprof.8,v 1.14.2.2 2023/08/01 17:34:32 martin Exp $
.\"
.\" Copyright (c)2011 YAMAMOTO Takashi,
.\" All rights reserved.
@ -24,7 +24,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd October 11, 2019
.Dd April 10, 2023
.Dt TPROF 8
.Os
.Sh NAME
@ -37,7 +37,9 @@
.Sh DESCRIPTION
The
.Nm
tool can be used to monitor hardware events (PMCs) during the execution of
tool can be used to monitor hardware events
.Tn ( PMC Ns s )
during the execution of
certain commands.
.Pp
The
@ -48,7 +50,7 @@ keeps recording samples from the kernel driver until the command finishes,
and reports statistics to the standard error.
.Pp
The
.Nm tprof
.Xr tprof 4
pseudo driver and a suitable backend should be loaded beforehand.
.Pp
The
@ -134,9 +136,11 @@ x86 AMD Family 15h
.It
x86 AMD Family 17h
.It
x86 AMD Family 19h
.It
x86 Intel Generic (all Intel CPUs)
.It
x86 Intel Skylake/Kabylake
x86 Intel Skylake, Kabylake and Cometlake
.It
x86 Intel Silvermont/Airmont
.It
@ -148,7 +152,7 @@ x86 Intel Goldmont Plus
The
.Nm
utility reports the following statistics about the activities of the
.Nm tprof
.Xr tprof 4
pseudo driver.
.Bl -tag -width dropbuf_samples
.It sample

View File

@ -1,4 +1,4 @@
/* $NetBSD: tprof_analyze.c,v 1.3 2018/07/14 07:54:04 maxv Exp $ */
/* $NetBSD: tprof_analyze.c,v 1.3.6.1 2023/08/01 17:34:32 martin Exp $ */
/*
* Copyright (c) 2010,2011,2012 YAMAMOTO Takashi,
@ -28,7 +28,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: tprof_analyze.c,v 1.3 2018/07/14 07:54:04 maxv Exp $");
__RCSID("$NetBSD: tprof_analyze.c,v 1.3.6.1 2023/08/01 17:34:32 martin Exp $");
#endif /* not lint */
#include <assert.h>
@ -112,7 +112,7 @@ ksymload(void)
fd = open(_PATH_KSYMS, O_RDONLY);
if (fd == -1) {
err(EXIT_FAILURE, "open");
err(EXIT_FAILURE, "open " _PATH_KSYMS);
}
if (elf_version(EV_CURRENT) == EV_NONE) {
goto elffail;