From: Eric Wong <e@80x24.org>
To: mwrap-public@80x24.org
Cc: Sam Saffron <sam.saffron@gmail.com>
Subject: [RFC/PATCH] workaround breakage from urcu v0.11.4
Date: Mon, 15 Aug 2022 21:22:17 +0000 [thread overview]
Message-ID: <20220815212217.GA11237@dcvr> (raw)
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;
}
reply other threads:[~2022-08-15 21:22 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://80x24.org/mwrap/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220815212217.GA11237@dcvr \
--to=e@80x24.org \
--cc=mwrap-public@80x24.org \
--cc=sam.saffron@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).