From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50514) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XTnvl-00075k-Cs for qemu-devel@nongnu.org; Tue, 16 Sep 2014 04:16:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XTnvf-0000kM-0K for qemu-devel@nongnu.org; Tue, 16 Sep 2014 04:16:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:1353) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XTnve-0000k9-Ci for qemu-devel@nongnu.org; Tue, 16 Sep 2014 04:16:02 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s8G8Fwwc030275 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Tue, 16 Sep 2014 04:15:59 -0400 Message-ID: <5417F1BC.3080408@redhat.com> Date: Tue, 16 Sep 2014 10:15:56 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1410758605-29375-1-git-send-email-famz@redhat.com> <1410758605-29375-3-git-send-email-famz@redhat.com> <5416BCB0.30502@redhat.com> <20140916071611.GA21826@fam-t430.nay.redhat.com> In-Reply-To: <20140916071611.GA21826@fam-t430.nay.redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2 2/2] virtio-scsi: Optimize virtio_scsi_init_req List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng Cc: qemu-devel@nongnu.org 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