Source-Changes-HG archive

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

[src/netbsd-10]: src/sys/dev/tprof Pull up following revision(s) (requested b...



details:   https://anonhg.NetBSD.org/src/rev/7696700c744b
branches:  netbsd-10
changeset: 372731:7696700c744b
user:      martin <martin%NetBSD.org@localhost>
date:      Fri Dec 23 08:09:48 2022 +0000

description:
Pull up following revision(s) (requested by ryo in ticket #20):

        sys/arch/arm/arm/cpufunc.c: revision 1.185
        sys/dev/tprof/tprof.c: revision 1.22
        sys/arch/arm/arm32/arm32_boot.c: revision 1.45
        sys/dev/tprof/tprof_armv8.c: revision 1.19
        sys/dev/tprof/tprof_armv7.c: revision 1.12
        sys/arch/aarch64/aarch64/cpu.c: revision 1.71
        sys/arch/aarch64/aarch64/cpu.c: revision 1.72

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

Explicitly disable overflow interrupts before enabling the cycle counter.

PMCR_EL0.LC should be set. ARM deprecates use of PMCR_EL0.LC=0

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.

diffstat:

 sys/arch/aarch64/aarch64/cpu.c  |   7 ++++---
 sys/arch/arm/arm/cpufunc.c      |   5 +++--
 sys/arch/arm/arm32/arm32_boot.c |   5 +++--
 sys/dev/tprof/tprof.c           |  16 ++++++++--------
 sys/dev/tprof/tprof_armv7.c     |   8 ++++----
 sys/dev/tprof/tprof_armv8.c     |   8 ++++----
 6 files changed, 26 insertions(+), 23 deletions(-)

diffs (212 lines):

diff -r 013c62751f84 -r 7696700c744b sys/arch/aarch64/aarch64/cpu.c
--- a/sys/arch/aarch64/aarch64/cpu.c    Wed Dec 21 20:00:07 2022 +0000
+++ b/sys/arch/aarch64/aarch64/cpu.c    Fri Dec 23 08:09:48 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.c,v 1.70 2022/05/29 16:14:41 ryo Exp $ */
+/* $NetBSD: cpu.c,v 1.70.4.1 2022/12/23 08:09:48 martin Exp $ */
 
 /*
  * Copyright (c) 2017 Ryo Shimizu <ryo%nerv.org@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: cpu.c,v 1.70 2022/05/29 16:14:41 ryo Exp $");
+__KERNEL_RCSID(1, "$NetBSD: cpu.c,v 1.70.4.1 2022/12/23 08:09:48 martin Exp $");
 
 #include "locators.h"
 #include "opt_arm_debug.h"
@@ -498,7 +498,8 @@
                return;
        }
 
-       reg_pmcr_el0_write(PMCR_E | PMCR_C);
+       reg_pmcr_el0_write(PMCR_E | PMCR_C | PMCR_LC);
+       reg_pmintenclr_el1_write(PMINTEN_C | PMINTEN_P);
        reg_pmcntenset_el0_write(PMCNTEN_C);
 
        const uint32_t prev = cpu_counter32();
diff -r 013c62751f84 -r 7696700c744b sys/arch/arm/arm/cpufunc.c
--- a/sys/arch/arm/arm/cpufunc.c        Wed Dec 21 20:00:07 2022 +0000
+++ b/sys/arch/arm/arm/cpufunc.c        Fri Dec 23 08:09:48 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cpufunc.c,v 1.184 2022/05/16 07:07:17 skrll Exp $      */
+/*     $NetBSD: cpufunc.c,v 1.184.4.1 2022/12/23 08:09:48 martin Exp $ */
 
 /*
  * arm7tdmi support code Copyright (c) 2001 John Fremlin
@@ -49,7 +49,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpufunc.c,v 1.184 2022/05/16 07:07:17 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpufunc.c,v 1.184.4.1 2022/12/23 08:09:48 martin Exp $");
 
 #include "opt_arm_start.h"
 #include "opt_compat_netbsd.h"
@@ -1964,6 +1964,7 @@
                 * Start and reset the PMC Cycle Counter.
                 */
                armreg_pmcr_write(ARM11_PMCCTL_E | ARM11_PMCCTL_P | ARM11_PMCCTL_C);
+               armreg_pmintenclr_write(PMINTEN_C | PMINTEN_P);
                armreg_pmcntenset_write(CORTEX_CNTENS_C);
                return 0;
        }
diff -r 013c62751f84 -r 7696700c744b sys/arch/arm/arm32/arm32_boot.c
--- a/sys/arch/arm/arm32/arm32_boot.c   Wed Dec 21 20:00:07 2022 +0000
+++ b/sys/arch/arm/arm32/arm32_boot.c   Fri Dec 23 08:09:48 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: arm32_boot.c,v 1.44 2021/10/31 16:23:47 skrll Exp $    */
+/*     $NetBSD: arm32_boot.c,v 1.44.4.1 2022/12/23 08:09:48 martin Exp $       */
 
 /*
  * Copyright (c) 2002, 2003, 2005  Genetec Corporation.  All rights reserved.
@@ -122,7 +122,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: arm32_boot.c,v 1.44 2021/10/31 16:23:47 skrll Exp $");
+__KERNEL_RCSID(1, "$NetBSD: arm32_boot.c,v 1.44.4.1 2022/12/23 08:09:48 martin Exp $");
 
 #include "opt_arm_debug.h"
 #include "opt_cputypes.h"
@@ -407,6 +407,7 @@
                 * Start and reset the PMC Cycle Counter.
                 */
                armreg_pmcr_write(ARM11_PMCCTL_E|ARM11_PMCCTL_P|ARM11_PMCCTL_C);
+               armreg_pmintenclr_write(PMINTEN_C | PMINTEN_P);
                armreg_pmcntenset_write(CORTEX_CNTENS_C);
        }
 #endif
