Source-Changes-HG archive

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

[src/trunk]: src/sys/external/bsd/drm2 Implement some of the Linux RCU API.



details:   https://anonhg.NetBSD.org/src/rev/cd3d9b99ff22
branches:  trunk
changeset: 835230:cd3d9b99ff22
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Mon Aug 27 13:31:36 2018 +0000

description:
Implement some of the Linux RCU API.

diffstat:

 sys/external/bsd/drm2/include/linux/rcupdate.h |   43 ++++---
 sys/external/bsd/drm2/include/linux/types.h    |    6 +-
 sys/external/bsd/drm2/linux/files.drmkms_linux |    3 +-
 sys/external/bsd/drm2/linux/linux_module.c     |   21 ++-
 sys/external/bsd/drm2/linux/linux_rcu.c        |  149 +++++++++++++++++++++++++
 5 files changed, 191 insertions(+), 31 deletions(-)

diffs (truncated from 335 to 300 lines):

diff -r 2cb656f632c5 -r cd3d9b99ff22 sys/external/bsd/drm2/include/linux/rcupdate.h
--- a/sys/external/bsd/drm2/include/linux/rcupdate.h    Mon Aug 27 13:20:47 2018 +0000
+++ b/sys/external/bsd/drm2/include/linux/rcupdate.h    Mon Aug 27 13:31:36 2018 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: rcupdate.h,v 1.4 2018/08/27 07:34:23 riastradh Exp $   */
+/*     $NetBSD: rcupdate.h,v 1.5 2018/08/27 13:31:36 riastradh Exp $   */
 
 /*-
- * Copyright (c) 2013 The NetBSD Foundation, Inc.
+ * Copyright (c) 2018 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -33,8 +33,8 @@
 #define _LINUX_RCUPDATE_H_
 
 #include <sys/atomic.h>
-#include <sys/null.h>
-#include <sys/xcall.h>
+#include <sys/cdefs.h>
+#include <sys/systm.h>
 
 #define        __rcu
 
@@ -44,15 +44,31 @@
 } while (0)
 
 
-#define        rcu_dereference(P)      rcu_dereference_protected((P), 1)
+#define        rcu_dereference(P) ({                                                 \
+       typeof(*(P)) *__rcu_dereference_tmp = (P);                            \
+       membar_datadep_consumer();                                            \
+       __rcu_dereference_tmp;                                                \
+})
 
 #define        rcu_dereference_protected(P, C) ({                                    \
        WARN_ON(!(C));                                                        \
-       typeof(*(P)) *__rcu_dereference_protected_tmp = (P);                  \
-       membar_datadep_consumer();                                            \
-       __rcu_dereference_protected_tmp;                                      \
+       (P);                                                                  \
 })
 
+struct rcu_head {
+       void            (*rcuh_callback)(struct rcu_head *);
+       struct rcu_head *rcuh_next;
+};
+
+#define        linux_call_rcu          call_rcu
+#define        linux_synchronize_rcu   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   synchronize_rcu(void);
+
 static inline void
 rcu_read_lock(void)
 {
@@ -69,15 +85,4 @@
        kpreempt_enable();
 }
 
-static inline void
-synchronize_rcu_xc(void *a, void *b)
-{
-}
-
-static inline void
-synchronize_rcu(void)
-{
-       xc_wait(xc_broadcast(0, &synchronize_rcu_xc, NULL, NULL));
-}
-
 #endif  /* _LINUX_RCUPDATE_H_ */
diff -r 2cb656f632c5 -r cd3d9b99ff22 sys/external/bsd/drm2/include/linux/types.h
--- a/sys/external/bsd/drm2/include/linux/types.h       Mon Aug 27 13:20:47 2018 +0000
+++ b/sys/external/bsd/drm2/include/linux/types.h       Mon Aug 27 13:31:36 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: types.h,v 1.7 2018/08/27 07:25:55 riastradh Exp $      */
+/*     $NetBSD: types.h,v 1.8 2018/08/27 13:31:36 riastradh Exp $      */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -88,10 +88,6 @@
 /* XXX Not sure this is correct.  */
 typedef off_t loff_t;
 
-struct rcu_head {
-
-};
-
 #define DECLARE_BITMAP(NAME, BITS)                                           \
        unsigned long NAME[((BITS) + ((NBBY*sizeof(unsigned long)) - 1)) /    \
                (NBBY*sizeof(unsigned long))]
diff -r 2cb656f632c5 -r cd3d9b99ff22 sys/external/bsd/drm2/linux/files.drmkms_linux
--- a/sys/external/bsd/drm2/linux/files.drmkms_linux    Mon Aug 27 13:20:47 2018 +0000
+++ b/sys/external/bsd/drm2/linux/files.drmkms_linux    Mon Aug 27 13:31:36 2018 +0000
@@ -1,4 +1,4 @@
-#       $NetBSD: files.drmkms_linux,v 1.11 2018/08/27 07:57:56 riastradh Exp $
+#       $NetBSD: files.drmkms_linux,v 1.12 2018/08/27 13:31:37 riastradh Exp $
 
 define drmkms_linux: i2cexec, i2c_bitbang
 
