Source-Changes-HG archive

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

[src/trunk]: src/sys/sys Fix cycle counter-based time keeping on Alpha in MP ...



details:   https://anonhg.NetBSD.org/src/rev/9bb9b92027dc
branches:  trunk
changeset: 940549:9bb9b92027dc
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sat Oct 10 03:05:04 2020 +0000

description:
Fix cycle counter-based time keeping on Alpha in MP environments by using
a simpler calibration algorithm for the CC timecounter.  Proposed in 2018
by Naruaki Etomi:

    https://mail-index.netbsd.org/tech-kern/2018/01/14/msg022940.html

This patch is largely based on the proposed change, but avoids changing
any other timecounter logic, and re-factors things a bit to keep them
as MI as possible.

diffstat:

 sys/arch/alpha/alpha/clock.c         |    7 +-
 sys/arch/alpha/alpha/cpu.c           |    8 +-
 sys/arch/alpha/alpha/interrupt.c     |   10 +-
 sys/arch/alpha/alpha/ipifuncs.c      |   17 +-
 sys/arch/alpha/include/alpha.h       |    3 +-
 sys/arch/alpha/include/cpu_counter.h |    6 +-
 sys/arch/alpha/include/intr.h        |    4 +-
 sys/kern/kern_cctr.c                 |  393 ++++++++++++++++------------------
 sys/sys/cctr.h                       |   31 +-
 9 files changed, 238 insertions(+), 241 deletions(-)

diffs (truncated from 736 to 300 lines):

diff -r 71c9927ca707 -r 9bb9b92027dc sys/arch/alpha/alpha/clock.c
--- a/sys/arch/alpha/alpha/clock.c      Sat Oct 10 00:10:06 2020 +0000
+++ b/sys/arch/alpha/alpha/clock.c      Sat Oct 10 03:05:04 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: clock.c,v 1.45 2020/09/29 01:33:00 thorpej Exp $ */
+/* $NetBSD: clock.c,v 1.46 2020/10/10 03:05:04 thorpej Exp $ */
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -39,7 +39,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.45 2020/09/29 01:33:00 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.46 2020/10/10 03:05:04 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -59,6 +59,8 @@
 void (*clock_init)(void *);
 void *clockdev;
 
