public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Ming Lei <tom.leiming@gmail.com>,
	"James E.J. Bottomley" <JBottomley@parallels.com>
Cc: linux-scsi@vger.kernel.org,
	Wanlong Gao <gaowanlong@cn.fujitsu.com>,
	Rusty Russell <rusty@rustcorp.com.au>
Subject: Re: [PATCH] virtio_scsi: remove ACCESS_ONCE() and smp_read_barrier_depends()
Date: Wed, 07 May 2014 17:50:39 +0200	[thread overview]
Message-ID: <536A564F.3060605@redhat.com> (raw)
In-Reply-To: <1399473279-24871-1-git-send-email-tom.leiming@gmail.com>

Il 07/05/2014 16:34, Ming Lei ha scritto:
>   *
> - * An interesting effect of this policy is that only writes to req_vq need to
> - * take the tgt_lock.  Read can be done outside the lock because:
> - *
> - * - writes of req_vq only occur when atomic_inc_return(&tgt->reqs) returns 1.
> - *   In that case, no other CPU is reading req_vq: even if they were in
> - *   virtscsi_queuecommand_multi, they would be spinning on tgt_lock.
> - *
> - * - reads of req_vq only occur when the target is not idle (reqs != 0).
> - *   A CPU that enters virtscsi_queuecommand_multi will not modify req_vq.
> + * tgt_lock is held to serialize reading and writing req_vq. Reading req_vq
> + * could be done locklessly, but we do not do it yet.
>   *
>   * Similarly, decrements of reqs are never concurrent with writes of req_vq.
>   * Thus they can happen outside the tgt_lock, provided of course we make reqs

The part you deleted explains _why_ decrements of reqs are never 
concurrent with writes of req_vq.  Perhaps:

 * An interesting effect of this policy is that only increments to reqs and writes
 * to req_vq need to take the tgt_lock.  Reads of req_vq and decrements or req_vq
 * can be done outside the lock because:
 *
 * - writes of req_vq only occur when atomic_inc_return(&tgt->reqs) returns 1.
 *   In that case, no other CPU is reading req_vq: even if they were in
 *   virtscsi_queuecommand_multi, they would be spinning on tgt_lock.
 *
 * - reads of req_vq only occur when the target is not idle (reqs != 0).
 *   A CPU that enters virtscsi_queuecommand_multi will not modify req_vq.
 *
 * - likewise, decrements of reqs only occur when reqs != 0.  If the decremented
 *   value is zero, the first CPU that enters virtscsi_queuecommand_multi will
 *   modify req_vq and the others will spin on tgt_lock.
 *
 * We do not try to read req_vq locklessly for simplicity, so tgt_lock is used
 * to serialize reads of req_vq too.

Paolo

  reply	other threads:[~2014-05-07 15:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-07 14:34 [PATCH] virtio_scsi: remove ACCESS_ONCE() and smp_read_barrier_depends() Ming Lei
2014-05-07 15:50 ` Paolo Bonzini [this message]
2014-05-07 16:03   ` Ming Lei
2014-05-07 16:12     ` Paolo Bonzini
2014-05-07 16:29       ` Ming Lei

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=536A564F.3060605@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=JBottomley@parallels.com \
    --cc=gaowanlong@cn.fujitsu.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=rusty@rustcorp.com.au \
    --cc=tom.leiming@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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox