From: "Jan Beulich" Subject: [PATCH 6/7] improve CSE in grant table code Date: Mon, 21 Sep 2009 13:11:27 +0100 Message-ID: <4AB7898F0200007800015F4D@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Return-path: Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org The grant table code had some particularly frequent repetitions of mfn_to_page() on each time the same input arguments. To help the compiler (which can do only a limited job on CSE), this adds explicit caching of the transformation result in a few places. Signed-off-by: Jan Beulich --- 2009-09-10.orig/xen/common/grant_table.c 2009-09-10 15:27:52.0000000= 00 +0200 +++ 2009-09-10/xen/common/grant_table.c 2009-09-10 17:19:24.000000000 = +0200 @@ -198,6 +198,7 @@ __gnttab_map_grant_ref( struct vcpu *led; int handle; unsigned long frame =3D 0, nr_gets =3D 0; + struct page_info *pg; int rc =3D GNTST_okay; u32 old_pin; u32 act_pin; @@ -346,12 +347,13 @@ __gnttab_map_grant_ref( =20 spin_unlock(&rd->grant_table->lock); =20 - if ( !mfn_valid(frame) || - (owner =3D page_get_owner_and_reference(mfn_to_page(frame))) = =3D=3D dom_io ) + pg =3D mfn_valid(frame) ? mfn_to_page(frame) : NULL; + + if ( !pg || (owner =3D page_get_owner_and_reference(pg)) =3D=3D = dom_io ) { /* Only needed the reference to confirm dom_io ownership. */ - if ( mfn_valid(frame) ) - put_page(mfn_to_page(frame)); + if ( pg ) + put_page(pg); =20 if ( paging_mode_external(ld) ) { @@ -377,7 +379,7 @@ __gnttab_map_grant_ref( else if ( owner =3D=3D rd ) { if ( gnttab_host_mapping_get_page_type(op, ld, rd) && - !get_page_type(mfn_to_page(frame), PGT_writable_page) ) + !get_page_type(pg, PGT_writable_page) ) goto could_not_pin; =20 nr_gets++; @@ -390,9 +392,9 @@ __gnttab_map_grant_ref( if ( op->flags & GNTMAP_device_map ) { nr_gets++; - (void)get_page(mfn_to_page(frame), rd); + (void)get_page(pg, rd); if ( !(op->flags & GNTMAP_readonly) ) - get_page_type(mfn_to_page(frame), PGT_writable_page); + get_page_type(pg, PGT_writable_page); } } } @@ -403,7 +405,7 @@ __gnttab_map_grant_ref( gdprintk(XENLOG_WARNING, "Could not pin grant frame %lx\n", frame); if ( owner !=3D NULL ) - put_page(mfn_to_page(frame)); + put_page(pg); rc =3D GNTST_general_error; goto undo_out; } @@ -442,14 +444,14 @@ __gnttab_map_grant_ref( if ( nr_gets > 1 ) { if ( !(op->flags & GNTMAP_readonly) ) - put_page_type(mfn_to_page(frame)); - put_page(mfn_to_page(frame)); + put_page_type(pg); + put_page(pg); } if ( nr_gets > 0 ) { if ( gnttab_host_mapping_get_page_type(op, ld, rd) ) - put_page_type(mfn_to_page(frame)); - put_page(mfn_to_page(frame)); + put_page_type(pg); + put_page(pg); } =20 spin_lock(&rd->grant_table->lock); @@ -621,6 +623,7 @@ __gnttab_unmap_common_complete(struct gn struct domain *ld, *rd; struct active_grant_entry *act; grant_entry_t *sha; + struct page_info *pg; =20 rd =3D op->rd; =20 @@ -651,14 +654,16 @@ __gnttab_unmap_common_complete(struct gn goto unmap_out; } =20 + pg =3D mfn_to_page(op->frame); + if ( op->flags & GNTMAP_device_map )=20 { if ( !is_iomem_page(act->frame) ) { if ( op->flags & GNTMAP_readonly ) - put_page(mfn_to_page(op->frame)); + put_page(pg); else - put_page_and_type(mfn_to_page(op->frame)); + put_page_and_type(pg); } } =20 @@ -676,8 +681,8 @@ __gnttab_unmap_common_complete(struct gn if ( !is_iomem_page(op->frame) )=20 { if ( gnttab_host_mapping_get_page_type(op, ld, rd) ) - put_page_type(mfn_to_page(op->frame)); - put_page(mfn_to_page(op->frame)); + put_page_type(pg); + put_page(pg); } } =20 @@ -1745,6 +1750,7 @@ gnttab_release_mappings( struct domain *rd; struct active_grant_entry *act; struct grant_entry *sha; + struct page_info *pg; =20 BUG_ON(!d->is_dying); =20 @@ -1772,6 +1778,7 @@ gnttab_release_mappings( =20 act =3D &active_entry(rd->grant_table, ref); sha =3D &shared_entry(rd->grant_table, ref); + pg =3D mfn_to_page(act->frame); =20 if ( map->flags & GNTMAP_readonly ) { @@ -1780,7 +1787,7 @@ gnttab_release_mappings( BUG_ON(!(act->pin & GNTPIN_devr_mask)); act->pin -=3D GNTPIN_devr_inc; if ( !is_iomem_page(act->frame) ) - put_page(mfn_to_page(act->frame)); + put_page(pg); } =20 if ( map->flags & GNTMAP_host_map ) @@ -1789,7 +1796,7 @@ gnttab_release_mappings( act->pin -=3D GNTPIN_hstr_inc; if ( gnttab_release_host_mappings(d) && !is_iomem_page(act->frame) ) - put_page(mfn_to_page(act->frame)); + put_page(pg); } } else @@ -1799,7 +1806,7 @@ gnttab_release_mappings( BUG_ON(!(act->pin & GNTPIN_devw_mask)); act->pin -=3D GNTPIN_devw_inc; if ( !is_iomem_page(act->frame) ) - put_page_and_type(mfn_to_page(act->frame)); + put_page_and_type(pg); } =20 if ( map->flags & GNTMAP_host_map ) @@ -1810,8 +1817,8 @@ gnttab_release_mappings( !is_iomem_page(act->frame) ) { if ( gnttab_host_mapping_get_page_type(map, d, rd) ) - put_page_type(mfn_to_page(act->frame)); - put_page(mfn_to_page(act->frame)); + put_page_type(pg); + put_page(pg); } } =20