Source-Changes-HG archive

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

[src/trunk]: src/sys/arch Since the PMC cycle counter is started in cpufunc n...



details:   https://anonhg.NetBSD.org/src/rev/9efcc29d4f0d
branches:  trunk
changeset: 781263:9efcc29d4f0d
user:      matt <matt%NetBSD.org@localhost>
date:      Wed Aug 29 19:10:15 2012 +0000

description:
Since the PMC cycle counter is started in cpufunc no reason to do so here.
Use curcpu()->ci_data.cpu_cc_freq and new armreg* inlines.

diffstat:

 sys/arch/arm/arm32/cortex_pmc.c               |  89 ++++++++------------------
 sys/arch/arm/include/arm32/machdep.h          |   3 +-
 sys/arch/evbarm/beagle/beagle_machdep.c       |   8 +-
 sys/arch/evbarm/conf/std.beagle               |   4 +-
 sys/arch/evbarm/gumstix/gumstix_machdep.c     |  10 +--
 sys/arch/evbarm/netwalker/netwalker_machdep.c |   8 +-
 6 files changed, 40 insertions(+), 82 deletions(-)

diffs (277 lines):

diff -r da7602ce1899 -r 9efcc29d4f0d sys/arch/arm/arm32/cortex_pmc.c
--- a/sys/arch/arm/arm32/cortex_pmc.c   Wed Aug 29 18:56:45 2012 +0000
+++ b/sys/arch/arm/arm32/cortex_pmc.c   Wed Aug 29 19:10:15 2012 +0000
@@ -28,12 +28,12 @@
 
 
 /*
- * support for ARM cortexa8 Performance Monitor Counters
+ * support for ARM cortex Performance Monitor Counters
  * based on arm11_pmc.c
  */
 
 #include <sys/cdefs.h>
-/* __KERNEL_RCSID(0, "$NetBSD: cortex_pmc.c,v 1.1 2010/06/19 19:44:57 matt Exp $"); */
+/* __KERNEL_RCSID(0, "$NetBSD: cortex_pmc.c,v 1.2 2012/08/29 19:10:15 matt Exp $"); */
 #include "opt_perfctrs.h"
 #include <sys/types.h>
 #include <sys/param.h>
@@ -41,69 +41,32 @@
 #include <sys/kernel.h>  
 #include <sys/time.h>
 #include <sys/timetc.h>
+
 #include <dev/clock_subr.h>
+
+#include <uvm/uvm_extern.h>
+
 #include <arm/armreg.h>
 #include <arm/cpufunc.h>
+#include <arm/arm32/machdep.h>
 
 #ifndef CORTEX_PMC_CCNT_HZ
 # define CORTEX_PMC_CCNT_HZ    400000000       /* 400MHz */
 #endif
 
-void cortexa8_pmc_ccnt_init(void);
-
-#define COUNTS_PER_USEC        (CORTEX_PMC_CCNT_HZ / 1000000)
-
-static uint32_t counts_per_wrap = ~0UL;                /* XXX off by 1 */
-
-#define PMNC "c9, c12, 0"
-#define CCNT "c9, c13, 0"
-
-static inline uint32_t
-cortexa8_pmc_ctrl_read(void)
-{
-       uint32_t val;
-
-       __asm volatile ("mrc p15, 0, %0, " PMNC : "=r" (val));
-
-       return val;
-}
+#define COUNTS_PER_USEC        (curcpu()->ci_data.cpu_cc_freq / (1000*1000))
 
-static inline void
-cortexa8_pmc_ctrl_write(uint32_t val)
-{
-       __asm volatile ("mcr p15, 0, %0, " PMNC :: "r" (val));
-}
-
-static inline uint32_t
-cortexa8_pmc_ccnt_read(void)
-{
-       uint32_t val;
-
-       __asm volatile ("mrc p15, 0, %0, " CCNT : "=r" (val));
-
-       return val;
-}
-
-static inline void
-cortexa8_pmc_ccnt_write(uint32_t val)
-{
-  __asm volatile ("mcr p15, 0, %0, c9, c12, 2"  :: "r" (CORTEX_CNTENC_C));
-  __asm volatile ("mcr p15, 0, %0, " CCNT :: "r" (val));
-  __asm volatile ("mcr p15, 0, %0, c9, c12, 1" :: "r" (CORTEX_CNTENS_C));
-}
+static const uint32_t counts_per_wrap = ~0UL - 1;
 
 /*
  * enable the PMC CCNT for delay()
  */
 void
