Source-Changes-HG archive

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

[src/trunk]: src/sys/external/bsd Move Linux RCU to common.



details:   https://anonhg.NetBSD.org/src/rev/d48fa57caec3
branches:  trunk
changeset: 1027994:d48fa57caec3
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sun Dec 19 01:33:17 2021 +0000

description:
Move Linux RCU to common.

diffstat:

 sys/external/bsd/common/conf/files.linux         |    3 +-
 sys/external/bsd/common/include/linux/rcupdate.h |  112 +++++++++
 sys/external/bsd/common/linux/linux_rcu.c        |  281 +++++++++++++++++++++++
 sys/external/bsd/drm2/include/linux/rcupdate.h   |  112 ---------
 sys/external/bsd/drm2/linux/files.drmkms_linux   |    3 +-
 sys/external/bsd/drm2/linux/linux_rcu.c          |  281 -----------------------
 6 files changed, 396 insertions(+), 396 deletions(-)

diffs (truncated from 833 to 300 lines):

diff -r 3d111cc0fb54 -r d48fa57caec3 sys/external/bsd/common/conf/files.linux
--- a/sys/external/bsd/common/conf/files.linux  Sun Dec 19 01:26:12 2021 +0000
+++ b/sys/external/bsd/common/conf/files.linux  Sun Dec 19 01:33:17 2021 +0000
@@ -1,8 +1,9 @@
-#       $NetBSD: files.linux,v 1.2 2021/12/19 01:17:14 riastradh Exp $
+#       $NetBSD: files.linux,v 1.3 2021/12/19 01:33:17 riastradh Exp $
 
 define linux
 
 makeoptions    linux   CPPFLAGS+="-I$S/external/bsd/common/include"
 
+file   external/bsd/common/linux/linux_rcu.c           linux
 file   external/bsd/common/linux/linux_tasklet.c       linux
 file   external/bsd/common/linux/linux_work.c          linux