@@ -11,5 +11,6 @@
 file   external/bsd/drm2/linux/linux_kmap.c            drmkms_linux
 file   external/bsd/drm2/linux/linux_list_sort.c       drmkms_linux
 file   external/bsd/drm2/linux/linux_module.c          drmkms_linux
+file   external/bsd/drm2/linux/linux_rcu.c             drmkms_linux
 file   external/bsd/drm2/linux/linux_writecomb.c       drmkms_linux
 file   external/bsd/drm2/linux/linux_ww_mutex.c        drmkms_linux
diff -r 2cb656f632c5 -r cd3d9b99ff22 sys/external/bsd/drm2/linux/linux_module.c
--- a/sys/external/bsd/drm2/linux/linux_module.c        Mon Aug 27 13:20:47 2018 +0000
+++ b/sys/external/bsd/drm2/linux/linux_module.c        Mon Aug 27 13:31:36 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: linux_module.c,v 1.6 2015/04/13 22:24:34 pgoyette Exp $        */
+/*     $NetBSD: linux_module.c,v 1.7 2018/08/27 13:31:37 riastradh Exp $       */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_module.c,v 1.6 2015/04/13 22:24:34 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_module.c,v 1.7 2018/08/27 13:31:37 riastradh Exp $");
 
 #include <sys/module.h>
 #ifndef _MODULE
@@ -41,6 +41,7 @@
 #include <linux/idr.h>
 #include <linux/io.h>
 #include <linux/mutex.h>
+#include <linux/rcupdate.h>
 #include <linux/reservation.h>
 #include <linux/workqueue.h>
 
@@ -65,24 +66,31 @@
                goto fail1;
        }
 
+       error = linux_rcu_gc_init();
+       if (error) {
+               printf("linux: unable to initialize rcu gc: %d\n", error);
+               goto fail2;
+       }
+
        error = linux_workqueue_init();
        if (error) {
                printf("linux: unable to initialize workqueues: %d\n", error);
-               goto fail2;
+               goto fail3;
        }
 
        error = linux_writecomb_init();
        if (error) {
                printf("linux: unable to initialize write-combining: %d\n",
                    error);
-               goto fail3;
+               goto fail4;
        }
 
        return 0;
 
-fail4: __unused
+fail5: __unused
        linux_writecomb_fini();
-fail3: linux_workqueue_fini();
+fail4: linux_workqueue_fini();
+fail3: linux_rcu_gc_fini();
 fail2: linux_kmap_fini();
 fail1: linux_idr_module_fini();
 fail0: return error;
@@ -107,6 +115,7 @@
 
        linux_writecomb_fini();
        linux_workqueue_fini();
+       linux_rcu_gc_fini();
        linux_kmap_fini();
        linux_idr_module_fini();
 }
diff -r 2cb656f632c5 -r cd3d9b99ff22 sys/external/bsd/drm2/linux/linux_rcu.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/external/bsd/drm2/linux/linux_rcu.c   Mon Aug 27 13:31:36 2018 +0000
@@ -0,0 +1,149 @@
+/*     $NetBSD: linux_rcu.c,v 1.1 2018/08/27 13:31:37 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 2018/08/27 13:31:37 riastradh Exp $");
+
+#include <sys/types.h>
+#include <sys/condvar.h>
+#include <sys/kthread.h>
+#include <sys/mutex.h>
+#include <sys/xcall.h>
+
+#include <linux/rcupdate.h>
+
+struct {
+       kmutex_t        lock;
+       kcondvar_t      cv;
+       struct rcu_head *first;
+       struct lwp      *lwp;
+       bool            dying;
+} gc __cacheline_aligned;
+
+static void
+rcu_xc(void *a, void *b)
+{
+}
+
+void
+synchronize_rcu(void)
+{
+
+       xc_wait(xc_broadcast(0, &rcu_xc, NULL, NULL));
+}
+
+void
+call_rcu(struct rcu_head *head, void (*callback)(struct rcu_head *))
+{
+
+       head->rcuh_callback = callback;
+
+       mutex_enter(&gc.lock);
+       head->rcuh_next = gc.first;
+       gc.first = head;
+       cv_signal(&gc.cv);
+       mutex_exit(&gc.lock);
+}
+
+static void
+gc_thread(void *cookie)
+{
+       struct rcu_head *head, *next;
+
+       mutex_enter(&gc.lock);
+       for (;;) {
+               /* Wait for a task or death notice.  */
+               while ((head = gc.first) == NULL && !gc.dying)
+                       cv_wait(&gc.cv, &gc.lock);
+
+               /* If we got a list of callbacks, run them.  */
+               if (head != NULL) {
+                       gc.first = NULL;        /* mine */
+                       mutex_exit(&gc.lock);
+
+                       /* Wait for activity on all CPUs.  */
+                       synchronize_rcu();
+
+                       /* It is now safe to call the callbacks.  */
+                       for (; head != NULL; head = next) {
+                               next = head->rcuh_next;
+                               (*head->rcuh_callback)(head);
+                       }
+
+                       mutex_enter(&gc.lock);
+               }
+
+               /* If we're asked to close shop, do so.  */
+               if (gc.dying)
+                       break;
+       }
+       mutex_exit(&gc.lock);
+}
+
+int
+linux_rcu_gc_init(void)
+{
+       int error;



Home | Main Index | Thread Index | Old Index