From: Petko Manolov <petko.manolov@konsulko.com>
To: "Paul E . McKenney" <paulmck@kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: [RFC] WRITE_ONCE_INC() and friends
Date: Sun, 19 Apr 2020 12:44:39 +0300 [thread overview]
Message-ID: <20200419094439.GA32841@carbon> (raw)
Hi Paul,
Recently I started reading up on KCSAN and at some point I ran into stuff like:
WRITE_ONCE(ssp->srcu_lock_nesting[idx], ssp->srcu_lock_nesting[idx] + 1);
WRITE_ONCE(p->mm->numa_scan_seq, READ_ONCE(p->mm->numa_scan_seq) + 1);
Some of these are a bit eye-watering for me and could easily be converted to:
WRITE_ONCE_INC(ssp->srcu_lock_nesting[idx]);
WRITE_ONCE_INC(p->mm->numa_scan_seq);
where the above macro could be either:
#define WRITE_ONCE_INC(x) WRITE_ONCE(x, READ_ONCE(x) + 1)
or the more relaxed version:
#define WRITE_ONCE_INC(x) WRITE_ONCE(x, x + 1)
I personally like the stronger version better as a) it doesn't seem to increase
code size (relative to the relaxed one), and b) should be less prone to load
tearing, etc. Given the growing popularity of KCSAN I expect a lot of
concurrent code soon will get the READ_ONCE/WRITE_ONCE conversion.
If you think the above makes sense we could also do this:
#define WRITE_ONCE_DEC(x) WRITE_ONCE(x, READ_ONCE(x) - 1)
#define WRITE_ONCE_ADD(x, v) WRITE_ONCE(x, READ_ONCE(x) + v)
#define WRITE_ONCE_SUB(x, v) WRITE_ONCE(x, READ_ONCE(x) - v)
cheers,
Petko
next reply other threads:[~2020-04-19 9:45 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-19 9:44 Petko Manolov [this message]
2020-04-19 18:02 ` [RFC] WRITE_ONCE_INC() and friends David Laight
2020-04-19 18:29 ` Petko Manolov
2020-04-19 21:37 ` David Laight
2020-04-20 15:05 ` Paul E. McKenney
2020-04-20 16:32 ` Petko Manolov
2020-04-21 8:00 ` David Laight
2020-04-21 9:30 ` Petko Manolov
2020-04-20 22:57 ` Marco Elver
2020-04-20 23:12 ` Paul E. McKenney
2020-04-21 9:33 ` Marco Elver
2020-04-21 13:19 ` Paul E. McKenney
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200419094439.GA32841@carbon \
--to=petko.manolov@konsulko.com \
--cc=linux-kernel@vger.kernel.org \
--cc=paulmck@kernel.org \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox