qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Fam Zheng <famz@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v2 2/2] virtio-scsi: Optimize virtio_scsi_init_req
Date: Tue, 16 Sep 2014 10:15:56 +0200	[thread overview]
Message-ID: <5417F1BC.3080408@redhat.com> (raw)
In-Reply-To: <20140916071611.GA21826@fam-t430.nay.redhat.com>

Il 16/09/2014 09:16, Fam Zheng ha scritto:
> On Mon, 09/15 12:17, Paolo Bonzini wrote:
>> Il 15/09/2014 07:23, Fam Zheng ha scritto:
>>>      SCSIRequest *sreq;
>>>      size_t resp_size;
>>>      enum SCSIXferMode mode;
>>> -    QEMUIOVector resp_iov;
>>>      union {
>>>          VirtIOSCSICmdResp     cmd;
>>>          VirtIOSCSICtrlTMFResp tmf;
>>> @@ -68,23 +75,27 @@ static inline SCSIDevice *virtio_scsi_device_find(VirtIOSCSI *s, uint8_t *lun)
>>>  static VirtIOSCSIReq *virtio_scsi_init_req(VirtIOSCSI *s, VirtQueue *vq)
>>>  {
>>>      VirtIOSCSIReq *req;
>>> -    VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(s);
>>> -
>>> -    req = g_malloc0(sizeof(*req) + vs->cdb_size);
>>> +    VirtIOSCSICommon *vs = (VirtIOSCSICommon *)s;
>>> +    const size_t zero_skip = offsetof(VirtIOSCSIReq, elem)
>>> +                             + sizeof(VirtQueueElement);
>>>  
>>> +    req = g_slice_alloc(sizeof(*req) + vs->cdb_size);
>>
>> Looks good, but why do you need to zero the union?  You only need to
>> zero sreq, resp_size and mode, don't you (and at this point, memset
>> becomes superfluous)?
>>
> 
> The structures in unions are not zeroed by caller, also leaving them breaks
> virtio-scsi in my test.
> 
> FWIW, I will remove the "req->sreq = NULL;" two lines below in v3. At this
> point tuning these small fields are subtle optimization compared to the arrays,
> I say let's just simply keep the memset so that adding more fields in the
> future are also safe.

Perhaps the response fields have to be zeroed?  The request shouldn't
need it.  It can be done separately though---the VirtQueueElement is the
big one that we have to fix.

Paolo

      reply	other threads:[~2014-09-16  8:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-15  5:23 [Qemu-devel] [PATCH v2 0/2] virtio-scsi: Optimizing request allocation Fam Zheng
2014-09-15  5:23 ` [Qemu-devel] [PATCH v2 1/2] scsi: Optimize scsi_req_alloc Fam Zheng
2014-09-15 10:15   ` Paolo Bonzini
2014-09-15  5:23 ` [Qemu-devel] [PATCH v2 2/2] virtio-scsi: Optimize virtio_scsi_init_req Fam Zheng
2014-09-15 10:17   ` Paolo Bonzini
2014-09-16  7:16     ` Fam Zheng
2014-09-16  8:15       ` Paolo Bonzini [this message]

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=5417F1BC.3080408@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=famz@redhat.com \
    --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).