rcu: use coroutine TLS macros
RCU may be used from coroutines. Standard __thread variables cannot be used by coroutines. Use the coroutine TLS macros instead. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Message-Id: <20220222140150.27240-4-stefanha@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
47b7446456
commit
17c78154b0
@ -29,6 +29,7 @@
|
|||||||
#include "qemu/atomic.h"
|
#include "qemu/atomic.h"
|
||||||
#include "qemu/notify.h"
|
#include "qemu/notify.h"
|
||||||
#include "qemu/sys_membarrier.h"
|
#include "qemu/sys_membarrier.h"
|
||||||
|
#include "qemu/coroutine-tls.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@ -76,11 +77,11 @@ struct rcu_reader_data {
|
|||||||
NotifierList force_rcu;
|
NotifierList force_rcu;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern __thread struct rcu_reader_data rcu_reader;
|
QEMU_DECLARE_CO_TLS(struct rcu_reader_data, rcu_reader)
|
||||||
|
|
||||||
static inline void rcu_read_lock(void)
|
static inline void rcu_read_lock(void)
|
||||||
{
|
{
|
||||||
struct rcu_reader_data *p_rcu_reader = &rcu_reader;
|
struct rcu_reader_data *p_rcu_reader = get_ptr_rcu_reader();
|
||||||
unsigned ctr;
|
unsigned ctr;
|
||||||
|
|
||||||
if (p_rcu_reader->depth++ > 0) {
|
if (p_rcu_reader->depth++ > 0) {
|
||||||
@ -96,7 +97,7 @@ static inline void rcu_read_lock(void)
|
|||||||
|
|
||||||
static inline void rcu_read_unlock(void)
|
static inline void rcu_read_unlock(void)
|
||||||
{
|
{
|
||||||
struct rcu_reader_data *p_rcu_reader = &rcu_reader;
|
struct rcu_reader_data *p_rcu_reader = get_ptr_rcu_reader();
|
||||||
|
|
||||||
assert(p_rcu_reader->depth != 0);
|
assert(p_rcu_reader->depth != 0);
|
||||||
if (--p_rcu_reader->depth > 0) {
|
if (--p_rcu_reader->depth > 0) {
|
||||||
|
@ -122,7 +122,7 @@ static void *rcu_read_perf_test(void *arg)
|
|||||||
|
|
||||||
rcu_register_thread();
|
rcu_register_thread();
|
||||||
|
|
||||||
*(struct rcu_reader_data **)arg = &rcu_reader;
|
*(struct rcu_reader_data **)arg = get_ptr_rcu_reader();
|
||||||
qatomic_inc(&nthreadsrunning);
|
qatomic_inc(&nthreadsrunning);
|
||||||
while (goflag == GOFLAG_INIT) {
|
while (goflag == GOFLAG_INIT) {
|
||||||
g_usleep(1000);
|
g_usleep(1000);
|
||||||
@ -148,7 +148,7 @@ static void *rcu_update_perf_test(void *arg)
|
|||||||
|
|
||||||
rcu_register_thread();
|
rcu_register_thread();
|
||||||
|
|
||||||
*(struct rcu_reader_data **)arg = &rcu_reader;
|
*(struct rcu_reader_data **)arg = get_ptr_rcu_reader();
|
||||||
qatomic_inc(&nthreadsrunning);
|
qatomic_inc(&nthreadsrunning);
|
||||||
while (goflag == GOFLAG_INIT) {
|
while (goflag == GOFLAG_INIT) {
|
||||||
g_usleep(1000);
|
g_usleep(1000);
|
||||||
@ -253,7 +253,7 @@ static void *rcu_read_stress_test(void *arg)
|
|||||||
|
|
||||||
rcu_register_thread();
|
rcu_register_thread();
|
||||||
|
|
||||||
*(struct rcu_reader_data **)arg = &rcu_reader;
|
*(struct rcu_reader_data **)arg = get_ptr_rcu_reader();
|
||||||
while (goflag == GOFLAG_INIT) {
|
while (goflag == GOFLAG_INIT) {
|
||||||
g_usleep(1000);
|
g_usleep(1000);
|
||||||
}
|
}
|
||||||
@ -304,7 +304,7 @@ static void *rcu_update_stress_test(void *arg)
|
|||||||
struct rcu_stress *cp = qatomic_read(&rcu_stress_current);
|
struct rcu_stress *cp = qatomic_read(&rcu_stress_current);
|
||||||
|
|
||||||
rcu_register_thread();
|
rcu_register_thread();
|
||||||
*(struct rcu_reader_data **)arg = &rcu_reader;
|
*(struct rcu_reader_data **)arg = get_ptr_rcu_reader();
|
||||||
|
|
||||||
while (goflag == GOFLAG_INIT) {
|
while (goflag == GOFLAG_INIT) {
|
||||||
g_usleep(1000);
|
g_usleep(1000);
|
||||||
@ -347,7 +347,7 @@ static void *rcu_fake_update_stress_test(void *arg)
|
|||||||
{
|
{
|
||||||
rcu_register_thread();
|
rcu_register_thread();
|
||||||
|
|
||||||
*(struct rcu_reader_data **)arg = &rcu_reader;
|
*(struct rcu_reader_data **)arg = get_ptr_rcu_reader();
|
||||||
while (goflag == GOFLAG_INIT) {
|
while (goflag == GOFLAG_INIT) {
|
||||||
g_usleep(1000);
|
g_usleep(1000);
|
||||||
}
|
}
|
||||||
|
@ -171,7 +171,7 @@ static void *rcu_q_reader(void *arg)
|
|||||||
|
|
||||||
rcu_register_thread();
|
rcu_register_thread();
|
||||||
|
|
||||||
*(struct rcu_reader_data **)arg = &rcu_reader;
|
*(struct rcu_reader_data **)arg = get_ptr_rcu_reader();
|
||||||
qatomic_inc(&nthreadsrunning);
|
qatomic_inc(&nthreadsrunning);
|
||||||
while (qatomic_read(&goflag) == GOFLAG_INIT) {
|
while (qatomic_read(&goflag) == GOFLAG_INIT) {
|
||||||
g_usleep(1000);
|
g_usleep(1000);
|
||||||
@ -206,7 +206,7 @@ static void *rcu_q_updater(void *arg)
|
|||||||
long long n_removed_local = 0;
|
long long n_removed_local = 0;
|
||||||
struct list_element *el, *prev_el;
|
struct list_element *el, *prev_el;
|
||||||
|
|
||||||
*(struct rcu_reader_data **)arg = &rcu_reader;
|
*(struct rcu_reader_data **)arg = get_ptr_rcu_reader();
|
||||||
qatomic_inc(&nthreadsrunning);
|
qatomic_inc(&nthreadsrunning);
|
||||||
while (qatomic_read(&goflag) == GOFLAG_INIT) {
|
while (qatomic_read(&goflag) == GOFLAG_INIT) {
|
||||||
g_usleep(1000);
|
g_usleep(1000);
|
||||||
|
10
util/rcu.c
10
util/rcu.c
@ -65,7 +65,7 @@ static inline int rcu_gp_ongoing(unsigned long *ctr)
|
|||||||
/* Written to only by each individual reader. Read by both the reader and the
|
/* Written to only by each individual reader. Read by both the reader and the
|
||||||
* writers.
|
* writers.
|
||||||
*/
|
*/
|
||||||
__thread struct rcu_reader_data rcu_reader;
|
QEMU_DEFINE_CO_TLS(struct rcu_reader_data, rcu_reader)
|
||||||
|
|
||||||
/* Protected by rcu_registry_lock. */
|
/* Protected by rcu_registry_lock. */
|
||||||
typedef QLIST_HEAD(, rcu_reader_data) ThreadList;
|
typedef QLIST_HEAD(, rcu_reader_data) ThreadList;
|
||||||
@ -355,23 +355,23 @@ void drain_call_rcu(void)
|
|||||||
|
|
||||||
void rcu_register_thread(void)
|
void rcu_register_thread(void)
|
||||||
{
|
{
|
||||||
assert(rcu_reader.ctr == 0);
|
assert(get_ptr_rcu_reader()->ctr == 0);
|
||||||
qemu_mutex_lock(&rcu_registry_lock);
|
qemu_mutex_lock(&rcu_registry_lock);
|
||||||
QLIST_INSERT_HEAD(®istry, &rcu_reader, node);
|
QLIST_INSERT_HEAD(®istry, get_ptr_rcu_reader(), node);
|
||||||
qemu_mutex_unlock(&rcu_registry_lock);
|
qemu_mutex_unlock(&rcu_registry_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rcu_unregister_thread(void)
|
void rcu_unregister_thread(void)
|
||||||
{
|
{
|
||||||
qemu_mutex_lock(&rcu_registry_lock);
|
qemu_mutex_lock(&rcu_registry_lock);
|
||||||
QLIST_REMOVE(&rcu_reader, node);
|
QLIST_REMOVE(get_ptr_rcu_reader(), node);
|
||||||
qemu_mutex_unlock(&rcu_registry_lock);
|
qemu_mutex_unlock(&rcu_registry_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rcu_add_force_rcu_notifier(Notifier *n)
|
void rcu_add_force_rcu_notifier(Notifier *n)
|
||||||
{
|
{
|
||||||
qemu_mutex_lock(&rcu_registry_lock);
|
qemu_mutex_lock(&rcu_registry_lock);
|
||||||
notifier_list_add(&rcu_reader.force_rcu, n);
|
notifier_list_add(&get_ptr_rcu_reader()->force_rcu, n);
|
||||||
qemu_mutex_unlock(&rcu_registry_lock);
|
qemu_mutex_unlock(&rcu_registry_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user