From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Alex Bennée" <alex.bennee@linaro.org>
Subject: [Qemu-devel] [PULL 14/39] qom/object: update class cache atomically
Date: Fri, 7 Oct 2016 18:57:38 +0200 [thread overview]
Message-ID: <1475859483-32234-15-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1475859483-32234-1-git-send-email-pbonzini@redhat.com>
From: Alex Bennée <alex.bennee@linaro.org>
The idiom CPU_GET_CLASS(cpu) is fairly extensively used in various
threads and trips of ThreadSanitizer due to the fact it updates
obj->class->object_cast_cache behind the scenes. As this is just a
fast-path cache there is no need to lock updates.
However to ensure defined C11 behaviour across threads we need to use
the plain atomic_read/set primitives and keep the sanitizer happy.
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20160930213106.20186-7-alex.bennee@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
qom/object.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/qom/object.c b/qom/object.c
index 8166b7d..7a05e35 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -614,7 +614,7 @@ Object *object_dynamic_cast_assert(Object *obj, const char *typename,
Object *inst;
for (i = 0; obj && i < OBJECT_CLASS_CAST_CACHE; i++) {
- if (obj->class->object_cast_cache[i] == typename) {
+ if (atomic_read(&obj->class->object_cast_cache[i]) == typename) {
goto out;
}
}
@@ -631,10 +631,10 @@ Object *object_dynamic_cast_assert(Object *obj, const char *typename,
if (obj && obj == inst) {
for (i = 1; i < OBJECT_CLASS_CAST_CACHE; i++) {
- obj->class->object_cast_cache[i - 1] =
- obj->class->object_cast_cache[i];
+ atomic_set(&obj->class->object_cast_cache[i - 1],
+ atomic_read(&obj->class->object_cast_cache[i]));
}
- obj->class->object_cast_cache[i - 1] = typename;
+ atomic_set(&obj->class->object_cast_cache[i - 1], typename);
}
out:
@@ -704,7 +704,7 @@ ObjectClass *object_class_dynamic_cast_assert(ObjectClass *class,
int i;
for (i = 0; class && i < OBJECT_CLASS_CAST_CACHE; i++) {
- if (class->class_cast_cache[i] == typename) {
+ if (atomic_read(&class->class_cast_cache[i]) == typename) {
ret = class;
goto out;
}
@@ -725,9 +725,10 @@ ObjectClass *object_class_dynamic_cast_assert(ObjectClass *class,
#ifdef CONFIG_QOM_CAST_DEBUG
if (class && ret == class) {
for (i = 1; i < OBJECT_CLASS_CAST_CACHE; i++) {
- class->class_cast_cache[i - 1] = class->class_cast_cache[i];
+ atomic_set(&class->class_cast_cache[i - 1],
+ atomic_read(&class->class_cast_cache[i]));
}
- class->class_cast_cache[i - 1] = typename;
+ atomic_set(&class->class_cast_cache[i - 1], typename);
}
out:
#endif
--
2.7.4
next prev parent reply other threads:[~2016-10-07 16:58 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-07 16:57 [Qemu-devel] [PULL 00/39] Misc patches for 2016-10-07 Paolo Bonzini
2016-10-07 16:57 ` [Qemu-devel] [PULL 01/39] hw/iommu: Fix problems reported by Coverity scan Paolo Bonzini
2016-10-07 16:57 ` [Qemu-devel] [PULL 02/39] MC146818 RTC: coordinate guest clock base to destination host after migration Paolo Bonzini
2016-10-07 16:57 ` [Qemu-devel] [PULL 03/39] hw/misc/edu: support MSI interrupt Paolo Bonzini
2016-10-07 16:57 ` [Qemu-devel] [PULL 04/39] intc: add an interface to gather statistics/informations on interrupt controllers Paolo Bonzini
2016-10-07 16:57 ` [Qemu-devel] [PULL 05/39] intc/i8259: implement InterruptStatsProvider interface Paolo Bonzini
2016-10-07 16:57 ` [Qemu-devel] [PULL 06/39] intc/slavio_intctl: " Paolo Bonzini
2016-10-07 16:57 ` [Qemu-devel] [PULL 07/39] intc/lm32_pic: " Paolo Bonzini
2016-10-07 16:57 ` [Qemu-devel] [PULL 08/39] intc: make HMP 'info irq' and 'info pic' commands use " Paolo Bonzini
2016-10-07 16:57 ` [Qemu-devel] [PULL 09/39] intc: make HMP 'info irq' and 'info pic' commands available on all targets Paolo Bonzini
2016-10-07 16:57 ` [Qemu-devel] [PULL 10/39] atomic.h: fix __SANITIZE_THREAD__ build Paolo Bonzini
2016-10-07 16:57 ` [Qemu-devel] [PULL 11/39] atomic.h: comment on use of atomic_read/set Paolo Bonzini
2016-10-07 16:57 ` [Qemu-devel] [PULL 12/39] tcg/optimize: move default return out of if statement Paolo Bonzini
2016-10-07 16:57 ` [Qemu-devel] [PULL 13/39] seqlock: use atomic writes for the sequence Paolo Bonzini
2016-10-07 16:57 ` Paolo Bonzini [this message]
2016-10-07 16:57 ` [Qemu-devel] [PULL 15/39] qom/cpu: atomically clear the tb_jmp_cache Paolo Bonzini
2016-10-07 16:57 ` [Qemu-devel] [PULL 16/39] cpu: atomically modify cpu->exit_request Paolo Bonzini
2016-10-07 16:57 ` [Qemu-devel] [PULL 17/39] util/qht: atomically set b->hashes Paolo Bonzini
2016-10-07 16:57 ` [Qemu-devel] [PULL 18/39] linux-user/syscall: extend lock around cpu-list Paolo Bonzini
2016-10-07 16:57 ` [Qemu-devel] [PULL 19/39] qga/command: use QEMU atomic primitives Paolo Bonzini
2016-10-07 16:57 ` [Qemu-devel] [PULL 20/39] .travis.yml: add gcc sanitizer build Paolo Bonzini
2016-10-07 16:57 ` [Qemu-devel] [PULL 21/39] i8259: give ISA device when registering ISA ioports Paolo Bonzini
2016-10-07 16:57 ` [Qemu-devel] [PULL 22/39] char: use a fixed idx for child muxed chr Paolo Bonzini
2016-10-07 16:57 ` [Qemu-devel] [PULL 23/39] char: update read handler in all cases Paolo Bonzini
2016-10-07 16:57 ` [Qemu-devel] [PULL 24/39] util: Introduce qemu_get_pid_name Paolo Bonzini
2016-10-07 16:57 ` [Qemu-devel] [PULL 25/39] qemu_kill_report: Report PID name too Paolo Bonzini
2016-10-07 16:57 ` [Qemu-devel] [PULL 26/39] qemu-nbd: Shrink image size by specified offset Paolo Bonzini
2016-10-07 16:57 ` [Qemu-devel] [PULL 27/39] qht: simplify qht_reset_size Paolo Bonzini
2016-10-07 16:57 ` [Qemu-devel] [PULL 28/39] qht: fix unlock-after-free segfault upon resizing Paolo Bonzini
2016-10-07 16:57 ` [Qemu-devel] [PULL 29/39] test-qht: perform lookups under rcu_read_lock Paolo Bonzini
2016-10-07 16:57 ` [Qemu-devel] [PULL 30/39] qemu-tech: drop index Paolo Bonzini
2016-10-07 16:57 ` [Qemu-devel] [PULL 31/39] qemu-doc: replace introduction with the one from the internals manual Paolo Bonzini
2016-10-07 16:57 ` [Qemu-devel] [PULL 32/39] qemu-doc: drop installation and compilation notes Paolo Bonzini
2016-10-07 16:57 ` [Qemu-devel] [PULL 33/39] qemu-tech: move text from qemu-tech to tcg/README Paolo Bonzini
2016-10-07 16:57 ` [Qemu-devel] [PULL 34/39] qemu-tech: document lazy condition code evaluation in cpu.h Paolo Bonzini
2016-10-07 16:57 ` [Qemu-devel] [PULL 35/39] qemu-tech: move user mode emulation features from qemu-tech Paolo Bonzini
2016-10-07 16:58 ` [Qemu-devel] [PULL 36/39] qemu-tech: move TCG test documentation to tests/tcg/README Paolo Bonzini
2016-10-07 16:58 ` [Qemu-devel] [PULL 37/39] qemu-tech: reorganize content Paolo Bonzini
2016-10-07 16:58 ` [Qemu-devel] [PULL 38/39] qemu-tech: rewrite some parts Paolo Bonzini
2016-10-07 16:58 ` [Qemu-devel] [PULL 39/39] qemu-doc: merge qemu-tech and qemu-doc Paolo Bonzini
2016-10-10 10:44 ` [Qemu-devel] [PULL 00/39] Misc patches for 2016-10-07 Peter Maydell
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=1475859483-32234-15-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=alex.bennee@linaro.org \
--cc=qemu-devel@nongnu.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;
as well as URLs for NNTP newsgroup(s).