diff -r 3d111cc0fb54 -r d48fa57caec3 sys/external/bsd/common/include/linux/rcupdate.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/external/bsd/common/include/linux/rcupdate.h  Sun Dec 19 01:33:17 2021 +0000
@@ -0,0 +1,112 @@
+/*     $NetBSD: rcupdate.h,v 1.1 2021/12/19 01:33:17 riastradh Exp $   */
+
+/*-
+ * Copyright (c) 2018 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Taylor R. Campbell.
+ *
+ * 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.
+ */
+
+#ifndef _LINUX_RCUPDATE_H_
+#define _LINUX_RCUPDATE_H_
+
+#include <sys/atomic.h>
+#include <sys/cdefs.h>
+#include <sys/systm.h>
+
+#define        __rcu
+
+#define        RCU_INIT_POINTER(P, V)  ((P) = (V))
+
+#define        rcu_assign_pointer(P, V) do {                                         \
+       __typeof__(*(P)) *__rcu_assign_pointer_tmp = (V);                     \
+       membar_exit();                                                        \
+       (P) = __rcu_assign_pointer_tmp;                                       \
+} while (0)
+
+#define        rcu_dereference(P) ({                                                 \
+       __typeof__(*(P)) *__rcu_dereference_tmp = (P);                        \
+       membar_datadep_consumer();                                            \
+       __rcu_dereference_tmp;                                                \
+})
+
+#define        rcu_dereference_raw     rcu_dereference
+
+#define        rcu_dereference_protected(P, C) ({                                    \
+       WARN_ON(!(C));                                                        \
+       (P);                                                                  \
+})
+
+#define        rcu_access_pointer(P) ({                                              \
+       __typeof__(*(P)) *__rcu_access_pointer_tmp = (P);                     \
+       __insn_barrier();                                                     \
+       __rcu_access_pointer_tmp;                                             \
+})
+
+/* kill_dependency */
+#define        rcu_pointer_handoff(P)  (P)
+
+struct rcu_head {
+       union {
+               void            (*callback)(struct rcu_head *);
+               void            *obj;
+       }               rcuh_u;
+       struct rcu_head *rcuh_next;
+};
+
+#define        _kfree_rcu              linux__kfree_rcu
+#define        call_rcu                linux_call_rcu
+#define        rcu_barrier             linux_rcu_barrier
+#define        synchronize_rcu         linux_synchronize_rcu
+
+int    linux_rcu_gc_init(void);
+void   linux_rcu_gc_fini(void);
+
+void   call_rcu(struct rcu_head *, void (*)(struct rcu_head *));
+void   rcu_barrier(void);
+void   synchronize_rcu(void);
+
+void   _kfree_rcu(struct rcu_head *, void *);
+
+static inline void
+rcu_read_lock(void)
+{
+
+       kpreempt_disable();
+       __insn_barrier();
+}
+
+static inline void
+rcu_read_unlock(void)
+{
+
+       __insn_barrier();
+       kpreempt_enable();
+}
+
+#define        kfree_rcu(P, F)                                                       \
+       _kfree_rcu(&(P)->F, (P))
+
+#endif  /* _LINUX_RCUPDATE_H_ */
diff -r 3d111cc0fb54 -r d48fa57caec3 sys/external/bsd/common/linux/linux_rcu.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/external/bsd/common/linux/linux_rcu.c Sun Dec 19 01:33:17 2021 +0000
@@ -0,0 +1,281 @@
+/*     $NetBSD: linux_rcu.c,v 1.1 2021/12/19 01:33:17 riastradh Exp $  */
+
+/*-
+ * Copyright (c) 2018 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Taylor R. Campbell.
+ *
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: linux_rcu.c,v 1.1 2021/12/19 01:33:17 riastradh Exp $");
+
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/condvar.h>
+#include <sys/cpu.h>
+#include <sys/kthread.h>
+#include <sys/mutex.h>
+#include <sys/sdt.h>
+#include <sys/xcall.h>
+
+#include <linux/rcupdate.h>
+#include <linux/slab.h>
+
+SDT_PROBE_DEFINE0(sdt, linux, rcu, synchronize__start);
+SDT_PROBE_DEFINE1(sdt, linux, rcu, synchronize__cpu, "unsigned"/*cpu*/);
+SDT_PROBE_DEFINE0(sdt, linux, rcu, synchronize__done);
+SDT_PROBE_DEFINE0(sdt, linux, rcu, barrier__start);
+SDT_PROBE_DEFINE0(sdt, linux, rcu, barrier__done);
+SDT_PROBE_DEFINE2(sdt, linux, rcu, call__queue,
+    "struct rcu_head *"/*head*/, "void (*)(struct rcu_head *)"/*callback*/);
+SDT_PROBE_DEFINE2(sdt, linux, rcu, call__run,
+    "struct rcu_head *"/*head*/, "void (*)(struct rcu_head *)"/*callback*/);
+SDT_PROBE_DEFINE2(sdt, linux, rcu, call__done,
+    "struct rcu_head *"/*head*/, "void (*)(struct rcu_head *)"/*callback*/);
+SDT_PROBE_DEFINE2(sdt, linux, rcu, kfree__queue,
+    "struct rcu_head *"/*head*/, "void *"/*obj*/);
+SDT_PROBE_DEFINE2(sdt, linux, rcu, kfree__free,
+    "struct rcu_head *"/*head*/, "void *"/*obj*/);
+SDT_PROBE_DEFINE2(sdt, linux, rcu, kfree__done,
+    "struct rcu_head *"/*head*/, "void *"/*obj*/);
+
+static struct {
+       kmutex_t        lock;
+       kcondvar_t      cv;
+       struct rcu_head *first_callback;
+       struct rcu_head *first_kfree;
+       struct lwp      *lwp;
+       uint64_t        gen;
+       bool            dying;
+} gc __cacheline_aligned;
+
+static void
+synchronize_rcu_xc(void *a, void *b)
+{
+
+       SDT_PROBE1(sdt, linux, rcu, synchronize__cpu,  cpu_index(curcpu()));
+}
+
+/*
+ * synchronize_rcu()
+ *
+ *     Wait for any pending RCU read section on every CPU to complete
+ *     by triggering on every CPU activity that is blocked by an RCU
+ *     read section.
+ */
+void
+synchronize_rcu(void)
+{
+
+       SDT_PROBE0(sdt, linux, rcu, synchronize__start);
+       xc_wait(xc_broadcast(0, &synchronize_rcu_xc, NULL, NULL));
+       SDT_PROBE0(sdt, linux, rcu, synchronize__done);
+}
+
+/*
+ * rcu_barrier()
+ *
+ *     Wait for all pending RCU callbacks to complete.
+ *
+ *     Does not imply, and is not implied by, synchronize_rcu.
+ */
+void
+rcu_barrier(void)
+{
+       uint64_t gen;
+
+       SDT_PROBE0(sdt, linux, rcu, barrier__start);
+       mutex_enter(&gc.lock);
+       if (gc.first_callback != NULL || gc.first_kfree != NULL) {
+               gen = gc.gen;
+               do {
+                       cv_wait(&gc.cv, &gc.lock);
+               } while (gc.gen == gen);
+       }
+       mutex_exit(&gc.lock);
+       SDT_PROBE0(sdt, linux, rcu, barrier__done);
+}
+
+/*
+ * call_rcu(head, callback)
+ *
+ *     Arrange to call callback(head) after any pending RCU read
+ *     sections on every CPU is complete.  Return immediately.
+ */
+void
+call_rcu(struct rcu_head *head, void (*callback)(struct rcu_head *))
+{
+
+       head->rcuh_u.callback = callback;
+
+       mutex_enter(&gc.lock);
+       head->rcuh_next = gc.first_callback;
+       gc.first_callback = head;
+       cv_broadcast(&gc.cv);
+       SDT_PROBE2(sdt, linux, rcu, call__queue,  head, callback);
+       mutex_exit(&gc.lock);
+}
+
+/*
+ * _kfree_rcu(head, obj)
+ *
+ *     kfree_rcu helper: schedule kfree(obj) using head for storage.
+ */
+void
+_kfree_rcu(struct rcu_head *head, void *obj)
+{
+
+       head->rcuh_u.obj = obj;
+
+       mutex_enter(&gc.lock);
+       head->rcuh_next = gc.first_kfree;
+       gc.first_kfree = head;
+       cv_broadcast(&gc.cv);
+       SDT_PROBE2(sdt, linux, rcu, kfree__queue,  head, obj);
+       mutex_exit(&gc.lock);
+}
+
+static void
+gc_thread(void *cookie)
+{
+       struct rcu_head *head_callback, *head_kfree, *head, *next;
+
+       mutex_enter(&gc.lock);



Home | Main Index | Thread Index | Old Index