Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys tprof: record pid and userland events.
details: https://anonhg.NetBSD.org/src/rev/33ccc3b6e6b5
branches: trunk
changeset: 761694:33ccc3b6e6b5
user: yamt <yamt%NetBSD.org@localhost>
date: Sat Feb 05 14:04:40 2011 +0000
description:
tprof: record pid and userland events.
diffstat:
sys/arch/x86/x86/tprof_amdpmi.c | 9 ++++--
sys/arch/x86/x86/tprof_pmi.c | 11 +++++---
sys/dev/tprof/tprof.c | 36 ++++++++++++---------------
sys/dev/tprof/tprof.h | 17 +++++++++---
sys/dev/tprof/tprof_ioctl.h | 12 ++++++--
sys/dev/tprof/tprof_types.h | 54 +++++++++++++++++++++++++++++++++++++++++
6 files changed, 105 insertions(+), 34 deletions(-)
diffs (truncated from 336 to 300 lines):
diff -r bfb31d8ec472 -r 33ccc3b6e6b5 sys/arch/x86/x86/tprof_amdpmi.c
--- a/sys/arch/x86/x86/tprof_amdpmi.c Sat Feb 05 14:00:34 2011 +0000
+++ b/sys/arch/x86/x86/tprof_amdpmi.c Sat Feb 05 14:04:40 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tprof_amdpmi.c,v 1.2 2009/03/13 11:10:20 yamt Exp $ */
+/* $NetBSD: tprof_amdpmi.c,v 1.3 2011/02/05 14:04:40 yamt Exp $ */
/*-
* Copyright (c)2008,2009 YAMAMOTO Takashi,
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tprof_amdpmi.c,v 1.2 2009/03/13 11:10:20 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tprof_amdpmi.c,v 1.3 2011/02/05 14:04:40 yamt Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -39,6 +39,8 @@
#include <dev/tprof/tprof.h>
+#include <uvm/uvm.h> /* VM_MIN_KERNEL_ADDRESS */
+
#include <x86/tprof.h>
#include <x86/nmi.h>
@@ -100,7 +102,7 @@
event_hi = event >> 8;
event_lo = event & 0xff;
- pesr = PESR_OS | PESR_INT |
+ pesr = PESR_USR | PESR_OS | PESR_INT |
__SHIFTIN(event_lo, PESR_EVENT_MASK_LO) |
__SHIFTIN(event_hi, PESR_EVENT_MASK_HI) |
__SHIFTIN(0, PESR_COUNTER_MASK) |
@@ -146,6 +148,7 @@
#else /* defined(__x86_64__) */
tfi.tfi_pc = tf->tf_eip;
#endif /* defined(__x86_64__) */
+ tfi.tfi_inkernel = tfi.tfi_pc >= VM_MIN_KERNEL_ADDRESS;
tprof_sample(tprof_cookie, &tfi);
/* reset counter */
diff -r bfb31d8ec472 -r 33ccc3b6e6b5 sys/arch/x86/x86/tprof_pmi.c
--- a/sys/arch/x86/x86/tprof_pmi.c Sat Feb 05 14:00:34 2011 +0000
+++ b/sys/arch/x86/x86/tprof_pmi.c Sat Feb 05 14:04:40 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tprof_pmi.c,v 1.11 2010/05/09 20:32:41 rmind Exp $ */
+/* $NetBSD: tprof_pmi.c,v 1.12 2011/02/05 14:04:40 yamt Exp $ */
/*-
* Copyright (c)2008,2009 YAMAMOTO Takashi,
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tprof_pmi.c,v 1.11 2010/05/09 20:32:41 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tprof_pmi.c,v 1.12 2011/02/05 14:04:40 yamt Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -40,6 +40,8 @@
#include <dev/tprof/tprof.h>
+#include <uvm/uvm.h> /* VM_MIN_KERNEL_ADDRESS */
+
#include <x86/tprof.h>
#include <x86/nmi.h>
@@ -126,10 +128,10 @@
cccr = CCCR_ENABLE | __SHIFTIN(cccr_escr_select, CCCR_ESCR_SELECT) |
CCCR_MUST_BE_SET;
if (ci->ci_smt_id == 0) {
- escr |= ESCR_T0_OS;
+ escr |= ESCR_T0_OS | ESCR_T0_USR;
cccr |= CCCR_OVF_PMI_T0;
} else {
- escr |= ESCR_T1_OS;
+ escr |= ESCR_T1_OS | ESCR_T0_USR;
cccr |= CCCR_OVF_PMI_T1;
}
@@ -189,6 +191,7 @@
#else /* defined(__x86_64__) */
tfi.tfi_pc = tf->tf_eip;
#endif /* defined(__x86_64__) */
+ tfi.tfi_inkernel = tfi.tfi_pc >= VM_MIN_KERNEL_ADDRESS;
tprof_sample(tprof_cookie, &tfi);
/* reset counter */
diff -r bfb31d8ec472 -r 33ccc3b6e6b5 sys/dev/tprof/tprof.c
--- a/sys/dev/tprof/tprof.c Sat Feb 05 14:00:34 2011 +0000
+++ b/sys/dev/tprof/tprof.c Sat Feb 05 14:04:40 2011 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: tprof.c,v 1.7 2010/08/11 11:36:02 pgoyette Exp $ */
+/* $NetBSD: tprof.c,v 1.8 2011/02/05 14:04:40 yamt Exp $ */
/*-
- * Copyright (c)2008,2009 YAMAMOTO Takashi,
+ * Copyright (c)2008,2009,2010 YAMAMOTO Takashi,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tprof.c,v 1.7 2010/08/11 11:36:02 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tprof.c,v 1.8 2011/02/05 14:04:40 yamt Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -38,6 +38,7 @@
#include <sys/callout.h>
#include <sys/kmem.h>
#include <sys/module.h>
+#include <sys/proc.h>
#include <sys/workqueue.h>
#include <sys/queue.h>
@@ -55,12 +56,10 @@
* L: tprof_lock
* R: tprof_reader_lock
* S: tprof_startstop_lock
+ * s: writer should hold tprof_startstop_lock and tprof_lock
+ * reader should hold tprof_startstop_lock or tprof_lock
*/
-typedef struct {
- uintptr_t s_pc; /* program counter */
-} tprof_sample_t;
-
typedef struct tprof_buf {
u_int b_used;
u_int b_size;
@@ -89,7 +88,7 @@
} tprof_backend_t;
static kmutex_t tprof_lock;
-static bool tprof_running;
+static bool tprof_running; /* s: */
static u_int tprof_nworker; /* L: # of running worker LWPs */
static lwp_t *tprof_owner;
static STAILQ_HEAD(, tprof_buf) tprof_list; /* L: global buffer list */
@@ -318,8 +317,6 @@
static void
tprof_stop(void)
{
- CPU_INFO_ITERATOR cii;
- struct cpu_info *ci;
tprof_backend_t *tb;
KASSERT(mutex_owned(&tprof_startstop_lock));
@@ -335,16 +332,11 @@
mutex_enter(&tprof_lock);
tprof_running = false;
cv_broadcast(&tprof_reader_cv);
+ while (tprof_nworker > 0) {
+ cv_wait(&tprof_cv, &tprof_lock);
+ }
mutex_exit(&tprof_lock);
- for (CPU_INFO_FOREACH(cii, ci)) {
- mutex_enter(&tprof_lock);
- while (tprof_nworker > 0) {
- cv_wait(&tprof_cv, &tprof_lock);
- }
- mutex_exit(&tprof_lock);
- }
-
tprof_stop1();
done:
;
@@ -400,7 +392,7 @@
* tprof_sample: record a sample on the per-cpu buffer.
*
* be careful; can be called in NMI context.
- * we are assuming that curcpu() is safe.
+ * we are bluntly assuming that curcpu() and curlwp->l_proc->p_pid are safe.
*/
void
@@ -408,6 +400,7 @@
{
tprof_cpu_t * const c = tprof_curcpu();
tprof_buf_t * const buf = c->c_buf;
+ tprof_sample_t *sp;
const uintptr_t pc = tfi->tfi_pc;
u_int idx;
@@ -416,7 +409,10 @@
buf->b_overflow++;
return;
}
- buf->b_data[idx].s_pc = pc;
+ sp = &buf->b_data[idx];
+ sp->s_pid = curlwp->l_proc->p_pid;
+ sp->s_flags = (tfi->tfi_inkernel) ? TPROF_SAMPLE_INKERNEL : 0;
+ sp->s_pc = pc;
buf->b_used = idx + 1;
}
diff -r bfb31d8ec472 -r 33ccc3b6e6b5 sys/dev/tprof/tprof.h
--- a/sys/dev/tprof/tprof.h Sat Feb 05 14:00:34 2011 +0000
+++ b/sys/dev/tprof/tprof.h Sat Feb 05 14:04:40 2011 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: tprof.h,v 1.4 2009/11/18 12:24:05 yamt Exp $ */
+/* $NetBSD: tprof.h,v 1.5 2011/02/05 14:04:40 yamt Exp $ */
/*-
- * Copyright (c)2008,2009 YAMAMOTO Takashi,
+ * Copyright (c)2008,2009,2010 YAMAMOTO Takashi,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -29,6 +29,14 @@
#ifndef _DEV_TPROF_TPROF_H_
#define _DEV_TPROF_TPROF_H_
+/*
+ * definitions used by backend drivers
+ */
+
+#include <sys/types.h>
+
+#include <dev/tprof/tprof_types.h>
+
typedef struct tprof_backend_cookie tprof_backend_cookie_t;
typedef struct tprof_backend_ops {
@@ -37,12 +45,13 @@
void (*tbo_stop)(tprof_backend_cookie_t *);
} tprof_backend_ops_t;
-#define TPROF_BACKEND_VERSION 2
+#define TPROF_BACKEND_VERSION 3
int tprof_backend_register(const char *, const tprof_backend_ops_t *, int);
int tprof_backend_unregister(const char *);
typedef struct {
- uintptr_t tfi_pc;
+ uintptr_t tfi_pc; /* program counter */
+ bool tfi_inkernel; /* if tfi_pc is in the kernel address space */
} tprof_frame_info_t;
void tprof_sample(tprof_backend_cookie_t *, const tprof_frame_info_t *);
diff -r bfb31d8ec472 -r 33ccc3b6e6b5 sys/dev/tprof/tprof_ioctl.h
--- a/sys/dev/tprof/tprof_ioctl.h Sat Feb 05 14:00:34 2011 +0000
+++ b/sys/dev/tprof/tprof_ioctl.h Sat Feb 05 14:04:40 2011 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: tprof_ioctl.h,v 1.1 2008/01/01 21:28:38 yamt Exp $ */
+/* $NetBSD: tprof_ioctl.h,v 1.2 2011/02/05 14:04:40 yamt Exp $ */
/*-
- * Copyright (c)2008 YAMAMOTO Takashi,
+ * Copyright (c)2008,2010 YAMAMOTO Takashi,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -29,9 +29,15 @@
#ifndef _DEV_TPROF_TPROF_IOCTL_H_
#define _DEV_TPROF_TPROF_IOCTL_H_
+/*
+ * definitions for userland consumer
+ */
+
#include <sys/ioccom.h>
-#define TPROF_VERSION 1
+#include <dev/tprof/tprof_types.h>
+
+#define TPROF_VERSION 2
#define TPROF_IOC_GETVERSION _IOR('T', 1, int)
diff -r bfb31d8ec472 -r 33ccc3b6e6b5 sys/dev/tprof/tprof_types.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/tprof/tprof_types.h Sat Feb 05 14:04:40 2011 +0000
@@ -0,0 +1,54 @@
+/* $NetBSD: tprof_types.h,v 1.1 2011/02/05 14:04:40 yamt Exp $ */
+
+/*-
+ * Copyright (c)2010 YAMAMOTO Takashi,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Home |
Main Index |
Thread Index |
Old Index