[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v4 01/12] util/qht: Document memory ordering assumpt
From: |
Sergey Fedorov |
Subject: |
[Qemu-devel] [PATCH v4 01/12] util/qht: Document memory ordering assumptions |
Date: |
Fri, 15 Jul 2016 20:58:41 +0300 |
From: Paolo Bonzini <address@hidden>
It is naturally expected that some memory ordering should be provided
around qht_insert() and qht_lookup(). Document these assumptions in the
header file and put some comments in the source to denote how that
memory ordering requirements are fulfilled.
Signed-off-by: Paolo Bonzini <address@hidden>
[Sergey Fedorov: commit title and message provided;
comment on qht_remove() elided]
Signed-off-by: Sergey Fedorov <address@hidden>
---
Changes in v4:
- Modified version of Paolo's patch is used
---
include/qemu/qht.h | 5 +++++
util/qht.c | 7 ++++++-
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/include/qemu/qht.h b/include/qemu/qht.h
index 70bfc68b8d67..311139b85a9a 100644
--- a/include/qemu/qht.h
+++ b/include/qemu/qht.h
@@ -69,6 +69,9 @@ void qht_destroy(struct qht *ht);
* Attempting to insert a NULL @p is a bug.
* Inserting the same pointer @p with different @hash values is a bug.
*
+ * In case of successful operation, smp_wmb() is implied before the pointer is
+ * inserted into the hash table.
+ *
* Returns true on sucess.
* Returns false if the @address@hidden pair already exists in the hash table.
*/
@@ -83,6 +86,8 @@ bool qht_insert(struct qht *ht, void *p, uint32_t hash);
*
* Needs to be called under an RCU read-critical section.
*
+ * smp_read_barrier_depends() is implied before the call to @func.
+ *
* The user-provided @func compares pointers in QHT against @userp.
* If the function returns true, a match has been found.
*
diff --git a/util/qht.c b/util/qht.c
index 40d6e218f759..28ce289245a7 100644
--- a/util/qht.c
+++ b/util/qht.c
@@ -445,7 +445,11 @@ void *qht_do_lookup(struct qht_bucket *head,
qht_lookup_func_t func,
do {
for (i = 0; i < QHT_BUCKET_ENTRIES; i++) {
if (b->hashes[i] == hash) {
- void *p = atomic_read(&b->pointers[i]);
+ /* The pointer is dereferenced before seqlock_read_retry,
+ * so (unlike qht_insert__locked) we need to use
+ * atomic_rcu_read here.
+ */
+ void *p = atomic_rcu_read(&b->pointers[i]);
if (likely(p) && likely(func(p, userp))) {
return p;
@@ -535,6 +539,7 @@ static bool qht_insert__locked(struct qht *ht, struct
qht_map *map,
atomic_rcu_set(&prev->next, b);
}
b->hashes[i] = hash;
+ /* smp_wmb() implicit in seqlock_write_begin. */
atomic_set(&b->pointers[i], p);
seqlock_write_end(&head->sequence);
return true;
--
2.9.1
- [Qemu-devel] [PATCH v4 00/12] Reduce lock contention on TCG hot-path, Sergey Fedorov, 2016/07/15
- [Qemu-devel] [PATCH v4 02/12] tcg: Pass last_tb by value to tb_find_fast(), Sergey Fedorov, 2016/07/15
- [Qemu-devel] [PATCH v4 03/12] tcg: Prepare safe tb_jmp_cache lookup out of tb_lock, Sergey Fedorov, 2016/07/15
- [Qemu-devel] [PATCH v4 01/12] util/qht: Document memory ordering assumptions,
Sergey Fedorov <=
- [Qemu-devel] [PATCH v4 04/12] tcg: Prepare safe access to tb_flushed out of tb_lock, Sergey Fedorov, 2016/07/15
- [Qemu-devel] [PATCH v4 08/12] tcg: set up tb->page_addr before insertion, Sergey Fedorov, 2016/07/15
- [Qemu-devel] [PATCH v4 07/12] tcg: Prepare TB invalidation for lockless TB lookup, Sergey Fedorov, 2016/07/15
- [Qemu-devel] [PATCH v4 05/12] target-i386: Remove redundant HF_SOFTMMU_MASK, Sergey Fedorov, 2016/07/15
- [Qemu-devel] [PATCH v4 06/12] tcg: Introduce tb_mark_invalid() and tb_is_invalid(), Sergey Fedorov, 2016/07/15
- [Qemu-devel] [PATCH v4 09/12] tcg: cpu-exec: remove tb_lock from the hot-path, Sergey Fedorov, 2016/07/15
- [Qemu-devel] [PATCH v4 10/12] tcg: Avoid bouncing tb_lock between tb_gen_code() and tb_add_jump(), Sergey Fedorov, 2016/07/15
- [Qemu-devel] [PATCH v4 12/12] tcg: rename tb_find_physical(), Sergey Fedorov, 2016/07/15
- [Qemu-devel] [PATCH v4 11/12] tcg: Merge tb_find_slow() and tb_find_fast(), Sergey Fedorov, 2016/07/15
- Re: [Qemu-devel] [PATCH v4 00/12] Reduce lock contention on TCG hot-path, Paolo Bonzini, 2016/07/16