diff -r 013c62751f84 -r 7696700c744b sys/dev/tprof/tprof.c
--- a/sys/dev/tprof/tprof.c     Wed Dec 21 20:00:07 2022 +0000
+++ b/sys/dev/tprof/tprof.c     Fri Dec 23 08:09:48 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tprof.c,v 1.21 2022/12/16 07:59:42 ryo Exp $   */
+/*     $NetBSD: tprof.c,v 1.21.2.1 2022/12/23 08:09:48 martin Exp $    */
 
 /*-
  * Copyright (c)2008,2009,2010 YAMAMOTO Takashi,
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__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.21.2.1 2022/12/23 08:09:48 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -885,9 +885,9 @@
 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 @@
        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 @@
        }
 
        if ((hint & NOTE_SUBMIT) == 0)
-               mutex_spin_exit(&tprof_lock);
+               mutex_exit(&tprof_lock);
 
        return rv;
 }
@@ -929,9 +929,9 @@
        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;
diff -r 013c62751f84 -r 7696700c744b sys/dev/tprof/tprof_armv7.c
--- a/sys/dev/tprof/tprof_armv7.c       Wed Dec 21 20:00:07 2022 +0000
+++ b/sys/dev/tprof/tprof_armv7.c       Fri Dec 23 08:09:48 2022 +0000
@@ -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.11.2.1 2022/12/23 08:09:48 martin Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__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.11.2.1 2022/12/23 08:09:48 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -225,7 +225,7 @@
        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 @@
                            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);
                }
diff -r 013c62751f84 -r 7696700c744b sys/dev/tprof/tprof_armv8.c
--- a/sys/dev/tprof/tprof_armv8.c       Wed Dec 21 20:00:07 2022 +0000
+++ b/sys/dev/tprof/tprof_armv8.c       Fri Dec 23 08:09:48 2022 +0000
@@ -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.18.2.1 2022/12/23 08:09:48 martin Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__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.18.2.1 2022/12/23 08:09:48 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -197,7 +197,7 @@
        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 @@
                            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);
                }



Home | Main Index | Thread Index | Old Index