From: "Jan Beulich" Subject: [PATCH] linux-2.6.18/blkback: streamline main processing loop Date: Mon, 26 Mar 2012 16:38:51 +0100 Message-ID: <4F70A9AC020000780007AF2C@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part416F739B.0__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part416F739B.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline - move stats updates into dispatch_rw_block_io(), allowing to fold common cases - don't alloc pending_req_t instance when none is going to be needed (particularly relevant since they are a global resource) - use type-safe assignment rather than memcpy() for obtaining native requests from ring --- a/drivers/xen/blkback/blkback.c +++ b/drivers/xen/blkback/blkback.c @@ -315,32 +315,21 @@ static int _do_block_io_op(blkif_t *blki blkif_request_t req; pending_req_t *pending_req; RING_IDX rc, rp; - int more_to_do =3D 0; =20 rc =3D blk_rings->common.req_cons; rp =3D blk_rings->common.sring->req_prod; rmb(); /* Ensure we see queued requests up to 'rp'. */ =20 - while ((rc !=3D rp)) { - + while (rc !=3D rp) { if (RING_REQUEST_CONS_OVERFLOW(&blk_rings->common, rc)) break; =20 - if (kthread_should_stop()) { - more_to_do =3D 1; - break; - } - - pending_req =3D alloc_req(); - if (NULL =3D=3D pending_req) { - blkif->st_oo_req++; - more_to_do =3D 1; - break; - } + if (kthread_should_stop()) + return 1; =20 switch (blkif->blk_protocol) { case BLKIF_PROTOCOL_NATIVE: - memcpy(&req, RING_GET_REQUEST(&blk_rings->native, = rc), sizeof(req)); + req =3D *RING_GET_REQUEST(&blk_rings->native, rc); break; case BLKIF_PROTOCOL_X86_32: blkif_get_x86_32_req(&req, RING_GET_REQUEST(&blk_ri= ngs->x86_32, rc)); @@ -351,32 +340,37 @@ static int _do_block_io_op(blkif_t *blki default: BUG(); } - blk_rings->common.req_cons =3D ++rc; /* before make_respons= e() */ =20 - /* Apply all sanity checks to /private copy/ of request. = */ - barrier(); + ++rc; =20 switch (req.operation) { case BLKIF_OP_READ: - blkif->st_rd_req++; - dispatch_rw_block_io(blkif, &req, pending_req); - break; - case BLKIF_OP_WRITE_BARRIER: - blkif->st_br_req++; - /* fall through */ case BLKIF_OP_WRITE: - blkif->st_wr_req++; + case BLKIF_OP_WRITE_BARRIER: + pending_req =3D alloc_req(); + if (!pending_req) { + blkif->st_oo_req++; + return 1; + } + + /* before make_response() */ + blk_rings->common.req_cons =3D rc; + + /* Apply all sanity checks to /private copy/ of = request. */ + barrier(); + dispatch_rw_block_io(blkif, &req, pending_req); break; default: /* A good sign something is wrong: sleep for a = while to * avoid excessive CPU consumption by a bad guest. = */ msleep(1); + blk_rings->common.req_cons =3D rc; + barrier(); DPRINTK("error: unknown block io operation = [%d]\n", req.operation); make_response(blkif, req.id, req.operation, BLKIF_RSP_ERROR); - free_req(pending_req); break; } =20 @@ -384,7 +378,7 @@ static int _do_block_io_op(blkif_t *blki cond_resched(); } =20 - return more_to_do; + return 0; } =20 static int @@ -421,12 +415,15 @@ static void dispatch_rw_block_io(blkif_t =20 switch (req->operation) { case BLKIF_OP_READ: + blkif->st_rd_req++; operation =3D READ; break; case BLKIF_OP_WRITE: + blkif->st_wr_req++; operation =3D WRITE; break; case BLKIF_OP_WRITE_BARRIER: + blkif->st_br_req++; operation =3D WRITE_BARRIER; break; default: @@ -559,7 +556,7 @@ static void dispatch_rw_block_io(blkif_t =20 if (operation =3D=3D READ) blkif->st_rd_sect +=3D preq.nr_sects; - else if (operation =3D=3D WRITE || operation =3D=3D WRITE_BARRIER) + else blkif->st_wr_sect +=3D preq.nr_sects; =20 return; --=__Part416F739B.0__= Content-Type: text/plain; name="xen-blkback-streamline-main-loop.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="xen-blkback-streamline-main-loop.patch" blkback: streamline main processing loop=0A=0A- move stats updates into = dispatch_rw_block_io(), allowing to fold=0A common cases=0A- don't alloc = pending_req_t instance when none is going to be needed=0A (particularly = relevant since they are a global resource)=0A- use type-safe assignment = rather than memcpy() for obtaining native=0A requests from ring=0A=0A--- = a/drivers/xen/blkback/blkback.c=0A+++ b/drivers/xen/blkback/blkback.c=0A@@ = -315,32 +315,21 @@ static int _do_block_io_op(blkif_t *blki=0A blkif_reque= st_t req;=0A pending_req_t *pending_req;=0A RING_IDX rc, rp;=0A- = int more_to_do =3D 0;=0A =0A rc =3D blk_rings->common.req_cons;=0A rp = =3D blk_rings->common.sring->req_prod;=0A rmb(); /* Ensure we see = queued requests up to 'rp'. */=0A =0A- while ((rc !=3D rp)) {=0A-=0A+ = while (rc !=3D rp) {=0A if (RING_REQUEST_CONS_OVERFLOW(&blk= _rings->common, rc))=0A break;=0A =0A- if = (kthread_should_stop()) {=0A- more_to_do =3D 1;=0A- = break;=0A- }=0A-=0A- pending_req =3D = alloc_req();=0A- if (NULL =3D=3D pending_req) {=0A- = blkif->st_oo_req++;=0A- more_to_do =3D 1;=0A- = break;=0A- }=0A+ if (kthread_should_stop())= =0A+ return 1;=0A =0A switch (blkif->blk_= protocol) {=0A case BLKIF_PROTOCOL_NATIVE:=0A- = memcpy(&req, RING_GET_REQUEST(&blk_rings->native, rc), sizeof(req));=0A+ = req =3D *RING_GET_REQUEST(&blk_rings->native, rc);=0A = break;=0A case BLKIF_PROTOCOL_X86_32:=0A = blkif_get_x86_32_req(&req, RING_GET_REQUEST(&blk_rings->x86_32, rc));=0A@@ = -351,32 +340,37 @@ static int _do_block_io_op(blkif_t *blki=0A = default:=0A BUG();=0A }=0A- = blk_rings->common.req_cons =3D ++rc; /* before make_response() */=0A =0A- = /* Apply all sanity checks to /private copy/ of request. */=0A- = barrier();=0A+ ++rc;=0A =0A switch (req.operation) = {=0A case BLKIF_OP_READ:=0A- blkif->st_rd_req++;= =0A- dispatch_rw_block_io(blkif, &req, pending_req);=0A-= break;=0A- case BLKIF_OP_WRITE_BARRIER= :=0A- blkif->st_br_req++;=0A- /* fall = through */=0A case BLKIF_OP_WRITE:=0A- = blkif->st_wr_req++;=0A+ case BLKIF_OP_WRITE_BARRIER:=0A+ = pending_req =3D alloc_req();=0A+ if = (!pending_req) {=0A+ blkif->st_oo_req++;=0A+ = return 1;=0A+ }=0A+=0A+ = /* before make_response() */=0A+ blk_rings->common.r= eq_cons =3D rc;=0A+=0A+ /* Apply all sanity checks to = /private copy/ of request. */=0A+ barrier();=0A+=0A = dispatch_rw_block_io(blkif, &req, pending_req);=0A = break;=0A default:=0A /* A good = sign something is wrong: sleep for a while to=0A * = avoid excessive CPU consumption by a bad guest. */=0A = msleep(1);=0A+ blk_rings->common.req_cons =3D rc;=0A+ = barrier();=0A DPRINTK("error: unknown block io = operation [%d]\n",=0A req.operation);=0A = make_response(blkif, req.id, req.operation,=0A = BLKIF_RSP_ERROR);=0A- free_req(pending_req);=0A = break;=0A }=0A =0A@@ -384,7 +378,7 @@ static = int _do_block_io_op(blkif_t *blki=0A cond_resched();=0A = }=0A =0A- return more_to_do;=0A+ return 0;=0A }=0A =0A static = int=0A@@ -421,12 +415,15 @@ static void dispatch_rw_block_io(blkif_t=0A = =0A switch (req->operation) {=0A case BLKIF_OP_READ:=0A+ = blkif->st_rd_req++;=0A operation =3D READ;=0A break;=0A = case BLKIF_OP_WRITE:=0A+ blkif->st_wr_req++;=0A = operation =3D WRITE;=0A break;=0A case BLKIF_OP_WRITE= _BARRIER:=0A+ blkif->st_br_req++;=0A operation =3D = WRITE_BARRIER;=0A break;=0A default:=0A@@ -559,7 = +556,7 @@ static void dispatch_rw_block_io(blkif_t=0A =0A if = (operation =3D=3D READ)=0A blkif->st_rd_sect +=3D preq.nr_sect= s;=0A- else if (operation =3D=3D WRITE || operation =3D=3D WRITE_BARRIER)= =0A+ else=0A blkif->st_wr_sect +=3D preq.nr_sects;=0A = =0A return;=0A --=__Part416F739B.0__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__Part416F739B.0__=--