Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 14 Oct 2016 02:03:53 +0000 (UTC)
From:      Sepherosa Ziehau <sephe@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r307244 - stable/10/sys/x86/x86
Message-ID:  <201610140203.u9E23rUU041270@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: sephe
Date: Fri Oct 14 02:03:53 2016
New Revision: 307244
URL: https://svnweb.freebsd.org/changeset/base/307244

Log:
  MFC 305722
  
      x86: Use sx lock for interrupt sources.
  
      - Certain pic_assign_cpu, e.g. msi_assign_cpu can have quite a long
        call chain.  For msi_assign_cpu, mutex makes complex PCI bridge
        drivers more tricky, e.g. sleep can note be called, etc, it will
        be pretty tricky for upcoming Hyper-V PCI bridge driver for PCI
        pass-through.
      - It is not used on any hot code path nor non-sleepable context, so
        sx should have the same effect as mutex.
  
      PIC list is still protected by mutex to keep suspend/resume work.
  
      Discussed with: jhb
      Reviewed by:    jhb
      Sponsored by:   Microsoft
      Differential Revision:  https://reviews.freebsd.org/D7784

Modified:
  stable/10/sys/x86/x86/intr_machdep.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/x86/x86/intr_machdep.c
==============================================================================
--- stable/10/sys/x86/x86/intr_machdep.c	Fri Oct 14 01:53:15 2016	(r307243)
+++ stable/10/sys/x86/x86/intr_machdep.c	Fri Oct 14 02:03:53 2016	(r307244)
@@ -46,6 +46,7 @@
 #include <sys/mutex.h>
 #include <sys/proc.h>
 #include <sys/smp.h>
+#include <sys/sx.h>
 #include <sys/syslog.h>
 #include <sys/systm.h>
 #include <machine/clock.h>
@@ -73,7 +74,8 @@ typedef void (*mask_fn)(void *);
 
 static int intrcnt_index;
 static struct intsrc *interrupt_sources[NUM_IO_INTS];
-static struct mtx intr_table_lock;
+static struct sx intrsrc_lock;
+static struct mtx intrpic_lock;
 static struct mtx intrcnt_lock;
 static TAILQ_HEAD(pics_head, pic) pics;
 
@@ -117,14 +119,14 @@ intr_register_pic(struct pic *pic)
 {
 	int error;
 
-	mtx_lock(&intr_table_lock);
+	mtx_lock(&intrpic_lock);
 	if (intr_pic_registered(pic))
 		error = EBUSY;
 	else {
 		TAILQ_INSERT_TAIL(&pics, pic, pics);
 		error = 0;
 	}
-	mtx_unlock(&intr_table_lock);
+	mtx_unlock(&intrpic_lock);
 	return (error);
 }
 
@@ -148,16 +150,16 @@ intr_register_source(struct intsrc *isrc
 	    vector);
 	if (error)
 		return (error);
-	mtx_lock(&intr_table_lock);
+	sx_xlock(&intrsrc_lock);
 	if (interrupt_sources[vector] != NULL) {
-		mtx_unlock(&intr_table_lock);
+		sx_xunlock(&intrsrc_lock);
 		intr_event_destroy(isrc->is_event);
 		return (EEXIST);
 	}
 	intrcnt_register(isrc);
 	interrupt_sources[vector] = isrc;
 	isrc->is_handlers = 0;
-	mtx_unlock(&intr_table_lock);
+	sx_xunlock(&intrsrc_lock);
 	return (0);
 }
 
@@ -181,14 +183,14 @@ intr_add_handler(const char *name, int v
 	error = intr_event_add_handler(isrc->is_event, name, filter, handler,
 	    arg, intr_priority(flags), flags, cookiep);
 	if (error == 0) {
-		mtx_lock(&intr_table_lock);
+		sx_xlock(&intrsrc_lock);
 		intrcnt_updatename(isrc);
 		isrc->is_handlers++;
 		if (isrc->is_handlers == 1) {
 			isrc->is_pic->pic_enable_intr(isrc);
 			isrc->is_pic->pic_enable_source(isrc);
 		}
-		mtx_unlock(&intr_table_lock);
+		sx_xunlock(&intrsrc_lock);
 	}
 	return (error);
 }
@@ -202,14 +204,14 @@ intr_remove_handler(void *cookie)
 	isrc = intr_handler_source(cookie);
 	error = intr_event_remove_handler(cookie);
 	if (error == 0) {
-		mtx_lock(&intr_table_lock);
+		sx_xlock(&intrsrc_lock);
 		isrc->is_handlers--;
 		if (isrc->is_handlers == 0) {
 			isrc->is_pic->pic_disable_source(isrc, PIC_NO_EOI);
 			isrc->is_pic->pic_disable_intr(isrc);
 		}
 		intrcnt_updatename(isrc);
-		mtx_unlock(&intr_table_lock);
+		sx_xunlock(&intrsrc_lock);
 	}
 	return (error);
 }
@@ -283,12 +285,12 @@ intr_resume(bool suspend_cancelled)
 #ifndef DEV_ATPIC
 	atpic_reset();
 #endif
-	mtx_lock(&intr_table_lock);
+	mtx_lock(&intrpic_lock);
 	TAILQ_FOREACH(pic, &pics, pics) {
 		if (pic->pic_resume != NULL)
 			pic->pic_resume(pic, suspend_cancelled);
 	}
-	mtx_unlock(&intr_table_lock);
+	mtx_unlock(&intrpic_lock);
 }
 
 void
@@ -296,12 +298,12 @@ intr_suspend(void)
 {
 	struct pic *pic;
 
-	mtx_lock(&intr_table_lock);
+	mtx_lock(&intrpic_lock);
 	TAILQ_FOREACH_REVERSE(pic, &pics, pics_head, pics) {
 		if (pic->pic_suspend != NULL)
 			pic->pic_suspend(pic);
 	}
-	mtx_unlock(&intr_table_lock);
+	mtx_unlock(&intrpic_lock);
 }
 
 static int
@@ -317,9 +319,9 @@ intr_assign_cpu(void *arg, u_char cpu)
 	 */
 	if (assign_cpu && cpu != NOCPU) {
 		isrc = arg;
-		mtx_lock(&intr_table_lock);
+		sx_xlock(&intrsrc_lock);
 		error = isrc->is_pic->pic_assign_cpu(isrc, cpu_apic_ids[cpu]);
-		mtx_unlock(&intr_table_lock);
+		sx_xunlock(&intrsrc_lock);
 	} else
 		error = 0;
 	return (error);
@@ -379,7 +381,8 @@ intr_init(void *dummy __unused)
 	intrcnt_setname("???", 0);
 	intrcnt_index = 1;
 	TAILQ_INIT(&pics);
-	mtx_init(&intr_table_lock, "intr sources", NULL, MTX_DEF);
+	mtx_init(&intrpic_lock, "intrpic", NULL, MTX_DEF);
+	sx_init(&intrsrc_lock, "intrsrc");
 	mtx_init(&intrcnt_lock, "intrcnt", NULL, MTX_SPIN);
 }
 SYSINIT(intr_init, SI_SUB_INTR, SI_ORDER_FIRST, intr_init, NULL);
@@ -527,7 +530,7 @@ intr_shuffle_irqs(void *arg __unused)
 		return;
 
 	/* Round-robin assign a CPU to each enabled source. */
-	mtx_lock(&intr_table_lock);
+	sx_xlock(&intrsrc_lock);
 	assign_cpu = 1;
 	for (i = 0; i < NUM_IO_INTS; i++) {
 		isrc = interrupt_sources[i];
@@ -548,7 +551,7 @@ intr_shuffle_irqs(void *arg __unused)
 
 		}
 	}
-	mtx_unlock(&intr_table_lock);
+	sx_xunlock(&intrsrc_lock);
 }
 SYSINIT(intr_shuffle_irqs, SI_SUB_SMP, SI_ORDER_SECOND, intr_shuffle_irqs,
     NULL);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201610140203.u9E23rUU041270>