Module Name:    src
Committed By:   yamt
Date:           Thu Apr 14 16:23:59 UTC 2011

Modified Files:
        src/sys/dev/tprof: tprof.c tprof_ioctl.h tprof_types.h

Log Message:
for each samples, record and report cpuid and lwpid.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/tprof/tprof.c
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/tprof/tprof_ioctl.h
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/tprof/tprof_types.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/tprof/tprof.c
diff -u src/sys/dev/tprof/tprof.c:1.9 src/sys/dev/tprof/tprof.c:1.10
--- src/sys/dev/tprof/tprof.c:1.9	Fri Feb 25 22:35:38 2011
+++ src/sys/dev/tprof/tprof.c	Thu Apr 14 16:23:59 2011
@@ -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

Index: src/sys/dev/tprof/tprof_ioctl.h
diff -u src/sys/dev/tprof/tprof_ioctl.h:1.2 src/sys/dev/tprof/tprof_ioctl.h:1.3
--- src/sys/dev/tprof/tprof_ioctl.h:1.2	Sat Feb  5 14:04:40 2011
+++ src/sys/dev/tprof/tprof_ioctl.h	Thu Apr 14 16:23:59 2011
@@ -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)
 

Index: src/sys/dev/tprof/tprof_types.h
diff -u src/sys/dev/tprof/tprof_types.h:1.1 src/sys/dev/tprof/tprof_types.h:1.2
--- src/sys/dev/tprof/tprof_types.h:1.1	Sat Feb  5 14:04:40 2011
+++ src/sys/dev/tprof/tprof_types.h	Thu Apr 14 16:23:59 2011
@@ -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;

Reply via email to