Module Name:    src
Committed By:   ad
Date:           Tue May 19 21:40:55 UTC 2020

Modified Files:
        src/sys/arch/amd64/amd64: cpufunc.S
        src/sys/arch/i386/i386: cpufunc.S i386func.S

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


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/sys/arch/amd64/amd64/cpufunc.S
cvs rdiff -u -r1.40 -r1.41 src/sys/arch/i386/i386/cpufunc.S
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/i386/i386/i386func.S

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/amd64/amd64/cpufunc.S
diff -u src/sys/arch/amd64/amd64/cpufunc.S:1.52 src/sys/arch/amd64/amd64/cpufunc.S:1.53
--- src/sys/arch/amd64/amd64/cpufunc.S:1.52	Fri May  8 21:58:03 2020
+++ src/sys/arch/amd64/amd64/cpufunc.S	Tue May 19 21:40:55 2020
@@ -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 @@ ENTRY(tsc_get_timecount)
 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 @@ ENTRY(tsc_get_timecount)
 	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 @@ ENTRY(msr_onfault)
 	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

Index: src/sys/arch/i386/i386/cpufunc.S
diff -u src/sys/arch/i386/i386/cpufunc.S:1.40 src/sys/arch/i386/i386/cpufunc.S:1.41
--- src/sys/arch/i386/i386/cpufunc.S:1.40	Sat May  2 17:14:01 2020
+++ src/sys/arch/i386/i386/cpufunc.S	Tue May 19 21:40:55 2020
@@ -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 @@ ENTRY(msr_onfault)
 	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)
-
-ENTRY(cpu_counter32)
-	rdtsc
-	addl	CPUVAR(CC_SKEW), %eax
+2:
+	jmp	1b
 	ret
-END(cpu_counter32)
+END(tsc_get_timecount)
+
+STRONG_ALIAS(cpu_counter, tsc_get_timecount)
+STRONG_ALIAS(cpu_counter32, tsc_get_timecount)
 
 ENTRY(breakpoint)
 	pushl	%ebp

Index: src/sys/arch/i386/i386/i386func.S
diff -u src/sys/arch/i386/i386/i386func.S:1.21 src/sys/arch/i386/i386/i386func.S:1.22
--- src/sys/arch/i386/i386/i386func.S:1.21	Sat May  4 07:20:22 2019
+++ src/sys/arch/i386/i386/i386func.S	Tue May 19 21:40:55 2020
@@ -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 @@ ENTRY(lgdt)
 	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)

Reply via email to