All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Sergey Fedorov <serge.fdrv@gmail.com>,
	Sergey Fedorov <sergey.fedorov@linaro.org>,
	qemu-devel@nongnu.org, mttcg@greensocs.com,
	fred.konrad@greensocs.com, a.rigo@virtualopensystems.com,
	cota@braap.org, bobby.prani@gmail.com, rth@twiddle.net
Cc: peter.maydell@linaro.org, patches@linaro.org,
	claudio.fontana@huawei.com, mark.burton@greensocs.com,
	jan.kiszka@siemens.com, "Alex Bennée" <alex.bennee@linaro.org>
Subject: Re: [Qemu-devel] [PATCH v3 01/11] util/qht: Document memory ordering assumptions
Date: Thu, 14 Jul 2016 10:05:26 +0200	[thread overview]
Message-ID: <2ace7f8e-3693-0415-d4d1-5e7dc05af625@redhat.com> (raw)
In-Reply-To: <5786825D.5020009@gmail.com>



On 13/07/2016 20:03, Sergey Fedorov wrote:
> On 13/07/16 14:13, Paolo Bonzini wrote:
>>
>> On 12/07/2016 22:13, Sergey Fedorov wrote:
>>> diff --git a/include/qemu/qht.h b/include/qemu/qht.h
>>> index 70bfc68b8d67..5f633e5d8100 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 @p-@hash pair already exists in the hash table.
>>>   */
>>> @@ -86,6 +89,9 @@ bool qht_insert(struct qht *ht, void *p, uint32_t hash);
>>>   * The user-provided @func compares pointers in QHT against @userp.
>>>   * If the function returns true, a match has been found.
>>>   *
>>> + * smp_rmb() is implied before and after the pointer is looked up and retrieved
>>> + * from the hash table.
>> Do we really need to guarantee smp_rmb(), or is smp_read_barrier_depends()
>> aka atomic_rcu_read() enough?
> 
> The idea was something like: qht_lookup() can be "paired" with either
> qht_insert() or qht_remove(). The intention was to guarantee independent
> tb_jmp_cache lookup performed before qht_lookup() in tb_find_physical().

Of course; that would not be impacted if qht_lookup() only made a weaker
promise.

Anyway, this patch (or mine or a mix of them) can go in after hard freeze.

Paolo

