Source-Changes-HG archive

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

[src/trunk]: src/sys Hide 'hardclock_ticks' behind a new getticks() function,...



details:   https://anonhg.NetBSD.org/src/rev/827f6b66008f
branches:  trunk
changeset: 1008769:827f6b66008f
user:      maxv <maxv%NetBSD.org@localhost>
date:      Thu Apr 02 16:29:30 2020 +0000

description:
Hide 'hardclock_ticks' behind a new getticks() function, and use relaxed
atomics internally. Only one caller is converted for now.

Discussed with riastradh@ and ad@.

diffstat:

 sys/kern/kern_clock.c        |  15 +++++++++++----
 sys/sys/kernel.h             |   8 ++++++--
 sys/uvm/uvm_pdpolicy_clock.c |  10 +++++-----
 3 files changed, 22 insertions(+), 11 deletions(-)

diffs (117 lines):

diff -r 273924f8d430 -r 827f6b66008f sys/kern/kern_clock.c
--- a/sys/kern/kern_clock.c     Thu Apr 02 16:18:51 2020 +0000
+++ b/sys/kern/kern_clock.c     Thu Apr 02 16:29:30 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_clock.c,v 1.139 2019/12/01 15:34:46 ad Exp $      */
+/*     $NetBSD: kern_clock.c,v 1.140 2020/04/02 16:29:30 maxv Exp $    */
 
 /*-
  * Copyright (c) 2000, 2004, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -69,7 +69,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_clock.c,v 1.139 2019/12/01 15:34:46 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_clock.c,v 1.140 2020/04/02 16:29:30 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_dtrace.h"
@@ -155,7 +155,13 @@
 get_intr_timecount(struct timecounter *tc)
 {
 
-       return (u_int)hardclock_ticks;
+       return (u_int)getticks();
+}
+
+int
+getticks(void)
+{
+       return atomic_load_relaxed(&hardclock_ticks);
 }
 
 /*
@@ -242,7 +248,8 @@
                sched_tick(ci);
 
        if (CPU_IS_PRIMARY(ci)) {
-               hardclock_ticks++;
+               atomic_store_relaxed(&hardclock_ticks,
+                   atomic_load_relaxed(&hardclock_ticks) + 1);
                tc_ticktock();
        }
 
diff -r 273924f8d430 -r 827f6b66008f sys/sys/kernel.h
--- a/sys/sys/kernel.h  Thu Apr 02 16:18:51 2020 +0000
+++ b/sys/sys/kernel.h  Thu Apr 02 16:29:30 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kernel.h,v 1.32 2020/01/02 15:42:27 thorpej Exp $      */
+/*     $NetBSD: kernel.h,v 1.33 2020/04/02 16:29:30 maxv Exp $ */
 
 /*-
  * Copyright (c) 1990, 1993
@@ -56,7 +56,7 @@
 extern int shutting_down;      /* system is shutting down */
 extern int tick;               /* usec per tick (1000000 / hz) */
 extern int tickadj;            /* "standard" clock skew, us./tick */
-extern int hardclock_ticks;    /* # of hardclock ticks */
+extern int hardclock_ticks;    /* # of hardclock ticks; XXX use getticks()! */
 extern int hz;                 /* system clock's frequency */
 extern int stathz;             /* statistics clock's frequency */
 extern int profhz;             /* profiling clock's frequency */
@@ -64,6 +64,10 @@
 extern int profsrc;            /* profiling source */
 extern int psratio;            /* ratio: prof / stat */
 
+/* Accessors. */
+
+int getticks(void);
+
 #define PROFSRC_CLOCK  0
 
 #endif
diff -r 273924f8d430 -r 827f6b66008f sys/uvm/uvm_pdpolicy_clock.c
--- a/sys/uvm/uvm_pdpolicy_clock.c      Thu Apr 02 16:18:51 2020 +0000
+++ b/sys/uvm/uvm_pdpolicy_clock.c      Thu Apr 02 16:29:30 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm_pdpolicy_clock.c,v 1.35 2020/03/14 13:53:26 ad Exp $       */
+/*     $NetBSD: uvm_pdpolicy_clock.c,v 1.36 2020/04/02 16:29:30 maxv Exp $     */
 /*     NetBSD: uvm_pdaemon.c,v 1.72 2006/01/05 10:47:33 yamt Exp $     */
 
 /*-
@@ -98,7 +98,7 @@
 #else /* defined(PDSIM) */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_pdpolicy_clock.c,v 1.35 2020/03/14 13:53:26 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_pdpolicy_clock.c,v 1.36 2020/04/02 16:29:30 maxv Exp $");
 
 #include <sys/param.h>
 #include <sys/proc.h>
@@ -771,7 +771,7 @@
         * if no pages in the queue, we have nothing to do.
         */
        if (ucpu->pdqhead == ucpu->pdqtail) {
-               ucpu->pdqtime = hardclock_ticks;
+               ucpu->pdqtime = getticks();
                return;
        }
 
@@ -779,7 +779,7 @@
         * don't do this more than ~8 times a second as it would needlessly
         * exert pressure.
         */
-       if (hardclock_ticks - ucpu->pdqtime < (hz >> 3)) {
+       if (getticks() - ucpu->pdqtime < (hz >> 3)) {
                return;
        }
 
@@ -803,7 +803,7 @@
                        }
                }
                if (ucpu->pdqhead == ucpu->pdqtail) {
-                       ucpu->pdqtime = hardclock_ticks;
+                       ucpu->pdqtime = getticks();
                }
                mutex_exit(&s->lock);
        }



Home | Main Index | Thread Index | Old Index