CVS commit: src/usr.sbin/tprof

2024-01-02 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Tue Jan  2 22:35:26 UTC 2024

Modified Files:
src/usr.sbin/tprof: tprof_top.c

Log Message:
This needs  - it used to come from  (inappropriately)
but no longer (normally).This should unbreak the builds.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/usr.sbin/tprof/tprof_top.c

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

Modified files:

Index: src/usr.sbin/tprof/tprof_top.c
diff -u src/usr.sbin/tprof/tprof_top.c:1.9 src/usr.sbin/tprof/tprof_top.c:1.10
--- src/usr.sbin/tprof/tprof_top.c:1.9	Mon Apr 17 08:37:24 2023
+++ src/usr.sbin/tprof/tprof_top.c	Tue Jan  2 22:35:26 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: tprof_top.c,v 1.9 2023/04/17 08:37:24 msaitoh Exp $	*/
+/*	$NetBSD: tprof_top.c,v 1.10 2024/01/02 22:35:26 kre Exp $	*/
 
 /*-
  * Copyright (c) 2022 Ryo Shimizu 
@@ -28,7 +28,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: tprof_top.c,v 1.9 2023/04/17 08:37:24 msaitoh Exp $");
+__RCSID("$NetBSD: tprof_top.c,v 1.10 2024/01/02 22:35:26 kre Exp $");
 #endif /* not lint */
 
 #include 
