CVS commit: src/sys/dev/tprof

2023-04-11 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Tue Apr 11 10:07:12 UTC 2023

Modified Files:
src/sys/dev/tprof: tprof.c tprof_armv7.c tprof_armv8.c tprof_types.h
tprof_x86_amd.c tprof_x86_intel.c

Log Message:
KNF. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/dev/tprof/tprof.c
cvs rdiff -u -r1.12 -r1.13 src/sys/dev/tprof/tprof_armv7.c
cvs rdiff -u -r1.19 -r1.20 src/sys/dev/tprof/tprof_armv8.c
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/tprof/tprof_types.h
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/tprof/tprof_x86_amd.c \
src/sys/dev/tprof/tprof_x86_intel.c

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

Modified files:

Index: src/sys/dev/tprof/tprof.c
diff -u src/sys/dev/tprof/tprof.c:1.22 src/sys/dev/tprof/tprof.c:1.23
--- src/sys/dev/tprof/tprof.c:1.22	Fri Dec 16 17:38:56 2022
+++ src/sys/dev/tprof/tprof.c	Tue Apr 11 10:07:12 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: tprof.c,v 1.22 2022/12/16 17:38:56 ryo Exp $	*/
+/*	$NetBSD: tprof.c,v 1.23 2023/04/11 10:07:12 msaitoh Exp $	*/
 
 /*-
  * Copyright (c)2008,2009,2010 YAMAMOTO Takashi,
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tprof.c,v 1.22 2022/12/16 17:38:56 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tprof.c,v 1.23 2023/04/11 10:07:12 msaitoh Exp $");
 
 #include 
 #include 
@@ -213,7 +213,7 @@ tprof_worker(struct work *wk, void *dumm
 	KASSERT(dummy == NULL);
 
 	/*
-	 * get a per cpu buffer.
+	 * Get a per cpu buffer.
 	 */
 	buf = tprof_buf_refresh();
 
@@ -245,12 +245,11 @@ tprof_worker(struct work *wk, void *dumm
 		tprof_stat.ts_dropbuf++;
 	}
 	mutex_exit(&tprof_lock);
-	if (buf) {
+	if (buf)
 		tprof_buf_free(buf);
-	}
-	if (!shouldstop) {
+
+	if (!shouldstop)
 		callout_schedule(&c->c_callout, hz / 8);
-	}
 }
 
 static void
@@ -276,9 +275,9 @@ tprof_stop1(void)
 		tprof_buf_t *old;
 
 		old = tprof_buf_switch(c, NULL);
-		if (old != NULL) {
+		if (old != NULL)
 			tprof_buf_free(old);
-		}
+
 		callout_destroy(&c->c_callout);
 	}
 	workqueue_destroy(tprof_wq);
@@ -293,9 +292,8 @@ tprof_getinfo(struct tprof_info *info)
 
 	memset(info, 0, sizeof(*info));
 	info->ti_version = TPROF_VERSION;
-	if ((tb = tprof_backend) != NULL) {
+	if ((tb = tprof_backend) != NULL)
 		info->ti_ident = tb->tb_ops->tbo_ident();
-	}
 }
 
 static int
