From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Jan Beulich" Subject: [PATCH] switch rangeset's lock to rwlock Date: Fri, 25 Mar 2011 16:49:47 +0000 Message-ID: <4D8CD5BB02000078000386C1@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartD5F919BB.0__=" Return-path: 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 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. --=__PartD5F919BB.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline As a general library routine, it should behave as efficiently as possible, even if at present no significant contention is known here. Signed-off-by: Jan Beulich --- a/xen/common/rangeset.c +++ b/xen/common/rangeset.c @@ -25,7 +25,7 @@ struct rangeset { =20 /* Ordered list of ranges contained in this set, and protecting lock. = */ struct list_head range_list; - spinlock_t lock; + rwlock_t lock; =20 /* Pretty-printing name. */ char name[32]; @@ -103,7 +103,7 @@ int rangeset_add_range( =20 ASSERT(s <=3D e); =20 - spin_lock(&r->lock); + write_lock(&r->lock); =20 x =3D find_range(r, s); y =3D find_range(r, e); @@ -159,7 +159,7 @@ int rangeset_add_range( } =20 out: - spin_unlock(&r->lock); + write_unlock(&r->lock); return rc; } =20 @@ -175,7 +175,7 @@ int rangeset_remove_range( =20 ASSERT(s <=3D e); =20 - spin_lock(&r->lock); + write_lock(&r->lock); =20 x =3D find_range(r, s); y =3D find_range(r, e); @@ -231,7 +231,7 @@ int rangeset_remove_range( } =20 out: - spin_unlock(&r->lock); + write_unlock(&r->lock); return rc; } =20 @@ -243,10 +243,10 @@ int rangeset_contains_range( =20 ASSERT(s <=3D e); =20 - spin_lock(&r->lock); + read_lock(&r->lock); x =3D find_range(r, s); contains =3D (x && (x->e >=3D e)); - spin_unlock(&r->lock); + read_unlock(&r->lock); =20 return contains; } @@ -259,10 +259,10 @@ int rangeset_overlaps_range( =20 ASSERT(s <=3D e); =20 - spin_lock(&r->lock); + read_lock(&r->lock); x =3D find_range(r, e); overlaps =3D (x && (s <=3D x->e)); - spin_unlock(&r->lock); + read_unlock(&r->lock); =20 return overlaps; } @@ -274,13 +274,13 @@ int rangeset_report_ranges( struct range *x; int rc =3D 0; =20 - spin_lock(&r->lock); + read_lock(&r->lock); =20 for ( x =3D find_range(r, s); x && (x->s <=3D e) && !rc; x =3D = next_range(r, x) ) if ( x->e >=3D s ) rc =3D cb(max(x->s, s), min(x->e, e), ctxt); =20 - spin_unlock(&r->lock); + read_unlock(&r->lock); =20 return rc; } @@ -318,7 +318,7 @@ struct rangeset *rangeset_new( if ( r =3D=3D NULL ) return NULL; =20 - spin_lock_init(&r->lock); + rwlock_init(&r->lock); INIT_LIST_HEAD(&r->range_list); =20 BUG_ON(flags & ~RANGESETF_prettyprint_hex); @@ -403,7 +403,7 @@ void rangeset_printk( int nr_printed =3D 0; struct range *x; =20 - spin_lock(&r->lock); + read_lock(&r->lock); =20 printk("%-10s {", r->name); =20 @@ -422,7 +422,7 @@ void rangeset_printk( =20 printk(" }"); =20 - spin_unlock(&r->lock); + read_unlock(&r->lock); } =20 void rangeset_domain_printk( --=__PartD5F919BB.0__= Content-Type: text/plain; name="rangesets-rwlock.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="rangesets-rwlock.patch" As a general library routine, it should behave as efficiently as=0Apossible= , even if at present no significant contention is known here.=0A=0ASigned-o= ff-by: Jan Beulich =0A=0A--- a/xen/common/rangeset.c= =0A+++ b/xen/common/rangeset.c=0A@@ -25,7 +25,7 @@ struct rangeset {=0A = =0A /* Ordered list of ranges contained in this set, and protecting = lock. */=0A struct list_head range_list;=0A- spinlock_t = lock;=0A+ rwlock_t lock;=0A =0A /* Pretty-printing name. = */=0A char name[32];=0A@@ -103,7 +103,7 @@ int rangeset_add= _range(=0A =0A ASSERT(s <=3D e);=0A =0A- spin_lock(&r->lock);=0A+ = write_lock(&r->lock);=0A =0A x =3D find_range(r, s);=0A y =3D = find_range(r, e);=0A@@ -159,7 +159,7 @@ int rangeset_add_range(=0A = }=0A =0A out:=0A- spin_unlock(&r->lock);=0A+ write_unlock(&r->lock);= =0A return rc;=0A }=0A =0A@@ -175,7 +175,7 @@ int rangeset_remove_range= (=0A =0A ASSERT(s <=3D e);=0A =0A- spin_lock(&r->lock);=0A+ = write_lock(&r->lock);=0A =0A x =3D find_range(r, s);=0A y =3D = find_range(r, e);=0A@@ -231,7 +231,7 @@ int rangeset_remove_range(=0A = }=0A =0A out:=0A- spin_unlock(&r->lock);=0A+ write_unlock(&r->lock);= =0A return rc;=0A }=0A =0A@@ -243,10 +243,10 @@ int rangeset_contains_r= ange(=0A =0A ASSERT(s <=3D e);=0A =0A- spin_lock(&r->lock);=0A+ = read_lock(&r->lock);=0A x =3D find_range(r, s);=0A contains =3D (x = && (x->e >=3D e));=0A- spin_unlock(&r->lock);=0A+ read_unlock(&r->loc= k);=0A =0A return contains;=0A }=0A@@ -259,10 +259,10 @@ int rangeset_o= verlaps_range(=0A =0A ASSERT(s <=3D e);=0A =0A- spin_lock(&r->lock);= =0A+ read_lock(&r->lock);=0A x =3D find_range(r, e);=0A = overlaps =3D (x && (s <=3D x->e));=0A- spin_unlock(&r->lock);=0A+ = read_unlock(&r->lock);=0A =0A return overlaps;=0A }=0A@@ -274,13 = +274,13 @@ int rangeset_report_ranges(=0A struct range *x;=0A int = rc =3D 0;=0A =0A- spin_lock(&r->lock);=0A+ read_lock(&r->lock);=0A = =0A for ( x =3D find_range(r, s); x && (x->s <=3D e) && !rc; x =3D = next_range(r, x) )=0A if ( x->e >=3D s )=0A rc =3D = cb(max(x->s, s), min(x->e, e), ctxt);=0A =0A- spin_unlock(&r->lock);=0A+= read_unlock(&r->lock);=0A =0A return rc;=0A }=0A@@ -318,7 +318,7 = @@ struct rangeset *rangeset_new(=0A if ( r =3D=3D NULL )=0A = return NULL;=0A =0A- spin_lock_init(&r->lock);=0A+ rwlock_init(&r->lo= ck);=0A INIT_LIST_HEAD(&r->range_list);=0A =0A BUG_ON(flags & = ~RANGESETF_prettyprint_hex);=0A@@ -403,7 +403,7 @@ void rangeset_printk(=0A= int nr_printed =3D 0;=0A struct range *x;=0A =0A- spin_lock(&r-= >lock);=0A+ read_lock(&r->lock);=0A =0A printk("%-10s {", = r->name);=0A =0A@@ -422,7 +422,7 @@ void rangeset_printk(=0A =0A = printk(" }");=0A =0A- spin_unlock(&r->lock);=0A+ read_unlock(&r->lock= );=0A }=0A =0A void rangeset_domain_printk(=0A --=__PartD5F919BB.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.xensource.com http://lists.xensource.com/xen-devel --=__PartD5F919BB.0__=--