-cortexa8_pmc_ccnt_init(void)
+cortex_pmc_ccnt_init(void)
 {
-  uint32_t val;
-  
-  val = ARM11_PMCCTL_E | ARM11_PMCCTL_P | ARM11_PMCCTL_C;
-       
-  cortexa8_pmc_ctrl_write(val);
-  __asm volatile ("mcr p15, 0, %0, c9, c12, 1" :: "r" (CORTEX_CNTENS_C));
+       if (curcpu()->ci_data.cpu_cc_freq == 0) {
+               curcpu()->ci_data.cpu_cc_freq = CORTEX_PMC_CCNT_HZ;
+       }
 }
 
 /*
@@ -112,7 +75,6 @@
  *     NOTE: at 400MHz we are restricted to (uint32_t)~0 "counts"
  *     if this is a problem, accumulate counts in LL vars
  */
-#define DELAY_ARG_LIMIT (((uint32_t)~0) / COUNTS_PER_USEC)     /* about 10 sec */
 void
 delay(u_int arg)
 {
@@ -121,29 +83,32 @@
        uint32_t last;
        uint32_t delta = 0;
        uint32_t usecs = 0;
+       const uint32_t counts_per_usec = COUNTS_PER_USEC;
+       const uint32_t delay_arg_limit = ~0UL / counts_per_usec; /* about 10 sec */
 
-       if (arg > DELAY_ARG_LIMIT)
-               panic("delay: arg %u overflow, limit is %d usec\n", arg, DELAY_ARG_LIMIT);
+       if (arg > delay_arg_limit)
+               panic("%s: arg %u overflow, limit is %u usec\n",
+                   __func__, arg, delay_arg_limit);
 
-       last = cortexa8_pmc_ccnt_read();
+       last = armreg_pmccntr_read();
        delta = usecs = 0;
        while (arg > usecs) {
-               cur  = cortexa8_pmc_ccnt_read();
+               cur = armreg_pmccntr_read();
                
                /* overflow flag is moved to a separate register
                   and is not read from PMC Control Register */
-               __asm volatile ("mrc p15, 0, %0, c9, c12, 3" : "=r" (ctrl));
-               if(ctrl & CORTEX_CNTOFL_C){
+               ctrl = armreg_pmovsr_read();
+               if (ctrl & CORTEX_CNTOFL_C) {
                  /* Reset overflow flag for cycle counter in overflow register */
-                 __asm volatile ("mcr p15, 0, %0, c9, c12, 3" :: "r" (CORTEX_CNTOFL_C));
-                 delta += (last + (counts_per_wrap - cur));
+                       armreg_pmovsr_write(CORTEX_CNTOFL_C);
+                       delta += (last + (counts_per_wrap - cur));
                } else {
                        delta += (cur - last);
                }
                last = cur;
-               if (delta >= COUNTS_PER_USEC) {
-                       usecs += delta / COUNTS_PER_USEC;
-                       delta %= COUNTS_PER_USEC;
+               if (delta >= counts_per_usec) {
+                       usecs += delta / counts_per_usec;
+                       delta %= counts_per_usec;
                }
        }
 }
diff -r da7602ce1899 -r 9efcc29d4f0d sys/arch/arm/include/arm32/machdep.h
--- a/sys/arch/arm/include/arm32/machdep.h      Wed Aug 29 18:56:45 2012 +0000
+++ b/sys/arch/arm/include/arm32/machdep.h      Wed Aug 29 19:10:15 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.h,v 1.11 2012/08/16 18:22:40 matt Exp $ */
+/* $NetBSD: machdep.h,v 1.12 2012/08/29 19:10:16 matt Exp $ */
 
 #ifndef _ARM32_BOOT_MACHDEP_H_
 #define _ARM32_BOOT_MACHDEP_H_
@@ -32,6 +32,7 @@
 extern char *booted_kernel;
 
 /* misc prototypes used by the many arm machdeps */
+void cortex_pmc_ccnt_init(void);
 void halt(void);
 void parse_mi_bootargs(char *);
 void data_abort_handler(trapframe_t *);
diff -r da7602ce1899 -r 9efcc29d4f0d sys/arch/evbarm/beagle/beagle_machdep.c
--- a/sys/arch/evbarm/beagle/beagle_machdep.c   Wed Aug 29 18:56:45 2012 +0000
+++ b/sys/arch/evbarm/beagle/beagle_machdep.c   Wed Aug 29 19:10:15 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: beagle_machdep.c,v 1.18 2012/08/29 18:05:41 matt Exp $ */
+/*     $NetBSD: beagle_machdep.c,v 1.19 2012/08/29 19:10:16 matt Exp $ */
 
 /*
  * Machine dependent functions for kernel setup for TI OSK5912 board.
@@ -125,7 +125,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: beagle_machdep.c,v 1.18 2012/08/29 18:05:41 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: beagle_machdep.c,v 1.19 2012/08/29 19:10:16 matt Exp $");
 
 #include "opt_machdep.h"
 #include "opt_ddb.h"
@@ -645,8 +645,6 @@
        return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
 }
 
-void cortexa8_pmc_ccnt_init(void);
-
 static void
 init_clocks(void)
 {
@@ -663,7 +661,7 @@
        }
        beagle_putchar('G');
 #endif
-       cortexa8_pmc_ccnt_init();
+       cortex_pmc_ccnt_init();
 }
 
 #ifndef CONSADDR
diff -r da7602ce1899 -r 9efcc29d4f0d sys/arch/evbarm/conf/std.beagle
--- a/sys/arch/evbarm/conf/std.beagle   Wed Aug 29 18:56:45 2012 +0000
+++ b/sys/arch/evbarm/conf/std.beagle   Wed Aug 29 19:10:15 2012 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: std.beagle,v 1.4 2012/08/29 07:14:05 matt Exp $
+#      $NetBSD: std.beagle,v 1.5 2012/08/29 19:10:16 matt Exp $
 #
 # standard NetBSD/evbarm for BEAGLEBAORD options
 
@@ -12,9 +12,9 @@
 options        EXEC_SCRIPT
 
 # To support easy transit to ../arch/arm/arm32
+options        __HAVE_CPU_COUNTER
 options        ARM32
 options        CORTEX_PMC
-options        CORTEX_PMC_CCNT_HZ=500000000
 options        __HAVE_FAST_SOFTINTS            # should be in types.h
 options        TPIDRPRW_IS_CURCPU
 options        KERNEL_BASE_EXT=0x80000000
diff -r da7602ce1899 -r 9efcc29d4f0d sys/arch/evbarm/gumstix/gumstix_machdep.c
--- a/sys/arch/evbarm/gumstix/gumstix_machdep.c Wed Aug 29 18:56:45 2012 +0000
+++ b/sys/arch/evbarm/gumstix/gumstix_machdep.c Wed Aug 29 19:10:15 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: gumstix_machdep.c,v 1.41 2012/08/16 18:22:43 matt Exp $ */
+/*     $NetBSD: gumstix_machdep.c,v 1.42 2012/08/29 19:10:16 matt Exp $ */
 /*
  * Copyright (C) 2005, 2006, 2007  WIDE Project and SOUM Corporation.
  * All rights reserved.
@@ -530,12 +530,8 @@
        pxa2x0_gpio_bootstrap(GUMSTIX_GPIO_VBASE);
 
        pxa2x0_clkman_bootstrap(GUMSTIX_CLKMAN_VBASE);
-#elif defined(CPU_CORTEXA8)
-       {
-               void cortexa8_pmc_ccnt_init(void);
-
-               cortexa8_pmc_ccnt_init();
-       }
+#elif defined(CPU_CORTEX)
+       cortex_pmc_ccnt_init();
 #endif
 
        cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
diff -r da7602ce1899 -r 9efcc29d4f0d sys/arch/evbarm/netwalker/netwalker_machdep.c
--- a/sys/arch/evbarm/netwalker/netwalker_machdep.c     Wed Aug 29 18:56:45 2012 +0000
+++ b/sys/arch/evbarm/netwalker/netwalker_machdep.c     Wed Aug 29 19:10:15 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: netwalker_machdep.c,v 1.8 2012/08/16 18:22:45 matt Exp $       */
+/*     $NetBSD: netwalker_machdep.c,v 1.9 2012/08/29 19:10:17 matt Exp $       */
 
 /*
  * Copyright (c) 2002, 2003, 2005, 2010  Genetec Corporation. 
@@ -102,7 +102,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netwalker_machdep.c,v 1.8 2012/08/16 18:22:45 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netwalker_machdep.c,v 1.9 2012/08/29 19:10:17 matt Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -887,9 +887,7 @@
 static void
 init_clocks(void)
 {
-       extern void cortexa8_pmc_ccnt_init(void);
-
-       cortexa8_pmc_ccnt_init();
+       cortex_pmc_ccnt_init();
 }
 
 struct iomux_setup {



Home | Main Index | Thread Index | Old Index