@@ -46,6 +46,7 @@ __RCSID("$NetBSD: tprof_top.c,v 1.9 2023
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 



CVS commit: src/usr.sbin/tprof

2024-01-02 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Tue Jan  2 22:35:26 UTC 2024

Modified Files:
src/usr.sbin/tprof: tprof_top.c

Log Message:
This needs  - it used to come from  (inappropriately)
but no longer (normally).This should unbreak the builds.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/usr.sbin/tprof/tprof_top.c

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



CVS commit: src/usr.sbin/tprof/arch

2023-07-06 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Fri Jul  7 04:43:15 UTC 2023

Modified Files:
src/usr.sbin/tprof/arch: tprof_x86.c

Log Message:
tprof(8): Add support for Skylake-X and Cascade Lake.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/usr.sbin/tprof/arch/tprof_x86.c

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

Modified files:

Index: src/usr.sbin/tprof/arch/tprof_x86.c
diff -u src/usr.sbin/tprof/arch/tprof_x86.c:1.18 src/usr.sbin/tprof/arch/tprof_x86.c:1.19
--- src/usr.sbin/tprof/arch/tprof_x86.c:1.18	Fri Jul  7 04:37:03 2023
+++ src/usr.sbin/tprof/arch/tprof_x86.c	Fri Jul  7 04:43:15 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: tprof_x86.c,v 1.18 2023/07/07 04:37:03 msaitoh Exp $	*/
+/*	$NetBSD: tprof_x86.c,v 1.19 2023/07/07 04:43:15 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2018-2019 The NetBSD Foundation, Inc.
@@ -529,11 +529,276 @@ init_intel_skylake_kabylake(void)
 	return _skylake_kabylake;
 }
 
+/*
+ * Intel Skylake-X (and Cascade Lake).
+ */
+static struct name_to_event intel_skylake_x_names[] = {
+	{ "INST_RETIRED.ANY",0x00, 0x01, true },
+	{ "CPU_CLK_UNHALTED.THREAD",			0x00, 0x02, true },
+	{ "CPU_CLK_UNHALTED.REF_TSC",			0x00, 0x03, true },
+	{ "LD_BLOCKS.STORE_FORWARD",			0x03, 0x02, true },
+	{ "LD_BLOCKS.NO_SR",0x03, 0x08, true },
+	{ "LD_BLOCKS_PARTIAL.ADDRESS_ALIAS",		0x07, 0x01, true },
+	{ "DTLB_LOAD_MISSES.MISS_CAUSES_A_WALK",	0x08, 0x01, true },
+	{ "DTLB_LOAD_MISSES.WALK_COMPLETED_4K",		0x08, 0x02, true },
+	{ "DTLB_LOAD_MISSES.WALK_COMPLETED_2M_4M",	0x08, 0x04, true },
+	{ "DTLB_LOAD_MISSES.WALK_COMPLETED_1G",		0x08, 0x08, true },
+	{ "DTLB_LOAD_MISSES.WALK_COMPLETED",		0x08, 0x0E, true },
+	{ "DTLB_LOAD_MISSES.WALK_PENDING",		0x08, 0x10, true },
+	{ "DTLB_LOAD_MISSES.STLB_HIT",			0x08, 0x20, true },
+	{ "INT_MISC.RECOVERY_CYCLES",			0x0D, 0x01, true },
+	{ "INT_MISC.CLEAR_RESTEER_CYCLES",		0x0D, 0x80, true },
+	{ "UOPS_ISSUED.ANY",0x0E, 0x01, true },
+	{ "UOPS_ISSUED.VECTOR_WIDTH_MISMATCH",		0x0E, 0x02, true },
+	{ "UOPS_ISSUED.SLOW_LEA",			0x0E, 0x20, true },
+	{ "ARITH.DIVIDER_ACTIVE",			0x14, 0x01, true },
+	{ "L2_RQSTS.DEMAND_DATA_RD_MISS",		0x24, 0x21, true },
+	{ "L2_RQSTS.RFO_MISS",0x24, 0x22, true },
+	{ "L2_RQSTS.CODE_RD_MISS",			0x24, 0x24, true },
+	{ "L2_RQSTS.ALL_DEMAND_MISS",			0x24, 0x27, true },
+	{ "L2_RQSTS.PF_MISS",0x24, 0x38, true },
+	{ "L2_RQSTS.MISS",0x24, 0x3F, true },
+	{ "L2_RQSTS.DEMAND_DATA_RD_HIT",		0x24, 0x41, true },
+	{ "L2_RQSTS.RFO_HIT",0x24, 0x42, true },
+	{ "L2_RQSTS.CODE_RD_HIT",			0x24, 0x44, true },
+	{ "L2_RQSTS.PF_HIT",0x24, 0xD8, true },
+	{ "L2_RQSTS.ALL_DEMAND_DATA_RD",		0x24, 0xE1, true },
+	{ "L2_RQSTS.ALL_RFO",0x24, 0xE2, true },
+	{ "L2_RQSTS.ALL_CODE_RD",			0x24, 0xE4, true },
+	{ "L2_RQSTS.ALL_DEMAND_REFERENCES",		0x24, 0xE7, true },
+	{ "L2_RQSTS.ALL_PF",0x24, 0xF8, true },
+	{ "L2_RQSTS.REFERENCES All L2",			0x24, 0xFF, true },
+	{ "CORE_POWER.LVL0_TURBO_LICENSE",		0x28, 0x07, true },
+	{ "CORE_POWER.LVL1_TURBO_LICENSE",		0x28, 0x18, true },
+	{ "CORE_POWER.LVL2_TURBO_LICENSE",		0x28, 0x20, true },
+	{ "CORE_POWER.THROTTLE",			0x28, 0x40, true },
+	{ "LONGEST_LAT_CACHE.MISS",			0x2E, 0x41, true },
+	{ "LONGEST_LAT_CACHE.REFERENCE",		0x2E, 0x4F, true },
+	{ "CPU_CLK_UNHALTED.THREAD_P",			0x3C, 0x00, true },
+	{ "CPU_CLK_THREAD_UNHALTED.REF_XCLK",		0x3C, 0x01, true },
+	{ "CPU_CLK_THREAD_UNHALTED.ONE_THREAD_ACTIVE",	0x3C, 0x02, true },
+	{ "L1D_PEND_MISS.PENDING",			0x48, 0x01, true },
+	{ "L1D_PEND_MISS.FB_FULL",			0x48, 0x02, true },
+	{ "DTLB_STORE_MISSES.MISS_CAUSES_A_WALK",	0x49, 0x01, true },
+	{ "DTLB_STORE_MISSES.WALK_COMPLETED_4K",	0x49, 0x02, true },
+	{ "DTLB_STORE_MISSES.WALK_COMPLETED_2M_4M",	0x49, 0x04, true },
+	{ "DTLB_STORE_MISSES.WALK_COMPLETED_1G",	0x49, 0x08, true },
+	{ "DTLB_STORE_MISSES.WALK_COMPLETED",		0x49, 0x0E, true },
+	{ "DTLB_STORE_MISSES.WALK_PENDING",		0x49, 0x10, true },
+	{ "DTLB_STORE_MISSES.STLB_HIT",			0x49, 0x20, true },
+	{ "LOAD_HIT_PRE.SW_PF",0x4C, 0x01, true },
+	{ "EPT.WALK_PENDING",0x4F, 0x10, true },
+	{ "L1D.REPLACEMENT",0x51, 0x01, true },
+	{ "TX_MEM.ABORT_CONFLICT",			0x54, 0x01, true },
+	{ "TX_MEM.ABORT_CAPACITY",			0x54, 0x02, true },
+	{ "TX_MEM.ABORT_HLE_STORE_TO_ELIDED_LOCK",	0x54, 0x04, true },
+	{ "TX_MEM.ABORT_HLE_ELISION_BUFFER_NOT_EMPTY",	0x54, 0x08, true },
+	{ "TX_MEM.ABORT_HLE_ELISION_BUFFER_MISMATCH",	0x54, 0x10, true },
+	{ "TX_MEM.ABORT_HLE_ELISION_BUFFER_UNSUPPORTED_ALIGNMENT",
+			0x54, 0x20, true },
+	{ "TX_MEM.HLE_ELISION_BUFFER_FULL",		0x54, 0x40, true },
+	{ "TX_EXEC.MISC1",0x5D, 0x01, true },
+	{ "TX_EXEC.MISC2",0x5D, 0x02, true },
+	{ "TX_EXEC.MISC3",0x5D, 0x04, true },
+	{ "TX_EXEC.MISC4",0x5D, 0x08, true },
+	{ "TX_EXEC.MISC5",0x5D, 0x10, true },
+	{ "RS_EVENTS.EMPTY_CYCLES",			0x5E, 0x01, true },
+	{ "OFFCORE_REQUESTS_OUTSTANDING.DEMAND_DATA_RD",
+			0x60, 0x01, true },

CVS commit: src/usr.sbin/tprof/arch

2023-07-06 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Fri Jul  7 04:43:15 UTC 2023

Modified Files:
src/usr.sbin/tprof/arch: tprof_x86.c

Log Message:
tprof(8): Add support for Skylake-X and Cascade Lake.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/usr.sbin/tprof/arch/tprof_x86.c

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



CVS commit: src/usr.sbin/tprof/arch

2023-07-06 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Fri Jul  7 04:37:03 UTC 2023

Modified Files:
src/usr.sbin/tprof/arch: tprof_x86.c

Log Message:
Modify comment. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/usr.sbin/tprof/arch/tprof_x86.c

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

Modified files:

Index: src/usr.sbin/tprof/arch/tprof_x86.c
diff -u src/usr.sbin/tprof/arch/tprof_x86.c:1.17 src/usr.sbin/tprof/arch/tprof_x86.c:1.18
--- src/usr.sbin/tprof/arch/tprof_x86.c:1.17	Wed Apr 12 02:15:51 2023
+++ src/usr.sbin/tprof/arch/tprof_x86.c	Fri Jul  7 04:37:03 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: tprof_x86.c,v 1.17 2023/04/12 02:15:51 msaitoh Exp $	*/
+/*	$NetBSD: tprof_x86.c,v 1.18 2023/07/07 04:37:03 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2018-2019 The NetBSD Foundation, Inc.
@@ -570,10 +570,10 @@ init_intel_generic(void)
 			break;
 		case 0x4e: /* Skylake */
 		case 0x5e: /* Skylake */
-		case 0x8e: /* Kabylake */
-		case 0x9e: /* Kabylake */
-		case 0xa5: /* Cometlake */
-		case 0xa6: /* Cometlake */
+		case 0x8e: /* Kaby Lake */
+		case 0x9e: /* Kaby Lake */
+		case 0xa5: /* Comet Lake */
+		case 0xa6: /* Comet Lake */
 			table->next = init_intel_skylake_kabylake();
 			break;
 		}



CVS commit: src/usr.sbin/tprof/arch

2023-07-06 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Fri Jul  7 04:37:03 UTC 2023

Modified Files:
src/usr.sbin/tprof/arch: tprof_x86.c

Log Message:
Modify comment. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/usr.sbin/tprof/arch/tprof_x86.c

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



CVS commit: src/usr.sbin/tprof

2023-04-17 Thread David H. Gutteridge
Module Name:src
Committed By:   gutteridge
Date:   Tue Apr 18 00:21:24 UTC 2023

Modified Files:
src/usr.sbin/tprof: tprof.8

Log Message:
tprof.8: fix typo, s/speficied/specified/


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/usr.sbin/tprof/tprof.8

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



CVS commit: src/usr.sbin/tprof

2023-04-17 Thread David H. Gutteridge
Module Name:src
Committed By:   gutteridge
Date:   Tue Apr 18 00:21:24 UTC 2023

Modified Files:
src/usr.sbin/tprof: tprof.8

Log Message:
tprof.8: fix typo, s/speficied/specified/


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/usr.sbin/tprof/tprof.8

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

Modified files:

Index: src/usr.sbin/tprof/tprof.8
diff -u src/usr.sbin/tprof/tprof.8:1.29 src/usr.sbin/tprof/tprof.8:1.30
--- src/usr.sbin/tprof/tprof.8:1.29	Mon Apr 17 21:51:40 2023
+++ src/usr.sbin/tprof/tprof.8	Tue Apr 18 00:21:23 2023
@@ -1,4 +1,4 @@
-.\"	$NetBSD: tprof.8,v 1.29 2023/04/17 21:51:40 uwe Exp $
+.\"	$NetBSD: tprof.8,v 1.30 2023/04/18 00:21:23 gutteridge Exp $
 .\"
 .\" Copyright (c)2011 YAMAMOTO Takashi,
 .\" All rights reserved.
@@ -103,7 +103,7 @@ Multiple
 arguments can be specified.
 If none of the
 .Fl e
-arguments are speficied, the CPU's default counter is used.
+arguments are specified, the CPU's default counter is used.
 .Pp
 .Ar scale
 specifies the ratio of the speed to the cycle counter, or the counter until



CVS commit: src/usr.sbin/tprof

2023-04-17 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Mon Apr 17 21:51:40 UTC 2023

Modified Files:
src/usr.sbin/tprof: tprof.8

Log Message:
tprof(8): fix markup nits


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/usr.sbin/tprof/tprof.8

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



CVS commit: src/usr.sbin/tprof

2023-04-17 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Mon Apr 17 21:51:40 UTC 2023

Modified Files:
src/usr.sbin/tprof: tprof.8

Log Message:
tprof(8): fix markup nits


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/usr.sbin/tprof/tprof.8

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

Modified files:

Index: src/usr.sbin/tprof/tprof.8
diff -u src/usr.sbin/tprof/tprof.8:1.28 src/usr.sbin/tprof/tprof.8:1.29
--- src/usr.sbin/tprof/tprof.8:1.28	Mon Apr 17 21:46:12 2023
+++ src/usr.sbin/tprof/tprof.8	Mon Apr 17 21:51:40 2023
@@ -1,4 +1,4 @@
-.\"	$NetBSD: tprof.8,v 1.28 2023/04/17 21:46:12 gutteridge Exp $
+.\"	$NetBSD: tprof.8,v 1.29 2023/04/17 21:51:40 uwe Exp $
 .\"
 .\" Copyright (c)2011 YAMAMOTO Takashi,
 .\" All rights reserved.
@@ -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,11 +50,8 @@ keeps recording samples from the kernel 
 and reports statistics to the standard error.
 .Pp
 The
-.Nm tprof
-pseudo driver and a suitable backend should be loaded beforehand.
-See
 .Xr tprof 4
-for the details.
+pseudo driver and a suitable backend should be loaded beforehand.
 .Pp
 The
 .Nm
@@ -61,8 +60,10 @@ The first argument,
 .Ar op ,
 specifies the action to take.
 Valid actions are:
-.Bl -tag -width offline -offset indent
-.It list
+.Bl -tag -width Cm
+.
+.It Cm list
+.
 Display the following information:
 .Bl -bullet -compact
 .It
@@ -70,24 +71,31 @@ a list of performance counter events ava
 .It
 the maximum number of counters that can be used simultaneously
 .It
-the default counter for monitor and top command
+the default counter for
+.Cm monitor
+and
+.Cm top
+commands
 .El
-.It monitor Xo
-.Op Fl e Ar name[:option][,scale]
+.
+.It Cm monitor Xo
+.Op Fl e Ar name\| Ns Oo Cm \&: Ns Ar option\^ Oc Ns Oo Cm \&, Ns Ar scale\^ Oc
 .Op Fl e Ar ...
 .Op Fl o Ar outfile
 .Ar command
 .Xc
-Monitor the execution of command
+.
+Monitor the execution of
 .Ar command .
+The
 .Ar name
-specifies the name of the event to count; it must be taken from the list of
+specifies the event to count; it must be taken from the list of
 available events.
 .Ar option
 specifies the source of the event; it must be a combination of
-.Ar u
+.Cm u
 (userland) and
-.Ar k
+.Cm k
 (kernel).
 If omitted, it is assumed that both are specified.
 Multiple
@@ -96,7 +104,7 @@ arguments can be specified.
 If none of the
 .Fl e
 arguments are speficied, the CPU's default counter is used.
-The collected samples are written into the file
+.Pp
 .Ar scale
 specifies the ratio of the speed to the cycle counter, or the counter until
 overflow.
@@ -105,38 +113,43 @@ speed of the cycle counter by default, b
 too large (counter increasing too slowly) to be sufficient for profiling.
 For example, to specify an event that increases about 1000 times slower than
 the cycle counter, specify
-.Dq Pa -e event,1000 .
+.Ql -e event,1000 .
 Also, if
-.Dq Pa -e event,=200
+.Ql -e event,=200
 is specified, profiling is performed every time the counter is increased by 200.
+.Pp
+The collected samples are written into the file
 .Ar outfile
 if specified.
 The default is
-.Dq Pa tprof.out .
-.It count Xo
-.Fl e
-.Ar name[:option]
+.Pa tprof.out .
+.
+.It Cm count Xo
+.Fl e Ar name\| Ns Op Cm \&: Ns Ar option
 .Op Fl e Ar ...
 .Op Fl i Ar interval
 .Ar command
 .Xc
+.
 Same as
-.Ar monitor ,
+.Cm monitor ,
 but does not do any profiling,
 only outputs counters every
 .Ar interval
 second.
-.It analyze Xo
+.
+.It Cm analyze Xo
 .Op Fl CkLPs
 .Op Fl p Ar pid
 .Ar file
 .Xc
+.
 Analyze the samples produced by a previous run of
-.Nm tprof ,
+.Nm ,
 stored in
 .Ar file ,
 and generate a plain text representation of them.
-.Bl -tag -width XPXpidXX -offset indent
+.Bl -tag -width Fl
 .It Fl C
 Don't distinguish CPUs.
 All samples are treated as its CPU number is 0.
@@ -156,27 +169,28 @@ and ignore the rest.
 .It Fl s
 Per symbol.
 .El
-.It top Xo
-.Oo
-.Fl e
-.Ar name[,scale]
+.
+.It Cm top Xo
+.Op Fl acu
+.Op Fl e Ar name\| Ns Oo Cm \&, Ns Ar scale\^ Oc
 .Op Fl e Ar ...
-.Oc
 .Op Fl i Ar interval
-.Op Fl acu
 .Xc
+.
 Displays profiling results in real-time.
 .Ar name
 specifies the name of the event to count.
-.Bl -tag -width XXintervalX -offset indent
-.It Fl i Ar interval
-set the update interval in seconds. The default value is 1.
+.Bl -tag -width Fl
 .It Fl a
-Starts in accumulation mode. The display is updated every
+Starts in accumulation mode.
+The display is updated every
 .Ar interval
 second, but the values are accumulative.
 .It Fl c
-show the delta of the event counters.
+Show the delta of the event counters.
+.It Fl i Ar interval
+Set the update interval in seconds.
+The default value is 1.
 .It Fl u
 Userland processes are also included in the profiling.
 .El
@@ -186,23 +200,27 @@ 

CVS commit: src/usr.sbin/tprof

2023-04-17 Thread David H. Gutteridge
Module Name:src
Committed By:   gutteridge
Date:   Mon Apr 17 21:46:12 UTC 2023

Modified Files:
src/usr.sbin/tprof: tprof.8

Log Message:
tprof.8: new sentence, new line


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/usr.sbin/tprof/tprof.8

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

Modified files:

Index: src/usr.sbin/tprof/tprof.8
diff -u src/usr.sbin/tprof/tprof.8:1.27 src/usr.sbin/tprof/tprof.8:1.28
--- src/usr.sbin/tprof/tprof.8:1.27	Mon Apr 17 08:37:24 2023
+++ src/usr.sbin/tprof/tprof.8	Mon Apr 17 21:46:12 2023
@@ -1,4 +1,4 @@
-.\"	$NetBSD: tprof.8,v 1.27 2023/04/17 08:37:24 msaitoh Exp $
+.\"	$NetBSD: tprof.8,v 1.28 2023/04/17 21:46:12 gutteridge Exp $
 .\"
 .\" Copyright (c)2011 YAMAMOTO Takashi,
 .\" All rights reserved.
@@ -88,7 +88,8 @@ specifies the source of the event; it mu
 .Ar u
 (userland) and
 .Ar k
-(kernel). If omitted, it is assumed that both are specified.
+(kernel).
+If omitted, it is assumed that both are specified.
 Multiple
 .Fl e
 arguments can be specified.



CVS commit: src/usr.sbin/tprof

2023-04-17 Thread David H. Gutteridge
Module Name:src
Committed By:   gutteridge
Date:   Mon Apr 17 21:46:12 UTC 2023

Modified Files:
src/usr.sbin/tprof: tprof.8

Log Message:
tprof.8: new sentence, new line


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/usr.sbin/tprof/tprof.8

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



CVS commit: src/usr.sbin/tprof

2023-04-17 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Apr 17 08:37:24 UTC 2023

Modified Files:
src/usr.sbin/tprof: tprof.8 tprof.c tprof.h tprof_top.c

Log Message:
Use the default counter if -e argument is not specified.

 monitor command:
 The default counter is selected if -e argument is not specified.
 list command:
 Print the name of the default counter for monitor and top command.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/usr.sbin/tprof/tprof.8
cvs rdiff -u -r1.20 -r1.21 src/usr.sbin/tprof/tprof.c
cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/tprof/tprof.h
cvs rdiff -u -r1.8 -r1.9 src/usr.sbin/tprof/tprof_top.c

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

Modified files:

Index: src/usr.sbin/tprof/tprof.8
diff -u src/usr.sbin/tprof/tprof.8:1.26 src/usr.sbin/tprof/tprof.8:1.27
--- src/usr.sbin/tprof/tprof.8:1.26	Mon Apr 17 07:13:35 2023
+++ src/usr.sbin/tprof/tprof.8	Mon Apr 17 08:37:24 2023
@@ -1,4 +1,4 @@
-.\"	$NetBSD: tprof.8,v 1.26 2023/04/17 07:13:35 msaitoh Exp $
+.\"	$NetBSD: tprof.8,v 1.27 2023/04/17 08:37:24 msaitoh Exp $
 .\"
 .\" Copyright (c)2011 YAMAMOTO Takashi,
 .\" All rights reserved.
@@ -69,10 +69,11 @@ Display the following information:
 a list of performance counter events available on the system
 .It
 the maximum number of counters that can be used simultaneously
+.It
+the default counter for monitor and top command
 .El
 .It monitor Xo
-.Fl e
-.Ar name[:option][,scale]
+.Op Fl e Ar name[:option][,scale]
 .Op Fl e Ar ...
 .Op Fl o Ar outfile
 .Ar command
@@ -91,6 +92,9 @@ specifies the source of the event; it mu
 Multiple
 .Fl e
 arguments can be specified.
+If none of the
+.Fl e
+arguments are speficied, the CPU's default counter is used.
 The collected samples are written into the file
 .Ar scale
 specifies the ratio of the speed to the cycle counter, or the counter until

Index: src/usr.sbin/tprof/tprof.c
diff -u src/usr.sbin/tprof/tprof.c:1.20 src/usr.sbin/tprof/tprof.c:1.21
--- src/usr.sbin/tprof/tprof.c:1.20	Mon Dec 26 08:00:13 2022
+++ src/usr.sbin/tprof/tprof.c	Mon Apr 17 08:37:24 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: tprof.c,v 1.20 2022/12/26 08:00:13 ryo Exp $	*/
+/*	$NetBSD: tprof.c,v 1.21 2023/04/17 08:37:24 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -57,7 +57,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: tprof.c,v 1.20 2022/12/26 08:00:13 ryo Exp $");
+__RCSID("$NetBSD: tprof.c,v 1.21 2023/04/17 08:37:24 msaitoh Exp $");
 #endif /* not lint */
 
 #include 
@@ -260,7 +260,12 @@ process_stat(void *arg)
 static void
 tprof_list(int argc, char **argv)
 {
-	printf("%u events can be counted at the same time\n", ncounters);
+	const char *defaultevent = tprof_cycle_event_name();
+
+	printf("%u events can be counted at the same time.\n", ncounters);
+	if (defaultevent != NULL)
+		printf("The default counter for monitor and top command is "
+		"\"%s\".\n", defaultevent);
 	tprof_event_list();
 }
 
@@ -356,6 +361,29 @@ tprof_parse_event(tprof_param_t *param, 
 	return error;
 }
 
+const char *
+tprof_cycle_event_name(void)
+{
+	const char *cycleevent;
+
+	switch (tprof_info.ti_ident) {
+	case TPROF_IDENT_INTEL_GENERIC:
+		cycleevent = "unhalted-core-cycles";
+		break;
+	case TPROF_IDENT_AMD_GENERIC:
+		cycleevent = "LsNotHaltedCyc";
+		break;
+	case TPROF_IDENT_ARMV8_GENERIC:
+	case TPROF_IDENT_ARMV7_GENERIC:
+		cycleevent = "CPU_CYCLES";
+		break;
+	default:
+		cycleevent = NULL;
+		break;
+	}
+	return cycleevent;
+}
+
 static void
 tprof_monitor_common(bool do_profile, int argc, char **argv)
 {
@@ -404,8 +432,17 @@ tprof_monitor_common(bool do_profile, in
 	}
 	argc -= optind;
 	argv += optind;
-	if (argc == 0 || nevent == 0) {
+	if (argc == 0)
 		usage();
+	if (nevent == 0) {
+		const char *defaultevent = tprof_cycle_event_name();
+		if (defaultevent == NULL)
+			errx(EXIT_FAILURE, "cpu not supported");
+
+		tprof_event_lookup(defaultevent, [nevent]);
+		eventname[nevent] = defaultevent;
+		params[nevent].p_flags |= TPROF_PARAM_KERN;
+		nevent++;
 	}
 
 	if (do_profile) {

Index: src/usr.sbin/tprof/tprof.h
diff -u src/usr.sbin/tprof/tprof.h:1.4 src/usr.sbin/tprof/tprof.h:1.5
--- src/usr.sbin/tprof/tprof.h:1.4	Fri Dec 16 08:02:04 2022
+++ src/usr.sbin/tprof/tprof.h	Mon Apr 17 08:37:24 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: tprof.h,v 1.4 2022/12/16 08:02:04 ryo Exp $	*/
+/*	$NetBSD: tprof.h,v 1.5 2023/04/17 08:37:24 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -34,6 +34,7 @@ extern int ncpu;
 extern int devfd;
 extern u_int ncounters;
 
+const char *tprof_cycle_event_name(void);
 int tprof_event_init(uint32_t);
 void tprof_event_list(void);
 void tprof_event_lookup(const char *, struct tprof_param *);

Index: src/usr.sbin/tprof/tprof_top.c
diff -u src/usr.sbin/tprof/tprof_top.c:1.8 src/usr.sbin/tprof/tprof_top.c:1.9
--- src/usr.sbin/tprof/tprof_top.c:1.8	Fri Dec 23 19:37:06 2022
+++ 

CVS commit: src/usr.sbin/tprof

2023-04-17 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Apr 17 08:37:24 UTC 2023

Modified Files:
src/usr.sbin/tprof: tprof.8 tprof.c tprof.h tprof_top.c

Log Message:
Use the default counter if -e argument is not specified.

 monitor command:
 The default counter is selected if -e argument is not specified.
 list command:
 Print the name of the default counter for monitor and top command.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/usr.sbin/tprof/tprof.8
cvs rdiff -u -r1.20 -r1.21 src/usr.sbin/tprof/tprof.c
cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/tprof/tprof.h
cvs rdiff -u -r1.8 -r1.9 src/usr.sbin/tprof/tprof_top.c

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



CVS commit: src/usr.sbin/tprof

2023-04-17 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Apr 17 07:13:36 UTC 2023

Modified Files:
src/usr.sbin/tprof: tprof.8

Log Message:
Add two note to the tprof(8)'s manual page.

 - "list" command prints the maximum number of counters that can be used
   simultaneously.
 - multiple -e arguments can be specified.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/usr.sbin/tprof/tprof.8

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



CVS commit: src/usr.sbin/tprof

2023-04-17 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Apr 17 07:13:36 UTC 2023

Modified Files:
src/usr.sbin/tprof: tprof.8

Log Message:
Add two note to the tprof(8)'s manual page.

 - "list" command prints the maximum number of counters that can be used
   simultaneously.
 - multiple -e arguments can be specified.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/usr.sbin/tprof/tprof.8

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

Modified files:

Index: src/usr.sbin/tprof/tprof.8
diff -u src/usr.sbin/tprof/tprof.8:1.25 src/usr.sbin/tprof/tprof.8:1.26
--- src/usr.sbin/tprof/tprof.8:1.25	Mon Apr 10 06:08:55 2023
+++ src/usr.sbin/tprof/tprof.8	Mon Apr 17 07:13:35 2023
@@ -1,4 +1,4 @@
-.\"	$NetBSD: tprof.8,v 1.25 2023/04/10 06:08:55 msaitoh Exp $
+.\"	$NetBSD: tprof.8,v 1.26 2023/04/17 07:13:35 msaitoh 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 April 10, 2023
+.Dd April 17, 2023
 .Dt TPROF 8
 .Os
 .Sh NAME
@@ -63,7 +63,13 @@ specifies the action to take.
 Valid actions are:
 .Bl -tag -width offline -offset indent
 .It list
-Display a list of performance counter events available on the system.
+Display the following information:
+.Bl -bullet -compact
+.It
+a list of performance counter events available on the system
+.It
+the maximum number of counters that can be used simultaneously
+.El
 .It monitor Xo
 .Fl e
 .Ar name[:option][,scale]
@@ -82,6 +88,9 @@ specifies the source of the event; it mu
 (userland) and
 .Ar k
 (kernel). If omitted, it is assumed that both are specified.
+Multiple
+.Fl e
+arguments can be specified.
 The collected samples are written into the file
 .Ar scale
 specifies the ratio of the speed to the cycle counter, or the counter until



CVS commit: src/usr.sbin/tprof/arch

2023-04-11 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Wed Apr 12 02:15:51 UTC 2023

Modified Files:
src/usr.sbin/tprof/arch: tprof_x86.c

Log Message:
KNF. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/usr.sbin/tprof/arch/tprof_x86.c

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

Modified files:

Index: src/usr.sbin/tprof/arch/tprof_x86.c
diff -u src/usr.sbin/tprof/arch/tprof_x86.c:1.16 src/usr.sbin/tprof/arch/tprof_x86.c:1.17
--- src/usr.sbin/tprof/arch/tprof_x86.c:1.16	Mon Apr 10 06:08:56 2023
+++ src/usr.sbin/tprof/arch/tprof_x86.c	Wed Apr 12 02:15:51 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: tprof_x86.c,v 1.16 2023/04/10 06:08:56 msaitoh Exp $	*/
+/*	$NetBSD: tprof_x86.c,v 1.17 2023/04/12 02:15:51 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2018-2019 The NetBSD Foundation, Inc.
@@ -60,7 +60,8 @@ struct event_table {
 
 static struct event_table *cpuevents = NULL;
 
-static void x86_cpuid(unsigned int *eax, unsigned int *ebx,
+static void
+x86_cpuid(unsigned int *eax, unsigned int *ebx,
 unsigned int *ecx, unsigned int *edx)
 {
 	asm volatile("cpuid"
@@ -429,7 +430,7 @@ static struct name_to_event intel_skylak
 	{ "OFFCORE_REQUESTS_OUTSTANDING.DEMAND_RFO",	0x60, 0x04, true },
 	{ "OFFCORE_REQUESTS_OUTSTANDING.ALL_DATA_RD",	0x60, 0x08, true },
 	{ "OFFCORE_REQUESTS_OUTSTANDING.L3_MISS_DEMAND_DATA_RD",
-	  		0x60, 0x10, true },
+			0x60, 0x10, true },
 	{ "IDQ.MITE_UOPS",0x79, 0x04, true },
 	{ "IDQ.DSB_UOPS",0x79, 0x08, true },
 	{ "IDQ.MS_MITE_UOPS",0x79, 0x20, true },



CVS commit: src/usr.sbin/tprof/arch

2023-04-11 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Wed Apr 12 02:15:51 UTC 2023

Modified Files:
src/usr.sbin/tprof/arch: tprof_x86.c

Log Message:
KNF. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/usr.sbin/tprof/arch/tprof_x86.c

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



CVS commit: src/usr.sbin/tprof

2023-04-10 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Apr 10 06:08:56 UTC 2023

Modified Files:
src/usr.sbin/tprof: tprof.8
src/usr.sbin/tprof/arch: tprof_x86.c

Log Message:
Add Cometlake support.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/usr.sbin/tprof/tprof.8
cvs rdiff -u -r1.15 -r1.16 src/usr.sbin/tprof/arch/tprof_x86.c

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

Modified files:

Index: src/usr.sbin/tprof/tprof.8
diff -u src/usr.sbin/tprof/tprof.8:1.24 src/usr.sbin/tprof/tprof.8:1.25
--- src/usr.sbin/tprof/tprof.8:1.24	Fri Dec 16 08:02:04 2022
+++ src/usr.sbin/tprof/tprof.8	Mon Apr 10 06:08:55 2023
@@ -1,4 +1,4 @@
-.\"	$NetBSD: tprof.8,v 1.24 2022/12/16 08:02:04 ryo Exp $
+.\"	$NetBSD: tprof.8,v 1.25 2023/04/10 06:08:55 msaitoh 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 December 16, 2022
+.Dd April 10, 2023
 .Dt TPROF 8
 .Os
 .Sh NAME
@@ -208,7 +208,7 @@ 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

Index: src/usr.sbin/tprof/arch/tprof_x86.c
diff -u src/usr.sbin/tprof/arch/tprof_x86.c:1.15 src/usr.sbin/tprof/arch/tprof_x86.c:1.16
--- src/usr.sbin/tprof/arch/tprof_x86.c:1.15	Thu Dec  8 05:29:27 2022
+++ src/usr.sbin/tprof/arch/tprof_x86.c	Mon Apr 10 06:08:56 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: tprof_x86.c,v 1.15 2022/12/08 05:29:27 msaitoh Exp $	*/
+/*	$NetBSD: tprof_x86.c,v 1.16 2023/04/10 06:08:56 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2018-2019 The NetBSD Foundation, Inc.
@@ -571,6 +571,8 @@ init_intel_generic(void)
 		case 0x5e: /* Skylake */
 		case 0x8e: /* Kabylake */
 		case 0x9e: /* Kabylake */
+		case 0xa5: /* Cometlake */
+		case 0xa6: /* Cometlake */
 			table->next = init_intel_skylake_kabylake();
 			break;
 		}



CVS commit: src/usr.sbin/tprof

2023-04-10 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Apr 10 06:08:56 UTC 2023

Modified Files:
src/usr.sbin/tprof: tprof.8
src/usr.sbin/tprof/arch: tprof_x86.c

Log Message:
Add Cometlake support.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/usr.sbin/tprof/tprof.8
cvs rdiff -u -r1.15 -r1.16 src/usr.sbin/tprof/arch/tprof_x86.c

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



CVS commit: src/usr.sbin/tprof

2022-12-26 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Mon Dec 26 08:00:13 UTC 2022

Modified Files:
src/usr.sbin/tprof: tprof.c

Log Message:
fixed parsing of event options.
if event option was specivied, it was stuck in a busy loop.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/usr.sbin/tprof/tprof.c

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

Modified files:

Index: src/usr.sbin/tprof/tprof.c
diff -u src/usr.sbin/tprof/tprof.c:1.19 src/usr.sbin/tprof/tprof.c:1.20
--- src/usr.sbin/tprof/tprof.c:1.19	Mon Dec 26 03:25:55 2022
+++ src/usr.sbin/tprof/tprof.c	Mon Dec 26 08:00:13 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: tprof.c,v 1.19 2022/12/26 03:25:55 ryoon Exp $	*/
+/*	$NetBSD: tprof.c,v 1.20 2022/12/26 08:00:13 ryo Exp $	*/
 
 /*
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -57,7 +57,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: tprof.c,v 1.19 2022/12/26 03:25:55 ryoon Exp $");
+__RCSID("$NetBSD: tprof.c,v 1.20 2022/12/26 08:00:13 ryo Exp $");
 #endif /* not lint */
 
 #include 
@@ -310,6 +310,7 @@ tprof_parse_event(tprof_param_t *param, 
 "invalid option: '%c'", *opt);
 goto done;
 			}
+			opt++;
 		}
 	} else if (allow_option) {
 		param->p_flags |= TPROF_PARAM_USER;



CVS commit: src/usr.sbin/tprof

2022-12-26 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Mon Dec 26 08:00:13 UTC 2022

Modified Files:
src/usr.sbin/tprof: tprof.c

Log Message:
fixed parsing of event options.
if event option was specivied, it was stuck in a busy loop.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/usr.sbin/tprof/tprof.c

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



CVS commit: src/usr.sbin/tprof

2022-12-25 Thread Ryo ONODERA
Module Name:src
Committed By:   ryoon
Date:   Mon Dec 26 03:25:55 UTC 2022

Modified Files:
src/usr.sbin/tprof: tprof.c

Log Message:
Reflect recent new options for top operation, add a and c


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/usr.sbin/tprof/tprof.c

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



CVS commit: src/usr.sbin/tprof

2022-12-25 Thread Ryo ONODERA
Module Name:src
Committed By:   ryoon
Date:   Mon Dec 26 03:25:55 UTC 2022

Modified Files:
src/usr.sbin/tprof: tprof.c

Log Message:
Reflect recent new options for top operation, add a and c


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/usr.sbin/tprof/tprof.c

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

Modified files:

Index: src/usr.sbin/tprof/tprof.c
diff -u src/usr.sbin/tprof/tprof.c:1.18 src/usr.sbin/tprof/tprof.c:1.19
--- src/usr.sbin/tprof/tprof.c:1.18	Fri Dec 16 08:02:04 2022
+++ src/usr.sbin/tprof/tprof.c	Mon Dec 26 03:25:55 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: tprof.c,v 1.18 2022/12/16 08:02:04 ryo Exp $	*/
+/*	$NetBSD: tprof.c,v 1.19 2022/12/26 03:25:55 ryoon Exp $	*/
 
 /*
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -57,7 +57,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: tprof.c,v 1.18 2022/12/16 08:02:04 ryo Exp $");
+__RCSID("$NetBSD: tprof.c,v 1.19 2022/12/26 03:25:55 ryoon Exp $");
 #endif /* not lint */
 
 #include 
@@ -133,7 +133,7 @@ usage(void)
 	" only outputs a counter.\n");
 	fprintf(stderr, "\tanalyze [-CkLPs] [-p pid] file\n");
 	fprintf(stderr, "\t\tAnalyze the samples of the file 'file'.\n");
-	fprintf(stderr, "\ttop [-e name [-e ...]] [-i interval] [-u]\n");
+	fprintf(stderr, "\ttop [-e name [-e ...]] [-i interval] [-acu]\n");
 	fprintf(stderr, "\t\tDisplay profiling results in real-time.\n");
 	exit(EXIT_FAILURE);
 }



Re: CVS commit: src/usr.sbin/tprof

2022-12-24 Thread Christos Zoulas
Requested!

christos

> On Dec 24, 2022, at 6:09 AM, Alexander Nasonov  wrote:
> 
> Christos Zoulas wrote:
>> Module Name: src
>> Committed By:christos
>> Date:Fri Dec 23 19:37:06 UTC 2022
>> 
>> Modified Files:
>>  src/usr.sbin/tprof: tprof_top.c
>> 
>> Log Message:
>> use malloc instead of alloca so that SSP works.
> 
> pullup to 10?



signature.asc
Description: Message signed with OpenPGP


Re: CVS commit: src/usr.sbin/tprof

2022-12-24 Thread Alexander Nasonov
Christos Zoulas wrote:
> Module Name:  src
> Committed By: christos
> Date: Fri Dec 23 19:37:06 UTC 2022
> 
> Modified Files:
>   src/usr.sbin/tprof: tprof_top.c
> 
> Log Message:
> use malloc instead of alloca so that SSP works.

pullup to 10?


CVS commit: src/usr.sbin/tprof

2022-12-23 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Dec 23 19:37:06 UTC 2022

Modified Files:
src/usr.sbin/tprof: tprof_top.c

Log Message:
use malloc instead of alloca so that SSP works.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.sbin/tprof/tprof_top.c

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

Modified files:

Index: src/usr.sbin/tprof/tprof_top.c
diff -u src/usr.sbin/tprof/tprof_top.c:1.7 src/usr.sbin/tprof/tprof_top.c:1.8
--- src/usr.sbin/tprof/tprof_top.c:1.7	Fri Dec 16 03:02:04 2022
+++ src/usr.sbin/tprof/tprof_top.c	Fri Dec 23 14:37:06 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: tprof_top.c,v 1.7 2022/12/16 08:02:04 ryo Exp $	*/
+/*	$NetBSD: tprof_top.c,v 1.8 2022/12/23 19:37:06 christos Exp $	*/
 
 /*-
  * Copyright (c) 2022 Ryo Shimizu 
@@ -28,7 +28,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: tprof_top.c,v 1.7 2022/12/16 08:02:04 ryo Exp $");
+__RCSID("$NetBSD: tprof_top.c,v 1.8 2022/12/23 19:37:06 christos Exp $");
 #endif /* not lint */
 
 #include 
@@ -194,7 +194,9 @@ lim_printf(int *lim, const char *fmt, ..
 	if (*lim <= 0)
 		return 0;
 
-	p = alloca(*lim + 1);
+	p = malloc(*lim + 1);
+	if (p == NULL)
+		return -1;
 
 	va_start(ap, fmt);
 	vsnprintf(p, *lim + 1, fmt, ap);
@@ -202,6 +204,7 @@ lim_printf(int *lim, const char *fmt, ..
 
 	written = strlen(p);
 	if (written == 0) {
+		free(p);
 		*lim = 0;
 		return 0;
 	}
@@ -209,6 +212,7 @@ lim_printf(int *lim, const char *fmt, ..
 	fwrite(p, written, 1, stdout);
 	*lim -= written;
 
+	free(p);
 	return written;
 }
 



CVS commit: src/usr.sbin/tprof

2022-12-23 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Dec 23 19:37:06 UTC 2022

Modified Files:
src/usr.sbin/tprof: tprof_top.c

Log Message:
use malloc instead of alloca so that SSP works.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.sbin/tprof/tprof_top.c

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



CVS commit: src/usr.sbin/tprof

2022-12-16 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Fri Dec 16 08:02:04 UTC 2022

Modified Files:
src/usr.sbin/tprof: tprof.8 tprof.c tprof.h tprof_top.c

Log Message:
the "scale" option can be specified in the event name even in "tprof monitor"


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/usr.sbin/tprof/tprof.8
cvs rdiff -u -r1.17 -r1.18 src/usr.sbin/tprof/tprof.c
cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/tprof/tprof.h
cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/tprof/tprof_top.c

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

Modified files:

Index: src/usr.sbin/tprof/tprof.8
diff -u src/usr.sbin/tprof/tprof.8:1.23 src/usr.sbin/tprof/tprof.8:1.24
--- src/usr.sbin/tprof/tprof.8:1.23	Fri Dec 16 08:00:47 2022
+++ src/usr.sbin/tprof/tprof.8	Fri Dec 16 08:02:04 2022
@@ -1,4 +1,4 @@
-.\"	$NetBSD: tprof.8,v 1.23 2022/12/16 08:00:47 ryo Exp $
+.\"	$NetBSD: tprof.8,v 1.24 2022/12/16 08:02:04 ryo Exp $
 .\"
 .\" Copyright (c)2011 YAMAMOTO Takashi,
 .\" All rights reserved.
@@ -66,7 +66,7 @@ Valid actions are:
 Display a list of performance counter events available on the system.
 .It monitor Xo
 .Fl e
-.Ar name[:option]
+.Ar name[:option][,scale]
 .Op Fl e Ar ...
 .Op Fl o Ar outfile
 .Ar command
@@ -83,6 +83,18 @@ specifies the source of the event; it mu
 .Ar k
 (kernel). If omitted, it is assumed that both are specified.
 The collected samples are written into the file
+.Ar scale
+specifies the ratio of the speed to the cycle counter, or the counter until
+overflow.
+The counter reset value on overflow used for profiling is calculated from the
+speed of the cycle counter by default, but for some events this value may be
+too large (counter increasing too slowly) to be sufficient for profiling.
+For example, to specify an event that increases about 1000 times slower than
+the cycle counter, specify
+.Dq Pa -e event,1000 .
+Also, if
+.Dq Pa -e event,=200
+is specified, profiling is performed every time the counter is increased by 200.
 .Ar outfile
 if specified.
 The default is
@@ -133,7 +145,7 @@ Per symbol.
 .It top Xo
 .Oo
 .Fl e
-.Ar name[,value]
+.Ar name[,scale]
 .Op Fl e Ar ...
 .Oc
 .Op Fl i Ar interval
@@ -142,18 +154,6 @@ Per symbol.
 Displays profiling results in real-time.
 .Ar name
 specifies the name of the event to count.
-.Ar value
-specifies the ratio of the speed to the cycle counter, or the counter until
-overflow.
-The counter reset value on overflow used for profiling is calculated from the
-speed of the cycle counter by default, but for some events this value may be
-too large (counter increasing too slowly) to be sufficient for profiling.
-For example, to specify an event that increases about 1000 times slower than
-the cycle counter, specify
-.Dq Pa -e event,1000 .
-Also, if 
-.Dq Pa -e event,=200
-is specified, profiling is performed every time the counter is increased by 200.
 .Bl -tag -width XXintervalX -offset indent
 .It Fl i Ar interval
 set the update interval in seconds. The default value is 1.

Index: src/usr.sbin/tprof/tprof.c
diff -u src/usr.sbin/tprof/tprof.c:1.17 src/usr.sbin/tprof/tprof.c:1.18
--- src/usr.sbin/tprof/tprof.c:1.17	Mon Dec  5 05:02:45 2022
+++ src/usr.sbin/tprof/tprof.c	Fri Dec 16 08:02:04 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: tprof.c,v 1.17 2022/12/05 05:02:45 ryo Exp $	*/
+/*	$NetBSD: tprof.c,v 1.18 2022/12/16 08:02:04 ryo Exp $	*/
 
 /*
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -57,7 +57,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: tprof.c,v 1.17 2022/12/05 05:02:45 ryo Exp $");
+__RCSID("$NetBSD: tprof.c,v 1.18 2022/12/16 08:02:04 ryo Exp $");
 #endif /* not lint */
 
 #include 
@@ -264,6 +264,97 @@ tprof_list(int argc, char **argv)
 	tprof_event_list();
 }
 
+int
+tprof_parse_event(tprof_param_t *param, const char *str, uint32_t flags,
+const char **eventnamep, char **errmsgp)
+{
+	double d;
+	uint64_t n;
+	int error = 0;
+	char *p, *event = NULL, *opt = NULL, *scale = NULL;
+	bool allow_option, allow_scale;
+	static char errmsgbuf[128];
+
+	allow_option = flags & TPROF_PARSE_EVENT_F_ALLOWOPTION;
+	allow_scale = flags & TPROF_PARSE_EVENT_F_ALLOWSCALE;
+
+	p = estrdup(str);
+	event = p;
+	if (allow_option) {
+		opt = strchr(p, ':');
+		if (opt != NULL) {
+			*opt++ = '\0';
+			p = opt;
+		}
+	}
+	if (allow_scale) {
+		scale = strchr(p, ',');
+		if (scale != NULL)
+			*scale++ = '\0';
+	}
+
+	tprof_event_lookup(event, param);
+
+	if (opt != NULL) {
+		while (*opt != '\0') {
+			switch (*opt) {
+			case 'u':
+param->p_flags |= TPROF_PARAM_USER;
+break;
+			case 'k':
+param->p_flags |= TPROF_PARAM_KERN;
+break;
+			default:
+error = -1;
+snprintf(errmsgbuf, sizeof(errmsgbuf),
+"invalid option: '%c'", *opt);
+goto done;
+			}
+		}
+	} else if (allow_option) {
+		param->p_flags |= TPROF_PARAM_USER;
+		param->p_flags |= TPROF_PARAM_KERN;
+	}
+
+	if (scale != NULL) {
+		if (*scale == '=') {
+			scale++;
+			n = 

CVS commit: src/usr.sbin/tprof

2022-12-16 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Fri Dec 16 08:02:04 UTC 2022

Modified Files:
src/usr.sbin/tprof: tprof.8 tprof.c tprof.h tprof_top.c

Log Message:
the "scale" option can be specified in the event name even in "tprof monitor"


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/usr.sbin/tprof/tprof.8
cvs rdiff -u -r1.17 -r1.18 src/usr.sbin/tprof/tprof.c
cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/tprof/tprof.h
cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/tprof/tprof_top.c

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



CVS commit: src/usr.sbin/tprof

2022-12-16 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Fri Dec 16 08:00:48 UTC 2022

Modified Files:
src/usr.sbin/tprof: tprof.8 tprof_top.c

Log Message:
- added 'c' command to tprof-top to show/hide event counter.
- column widths were not calculated correctly and sometimes displayed 
incorrectly.
- use putp() for terminfo str.
- fix build error with llvm.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/usr.sbin/tprof/tprof.8
cvs rdiff -u -r1.5 -r1.6 src/usr.sbin/tprof/tprof_top.c

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

Modified files:

Index: src/usr.sbin/tprof/tprof.8
diff -u src/usr.sbin/tprof/tprof.8:1.22 src/usr.sbin/tprof/tprof.8:1.23
--- src/usr.sbin/tprof/tprof.8:1.22	Fri Dec  9 01:59:51 2022
+++ src/usr.sbin/tprof/tprof.8	Fri Dec 16 08:00:47 2022
@@ -1,4 +1,4 @@
-.\"	$NetBSD: tprof.8,v 1.22 2022/12/09 01:59:51 ryo Exp $
+.\"	$NetBSD: tprof.8,v 1.23 2022/12/16 08:00:47 ryo 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 December 9, 2022
+.Dd December 16, 2022
 .Dt TPROF 8
 .Os
 .Sh NAME
@@ -175,6 +175,8 @@ These commands are currently recognized:
 .Bl -tag -width XXcommandsX -offset indent
 .It Ic a
 toggle accumurative mode.
+.It Ic c
+shows/hides the event counters.
 .It Ic q
 quit
 .Nm .

Index: src/usr.sbin/tprof/tprof_top.c
diff -u src/usr.sbin/tprof/tprof_top.c:1.5 src/usr.sbin/tprof/tprof_top.c:1.6
--- src/usr.sbin/tprof/tprof_top.c:1.5	Fri Dec  9 02:19:07 2022
+++ src/usr.sbin/tprof/tprof_top.c	Fri Dec 16 08:00:47 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: tprof_top.c,v 1.5 2022/12/09 02:19:07 ryo Exp $	*/
+/*	$NetBSD: tprof_top.c,v 1.6 2022/12/16 08:00:47 ryo Exp $	*/
 
 /*-
  * Copyright (c) 2022 Ryo Shimizu 
@@ -28,7 +28,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: tprof_top.c,v 1.5 2022/12/09 02:19:07 ryo Exp $");
+__RCSID("$NetBSD: tprof_top.c,v 1.6 2022/12/16 08:00:47 ryo Exp $");
 #endif /* not lint */
 
 #include 
@@ -154,10 +154,10 @@ reset_cursor_pos(void)
 
 	/* cursor_up * n */
 	if ((p = tigetstr("cuu")) != NULL) {
-		printf("%s", tparm(p, win.ws_row - 1, 0, 0, 0, 0, 0, 0, 0, 0));
+		putp(tparm(p, win.ws_row - 1, 0, 0, 0, 0, 0, 0, 0, 0));
 	} else if ((p = tigetstr("cuu1")) != NULL) {
 		for (i = win.ws_row - 1; i > 0; i--)
-			printf("%s", p);
+			putp(p);
 	}
 }
 
@@ -170,7 +170,7 @@ clr_to_eol(void)
 		return;
 
 	if ((p = tigetstr("el")) != NULL)
-		printf("%s", p);
+		putp(p);
 }
 
 /* newline, and clearing to end of line if needed */
@@ -288,7 +288,7 @@ sigalrm_handler(int signo)
 	sigalrm = 1;
 }
 
-static void
+__dead static void
 die(int signo)
 {
 	tty_restore();
@@ -297,7 +297,7 @@ die(int signo)
 	exit(EXIT_SUCCESS);
 }
 
-static void __dead
+__dead static void
 die_errc(int status, int code, const char *fmt, ...)
 {
 	va_list ap;
@@ -676,20 +676,21 @@ show_count_per_event(int *lim)
 			do_redraw = true;
 		}
 	}
