Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/tprof for each samples, record and report cpuid and ...



details:   https://anonhg.NetBSD.org/src/rev/4b82d44a597c
branches:  trunk
changeset: 764264:4b82d44a597c
user:      yamt <yamt%NetBSD.org@localhost>
date:      Thu Apr 14 16:23:59 2011 +0000

description:
for each samples, record and report cpuid and lwpid.

diffstat:

 sys/dev/tprof/tprof.c       |  22 ++++++++++++++++++----
 sys/dev/tprof/tprof_ioctl.h |   4 ++--
 sys/dev/tprof/tprof_types.h |   6 ++++--
 3 files changed, 24 insertions(+), 8 deletions(-)

diffs (118 lines):

diff -r 7a52b99755f6 -r 4b82d44a597c sys/dev/tprof/tprof.c
--- a/sys/dev/tprof/tprof.c     Thu Apr 14 16:20:52 2011 +0000
+++ b/sys/dev/tprof/tprof.c     Thu Apr 14 16:23:59 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tprof.c,v 1.9 2011/02/25 22:35:38 yamt Exp $   */
+/*     $NetBSD: tprof.c,v 1.10 2011/04/14 16:23:59 yamt Exp $  */
 
 /*-
  * Copyright (c)2008,2009,2010 YAMAMOTO Takashi,
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tprof.c,v 1.9 2011/02/25 22:35:38 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tprof.c,v 1.10 2011/04/14 16:23:59 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -76,6 +76,7 @@
 
 typedef struct {
        tprof_buf_t *c_buf;
+       uint32_t c_cpuid;
        struct work c_work;
        callout_t c_callout;
 } __aligned(CACHE_LINE_SIZE) tprof_cpu_t;
@@ -394,7 +395,10 @@
  * tprof_sample: record a sample on the per-cpu buffer.
  *
  * be careful; can be called in NMI context.
- * we are bluntly assuming that curcpu() and curlwp->l_proc->p_pid are safe.
+ * we are bluntly assuming the followings are safe.
+ *     curcpu()
+ *     curlwp->l_lid
+ *     curlwp->l_proc->p_pid
  */
 
 void
@@ -404,6 +408,7 @@
        tprof_buf_t * const buf = c->c_buf;
        tprof_sample_t *sp;
        const uintptr_t pc = tfi->tfi_pc;
+       const lwp_t * const l = curlwp;
        u_int idx;
 
        idx = buf->b_used;
@@ -412,7 +417,9 @@
                return;
        }
        sp = &buf->b_data[idx];
-       sp->s_pid = curlwp->l_proc->p_pid;
+       sp->s_pid = l->l_proc->p_pid;
+       sp->s_lwpid = l->l_lid;
+       sp->s_cpuid = c->c_cpuid;
        sp->s_flags = (tfi->tfi_inkernel) ? TPROF_SAMPLE_INKERNEL : 0;
        sp->s_pc = pc;
        buf->b_used = idx + 1;
@@ -660,6 +667,7 @@
 static void
 tprof_driver_init(void)
 {
+       unsigned int i;
 
        mutex_init(&tprof_lock, MUTEX_DEFAULT, IPL_NONE);
        mutex_init(&tprof_reader_lock, MUTEX_DEFAULT, IPL_NONE);
@@ -667,6 +675,12 @@
        cv_init(&tprof_cv, "tprof");
        cv_init(&tprof_reader_cv, "tprof_rd");
        STAILQ_INIT(&tprof_list);
+       for (i = 0; i < __arraycount(tprof_cpus); i++) {
+               tprof_cpu_t * const c = &tprof_cpus[i];
+
+               c->c_buf = NULL;
+               c->c_cpuid = i;
+       }
 }
 
 static void
diff -r 7a52b99755f6 -r 4b82d44a597c sys/dev/tprof/tprof_ioctl.h
--- a/sys/dev/tprof/tprof_ioctl.h       Thu Apr 14 16:20:52 2011 +0000
+++ b/sys/dev/tprof/tprof_ioctl.h       Thu Apr 14 16:23:59 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tprof_ioctl.h,v 1.2 2011/02/05 14:04:40 yamt Exp $     */
+/*     $NetBSD: tprof_ioctl.h,v 1.3 2011/04/14 16:23:59 yamt Exp $     */
 
 /*-
  * Copyright (c)2008,2010 YAMAMOTO Takashi,
@@ -37,7 +37,7 @@
 
 #include <dev/tprof/tprof_types.h>
 
-#define        TPROF_VERSION   2
+#define        TPROF_VERSION   3       /* kernel-userland ABI version */
 
 #define        TPROF_IOC_GETVERSION    _IOR('T', 1, int)
 
diff -r 7a52b99755f6 -r 4b82d44a597c sys/dev/tprof/tprof_types.h
--- a/sys/dev/tprof/tprof_types.h       Thu Apr 14 16:20:52 2011 +0000
+++ b/sys/dev/tprof/tprof_types.h       Thu Apr 14 16:23:59 2011 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: tprof_types.h,v 1.1 2011/02/05 14:04:40 yamt Exp $     */
+/*     $NetBSD: tprof_types.h,v 1.2 2011/04/14 16:23:59 yamt Exp $     */
 
 /*-
- * Copyright (c)2010 YAMAMOTO Takashi,
+ * Copyright (c)2010,2011 YAMAMOTO Takashi,
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -41,6 +41,8 @@
 
 typedef struct {
        uint32_t s_pid;         /* process id */
+       uint32_t s_lwpid;       /* lwp id */
+       uint32_t s_cpuid;       /* cpu id */
        uint32_t s_flags;       /* flags */
        uintptr_t s_pc;         /* program counter */
 } tprof_sample_t;



Home | Main Index | Thread Index | Old Index