Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 4 Jan 2009 19:22:53 +0000 (UTC)
From:      Ed Schouten <ed@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r186747 - head/sys/kern
Message-ID:  <200901041922.n04JMrLt072275@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ed
Date: Sun Jan  4 19:22:53 2009
New Revision: 186747
URL: http://svn.freebsd.org/changeset/base/186747

Log:
  Remove Giant locking from domains list.
  
  During boot, the domain list is locked with Giant. It is not possible to
  register any protocols after the system has booted, so the lock is only
  used to protect insertion of entries.
  
  There is already a mutex in uipc_domain.c called dom_mtx. Use this mutex
  to lock the list, instead of using Giant. It won't matter anything with
  respect to performance, but we'll never get rid of Giant if we don't
  remove from places where we don't need it.
  
  Approved by:	rwatson
  MFC after:	3 weeks

Modified:
  head/sys/kern/uipc_domain.c

Modified: head/sys/kern/uipc_domain.c
==============================================================================
--- head/sys/kern/uipc_domain.c	Sun Jan  4 19:16:36 2009	(r186746)
+++ head/sys/kern/uipc_domain.c	Sun Jan  4 19:22:53 2009	(r186747)
@@ -72,7 +72,7 @@ static void	pfslowtimo(void *);
 
 struct domain *domains;		/* registered protocol domains */
 int domain_init_status = 0;
-struct mtx dom_mtx;		/* domain list lock */
+static struct mtx dom_mtx;		/* domain list lock */
 MTX_SYSINIT(domain, &dom_mtx, "domain list", MTX_DEF);
 
 /*
@@ -338,13 +338,13 @@ found:
 	 * Protect us against races when two protocol registrations for
 	 * the same protocol happen at the same time.
 	 */
-	mtx_lock(&Giant);
+	mtx_lock(&dom_mtx);
 
 	/* The new protocol must not yet exist. */
 	for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
 		if ((pr->pr_type == npr->pr_type) &&
 		    (pr->pr_protocol == npr->pr_protocol)) {
-			mtx_unlock(&Giant);
+			mtx_unlock(&dom_mtx);
 			return (EEXIST);	/* XXX: Check only protocol? */
 		}
 		/* While here, remember the first free spacer. */
@@ -354,7 +354,7 @@ found:
 
 	/* If no free spacer is found we can't add the new protocol. */
 	if (fpr == NULL) {
-		mtx_unlock(&Giant);
+		mtx_unlock(&dom_mtx);
 		return (ENOMEM);
 	}
 
@@ -362,7 +362,7 @@ found:
 	bcopy(npr, fpr, sizeof(*fpr));
 
 	/* Job is done, no more protection required. */
-	mtx_unlock(&Giant);
+	mtx_unlock(&dom_mtx);
 
 	/* Initialize and activate the protocol. */
 	protosw_init(fpr);
@@ -398,13 +398,13 @@ found:
 	dpr = NULL;
 
 	/* Lock out everyone else while we are manipulating the protosw. */
-	mtx_lock(&Giant);
+	mtx_lock(&dom_mtx);
 
 	/* The protocol must exist and only once. */
 	for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
 		if ((pr->pr_type == type) && (pr->pr_protocol == protocol)) {
 			if (dpr != NULL) {
-				mtx_unlock(&Giant);
+				mtx_unlock(&dom_mtx);
 				return (EMLINK);   /* Should not happen! */
 			} else
 				dpr = pr;
@@ -413,7 +413,7 @@ found:
 
 	/* Protocol does not exist. */
 	if (dpr == NULL) {
-		mtx_unlock(&Giant);
+		mtx_unlock(&dom_mtx);
 		return (EPROTONOSUPPORT);
 	}
 
@@ -433,7 +433,7 @@ found:
 	dpr->pr_usrreqs = &nousrreqs;
 
 	/* Job is done, not more protection required. */
-	mtx_unlock(&Giant);
+	mtx_unlock(&dom_mtx);
 
 	return (0);
 }



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