From: "Jan Beulich" Subject: [PATCH] switch rangeset's lock to rwlock Date: Fri, 12 Sep 2014 13:55:07 +0100 Message-ID: <5413094B020000780003480E@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartF8CDB33B.1__=" Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XSQNZ-0003oe-C3 for xen-devel@lists.xenproject.org; Fri, 12 Sep 2014 12:55:09 +0000 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 Cc: Ian Campbell , Keir Fraser , Ian Jackson , Tim Deegan 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. --=__PartF8CDB33B.1__= 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 --- With the widened use of rangesets I'd like to re-suggest this change which I had posted already a couple of years back. --- a/xen/common/rangeset.c +++ b/xen/common/rangeset.c @@ -28,7 +28,7 @@ struct rangeset { =20 /* Number of ranges that can be allocated */ long nr_ranges; - spinlock_t lock; + rwlock_t lock; =20 /* Pretty-printing name. */ char name[32]; @@ -120,7 +120,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); @@ -176,7 +176,7 @@ int rangeset_add_range( } =20 out: - spin_unlock(&r->lock); + write_unlock(&r->lock); return rc; } =20 @@ -188,7 +188,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); @@ -244,7 +244,7 @@ int rangeset_remove_range( } =20 out: - spin_unlock(&r->lock); + write_unlock(&r->lock); return rc; } =20 @@ -256,10 +256,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; } @@ -272,10 +272,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; } @@ -287,13 +287,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; } @@ -331,7 +331,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); r->nr_ranges =3D -1; =20 @@ -414,21 +414,21 @@ void rangeset_swap(struct rangeset *a, s =20 if ( a < b ) { - spin_lock(&a->lock); - spin_lock(&b->lock); + write_lock(&a->lock); + write_lock(&b->lock); } else { - spin_lock(&b->lock); - spin_lock(&a->lock); + write_lock(&b->lock); + write_lock(&a->lock); } =20 list_splice_init(&a->range_list, &tmp); list_splice_init(&b->range_list, &a->range_list); list_splice(&tmp, &b->range_list); =20 - spin_unlock(&a->lock); - spin_unlock(&b->lock); + write_unlock(&a->lock); + write_unlock(&b->lock); } =20 /***************************** @@ -446,7 +446,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 @@ -465,7 +465,7 @@ void rangeset_printk( =20 printk(" }"); =20 - spin_unlock(&r->lock); + read_unlock(&r->lock); } =20 void rangeset_domain_printk( --=__PartF8CDB33B.1__= Content-Type: text/plain; name="rangesets-rwlock.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="rangesets-rwlock.patch" switch rangeset's lock to rwlock=0A=0AAs a general library routine, it = should behave as efficiently as=0Apossible, even if at present no = significant contention is known here.=0A=0ASigned-off-by: Jan Beulich = =0A---=0AWith the widened use of rangesets I'd like to = re-suggest this change=0Awhich I had posted already a couple of years = back.=0A=0A--- a/xen/common/rangeset.c=0A+++ b/xen/common/rangeset.c=0A@@ = -28,7 +28,7 @@ struct rangeset {=0A =0A /* Number of ranges that can = be allocated */=0A long nr_ranges;=0A- spinlock_t = lock;=0A+ rwlock_t lock;=0A =0A /* Pretty-printing name. = */=0A char name[32];=0A@@ -120,7 +120,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@@ -176,7 +176,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@@ -188,7 +188,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@@ -244,7 +244,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@@ -256,10 +256,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@@ -272,10 +272,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@@ -287,13 = +287,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@@ -331,7 +331,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 r->nr_ranges =3D -1;=0A = =0A@@ -414,21 +414,21 @@ void rangeset_swap(struct rangeset *a, s=0A =0A = if ( a < b )=0A {=0A- spin_lock(&a->lock);=0A- = spin_lock(&b->lock);=0A+ write_lock(&a->lock);=0A+ write_lock= (&b->lock);=0A }=0A else=0A {=0A- spin_lock(&b->lock);= =0A- spin_lock(&a->lock);=0A+ write_lock(&b->lock);=0A+ = write_lock(&a->lock);=0A }=0A =0A list_splice_init(&a->range_list= , &tmp);=0A list_splice_init(&b->range_list, &a->range_list);=0A = list_splice(&tmp, &b->range_list);=0A =0A- spin_unlock(&a->lock);=0A- = spin_unlock(&b->lock);=0A+ write_unlock(&a->lock);=0A+ write_unlock(= &b->lock);=0A }=0A =0A /*****************************=0A@@ -446,7 +446,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@@ -465,7 +465,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 --=__PartF8CDB33B.1__= 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 --=__PartF8CDB33B.1__=--