11a01b4e5SHans Petter Selasky /*- 296fc97c8SStephen Hurd * Copyright (c) 2016 Matthew Macy (mmacy@mattmacy.io) 3c20feee4SHans Petter Selasky * Copyright (c) 2017 Hans Petter Selasky (hselasky@freebsd.org) 41a01b4e5SHans Petter Selasky * All rights reserved. 51a01b4e5SHans Petter Selasky * 61a01b4e5SHans Petter Selasky * Redistribution and use in source and binary forms, with or without 71a01b4e5SHans Petter Selasky * modification, are permitted provided that the following conditions 81a01b4e5SHans Petter Selasky * are met: 91a01b4e5SHans Petter Selasky * 1. Redistributions of source code must retain the above copyright 101a01b4e5SHans Petter Selasky * notice unmodified, this list of conditions, and the following 111a01b4e5SHans Petter Selasky * disclaimer. 121a01b4e5SHans Petter Selasky * 2. Redistributions in binary form must reproduce the above copyright 131a01b4e5SHans Petter Selasky * notice, this list of conditions and the following disclaimer in the 141a01b4e5SHans Petter Selasky * documentation and/or other materials provided with the distribution. 151a01b4e5SHans Petter Selasky * 161a01b4e5SHans Petter Selasky * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 171a01b4e5SHans Petter Selasky * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 181a01b4e5SHans Petter Selasky * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 191a01b4e5SHans Petter Selasky * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 201a01b4e5SHans Petter Selasky * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 211a01b4e5SHans Petter Selasky * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 221a01b4e5SHans Petter Selasky * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 231a01b4e5SHans Petter Selasky * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 241a01b4e5SHans Petter Selasky * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 251a01b4e5SHans Petter Selasky * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 261a01b4e5SHans Petter Selasky */ 271a01b4e5SHans Petter Selasky 281a01b4e5SHans Petter Selasky #include <sys/cdefs.h> 291a01b4e5SHans Petter Selasky __FBSDID("$FreeBSD$"); 301a01b4e5SHans Petter Selasky 311a01b4e5SHans Petter Selasky #include <sys/types.h> 321a01b4e5SHans Petter Selasky #include <sys/systm.h> 331a01b4e5SHans Petter Selasky #include <sys/malloc.h> 341a01b4e5SHans Petter Selasky #include <sys/kernel.h> 351a01b4e5SHans Petter Selasky #include <sys/lock.h> 361a01b4e5SHans Petter Selasky #include <sys/mutex.h> 371a01b4e5SHans Petter Selasky #include <sys/proc.h> 381a01b4e5SHans Petter Selasky #include <sys/sched.h> 391a01b4e5SHans Petter Selasky #include <sys/smp.h> 401a01b4e5SHans Petter Selasky #include <sys/queue.h> 411a01b4e5SHans Petter Selasky #include <sys/taskqueue.h> 42f3de9af6SHans Petter Selasky #include <sys/kdb.h> 431a01b4e5SHans Petter Selasky 441a01b4e5SHans Petter Selasky #include <ck_epoch.h> 451a01b4e5SHans Petter Selasky 461a01b4e5SHans Petter Selasky #include <linux/rcupdate.h> 471a01b4e5SHans Petter Selasky #include <linux/srcu.h> 481a01b4e5SHans Petter Selasky #include <linux/slab.h> 491a01b4e5SHans Petter Selasky #include <linux/kernel.h> 50f3de9af6SHans Petter Selasky #include <linux/compat.h> 511a01b4e5SHans Petter Selasky 52f3de9af6SHans Petter Selasky /* 53f3de9af6SHans Petter Selasky * By defining CONFIG_NO_RCU_SKIP LinuxKPI RCU locks and asserts will 54f3de9af6SHans Petter Selasky * not be skipped during panic(). 55f3de9af6SHans Petter Selasky */ 56f3de9af6SHans Petter Selasky #ifdef CONFIG_NO_RCU_SKIP 57f3de9af6SHans Petter Selasky #define RCU_SKIP(void) 0 58f3de9af6SHans Petter Selasky #else 59f3de9af6SHans Petter Selasky #define RCU_SKIP(void) unlikely(SCHEDULER_STOPPED() || kdb_active) 60f3de9af6SHans Petter Selasky #endif 611f827dabSHans Petter Selasky 621f827dabSHans Petter Selasky struct callback_head { 631f827dabSHans Petter Selasky STAILQ_ENTRY(callback_head) entry; 641f827dabSHans Petter Selasky rcu_callback_t func; 651f827dabSHans Petter Selasky }; 661f827dabSHans Petter Selasky 67f3de9af6SHans Petter Selasky struct linux_epoch_head { 68f3de9af6SHans Petter Selasky STAILQ_HEAD(, callback_head) cb_head; 69f3de9af6SHans Petter Selasky struct mtx lock; 70f3de9af6SHans Petter Selasky struct task task; 71f3de9af6SHans Petter Selasky } __aligned(CACHE_LINE_SIZE); 72f3de9af6SHans Petter Selasky 73f3de9af6SHans Petter Selasky struct linux_epoch_record { 741f827dabSHans Petter Selasky ck_epoch_record_t epoch_record; 75f3de9af6SHans Petter Selasky TAILQ_HEAD(, task_struct) ts_head; 76f3de9af6SHans Petter Selasky int cpuid; 77f3de9af6SHans Petter Selasky } __aligned(CACHE_LINE_SIZE); 781a01b4e5SHans Petter Selasky 791a01b4e5SHans Petter Selasky /* 801a01b4e5SHans Petter Selasky * Verify that "struct rcu_head" is big enough to hold "struct 811a01b4e5SHans Petter Selasky * callback_head". This has been done to avoid having to add special 821a01b4e5SHans Petter Selasky * compile flags for including ck_epoch.h to all clients of the 831a01b4e5SHans Petter Selasky * LinuxKPI. 841a01b4e5SHans Petter Selasky */ 85f3de9af6SHans Petter Selasky CTASSERT(sizeof(struct rcu_head) == sizeof(struct callback_head)); 861a01b4e5SHans Petter Selasky 871f827dabSHans Petter Selasky /* 881f827dabSHans Petter Selasky * Verify that "epoch_record" is at beginning of "struct 89f3de9af6SHans Petter Selasky * linux_epoch_record": 901f827dabSHans Petter Selasky */ 91f3de9af6SHans Petter Selasky CTASSERT(offsetof(struct linux_epoch_record, epoch_record) == 0); 921f827dabSHans Petter Selasky 931a01b4e5SHans Petter Selasky static ck_epoch_t linux_epoch; 94f3de9af6SHans Petter Selasky static struct linux_epoch_head linux_epoch_head; 952bf95012SAndrew Turner DPCPU_DEFINE_STATIC(struct linux_epoch_record, linux_epoch_record); 961f827dabSHans Petter Selasky 971f827dabSHans Petter Selasky static void linux_rcu_cleaner_func(void *, int); 981a01b4e5SHans Petter Selasky 991a01b4e5SHans Petter Selasky static void 1001a01b4e5SHans Petter Selasky linux_rcu_runtime_init(void *arg __unused) 1011a01b4e5SHans Petter Selasky { 102f3de9af6SHans Petter Selasky struct linux_epoch_head *head; 1031a01b4e5SHans Petter Selasky int i; 1041a01b4e5SHans Petter Selasky 1051a01b4e5SHans Petter Selasky ck_epoch_init(&linux_epoch); 1061a01b4e5SHans Petter Selasky 107f3de9af6SHans Petter Selasky head = &linux_epoch_head; 108f3de9af6SHans Petter Selasky 109f3de9af6SHans Petter Selasky mtx_init(&head->lock, "LRCU-HEAD", NULL, MTX_DEF); 110f3de9af6SHans Petter Selasky TASK_INIT(&head->task, 0, linux_rcu_cleaner_func, NULL); 111f3de9af6SHans Petter Selasky STAILQ_INIT(&head->cb_head); 112f3de9af6SHans Petter Selasky 1131a01b4e5SHans Petter Selasky CPU_FOREACH(i) { 114f3de9af6SHans Petter Selasky struct linux_epoch_record *record; 1151f827dabSHans Petter Selasky 116f3de9af6SHans Petter Selasky record = &DPCPU_ID_GET(i, linux_epoch_record); 1171f827dabSHans Petter Selasky 118f3de9af6SHans Petter Selasky record->cpuid = i; 1197e8cd4e1SOlivier Houchard ck_epoch_register(&linux_epoch, &record->epoch_record, NULL); 120f3de9af6SHans Petter Selasky TAILQ_INIT(&record->ts_head); 1211a01b4e5SHans Petter Selasky } 1221a01b4e5SHans Petter Selasky } 123d8e073a9SHans Petter Selasky SYSINIT(linux_rcu_runtime, SI_SUB_CPU, SI_ORDER_ANY, linux_rcu_runtime_init, NULL); 1241a01b4e5SHans Petter Selasky 1251a01b4e5SHans Petter Selasky static void 1261a01b4e5SHans Petter Selasky linux_rcu_runtime_uninit(void *arg __unused) 1271a01b4e5SHans Petter Selasky { 128f3de9af6SHans Petter Selasky struct linux_epoch_head *head; 1291a01b4e5SHans Petter Selasky 130f3de9af6SHans Petter Selasky head = &linux_epoch_head; 1311a01b4e5SHans Petter Selasky 132f3de9af6SHans Petter Selasky /* destroy head lock */ 133f3de9af6SHans Petter Selasky mtx_destroy(&head->lock); 1341a01b4e5SHans Petter Selasky } 1351a01b4e5SHans Petter Selasky SYSUNINIT(linux_rcu_runtime, SI_SUB_LOCK, SI_ORDER_SECOND, linux_rcu_runtime_uninit, NULL); 1361a01b4e5SHans Petter Selasky 1371f827dabSHans Petter Selasky static void 138f3de9af6SHans Petter Selasky linux_rcu_cleaner_func(void *context __unused, int pending __unused) 1391f827dabSHans Petter Selasky { 140f3de9af6SHans Petter Selasky struct linux_epoch_head *head; 1411a01b4e5SHans Petter Selasky struct callback_head *rcu; 142f3de9af6SHans Petter Selasky STAILQ_HEAD(, callback_head) tmp_head; 1431f827dabSHans Petter Selasky 144f3de9af6SHans Petter Selasky linux_set_current(curthread); 145f3de9af6SHans Petter Selasky 146f3de9af6SHans Petter Selasky head = &linux_epoch_head; 1471f827dabSHans Petter Selasky 1481f827dabSHans Petter Selasky /* move current callbacks into own queue */ 149f3de9af6SHans Petter Selasky mtx_lock(&head->lock); 150f3de9af6SHans Petter Selasky STAILQ_INIT(&tmp_head); 151f3de9af6SHans Petter Selasky STAILQ_CONCAT(&tmp_head, &head->cb_head); 152f3de9af6SHans Petter Selasky mtx_unlock(&head->lock); 1531f827dabSHans Petter Selasky 1541f827dabSHans Petter Selasky /* synchronize */ 155f3de9af6SHans Petter Selasky linux_synchronize_rcu(); 1561f827dabSHans Petter Selasky 1571f827dabSHans Petter Selasky /* dispatch all callbacks, if any */ 158f3de9af6SHans Petter Selasky while ((rcu = STAILQ_FIRST(&tmp_head)) != NULL) { 1591a01b4e5SHans Petter Selasky uintptr_t offset; 1601a01b4e5SHans Petter Selasky 161f3de9af6SHans Petter Selasky STAILQ_REMOVE_HEAD(&tmp_head, entry); 1621a01b4e5SHans Petter Selasky 1631a01b4e5SHans Petter Selasky offset = (uintptr_t)rcu->func; 1641a01b4e5SHans Petter Selasky 1651a01b4e5SHans Petter Selasky if (offset < LINUX_KFREE_RCU_OFFSET_MAX) 1661a01b4e5SHans Petter Selasky kfree((char *)rcu - offset); 1671a01b4e5SHans Petter Selasky else 1681a01b4e5SHans Petter Selasky rcu->func((struct rcu_head *)rcu); 1691a01b4e5SHans Petter Selasky } 1701a01b4e5SHans Petter Selasky } 1711a01b4e5SHans Petter Selasky 1721a01b4e5SHans Petter Selasky void 1731a01b4e5SHans Petter Selasky linux_rcu_read_lock(void) 1741a01b4e5SHans Petter Selasky { 175f3de9af6SHans Petter Selasky struct linux_epoch_record *record; 176f3de9af6SHans Petter Selasky struct task_struct *ts; 177f3de9af6SHans Petter Selasky 178f3de9af6SHans Petter Selasky if (RCU_SKIP()) 179f3de9af6SHans Petter Selasky return; 1801a01b4e5SHans Petter Selasky 1811f827dabSHans Petter Selasky /* 1821f827dabSHans Petter Selasky * Pin thread to current CPU so that the unlock code gets the 183f3de9af6SHans Petter Selasky * same per-CPU epoch record: 1841f827dabSHans Petter Selasky */ 1851a01b4e5SHans Petter Selasky sched_pin(); 1861a01b4e5SHans Petter Selasky 187f3de9af6SHans Petter Selasky record = &DPCPU_GET(linux_epoch_record); 188f3de9af6SHans Petter Selasky ts = current; 1891f827dabSHans Petter Selasky 1901f827dabSHans Petter Selasky /* 1911f827dabSHans Petter Selasky * Use a critical section to prevent recursion inside 1921f827dabSHans Petter Selasky * ck_epoch_begin(). Else this function supports recursion. 1931f827dabSHans Petter Selasky */ 1941f827dabSHans Petter Selasky critical_enter(); 195f3de9af6SHans Petter Selasky ck_epoch_begin(&record->epoch_record, NULL); 196f3de9af6SHans Petter Selasky ts->rcu_recurse++; 197f3de9af6SHans Petter Selasky if (ts->rcu_recurse == 1) 198f3de9af6SHans Petter Selasky TAILQ_INSERT_TAIL(&record->ts_head, ts, rcu_entry); 1991f827dabSHans Petter Selasky critical_exit(); 2001a01b4e5SHans Petter Selasky } 2011a01b4e5SHans Petter Selasky 2021a01b4e5SHans Petter Selasky void 2031a01b4e5SHans Petter Selasky linux_rcu_read_unlock(void) 2041a01b4e5SHans Petter Selasky { 205f3de9af6SHans Petter Selasky struct linux_epoch_record *record; 206f3de9af6SHans Petter Selasky struct task_struct *ts; 2071a01b4e5SHans Petter Selasky 208f3de9af6SHans Petter Selasky if (RCU_SKIP()) 209f3de9af6SHans Petter Selasky return; 210f3de9af6SHans Petter Selasky 211f3de9af6SHans Petter Selasky record = &DPCPU_GET(linux_epoch_record); 212f3de9af6SHans Petter Selasky ts = current; 2131f827dabSHans Petter Selasky 2141f827dabSHans Petter Selasky /* 2151f827dabSHans Petter Selasky * Use a critical section to prevent recursion inside 2161f827dabSHans Petter Selasky * ck_epoch_end(). Else this function supports recursion. 2171f827dabSHans Petter Selasky */ 2181f827dabSHans Petter Selasky critical_enter(); 219f3de9af6SHans Petter Selasky ck_epoch_end(&record->epoch_record, NULL); 220f3de9af6SHans Petter Selasky ts->rcu_recurse--; 221f3de9af6SHans Petter Selasky if (ts->rcu_recurse == 0) 222f3de9af6SHans Petter Selasky TAILQ_REMOVE(&record->ts_head, ts, rcu_entry); 2231f827dabSHans Petter Selasky critical_exit(); 2241f827dabSHans Petter Selasky 2251a01b4e5SHans Petter Selasky sched_unpin(); 2261a01b4e5SHans Petter Selasky } 2271a01b4e5SHans Petter Selasky 228f3de9af6SHans Petter Selasky static void 229f3de9af6SHans Petter Selasky linux_synchronize_rcu_cb(ck_epoch_t *epoch __unused, ck_epoch_record_t *epoch_record, void *arg __unused) 230f3de9af6SHans Petter Selasky { 231f3de9af6SHans Petter Selasky struct linux_epoch_record *record = 232f3de9af6SHans Petter Selasky container_of(epoch_record, struct linux_epoch_record, epoch_record); 233f3de9af6SHans Petter Selasky struct thread *td = curthread; 234f3de9af6SHans Petter Selasky struct task_struct *ts; 235f3de9af6SHans Petter Selasky 236f3de9af6SHans Petter Selasky /* check if blocked on the current CPU */ 237f3de9af6SHans Petter Selasky if (record->cpuid == PCPU_GET(cpuid)) { 238f3de9af6SHans Petter Selasky bool is_sleeping = 0; 239f3de9af6SHans Petter Selasky u_char prio = 0; 240f3de9af6SHans Petter Selasky 241f3de9af6SHans Petter Selasky /* 242f3de9af6SHans Petter Selasky * Find the lowest priority or sleeping thread which 243f3de9af6SHans Petter Selasky * is blocking synchronization on this CPU core. All 244f3de9af6SHans Petter Selasky * the threads in the queue are CPU-pinned and cannot 245f3de9af6SHans Petter Selasky * go anywhere while the current thread is locked. 246f3de9af6SHans Petter Selasky */ 247f3de9af6SHans Petter Selasky TAILQ_FOREACH(ts, &record->ts_head, rcu_entry) { 248f3de9af6SHans Petter Selasky if (ts->task_thread->td_priority > prio) 249f3de9af6SHans Petter Selasky prio = ts->task_thread->td_priority; 250f3de9af6SHans Petter Selasky is_sleeping |= (ts->task_thread->td_inhibitors != 0); 251f3de9af6SHans Petter Selasky } 252f3de9af6SHans Petter Selasky 253f3de9af6SHans Petter Selasky if (is_sleeping) { 254f3de9af6SHans Petter Selasky thread_unlock(td); 255f3de9af6SHans Petter Selasky pause("W", 1); 256f3de9af6SHans Petter Selasky thread_lock(td); 257f3de9af6SHans Petter Selasky } else { 258f3de9af6SHans Petter Selasky /* set new thread priority */ 259f3de9af6SHans Petter Selasky sched_prio(td, prio); 260f3de9af6SHans Petter Selasky /* task switch */ 261686bcb5cSJeff Roberson mi_switch(SW_VOL | SWT_RELINQUISH); 262cc79ea3aSHans Petter Selasky /* 263cc79ea3aSHans Petter Selasky * It is important the thread lock is dropped 264cc79ea3aSHans Petter Selasky * while yielding to allow other threads to 265cc79ea3aSHans Petter Selasky * acquire the lock pointed to by 266cc79ea3aSHans Petter Selasky * TDQ_LOCKPTR(td). Currently mi_switch() will 267cc79ea3aSHans Petter Selasky * unlock the thread lock before 268cc79ea3aSHans Petter Selasky * returning. Else a deadlock like situation 269cc79ea3aSHans Petter Selasky * might happen. 270cc79ea3aSHans Petter Selasky */ 271714ed5b2SHans Petter Selasky thread_lock(td); 272f3de9af6SHans Petter Selasky } 273f3de9af6SHans Petter Selasky } else { 274f3de9af6SHans Petter Selasky /* 275f3de9af6SHans Petter Selasky * To avoid spinning move execution to the other CPU 276f3de9af6SHans Petter Selasky * which is blocking synchronization. Set highest 277f3de9af6SHans Petter Selasky * thread priority so that code gets run. The thread 278f3de9af6SHans Petter Selasky * priority will be restored later. 279f3de9af6SHans Petter Selasky */ 280f3de9af6SHans Petter Selasky sched_prio(td, 0); 281f3de9af6SHans Petter Selasky sched_bind(td, record->cpuid); 282f3de9af6SHans Petter Selasky } 283f3de9af6SHans Petter Selasky } 284f3de9af6SHans Petter Selasky 2851a01b4e5SHans Petter Selasky void 2861a01b4e5SHans Petter Selasky linux_synchronize_rcu(void) 2871a01b4e5SHans Petter Selasky { 288f3de9af6SHans Petter Selasky struct thread *td; 289f3de9af6SHans Petter Selasky int was_bound; 290f3de9af6SHans Petter Selasky int old_cpu; 291f3de9af6SHans Petter Selasky int old_pinned; 2923f743d78SHans Petter Selasky u_char old_prio; 293f3de9af6SHans Petter Selasky 294f3de9af6SHans Petter Selasky if (RCU_SKIP()) 295f3de9af6SHans Petter Selasky return; 296f3de9af6SHans Petter Selasky 297f3de9af6SHans Petter Selasky WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL, 298f3de9af6SHans Petter Selasky "linux_synchronize_rcu() can sleep"); 299f3de9af6SHans Petter Selasky 300f3de9af6SHans Petter Selasky td = curthread; 301*fedab1b4SKonstantin Belousov DROP_GIANT(); 302f3de9af6SHans Petter Selasky 303f3de9af6SHans Petter Selasky /* 304f3de9af6SHans Petter Selasky * Synchronizing RCU might change the CPU core this function 305f3de9af6SHans Petter Selasky * is running on. Save current values: 306f3de9af6SHans Petter Selasky */ 307f3de9af6SHans Petter Selasky thread_lock(td); 308f3de9af6SHans Petter Selasky 309f3de9af6SHans Petter Selasky old_cpu = PCPU_GET(cpuid); 310f3de9af6SHans Petter Selasky old_pinned = td->td_pinned; 3113f743d78SHans Petter Selasky old_prio = td->td_priority; 312f3de9af6SHans Petter Selasky was_bound = sched_is_bound(td); 313ea165254SHans Petter Selasky sched_unbind(td); 314ea165254SHans Petter Selasky td->td_pinned = 0; 315f3de9af6SHans Petter Selasky sched_bind(td, old_cpu); 316f3de9af6SHans Petter Selasky 317f3de9af6SHans Petter Selasky ck_epoch_synchronize_wait(&linux_epoch, 318f3de9af6SHans Petter Selasky &linux_synchronize_rcu_cb, NULL); 319f3de9af6SHans Petter Selasky 320f3de9af6SHans Petter Selasky /* restore CPU binding, if any */ 321f3de9af6SHans Petter Selasky if (was_bound != 0) { 322f3de9af6SHans Petter Selasky sched_bind(td, old_cpu); 323f3de9af6SHans Petter Selasky } else { 324f3de9af6SHans Petter Selasky /* get thread back to initial CPU, if any */ 325f3de9af6SHans Petter Selasky if (old_pinned != 0) 326f3de9af6SHans Petter Selasky sched_bind(td, old_cpu); 327f3de9af6SHans Petter Selasky sched_unbind(td); 328f3de9af6SHans Petter Selasky } 329f3de9af6SHans Petter Selasky /* restore pinned after bind */ 330f3de9af6SHans Petter Selasky td->td_pinned = old_pinned; 3313f743d78SHans Petter Selasky 3323f743d78SHans Petter Selasky /* restore thread priority */ 3333f743d78SHans Petter Selasky sched_prio(td, old_prio); 334f3de9af6SHans Petter Selasky thread_unlock(td); 335f3de9af6SHans Petter Selasky 336f3de9af6SHans Petter Selasky PICKUP_GIANT(); 3371a01b4e5SHans Petter Selasky } 3381a01b4e5SHans Petter Selasky 3391a01b4e5SHans Petter Selasky void 3401a01b4e5SHans Petter Selasky linux_rcu_barrier(void) 3411a01b4e5SHans Petter Selasky { 342f3de9af6SHans Petter Selasky struct linux_epoch_head *head; 3431a01b4e5SHans Petter Selasky 344f3de9af6SHans Petter Selasky linux_synchronize_rcu(); 3451f827dabSHans Petter Selasky 346f3de9af6SHans Petter Selasky head = &linux_epoch_head; 3471f827dabSHans Petter Selasky 3481f827dabSHans Petter Selasky /* wait for callbacks to complete */ 349f3de9af6SHans Petter Selasky taskqueue_drain(taskqueue_fast, &head->task); 3501a01b4e5SHans Petter Selasky } 3511a01b4e5SHans Petter Selasky 3521a01b4e5SHans Petter Selasky void 3531a01b4e5SHans Petter Selasky linux_call_rcu(struct rcu_head *context, rcu_callback_t func) 3541a01b4e5SHans Petter Selasky { 3551f827dabSHans Petter Selasky struct callback_head *rcu = (struct callback_head *)context; 356f3de9af6SHans Petter Selasky struct linux_epoch_head *head = &linux_epoch_head; 3571a01b4e5SHans Petter Selasky 358f3de9af6SHans Petter Selasky mtx_lock(&head->lock); 3591f827dabSHans Petter Selasky rcu->func = func; 360f3de9af6SHans Petter Selasky STAILQ_INSERT_TAIL(&head->cb_head, rcu, entry); 361f3de9af6SHans Petter Selasky taskqueue_enqueue(taskqueue_fast, &head->task); 362f3de9af6SHans Petter Selasky mtx_unlock(&head->lock); 3631a01b4e5SHans Petter Selasky } 3641a01b4e5SHans Petter Selasky 3651a01b4e5SHans Petter Selasky int 3661a01b4e5SHans Petter Selasky init_srcu_struct(struct srcu_struct *srcu) 3671a01b4e5SHans Petter Selasky { 3681a01b4e5SHans Petter Selasky return (0); 3691a01b4e5SHans Petter Selasky } 3701a01b4e5SHans Petter Selasky 3711a01b4e5SHans Petter Selasky void 3721a01b4e5SHans Petter Selasky cleanup_srcu_struct(struct srcu_struct *srcu) 3731a01b4e5SHans Petter Selasky { 3741a01b4e5SHans Petter Selasky } 3751a01b4e5SHans Petter Selasky 3761a01b4e5SHans Petter Selasky int 3771a01b4e5SHans Petter Selasky srcu_read_lock(struct srcu_struct *srcu) 3781a01b4e5SHans Petter Selasky { 379f3de9af6SHans Petter Selasky linux_rcu_read_lock(); 3801a01b4e5SHans Petter Selasky return (0); 3811a01b4e5SHans Petter Selasky } 3821a01b4e5SHans Petter Selasky 3831a01b4e5SHans Petter Selasky void 3841a01b4e5SHans Petter Selasky srcu_read_unlock(struct srcu_struct *srcu, int key __unused) 3851a01b4e5SHans Petter Selasky { 386f3de9af6SHans Petter Selasky linux_rcu_read_unlock(); 3871a01b4e5SHans Petter Selasky } 3881a01b4e5SHans Petter Selasky 3891a01b4e5SHans Petter Selasky void 3901a01b4e5SHans Petter Selasky synchronize_srcu(struct srcu_struct *srcu) 3911a01b4e5SHans Petter Selasky { 392f3de9af6SHans Petter Selasky linux_synchronize_rcu(); 3931f827dabSHans Petter Selasky } 3941f827dabSHans Petter Selasky 3951f827dabSHans Petter Selasky void 3961f827dabSHans Petter Selasky srcu_barrier(struct srcu_struct *srcu) 3971f827dabSHans Petter Selasky { 398f3de9af6SHans Petter Selasky linux_rcu_barrier(); 3991a01b4e5SHans Petter Selasky } 400