Paolo Bonzini | 7911747 | 2013-05-13 13:29:47 +0200 | [diff] [blame] | 1 | /* |
| 2 | * urcu-mb.c |
| 3 | * |
| 4 | * Userspace RCU library with explicit memory barriers |
| 5 | * |
| 6 | * Copyright (c) 2009 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 7 | * Copyright (c) 2009 Paul E. McKenney, IBM Corporation. |
| 8 | * Copyright 2015 Red Hat, Inc. |
| 9 | * |
| 10 | * Ported to QEMU by Paolo Bonzini <pbonzini@redhat.com> |
| 11 | * |
| 12 | * This library is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU Lesser General Public |
| 14 | * License as published by the Free Software Foundation; either |
| 15 | * version 2.1 of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * This library is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 20 | * Lesser General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU Lesser General Public |
| 23 | * License along with this library; if not, write to the Free Software |
| 24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 25 | * |
| 26 | * IBM's contributions to this file may be relicensed under LGPLv2 or later. |
| 27 | */ |
| 28 | |
Peter Maydell | aafd758 | 2016-01-29 17:49:55 +0000 | [diff] [blame] | 29 | #include "qemu/osdep.h" |
Paolo Bonzini | 7911747 | 2013-05-13 13:29:47 +0200 | [diff] [blame] | 30 | #include "qemu/rcu.h" |
| 31 | #include "qemu/atomic.h" |
Paolo Bonzini | 26387f8 | 2013-05-13 17:49:24 +0200 | [diff] [blame] | 32 | #include "qemu/thread.h" |
Paolo Bonzini | a464982 | 2015-02-11 17:15:18 +0100 | [diff] [blame] | 33 | #include "qemu/main-loop.h" |
Daniel Brodsky | 6e8a355 | 2020-04-03 21:21:08 -0700 | [diff] [blame] | 34 | #include "qemu/lockable.h" |
Yang Zhong | 5a22ab7 | 2017-12-20 21:16:46 +0800 | [diff] [blame] | 35 | #if defined(CONFIG_MALLOC_TRIM) |
| 36 | #include <malloc.h> |
| 37 | #endif |
Paolo Bonzini | 7911747 | 2013-05-13 13:29:47 +0200 | [diff] [blame] | 38 | |
| 39 | /* |
| 40 | * Global grace period counter. Bit 0 is always one in rcu_gp_ctr. |
| 41 | * Bits 1 and above are defined in synchronize_rcu. |
| 42 | */ |
| 43 | #define RCU_GP_LOCKED (1UL << 0) |
| 44 | #define RCU_GP_CTR (1UL << 1) |
| 45 | |
| 46 | unsigned long rcu_gp_ctr = RCU_GP_LOCKED; |
| 47 | |
| 48 | QemuEvent rcu_gp_event; |
Wen Congyang | c097a60 | 2015-07-27 10:24:18 +0800 | [diff] [blame] | 49 | static QemuMutex rcu_registry_lock; |
| 50 | static QemuMutex rcu_sync_lock; |
Paolo Bonzini | 7911747 | 2013-05-13 13:29:47 +0200 | [diff] [blame] | 51 | |
| 52 | /* |
| 53 | * Check whether a quiescent state was crossed between the beginning of |
| 54 | * update_counter_and_wait and now. |
| 55 | */ |
| 56 | static inline int rcu_gp_ongoing(unsigned long *ctr) |
| 57 | { |
| 58 | unsigned long v; |
| 59 | |
| 60 | v = atomic_read(ctr); |
| 61 | return v && (v != rcu_gp_ctr); |
| 62 | } |
| 63 | |
| 64 | /* Written to only by each individual reader. Read by both the reader and the |
| 65 | * writers. |
| 66 | */ |
| 67 | __thread struct rcu_reader_data rcu_reader; |
| 68 | |
Wen Congyang | c097a60 | 2015-07-27 10:24:18 +0800 | [diff] [blame] | 69 | /* Protected by rcu_registry_lock. */ |
Paolo Bonzini | 7911747 | 2013-05-13 13:29:47 +0200 | [diff] [blame] | 70 | typedef QLIST_HEAD(, rcu_reader_data) ThreadList; |
| 71 | static ThreadList registry = QLIST_HEAD_INITIALIZER(registry); |
| 72 | |
| 73 | /* Wait for previous parity/grace period to be empty of readers. */ |
| 74 | static void wait_for_readers(void) |
| 75 | { |
| 76 | ThreadList qsreaders = QLIST_HEAD_INITIALIZER(qsreaders); |
| 77 | struct rcu_reader_data *index, *tmp; |
| 78 | |
| 79 | for (;;) { |
| 80 | /* We want to be notified of changes made to rcu_gp_ongoing |
| 81 | * while we walk the list. |
| 82 | */ |
| 83 | qemu_event_reset(&rcu_gp_event); |
| 84 | |
| 85 | /* Instead of using atomic_mb_set for index->waiting, and |
| 86 | * atomic_mb_read for index->ctr, memory barriers are placed |
| 87 | * manually since writes to different threads are independent. |
Paolo Bonzini | e11131b | 2016-09-19 11:27:46 +0200 | [diff] [blame] | 88 | * qemu_event_reset has acquire semantics, so no memory barrier |
| 89 | * is needed here. |
Paolo Bonzini | 7911747 | 2013-05-13 13:29:47 +0200 | [diff] [blame] | 90 | */ |
Paolo Bonzini | 7911747 | 2013-05-13 13:29:47 +0200 | [diff] [blame] | 91 | QLIST_FOREACH(index, ®istry, node) { |
| 92 | atomic_set(&index->waiting, true); |
| 93 | } |
| 94 | |
Paolo Bonzini | 77a8b84 | 2018-02-16 09:23:31 +0100 | [diff] [blame] | 95 | /* Here, order the stores to index->waiting before the loads of |
Paolo Bonzini | c8d3877 | 2018-02-16 10:04:18 +0100 | [diff] [blame] | 96 | * index->ctr. Pairs with smp_mb_placeholder() in rcu_read_unlock(), |
Paolo Bonzini | 77a8b84 | 2018-02-16 09:23:31 +0100 | [diff] [blame] | 97 | * ensuring that the loads of index->ctr are sequentially consistent. |
Paolo Bonzini | e11131b | 2016-09-19 11:27:46 +0200 | [diff] [blame] | 98 | */ |
Paolo Bonzini | c8d3877 | 2018-02-16 10:04:18 +0100 | [diff] [blame] | 99 | smp_mb_global(); |
Paolo Bonzini | 7911747 | 2013-05-13 13:29:47 +0200 | [diff] [blame] | 100 | |
| 101 | QLIST_FOREACH_SAFE(index, ®istry, node, tmp) { |
| 102 | if (!rcu_gp_ongoing(&index->ctr)) { |
| 103 | QLIST_REMOVE(index, node); |
| 104 | QLIST_INSERT_HEAD(&qsreaders, index, node); |
| 105 | |
| 106 | /* No need for mb_set here, worst of all we |
| 107 | * get some extra futex wakeups. |
| 108 | */ |
| 109 | atomic_set(&index->waiting, false); |
| 110 | } |
| 111 | } |
| 112 | |
Paolo Bonzini | 7911747 | 2013-05-13 13:29:47 +0200 | [diff] [blame] | 113 | if (QLIST_EMPTY(®istry)) { |
| 114 | break; |
| 115 | } |
| 116 | |
Wen Congyang | c097a60 | 2015-07-27 10:24:18 +0800 | [diff] [blame] | 117 | /* Wait for one thread to report a quiescent state and try again. |
| 118 | * Release rcu_registry_lock, so rcu_(un)register_thread() doesn't |
| 119 | * wait too much time. |
| 120 | * |
| 121 | * rcu_register_thread() may add nodes to ®istry; it will not |
| 122 | * wake up synchronize_rcu, but that is okay because at least another |
| 123 | * thread must exit its RCU read-side critical section before |
| 124 | * synchronize_rcu is done. The next iteration of the loop will |
| 125 | * move the new thread's rcu_reader from ®istry to &qsreaders, |
| 126 | * because rcu_gp_ongoing() will return false. |
| 127 | * |
| 128 | * rcu_unregister_thread() may remove nodes from &qsreaders instead |
| 129 | * of ®istry if it runs during qemu_event_wait. That's okay; |
| 130 | * the node then will not be added back to ®istry by QLIST_SWAP |
| 131 | * below. The invariant is that the node is part of one list when |
| 132 | * rcu_registry_lock is released. |
Paolo Bonzini | 7911747 | 2013-05-13 13:29:47 +0200 | [diff] [blame] | 133 | */ |
Wen Congyang | c097a60 | 2015-07-27 10:24:18 +0800 | [diff] [blame] | 134 | qemu_mutex_unlock(&rcu_registry_lock); |
Paolo Bonzini | 7911747 | 2013-05-13 13:29:47 +0200 | [diff] [blame] | 135 | qemu_event_wait(&rcu_gp_event); |
Wen Congyang | c097a60 | 2015-07-27 10:24:18 +0800 | [diff] [blame] | 136 | qemu_mutex_lock(&rcu_registry_lock); |
Paolo Bonzini | 7911747 | 2013-05-13 13:29:47 +0200 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | /* put back the reader list in the registry */ |
| 140 | QLIST_SWAP(®istry, &qsreaders, node); |
| 141 | } |
| 142 | |
| 143 | void synchronize_rcu(void) |
| 144 | { |
Daniel Brodsky | 6e8a355 | 2020-04-03 21:21:08 -0700 | [diff] [blame] | 145 | QEMU_LOCK_GUARD(&rcu_sync_lock); |
Paolo Bonzini | 7911747 | 2013-05-13 13:29:47 +0200 | [diff] [blame] | 146 | |
Paolo Bonzini | 77a8b84 | 2018-02-16 09:23:31 +0100 | [diff] [blame] | 147 | /* Write RCU-protected pointers before reading p_rcu_reader->ctr. |
Paolo Bonzini | c8d3877 | 2018-02-16 10:04:18 +0100 | [diff] [blame] | 148 | * Pairs with smp_mb_placeholder() in rcu_read_lock(). |
Paolo Bonzini | 77a8b84 | 2018-02-16 09:23:31 +0100 | [diff] [blame] | 149 | */ |
Paolo Bonzini | c8d3877 | 2018-02-16 10:04:18 +0100 | [diff] [blame] | 150 | smp_mb_global(); |
Paolo Bonzini | 77a8b84 | 2018-02-16 09:23:31 +0100 | [diff] [blame] | 151 | |
Daniel Brodsky | 6e8a355 | 2020-04-03 21:21:08 -0700 | [diff] [blame] | 152 | QEMU_LOCK_GUARD(&rcu_registry_lock); |
Paolo Bonzini | 7911747 | 2013-05-13 13:29:47 +0200 | [diff] [blame] | 153 | if (!QLIST_EMPTY(®istry)) { |
| 154 | /* In either case, the atomic_mb_set below blocks stores that free |
| 155 | * old RCU-protected pointers. |
| 156 | */ |
| 157 | if (sizeof(rcu_gp_ctr) < 8) { |
| 158 | /* For architectures with 32-bit longs, a two-subphases algorithm |
| 159 | * ensures we do not encounter overflow bugs. |
| 160 | * |
| 161 | * Switch parity: 0 -> 1, 1 -> 0. |
| 162 | */ |
| 163 | atomic_mb_set(&rcu_gp_ctr, rcu_gp_ctr ^ RCU_GP_CTR); |
| 164 | wait_for_readers(); |
| 165 | atomic_mb_set(&rcu_gp_ctr, rcu_gp_ctr ^ RCU_GP_CTR); |
| 166 | } else { |
| 167 | /* Increment current grace period. */ |
| 168 | atomic_mb_set(&rcu_gp_ctr, rcu_gp_ctr + RCU_GP_CTR); |
| 169 | } |
| 170 | |
| 171 | wait_for_readers(); |
| 172 | } |
Paolo Bonzini | 7911747 | 2013-05-13 13:29:47 +0200 | [diff] [blame] | 173 | } |
| 174 | |
Paolo Bonzini | 26387f8 | 2013-05-13 17:49:24 +0200 | [diff] [blame] | 175 | |
| 176 | #define RCU_CALL_MIN_SIZE 30 |
| 177 | |
| 178 | /* Multi-producer, single-consumer queue based on urcu/static/wfqueue.h |
| 179 | * from liburcu. Note that head is only used by the consumer. |
| 180 | */ |
| 181 | static struct rcu_head dummy; |
| 182 | static struct rcu_head *head = &dummy, **tail = &dummy.next; |
| 183 | static int rcu_call_count; |
| 184 | static QemuEvent rcu_call_ready_event; |
| 185 | |
| 186 | static void enqueue(struct rcu_head *node) |
| 187 | { |
| 188 | struct rcu_head **old_tail; |
| 189 | |
| 190 | node->next = NULL; |
| 191 | old_tail = atomic_xchg(&tail, &node->next); |
| 192 | atomic_mb_set(old_tail, node); |
| 193 | } |
| 194 | |
| 195 | static struct rcu_head *try_dequeue(void) |
| 196 | { |
| 197 | struct rcu_head *node, *next; |
| 198 | |
| 199 | retry: |
| 200 | /* Test for an empty list, which we do not expect. Note that for |
| 201 | * the consumer head and tail are always consistent. The head |
| 202 | * is consistent because only the consumer reads/writes it. |
| 203 | * The tail, because it is the first step in the enqueuing. |
| 204 | * It is only the next pointers that might be inconsistent. |
| 205 | */ |
| 206 | if (head == &dummy && atomic_mb_read(&tail) == &dummy.next) { |
| 207 | abort(); |
| 208 | } |
| 209 | |
| 210 | /* If the head node has NULL in its next pointer, the value is |
| 211 | * wrong and we need to wait until its enqueuer finishes the update. |
| 212 | */ |
| 213 | node = head; |
| 214 | next = atomic_mb_read(&head->next); |
| 215 | if (!next) { |
| 216 | return NULL; |
| 217 | } |
| 218 | |
| 219 | /* Since we are the sole consumer, and we excluded the empty case |
| 220 | * above, the queue will always have at least two nodes: the |
| 221 | * dummy node, and the one being removed. So we do not need to update |
| 222 | * the tail pointer. |
| 223 | */ |
| 224 | head = next; |
| 225 | |
| 226 | /* If we dequeued the dummy node, add it back at the end and retry. */ |
| 227 | if (node == &dummy) { |
| 228 | enqueue(node); |
| 229 | goto retry; |
| 230 | } |
| 231 | |
| 232 | return node; |
| 233 | } |
| 234 | |
| 235 | static void *call_rcu_thread(void *opaque) |
| 236 | { |
| 237 | struct rcu_head *node; |
| 238 | |
Paolo Bonzini | ab28bd2 | 2015-07-09 08:55:38 +0200 | [diff] [blame] | 239 | rcu_register_thread(); |
| 240 | |
Paolo Bonzini | 26387f8 | 2013-05-13 17:49:24 +0200 | [diff] [blame] | 241 | for (;;) { |
| 242 | int tries = 0; |
| 243 | int n = atomic_read(&rcu_call_count); |
| 244 | |
| 245 | /* Heuristically wait for a decent number of callbacks to pile up. |
| 246 | * Fetch rcu_call_count now, we only must process elements that were |
| 247 | * added before synchronize_rcu() starts. |
| 248 | */ |
Paolo Bonzini | a7d1d63 | 2015-02-11 15:51:54 +0100 | [diff] [blame] | 249 | while (n == 0 || (n < RCU_CALL_MIN_SIZE && ++tries <= 5)) { |
| 250 | g_usleep(10000); |
| 251 | if (n == 0) { |
| 252 | qemu_event_reset(&rcu_call_ready_event); |
Paolo Bonzini | 26387f8 | 2013-05-13 17:49:24 +0200 | [diff] [blame] | 253 | n = atomic_read(&rcu_call_count); |
Paolo Bonzini | a7d1d63 | 2015-02-11 15:51:54 +0100 | [diff] [blame] | 254 | if (n == 0) { |
Yang Zhong | 5a22ab7 | 2017-12-20 21:16:46 +0800 | [diff] [blame] | 255 | #if defined(CONFIG_MALLOC_TRIM) |
| 256 | malloc_trim(4 * 1024 * 1024); |
| 257 | #endif |
Paolo Bonzini | a7d1d63 | 2015-02-11 15:51:54 +0100 | [diff] [blame] | 258 | qemu_event_wait(&rcu_call_ready_event); |
| 259 | } |
Paolo Bonzini | 26387f8 | 2013-05-13 17:49:24 +0200 | [diff] [blame] | 260 | } |
Paolo Bonzini | a7d1d63 | 2015-02-11 15:51:54 +0100 | [diff] [blame] | 261 | n = atomic_read(&rcu_call_count); |
Paolo Bonzini | 26387f8 | 2013-05-13 17:49:24 +0200 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | atomic_sub(&rcu_call_count, n); |
| 265 | synchronize_rcu(); |
Paolo Bonzini | a464982 | 2015-02-11 17:15:18 +0100 | [diff] [blame] | 266 | qemu_mutex_lock_iothread(); |
Paolo Bonzini | 26387f8 | 2013-05-13 17:49:24 +0200 | [diff] [blame] | 267 | while (n > 0) { |
| 268 | node = try_dequeue(); |
| 269 | while (!node) { |
Paolo Bonzini | a464982 | 2015-02-11 17:15:18 +0100 | [diff] [blame] | 270 | qemu_mutex_unlock_iothread(); |
Paolo Bonzini | 26387f8 | 2013-05-13 17:49:24 +0200 | [diff] [blame] | 271 | qemu_event_reset(&rcu_call_ready_event); |
| 272 | node = try_dequeue(); |
| 273 | if (!node) { |
| 274 | qemu_event_wait(&rcu_call_ready_event); |
| 275 | node = try_dequeue(); |
| 276 | } |
Paolo Bonzini | a464982 | 2015-02-11 17:15:18 +0100 | [diff] [blame] | 277 | qemu_mutex_lock_iothread(); |
Paolo Bonzini | 26387f8 | 2013-05-13 17:49:24 +0200 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | n--; |
| 281 | node->func(node); |
| 282 | } |
Paolo Bonzini | a464982 | 2015-02-11 17:15:18 +0100 | [diff] [blame] | 283 | qemu_mutex_unlock_iothread(); |
Paolo Bonzini | 26387f8 | 2013-05-13 17:49:24 +0200 | [diff] [blame] | 284 | } |
| 285 | abort(); |
| 286 | } |
| 287 | |
| 288 | void call_rcu1(struct rcu_head *node, void (*func)(struct rcu_head *node)) |
| 289 | { |
| 290 | node->func = func; |
| 291 | enqueue(node); |
| 292 | atomic_inc(&rcu_call_count); |
| 293 | qemu_event_set(&rcu_call_ready_event); |
| 294 | } |
| 295 | |
Paolo Bonzini | 7911747 | 2013-05-13 13:29:47 +0200 | [diff] [blame] | 296 | void rcu_register_thread(void) |
| 297 | { |
| 298 | assert(rcu_reader.ctr == 0); |
Wen Congyang | c097a60 | 2015-07-27 10:24:18 +0800 | [diff] [blame] | 299 | qemu_mutex_lock(&rcu_registry_lock); |
Paolo Bonzini | 7911747 | 2013-05-13 13:29:47 +0200 | [diff] [blame] | 300 | QLIST_INSERT_HEAD(®istry, &rcu_reader, node); |
Wen Congyang | c097a60 | 2015-07-27 10:24:18 +0800 | [diff] [blame] | 301 | qemu_mutex_unlock(&rcu_registry_lock); |
Paolo Bonzini | 7911747 | 2013-05-13 13:29:47 +0200 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | void rcu_unregister_thread(void) |
| 305 | { |
Wen Congyang | c097a60 | 2015-07-27 10:24:18 +0800 | [diff] [blame] | 306 | qemu_mutex_lock(&rcu_registry_lock); |
Paolo Bonzini | 7911747 | 2013-05-13 13:29:47 +0200 | [diff] [blame] | 307 | QLIST_REMOVE(&rcu_reader, node); |
Wen Congyang | c097a60 | 2015-07-27 10:24:18 +0800 | [diff] [blame] | 308 | qemu_mutex_unlock(&rcu_registry_lock); |
Paolo Bonzini | 7911747 | 2013-05-13 13:29:47 +0200 | [diff] [blame] | 309 | } |
| 310 | |
Paolo Bonzini | 21b7cf9 | 2015-03-05 16:53:48 +0100 | [diff] [blame] | 311 | static void rcu_init_complete(void) |
Paolo Bonzini | 7911747 | 2013-05-13 13:29:47 +0200 | [diff] [blame] | 312 | { |
Paolo Bonzini | 26387f8 | 2013-05-13 17:49:24 +0200 | [diff] [blame] | 313 | QemuThread thread; |
| 314 | |
Wen Congyang | c097a60 | 2015-07-27 10:24:18 +0800 | [diff] [blame] | 315 | qemu_mutex_init(&rcu_registry_lock); |
| 316 | qemu_mutex_init(&rcu_sync_lock); |
Paolo Bonzini | 7911747 | 2013-05-13 13:29:47 +0200 | [diff] [blame] | 317 | qemu_event_init(&rcu_gp_event, true); |
Paolo Bonzini | 26387f8 | 2013-05-13 17:49:24 +0200 | [diff] [blame] | 318 | |
| 319 | qemu_event_init(&rcu_call_ready_event, false); |
Paolo Bonzini | 21b7cf9 | 2015-03-05 16:53:48 +0100 | [diff] [blame] | 320 | |
| 321 | /* The caller is assumed to have iothread lock, so the call_rcu thread |
| 322 | * must have been quiescent even after forking, just recreate it. |
| 323 | */ |
Paolo Bonzini | 26387f8 | 2013-05-13 17:49:24 +0200 | [diff] [blame] | 324 | qemu_thread_create(&thread, "call_rcu", call_rcu_thread, |
| 325 | NULL, QEMU_THREAD_DETACHED); |
| 326 | |
Paolo Bonzini | 7911747 | 2013-05-13 13:29:47 +0200 | [diff] [blame] | 327 | rcu_register_thread(); |
| 328 | } |
Paolo Bonzini | 21b7cf9 | 2015-03-05 16:53:48 +0100 | [diff] [blame] | 329 | |
Paolo Bonzini | 73c6e40 | 2016-01-27 08:49:21 +0100 | [diff] [blame] | 330 | static int atfork_depth = 1; |
| 331 | |
| 332 | void rcu_enable_atfork(void) |
| 333 | { |
| 334 | atfork_depth++; |
| 335 | } |
| 336 | |
| 337 | void rcu_disable_atfork(void) |
| 338 | { |
| 339 | atfork_depth--; |
| 340 | } |
| 341 | |
Paolo Bonzini | 21b7cf9 | 2015-03-05 16:53:48 +0100 | [diff] [blame] | 342 | #ifdef CONFIG_POSIX |
| 343 | static void rcu_init_lock(void) |
| 344 | { |
Paolo Bonzini | 73c6e40 | 2016-01-27 08:49:21 +0100 | [diff] [blame] | 345 | if (atfork_depth < 1) { |
| 346 | return; |
| 347 | } |
| 348 | |
Wen Congyang | c097a60 | 2015-07-27 10:24:18 +0800 | [diff] [blame] | 349 | qemu_mutex_lock(&rcu_sync_lock); |
| 350 | qemu_mutex_lock(&rcu_registry_lock); |
Paolo Bonzini | 21b7cf9 | 2015-03-05 16:53:48 +0100 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | static void rcu_init_unlock(void) |
| 354 | { |
Paolo Bonzini | 73c6e40 | 2016-01-27 08:49:21 +0100 | [diff] [blame] | 355 | if (atfork_depth < 1) { |
| 356 | return; |
| 357 | } |
| 358 | |
Wen Congyang | c097a60 | 2015-07-27 10:24:18 +0800 | [diff] [blame] | 359 | qemu_mutex_unlock(&rcu_registry_lock); |
| 360 | qemu_mutex_unlock(&rcu_sync_lock); |
Paolo Bonzini | 21b7cf9 | 2015-03-05 16:53:48 +0100 | [diff] [blame] | 361 | } |
| 362 | |
Paolo Bonzini | 2a96a55 | 2016-03-25 14:00:51 +0100 | [diff] [blame] | 363 | static void rcu_init_child(void) |
Paolo Bonzini | 21b7cf9 | 2015-03-05 16:53:48 +0100 | [diff] [blame] | 364 | { |
Paolo Bonzini | 2a96a55 | 2016-03-25 14:00:51 +0100 | [diff] [blame] | 365 | if (atfork_depth < 1) { |
| 366 | return; |
| 367 | } |
| 368 | |
Paolo Bonzini | 21b7cf9 | 2015-03-05 16:53:48 +0100 | [diff] [blame] | 369 | memset(®istry, 0, sizeof(registry)); |
| 370 | rcu_init_complete(); |
| 371 | } |
Paolo Bonzini | 2a96a55 | 2016-03-25 14:00:51 +0100 | [diff] [blame] | 372 | #endif |
Paolo Bonzini | 21b7cf9 | 2015-03-05 16:53:48 +0100 | [diff] [blame] | 373 | |
| 374 | static void __attribute__((__constructor__)) rcu_init(void) |
| 375 | { |
Paolo Bonzini | c8d3877 | 2018-02-16 10:04:18 +0100 | [diff] [blame] | 376 | smp_mb_global_init(); |
Paolo Bonzini | 21b7cf9 | 2015-03-05 16:53:48 +0100 | [diff] [blame] | 377 | #ifdef CONFIG_POSIX |
Paolo Bonzini | 2a96a55 | 2016-03-25 14:00:51 +0100 | [diff] [blame] | 378 | pthread_atfork(rcu_init_lock, rcu_init_unlock, rcu_init_child); |
Paolo Bonzini | 21b7cf9 | 2015-03-05 16:53:48 +0100 | [diff] [blame] | 379 | #endif |
| 380 | rcu_init_complete(); |
| 381 | } |