>>
>> Likewise, perhaps only an implicit smp_wmb() before the insert is
>> "interesting" to qht_insert__locked callers .
> 
> I see the idea behind this patch is worthwhile so I spend more time on
> refining it and I must look at your patch carefully ;)
> 
> Thanks,
> Sergey
> 
>>
>> Something like:
>>
>> diff --git a/include/qemu/qht.h b/include/qemu/qht.h
>> index 70bfc68..f4f1d55 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 @p-@hash 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.
>>   *
>> @@ -105,6 +110,10 @@ void *qht_lookup(struct qht *ht, qht_lookup_func_t func, const void *userp,
>>   * This guarantees that concurrent lookups will always compare against valid
>>   * data.
>>   *
>> + * In case of successful operation, a smp_wmb() barrier is implied before and
>> + * after the pointer is removed from the hash table.  In other words,
>> + * a successful qht_remove acts as a bidirectional write barrier.
>> + *
>>   * Returns true on success.
>>   * Returns false if the @p-@hash pair was not found.
>>   */
>> diff --git a/util/qht.c b/util/qht.c
>> index 40d6e21..d38948e 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;
>> @@ -659,6 +664,9 @@ bool qht_remove__locked(struct qht_map *map, struct qht_bucket *head,
>>              }
>>              if (q == p) {
>>                  qht_debug_assert(b->hashes[i] == hash);
>> +                /* seqlock_write_begin and seqlock_write_end provide write
>> +                 * memory barrier semantics to callers of qht_remove.
>> +                 */
>>                  seqlock_write_begin(&head->sequence);
>>                  qht_bucket_remove_entry(b, i);
>>                  seqlock_write_end(&head->sequence);
> 

  reply	other threads:[~2016-07-14  8:05 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-12 20:13 [Qemu-devel] [PATCH v3 00/11] Reduce lock contention on TCG hot-path Sergey Fedorov
2016-07-12 20:13 ` [Qemu-devel] [PATCH v3 01/11] util/qht: Document memory ordering assumptions Sergey Fedorov
2016-07-12 23:19   ` Emilio G. Cota
2016-07-13  7:36     ` Paolo Bonzini
2016-07-13 17:50       ` Sergey Fedorov
2016-07-14 13:56         ` Paolo Bonzini
2016-07-14 14:08           ` Sergey Fedorov
2016-07-13 11:13   ` Paolo Bonzini
2016-07-13 18:03     ` Sergey Fedorov
2016-07-14  8:05       ` Paolo Bonzini [this message]
2016-07-15 12:37     ` Sergey Fedorov
2016-07-15 12:51       ` Paolo Bonzini
2016-07-15 13:18         ` Sergey Fedorov
2016-07-12 20:13 ` [Qemu-devel] [PATCH v3 02/11] cpu-exec: Pass last_tb by value to tb_find_fast() Sergey Fedorov
2016-07-12 20:13 ` [Qemu-devel] [PATCH v3 03/11] tcg: Prepare safe tb_jmp_cache lookup out of tb_lock Sergey Fedorov
2016-07-14 12:14   ` Alex Bennée
2016-07-12 20:13 ` [Qemu-devel] [PATCH v3 04/11] tcg: Prepare safe access to tb_flushed " Sergey Fedorov
2016-07-14 12:45   ` Alex Bennée
2016-07-14 12:55     ` Sergey Fedorov
2016-07-14 13:12       ` Alex Bennée
2016-07-12 20:13 ` [Qemu-devel] [PATCH v3 05/11] target-i386: Remove redundant HF_SOFTMMU_MASK Sergey Fedorov
2016-07-14 12:19   ` Alex Bennée
2016-07-12 20:13 ` [Qemu-devel] [PATCH v3 06/11] tcg: Introduce tb_mark_invalid() and tb_is_invalid() Sergey Fedorov
2016-07-14 10:25   ` Alex Bennée
2016-07-14 11:10     ` Sergey Fedorov
2016-07-14 11:48       ` Paolo Bonzini
2016-07-14 12:04         ` Alex Bennée
2016-07-14 12:53   ` Alex Bennée
2016-07-14 13:00     ` Sergey Fedorov
2016-07-14 13:12       ` Paolo Bonzini
2016-07-14 13:15       ` Alex Bennée
2016-07-12 20:13 ` [Qemu-devel] [PATCH v3 07/11] tcg: Prepare TB invalidation for lockless TB lookup Sergey Fedorov
2016-07-14 12:59   ` Alex Bennée
2016-07-14 13:11     ` Sergey Fedorov
2016-07-12 20:13 ` [Qemu-devel] [PATCH v3 08/11] tcg: set up tb->page_addr before insertion Sergey Fedorov
2016-07-12 20:13 ` [Qemu-devel] [PATCH v3 09/11] tcg: cpu-exec: remove tb_lock from the hot-path Sergey Fedorov
2016-07-12 20:13 ` [Qemu-devel] [PATCH v3 10/11] tcg: Avoid bouncing tb_lock between tb_gen_code() and tb_add_jump() Sergey Fedorov
2016-07-14 13:01   ` Alex Bennée
2016-07-14 13:13     ` Sergey Fedorov
2016-07-12 20:13 ` [Qemu-devel] [PATCH v3 11/11] tcg: Merge tb_find_slow() and tb_find_fast() Sergey Fedorov
2016-07-14 13:02   ` Alex Bennée
2016-07-13  7:39 ` [Qemu-devel] [PATCH v3 00/11] Reduce lock contention on TCG hot-path Paolo Bonzini
2016-07-13 17:00   ` Sergey Fedorov
2016-07-14  9:55     ` Alex Bennée
2016-07-14 11:13       ` Sergey Fedorov
2016-07-13 18:06   ` Sergey Fedorov
2016-07-14 12:02   ` Alex Bennée
2016-07-14 12:10     ` Paolo Bonzini
2016-07-14 13:13       ` Alex Bennée

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=2ace7f8e-3693-0415-d4d1-5e7dc05af625@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=a.rigo@virtualopensystems.com \
    --cc=alex.bennee@linaro.org \
    --cc=bobby.prani@gmail.com \
    --cc=claudio.fontana@huawei.com \
    --cc=cota@braap.org \
    --cc=fred.konrad@greensocs.com \
    --cc=jan.kiszka@siemens.com \
    --cc=mark.burton@greensocs.com \
    --cc=mttcg@greensocs.com \
    --cc=patches@linaro.org \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    --cc=serge.fdrv@gmail.com \
    --cc=sergey.fedorov@linaro.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.