Source-Changes-HG archive

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

[src/ad-namecache]: src/sys/sys Back out previous.



details:   https://anonhg.NetBSD.org/src/rev/5a4f104cd914
branches:  ad-namecache
changeset: 983000:5a4f104cd914
user:      ad <ad%NetBSD.org@localhost>
date:      Wed Jan 22 11:40:16 2020 +0000

description:
Back out previous.

diffstat:

 sys/arch/amd64/amd64/genassym.cf  |   12 +-
 sys/arch/amd64/amd64/lock_stubs.S |  122 +++++++++++-
 sys/arch/amd64/include/rwlock.h   |    3 +
 sys/arch/i386/i386/genassym.cf    |   12 +-
 sys/arch/i386/i386/lock_stubs.S   |  130 +++++++++++-
 sys/arch/x86/include/rwlock.h     |   37 +++
 sys/kern/kern_rwlock.c            |  413 +++++++++----------------------------
 sys/sys/lwp.h                     |    3 +-
 sys/sys/rwlock.h                  |   11 +-
 9 files changed, 424 insertions(+), 319 deletions(-)

diffs (truncated from 1102 to 300 lines):

diff -r 7cfce7703fb3 -r 5a4f104cd914 sys/arch/amd64/amd64/genassym.cf
--- a/sys/arch/amd64/amd64/genassym.cf  Sun Jan 19 21:24:01 2020 +0000
+++ b/sys/arch/amd64/amd64/genassym.cf  Wed Jan 22 11:40:16 2020 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: genassym.cf,v 1.80.2.2 2020/01/19 21:08:29 ad Exp $
+#      $NetBSD: genassym.cf,v 1.80.2.3 2020/01/22 11:40:16 ad Exp $
 
 #
 # Copyright (c) 1998, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -78,6 +78,7 @@
 include <sys/device.h>
 include <sys/mbuf.h>
 include <sys/mutex.h>
+include <sys/rwlock.h>
 include <sys/cpu_data.h>
 include <sys/evcnt.h>
 include <sys/cpu.h>
@@ -345,6 +346,15 @@
 define MTX_LOCK                offsetof(struct kmutex, u.s.mtxs_lock)
 define MTX_OWNER               offsetof(struct kmutex, u.mtxa_owner)
 
+define RW_OWNER                offsetof(struct krwlock, rw_owner)
+define RW_WRITE_LOCKED         RW_WRITE_LOCKED
+define RW_WRITE_WANTED         RW_WRITE_WANTED
+define RW_READ_INCR            RW_READ_INCR
+define RW_HAS_WAITERS          RW_HAS_WAITERS
+define RW_THREAD               RW_THREAD
+define RW_READER               RW_READER
+define RW_WRITER               RW_WRITER
+
 define EV_COUNT                offsetof(struct evcnt, ev_count)
 
 define OPTERON_MSR_PASSCODE    OPTERON_MSR_PASSCODE
