提交 61e68b3f 编写于 作者: F Fam Zheng 提交者: Paolo Bonzini

scsi: Optimize scsi_req_alloc

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 zeroed fields to the end of the structure and use a
partial memset.

The explicitly initialized fields (by scsi_req_alloc or scsi_req_new)
are moved to the beginning of the structure, before sense buffer, to
skip the memset.

Also change g_malloc0 to g_slice_alloc.
Signed-off-by: NFam Zheng <famz@redhat.com>
Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
上级 380f649e
...@@ -551,8 +551,11 @@ SCSIRequest *scsi_req_alloc(const SCSIReqOps *reqops, SCSIDevice *d, ...@@ -551,8 +551,11 @@ SCSIRequest *scsi_req_alloc(const SCSIReqOps *reqops, SCSIDevice *d,
SCSIRequest *req; SCSIRequest *req;
SCSIBus *bus = scsi_bus_from_device(d); SCSIBus *bus = scsi_bus_from_device(d);
BusState *qbus = BUS(bus); 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->refcount = 1;
req->bus = bus; req->bus = bus;
req->dev = d; req->dev = d;
...@@ -560,7 +563,6 @@ SCSIRequest *scsi_req_alloc(const SCSIReqOps *reqops, SCSIDevice *d, ...@@ -560,7 +563,6 @@ SCSIRequest *scsi_req_alloc(const SCSIReqOps *reqops, SCSIDevice *d,
req->lun = lun; req->lun = lun;
req->hba_private = hba_private; req->hba_private = hba_private;
req->status = -1; req->status = -1;
req->sense_len = 0;
req->ops = reqops; req->ops = reqops;
object_ref(OBJECT(d)); object_ref(OBJECT(d));
object_ref(OBJECT(qbus->parent)); object_ref(OBJECT(qbus->parent));
...@@ -1603,7 +1605,7 @@ void scsi_req_unref(SCSIRequest *req) ...@@ -1603,7 +1605,7 @@ void scsi_req_unref(SCSIRequest *req)
} }
object_unref(OBJECT(req->dev)); object_unref(OBJECT(req->dev));
object_unref(OBJECT(qbus->parent)); object_unref(OBJECT(qbus->parent));
g_free(req); g_slice_free1(req->ops->size, req);
} }
} }
......
...@@ -50,17 +50,24 @@ struct SCSIRequest { ...@@ -50,17 +50,24 @@ struct SCSIRequest {
uint32_t tag; uint32_t tag;
uint32_t lun; uint32_t lun;
uint32_t status; uint32_t status;
void *hba_private;
size_t resid; size_t resid;
SCSICommand cmd; SCSICommand cmd;
/* 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];
uint32_t sense_len;
bool enqueued;
bool io_canceled;
bool retry;
bool dma_started;
BlockDriverAIOCB *aiocb; BlockDriverAIOCB *aiocb;
QEMUSGList *sg; 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; QTAILQ_ENTRY(SCSIRequest) next;
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册