-	for (i = 0; i < nevent; i++) {
-		for (n = 0; n < ncpu; n++) {
-			l = snprintf(buf, sizeof(buf), "%"PRIu64,
-			sample_n_per_event_cpu[opt_mode][nevent * n + i]);
-			if (sample_cpu_width[n] < (u_int)l) {
-sample_cpu_width[n] = l;
-do_redraw = true;
-			}
+	for (n = 0; n < ncpu; n++) {
+		uint64_t sum = 0;
+		for (i = 0; i < nevent; i++)
+			sum += sample_n_per_event_cpu[opt_mode][nevent * n + i];
+		l = snprintf(buf, sizeof(buf), "%"PRIu64, sum);
+		if (sample_cpu_width[n] < (u_int)l) {
+			sample_cpu_width[n] = l;
+			do_redraw = true;
 		}
 	}
 
 	if (do_redraw) {
-		lim_printf(lim, "  Rate %*s Eventname   ",
-		sample_event_width, "Sample#");
+		lim_printf(lim, "  Rate %*s %-*s",
+		sample_event_width, "Sample#",
+		SYMBOL_LEN, "Eventname");
 		for (n = 0; n < ncpu; n++) {
 			snprintf(buf, sizeof(buf), "CPU%d", n);
 			lim_printf(lim, " %*s", sample_cpu_width[n], buf);
@@ -796,8 +797,9 @@ sample_show(void)
 	lim_newline();
 
 	if (do_redraw) {
-		lim_printf(, "  Rate %*s Symbol  ",
-		sample_event_width, "Sample#");
+		lim_printf(, "  Rate %*s %-*s",
+		sample_event_width, "Sample#",
+		SYMBOL_LEN, "Symbol");
 		for (n = 0; n < ncpu; n++) {
 			snprintf(namebuf, sizeof(namebuf), "CPU%d", n);
 			lim_printf(, " %*s", sample_cpu_width[n], namebuf);
@@ -944,7 +946,7 @@ parse_event_scale(tprof_param_t *param, 
 	return 0;
 }
 
-void
+__dead void
 tprof_top(int argc, char **argv)
 {
 	tprof_param_t params[TPROF_MAXCOUNTERS];
@@ -1046,12 +1048,12 @@ tprof_top(int argc, char **argv)
 	printf("collecting samples...");
 	fflush(stdout);
 
-	tprof_bufsize = sizeof(tprof_sample_t) * 8192;
+	tprof_bufsize = sizeof(tprof_sample_t) * 1024 * 32;
 	tprof_buf = emalloc(tprof_bufsize);
 	do {
 		bool force_update = false;
 
-		for (;;) {
+		while (sigalrm == 0 && !force_update) {
 			fd_set r;
 			int nfound;
 			char c;
@@ -1081,6 +1083,12 

CVS commit: src/usr.sbin/tprof

2022-12-16 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Fri Dec 16 08:00:48 UTC 2022

Modified Files:
src/usr.sbin/tprof: tprof.8 tprof_top.c

Log Message:
- added 'c' command to tprof-top to show/hide event counter.
- column widths were not calculated correctly and sometimes displayed 
incorrectly.
- use putp() for terminfo str.
- fix build error with llvm.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/usr.sbin/tprof/tprof.8
cvs rdiff -u -r1.5 -r1.6 src/usr.sbin/tprof/tprof_top.c

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



CVS commit: src/usr.sbin/tprof

2022-12-08 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Fri Dec  9 02:19:07 UTC 2022

Modified Files:
src/usr.sbin/tprof: tprof_top.c

Log Message:
if column width changes, the screen must be updated.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/tprof/tprof_top.c

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

Modified files:

Index: src/usr.sbin/tprof/tprof_top.c
diff -u src/usr.sbin/tprof/tprof_top.c:1.4 src/usr.sbin/tprof/tprof_top.c:1.5
--- src/usr.sbin/tprof/tprof_top.c:1.4	Fri Dec  9 01:56:40 2022
+++ src/usr.sbin/tprof/tprof_top.c	Fri Dec  9 02:19:07 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: tprof_top.c,v 1.4 2022/12/09 01:56:40 ryo Exp $	*/
+/*	$NetBSD: tprof_top.c,v 1.5 2022/12/09 02:19:07 ryo Exp $	*/
 
 /*-
  * Copyright (c) 2022 Ryo Shimizu 
@@ -28,7 +28,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: tprof_top.c,v 1.4 2022/12/09 01:56:40 ryo Exp $");
+__RCSID("$NetBSD: tprof_top.c,v 1.5 2022/12/09 02:19:07 ryo Exp $");
 #endif /* not lint */
 
 #include 
@@ -671,15 +671,19 @@ show_count_per_event(int *lim)
 	for (i = 0; i < nevent; i++) {
 		l = snprintf(buf, sizeof(buf), "%"PRIu64,
 		sample_n_per_event[opt_mode][i]);
-		if (sample_event_width < (u_int)l)
+		if (sample_event_width < (u_int)l) {
 			sample_event_width = l;
+			do_redraw = true;
+		}
 	}
 	for (i = 0; i < nevent; i++) {
 		for (n = 0; n < ncpu; n++) {
 			l = snprintf(buf, sizeof(buf), "%"PRIu64,
 			sample_n_per_event_cpu[opt_mode][nevent * n + i]);
-			if (sample_cpu_width[n] < (u_int)l)
+			if (sample_cpu_width[n] < (u_int)l) {
 sample_cpu_width[n] = l;
+do_redraw = true;
+			}
 		}
 	}
 



CVS commit: src/usr.sbin/tprof

2022-12-08 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Fri Dec  9 02:19:07 UTC 2022

Modified Files:
src/usr.sbin/tprof: tprof_top.c

Log Message:
if column width changes, the screen must be updated.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/tprof/tprof_top.c

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



CVS commit: src/usr.sbin/tprof

2022-12-08 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Fri Dec  9 01:59:51 UTC 2022

Modified Files:
src/usr.sbin/tprof: tprof.8

Log Message:
supported AMD family added


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/usr.sbin/tprof/tprof.8

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

Modified files:

Index: src/usr.sbin/tprof/tprof.8
diff -u src/usr.sbin/tprof/tprof.8:1.21 src/usr.sbin/tprof/tprof.8:1.22
--- src/usr.sbin/tprof/tprof.8:1.21	Fri Dec  9 01:56:40 2022
+++ src/usr.sbin/tprof/tprof.8	Fri Dec  9 01:59:51 2022
@@ -1,4 +1,4 @@
-.\"	$NetBSD: tprof.8,v 1.21 2022/12/09 01:56:40 ryo Exp $
+.\"	$NetBSD: tprof.8,v 1.22 2022/12/09 01:59:51 ryo Exp $
 .\"
 .\" Copyright (c)2011 YAMAMOTO Takashi,
 .\" All rights reserved.
@@ -202,6 +202,8 @@ 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



CVS commit: src/usr.sbin/tprof

2022-12-08 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Fri Dec  9 01:59:51 UTC 2022

Modified Files:
src/usr.sbin/tprof: tprof.8

Log Message:
supported AMD family added


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/usr.sbin/tprof/tprof.8

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



CVS commit: src/usr.sbin/tprof

2022-12-08 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Fri Dec  9 01:56:40 UTC 2022

Modified Files:
src/usr.sbin/tprof: Makefile tprof.8 tprof_top.c

Log Message:
mainly fixes around display.

- use terminfo
- dynamically adjust column widths
- mode can be changed while running


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/usr.sbin/tprof/Makefile
cvs rdiff -u -r1.20 -r1.21 src/usr.sbin/tprof/tprof.8
cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/tprof/tprof_top.c

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



CVS commit: src/usr.sbin/tprof

2022-12-08 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Fri Dec  9 01:56:40 UTC 2022

Modified Files:
src/usr.sbin/tprof: Makefile tprof.8 tprof_top.c

Log Message:
mainly fixes around display.

- use terminfo
- dynamically adjust column widths
- mode can be changed while running


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/usr.sbin/tprof/Makefile
cvs rdiff -u -r1.20 -r1.21 src/usr.sbin/tprof/tprof.8
cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/tprof/tprof_top.c

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

Modified files:

Index: src/usr.sbin/tprof/Makefile
diff -u src/usr.sbin/tprof/Makefile:1.12 src/usr.sbin/tprof/Makefile:1.13
--- src/usr.sbin/tprof/Makefile:1.12	Thu Dec  1 00:43:27 2022
+++ src/usr.sbin/tprof/Makefile	Fri Dec  9 01:56:40 2022
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.12 2022/12/01 00:43:27 ryo Exp $
+#	$NetBSD: Makefile,v 1.13 2022/12/09 01:56:40 ryo Exp $
 
 .PATH:	${.CURDIR}/arch
 
@@ -21,11 +21,15 @@ CPPFLAGS+= -I${NETBSDSRCDIR}/sys/
 LDADD+= -lpthread
 LDADD+= -lm
 LDADD+= -lelf
+LDADD+= -lterminfo
 LDADD+= -lutil
 DPADD+= ${LIBPTHREAD}
 DPADD+= ${LIBM}
 DPADD+= ${LIBELF}
+DPADD+= ${LIBTERMINFO}
 DPADD+= ${LIBUTIL}
 
+COPTS.tprof_top.c = -Wno-format-nonliteral
+
 .include 
 .include 

Index: src/usr.sbin/tprof/tprof.8
diff -u src/usr.sbin/tprof/tprof.8:1.20 src/usr.sbin/tprof/tprof.8:1.21
--- src/usr.sbin/tprof/tprof.8:1.20	Fri Dec  9 01:55:46 2022
+++ src/usr.sbin/tprof/tprof.8	Fri Dec  9 01:56:40 2022
@@ -1,4 +1,4 @@
-.\"	$NetBSD: tprof.8,v 1.20 2022/12/09 01:55:46 ryo Exp $
+.\"	$NetBSD: tprof.8,v 1.21 2022/12/09 01:56:40 ryo Exp $
 .\"
 .\" Copyright (c)2011 YAMAMOTO Takashi,
 .\" All rights reserved.
@@ -166,6 +166,21 @@ show the delta of the event counters.
 .It Fl u
 Userland processes are also included in the profiling.
 .El
+.Pp
+While
+.Nm
+.Ar top
+is running, it accepts commands from the terminal.
+These commands are currently recognized:
+.Bl -tag -width XXcommandsX -offset indent
+.It Ic a
+toggle accumurative mode.
+.It Ic q
+quit
+.Nm .
+.It Ic z
+clear accumulated data.
+.El
 .El
 .Sh EXAMPLES
 The following command profiles the system during 20 seconds and writes the

Index: src/usr.sbin/tprof/tprof_top.c
diff -u src/usr.sbin/tprof/tprof_top.c:1.3 src/usr.sbin/tprof/tprof_top.c:1.4
--- src/usr.sbin/tprof/tprof_top.c:1.3	Fri Dec  9 01:55:46 2022
+++ src/usr.sbin/tprof/tprof_top.c	Fri Dec  9 01:56:40 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: tprof_top.c,v 1.3 2022/12/09 01:55:46 ryo Exp $	*/
+/*	$NetBSD: tprof_top.c,v 1.4 2022/12/09 01:56:40 ryo Exp $	*/
 
 /*-
  * Copyright (c) 2022 Ryo Shimizu 
@@ -28,15 +28,17 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: tprof_top.c,v 1.3 2022/12/09 01:55:46 ryo Exp $");
+__RCSID("$NetBSD: tprof_top.c,v 1.4 2022/12/09 01:56:40 ryo Exp $");
 #endif /* not lint */
 
 #include 
 #include 
-#include 
 #include 
+#include 
+#include 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -46,6 +48,8 @@ __RCSID("$NetBSD: tprof_top.c,v 1.3 2022
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 #include 
 
@@ -57,6 +61,9 @@ __RCSID("$NetBSD: tprof_top.c,v 1.3 2022
 #define SAMPLE_MODE_INSTANTANEOUS	1
 #define SAMPLE_MODE_NUM			2
 
+#define LINESTR	"-"
+#define SYMBOL_LEN			32	/* symbol and event name */
+
 struct sample_elm {
 	struct rb_node node;
 	uint64_t addr;
@@ -80,9 +87,14 @@ static int opt_userland = 0;
 static int opt_showcounter = 0;
 
 /* for display */
+static char *term;
 static struct winsize win;
 static int nontty;
+static struct termios termios_save;
+static bool termios_saved;
 static long top_interval = 1;
+static bool do_redraw;
+static u_int nshow;
 
 /* for profiling and counting samples */
 static sig_atomic_t sigalrm;
@@ -95,6 +107,8 @@ static rb_tree_t rb_tree_sample;
 struct ptrarray sample_list[SAMPLE_MODE_NUM];
 static u_int sample_n_kern[SAMPLE_MODE_NUM];
 static u_int sample_n_user[SAMPLE_MODE_NUM];
+static u_int sample_event_width = 7;
+static u_int *sample_cpu_width;	/* [ncpu] */
 static uint32_t *sample_n_kern_per_cpu[SAMPLE_MODE_NUM];	/* [ncpu] */
 static uint32_t *sample_n_user_per_cpu[SAMPLE_MODE_NUM];	/* [ncpu] */
 static uint64_t *sample_n_per_event[SAMPLE_MODE_NUM];		/* [nevent] */
@@ -127,43 +141,145 @@ cycle_event_name(void)
 	return cycleevent;
 }
 
-/* XXX: use terminfo or curses */
 static void
-cursor_address(u_int x, u_int y)
+reset_cursor_pos(void)
 {
-	if (nontty)
+	int i;
+	char *p;
+
+	if (nontty || term == NULL)
 		return;
-	printf("\e[%u;%uH", y - 1, x - 1);
+
+	printf("\r");
+
+	/* cursor_up * n */
+	if ((p = tigetstr("cuu")) != NULL) {
+		printf("%s", tparm(p, win.ws_row - 1, 0, 0, 0, 0, 0, 0, 0, 0));
+	} else if ((p = tigetstr("cuu1")) != NULL) {
+		for (i = win.ws_row - 1; i > 0; i--)
+			printf("%s", p);
+	}
 }
 
 static void
-cursor_home(void)
+clr_to_eol(void)
 {
-	if (nontty)
+	char *p;
+
+	if (nontty || 

CVS commit: src/usr.sbin/tprof

2022-12-08 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Fri Dec  9 01:55:46 UTC 2022

Modified Files:
src/usr.sbin/tprof: tprof.8 tprof_top.c

Log Message:
add accumulative mode. "tprof top -a"


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/usr.sbin/tprof/tprof.8
cvs rdiff -u -r1.2 -r1.3 src/usr.sbin/tprof/tprof_top.c

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



CVS commit: src/usr.sbin/tprof

2022-12-08 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Fri Dec  9 01:55:46 UTC 2022

Modified Files:
src/usr.sbin/tprof: tprof.8 tprof_top.c

Log Message:
add accumulative mode. "tprof top -a"


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/usr.sbin/tprof/tprof.8
cvs rdiff -u -r1.2 -r1.3 src/usr.sbin/tprof/tprof_top.c

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

Modified files:

Index: src/usr.sbin/tprof/tprof.8
diff -u src/usr.sbin/tprof/tprof.8:1.19 src/usr.sbin/tprof/tprof.8:1.20
--- src/usr.sbin/tprof/tprof.8:1.19	Thu Dec  1 00:43:27 2022
+++ src/usr.sbin/tprof/tprof.8	Fri Dec  9 01:55:46 2022
@@ -1,4 +1,4 @@
-.\"	$NetBSD: tprof.8,v 1.19 2022/12/01 00:43:27 ryo Exp $
+.\"	$NetBSD: tprof.8,v 1.20 2022/12/09 01:55:46 ryo 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 December 1, 2022
+.Dd December 9, 2022
 .Dt TPROF 8
 .Os
 .Sh NAME
@@ -137,8 +137,7 @@ Per symbol.
 .Op Fl e Ar ...
 .Oc
 .Op Fl i Ar interval
-.Op Fl c
-.Op Fl u
+.Op Fl acu
 .Xc
 Displays profiling results in real-time.
 .Ar name
@@ -158,6 +157,10 @@ is specified, profiling is performed eve
 .Bl -tag -width XXintervalX -offset indent
 .It Fl i Ar interval
 set the update interval in seconds. The default value is 1.
+.It Fl a
+Starts in accumulation mode. The display is updated every
+.Ar interval
+second, but the values are accumulative.
 .It Fl c
 show the delta of the event counters.
 .It Fl u
@@ -226,7 +229,9 @@ utility was written by
 .An YAMAMOTO Takashi .
 It was revamped by
 .An Maxime Villard
-in 2018.
+in 2018, and by
+.An Ryo Shimizu
+in 2022.
 .Sh CAVEATS
 The contents and representation of recorded samples are undocumented and
 will likely be changed for future releases of

Index: src/usr.sbin/tprof/tprof_top.c
diff -u src/usr.sbin/tprof/tprof_top.c:1.2 src/usr.sbin/tprof/tprof_top.c:1.3
--- src/usr.sbin/tprof/tprof_top.c:1.2	Thu Dec  1 03:32:24 2022
+++ src/usr.sbin/tprof/tprof_top.c	Fri Dec  9 01:55:46 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: tprof_top.c,v 1.2 2022/12/01 03:32:24 ryo Exp $	*/
+/*	$NetBSD: tprof_top.c,v 1.3 2022/12/09 01:55:46 ryo Exp $	*/
 
 /*-
  * Copyright (c) 2022 Ryo Shimizu 
@@ -28,7 +28,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: tprof_top.c,v 1.2 2022/12/01 03:32:24 ryo Exp $");
+__RCSID("$NetBSD: tprof_top.c,v 1.3 2022/12/09 01:55:46 ryo Exp $");
 #endif /* not lint */
 
 #include 
@@ -37,7 +37,6 @@ __RCSID("$NetBSD: tprof_top.c,v 1.2 2022
 #include 
 #include 
 
-#include 
 #include 
 #include 
 #include 
@@ -54,14 +53,79 @@ __RCSID("$NetBSD: tprof_top.c,v 1.2 2022
 #include "tprof.h"
 #include "ksyms.h"
 
-static struct sym **ksyms;
-static size_t nksyms;
-static sig_atomic_t sigalrm;
+#define SAMPLE_MODE_ACCUMULATIVE	0
+#define SAMPLE_MODE_INSTANTANEOUS	1
+#define SAMPLE_MODE_NUM			2
+
+struct sample_elm {
+	struct rb_node node;
+	uint64_t addr;
+	const char *name;
+	uint32_t flags;
+#define SAMPLE_ELM_FLAGS_USER	0x0001
+	uint32_t num[SAMPLE_MODE_NUM];
+	uint32_t num_cpu[];	/* [SAMPLE_MODE_NUM][ncpu] */
+#define SAMPLE_ELM_NUM_CPU(e, k)		\
+	((e)->num_cpu + (k) *  ncpu)
+};
+
+struct ptrarray {
+	void **pa_ptrs;
+	size_t pa_allocnum;
+	size_t pa_inuse;
+};
+
+static int opt_mode = SAMPLE_MODE_INSTANTANEOUS;
+static int opt_userland = 0;
+static int opt_showcounter = 0;
+
+/* for display */
 static struct winsize win;
+static int nontty;
 static long top_interval = 1;
+
+/* for profiling and counting samples */
+static sig_atomic_t sigalrm;
+static struct sym **ksyms;
+static size_t nksyms;
 static u_int nevent;
 static const char *eventname[TPROF_MAXCOUNTERS];
-static int nontty;
+static size_t sizeof_sample_elm;
+static rb_tree_t rb_tree_sample;
+struct ptrarray sample_list[SAMPLE_MODE_NUM];
+static u_int sample_n_kern[SAMPLE_MODE_NUM];
+static u_int sample_n_user[SAMPLE_MODE_NUM];
+static uint32_t *sample_n_kern_per_cpu[SAMPLE_MODE_NUM];	/* [ncpu] */
+static uint32_t *sample_n_user_per_cpu[SAMPLE_MODE_NUM];	/* [ncpu] */
+static uint64_t *sample_n_per_event[SAMPLE_MODE_NUM];		/* [nevent] */
+static uint64_t *sample_n_per_event_cpu[SAMPLE_MODE_NUM];	/* [ncpu] */
+
+/* raw event counter */
+static uint64_t *counters;	/* counters[2][ncpu][nevent] */
+static u_int counters_i;
+
+static const char *
+cycle_event_name(void)
+{
+	const char *cycleevent;
+
+	switch (tprof_info.ti_ident) {
+	case TPROF_IDENT_INTEL_GENERIC:
+		cycleevent = "unhalted-core-cycles";
+		break;
+	case TPROF_IDENT_AMD_GENERIC:
+		cycleevent = "LsNotHaltedCyc";
+		break;
+	case TPROF_IDENT_ARMV8_GENERIC:
+	case TPROF_IDENT_ARMV7_GENERIC:
+		cycleevent = "CPU_CYCLES";
+		break;
+	default:
+		cycleevent = NULL;
+		break;
+	}
+	return cycleevent;
+}
 
 /* XXX: use terminfo or curses */
 static void
@@ -108,31 +172,37 @@ sigalrm_handler(int signo)
 	sigalrm = 1;
 }
 
-struct 

CVS commit: src/usr.sbin/tprof/arch

2022-12-07 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Dec  8 02:12:18 UTC 2022

Modified Files:
src/usr.sbin/tprof/arch: tprof_x86.c

Log Message:
Use lowercase consistently for hexadecimal numbers. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/usr.sbin/tprof/arch/tprof_x86.c

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



CVS commit: src/usr.sbin/tprof/arch

2022-12-07 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Dec  8 02:12:18 UTC 2022

Modified Files:
src/usr.sbin/tprof/arch: tprof_x86.c

Log Message:
Use lowercase consistently for hexadecimal numbers. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/usr.sbin/tprof/arch/tprof_x86.c

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

Modified files:

Index: src/usr.sbin/tprof/arch/tprof_x86.c
diff -u src/usr.sbin/tprof/arch/tprof_x86.c:1.13 src/usr.sbin/tprof/arch/tprof_x86.c:1.14
--- src/usr.sbin/tprof/arch/tprof_x86.c:1.13	Wed Dec  7 08:11:49 2022
+++ src/usr.sbin/tprof/arch/tprof_x86.c	Thu Dec  8 02:12:18 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: tprof_x86.c,v 1.13 2022/12/07 08:11:49 msaitoh Exp $	*/
+/*	$NetBSD: tprof_x86.c,v 1.14 2022/12/08 02:12:18 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2018-2019 The NetBSD Foundation, Inc.
@@ -78,14 +78,14 @@ static void x86_cpuid(unsigned int *eax,
  */
 static struct name_to_event intel_arch1_names[] = {
 	/* Event Name - Event Select - UMask */
-	{ "unhalted-core-cycles",	0x3C, 0x00, true },
-	{ "instruction-retired",	0xC0, 0x00, true },
-	{ "unhalted-reference-cycles",	0x3C, 0x01, true },
-	{ "llc-reference",		0x2E, 0x4F, true },
-	{ "llc-misses",			0x2E, 0x41, true },
-	{ "branch-instruction-retired",	0xC4, 0x00, true },
-	{ "branch-misses-retired",	0xC5, 0x00, true },
-	{ "topdown-slots",		0xA4, 0x01, true },
+	{ "unhalted-core-cycles",	0x3c, 0x00, true },
+	{ "instruction-retired",	0xc0, 0x00, true },
+	{ "unhalted-reference-cycles",	0x3c, 0x01, true },
+	{ "llc-reference",		0x2e, 0x4f, true },
+	{ "llc-misses",			0x2e, 0x41, true },
+	{ "branch-instruction-retired",	0xc4, 0x00, true },
+	{ "branch-misses-retired",	0xc5, 0x00, true },
+	{ "topdown-slots",		0xa4, 0x01, true },
 };
 
 static struct event_table intel_arch1 = {
@@ -103,7 +103,7 @@ init_intel_arch1(void)
 	struct event_table *table;
 	size_t i;
 
-	eax = 0x0A;
+	eax = 0x0a;
 	ebx = 0;
 	ecx = 0;
 	edx = 0;
@@ -150,53 +150,53 @@ static struct name_to_event intel_silver
 	{ "PAGE_WALKS.D_SIDE_CYCLES",		0x05, 0x01, true },
 	{ "PAGE_WALKS.I_SIDE_CYCLES",		0x05, 0x02, true },
 	{ "PAGE_WALKS.WALKS",			0x05, 0x03, true },
-	{ "LONGEST_LAT_CACHE.MISS",		0x2E, 0x41, true },
-	{ "LONGEST_LAT_CACHE.REFERENCE",	0x2E, 0x4F, true },
+	{ "LONGEST_LAT_CACHE.MISS",		0x2e, 0x41, true },
+	{ "LONGEST_LAT_CACHE.REFERENCE",	0x2e, 0x4f, true },
 	{ "L2_REJECT_XQ.ALL",			0x30, 0x00, true },
 	{ "CORE_REJECT_L2Q.ALL",		0x31, 0x00, true },
-	{ "CPU_CLK_UNHALTED.CORE_P",		0x3C, 0x00, true },
-	{ "CPU_CLK_UNHALTED.REF_P",		0x3C, 0x01, true },
+	{ "CPU_CLK_UNHALTED.CORE_P",		0x3c, 0x00, true },
+	{ "CPU_CLK_UNHALTED.REF_P",		0x3c, 0x01, true },
 	{ "ICACHE.HIT",0x80, 0x01, true },
 	{ "ICACHE.MISSES",			0x80, 0x02, true },
 	{ "ICACHE.ACCESSES",			0x80, 0x03, true },
-	{ "OFFCORE_RESPONSE_0",			0xB7, 0x01, true },
-	{ "OFFCORE_RESPONSE_1",			0xB7, 0x02, true },
-	{ "INST_RETIRED.ANY_P",			0xC0, 0x00, true },
-	{ "UOPS_RETIRED.MS",			0xC2, 0x01, true },
-	{ "UOPS_RETIRED.ALL",			0xC2, 0x10, true },
-	{ "MACHINE_CLEARS.SMC",			0xC3, 0x01, true },
-	{ "MACHINE_CLEARS.MEMORY_ORDERING",	0xC3, 0x02, true },
-	{ "MACHINE_CLEARS.FP_ASSIST",		0xC3, 0x04, true },
-	{ "MACHINE_CLEARS.ALL",			0xC3, 0x08, true },
-	{ "BR_INST_RETIRED.ALL_BRANCHES",	0xC4, 0x00, true },
-	{ "BR_INST_RETIRED.JCC",		0xC4, 0x7E, true },
-	{ "BR_INST_RETIRED.FAR_BRANCH",		0xC4, 0xBF, true },
-	{ "BR_INST_RETIRED.NON_RETURN_IND",	0xC4, 0xEB, true },
-	{ "BR_INST_RETIRED.RETURN",		0xC4, 0xF7, true },
-	{ "BR_INST_RETIRED.CALL",		0xC4, 0xF9, true },
-	{ "BR_INST_RETIRED.IND_CALL",		0xC4, 0xFB, true },
-	{ "BR_INST_RETIRED.REL_CALL",		0xC4, 0xFD, true },
-	{ "BR_INST_RETIRED.TAKEN_JCC",		0xC4, 0xFE, true },
-	{ "BR_MISP_RETIRED.ALL_BRANCHES",	0xC5, 0x00, true },
-	{ "BR_MISP_RETIRED.JCC",		0xC5, 0x7E, true },
-	{ "BR_MISP_RETIRED.FAR",		0xC5, 0xBF, true },
-	{ "BR_MISP_RETIRED.NON_RETURN_IND",	0xC5, 0xEB, true },
-	{ "BR_MISP_RETIRED.RETURN",		0xC5, 0xF7, true },
-	{ "BR_MISP_RETIRED.CALL",		0xC5, 0xF9, true },
-	{ "BR_MISP_RETIRED.IND_CALL",		0xC5, 0xFB, true },
-	{ "BR_MISP_RETIRED.REL_CALL",		0xC5, 0xFD, true },
-	{ "BR_MISP_RETIRED.TAKEN_JCC",		0xC5, 0xFE, true },
-	{ "NO_ALLOC_CYCLES.ROB_FULL",		0xCA, 0x01, true },
-	{ "NO_ALLOC_CYCLES.RAT_STALL",		0xCA, 0x20, true },
-	{ "NO_ALLOC_CYCLES.ALL",		0xCA, 0x3F, true },
-	{ "NO_ALLOC_CYCLES.NOT_DELIVERED",	0xCA, 0x50, true },
-	{ "RS_FULL_STALL.MEC",			0xCB, 0x01, true },
-	{ "RS_FULL_STALL.ALL",			0xCB, 0x1F, true },
-	{ "CYCLES_DIV_BUSY.ANY",		0xCD, 0x01, true },
-	{ "BACLEARS.ALL",			0xE6, 0x01, true },
-	{ "BACLEARS.RETURN",			0xE6, 0x08, true },
-	{ "BACLEARS.COND",			0xE6, 0x10, true },
-	{ "MS_DECODED.MS_ENTRY",		0xE7, 0x01, true },
+	{ "OFFCORE_RESPONSE_0",			0xb7, 0x01, true },
+	{ "OFFCORE_RESPONSE_1",			0xb7, 0x02, true },
+	{ "INST_RETIRED.ANY_P",			0xc0, 0x00, true },
+	{ 

CVS commit: src/usr.sbin/tprof/arch

2022-12-07 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Wed Dec  7 08:11:49 UTC 2022

Modified Files:
src/usr.sbin/tprof/arch: tprof_x86.c

Log Message:
KNF. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/usr.sbin/tprof/arch/tprof_x86.c

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

Modified files:

Index: src/usr.sbin/tprof/arch/tprof_x86.c
diff -u src/usr.sbin/tprof/arch/tprof_x86.c:1.12 src/usr.sbin/tprof/arch/tprof_x86.c:1.13
--- src/usr.sbin/tprof/arch/tprof_x86.c:1.12	Mon Jun 13 09:28:58 2022
+++ src/usr.sbin/tprof/arch/tprof_x86.c	Wed Dec  7 08:11:49 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: tprof_x86.c,v 1.12 2022/06/13 09:28:58 msaitoh Exp $	*/
+/*	$NetBSD: tprof_x86.c,v 1.13 2022/12/07 08:11:49 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2018-2019 The NetBSD Foundation, Inc.
@@ -71,7 +71,7 @@ static void x86_cpuid(unsigned int *eax,
 	: "0" (*eax), "2" (*ecx));
 }
 
-/* -- */
+/* - */
 
 /*
  * Intel Architectural Version 1.
@@ -374,142 +374,143 @@ init_intel_goldmontplus(void)
  */
 static struct name_to_event intel_skylake_kabylake_names[] = {
 	/* Event Name - Event Select - UMask */
-	{ "LD_BLOCKS.STORE_FORWARD",	0x03, 0x02, true },
-	{ "LD_BLOCKS.NO_SR",		0x03, 0x08, true },
-	{ "LD_BLOCKS_PARTIAL.ADDRESS_ALIAS",0x07, 0x01, true },
-	{ "DTLB_LOAD_MISSES.MISS_CAUSES_A_WALK",			0x08, 0x01, true },
-	{ "DTLB_LOAD_MISSES.WALK_COMPLETED_4K",0x08, 0x02, true },
-	{ "DTLB_LOAD_MISSES.WALK_COMPLETED_2M_4M",			0x08, 0x04, true },
-	{ "DTLB_LOAD_MISSES.WALK_COMPLETED_1G",0x08, 0x08, true },
-	{ "DTLB_LOAD_MISSES.WALK_COMPLETED",0x08, 0x0E, true },
-	{ "DTLB_LOAD_MISSES.WALK_PENDING",0x08, 0x10, true },
-	{ "DTLB_LOAD_MISSES.STLB_HIT",	0x08, 0x20, true },
-	{ "INT_MISC.RECOVERY_CYCLES",	0x0D, 0x01, true },
-	{ "INT_MISC.CLEAR_RESTEER_CYCLES",0x0D, 0x80, true },
-	{ "UOPS_ISSUED.ANY",		0x0E, 0x01, true },
-	{ "UOPS_ISSUED.VECTOR_WIDTH_MISMATCH",0x0E, 0x02, true },
-	{ "UOPS_ISSUED.SLOW_LEA",	0x0E, 0x20, true },
-	{ "L2_RQSTS.DEMAND_DATA_RD_MISS",0x24, 0x21, true },
-	{ "L2_RQSTS.RFO_MISS",		0x24, 0x22, true },
-	{ "L2_RQSTS.CODE_RD_MISS",	0x24, 0x24, true },
-	{ "L2_RQSTS.ALL_DEMAND_MISS",	0x24, 0x27, true },
-	{ "L2_RQSTS.PF_MISS",		0x24, 0x38, true },
-	{ "L2_RQSTS.MISS",		0x24, 0x3F, true },
-	{ "L2_RQSTS.DEMAND_DATA_RD_HIT",0x24, 0x41, true },
-	{ "L2_RQSTS.RFO_HIT",		0x24, 0x42, true },
-	{ "L2_RQSTS.CODE_RD_HIT",	0x24, 0x44, true },
-	{ "L2_RQSTS.PF_HIT",		0x24, 0xD8, true },
-	{ "L2_RQSTS.ALL_DEMAND_DATA_RD",0x24, 0xE1, true },
-	{ "L2_RQSTS.ALL_RFO",		0x24, 0xE2, true },
-	{ "L2_RQSTS.ALL_CODE_RD",	0x24, 0xE4, true },
-	{ "L2_RQSTS.ALL_DEMAND_REFERENCES",0x24, 0xE7, true },
-	{ "L2_RQSTS.ALL_PF",		0x24, 0xF8, true },
-	{ "L2_RQSTS.REFERENCES",	0x24, 0xFF, true },
-	{ "SW_PREFETCH_ACCESS.NTA",	0x32, 0x01, true },
-	{ "SW_PREFETCH_ACCESS.T0",	0x32, 0x02, true },
-	{ "SW_PREFETCH_ACCESS.T1_T2",	0x32, 0x04, true },
-	{ "SW_PREFETCH_ACCESS.PREFETCHW",0x32, 0x08, true },
-	{ "CPU_CLK_THREAD_UNHALTED.ONE_THREAD_ACTIVE",			0x3C, 0x02, true },
-	{ "CPU_CLK_UNHALTED.ONE_THREAD_ACTIVE",0x3C, 0x02, true },
-	{ "L1D_PEND_MISS.PENDING",	0x48, 0x01, true },
-	{ "L1D_PEND_MISS.FB_FULL",	0x48, 0x02, true },
-	{ "DTLB_STORE_MISSES.MISS_CAUSES_A_WALK",			0x49, 0x01, true },
-	{ "DTLB_STORE_MISSES.WALK_COMPLETED_4K",			0x49, 0x02, true },
-	{ "DTLB_STORE_MISSES.WALK_COMPLETED_2M_4M",			0x49, 0x04, true },
-	{ "DTLB_STORE_MISSES.WALK_COMPLETED_1G",			0x49, 0x08, true },
-	{ "DTLB_STORE_MISSES.WALK_COMPLETED",0x49, 0x0E, true },
-	{ "DTLB_STORE_MISSES.WALK_PENDING",0x49, 0x10, true },
-	{ "DTLB_STORE_MISSES.STLB_HIT",	0x49, 0x20, true },
-	{ "LOAD_HIT_PRE.SW_PF",		0x4C, 0x01, true },
-	{ "EPT.WALK_PENDING",		0x4F, 0x10, true },
-	{ "L1D.REPLACEMENT",		0x51, 0x01, true },
-	{ "RS_EVENTS.EMPTY_CYCLES",	0x5E, 0x01, true },
-	{ "OFFCORE_REQUESTS_OUTSTANDING.DEMAND_DATA_RD",		0x60, 0x01, true },
-	{ "OFFCORE_REQUESTS_OUTSTANDING.DEMAND_CODE_RD",		0x60, 0x02, true },
-	{ "OFFCORE_REQUESTS_OUTSTANDING.DEMAND_RFO",			0x60, 0x04, true },
-	{ "OFFCORE_REQUESTS_OUTSTANDING.ALL_DATA_RD",			0x60, 0x08, true },
-	{ "OFFCORE_REQUESTS_OUTSTANDING.L3_MISS_DEMAND_DATA_RD",	0x60, 0x10, true },
-	{ "IDQ.MITE_UOPS",		0x79, 0x04, true },
-	{ "IDQ.DSB_UOPS",		0x79, 0x08, true },
-	{ "IDQ.MS_MITE_UOPS",		0x79, 0x20, true },
-	{ "IDQ.MS_UOPS",		0x79, 0x30, true },
-	{ "ICACHE_16B.IFDATA_STALL",	0x80, 0x04, true },
-	{ "ICACHE_64B.IFTAG_HIT",	0x83, 0x01, true },
-	{ "ICACHE_64B.IFTAG_MISS",	0x83, 0x02, true },
-	{ "ICACHE_64B.IFTAG_STALL",	0x83, 0x04, true },
-	{ 

CVS commit: src/usr.sbin/tprof/arch

2022-12-07 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Wed Dec  7 08:11:49 UTC 2022

Modified Files:
src/usr.sbin/tprof/arch: tprof_x86.c

Log Message:
KNF. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/usr.sbin/tprof/arch/tprof_x86.c

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



CVS commit: src/usr.sbin/tprof

2022-12-04 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Mon Dec  5 05:02:45 UTC 2022

Modified Files:
src/usr.sbin/tprof: tprof.c

Log Message:
fix build error with llvm


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/usr.sbin/tprof/tprof.c

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

Modified files:

Index: src/usr.sbin/tprof/tprof.c
diff -u src/usr.sbin/tprof/tprof.c:1.16 src/usr.sbin/tprof/tprof.c:1.17
--- src/usr.sbin/tprof/tprof.c:1.16	Thu Dec  1 00:43:27 2022
+++ src/usr.sbin/tprof/tprof.c	Mon Dec  5 05:02:45 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: tprof.c,v 1.16 2022/12/01 00:43:27 ryo Exp $	*/
+/*	$NetBSD: tprof.c,v 1.17 2022/12/05 05:02:45 ryo Exp $	*/
 
 /*
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -57,7 +57,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: tprof.c,v 1.16 2022/12/01 00:43:27 ryo Exp $");
+__RCSID("$NetBSD: tprof.c,v 1.17 2022/12/05 05:02:45 ryo Exp $");
 #endif /* not lint */
 
 #include 
@@ -98,8 +98,8 @@ u_int eventnamewidth[TPROF_MAXCOUNTERS];
 
 static void tprof_list(int, char **);
 static void tprof_monitor_common(bool, int, char **) __dead;
-static void tprof_monitor(int, char **);
-static void tprof_count(int, char **);
+static void tprof_monitor(int, char **) __dead;
+static void tprof_count(int, char **) __dead;
 
 static struct cmdtab {
 	const char *label;



CVS commit: src/usr.sbin/tprof

2022-12-04 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Mon Dec  5 05:02:45 UTC 2022

Modified Files:
src/usr.sbin/tprof: tprof.c

Log Message:
fix build error with llvm


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/usr.sbin/tprof/tprof.c

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



CVS commit: src/usr.sbin/tprof

2022-11-30 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Thu Dec  1 03:32:24 UTC 2022

Modified Files:
src/usr.sbin/tprof: tprof_top.c

Log Message:
fix build error of printf format


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/tprof/tprof_top.c

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

Modified files:

Index: src/usr.sbin/tprof/tprof_top.c
diff -u src/usr.sbin/tprof/tprof_top.c:1.1 src/usr.sbin/tprof/tprof_top.c:1.2
--- src/usr.sbin/tprof/tprof_top.c:1.1	Thu Dec  1 00:43:27 2022
+++ src/usr.sbin/tprof/tprof_top.c	Thu Dec  1 03:32:24 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: tprof_top.c,v 1.1 2022/12/01 00:43:27 ryo Exp $	*/
+/*	$NetBSD: tprof_top.c,v 1.2 2022/12/01 03:32:24 ryo Exp $	*/
 
 /*-
  * Copyright (c) 2022 Ryo Shimizu 
@@ -28,7 +28,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: tprof_top.c,v 1.1 2022/12/01 00:43:27 ryo Exp $");
+__RCSID("$NetBSD: tprof_top.c,v 1.2 2022/12/01 03:32:24 ryo Exp $");
 #endif /* not lint */
 
 #include 
@@ -387,7 +387,7 @@ show_count_per_event(void)
 			printf("%5.2f%%", sample_nsample_per_event[i] *
 			100.00 / nsample_total);
 		}
-		printf("%8lu ", sample_nsample_per_event[i]);
+		printf("%8"PRIu64" ", sample_nsample_per_event[i]);
 
 		printf("%-32.32s", eventname[i]);
 		for (n = 0; n < ncpu; n++) {
@@ -481,10 +481,10 @@ sample_show(void)
 		name = e->name;
 		if (name == NULL) {
 			if (e->flags & SAMPLE_ELM_FLAGS_USER) {
-snprintf(namebuf, sizeof(namebuf), "",
+snprintf(namebuf, sizeof(namebuf), "",
 e->addr);
 			} else {
-snprintf(namebuf, sizeof(namebuf), "0x%016lx",
+snprintf(namebuf, sizeof(namebuf), "0x%016"PRIx64,
 e->addr);
 			}
 			name = namebuf;



CVS commit: src/usr.sbin/tprof

2022-11-30 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Thu Dec  1 03:32:24 UTC 2022

Modified Files:
src/usr.sbin/tprof: tprof_top.c

Log Message:
fix build error of printf format


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/tprof/tprof_top.c

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



CVS commit: src/usr.sbin/tprof

2022-11-30 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Thu Dec  1 00:43:27 UTC 2022

Modified Files:
src/usr.sbin/tprof: Makefile ksyms.c ksyms.h tprof.8 tprof.c tprof.h
tprof_analyze.c
Added Files:
src/usr.sbin/tprof: tprof_top.c

Log Message:
add "top" subcommand to tprof(8)


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/usr.sbin/tprof/Makefile
cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/tprof/ksyms.c \
src/usr.sbin/tprof/ksyms.h
cvs rdiff -u -r1.18 -r1.19 src/usr.sbin/tprof/tprof.8
cvs rdiff -u -r1.15 -r1.16 src/usr.sbin/tprof/tprof.c
cvs rdiff -u -r1.2 -r1.3 src/usr.sbin/tprof/tprof.h
cvs rdiff -u -r1.7 -r1.8 src/usr.sbin/tprof/tprof_analyze.c
cvs rdiff -u -r0 -r1.1 src/usr.sbin/tprof/tprof_top.c

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

Modified files:

Index: src/usr.sbin/tprof/Makefile
diff -u src/usr.sbin/tprof/Makefile:1.11 src/usr.sbin/tprof/Makefile:1.12
--- src/usr.sbin/tprof/Makefile:1.11	Thu Dec  1 00:41:10 2022
+++ src/usr.sbin/tprof/Makefile	Thu Dec  1 00:43:27 2022
@@ -1,10 +1,10 @@
-#	$NetBSD: Makefile,v 1.11 2022/12/01 00:41:10 ryo Exp $
+#	$NetBSD: Makefile,v 1.12 2022/12/01 00:43:27 ryo Exp $
 
 .PATH:	${.CURDIR}/arch
 
 PROG=	tprof
 MAN=	tprof.8
-SRCS=	tprof.c tprof_analyze.c ksyms.c
+SRCS=	tprof.c tprof_analyze.c tprof_top.c ksyms.c
 
 .if	${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "x86_64"
 SRCS+=	tprof_x86.c
@@ -19,9 +19,11 @@ SRCS+=	tprof_noarch.c
 CPPFLAGS+= -I${NETBSDSRCDIR}/sys/
 
 LDADD+= -lpthread
+LDADD+= -lm
 LDADD+= -lelf
 LDADD+= -lutil
 DPADD+= ${LIBPTHREAD}
+DPADD+= ${LIBM}
 DPADD+= ${LIBELF}
 DPADD+= ${LIBUTIL}
 

Index: src/usr.sbin/tprof/ksyms.c
diff -u src/usr.sbin/tprof/ksyms.c:1.1 src/usr.sbin/tprof/ksyms.c:1.2
--- src/usr.sbin/tprof/ksyms.c:1.1	Thu Dec  1 00:41:10 2022
+++ src/usr.sbin/tprof/ksyms.c	Thu Dec  1 00:43:27 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: ksyms.c,v 1.1 2022/12/01 00:41:10 ryo Exp $	*/
+/*	$NetBSD: ksyms.c,v 1.2 2022/12/01 00:43:27 ryo Exp $	*/
 
 /*
  * Copyright (c) 2010,2011,2012 YAMAMOTO Takashi,
@@ -28,7 +28,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: ksyms.c,v 1.1 2022/12/01 00:41:10 ryo Exp $");
+__RCSID("$NetBSD: ksyms.c,v 1.2 2022/12/01 00:43:27 ryo Exp $");
 #endif /* not lint */
 
 #include 
@@ -43,8 +43,8 @@ __RCSID("$NetBSD: ksyms.c,v 1.1 2022/12/
 #include 
 #include "ksyms.h"
 
-struct sym **syms = NULL;
-size_t nsyms = 0;
+static struct sym **syms = NULL;
+static size_t nsyms = 0;
 
 static int
 compare_value(const void *p1, const void *p2)
@@ -69,8 +69,8 @@ compare_value(const void *p1, const void
 	return strcmp(s1->name, s2->name);
 }
 
-void
-ksymload(void)
+struct sym **
+ksymload(size_t *nsymp)
 {
 	Elf *e;
 	Elf_Scn *s;
@@ -132,13 +132,15 @@ ksymload(void)
 	elf_end(e);
 	close(fd);
 	qsort(syms, nsyms, sizeof(*syms), compare_value);
-	return;
+	if (nsymp != NULL)
+		*nsymp = nsyms;
+	return syms;
 elffail:
 	errx(EXIT_FAILURE, "libelf: %s", elf_errmsg(elf_errno()));
 }
 
 const char *
-ksymlookup(uint64_t value, uint64_t *offset)
+ksymlookup(uint64_t value, uint64_t *offset, size_t *n)
 {
 	size_t hi;
 	size_t lo;
@@ -171,6 +173,8 @@ ksymlookup(uint64_t value, uint64_t *off
 		if (sym->value <= value &&
 		(sym->size == 0 || value - sym->value <= sym->size )) {
 			*offset = value - sym->value;
+			if (n != NULL)
+*n = i;
 			return sym->name;
 		}
 		if (sym->size != 0 && sym->value + sym->size < value) {
Index: src/usr.sbin/tprof/ksyms.h
diff -u src/usr.sbin/tprof/ksyms.h:1.1 src/usr.sbin/tprof/ksyms.h:1.2
--- src/usr.sbin/tprof/ksyms.h:1.1	Thu Dec  1 00:41:10 2022
+++ src/usr.sbin/tprof/ksyms.h	Thu Dec  1 00:43:27 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: ksyms.h,v 1.1 2022/12/01 00:41:10 ryo Exp $	*/
+/*	$NetBSD: ksyms.h,v 1.2 2022/12/01 00:43:27 ryo Exp $	*/
 
 /*
  * Copyright (c) 2010,2011,2012 YAMAMOTO Takashi,
@@ -35,10 +35,7 @@ struct sym {
 	uint64_t size;
 };
 
-extern struct sym **syms;
-extern size_t nsyms;
-
-void ksymload(void);
-const char *ksymlookup(uint64_t, uint64_t *);
+struct sym **ksymload(size_t *);
+const char *ksymlookup(uint64_t, uint64_t *, size_t *);
 
 #endif /* _KSYMS_H_ */

Index: src/usr.sbin/tprof/tprof.8
diff -u src/usr.sbin/tprof/tprof.8:1.18 src/usr.sbin/tprof/tprof.8:1.19
--- src/usr.sbin/tprof/tprof.8:1.18	Thu Dec  1 00:40:05 2022
+++ src/usr.sbin/tprof/tprof.8	Thu Dec  1 00:43:27 2022
@@ -1,4 +1,4 @@
-.\"	$NetBSD: tprof.8,v 1.18 2022/12/01 00:40:05 ryo Exp $
+.\"	$NetBSD: tprof.8,v 1.19 2022/12/01 00:43:27 ryo Exp $
 .\"
 .\" Copyright (c)2011 YAMAMOTO Takashi,
 .\" All rights reserved.
@@ -130,6 +130,39 @@ and ignore the rest.
 .It Fl s
 Per symbol.
 .El
+.It top Xo
+.Oo
+.Fl e
+.Ar name[,value]
+.Op Fl e Ar ...
+.Oc
+.Op Fl i Ar interval
+.Op Fl c
+.Op Fl u
+.Xc
+Displays profiling results in real-time.
+.Ar name
+specifies the name of the event to count.
+.Ar value
+specifies the ratio of the speed to the cycle counter, or the counter until
+overflow.

CVS commit: src/usr.sbin/tprof

2022-11-30 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Thu Dec  1 00:43:27 UTC 2022

Modified Files:
src/usr.sbin/tprof: Makefile ksyms.c ksyms.h tprof.8 tprof.c tprof.h
tprof_analyze.c
Added Files:
src/usr.sbin/tprof: tprof_top.c

Log Message:
add "top" subcommand to tprof(8)


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/usr.sbin/tprof/Makefile
cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/tprof/ksyms.c \
src/usr.sbin/tprof/ksyms.h
cvs rdiff -u -r1.18 -r1.19 src/usr.sbin/tprof/tprof.8
cvs rdiff -u -r1.15 -r1.16 src/usr.sbin/tprof/tprof.c
cvs rdiff -u -r1.2 -r1.3 src/usr.sbin/tprof/tprof.h
cvs rdiff -u -r1.7 -r1.8 src/usr.sbin/tprof/tprof_analyze.c
cvs rdiff -u -r0 -r1.1 src/usr.sbin/tprof/tprof_top.c

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



CVS commit: src/usr.sbin/tprof

2022-11-30 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Thu Dec  1 00:41:10 UTC 2022

Modified Files:
src/usr.sbin/tprof: Makefile tprof_analyze.c
Added Files:
src/usr.sbin/tprof: ksyms.c ksyms.h

Log Message:
split ksyms stuff into ksyms.[ch]


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/usr.sbin/tprof/Makefile
cvs rdiff -u -r0 -r1.1 src/usr.sbin/tprof/ksyms.c src/usr.sbin/tprof/ksyms.h
cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/tprof/tprof_analyze.c

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

Modified files:

Index: src/usr.sbin/tprof/Makefile
diff -u src/usr.sbin/tprof/Makefile:1.10 src/usr.sbin/tprof/Makefile:1.11
--- src/usr.sbin/tprof/Makefile:1.10	Tue Nov 17 10:47:17 2020
+++ src/usr.sbin/tprof/Makefile	Thu Dec  1 00:41:10 2022
@@ -1,10 +1,10 @@
-#	$NetBSD: Makefile,v 1.10 2020/11/17 10:47:17 rin Exp $
+#	$NetBSD: Makefile,v 1.11 2022/12/01 00:41:10 ryo Exp $
 
 .PATH:	${.CURDIR}/arch
 
 PROG=	tprof
 MAN=	tprof.8
-SRCS=	tprof.c tprof_analyze.c
+SRCS=	tprof.c tprof_analyze.c ksyms.c
 
 .if	${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "x86_64"
 SRCS+=	tprof_x86.c

Index: src/usr.sbin/tprof/tprof_analyze.c
diff -u src/usr.sbin/tprof/tprof_analyze.c:1.6 src/usr.sbin/tprof/tprof_analyze.c:1.7
--- src/usr.sbin/tprof/tprof_analyze.c:1.6	Thu Dec  1 00:32:52 2022
+++ src/usr.sbin/tprof/tprof_analyze.c	Thu Dec  1 00:41:10 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: tprof_analyze.c,v 1.6 2022/12/01 00:32:52 ryo Exp $	*/
+/*	$NetBSD: tprof_analyze.c,v 1.7 2022/12/01 00:41:10 ryo Exp $	*/
 
 /*
  * Copyright (c) 2010,2011,2012 YAMAMOTO Takashi,
@@ -28,7 +28,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: tprof_analyze.c,v 1.6 2022/12/01 00:32:52 ryo Exp $");
+__RCSID("$NetBSD: tprof_analyze.c,v 1.7 2022/12/01 00:41:10 ryo Exp $");
 #endif /* not lint */
 
 #include 
@@ -46,8 +46,7 @@ __RCSID("$NetBSD: tprof_analyze.c,v 1.6 
 #include 
 #include 
 #include "tprof.h"
-
-#define	_PATH_KSYMS	"/dev/ksyms"
+#include "ksyms.h"
 
 #include 
 
@@ -68,147 +67,6 @@ struct addr {
 
 static rb_tree_t addrtree;
 
-struct sym {
-	char *name;
-	uint64_t value;
-	uint64_t size;
-};
-
-static struct sym **syms = NULL;
-static size_t nsyms = 0;
-
-static int
-compare_value(const void *p1, const void *p2)
-{
-	const struct sym *s1 = *(const struct sym * const *)p1;
-	const struct sym *s2 = *(const struct sym * const *)p2;
-
-	if (s1->value > s2->value) {
-		return -1;
-	} else if (s1->value < s2->value) {
-		return 1;
-	}
-	/*
-	 * to produce a stable result, it's better not to return 0
-	 * even for __strong_alias.
-	 */
-	if (s1->size > s2->size) {
-		return -1;
-	} else if (s1->size < s2->size) {
-		return 1;
-	}
-	return strcmp(s1->name, s2->name);
-}
-
-static void
-ksymload(void)
-{
-	Elf *e;
-	Elf_Scn *s;
-	GElf_Shdr sh_store;
-	GElf_Shdr *sh;
-	Elf_Data *d;
-	int fd;
-	size_t size, i;
-
-	fd = open(_PATH_KSYMS, O_RDONLY);
-	if (fd == -1) {
-		err(EXIT_FAILURE, "open " _PATH_KSYMS);
-	}
-	if (elf_version(EV_CURRENT) == EV_NONE) {
-		goto elffail;
-	}
-	e = elf_begin(fd, ELF_C_READ, NULL);
-	if (e == NULL) {
-		goto elffail;
-	}
-	for (s = elf_nextscn(e, NULL); s != NULL; s = elf_nextscn(e, s)) {
-		sh = gelf_getshdr(s, _store);
-		if (sh == NULL) {
-			goto elffail;
-		}
-		if (sh->sh_type == SHT_SYMTAB) {
-			break;
-		}
-	}
-	if (s == NULL) {
-		errx(EXIT_FAILURE, "no symtab");
-	}
-	d = elf_getdata(s, NULL);
-	if (d == NULL) {
-		goto elffail;
-	}
-	assert(sh->sh_size == d->d_size);
-	size = sh->sh_size / sh->sh_entsize;
-	for (i = 1; i < size; i++) {
-		GElf_Sym st_store;
-		GElf_Sym *st;
-		struct sym *sym;
-
-		st = gelf_getsym(d, (int)i, _store);
-		if (st == NULL) {
-			goto elffail;
-		}
-		if (ELF_ST_TYPE(st->st_info) != STT_FUNC) {
-			continue;
-		}
-		sym = emalloc(sizeof(*sym));
-		sym->name = estrdup(elf_strptr(e, sh->sh_link, st->st_name));
-		sym->value = (uint64_t)st->st_value;
-		sym->size = st->st_size;
-		nsyms++;
-		syms = erealloc(syms, sizeof(*syms) * nsyms);
-		syms[nsyms - 1] = sym;
-	}
-	qsort(syms, nsyms, sizeof(*syms), compare_value);
-	return;
-elffail:
-	errx(EXIT_FAILURE, "libelf: %s", elf_errmsg(elf_errno()));
-}
-
-static const char *
-ksymlookup(uint64_t value, uint64_t *offset)
-{
-	size_t hi;
-	size_t lo;
-	size_t i;
-
-	/*
-	 * try to find the smallest i for which syms[i]->value <= value.
-	 * syms[] is ordered by syms[]->value in the descending order.
-	 */
-
-	hi = nsyms - 1;
-	lo = 0;
-	while (lo < hi) {
-		const size_t mid = (lo + hi) / 2;
-		const struct sym *sym = syms[mid];
-
-		assert(syms[lo]->value >= sym->value);
-		assert(sym->value >= syms[hi]->value);
-		if (sym->value <= value) {
-			hi = mid;
-			continue;
-		}
-		lo = mid + 1;
-	}
-	assert(lo == nsyms - 1 || syms[lo]->value <= value);
-	assert(lo == 0 || syms[lo - 1]->value > value);
-	for (i = lo; i < nsyms; i++) {
-		const struct sym *sym = syms[i];
-
-		if (sym->value <= value &&
-		(sym->size == 0 || value - 

CVS commit: src/usr.sbin/tprof

2022-11-30 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Thu Dec  1 00:41:10 UTC 2022

Modified Files:
src/usr.sbin/tprof: Makefile tprof_analyze.c
Added Files:
src/usr.sbin/tprof: ksyms.c ksyms.h

Log Message:
split ksyms stuff into ksyms.[ch]


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/usr.sbin/tprof/Makefile
cvs rdiff -u -r0 -r1.1 src/usr.sbin/tprof/ksyms.c src/usr.sbin/tprof/ksyms.h
cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/tprof/tprof_analyze.c

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



CVS commit: src/usr.sbin/tprof

2022-11-30 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Thu Dec  1 00:40:05 UTC 2022

Modified Files:
src/usr.sbin/tprof: tprof.8 tprof.c

Log Message:
Improve tprof(8)

- Added "tprof count" subcommand to perform counts only.
- Event options (u,k) are now optional. The default value is both userland and 
kernel. (:uk)
- Event counters can be displayed with SIGINFO during `tprof monitor' or `tprof 
count'.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/usr.sbin/tprof/tprof.8
cvs rdiff -u -r1.14 -r1.15 src/usr.sbin/tprof/tprof.c

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

Modified files:

Index: src/usr.sbin/tprof/tprof.8
diff -u src/usr.sbin/tprof/tprof.8:1.17 src/usr.sbin/tprof/tprof.8:1.18
--- src/usr.sbin/tprof/tprof.8:1.17	Thu Dec  1 00:32:52 2022
+++ src/usr.sbin/tprof/tprof.8	Thu Dec  1 00:40:05 2022
@@ -1,4 +1,4 @@
-.\"	$NetBSD: tprof.8,v 1.17 2022/12/01 00:32:52 ryo Exp $
+.\"	$NetBSD: tprof.8,v 1.18 2022/12/01 00:40:05 ryo Exp $
 .\"
 .\" Copyright (c)2011 YAMAMOTO Takashi,
 .\" All rights reserved.
@@ -66,7 +66,7 @@ Valid actions are:
 Display a list of performance counter events available on the system.
 .It monitor Xo
 .Fl e
-.Ar name:option
+.Ar name[:option]
 .Op Fl e Ar ...
 .Op Fl o Ar outfile
 .Ar command
@@ -81,12 +81,25 @@ specifies the source of the event; it mu
 .Ar u
 (userland) and
 .Ar k
-(kernel).
+(kernel). If omitted, it is assumed that both are specified.
 The collected samples are written into the file
 .Ar outfile
 if specified.
 The default is
 .Dq Pa tprof.out .
+.It count Xo
+.Fl e
+.Ar name[:option]
+.Op Fl e Ar ...
+.Op Fl i Ar interval
+.Ar command
+.Xc
+Same as
+.Ar monitor ,
+but does not do any profiling,
+only outputs counters every
+.Ar interval
+second.
 .It analyze Xo
 .Op Fl CkLPs
 .Op Fl p Ar pid

Index: src/usr.sbin/tprof/tprof.c
diff -u src/usr.sbin/tprof/tprof.c:1.14 src/usr.sbin/tprof/tprof.c:1.15
--- src/usr.sbin/tprof/tprof.c:1.14	Thu Dec  1 00:32:52 2022
+++ src/usr.sbin/tprof/tprof.c	Thu Dec  1 00:40:05 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: tprof.c,v 1.14 2022/12/01 00:32:52 ryo Exp $	*/
+/*	$NetBSD: tprof.c,v 1.15 2022/12/01 00:40:05 ryo Exp $	*/
 
 /*
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -57,10 +57,12 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: tprof.c,v 1.14 2022/12/01 00:32:52 ryo Exp $");
+__RCSID("$NetBSD: tprof.c,v 1.15 2022/12/01 00:40:05 ryo Exp $");
 #endif /* not lint */
 
+#include 
 #include 
+#include 
 #include 
 
 #include 
@@ -69,13 +71,16 @@ __RCSID("$NetBSD: tprof.c,v 1.14 2022/12
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
+#include 
 #include "tprof.h"
 
 #define	_PATH_TPROF	"/dev/tprof"
@@ -84,10 +89,17 @@ struct tprof_info tprof_info;
 u_int ncounters;
 int devfd;
 int outfd;
+int ncpu;
 u_int nevent;
+double interval = 0x;	/* XXX */
+const char *eventname[TPROF_MAXCOUNTERS];
+u_int eventnamewidth[TPROF_MAXCOUNTERS];
+#define	COUNTER_COLUMNS_WIDTH	11
 
 static void tprof_list(int, char **);
-static void tprof_monitor(int, char **) __dead;
+static void tprof_monitor_common(bool, int, char **) __dead;
+static void tprof_monitor(int, char **);
+static void tprof_count(int, char **);
 
 static struct cmdtab {
 	const char *label;
@@ -97,6 +109,7 @@ static struct cmdtab {
 } const tprof_cmdtab[] = {
 	{ "list",	false, false, tprof_list },
 	{ "monitor",	true,  false, tprof_monitor },
+	{ "count",	true,  false, tprof_count },
 	{ "analyze",	true,  true,  tprof_analyze },
 	{ NULL,		false, false, NULL },
 };
@@ -109,15 +122,33 @@ usage(void)
 	fprintf(stderr, "\n");
 	fprintf(stderr, "\tlist\n");
 	fprintf(stderr, "\t\tList the available events.\n");
-	fprintf(stderr, "\tmonitor -e name:option [-e ...] [-o outfile] command\n");
+	fprintf(stderr, "\tmonitor -e name[:option] [-e ...] [-o outfile] command\n");
 	fprintf(stderr, "\t\tMonitor the event 'name' with option 'option'\n"
 	"\t\tcounted during the execution of 'command'.\n");
+	fprintf(stderr, "\tcount -e name[:option] [-e ...] [-i interval]"
+	" command\n");
+	fprintf(stderr, "\t\tSame as monitor, but does not profile,"
+	" only outputs a counter.\n");
 	fprintf(stderr, "\tanalyze [-CkLPs] [-p pid] file\n");
 	fprintf(stderr, "\t\tAnalyze the samples of the file 'file'.\n");
 
 	exit(EXIT_FAILURE);
 }
 
+static int
+getncpu(void)
+{
+	size_t size;
+	int mib[2];
+
+	mib[0] = CTL_HW;
+	mib[1] = HW_NCPU;
+	size = sizeof(ncpu);
+	if (sysctl(mib, 2, , , NULL, 0) == -1)
+		ncpu = 1;
+	return ncpu;
+}
+
 static void *
 process_samples(void *dummy)
 {
@@ -150,13 +181,87 @@ process_samples(void *dummy)
 }
 
 static void
+show_counters(void)
+{
+	unsigned int i;
+	int n, ret;
+
+	fprintf(stderr, "  ");
+	for (i = 0; i < nevent; i++)
+		fprintf(stderr, " %*s", eventnamewidth[i], eventname[i]);
+	fprintf(stderr, "\n");
+
+	for (n = 0; n < ncpu; n++) {
+		tprof_counts_t 

CVS commit: src/usr.sbin/tprof

2022-11-30 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Thu Dec  1 00:40:05 UTC 2022

Modified Files:
src/usr.sbin/tprof: tprof.8 tprof.c

Log Message:
Improve tprof(8)

- Added "tprof count" subcommand to perform counts only.
- Event options (u,k) are now optional. The default value is both userland and 
kernel. (:uk)
- Event counters can be displayed with SIGINFO during `tprof monitor' or `tprof 
count'.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/usr.sbin/tprof/tprof.8
cvs rdiff -u -r1.14 -r1.15 src/usr.sbin/tprof/tprof.c

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



CVS commit: src/usr.sbin/tprof/arch

2022-06-13 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Jun 13 09:28:58 UTC 2022

Modified Files:
src/usr.sbin/tprof/arch: tprof_x86.c

Log Message:
Disable the unsupported events from the bit vector length in EAX.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/usr.sbin/tprof/arch/tprof_x86.c

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

Modified files:

Index: src/usr.sbin/tprof/arch/tprof_x86.c
diff -u src/usr.sbin/tprof/arch/tprof_x86.c:1.11 src/usr.sbin/tprof/arch/tprof_x86.c:1.12
--- src/usr.sbin/tprof/arch/tprof_x86.c:1.11	Mon Jun 13 07:40:58 2022
+++ src/usr.sbin/tprof/arch/tprof_x86.c	Mon Jun 13 09:28:58 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: tprof_x86.c,v 1.11 2022/06/13 07:40:58 msaitoh Exp $	*/
+/*	$NetBSD: tprof_x86.c,v 1.12 2022/06/13 09:28:58 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2018-2019 The NetBSD Foundation, Inc.
@@ -99,7 +99,7 @@ static struct event_table intel_arch1 = 
 static struct event_table *
 init_intel_arch1(void)
 {
-	unsigned int eax, ebx, ecx, edx;
+	unsigned int eax, ebx, ecx, edx, vectorlen;
 	struct event_table *table;
 	size_t i;
 
@@ -109,9 +109,17 @@ init_intel_arch1(void)
 	edx = 0;
 	x86_cpuid(, , , );
 
+	vectorlen = __SHIFTOUT(eax, CPUID_PERF_BVECLEN);
+
 	table = _arch1;
 	for (i = 0; i < table->nevents; i++) {
-		/* Disable the unsupported events. */
+		/*
+		 * Disable the unsupported events from:
+		 * a) the bit vector length in EAX.
+		 * b) the disable bit in EBX.
+		 */
+		if (i >= vectorlen)
+			table->names[i].enabled = false;
 		if ((ebx & (i << 1)) != 0)
 			table->names[i].enabled = false;
 	}



CVS commit: src/usr.sbin/tprof/arch

2022-06-13 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Jun 13 09:28:58 UTC 2022

Modified Files:
src/usr.sbin/tprof/arch: tprof_x86.c

Log Message:
Disable the unsupported events from the bit vector length in EAX.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/usr.sbin/tprof/arch/tprof_x86.c

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



CVS commit: src/usr.sbin/tprof/arch

2022-06-13 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Jun 13 07:40:58 UTC 2022

Modified Files:
src/usr.sbin/tprof/arch: tprof_x86.c

Log Message:
Add topdown-slots to Intel architectural performance monitoring version 1.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/usr.sbin/tprof/arch/tprof_x86.c

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

Modified files:

Index: src/usr.sbin/tprof/arch/tprof_x86.c
diff -u src/usr.sbin/tprof/arch/tprof_x86.c:1.10 src/usr.sbin/tprof/arch/tprof_x86.c:1.11
--- src/usr.sbin/tprof/arch/tprof_x86.c:1.10	Fri Apr 17 03:15:50 2020
+++ src/usr.sbin/tprof/arch/tprof_x86.c	Mon Jun 13 07:40:58 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: tprof_x86.c,v 1.10 2020/04/17 03:15:50 knakahara Exp $	*/
+/*	$NetBSD: tprof_x86.c,v 1.11 2022/06/13 07:40:58 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2018-2019 The NetBSD Foundation, Inc.
@@ -85,6 +85,7 @@ static struct name_to_event intel_arch1_
 	{ "llc-misses",			0x2E, 0x41, true },
 	{ "branch-instruction-retired",	0xC4, 0x00, true },
 	{ "branch-misses-retired",	0xC5, 0x00, true },
+	{ "topdown-slots",		0xA4, 0x01, true },
 };
 
 static struct event_table intel_arch1 = {



CVS commit: src/usr.sbin/tprof/arch

2022-06-13 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Jun 13 07:40:58 UTC 2022

Modified Files:
src/usr.sbin/tprof/arch: tprof_x86.c

Log Message:
Add topdown-slots to Intel architectural performance monitoring version 1.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/usr.sbin/tprof/arch/tprof_x86.c

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



CVS commit: src/usr.sbin/tprof

2022-05-25 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Wed May 25 06:17:19 UTC 2022

Modified Files:
src/usr.sbin/tprof: tprof.8

Log Message:
Add note about tprof(4) for people like me who forget to load tprof_x86.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/usr.sbin/tprof/tprof.8

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

Modified files:

Index: src/usr.sbin/tprof/tprof.8
diff -u src/usr.sbin/tprof/tprof.8:1.15 src/usr.sbin/tprof/tprof.8:1.16
--- src/usr.sbin/tprof/tprof.8:1.15	Fri Oct 11 20:18:20 2019
+++ src/usr.sbin/tprof/tprof.8	Wed May 25 06:17:19 2022
@@ -1,4 +1,4 @@
-.\"	$NetBSD: tprof.8,v 1.15 2019/10/11 20:18:20 jmcneill Exp $
+.\"	$NetBSD: tprof.8,v 1.16 2022/05/25 06:17:19 msaitoh Exp $
 .\"
 .\" Copyright (c)2011 YAMAMOTO Takashi,
 .\" All rights reserved.
@@ -50,6 +50,9 @@ and reports statistics to the standard e
 The
 .Nm tprof
 pseudo driver and a suitable backend should be loaded beforehand.
+See
+.Xr tprof 4
+for the details.
 .Pp
 The
 .Nm



CVS commit: src/usr.sbin/tprof

2022-05-25 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Wed May 25 06:17:19 UTC 2022

Modified Files:
src/usr.sbin/tprof: tprof.8

Log Message:
Add note about tprof(4) for people like me who forget to load tprof_x86.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/usr.sbin/tprof/tprof.8

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



CVS commit: src/usr.sbin/tprof

2021-10-14 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Oct 14 09:52:40 UTC 2021

Modified Files:
src/usr.sbin/tprof: tprof_analyze.c

Log Message:
Output alignement - give lwp 6 characters


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/tprof/tprof_analyze.c

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

Modified files:

Index: src/usr.sbin/tprof/tprof_analyze.c
diff -u src/usr.sbin/tprof/tprof_analyze.c:1.4 src/usr.sbin/tprof/tprof_analyze.c:1.5
--- src/usr.sbin/tprof/tprof_analyze.c:1.4	Sat Jan 30 11:46:25 2021
+++ src/usr.sbin/tprof/tprof_analyze.c	Thu Oct 14 09:52:40 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tprof_analyze.c,v 1.4 2021/01/30 11:46:25 jmcneill Exp $	*/
+/*	$NetBSD: tprof_analyze.c,v 1.5 2021/10/14 09:52:40 skrll Exp $	*/
 
 /*
  * Copyright (c) 2010,2011,2012 YAMAMOTO Takashi,
@@ -28,7 +28,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: tprof_analyze.c,v 1.4 2021/01/30 11:46:25 jmcneill Exp $");
+__RCSID("$NetBSD: tprof_analyze.c,v 1.5 2021/10/14 09:52:40 skrll Exp $");
 #endif /* not lint */
 
 #include 
@@ -423,8 +423,8 @@ tprof_analyze(int argc, char **argv)
 	 */
 	printf("File: %s\n", argv[0]);
 	printf("Number of samples: %zu\n\n", nsamples);
-	printf("percentage   nsamples pidlwp  cpu  k address  symbol\n");
-	printf("  --   -  --\n");
+	printf("percentage   nsamples pidlwpcpu  k address  symbol\n");
+	printf("  -- --  -  --\n");
 	for (i = 0; i < naddrs; i++) {
 		const char *name;
 		char buf[100];
@@ -448,7 +448,7 @@ tprof_analyze(int argc, char **argv)
 
 		perc = ((float)a->nsamples / (float)nsamples) * 100.0;
 
-		printf("%11f%% %8u %6" PRIu32 " %4" PRIu32 " %4" PRIu32 " %u %016"
+		printf("%11f%% %8u %6" PRIu32 " %6" PRIu32 " %4" PRIu32 " %u %016"
 		PRIx64 " %s\n",
 		perc,
 		a->nsamples, a->pid, a->lwpid, a->cpuid, a->in_kernel,



CVS commit: src/usr.sbin/tprof

2021-10-14 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Oct 14 09:52:40 UTC 2021

Modified Files:
src/usr.sbin/tprof: tprof_analyze.c

Log Message:
Output alignement - give lwp 6 characters


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/tprof/tprof_analyze.c

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



CVS commit: src/usr.sbin/tprof

2019-10-11 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri Oct 11 20:18:20 UTC 2019

Modified Files:
src/usr.sbin/tprof: tprof.8

Log Message:
Add AMD Family 15h to supported model list


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/usr.sbin/tprof/tprof.8

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



CVS commit: src/usr.sbin/tprof

2019-10-11 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri Oct 11 20:18:20 UTC 2019

Modified Files:
src/usr.sbin/tprof: tprof.8

Log Message:
Add AMD Family 15h to supported model list


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/usr.sbin/tprof/tprof.8

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

Modified files:

Index: src/usr.sbin/tprof/tprof.8
diff -u src/usr.sbin/tprof/tprof.8:1.14 src/usr.sbin/tprof/tprof.8:1.15
--- src/usr.sbin/tprof/tprof.8:1.14	Wed May 29 17:09:17 2019
+++ src/usr.sbin/tprof/tprof.8	Fri Oct 11 20:18:20 2019
@@ -1,4 +1,4 @@
-.\"	$NetBSD: tprof.8,v 1.14 2019/05/29 17:09:17 maxv Exp $
+.\"	$NetBSD: tprof.8,v 1.15 2019/10/11 20:18:20 jmcneill 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 May 29, 2019
+.Dd October 11, 2019
 .Dt TPROF 8
 .Os
 .Sh NAME
@@ -130,6 +130,8 @@ ARMv8
 .It
 x86 AMD Family 10h
 .It
+x86 AMD Family 15h
+.It
 x86 AMD Family 17h
 .It
 x86 Intel Generic (all Intel CPUs)



CVS commit: src/usr.sbin/tprof/arch

2019-10-11 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri Oct 11 18:05:52 UTC 2019

Modified Files:
src/usr.sbin/tprof/arch: tprof_x86.c

Log Message:
Add support for AMD Family 15h


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/usr.sbin/tprof/arch/tprof_x86.c

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

Modified files:

Index: src/usr.sbin/tprof/arch/tprof_x86.c
diff -u src/usr.sbin/tprof/arch/tprof_x86.c:1.8 src/usr.sbin/tprof/arch/tprof_x86.c:1.9
--- src/usr.sbin/tprof/arch/tprof_x86.c:1.8	Wed May 29 17:09:18 2019
+++ src/usr.sbin/tprof/arch/tprof_x86.c	Fri Oct 11 18:05:52 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: tprof_x86.c,v 1.8 2019/05/29 17:09:18 maxv Exp $	*/
+/*	$NetBSD: tprof_x86.c,v 1.9 2019/10/11 18:05:52 jmcneill Exp $	*/
 
 /*
  * Copyright (c) 2018-2019 The NetBSD Foundation, Inc.
@@ -655,6 +655,120 @@ static struct event_table amd_f10h = {
 };
 
 /*
+ * AMD Family 15h
+ */
+static struct name_to_event amd_f15h_names[] = {
+	{ "FpPipeAssignment",		0x000, 0x77, true },
+	{ "FpSchedulerEmpty",		0x001, 0x00, true },
+	{ "FpRetSseAvxOps",		0x003, 0xff, true },
+	{ "FpNumMovElim",		0x004, 0x0f, true },
+	{ "FpRetiredSerOps",		0x005, 0x0f, true },
+	{ "LsSegRegLoads",		0x020, 0x7f, true },
+	{ "LsPipeRestartSelfMod",	0x021, 0x00, true },
+	{ "LsPipeRestartVarious",	0x022, 0x1f, true },
+	{ "LsLoadQueueStoreQFull",	0x023, 0x03, true },
+	{ "LsLockedOps",		0x024, 0x00, true },
+	{ "LsRetClflushInstr",		0x026, 0x00, true },
+	{ "LsRetCpuidInstr",		0x027, 0x00, true },
+	{ "LsDispatch",			0x029, 0x07, true },
+	{ "LsCanStoreToLoadFwOps",	0x02a, 0x03, true },
+	{ "LsSmisReceived",		0x02b, 0x00, true },
+	{ "LsExecClflushInstr",		0x030, 0x00, true },
+	{ "LsMisalignStore",		0x032, 0x00, true },
+	{ "LsFpLoadBufStall",		0x034, 0x00, true },
+	{ "LsStlf",			0x035, 0x00, true },
+	{ "DcCacheAccess",		0x040, 0x00, true },
+	{ "DcCacheMiss",		0x041, 0x00, true },
+	{ "DcCacheFillL2Sys",		0x042, 0x1f, true },
+	{ "DcCacheFillSys",		0x043, 0x00, true },
+	{ "DcUnifiedTlbHit",		0x045, 0x77, true },
+	{ "DcUnifiedTlbMiss",		0x046, 0x77, true },
+	{ "DcMisalignAccess",		0x047, 0x00, true },
+	{ "DcPrefetchInstrDisp",	0x04b, 0x07, true },
+	{ "DcIneffSwPrefetch",		0x052, 0x09, true },
+	{ "CuCmdVictimBuf",		0x060, 0x98, true },
+	{ "CuCmdMaskedOps",		0x061, 0x65, true },
+	{ "CuCmdReadBlkOps",		0x062, 0x77, true },
+	{ "CuCmdChgDirtyOps",		0x063, 0x08, true },
+	{ "CuDramSysReq",		0x064, 0x00, true },
+	{ "CuMemReqByType",		0x065, 0x83, true },
+	{ "CuDataCachePrefetch",	0x067, 0x03, true },
+	{ "CuMabReq",			0x068, 0xff, true },
+	{ "CuMabWaitCyc",		0x069, 0xff, true },
+	{ "CuSysRespCacheFill",		0x06c, 0x3f, true },
+	{ "CuOctwordsWritten",		0x06d, 0x01, true },
+	{ "CuCacheXInv",		0x075, 0x0f, true },
+	{ "CuCpuClkNotHalted",		0x076, 0x00, true },
+	{ "CuL2Req",			0x07d, 0x5f, true },
+	{ "CuL2Miss",			0x07e, 0x17, true },
+	{ "CuL2FillWb",			0x07f, 0x07, true },
+	{ "CuPageSplintering",		0x165, 0x07, true },
+	{ "CuL2PrefetchTrigEv",		0x16c, 0x03, true },
+	{ "CuXabAllocStall",		0x177, 0x03, true },
+	{ "CuFreeXabEntries",		0x17f, 0x01, true },
+	{ "IcCacheFetch",		0x080, 0x00, true },
+	{ "IcCacheMiss",		0x081, 0x00, true },
+	{ "IcCacheFillL2",		0x082, 0x00, true },
+	{ "IcCacheFillSys",		0x083, 0x00, true },
+	{ "IcL1TlbMissL2Hit",		0x084, 0x00, true },
+	{ "IcL1TlbMissL2Miss",		0x085, 0x07, true },
+	{ "IcPipeRestartInstrStrProbe",	0x086, 0x00, true },
+	{ "IcFetchStall",		0x087, 0x00, true },
+	{ "IcRetStackHits",		0x088, 0x00, true },
+	{ "IcRetStackOver",		0x089, 0x00, true },
+	{ "IcCacheVictims",		0x08b, 0x00, true },
+	{ "IcCacheLinesInv",		0x08c, 0x0f, true },
+	{ "IcTlbReload",		0x099, 0x00, true },
+	{ "IcTlbReloadAbort",		0x09a, 0x00, true },
+	{ "IcUopsDispatched",		0x186, 0x01, true },
+	{ "ExRetInstr",			0x0c0, 0x00, true },
+	{ "ExRetCops",			0x0c1, 0x00, true },
+	{ "ExRetBrn",			0x0c2, 0x00, true },
+	{ "ExRetBrnMisp",		0x0c3, 0x00, true },
+	{ "ExRetBrnTkn",		0x0c4, 0x00, true },
+	{ "ExRetBrnTknMisp",		0x0c5, 0x00, true },
+	{ "ExRetBrnFar",		0x0c6, 0x00, true },
+	{ "ExRetBrnResync",		0x0c7, 0x00, true },
+	{ "ExRetNearRet",		0x0c8, 0x00, true },
+	{ "ExRetNearRetMispred",	0x0c9, 0x00, true },
+	{ "ExRetBrnIndMisp",		0x0ca, 0x00, true },
+	{ "ExRetMmxFpInstr@X87",	0x0cb, 0x01, true },
+	{ "ExRetMmxFpInstr@Mmx",	0x0cb, 0x02, true },
+	{ "ExRetMmxFpInstr@Sse",	0x0cb, 0x04, true },
+	{ "ExIntMaskedCyc",		0x0cd, 0x00, true },
+	{ "ExIntMaskedCycIntPend",	0x0ce, 0x00, true },
+	{ "ExIntTaken",			0x0cf, 0x00, true },
+	{ "ExDecEmpty",			0x0d0, 0x00, true },
+	{ "ExDispStall",		0x0d1, 0x00, true },
+	{ "ExUseqStallSer",		0x0d2, 0x00, true },
+	{ "ExDispStallInstrRetQFull",	0x0d5, 0x00, true },
+	{ "ExDispStallIntSchedQFull",	0x0d6, 0x00, true },
+	{ "ExDispStallFpSchedQFull",	0x0d7, 0x00, true },
+	{ "ExDispStallLdqFull",		0x0d8, 0x00, true },
+	{ "ExUseqStallAllQuiet",	0x0d9, 0x00, true },
+	{ 

CVS commit: src/usr.sbin/tprof/arch

2019-10-11 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri Oct 11 18:05:52 UTC 2019

Modified Files:
src/usr.sbin/tprof/arch: tprof_x86.c

Log Message:
Add support for AMD Family 15h


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/usr.sbin/tprof/arch/tprof_x86.c

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



Re: CVS commit: src/usr.sbin/tprof

2018-07-18 Thread Maxime Villard

Le 18/07/2018 à 19:35, Alexander Nasonov a écrit :

Thomas Klausner wrote:

Module Name:src
Committed By:   wiz
Date:   Wed Jul 18 16:50:05 UTC 2018

Modified Files:
src/usr.sbin/tprof: tprof.8 tprof.c

Log Message:
Various improvements to man page. Sync usage.



Does tprof work on amd64? When I tried it a couple of days ago, tprof
complained about missing /dev/tprof. I recompiled the kernel with

options GPROF
pseudo-device tprof

then tried creating the device with MAKEDEV. It didn't know about
tprof and I had to dig a major number in the code to create it manually.

With /dev/tproj available, the tool complained about unsupported cpu.
I'm on haswell notebook.

It'd be nice to mention /dev/tprof in the man page and list common
errors.


Without recompiling the kernel (which is how I use it)

mknod /dev/tprof c 191 0
modload /usr/src/sys/modules/tprof/./tprof.kmod
modload /usr/src/sys/modules/tprof_pmi/./tprof_pmi.kmod

You probably forgot to modload tprof_pmi, this provides the Intel backend,
and you should have at least the "Intel Architectural Version 1" events. It
shouldn't be complicated to add Haswell by the way.

If you're using amd you need to modload tprof_amdpmi

I know it's not clear, I intended to rename the modules and improve the man


Re: CVS commit: src/usr.sbin/tprof

2018-07-18 Thread Alexander Nasonov
Thomas Klausner wrote:
> Module Name:  src
> Committed By: wiz
> Date: Wed Jul 18 16:50:05 UTC 2018
> 
> Modified Files:
>   src/usr.sbin/tprof: tprof.8 tprof.c
> 
> Log Message:
> Various improvements to man page. Sync usage.
> 

Does tprof work on amd64? When I tried it a couple of days ago, tprof
complained about missing /dev/tprof. I recompiled the kernel with

options GPROF
pseudo-device tprof

then tried creating the device with MAKEDEV. It didn't know about
tprof and I had to dig a major number in the code to create it manually.

With /dev/tproj available, the tool complained about unsupported cpu.
I'm on haswell notebook.

It'd be nice to mention /dev/tprof in the man page and list common
errors.

Alex