+int    alpha_use_cctr;         /* != 0 if we're using the PCC timecounter */
+
 void
 clockattach(void (*fns)(void *), void *dev)
 {
@@ -111,6 +113,7 @@
        if (! alpha_is_qemu) {
                const uint64_t pcc_freq = cpu_frequency(curcpu());
                cc_init(NULL, pcc_freq, "PCC", PCC_QUAL);
+               alpha_use_cctr = 1;
        }
 
        /*
diff -r 71c9927ca707 -r 9bb9b92027dc sys/arch/alpha/alpha/cpu.c
--- a/sys/arch/alpha/alpha/cpu.c        Sat Oct 10 00:10:06 2020 +0000
+++ b/sys/arch/alpha/alpha/cpu.c        Sat Oct 10 03:05:04 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.c,v 1.101 2020/09/29 01:33:00 thorpej Exp $ */
+/* $NetBSD: cpu.c,v 1.102 2020/10/10 03:05:04 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
 
 #include <sys/cdefs.h>                 /* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.101 2020/09/29 01:33:00 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.102 2020/10/10 03:05:04 thorpej Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -602,7 +602,9 @@
        ALPHA_TBIA();
        alpha_pal_imb();
 
-       cc_calibrate_cpu(ci);
+       if (alpha_use_cctr) {
+               cc_init_secondary(ci);
+       }
 
        cpu_initclocks_secondary();
 }
diff -r 71c9927ca707 -r 9bb9b92027dc sys/arch/alpha/alpha/interrupt.c
--- a/sys/arch/alpha/alpha/interrupt.c  Sat Oct 10 00:10:06 2020 +0000
+++ b/sys/arch/alpha/alpha/interrupt.c  Sat Oct 10 03:05:04 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: interrupt.c,v 1.91 2020/09/26 21:07:48 thorpej Exp $ */
+/* $NetBSD: interrupt.c,v 1.92 2020/10/10 03:05:04 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
 
 #include <sys/cdefs.h>                 /* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: interrupt.c,v 1.91 2020/09/26 21:07:48 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: interrupt.c,v 1.92 2020/10/10 03:05:04 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -228,6 +228,12 @@
                         */
                        (*platform.clockintr)((struct clockframe *)framep);
 
+#if defined(MULTIPROCESSOR)
+                       if (alpha_use_cctr) {
+                               cc_hardclock(ci);
+                       }
+#endif /* MULTIPROCESSOR */
+
                        /*
                         * If it's time to call the scheduler clock,
                         * do so.
diff -r 71c9927ca707 -r 9bb9b92027dc sys/arch/alpha/alpha/ipifuncs.c
--- a/sys/arch/alpha/alpha/ipifuncs.c   Sat Oct 10 00:10:06 2020 +0000
+++ b/sys/arch/alpha/alpha/ipifuncs.c   Sat Oct 10 03:05:04 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ipifuncs.c,v 1.53 2020/09/03 02:03:14 thorpej Exp $ */
+/* $NetBSD: ipifuncs.c,v 1.54 2020/10/10 03:05:04 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 
 #include <sys/cdefs.h>                 /* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: ipifuncs.c,v 1.53 2020/09/03 02:03:14 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ipifuncs.c,v 1.54 2020/10/10 03:05:04 thorpej Exp $");
 
 /*
  * Interprocessor interrupt handlers.
@@ -61,7 +61,7 @@
 typedef void (*ipifunc_t)(struct cpu_info *, struct trapframe *);
 
 static void    alpha_ipi_halt(struct cpu_info *, struct trapframe *);
-static void    alpha_ipi_microset(struct cpu_info *, struct trapframe *);
+static void    alpha_ipi_primary_cc(struct cpu_info *, struct trapframe *);
 static void    alpha_ipi_ast(struct cpu_info *, struct trapframe *);
 static void    alpha_ipi_pause(struct cpu_info *, struct trapframe *);
 static void    alpha_ipi_xcall(struct cpu_info *, struct trapframe *);
@@ -69,7 +69,7 @@
 
 const ipifunc_t ipifuncs[ALPHA_NIPIS] = {
        [ilog2(ALPHA_IPI_HALT)] =       alpha_ipi_halt,
-       [ilog2(ALPHA_IPI_MICROSET)] =   alpha_ipi_microset,
+       [ilog2(ALPHA_IPI_PRIMARY_CC)] = alpha_ipi_primary_cc,
        [ilog2(ALPHA_IPI_SHOOTDOWN)] =  pmap_tlb_shootdown_ipi,
        [ilog2(ALPHA_IPI_AST)] =        alpha_ipi_ast,
        [ilog2(ALPHA_IPI_PAUSE)] =      alpha_ipi_pause,
@@ -79,7 +79,7 @@
 
 const char * const ipinames[ALPHA_NIPIS] = {
        [ilog2(ALPHA_IPI_HALT)] =       "halt ipi",
-       [ilog2(ALPHA_IPI_MICROSET)] =   "microset ipi",
+       [ilog2(ALPHA_IPI_PRIMARY_CC)] = "primary cc ipi",
        [ilog2(ALPHA_IPI_SHOOTDOWN)] =  "shootdown ipi",
        [ilog2(ALPHA_IPI_AST)] =        "ast ipi",
        [ilog2(ALPHA_IPI_PAUSE)] =      "pause ipi",
@@ -250,11 +250,12 @@
 }
 
 static void
-alpha_ipi_microset(struct cpu_info * const ci,
+alpha_ipi_primary_cc(struct cpu_info * const ci __unused,
     struct trapframe * const framep __unused)
 {
-
-       cc_calibrate_cpu(ci);
+       int const s = splhigh();
+       cc_primary_cc();
+       splx(s);
 }
 
 static void
diff -r 71c9927ca707 -r 9bb9b92027dc sys/arch/alpha/include/alpha.h
--- a/sys/arch/alpha/include/alpha.h    Sat Oct 10 00:10:06 2020 +0000
+++ b/sys/arch/alpha/include/alpha.h    Sat Oct 10 03:05:04 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: alpha.h,v 1.42 2020/10/03 17:31:46 thorpej Exp $ */
+/* $NetBSD: alpha.h,v 1.43 2020/10/10 03:05:04 thorpej Exp $ */
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -68,6 +68,7 @@
 struct trapframe;
 
 extern bool alpha_is_qemu;
+extern int alpha_use_cctr;
 extern u_long cpu_implver;             /* from IMPLVER instruction */
 extern u_long cpu_amask;               /* from AMASK instruction */
 extern int bootdev_debug;
diff -r 71c9927ca707 -r 9bb9b92027dc sys/arch/alpha/include/cpu_counter.h
--- a/sys/arch/alpha/include/cpu_counter.h      Sat Oct 10 00:10:06 2020 +0000
+++ b/sys/arch/alpha/include/cpu_counter.h      Sat Oct 10 03:05:04 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu_counter.h,v 1.6 2008/04/28 20:23:11 martin Exp $ */
+/* $NetBSD: cpu_counter.h,v 1.7 2020/10/10 03:05:04 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -41,8 +41,8 @@
 #include <machine/cpu.h>
 #include <machine/rpb.h>
 
-#define cc_calibrate_mp(ci)    \
-       alpha_multicast_ipi(cpus_running, ALPHA_IPI_MICROSET)
+#define        cc_get_primary_cc()     \
+       alpha_send_ipi(hwrpb->rpb_primary_cpu_id, ALPHA_IPI_PRIMARY_CC)
 
 /* Process Cycle Counter is always available. */
 #define cpu_hascounter()       (1)
diff -r 71c9927ca707 -r 9bb9b92027dc sys/arch/alpha/include/intr.h
--- a/sys/arch/alpha/include/intr.h     Sat Oct 10 00:10:06 2020 +0000
+++ b/sys/arch/alpha/include/intr.h     Sat Oct 10 03:05:04 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: intr.h,v 1.82 2020/09/26 21:07:48 thorpej Exp $ */
+/* $NetBSD: intr.h,v 1.83 2020/10/10 03:05:04 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2000, 2001, 2002 The NetBSD Foundation, Inc.
@@ -173,7 +173,7 @@
  * Interprocessor interrupts.  In order how we want them processed.
  */
 #define        ALPHA_IPI_HALT                  (1UL << 0)
-#define        ALPHA_IPI_MICROSET              (1UL << 1)
+#define        ALPHA_IPI_PRIMARY_CC            (1UL << 1)
 #define        ALPHA_IPI_SHOOTDOWN             (1UL << 2)
 #define        ALPHA_IPI_AST                   (1UL << 3)
 #define        ALPHA_IPI_PAUSE                 (1UL << 4)
diff -r 71c9927ca707 -r 9bb9b92027dc sys/kern/kern_cctr.c
--- a/sys/kern/kern_cctr.c      Sat Oct 10 00:10:06 2020 +0000
+++ b/sys/kern/kern_cctr.c      Sat Oct 10 03:05:04 2020 +0000
@@ -1,54 +1,8 @@
-/*     $NetBSD: kern_cctr.c,v 1.10 2019/06/24 06:24:33 skrll Exp $     */
+/*     $NetBSD: kern_cctr.c,v 1.11 2020/10/10 03:05:04 thorpej Exp $   */
 
 /*-
- * Copyright (c) 2006, 2008 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * re-implementation of TSC for MP systems merging cc_microtime and
- * TSC for timecounters by Frank Kardel
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-/* basic calibration ideas are (kern_microtime.c): */
-/******************************************************************************
- *                                                                            *
- * Copyright (c) David L. Mills 1993, 1994                                    *
- *                                                                            *
- * Permission to use, copy, modify, and distribute this software and its      *
- * documentation for any purpose and without fee is hereby granted, provided  *
- * that the above copyright notice appears in all copies and that both the    *
- * copyright notice and this permission notice appear in supporting           *
- * documentation, and that the name University of Delaware not be used in     *
- * advertising or publicity pertaining to distribution of the software        *
- * without specific, written prior permission.  The University of Delaware    *
- * makes no representations about the suitability this software for any       *
- * purpose.  It is provided "as is" without express or implied warranty.      *
- *                                                                            *
- ******************************************************************************/
-
-/* reminiscents from older version of this file are: */
-/*-
- * Copyright (c) 1998-2003 Poul-Henning Kamp
+ * Copyright (c) 2020 Jason R. Thorpe
+ * Copyright (c) 2018 Naruaki Etomi
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -60,26 +14,60 @@
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
  *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*



Home | Main Index | Thread Index | Old Index