diff -r 7cfce7703fb3 -r 5a4f104cd914 sys/arch/amd64/amd64/lock_stubs.S
--- a/sys/arch/amd64/amd64/lock_stubs.S Sun Jan 19 21:24:01 2020 +0000
+++ b/sys/arch/amd64/amd64/lock_stubs.S Wed Jan 22 11:40:16 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lock_stubs.S,v 1.35.2.1 2020/01/19 21:08:29 ad Exp $   */
+/*     $NetBSD: lock_stubs.S,v 1.35.2.2 2020/01/22 11:40:16 ad Exp $   */
 
 /*
  * Copyright (c) 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -185,6 +185,126 @@
 
 END(mutex_spin_exit)
 
+/*
+ * void        rw_enter(krwlock_t *rwl, krw_t op);
+ *
+ * Acquire one hold on a RW lock.
+ */
+ENTRY(rw_enter)
+       cmpl    $RW_READER, %esi
+       jne     2f
+
+       /*
+        * Reader: this is the most common case.
+        */
+       movq    (%rdi), %rax
+0:
+       testb   $(RW_WRITE_LOCKED|RW_WRITE_WANTED), %al
+       jnz     3f
+       leaq    RW_READ_INCR(%rax), %rdx
+       LOCK
+       cmpxchgq %rdx, (%rdi)
+       jnz     1f
+       RET
+1:
+       jmp     0b
+
+       /*
+        * Writer: if the compare-and-set fails, don't bother retrying.
+        */
+2:     movq    CPUVAR(CURLWP), %rcx
+       xorq    %rax, %rax
+       orq     $RW_WRITE_LOCKED, %rcx
+       LOCK
+       cmpxchgq %rcx, (%rdi)
+       jnz     3f
+       RET
+3:
+       jmp     _C_LABEL(rw_vector_enter)
+END(rw_enter)
+
+/*
+ * void        rw_exit(krwlock_t *rwl);
+ *
+ * Release one hold on a RW lock.
+ */
+ENTRY(rw_exit)
+       movq    (%rdi), %rax
+       testb   $RW_WRITE_LOCKED, %al
+       jnz     2f
+
+       /*
+        * Reader
+        */
+0:     testb   $RW_HAS_WAITERS, %al
+       jnz     3f
+       cmpq    $RW_READ_INCR, %rax
+       jb      3f
+       leaq    -RW_READ_INCR(%rax), %rdx
+       LOCK
+       cmpxchgq %rdx, (%rdi)
+       jnz     1f
+       ret
+1:
+       jmp     0b
+
+       /*
+        * Writer
+        */
+2:     leaq    -RW_WRITE_LOCKED(%rax), %rdx
+       subq    CPUVAR(CURLWP), %rdx
+       jnz     3f
+       LOCK
+       cmpxchgq %rdx, (%rdi)
+       jnz     3f
+       ret
+
+3:     jmp     _C_LABEL(rw_vector_exit)
+END(rw_exit)
+
+/*
+ * int rw_tryenter(krwlock_t *rwl, krw_t op);
+ *
+ * Try to acquire one hold on a RW lock.
+ */
+ENTRY(rw_tryenter)
+       cmpl    $RW_READER, %esi
+       jne     2f
+
+       /*
+        * Reader: this is the most common case.
+        */
+       movq    (%rdi), %rax
+0:
+       testb   $(RW_WRITE_LOCKED|RW_WRITE_WANTED), %al
+       jnz     4f
+       leaq    RW_READ_INCR(%rax), %rdx
+       LOCK
+       cmpxchgq %rdx, (%rdi)
+       jnz     1f
+       movl    %edx, %eax                      /* nonzero */
+       RET
+1:
+       jmp     0b
+
+       /*
+        * Writer: if the compare-and-set fails, don't bother retrying.
+        */
+2:     movq    CPUVAR(CURLWP), %rcx
+       xorq    %rax, %rax
+       orq     $RW_WRITE_LOCKED, %rcx
+       LOCK
+       cmpxchgq %rcx, (%rdi)
+       movl    $0, %eax
+       setz    %al
+3:
+       RET
+       ret
+4:
+       xorl    %eax, %eax
+       jmp     3b
+END(rw_tryenter)
+
 #endif /* LOCKDEBUG */
 
 /*
diff -r 7cfce7703fb3 -r 5a4f104cd914 sys/arch/amd64/include/rwlock.h
--- a/sys/arch/amd64/include/rwlock.h   Sun Jan 19 21:24:01 2020 +0000
+++ b/sys/arch/amd64/include/rwlock.h   Wed Jan 22 11:40:16 2020 +0000
@@ -0,0 +1,3 @@
+/*     $NetBSD: rwlock.h,v 1.2.144.2 2020/01/22 11:40:16 ad Exp $      */
+
+#include <x86/rwlock.h>
diff -r 7cfce7703fb3 -r 5a4f104cd914 sys/arch/i386/i386/genassym.cf
--- a/sys/arch/i386/i386/genassym.cf    Sun Jan 19 21:24:01 2020 +0000
+++ b/sys/arch/i386/i386/genassym.cf    Wed Jan 22 11:40:16 2020 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: genassym.cf,v 1.117.2.2 2020/01/19 21:08:29 ad Exp $
+#      $NetBSD: genassym.cf,v 1.117.2.3 2020/01/22 11:40:16 ad Exp $
 
 #
 # Copyright (c) 1998, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -79,6 +79,7 @@
 include <sys/device.h>
 include <sys/mbuf.h>
 include <sys/mutex.h>
