* [RFC/PATCH] workaround breakage from urcu v0.11.4
@ 2022-08-15 21:22 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2022-08-15 21:22 UTC (permalink / raw)
To: mwrap-public; +Cc: Sam Saffron
urcu v0.11.4+ introduced commit
7ca7fe9c03 (Make temporary variable in _rcu_dereference non-const, 2021-07-29)
which conflicts with our use of _LGPL_SOURCE. In retrospect,
CMM_LOAD_SHARED and CMM_STORE_SHARED seem sufficient for our use
of the `totals' cds_lfht pointer since the constructur should always
fire before any threads are running.
Link: https://lore.kernel.org/lttng-dev/20220809181927.GA3718@dcvr/
---
I'm nearly certain this change is correct and prior use of
rcu_dereference was overkill; but confirmation from a URCU
hacker would be nice.
ext/mwrap/mwrap.c | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/ext/mwrap/mwrap.c b/ext/mwrap/mwrap.c
index 4575e34..477b1cb 100644
--- a/ext/mwrap/mwrap.c
+++ b/ext/mwrap/mwrap.c
@@ -139,8 +139,8 @@ __attribute__((constructor)) static void resolve_malloc(void)
_exit(1);
}
#endif /* !FreeBSD */
- totals = lfht_new();
- if (!totals)
+ CMM_STORE_SHARED(totals, lfht_new());
+ if (!CMM_LOAD_SHARED(totals))
fprintf(stderr, "failed to allocate totals table\n");
err = pthread_atfork(call_rcu_before_fork,
@@ -375,7 +375,7 @@ static struct src_loc *totals_add_rcu(struct src_loc *k)
struct cds_lfht *t;
again:
- t = rcu_dereference(totals);
+ t = CMM_LOAD_SHARED(totals);
if (!t) goto out_unlock;
cds_lfht_lookup(t, k->hval, loc_eq, k, &iter);
cur = cds_lfht_iter_get_node(&iter);
@@ -417,7 +417,7 @@ static struct src_loc *update_stats_rcu_lock(size_t size, uintptr_t caller)
static const size_t xlen = sizeof(caller);
char *dst;
- if (caa_unlikely(!totals)) return 0;
+ if (caa_unlikely(!CMM_LOAD_SHARED(totals))) return 0;
if (locating++) goto out; /* do not recurse into another *alloc */
uatomic_add(&total_bytes_inc, size);
@@ -808,7 +808,7 @@ static void *dump_to_file(void *x)
++locating;
rcu_read_lock();
- t = rcu_dereference(totals);
+ t = CMM_LOAD_SHARED(totals);
if (!t)
goto out_unlock;
cds_lfht_for_each_entry(t, &iter, l, hnode) {
@@ -877,7 +877,7 @@ static void *totals_reset(void *ign)
uatomic_set(&total_bytes_dec, 0);
rcu_read_lock();
- t = rcu_dereference(totals);
+ t = CMM_LOAD_SHARED(totals);
cds_lfht_for_each_entry(t, &iter, l, hnode) {
uatomic_set(&l->total, 0);
uatomic_set(&l->allocations, 0);
@@ -945,7 +945,7 @@ static VALUE dump_each_rcu(VALUE x)
struct cds_lfht_iter iter;
struct src_loc *l;
- t = rcu_dereference(totals);
+ t = CMM_LOAD_SHARED(totals);
cds_lfht_for_each_entry(t, &iter, l, hnode) {
VALUE v[6];
if (l->total <= a->min) continue;
@@ -1049,9 +1049,9 @@ static VALUE mwrap_aref(VALUE mod, VALUE loc)
if (!k) return val;
+ t = CMM_LOAD_SHARED(totals);
+ if (!t) return val;
rcu_read_lock();
- t = rcu_dereference(totals);
- if (!t) goto out_unlock;
cds_lfht_lookup(t, k->hval, loc_eq, k, &iter);
cur = cds_lfht_iter_get_node(&iter);
@@ -1059,7 +1059,6 @@ static VALUE mwrap_aref(VALUE mod, VALUE loc)
l = caa_container_of(cur, struct src_loc, hnode);
val = TypedData_Wrap_Struct(cSrcLoc, &src_loc_type, l);
}
-out_unlock:
rcu_read_unlock();
return val;
}
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2022-08-15 21:22 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-15 21:22 [RFC/PATCH] workaround breakage from urcu v0.11.4 Eric Wong
Code repositories for project(s) associated with this public inbox
https://80x24.org/mwrap.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).