From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54471) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XS1Qw-0005jm-E7 for qemu-devel@nongnu.org; Thu, 11 Sep 2014 06:17:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XS1Qo-0000Fp-Ir for qemu-devel@nongnu.org; Thu, 11 Sep 2014 06:16:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:27910) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XS1Qo-0000Fe-9Y for qemu-devel@nongnu.org; Thu, 11 Sep 2014 06:16:50 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s8BAGnkp018309 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 11 Sep 2014 06:16:49 -0400 From: Fam Zheng Date: Thu, 11 Sep 2014 18:16:38 +0800 Message-Id: <1410430599-27540-2-git-send-email-famz@redhat.com> In-Reply-To: <1410430599-27540-1-git-send-email-famz@redhat.com> References: <1410430599-27540-1-git-send-email-famz@redhat.com> Subject: [Qemu-devel] [PATCH 1/2] scsi: Optimize scsi_req_alloc List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Paolo Bonzini Zeroing sense buffer for each scsi request is not efficient, we can just leave it uninitialized because sense_len is set to 0. Move the implicitly zeroes fields to the end of the structure and use a partial memset. Also change g_malloc0 to g_slice_alloc. Signed-off-by: Fam Zheng --- hw/scsi/scsi-bus.c | 7 +++++-- include/hw/scsi/scsi.h | 21 ++++++++++++++------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c index 954c607..71b45c0 100644 --- a/hw/scsi/scsi-bus.c +++ b/hw/scsi/scsi-bus.c @@ -551,8 +551,11 @@ SCSIRequest *scsi_req_alloc(const SCSIReqOps *reqops, SCSIDevice *d, SCSIRequest *req; SCSIBus *bus = scsi_bus_from_device(d); BusState *qbus = BUS(bus); + const int memset_off = offsetof(SCSIRequest, sense) + + sizeof(req->sense); - req = g_malloc0(reqops->size); + req = g_slice_alloc(reqops->size); + memset((uint8_t *)req + memset_off, 0, reqops->size - memset_off); req->refcount = 1; req->bus = bus; req->dev = d; @@ -1603,7 +1606,7 @@ void scsi_req_unref(SCSIRequest *req) } object_unref(OBJECT(req->dev)); object_unref(OBJECT(qbus->parent)); - g_free(req); + g_slice_free1(req->ops->size, req); } } diff --git a/include/hw/scsi/scsi.h b/include/hw/scsi/scsi.h index 2e3a8f9..889f659 100644 --- a/include/hw/scsi/scsi.h +++ b/include/hw/scsi/scsi.h @@ -50,17 +50,24 @@ struct SCSIRequest { uint32_t tag; uint32_t lun; uint32_t status; + uint32_t sense_len; + + /* Note: + * - fields before sense are initialized by scsi_req_alloc; + * - sense[] is uninitialized; + * - fields after sense are memset to 0 by scsi_req_alloc. + * */ + + uint8_t sense[SCSI_SENSE_BUF_SIZE]; + bool enqueued; + bool io_canceled; + bool retry; + bool dma_started; + void *hba_private; size_t resid; SCSICommand cmd; BlockDriverAIOCB *aiocb; QEMUSGList *sg; - bool dma_started; - uint8_t sense[SCSI_SENSE_BUF_SIZE]; - uint32_t sense_len; - bool enqueued; - bool io_canceled; - bool retry; - void *hba_private; QTAILQ_ENTRY(SCSIRequest) next; }; -- 1.9.3