+include <sys/rwlock.h>
 include <sys/cpu.h>
 
 include <netinet/in.h>
@@ -353,6 +354,15 @@
 define MTX_LOCK                offsetof(struct kmutex, mtx_lock)
 define MTX_OWNER               offsetof(struct kmutex, u.mtxa_owner)
 
+define RW_OWNER                offsetof(struct krwlock, rw_owner)
+define RW_WRITE_LOCKED         RW_WRITE_LOCKED
+define RW_WRITE_WANTED         RW_WRITE_WANTED
+define RW_READ_INCR            RW_READ_INCR
+define RW_HAS_WAITERS          RW_HAS_WAITERS
+define RW_THREAD               RW_THREAD
+define RW_READER               RW_READER
+define RW_WRITER               RW_WRITER
+
 define EV_COUNT                offsetof(struct evcnt, ev_count)
 
 define OPTERON_MSR_PASSCODE    OPTERON_MSR_PASSCODE
diff -r 7cfce7703fb3 -r 5a4f104cd914 sys/arch/i386/i386/lock_stubs.S
--- a/sys/arch/i386/i386/lock_stubs.S   Sun Jan 19 21:24:01 2020 +0000
+++ b/sys/arch/i386/i386/lock_stubs.S   Wed Jan 22 11:40:16 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lock_stubs.S,v 1.32.2.1 2020/01/19 21:08:29 ad Exp $   */
+/*     $NetBSD: lock_stubs.S,v 1.32.2.2 2020/01/22 11:40:16 ad Exp $   */
 
 /*-
  * Copyright (c) 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <machine/asm.h>
-__KERNEL_RCSID(0, "$NetBSD: lock_stubs.S,v 1.32.2.1 2020/01/19 21:08:29 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lock_stubs.S,v 1.32.2.2 2020/01/22 11:40:16 ad Exp $");
 
 #include "opt_lockdebug.h"
 
@@ -97,6 +97,132 @@
        jmp     _C_LABEL(mutex_vector_exit)
 END(mutex_exit)
 
+/*
+ * void rw_enter(krwlock_t *rwl, krw_t op);
+ *
+ * Acquire one hold on a RW lock.
+ */
+ENTRY(rw_enter)
+       movl    4(%esp), %edx
+       cmpl    $RW_READER, 8(%esp)
+       jne     2f
+
+       /*
+        * Reader
+        */
+       movl    (%edx), %eax
+0:
+       testb   $(RW_WRITE_LOCKED|RW_WRITE_WANTED), %al
+       jnz     3f
+       leal    RW_READ_INCR(%eax), %ecx
+       LOCK(2)
+       cmpxchgl %ecx, (%edx)
+       jnz     1f
+       RET(2)
+1:
+       jmp     0b
+
+       /*
+        * Writer
+        */
+2:     xorl    %eax, %eax
+       movl    %fs:CPU_INFO_CURLWP(%eax), %ecx
+       orl     $RW_WRITE_LOCKED, %ecx
+       LOCK(3)
+       cmpxchgl %ecx, (%edx)
+       jnz     3f
+       RET(3)
+3:
+       jmp     _C_LABEL(rw_vector_enter)
+END(rw_enter)
+
+/*
+ * void rw_exit(krwlock_t *rwl);
+ *
+ * Release one hold on a RW lock.
+ */
+ENTRY(rw_exit)
+       movl    4(%esp), %edx
+       movl    (%edx), %eax
+       testb   $RW_WRITE_LOCKED, %al
+       jnz     2f
+
+       /*
+        * Reader
+        */
+0:     testb   $RW_HAS_WAITERS, %al
+       jnz     3f
+       cmpl    $RW_READ_INCR, %eax
+       jb      3f
+       leal    -RW_READ_INCR(%eax), %ecx
+       LOCK(4)
+       cmpxchgl %ecx, (%edx)
+       jnz     1f
+       ret
+1:
+       jmp     0b
+
+       /*
+        * Writer
+        */
+2:     leal    -RW_WRITE_LOCKED(%eax), %ecx



Home | Main Index | Thread Index | Old Index