@@ -351,8 +349,8 @@ tprof_start(tprof_countermask_t runmask)
 	runmask &= tb->tb_softc.sc_ctr_configured_mask;
 	if (runmask == 0) {
 		/*
-		 * targets are already running.
-		 * unconfigured counters are ignored.
+		 * Targets are already running.
+		 * Unconfigured counters are ignored.
 		 */
 		error = 0;
 		goto done;
@@ -427,7 +425,7 @@ tprof_stop(tprof_countermask_t stopmask)
 	KASSERT(mutex_owned(&tprof_startstop_lock));
 	stopmask &= tb->tb_softc.sc_ctr_running_mask;
 	if (stopmask == 0) {
-		/* targets are not running */
+		/* Targets are not running */
 		goto done;
 	}
 
@@ -437,13 +435,13 @@ tprof_stop(tprof_countermask_t stopmask)
 	tb->tb_softc.sc_ctr_running_mask &= ~stopmask;
 	mutex_exit(&tprof_lock);
 
-	/* all counters have stopped? */
+	/* All counters have stopped? */
 	if (tb->tb_softc.sc_ctr_running_mask == 0) {
 		mutex_enter(&tprof_lock);
 		cv_broadcast(&tprof_reader_cv);
-		while (tprof_nworker > 0) {
+		while (tprof_nworker > 0)
 			cv_wait(&tprof_cv, &tprof_lock);
-		}
+
 		mutex_exit(&tprof_lock);
 
 		tprof_stop1();
@@ -516,7 +514,7 @@ tprof_configure_event(const tprof_param_
 	tb->tb_ops->tbo_counter_bitwidth(param->p_counter);
 
 	sc_param = &sc->sc_count[c].ctr_param;
-	memcpy(sc_param, param, sizeof(*sc_param));	/* save copy of param */
+	memcpy(sc_param, param, sizeof(*sc_param)); /* save copy of param */
 
 	if (ISSET(param->p_flags, TPROF_PARAM_PROFILE)) {
 		uint64_t freq, inum, dnum;
@@ -618,9 +616,8 @@ tprof_getcounts_cpu(void *arg1, void *ar
 			counters[c] = counters_offset[c] +
 			((ctr - sc->sc_count[c].ctr_counter_reset_val) &
 			__BITS(sc->sc_count[c].ctr_bitwidth - 1, 0));
-		} else {
+		} else
 			counters[c] = 0;
-		}
 	}
 	percpu_putref(sc->sc_ctr_offset_percpu);
 }
@@ -741,9 +738,8 @@ tprof_backend_register(const char *name,
 {
 	tprof_backend_t *tb;
 
-	if (vers != TPROF_BACKEND_VERSION) {
+	if (vers != TPROF_BACKEND_VERSION)
 		return EINVAL;
-	}
 
 	mutex_enter(&tprof_startstop_lock);
 	tb = tprof_backend_lookup(name);
@@ -768,7 +764,7 @@ tprof_backend_register(const char *name,
 #endif
 	mutex_exit(&tprof_startstop_lock);
 
-	/* init backend softc */
+	/* Init backend softc */
 	tb->tb_softc.sc_ncounters = tb->tb_ops->tbo_ncounters();
 	tb->tb_softc.sc_ctr_offset_percpu_size =
 	sizeof(uint64_t) * tb->tb_softc.sc_ncounters;
@@ -800,9 +796,8 @@ tprof_backend_unregister(const char *nam
 		return EBUSY;
 	}
 #if 1 /* XXX for now */
-	if (tprof_backend == tb) {
+	if (tprof_backend == tb)
 		tprof_backend = NULL;
-	}
 #endif
 	LIST_REMOVE(tb, tb_list);
 	mutex_exit(&tprof_startstop_lock);
@@ -811,7 +806

CVS commit: src/sys/dev/tprof

2023-04-11 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Tue Apr 11 10:07:12 UTC 2023

Modified Files:
src/sys/dev/tprof: tprof.c tprof_armv7.c tprof_armv8.c tprof_types.h
tprof_x86_amd.c tprof_x86_intel.c

Log Message:
KNF. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/dev/tprof/tprof.c
cvs rdiff -u -r1.12 -r1.13 src/sys/dev/tprof/tprof_armv7.c
cvs rdiff -u -r1.19 -r1.20 src/sys/dev/tprof/tprof_armv8.c
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/tprof/tprof_types.h
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/tprof/tprof_x86_amd.c \
src/sys/dev/tprof/tprof_x86_intel.c

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



CVS commit: src/sys/dev/tprof

2023-04-11 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Tue Apr 11 09:53:28 UTC 2023

Modified Files:
src/sys/dev/tprof: tprof_x86_intel.c

Log Message:
Test cpuid_level in tprof_intel_ncounters().

This function is called before tprof_intel_ident().


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/tprof/tprof_x86_intel.c

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

Modified files:

Index: src/sys/dev/tprof/tprof_x86_intel.c
diff -u src/sys/dev/tprof/tprof_x86_intel.c:1.6 src/sys/dev/tprof/tprof_x86_intel.c:1.7
--- src/sys/dev/tprof/tprof_x86_intel.c:1.6	Tue Apr 11 02:47:01 2023
+++ src/sys/dev/tprof/tprof_x86_intel.c	Tue Apr 11 09:53:28 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: tprof_x86_intel.c,v 1.6 2023/04/11 02:47:01 msaitoh Exp $	*/
+/*	$NetBSD: tprof_x86_intel.c,v 1.7 2023/04/11 09:53:28 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -56,7 +56,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tprof_x86_intel.c,v 1.6 2023/04/11 02:47:01 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tprof_x86_intel.c,v 1.7 2023/04/11 09:53:28 msaitoh Exp $");
 
 #include 
 #include 
@@ -103,6 +103,9 @@ tprof_intel_ncounters(void)
 {
 	uint32_t descs[4];
 
+	if (cpuid_level < 0x0a)
+		return 0;
+
 	x86_cpuid(0x0a, descs);
 
 	return __SHIFTOUT(descs[0], CPUID_PERF_NGPPC);



CVS commit: src/sys/dev/tprof

2023-04-11 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Tue Apr 11 09:53:28 UTC 2023

Modified Files:
src/sys/dev/tprof: tprof_x86_intel.c

Log Message:
Test cpuid_level in tprof_intel_ncounters().

This function is called before tprof_intel_ident().


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/tprof/tprof_x86_intel.c

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



CVS commit: src/sys/dev/tprof

2023-04-10 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Tue Apr 11 02:47:01 UTC 2023

Modified Files:
src/sys/dev/tprof: tprof_x86_intel.c

Log Message:
Obtain the number of general counters from CPUID 0xa.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/tprof/tprof_x86_intel.c

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

Modified files:

Index: src/sys/dev/tprof/tprof_x86_intel.c
diff -u src/sys/dev/tprof/tprof_x86_intel.c:1.5 src/sys/dev/tprof/tprof_x86_intel.c:1.6
--- src/sys/dev/tprof/tprof_x86_intel.c:1.5	Thu Dec  1 00:32:52 2022
+++ src/sys/dev/tprof/tprof_x86_intel.c	Tue Apr 11 02:47:01 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: tprof_x86_intel.c,v 1.5 2022/12/01 00:32:52 ryo Exp $	*/
+/*	$NetBSD: tprof_x86_intel.c,v 1.6 2023/04/11 02:47:01 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -56,7 +56,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tprof_x86_intel.c,v 1.5 2022/12/01 00:32:52 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tprof_x86_intel.c,v 1.6 2023/04/11 02:47:01 msaitoh Exp $");
 
 #include 
 #include 
@@ -79,7 +79,6 @@ __KERNEL_RCSID(0, "$NetBSD: tprof_x86_in
 #include 
 #include 
 
-#define	NCTRS	4	/* XXX */
 static u_int counter_bitwidth;
 
 #define	PERFEVTSEL(i)		(MSR_EVNTSEL0 + (i))
@@ -102,7 +101,11 @@ static nmi_handler_t *intel_nmi_handle;
 static uint32_t
 tprof_intel_ncounters(void)
 {
-	return NCTRS;
+	uint32_t descs[4];
+
+	x86_cpuid(0x0a, descs);
+
+	return __SHIFTOUT(descs[0], CPUID_PERF_NGPPC);
 }
 
 static u_int



CVS commit: src/sys/dev/tprof

2023-04-10 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Tue Apr 11 02:47:01 UTC 2023

Modified Files:
src/sys/dev/tprof: tprof_x86_intel.c

Log Message:
Obtain the number of general counters from CPUID 0xa.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/tprof/tprof_x86_intel.c

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



CVS commit: src/sys/dev/tprof

2022-12-21 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Thu Dec 22 06:59:33 UTC 2022

Modified Files:
src/sys/dev/tprof: tprof_armv7.c tprof_armv8.c

Log Message:
Even if an overflow interrupt is occured for a counter outside tprof management,
the bit of onverflow status register must be cleared to prevent an interrupt 
storm.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/tprof/tprof_armv7.c
cvs rdiff -u -r1.18 -r1.19 src/sys/dev/tprof/tprof_armv8.c

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

Modified files:

Index: src/sys/dev/tprof/tprof_armv7.c
diff -u src/sys/dev/tprof/tprof_armv7.c:1.11 src/sys/dev/tprof/tprof_armv7.c:1.12
--- src/sys/dev/tprof/tprof_armv7.c:1.11	Sat Dec  3 20:24:21 2022
+++ src/sys/dev/tprof/tprof_armv7.c	Thu Dec 22 06:59:32 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: tprof_armv7.c,v 1.11 2022/12/03 20:24:21 ryo Exp $ */
+/* $NetBSD: tprof_armv7.c,v 1.12 2022/12/22 06:59:32 ryo Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tprof_armv7.c,v 1.11 2022/12/03 20:24:21 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tprof_armv7.c,v 1.12 2022/12/22 06:59:32 ryo Exp $");
 
 #include 
 #include 
@@ -225,7 +225,7 @@ armv7_pmu_intr(void *priv)
 	tprof_backend_softc_t *sc = pmu_intr_arg;
 	tprof_frame_info_t tfi;
 	int bit;
-	const uint32_t pmovs = armreg_pmovsr_read() & PMOVS_P;
+	const uint32_t pmovs = armreg_pmovsr_read();
 
 	uint64_t *counters_offset =
 	percpu_getptr_remote(sc->sc_ctr_offset_percpu, curcpu());
@@ -248,7 +248,7 @@ armv7_pmu_intr(void *priv)
 			tfi.tfi_pc >= VM_MIN_KERNEL_ADDRESS &&
 			tfi.tfi_pc < VM_MAX_KERNEL_ADDRESS;
 			tprof_sample(NULL, &tfi);
-		} else {
+		} else if (ISSET(sc->sc_ctr_ovf_mask, __BIT(bit))) {
 			/* counter has overflowed */
 			counters_offset[bit] += __BIT(32);
 		}

Index: src/sys/dev/tprof/tprof_armv8.c
diff -u src/sys/dev/tprof/tprof_armv8.c:1.18 src/sys/dev/tprof/tprof_armv8.c:1.19
--- src/sys/dev/tprof/tprof_armv8.c:1.18	Thu Dec  1 00:32:52 2022
+++ src/sys/dev/tprof/tprof_armv8.c	Thu Dec 22 06:59:32 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: tprof_armv8.c,v 1.18 2022/12/01 00:32:52 ryo Exp $ */
+/* $NetBSD: tprof_armv8.c,v 1.19 2022/12/22 06:59:32 ryo Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tprof_armv8.c,v 1.18 2022/12/01 00:32:52 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tprof_armv8.c,v 1.19 2022/12/22 06:59:32 ryo Exp $");
 
 #include 
 #include 
@@ -197,7 +197,7 @@ armv8_pmu_intr(void *priv)
 	tprof_backend_softc_t *sc = pmu_intr_arg;
 	tprof_frame_info_t tfi;
 	int bit;
-	const uint32_t pmovs = reg_pmovsset_el0_read() & PMOVS_P;
+	const uint32_t pmovs = reg_pmovsset_el0_read();
 
 	uint64_t *counters_offset =
 	percpu_getptr_remote(sc->sc_ctr_offset_percpu, curcpu());
@@ -220,7 +220,7 @@ armv8_pmu_intr(void *priv)
 			tfi.tfi_pc >= VM_MIN_KERNEL_ADDRESS &&
 			tfi.tfi_pc < VM_MAX_KERNEL_ADDRESS;
 			tprof_sample(NULL, &tfi);
-		} else {
+		} else if (ISSET(sc->sc_ctr_ovf_mask, __BIT(bit))) {
 			/* counter has overflowed */
 			counters_offset[bit] += __BIT(32);
 		}



CVS commit: src/sys/dev/tprof

2022-12-21 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Thu Dec 22 06:59:33 UTC 2022

Modified Files:
src/sys/dev/tprof: tprof_armv7.c tprof_armv8.c

Log Message:
Even if an overflow interrupt is occured for a counter outside tprof management,
the bit of onverflow status register must be cleared to prevent an interrupt 
storm.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/tprof/tprof_armv7.c
cvs rdiff -u -r1.18 -r1.19 src/sys/dev/tprof/tprof_armv8.c

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



CVS commit: src/sys/dev/tprof

2022-12-16 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Fri Dec 16 17:38:56 UTC 2022

Modified Files:
src/sys/dev/tprof: tprof.c

Log Message:
tprof_lock is not a spin mutex. use mutex_{enter,exit}(). oops


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/dev/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/sys/dev/tprof/tprof.c
diff -u src/sys/dev/tprof/tprof.c:1.21 src/sys/dev/tprof/tprof.c:1.22
--- src/sys/dev/tprof/tprof.c:1.21	Fri Dec 16 07:59:42 2022
+++ src/sys/dev/tprof/tprof.c	Fri Dec 16 17:38:56 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: tprof.c,v 1.21 2022/12/16 07:59:42 ryo Exp $	*/
+/*	$NetBSD: tprof.c,v 1.22 2022/12/16 17:38:56 ryo Exp $	*/
 
 /*-
  * Copyright (c)2008,2009,2010 YAMAMOTO Takashi,
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tprof.c,v 1.21 2022/12/16 07:59:42 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tprof.c,v 1.22 2022/12/16 17:38:56 ryo Exp $");
 
 #include 
 #include 
@@ -885,9 +885,9 @@ tprof_poll(dev_t dev, int events, struct
 static void
 filt_tprof_read_detach(struct knote *kn)
 {
-	mutex_spin_enter(&tprof_lock);
+	mutex_enter(&tprof_lock);
 	selremove_knote(&tprof_selp, kn);
-	mutex_spin_exit(&tprof_lock);
+	mutex_exit(&tprof_lock);
 }
 
 static int
@@ -896,7 +896,7 @@ filt_tprof_read_event(struct knote *kn, 
 	int rv = 0;
 
 	if ((hint & NOTE_SUBMIT) == 0)
-		mutex_spin_enter(&tprof_lock);
+		mutex_enter(&tprof_lock);
 
 	if (!STAILQ_EMPTY(&tprof_list)) {
 		tprof_buf_t *buf;
@@ -911,7 +911,7 @@ filt_tprof_read_event(struct knote *kn, 
 	}
 
 	if ((hint & NOTE_SUBMIT) == 0)
-		mutex_spin_exit(&tprof_lock);
+		mutex_exit(&tprof_lock);
 
 	return rv;
 }
@@ -929,9 +929,9 @@ tprof_kqfilter(dev_t dev, struct knote *
 	switch (kn->kn_filter) {
 	case EVFILT_READ:
 		kn->kn_fop = &tprof_read_filtops;
-		mutex_spin_enter(&tprof_lock);
+		mutex_enter(&tprof_lock);
 		selrecord_knote(&tprof_selp, kn);
-		mutex_spin_exit(&tprof_lock);
+		mutex_exit(&tprof_lock);
 		break;
 	default:
 		return EINVAL;



CVS commit: src/sys/dev/tprof

2022-12-16 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Fri Dec 16 17:38:56 UTC 2022

Modified Files:
src/sys/dev/tprof: tprof.c

Log Message:
tprof_lock is not a spin mutex. use mutex_{enter,exit}(). oops


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/dev/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/sys/dev/tprof

2022-12-15 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Fri Dec 16 07:59:42 UTC 2022

Modified Files:
src/sys/dev/tprof: tprof.c

Log Message:
- Add support select(2)/poll(2) on /dev/tprof.
- Changed sampling buffer switching frequency (which is the frequency of 
tprof_worker()
  calls and also the maximum block time of read(2) of /dev/tprof) from 1sec to 
125ms.
  This improve tprof top responsiveness.
- The maximum number of sampling buffers is now adjusted according to the 
number of CPUs.
  Previously it was fixed at 100 and was insufficient if ncpu was greater than 
this.

The maximum number of samples per second per CPU is calculated by
"TPROF_MAX_SAMPLES_PER_BUF * (HZ of tprof_worker)".
Therefore, currently, 1 * (1000/125) = 8 maximum samplings per CPU.
The actual value will vary slightly from this due to tprof_worker and read(2) 
timing.
This value may need to be adjusted more in the future.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/dev/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/sys/dev/tprof

2022-12-15 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Fri Dec 16 07:59:42 UTC 2022

Modified Files:
src/sys/dev/tprof: tprof.c

Log Message:
- Add support select(2)/poll(2) on /dev/tprof.
- Changed sampling buffer switching frequency (which is the frequency of 
tprof_worker()
  calls and also the maximum block time of read(2) of /dev/tprof) from 1sec to 
125ms.
  This improve tprof top responsiveness.
- The maximum number of sampling buffers is now adjusted according to the 
number of CPUs.
  Previously it was fixed at 100 and was insufficient if ncpu was greater than 
this.

The maximum number of samples per second per CPU is calculated by
"TPROF_MAX_SAMPLES_PER_BUF * (HZ of tprof_worker)".
Therefore, currently, 1 * (1000/125) = 8 maximum samplings per CPU.
The actual value will vary slightly from this due to tprof_worker and read(2) 
timing.
This value may need to be adjusted more in the future.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/dev/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/sys/dev/tprof/tprof.c
diff -u src/sys/dev/tprof/tprof.c:1.20 src/sys/dev/tprof/tprof.c:1.21
--- src/sys/dev/tprof/tprof.c:1.20	Sun Dec 11 01:36:49 2022
+++ src/sys/dev/tprof/tprof.c	Fri Dec 16 07:59:42 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: tprof.c,v 1.20 2022/12/11 01:36:49 chs Exp $	*/
+/*	$NetBSD: tprof.c,v 1.21 2022/12/16 07:59:42 ryo Exp $	*/
 
 /*-
  * Copyright (c)2008,2009,2010 YAMAMOTO Takashi,
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tprof.c,v 1.20 2022/12/11 01:36:49 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tprof.c,v 1.21 2022/12/16 07:59:42 ryo Exp $");
 
 #include 
 #include 
@@ -39,8 +39,10 @@ __KERNEL_RCSID(0, "$NetBSD: tprof.c,v 1.
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -78,9 +80,7 @@ typedef struct tprof_buf {
 } tprof_buf_t;
 #define	TPROF_BUF_BYTESIZE(sz) \
 	(sizeof(tprof_buf_t) + (sz) * sizeof(tprof_sample_t))
-#define	TPROF_MAX_SAMPLES_PER_BUF	(TPROF_HZ * 2)
-
-#define	TPROF_MAX_BUF			100
+#define	TPROF_MAX_SAMPLES_PER_BUF	TPROF_HZ
 
 typedef struct {
 	tprof_buf_t *c_buf;
@@ -111,6 +111,7 @@ static u_int tprof_nbuf_on_list;	/* L: #
 static struct workqueue *tprof_wq;
 static struct percpu *tprof_cpus __read_mostly;	/* tprof_cpu_t * */
 static u_int tprof_samples_per_buf;
+static u_int tprof_max_buf;
 
 tprof_backend_t *tprof_backend;	/* S: */
 static LIST_HEAD(, tprof_backend) tprof_backends =
@@ -122,6 +123,7 @@ static off_t tprof_reader_offset;	/* R: 
 
 static kmutex_t tprof_startstop_lock;
 static kcondvar_t tprof_cv;		/* L: */
+static struct selinfo tprof_selp;	/* L: */
 
 static struct tprof_stat tprof_stat;	/* L: */
 
@@ -229,13 +231,14 @@ tprof_worker(struct work *wk, void *dumm
 	}
 	if (buf->b_used == 0) {
 		tprof_stat.ts_emptybuf++;
-	} else if (tprof_nbuf_on_list < TPROF_MAX_BUF) {
+	} else if (tprof_nbuf_on_list < tprof_max_buf) {
 		tprof_stat.ts_sample += buf->b_used;
 		tprof_stat.ts_overflow += buf->b_overflow;
 		tprof_stat.ts_buf++;
 		STAILQ_INSERT_TAIL(&tprof_list, buf, b_list);
 		tprof_nbuf_on_list++;
 		buf = NULL;
+		selnotify(&tprof_selp, 0, NOTE_SUBMIT);
 		cv_broadcast(&tprof_reader_cv);
 	} else {
 		tprof_stat.ts_dropbuf_sample += buf->b_used;
@@ -246,7 +249,7 @@ tprof_worker(struct work *wk, void *dumm
 		tprof_buf_free(buf);
 	}
 	if (!shouldstop) {
-		callout_schedule(&c->c_callout, hz);
+		callout_schedule(&c->c_callout, hz / 8);
 	}
 }
 
@@ -364,6 +367,7 @@ tprof_start(tprof_countermask_t runmask)
 		}
 
 		tprof_samples_per_buf = TPROF_MAX_SAMPLES_PER_BUF;
+		tprof_max_buf = ncpu * 3;
 		error = workqueue_create(&tprof_wq, "tprofmv", tprof_worker,
 		NULL, PRI_NONE, IPL_SOFTCLOCK, WQ_MPSAFE | WQ_PERCPU);
 		if (error != 0) {
@@ -860,12 +864,89 @@ tprof_close(dev_t dev, int flags, int ty
 }
 
 static int
+tprof_poll(dev_t dev, int events, struct lwp *l)
+{
+	int revents;
+
+	revents = events & (POLLIN | POLLRDNORM);
+	if (revents == 0)
+		return 0;
+
+	mutex_enter(&tprof_lock);
+	if (STAILQ_EMPTY(&tprof_list)) {
+		revents = 0;
+		selrecord(l, &tprof_selp);
+	}
+	mutex_exit(&tprof_lock);
+
+	return revents;
+}
+
+static void
+filt_tprof_read_detach(struct knote *kn)
+{
+	mutex_spin_enter(&tprof_lock);
+	selremove_knote(&tprof_selp, kn);
+	mutex_spin_exit(&tprof_lock);
+}
+
+static int
+filt_tprof_read_event(struct knote *kn, long hint)
+{
+	int rv = 0;
+
+	if ((hint & NOTE_SUBMIT) == 0)
+		mutex_spin_enter(&tprof_lock);
+
+	if (!STAILQ_EMPTY(&tprof_list)) {
+		tprof_buf_t *buf;
+		int64_t n = 0;
+
+		STAILQ_FOREACH(buf, &tprof_list, b_list) {
+			n += buf->b_used;
+		}
+		kn->kn_data = n * sizeof(tprof_sample_t);
+
+		rv = 1;
+	}
+
+	if ((hint & NOTE_SUBMIT) == 0)
+		mutex_spin_exit(&tprof_lock);
+
+	return rv;
+}
+
+static const struct filterops tprof_read_filtops = {
+	.f_flags = FILTEROP_ISFD | FILTEROP_MPSAFE,
+	.f_atta

CVS commit: src/sys/dev/tprof

2022-12-10 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Sun Dec 11 01:36:49 UTC 2022

Modified Files:
src/sys/dev/tprof: tprof.c

Log Message:
make sure error is initialized before we return it.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/dev/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/sys/dev/tprof/tprof.c
diff -u src/sys/dev/tprof/tprof.c:1.19 src/sys/dev/tprof/tprof.c:1.20
--- src/sys/dev/tprof/tprof.c:1.19	Thu Dec  1 00:32:52 2022
+++ src/sys/dev/tprof/tprof.c	Sun Dec 11 01:36:49 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: tprof.c,v 1.19 2022/12/01 00:32:52 ryo Exp $	*/
+/*	$NetBSD: tprof.c,v 1.20 2022/12/11 01:36:49 chs Exp $	*/
 
 /*-
  * Copyright (c)2008,2009,2010 YAMAMOTO Takashi,
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tprof.c,v 1.19 2022/12/01 00:32:52 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tprof.c,v 1.20 2022/12/11 01:36:49 chs Exp $");
 
 #include 
 #include 
@@ -404,6 +404,8 @@ tprof_start(tprof_countermask_t runmask)
 			workqueue_enqueue(tprof_wq, &c->c_work, ci);
 		}
 	}
+	error = 0;
+
 done:
 	return error;
 }



CVS commit: src/sys/dev/tprof

2022-12-10 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Sun Dec 11 01:36:49 UTC 2022

Modified Files:
src/sys/dev/tprof: tprof.c

Log Message:
make sure error is initialized before we return it.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/dev/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/sys/dev/tprof

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

Modified Files:
src/sys/dev/tprof: tprof_armv7.c

Log Message:
tprof_armv7 initializes on each CPUs, like tprof_armv8.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/dev/tprof/tprof_armv7.c

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



CVS commit: src/sys/dev/tprof

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

Modified Files:
src/sys/dev/tprof: tprof_armv7.c

Log Message:
tprof_armv7 initializes on each CPUs, like tprof_armv8.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/dev/tprof/tprof_armv7.c

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

Modified files:

Index: src/sys/dev/tprof/tprof_armv7.c
diff -u src/sys/dev/tprof/tprof_armv7.c:1.8 src/sys/dev/tprof/tprof_armv7.c:1.9
--- src/sys/dev/tprof/tprof_armv7.c:1.8	Thu Dec  1 00:29:10 2022
+++ src/sys/dev/tprof/tprof_armv7.c	Thu Dec  1 00:29:51 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: tprof_armv7.c,v 1.8 2022/12/01 00:29:10 ryo Exp $ */
+/* $NetBSD: tprof_armv7.c,v 1.9 2022/12/01 00:29:51 ryo Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tprof_armv7.c,v 1.8 2022/12/01 00:29:10 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tprof_armv7.c,v 1.9 2022/12/01 00:29:51 ryo Exp $");
 
 #include 
 #include 
@@ -258,8 +258,8 @@ armv7_pmu_intr(void *priv)
 	return 1;
 }
 
-int
-armv7_pmu_init(void)
+static void
+armv7_pmu_init_cpu(void *arg1, void *arg2)
 {
 	/* Disable user mode access to performance monitors */
 	armreg_pmuserenr_write(0);
@@ -269,6 +269,13 @@ armv7_pmu_init(void)
 
 	/* Disable counters */
 	armreg_pmcntenclr_write(PMCNTEN_P);
+}
+
+int
+armv7_pmu_init(void)
+{
+	uint64_t xc = xc_broadcast(0, armv7_pmu_init_cpu, NULL, NULL);
+	xc_wait(xc);
 
 	return tprof_backend_register("tprof_armv7", &tprof_armv7_pmu_ops,
 	TPROF_BACKEND_VERSION);



CVS commit: src/sys/dev/tprof

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

Modified Files:
src/sys/dev/tprof: tprof.c

Log Message:
don't call kpreempt_{disable,enable}() from an interrupt handler.

Fixed a problem in which the system would freeze if a high load (e.g., build.sh 
-j20)
was applied while running `tprof monitor -e LsNotHaltedCyc ...' on x86.

This almost eliminates the problem, but still is not enough. tprof_x86 uses NMI
interrupts, which are interrupted even in splhigh(), leaving the possibility of
being interrupted in the splhigh section of percpu_cpu_swap().


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/dev/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/sys/dev/tprof/tprof.c
diff -u src/sys/dev/tprof/tprof.c:1.17 src/sys/dev/tprof/tprof.c:1.18
--- src/sys/dev/tprof/tprof.c:1.17	Mon Mar 28 12:33:21 2022
+++ src/sys/dev/tprof/tprof.c	Thu Dec  1 00:27:59 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: tprof.c,v 1.17 2022/03/28 12:33:21 riastradh Exp $	*/
+/*	$NetBSD: tprof.c,v 1.18 2022/12/01 00:27:59 ryo Exp $	*/
 
 /*-
  * Copyright (c)2008,2009,2010 YAMAMOTO Takashi,
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tprof.c,v 1.17 2022/03/28 12:33:21 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tprof.c,v 1.18 2022/12/01 00:27:59 ryo Exp $");
 
 #include 
 #include 
@@ -115,9 +115,18 @@ static kcondvar_t tprof_cv;		/* L: */
 static struct tprof_stat tprof_stat;	/* L: */
 
 static tprof_cpu_t *
+tprof_cpu_direct(struct cpu_info *ci)
+{
+	tprof_cpu_t **cp;
+
+	cp = percpu_getptr_remote(tprof_cpus, ci);
+	return *cp;
+}
+
+static tprof_cpu_t *
 tprof_cpu(struct cpu_info *ci)
 {
-	tprof_cpu_t **cp, *c;
+	tprof_cpu_t *c;
 
 	/*
 	 * As long as xcalls are blocked -- e.g., by kpreempt_disable
@@ -126,8 +135,7 @@ tprof_cpu(struct cpu_info *ci)
 	 * moved to a new buffer, but we can safely read from it.
 	 */
 	kpreempt_disable();
-	cp = percpu_getptr_remote(tprof_cpus, ci);
-	c = *cp;
+	c = tprof_cpu_direct(ci);
 	kpreempt_enable();
 
 	return c;
@@ -433,7 +441,7 @@ tprof_backend_lookup(const char *name)
 void
 tprof_sample(void *unused, const tprof_frame_info_t *tfi)
 {
-	tprof_cpu_t * const c = tprof_curcpu();
+	tprof_cpu_t * const c = tprof_cpu_direct(curcpu());
 	tprof_buf_t * const buf = c->c_buf;
 	tprof_sample_t *sp;
 	const uintptr_t pc = tfi->tfi_pc;



CVS commit: src/sys/dev/tprof

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

Modified Files:
src/sys/dev/tprof: tprof.c

Log Message:
don't call kpreempt_{disable,enable}() from an interrupt handler.

Fixed a problem in which the system would freeze if a high load (e.g., build.sh 
-j20)
was applied while running `tprof monitor -e LsNotHaltedCyc ...' on x86.

This almost eliminates the problem, but still is not enough. tprof_x86 uses NMI
interrupts, which are interrupted even in splhigh(), leaving the possibility of
being interrupted in the splhigh section of percpu_cpu_swap().


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/dev/tprof/tprof.c

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



Re: CVS commit: src/sys/dev/tprof

2022-11-10 Thread Ryo Shimizu


>I think this is a bug in your device tree because the KASSERT was 
>intentional:
>
>  - In the ACPI case, we probe for CPU PMU support before calling
>armv8_pmu_init.
>  - In the FDT case, the PMU attaches to a node described in the device
>tree.
>
>So if you hit this KASSERT, AFAICT it means your device tree is describing 
>a device that is not there. Unless I'm missing something here.

I tried to fix it to work properly as a kernel module for debugging and
improving tprof itself, but the current implement is difficult due to
the acpi/fdt pmu interrupt and tprof, so I gave up :-P

I'll revert it. thanks!
-- 
ryo shimizu


CVS commit: src/sys/dev/tprof

2022-11-09 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Thu Nov 10 07:54:20 UTC 2022

Modified Files:
src/sys/dev/tprof: tprof_armv8.c

Log Message:
revert my previous commit.

since armv8_pmu_init is only called when it is reliably worked by ACPI or fdt,
there is no need for dynamic checks.

pointed out by jmcneill@, thanks


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/dev/tprof/tprof_armv8.c

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



CVS commit: src/sys/dev/tprof

2022-11-09 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Thu Nov 10 07:54:20 UTC 2022

Modified Files:
src/sys/dev/tprof: tprof_armv8.c

Log Message:
revert my previous commit.

since armv8_pmu_init is only called when it is reliably worked by ACPI or fdt,
there is no need for dynamic checks.

pointed out by jmcneill@, thanks


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/dev/tprof/tprof_armv8.c

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

Modified files:

Index: src/sys/dev/tprof/tprof_armv8.c
diff -u src/sys/dev/tprof/tprof_armv8.c:1.15 src/sys/dev/tprof/tprof_armv8.c:1.16
--- src/sys/dev/tprof/tprof_armv8.c:1.15	Wed Nov  9 19:06:46 2022
+++ src/sys/dev/tprof/tprof_armv8.c	Thu Nov 10 07:54:20 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: tprof_armv8.c,v 1.15 2022/11/09 19:06:46 ryo Exp $ */
+/* $NetBSD: tprof_armv8.c,v 1.16 2022/11/10 07:54:20 ryo Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tprof_armv8.c,v 1.15 2022/11/09 19:06:46 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tprof_armv8.c,v 1.16 2022/11/10 07:54:20 ryo Exp $");
 
 #include 
 #include 
@@ -233,8 +233,7 @@ armv8_pmu_detect(void)
 int
 armv8_pmu_init(void)
 {
-	if (!armv8_pmu_detect())
-		return ENOTSUP;
+	KASSERT(armv8_pmu_detect());
 
 	uint64_t xc = xc_broadcast(0, armv8_pmu_init_cpu, NULL, NULL);
 	xc_wait(xc);



Re: CVS commit: src/sys/dev/tprof

2022-11-09 Thread Jared McNeill
I think this is a bug in your device tree because the KASSERT was 
intentional:


 - In the ACPI case, we probe for CPU PMU support before calling
   armv8_pmu_init.
 - In the FDT case, the PMU attaches to a node described in the device
   tree.

So if you hit this KASSERT, AFAICT it means your device tree is describing 
a device that is not there. Unless I'm missing something here.


Take care,
Jared

On Wed, 9 Nov 2022, Ryo Shimizu wrote:


Module Name:src
Committed By:   ryo
Date:   Wed Nov  9 19:06:46 UTC 2022

Modified Files:
src/sys/dev/tprof: tprof_armv8.c

Log Message:
If the hardware does not support PMU, return an error instead of KASSERT.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/dev/tprof/tprof_armv8.c

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




CVS commit: src/sys/dev/tprof

2022-11-09 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Wed Nov  9 19:06:46 UTC 2022

Modified Files:
src/sys/dev/tprof: tprof_armv8.c

Log Message:
If the hardware does not support PMU, return an error instead of KASSERT.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/dev/tprof/tprof_armv8.c

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



CVS commit: src/sys/dev/tprof

2022-11-09 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Wed Nov  9 19:06:46 UTC 2022

Modified Files:
src/sys/dev/tprof: tprof_armv8.c

Log Message:
If the hardware does not support PMU, return an error instead of KASSERT.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/dev/tprof/tprof_armv8.c

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

Modified files:

Index: src/sys/dev/tprof/tprof_armv8.c
diff -u src/sys/dev/tprof/tprof_armv8.c:1.14 src/sys/dev/tprof/tprof_armv8.c:1.15
--- src/sys/dev/tprof/tprof_armv8.c:1.14	Mon May 16 09:42:32 2022
+++ src/sys/dev/tprof/tprof_armv8.c	Wed Nov  9 19:06:46 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: tprof_armv8.c,v 1.14 2022/05/16 09:42:32 jmcneill Exp $ */
+/* $NetBSD: tprof_armv8.c,v 1.15 2022/11/09 19:06:46 ryo Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tprof_armv8.c,v 1.14 2022/05/16 09:42:32 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tprof_armv8.c,v 1.15 2022/11/09 19:06:46 ryo Exp $");
 
 #include 
 #include 
@@ -233,7 +233,8 @@ armv8_pmu_detect(void)
 int
 armv8_pmu_init(void)
 {
-	KASSERT(armv8_pmu_detect());
+	if (!armv8_pmu_detect())
+		return ENOTSUP;
 
 	uint64_t xc = xc_broadcast(0, armv8_pmu_init_cpu, NULL, NULL);
 	xc_wait(xc);



CVS commit: src/sys/dev/tprof

2022-11-01 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Nov  1 11:03:01 UTC 2022

Modified Files:
src/sys/dev/tprof: tprof_armv7.c

Log Message:
Add support for Cortex-A9.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/tprof/tprof_armv7.c

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

Modified files:

Index: src/sys/dev/tprof/tprof_armv7.c
diff -u src/sys/dev/tprof/tprof_armv7.c:1.6 src/sys/dev/tprof/tprof_armv7.c:1.7
--- src/sys/dev/tprof/tprof_armv7.c:1.6	Fri Nov 26 13:24:28 2021
+++ src/sys/dev/tprof/tprof_armv7.c	Tue Nov  1 11:03:01 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: tprof_armv7.c,v 1.6 2021/11/26 13:24:28 christos Exp $ */
+/* $NetBSD: tprof_armv7.c,v 1.7 2022/11/01 11:03:01 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tprof_armv7.c,v 1.6 2021/11/26 13:24:28 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tprof_armv7.c,v 1.7 2022/11/01 11:03:01 jmcneill Exp $");
 
 #include 
 #include 
@@ -54,22 +54,53 @@ static const u_int armv7_pmu_counter = 1
 static uint32_t counter_val;
 static uint32_t counter_reset_val;
 
+static uint16_t cortexa9_events[] = {
+	0x40, 0x41, 0x42,
+	0x50, 0x51,
+	0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
+	0x6e,
+	0x70, 0x71, 0x72, 0x73, 0x74,
+	0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86,
+	0x8a, 0x8b,
+	0x90, 0x91, 0x92, 0x93,
+	0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5
+};
+
 static bool
 armv7_pmu_event_implemented(uint16_t event)
 {
-	uint32_t eid[2];
-
-	if (event >= 64)
-		return false;
-
-	eid[0] = armreg_pmceid0_read();
-	eid[1] = armreg_pmceid1_read();
-
-	const u_int idx = event / 32;
-	const u_int bit = event % 32;
-
-	if (eid[idx] & __BIT(bit))
-		return true;
+	if (CPU_ID_CORTEX_A9_P(curcpu()->ci_midr)) {
+		/* Cortex-A9 with PMUv1 lacks PMCEID0/1 */
+		u_int n;
+
+		/* Events specific to the Cortex-A9 */
+		for (n = 0; n < __arraycount(cortexa9_events); n++) {
+			if (cortexa9_events[n] == event) {
+return true;
+			}
+		}
+		/* Supported architectural events */
+		if (event != 0x08 && event != 0x0e && event < 0x1e) {
+			return true;
+		}
+	} else {
+		/* PMUv2 */
+		uint32_t eid[2];
+
+		if (event >= 64) {
+			return false;
+		}
+
+		eid[0] = armreg_pmceid0_read();
+		eid[1] = armreg_pmceid1_read();
+
+		const u_int idx = event / 32;
+		const u_int bit = event % 32;
+
+		if (eid[idx] & __BIT(bit)) {
+			return true;
+		}
+	}
 
 	return false;
 }



CVS commit: src/sys/dev/tprof

2022-11-01 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Nov  1 11:03:01 UTC 2022

Modified Files:
src/sys/dev/tprof: tprof_armv7.c

Log Message:
Add support for Cortex-A9.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/tprof/tprof_armv7.c

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



CVS commit: src/sys/dev/tprof

2022-05-26 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu May 26 13:02:04 UTC 2022

Modified Files:
src/sys/dev/tprof: tprof_x86_intel.c

Log Message:
Use CPUID_PERF_* macros defined in specialreg.h. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/tprof/tprof_x86_intel.c

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



CVS commit: src/sys/dev/tprof

2022-05-26 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu May 26 13:02:04 UTC 2022

Modified Files:
src/sys/dev/tprof: tprof_x86_intel.c

Log Message:
Use CPUID_PERF_* macros defined in specialreg.h. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/tprof/tprof_x86_intel.c

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

Modified files:

Index: src/sys/dev/tprof/tprof_x86_intel.c
diff -u src/sys/dev/tprof/tprof_x86_intel.c:1.3 src/sys/dev/tprof/tprof_x86_intel.c:1.4
--- src/sys/dev/tprof/tprof_x86_intel.c:1.3	Fri Jun 14 11:50:35 2019
+++ src/sys/dev/tprof/tprof_x86_intel.c	Thu May 26 13:02:04 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: tprof_x86_intel.c,v 1.3 2019/06/14 11:50:35 msaitoh Exp $	*/
+/*	$NetBSD: tprof_x86_intel.c,v 1.4 2022/05/26 13:02:04 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -56,7 +56,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tprof_x86_intel.c,v 1.3 2019/06/14 11:50:35 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tprof_x86_intel.c,v 1.4 2022/05/26 13:02:04 msaitoh Exp $");
 
 #include 
 #include 
@@ -90,10 +90,6 @@ __KERNEL_RCSID(0, "$NetBSD: tprof_x86_in
 #define	PERFEVTSEL_INV		__BIT(23)
 #define	PERFEVTSEL_COUNTER_MASK	__BITS(24, 31)
 
-#define CPUID_0A_VERSION	__BITS(0, 7)
-#define CPUID_0A_NCOUNTERS	__BITS(8, 15)
-#define CPUID_0A_BITWIDTH	__BITS(16, 23)
-
 static uint64_t counter_bitwidth;
 static uint64_t counter_val = 500;
 static uint64_t counter_reset_val;
@@ -195,14 +191,14 @@ tprof_intel_ident(void)
 		return TPROF_IDENT_NONE;
 	}
 	x86_cpuid(0x0A, descs);
-	if ((descs[0] & CPUID_0A_VERSION) == 0) {
+	if ((descs[0] & CPUID_PERF_VERSION) == 0) {
 		return TPROF_IDENT_NONE;
 	}
-	if ((descs[0] & CPUID_0A_NCOUNTERS) == 0) {
+	if ((descs[0] & CPUID_PERF_NGPPC) == 0) {
 		return TPROF_IDENT_NONE;
 	}
 
-	counter_bitwidth = __SHIFTOUT(descs[0], CPUID_0A_BITWIDTH);
+	counter_bitwidth = __SHIFTOUT(descs[0], CPUID_PERF_NBWGPPC);
 
 	return TPROF_IDENT_INTEL_GENERIC;
 }



CVS commit: src/sys/dev/tprof

2021-12-03 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Fri Dec  3 10:54:19 UTC 2021

Modified Files:
src/sys/dev/tprof: tprof_armv8.c

Log Message:
fix the typo that martin spotted.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/dev/tprof/tprof_armv8.c

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



CVS commit: src/sys/dev/tprof

2021-12-03 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Fri Dec  3 10:54:19 UTC 2021

Modified Files:
src/sys/dev/tprof: tprof_armv8.c

Log Message:
fix the typo that martin spotted.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/dev/tprof/tprof_armv8.c

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

Modified files:

Index: src/sys/dev/tprof/tprof_armv8.c
diff -u src/sys/dev/tprof/tprof_armv8.c:1.12 src/sys/dev/tprof/tprof_armv8.c:1.13
--- src/sys/dev/tprof/tprof_armv8.c:1.12	Fri Dec  3 08:02:52 2021
+++ src/sys/dev/tprof/tprof_armv8.c	Fri Dec  3 10:54:19 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: tprof_armv8.c,v 1.12 2021/12/03 08:02:52 skrll Exp $ */
+/* $NetBSD: tprof_armv8.c,v 1.13 2021/12/03 10:54:19 skrll Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tprof_armv8.c,v 1.12 2021/12/03 08:02:52 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tprof_armv8.c,v 1.13 2021/12/03 10:54:19 skrll Exp $");
 
 #include 
 #include 
@@ -57,7 +57,7 @@ armv8_pmu_event_implemented(uint16_t eve
 	eid[0] = reg_pmceid0_el0_read();
 	eid[1] = reg_pmceid1_el0_read();
 
-	/* The low 32bits of PMCEID[01]_EL0 contain the commmon events 0 to n */
+	/* The low 32bits of PMCEID[01]_EL0 contain the common events 0 to n */
 	const u_int idx = event / 32;
 	const u_int bit = event % 32;
 



CVS commit: src/sys/dev/tprof

2021-12-03 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Fri Dec  3 08:02:52 UTC 2021

Modified Files:
src/sys/dev/tprof: tprof_armv8.c

Log Message:
Add a comment and simplify the code ever so slightly.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/tprof/tprof_armv8.c

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

Modified files:

Index: src/sys/dev/tprof/tprof_armv8.c
diff -u src/sys/dev/tprof/tprof_armv8.c:1.11 src/sys/dev/tprof/tprof_armv8.c:1.12
--- src/sys/dev/tprof/tprof_armv8.c:1.11	Fri Dec  3 08:00:13 2021
+++ src/sys/dev/tprof/tprof_armv8.c	Fri Dec  3 08:02:52 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: tprof_armv8.c,v 1.11 2021/12/03 08:00:13 skrll Exp $ */
+/* $NetBSD: tprof_armv8.c,v 1.12 2021/12/03 08:02:52 skrll Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tprof_armv8.c,v 1.11 2021/12/03 08:00:13 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tprof_armv8.c,v 1.12 2021/12/03 08:02:52 skrll Exp $");
 
 #include 
 #include 
@@ -57,6 +57,7 @@ armv8_pmu_event_implemented(uint16_t eve
 	eid[0] = reg_pmceid0_el0_read();
 	eid[1] = reg_pmceid1_el0_read();
 
+	/* The low 32bits of PMCEID[01]_EL0 contain the commmon events 0 to n */
 	const u_int idx = event / 32;
 	const u_int bit = event % 32;
 
@@ -222,9 +223,7 @@ armv8_pmu_init_cpu(void *arg1, void *arg
 int
 armv8_pmu_init(void)
 {
-	uint64_t xc;
-
-	xc = xc_broadcast(0, armv8_pmu_init_cpu, NULL, NULL);
+	uint64_t xc = xc_broadcast(0, armv8_pmu_init_cpu, NULL, NULL);
 	xc_wait(xc);
 
 	return tprof_backend_register("tprof_armv8", &tprof_armv8_pmu_ops,



CVS commit: src/sys/dev/tprof

2021-12-03 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Fri Dec  3 08:02:52 UTC 2021

Modified Files:
src/sys/dev/tprof: tprof_armv8.c

Log Message:
Add a comment and simplify the code ever so slightly.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/tprof/tprof_armv8.c

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



CVS commit: src/sys/dev/tprof

2021-12-03 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Fri Dec  3 08:00:13 UTC 2021

Modified Files:
src/sys/dev/tprof: tprof_armv8.c

Log Message:
Use the first (not second) event counter as there might only be one
available.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/dev/tprof/tprof_armv8.c

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

Modified files:

Index: src/sys/dev/tprof/tprof_armv8.c
diff -u src/sys/dev/tprof/tprof_armv8.c:1.10 src/sys/dev/tprof/tprof_armv8.c:1.11
--- src/sys/dev/tprof/tprof_armv8.c:1.10	Fri Nov 26 13:24:28 2021
+++ src/sys/dev/tprof/tprof_armv8.c	Fri Dec  3 08:00:13 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: tprof_armv8.c,v 1.10 2021/11/26 13:24:28 christos Exp $ */
+/* $NetBSD: tprof_armv8.c,v 1.11 2021/12/03 08:00:13 skrll Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tprof_armv8.c,v 1.10 2021/11/26 13:24:28 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tprof_armv8.c,v 1.11 2021/12/03 08:00:13 skrll Exp $");
 
 #include 
 #include 
@@ -42,7 +42,7 @@ __KERNEL_RCSID(0, "$NetBSD: tprof_armv8.
 #include 
 
 static tprof_param_t armv8_pmu_param;
-static const u_int armv8_pmu_counter = 1;
+static const u_int armv8_pmu_counter = 0;
 static uint32_t counter_val;
 static uint32_t counter_reset_val;
 



CVS commit: src/sys/dev/tprof

2021-12-03 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Fri Dec  3 08:00:13 UTC 2021

Modified Files:
src/sys/dev/tprof: tprof_armv8.c

Log Message:
Use the first (not second) event counter as there might only be one
available.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/dev/tprof/tprof_armv8.c

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



Re: CVS commit: src/sys/dev/tprof

2021-11-26 Thread Nick Hudson

On 26/11/2021 13:24, Christos Zoulas wrote:

Module Name:src
Committed By:   christos
Date:   Fri Nov 26 13:24:28 UTC 2021

Modified Files:
src/sys/dev/tprof: tprof_armv7.c tprof_armv8.c

Log Message:
declare xc


Thanks!

Nick


CVS commit: src/sys/dev/tprof

2021-11-26 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Nov 26 13:24:28 UTC 2021

Modified Files:
src/sys/dev/tprof: tprof_armv7.c tprof_armv8.c

Log Message:
declare xc


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/tprof/tprof_armv7.c
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/tprof/tprof_armv8.c

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



CVS commit: src/sys/dev/tprof

2021-11-26 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Nov 26 13:24:28 UTC 2021

Modified Files:
src/sys/dev/tprof: tprof_armv7.c tprof_armv8.c

Log Message:
declare xc


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/tprof/tprof_armv7.c
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/tprof/tprof_armv8.c

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

Modified files:

Index: src/sys/dev/tprof/tprof_armv7.c
diff -u src/sys/dev/tprof/tprof_armv7.c:1.5 src/sys/dev/tprof/tprof_armv7.c:1.6
--- src/sys/dev/tprof/tprof_armv7.c:1.5	Thu Nov 25 04:36:21 2021
+++ src/sys/dev/tprof/tprof_armv7.c	Fri Nov 26 08:24:28 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: tprof_armv7.c,v 1.5 2021/11/25 09:36:21 skrll Exp $ */
+/* $NetBSD: tprof_armv7.c,v 1.6 2021/11/26 13:24:28 christos Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tprof_armv7.c,v 1.5 2021/11/25 09:36:21 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tprof_armv7.c,v 1.6 2021/11/26 13:24:28 christos Exp $");
 
 #include 
 #include 
@@ -185,7 +185,7 @@ armv7_pmu_start(const tprof_param_t *par
 	counter_reset_val = -counter_val + 1;
 
 	armv7_pmu_param = *param;
-	xc = xc_broadcast(0, armv7_pmu_start_cpu, NULL, NULL);
+	uint64_t xc = xc_broadcast(0, armv7_pmu_start_cpu, NULL, NULL);
 	xc_wait(xc);
 
 	return 0;

Index: src/sys/dev/tprof/tprof_armv8.c
diff -u src/sys/dev/tprof/tprof_armv8.c:1.9 src/sys/dev/tprof/tprof_armv8.c:1.10
--- src/sys/dev/tprof/tprof_armv8.c:1.9	Thu Nov 25 04:36:21 2021
+++ src/sys/dev/tprof/tprof_armv8.c	Fri Nov 26 08:24:28 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: tprof_armv8.c,v 1.9 2021/11/25 09:36:21 skrll Exp $ */
+/* $NetBSD: tprof_armv8.c,v 1.10 2021/11/26 13:24:28 christos Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tprof_armv8.c,v 1.9 2021/11/25 09:36:21 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tprof_armv8.c,v 1.10 2021/11/26 13:24:28 christos Exp $");
 
 #include 
 #include 
@@ -163,7 +163,7 @@ armv8_pmu_start(const tprof_param_t *par
 	counter_reset_val = -counter_val + 1;
 
 	armv8_pmu_param = *param;
-	xc = xc_broadcast(0, armv8_pmu_start_cpu, NULL, NULL);
+	uint64_t xc = xc_broadcast(0, armv8_pmu_start_cpu, NULL, NULL);
 	xc_wait(xc);
 
 	return 0;



CVS commit: src/sys/dev/tprof

2021-11-01 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Mon Nov  1 17:03:53 UTC 2021

Modified Files:
src/sys/dev/tprof: tprof.c tprof_armv8.c

Log Message:
Trailing whitespace


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/dev/tprof/tprof.c
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/tprof/tprof_armv8.c

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

Modified files:

Index: src/sys/dev/tprof/tprof.c
diff -u src/sys/dev/tprof/tprof.c:1.15 src/sys/dev/tprof/tprof.c:1.16
--- src/sys/dev/tprof/tprof.c:1.15	Fri Nov 27 20:10:25 2020
+++ src/sys/dev/tprof/tprof.c	Mon Nov  1 17:03:53 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tprof.c,v 1.15 2020/11/27 20:10:25 riastradh Exp $	*/
+/*	$NetBSD: tprof.c,v 1.16 2021/11/01 17:03:53 skrll Exp $	*/
 
 /*-
  * Copyright (c)2008,2009,2010 YAMAMOTO Takashi,
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tprof.c,v 1.15 2020/11/27 20:10:25 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tprof.c,v 1.16 2021/11/01 17:03:53 skrll Exp $");
 
 #include 
 #include 
@@ -455,7 +455,7 @@ tprof_sample(void *unused, const tprof_f
 }
 
 /*
- * tprof_backend_register: 
+ * tprof_backend_register:
  */
 
 int
@@ -496,7 +496,7 @@ tprof_backend_register(const char *name,
 }
 
 /*
- * tprof_backend_unregister: 
+ * tprof_backend_unregister:
  */
 
 int

Index: src/sys/dev/tprof/tprof_armv8.c
diff -u src/sys/dev/tprof/tprof_armv8.c:1.7 src/sys/dev/tprof/tprof_armv8.c:1.8
--- src/sys/dev/tprof/tprof_armv8.c:1.7	Sun Sep 26 13:37:36 2021
+++ src/sys/dev/tprof/tprof_armv8.c	Mon Nov  1 17:03:53 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: tprof_armv8.c,v 1.7 2021/09/26 13:37:36 jmcneill Exp $ */
+/* $NetBSD: tprof_armv8.c,v 1.8 2021/11/01 17:03:53 skrll Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tprof_armv8.c,v 1.7 2021/09/26 13:37:36 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tprof_armv8.c,v 1.8 2021/11/01 17:03:53 skrll Exp $");
 
 #include 
 #include 
@@ -205,7 +205,7 @@ armv8_pmu_intr(void *priv)
 
 static void
 armv8_pmu_init_cpu(void *arg1, void *arg2)
-{	
+{
 	/* Disable EL0 access to performance monitors */
 	reg_pmuserenr_el0_write(0);
 



CVS commit: src/sys/dev/tprof

2021-11-01 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Mon Nov  1 17:03:53 UTC 2021

Modified Files:
src/sys/dev/tprof: tprof.c tprof_armv8.c

Log Message:
Trailing whitespace


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/dev/tprof/tprof.c
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/tprof/tprof_armv8.c

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



CVS commit: src/sys/dev/tprof

2021-09-26 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Sep 26 13:37:36 UTC 2021

Modified Files:
src/sys/dev/tprof: tprof_armv8.c

Log Message:
Make sure setup happens on all CPUs.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/tprof/tprof_armv8.c

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

Modified files:

Index: src/sys/dev/tprof/tprof_armv8.c
diff -u src/sys/dev/tprof/tprof_armv8.c:1.6 src/sys/dev/tprof/tprof_armv8.c:1.7
--- src/sys/dev/tprof/tprof_armv8.c:1.6	Fri Oct 30 18:54:37 2020
+++ src/sys/dev/tprof/tprof_armv8.c	Sun Sep 26 13:37:36 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: tprof_armv8.c,v 1.6 2020/10/30 18:54:37 skrll Exp $ */
+/* $NetBSD: tprof_armv8.c,v 1.7 2021/09/26 13:37:36 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tprof_armv8.c,v 1.6 2020/10/30 18:54:37 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tprof_armv8.c,v 1.7 2021/09/26 13:37:36 jmcneill Exp $");
 
 #include 
 #include 
@@ -111,6 +111,7 @@ armv8_pmu_start_cpu(void *arg1, void *ar
 
 	/* Enable event counter */
 	reg_pmcntenset_el0_write(counter_mask);
+	reg_pmcr_el0_write(PMCR_E);
 }
 
 static void
@@ -123,6 +124,7 @@ armv8_pmu_stop_cpu(void *arg1, void *arg
 
 	/* Disable event counter */
 	reg_pmcntenclr_el0_write(counter_mask);
+	reg_pmcr_el0_write(0);
 }
 
 static uint64_t
@@ -130,16 +132,11 @@ armv8_pmu_estimate_freq(void)
 {
 	uint64_t cpufreq = curcpu()->ci_data.cpu_cc_freq;
 	uint64_t freq = 1;
-	uint32_t pmcr;
 
 	counter_val = cpufreq / freq;
 	if (counter_val == 0)
 		counter_val = 40ULL / freq;
 
-	pmcr = reg_pmcr_el0_read();
-	if (pmcr & PMCR_D)
-		counter_val /= 64;
-
 	return freq;
 }
 
@@ -206,9 +203,9 @@ armv8_pmu_intr(void *priv)
 	return 1;
 }
 
-int
-armv8_pmu_init(void)
-{
+static void
+armv8_pmu_init_cpu(void *arg1, void *arg2)
+{	
 	/* Disable EL0 access to performance monitors */
 	reg_pmuserenr_el0_write(0);
 
@@ -217,6 +214,15 @@ armv8_pmu_init(void)
 
 	/* Disable event counters */
 	reg_pmcntenclr_el0_write(PMCNTEN_P);
+}
+
+int
+armv8_pmu_init(void)
+{
+	uint64_t xc;
+
+	xc = xc_broadcast(0, armv8_pmu_init_cpu, NULL, NULL);
+	xc_wait(xc);
 
 	return tprof_backend_register("tprof_armv8", &tprof_armv8_pmu_ops,
 	TPROF_BACKEND_VERSION);



CVS commit: src/sys/dev/tprof

2021-09-26 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Sep 26 13:37:36 UTC 2021

Modified Files:
src/sys/dev/tprof: tprof_armv8.c

Log Message:
Make sure setup happens on all CPUs.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/tprof/tprof_armv8.c

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



CVS commit: src/sys/dev/tprof

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

Modified Files:
src/sys/dev/tprof: tprof_x86_amd.c

Log Message:
Match Family 15h


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/tprof/tprof_x86_amd.c

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

Modified files:

Index: src/sys/dev/tprof/tprof_x86_amd.c
diff -u src/sys/dev/tprof/tprof_x86_amd.c:1.4 src/sys/dev/tprof/tprof_x86_amd.c:1.5
--- src/sys/dev/tprof/tprof_x86_amd.c:1.4	Fri Jun 14 11:50:35 2019
+++ src/sys/dev/tprof/tprof_x86_amd.c	Fri Oct 11 18:04:52 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: tprof_x86_amd.c,v 1.4 2019/06/14 11:50:35 msaitoh Exp $	*/
+/*	$NetBSD: tprof_x86_amd.c,v 1.5 2019/10/11 18:04:52 jmcneill Exp $	*/
 
 /*
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -56,7 +56,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tprof_x86_amd.c,v 1.4 2019/06/14 11:50:35 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tprof_x86_amd.c,v 1.5 2019/10/11 18:04:52 jmcneill Exp $");
 
 #include 
 #include 
@@ -205,6 +205,7 @@ tprof_amd_ident(void)
 
 	switch (CPUID_TO_FAMILY(ci->ci_signature)) {
 	case 0x10:
+	case 0x15:
 	case 0x17:
 		return TPROF_IDENT_AMD_GENERIC;
 	}



CVS commit: src/sys/dev/tprof

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

Modified Files:
src/sys/dev/tprof: tprof_x86_amd.c

Log Message:
Match Family 15h


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/tprof/tprof_x86_amd.c

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



CVS commit: src/sys/dev/tprof

2019-06-14 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Fri Jun 14 11:50:35 UTC 2019

Modified Files:
src/sys/dev/tprof: tprof_x86_amd.c tprof_x86_intel.c

Log Message:
 Fix compile error (s/LAPIC_PCINT/LAPIC_LVT_PCINT/)


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/tprof/tprof_x86_amd.c
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/tprof/tprof_x86_intel.c

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

Modified files:

Index: src/sys/dev/tprof/tprof_x86_amd.c
diff -u src/sys/dev/tprof/tprof_x86_amd.c:1.3 src/sys/dev/tprof/tprof_x86_amd.c:1.4
--- src/sys/dev/tprof/tprof_x86_amd.c:1.3	Wed May 29 17:09:17 2019
+++ src/sys/dev/tprof/tprof_x86_amd.c	Fri Jun 14 11:50:35 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: tprof_x86_amd.c,v 1.3 2019/05/29 17:09:17 maxv Exp $	*/
+/*	$NetBSD: tprof_x86_amd.c,v 1.4 2019/06/14 11:50:35 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -56,7 +56,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tprof_x86_amd.c,v 1.3 2019/05/29 17:09:17 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tprof_x86_amd.c,v 1.4 2019/06/14 11:50:35 msaitoh Exp $");
 
 #include 
 #include 
@@ -135,8 +135,8 @@ tprof_amd_start_cpu(void *arg1, void *ar
 	wrmsr(PERFCTR(ctrno), counter_reset_val);
 	wrmsr(PERFEVTSEL(ctrno), pesr);
 
-	amd_lapic_saved[cpu_index(ci)] = lapic_readreg(LAPIC_PCINT);
-	lapic_writereg(LAPIC_PCINT, LAPIC_DLMODE_NMI);
+	amd_lapic_saved[cpu_index(ci)] = lapic_readreg(LAPIC_LVT_PCINT);
+	lapic_writereg(LAPIC_LVT_PCINT, LAPIC_DLMODE_NMI);
 
 	wrmsr(PERFEVTSEL(ctrno), pesr | PESR_EN);
 }
@@ -148,7 +148,7 @@ tprof_amd_stop_cpu(void *arg1, void *arg
 
 	wrmsr(PERFEVTSEL(ctrno), 0);
 
-	lapic_writereg(LAPIC_PCINT, amd_lapic_saved[cpu_index(ci)]);
+	lapic_writereg(LAPIC_LVT_PCINT, amd_lapic_saved[cpu_index(ci)]);
 }
 
 static int

Index: src/sys/dev/tprof/tprof_x86_intel.c
diff -u src/sys/dev/tprof/tprof_x86_intel.c:1.2 src/sys/dev/tprof/tprof_x86_intel.c:1.3
--- src/sys/dev/tprof/tprof_x86_intel.c:1.2	Tue Jul 24 09:47:35 2018
+++ src/sys/dev/tprof/tprof_x86_intel.c	Fri Jun 14 11:50:35 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: tprof_x86_intel.c,v 1.2 2018/07/24 09:47:35 maxv Exp $	*/
+/*	$NetBSD: tprof_x86_intel.c,v 1.3 2019/06/14 11:50:35 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -56,7 +56,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tprof_x86_intel.c,v 1.2 2018/07/24 09:47:35 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tprof_x86_intel.c,v 1.3 2019/06/14 11:50:35 msaitoh Exp $");
 
 #include 
 #include 
@@ -119,8 +119,8 @@ tprof_intel_start_cpu(void *arg1, void *
 	wrmsr(MSR_PERFCTR0, counter_reset_val);
 	wrmsr(MSR_EVNTSEL0, evtval);
 
-	intel_lapic_saved[cpu_index(ci)] = lapic_readreg(LAPIC_PCINT);
-	lapic_writereg(LAPIC_PCINT, LAPIC_DLMODE_NMI);
+	intel_lapic_saved[cpu_index(ci)] = lapic_readreg(LAPIC_LVT_PCINT);
+	lapic_writereg(LAPIC_LVT_PCINT, LAPIC_DLMODE_NMI);
 }
 
 static void
@@ -131,7 +131,7 @@ tprof_intel_stop_cpu(void *arg1, void *a
 	wrmsr(MSR_EVNTSEL0, 0);
 	wrmsr(MSR_PERFCTR0, 0);
 
-	lapic_writereg(LAPIC_PCINT, intel_lapic_saved[cpu_index(ci)]);
+	lapic_writereg(LAPIC_LVT_PCINT, intel_lapic_saved[cpu_index(ci)]);
 }
 
 static int
@@ -162,9 +162,9 @@ tprof_intel_nmi(const struct trapframe *
 	wrmsr(MSR_PERFCTR0, counter_reset_val);
 
 	/* unmask PMI */
-	pcint = lapic_readreg(LAPIC_PCINT);
+	pcint = lapic_readreg(LAPIC_LVT_PCINT);
 	KASSERT((pcint & LAPIC_LVT_MASKED) != 0);
-	lapic_writereg(LAPIC_PCINT, pcint & ~LAPIC_LVT_MASKED);
+	lapic_writereg(LAPIC_LVT_PCINT, pcint & ~LAPIC_LVT_MASKED);
 
 	return 1;
 }



CVS commit: src/sys/dev/tprof

2019-06-14 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Fri Jun 14 11:50:35 UTC 2019

Modified Files:
src/sys/dev/tprof: tprof_x86_amd.c tprof_x86_intel.c

Log Message:
 Fix compile error (s/LAPIC_PCINT/LAPIC_LVT_PCINT/)


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/tprof/tprof_x86_amd.c
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/tprof/tprof_x86_intel.c

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