Source-Changes-HG archive

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

[src/trunk]: src/sys/arch Make cpu_counter(), cpu_counter32() and tsc_get_tim...



details:   https://anonhg.NetBSD.org/src/rev/b2bac3c9caa2
branches:  trunk
changeset: 1010246:b2bac3c9caa2
user:      ad <ad%NetBSD.org@localhost>
date:      Tue May 19 21:40:55 2020 +0000

description:
Make cpu_counter(), cpu_counter32() and tsc_get_timecount() into a single
preemption-safe routine.

diffstat:

 sys/arch/amd64/amd64/cpufunc.S |  28 ++++++++--------------------
 sys/arch/i386/i386/cpufunc.S   |  26 ++++++++++++++++----------
 sys/arch/i386/i386/i386func.S  |  18 ++----------------
 3 files changed, 26 insertions(+), 46 deletions(-)

diffs (148 lines):

diff -r 217334a4c30d -r b2bac3c9caa2 sys/arch/amd64/amd64/cpufunc.S
--- a/sys/arch/amd64/amd64/cpufunc.S    Tue May 19 21:39:11 2020 +0000
+++ b/sys/arch/amd64/amd64/cpufunc.S    Tue May 19 21:40:55 2020 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: cpufunc.S,v 1.52 2020/05/08 21:58:03 ad Exp $  */
+/*     $NetBSD: cpufunc.S,v 1.53 2020/05/19 21:40:55 ad Exp $  */
 
 /*
- * Copyright (c) 1998, 2007, 2008 The NetBSD Foundation, Inc.
+ * Copyright (c) 1998, 2007, 2008, 2020 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -172,7 +172,9 @@
 1:
        movq    L_NCSW(%rcx), %rdi
        rdtsc
-       addl    CPUVAR(CC_SKEW), %eax
+       shlq    $32, %rdx
+       orq     %rdx, %rax
+       addq    CPUVAR(CC_SKEW), %rax
        cmpq    %rdi, L_NCSW(%rcx)
        jne     2f
        KMSAN_INIT_RET(4)
@@ -181,6 +183,9 @@
        jmp     1b
 END(tsc_get_timecount)
 
+STRONG_ALIAS(cpu_counter, tsc_get_timecount)
+STRONG_ALIAS(cpu_counter32, tsc_get_timecount)
+
 /*
  * %rdi = name
  * %rsi = sel
@@ -252,23 +257,6 @@
        ret
 END(msr_onfault)
 
-ENTRY(cpu_counter)
-       xorl    %eax, %eax
-       rdtsc
-       shlq    $32, %rdx
-       orq     %rdx, %rax
-       addq    CPUVAR(CC_SKEW), %rax
-       KMSAN_INIT_RET(8)
-       ret
-END(cpu_counter)
-
-ENTRY(cpu_counter32)
-       rdtsc
-       addl    CPUVAR(CC_SKEW), %eax
-       KMSAN_INIT_RET(4)
-       ret
-END(cpu_counter32)
-
 ENTRY(breakpoint)
        pushq   %rbp
        movq    %rsp, %rbp
diff -r 217334a4c30d -r b2bac3c9caa2 sys/arch/i386/i386/cpufunc.S
--- a/sys/arch/i386/i386/cpufunc.S      Tue May 19 21:39:11 2020 +0000
+++ b/sys/arch/i386/i386/cpufunc.S      Tue May 19 21:40:55 2020 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: cpufunc.S,v 1.40 2020/05/02 17:14:01 bouyer Exp $      */
+/*     $NetBSD: cpufunc.S,v 1.41 2020/05/19 21:40:55 ad Exp $  */
 
 /*-
- * Copyright (c) 1998, 2007 The NetBSD Foundation, Inc.
+ * Copyright (c) 1998, 2007, 2020 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -38,7 +38,7 @@
 #include <sys/errno.h>
 
 #include <machine/asm.h>
-__KERNEL_RCSID(0, "$NetBSD: cpufunc.S,v 1.40 2020/05/02 17:14:01 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpufunc.S,v 1.41 2020/05/19 21:40:55 ad Exp $");
 
 #include "opt_xen.h"
 
@@ -163,18 +163,24 @@
        ret
 END(msr_onfault)
 
-ENTRY(cpu_counter)
+ENTRY(tsc_get_timecount)
+       movl    CPUVAR(CURLWP), %ecx
+1:
+       pushl   L_NCSW(%ecx)
        rdtsc
        addl    CPUVAR(CC_SKEW), %eax
        adcl    CPUVAR(CC_SKEW+4), %edx
+       popl    %edx
+       cmpl    %edx, L_NCSW(%ecx)
+       jne     2f
        ret
-END(cpu_counter)
+2:
+       jmp     1b
+       ret
+END(tsc_get_timecount)
 
-ENTRY(cpu_counter32)
-       rdtsc
-       addl    CPUVAR(CC_SKEW), %eax
-       ret
-END(cpu_counter32)
+STRONG_ALIAS(cpu_counter, tsc_get_timecount)
+STRONG_ALIAS(cpu_counter32, tsc_get_timecount)
 
 ENTRY(breakpoint)
        pushl   %ebp
diff -r 217334a4c30d -r b2bac3c9caa2 sys/arch/i386/i386/i386func.S
--- a/sys/arch/i386/i386/i386func.S     Tue May 19 21:39:11 2020 +0000
+++ b/sys/arch/i386/i386/i386func.S     Tue May 19 21:40:55 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: i386func.S,v 1.21 2019/05/04 07:20:22 maxv Exp $       */
+/*     $NetBSD: i386func.S,v 1.22 2020/05/19 21:40:55 ad Exp $ */
 
 /*-
  * Copyright (c) 1998, 2007, 2008 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include <machine/asm.h>
-__KERNEL_RCSID(0, "$NetBSD: i386func.S,v 1.21 2019/05/04 07:20:22 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i386func.S,v 1.22 2020/05/19 21:40:55 ad Exp $");
 
 #include <machine/specialreg.h>
 #include <machine/segments.h>
@@ -137,17 +137,3 @@
        movl    %eax, %fs
        jmp     _C_LABEL(x86_flush)
 END(lgdt)
-
-ENTRY(tsc_get_timecount)
-       movl    CPUVAR(CURLWP), %ecx
-1:
-       pushl   L_NCSW(%ecx)
-       rdtsc
-       addl    CPUVAR(CC_SKEW), %eax
-       popl    %edx
-       cmpl    %edx, L_NCSW(%ecx)
-       jne     2f
-       ret
-2:
-       jmp     1b
-END(tsc_get_timecount)



Home | Main Index | Thread Index | Old Index