Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 25 Jun 2015 07:09:39 +0000 (UTC)
From:      Alexander Motin <mav@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: r284796 - stable/10/sys/cam/ctl
Message-ID:  <201506250709.t5P79dPd087235@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mav
Date: Thu Jun 25 07:09:39 2015
New Revision: 284796
URL: https://svnweb.freebsd.org/changeset/base/284796

Log:
  MFC r284639: Introduce separate lock for tokens to reduce ctl_lock scope.

Modified:
  stable/10/sys/cam/ctl/ctl_private.h
  stable/10/sys/cam/ctl/ctl_tpc.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/cam/ctl/ctl_private.h
==============================================================================
--- stable/10/sys/cam/ctl/ctl_private.h	Thu Jun 25 07:08:46 2015	(r284795)
+++ stable/10/sys/cam/ctl/ctl_private.h	Thu Jun 25 07:09:39 2015	(r284796)
@@ -494,6 +494,7 @@ struct ctl_softc {
 	struct ctl_thread threads[CTL_MAX_THREADS];
 	TAILQ_HEAD(tpc_tokens, tpc_token) tpc_tokens;
 	struct callout tpc_timeout;
+	struct mtx tpc_lock;
 };
 
 #ifdef _KERNEL

Modified: stable/10/sys/cam/ctl/ctl_tpc.c
==============================================================================
--- stable/10/sys/cam/ctl/ctl_tpc.c	Thu Jun 25 07:08:46 2015	(r284795)
+++ stable/10/sys/cam/ctl/ctl_tpc.c	Thu Jun 25 07:09:39 2015	(r284796)
@@ -167,6 +167,7 @@ tpc_timeout(void *arg)
 	}
 
 	/* Free inactive ROD tokens with expired timeout. */
+	mtx_lock(&softc->tpc_lock);
 	TAILQ_FOREACH_SAFE(token, &softc->tpc_tokens, links, ttoken) {
 		if (token->active ||
 		    time_uptime < token->last_active + token->timeout + 1)
@@ -175,6 +176,7 @@ tpc_timeout(void *arg)
 		free(token->params, M_CTL);
 		free(token, M_CTL);
 	}
+	mtx_unlock(&softc->tpc_lock);
 	callout_schedule(&softc->tpc_timeout, hz);
 }
 
@@ -182,6 +184,7 @@ void
 ctl_tpc_init(struct ctl_softc *softc)
 {
 
+	mtx_init(&softc->tpc_lock, "CTL TPC mutex", NULL, MTX_DEF);
 	TAILQ_INIT(&softc->tpc_tokens);
 	callout_init_mtx(&softc->tpc_timeout, &softc->ctl_lock, 0);
 	callout_reset(&softc->tpc_timeout, hz, tpc_timeout, softc);
@@ -195,13 +198,14 @@ ctl_tpc_shutdown(struct ctl_softc *softc
 	callout_drain(&softc->tpc_timeout);
 
 	/* Free ROD tokens. */
-	mtx_lock(&softc->ctl_lock);
+	mtx_lock(&softc->tpc_lock);
 	while ((token = TAILQ_FIRST(&softc->tpc_tokens)) != NULL) {
 		TAILQ_REMOVE(&softc->tpc_tokens, token, links);
 		free(token->params, M_CTL);
 		free(token, M_CTL);
 	}
-	mtx_unlock(&softc->ctl_lock);
+	mtx_unlock(&softc->tpc_lock);
+	mtx_destroy(&softc->tpc_lock);
 }
 
 void
@@ -227,7 +231,7 @@ ctl_tpc_lun_shutdown(struct ctl_lun *lun
 	}
 
 	/* Free ROD tokens for this LUN. */
-	mtx_assert(&softc->ctl_lock, MA_OWNED);
+	mtx_lock(&softc->tpc_lock);
 	TAILQ_FOREACH_SAFE(token, &softc->tpc_tokens, links, ttoken) {
 		if (token->lun != lun->lun || token->active)
 			continue;
@@ -235,6 +239,7 @@ ctl_tpc_lun_shutdown(struct ctl_lun *lun
 		free(token->params, M_CTL);
 		free(token, M_CTL);
 	}
+	mtx_unlock(&softc->tpc_lock);
 }
 
 int
@@ -1394,10 +1399,10 @@ done:
 	free(list->params, M_CTL);
 	list->params = NULL;
 	if (list->token) {
-		mtx_lock(&softc->ctl_lock);
+		mtx_lock(&softc->tpc_lock);
 		if (--list->token->active == 0)
 			list->token->last_active = time_uptime;
-		mtx_unlock(&softc->ctl_lock);
+		mtx_unlock(&softc->tpc_lock);
 		list->token = NULL;
 	}
 	mtx_lock(&lun->lun_lock);
@@ -1991,9 +1996,9 @@ ctl_populate_token(struct ctl_scsiio *ct
 	list->curseg = 0;
 	list->completed = 1;
 	list->last_active = time_uptime;
-	mtx_lock(&softc->ctl_lock);
+	mtx_lock(&softc->tpc_lock);
 	TAILQ_INSERT_TAIL(&softc->tpc_tokens, token, links);
-	mtx_unlock(&softc->ctl_lock);
+	mtx_unlock(&softc->tpc_lock);
 	ctl_set_success(ctsio);
 	ctl_done((union ctl_io *)ctsio);
 	return (CTL_RETVAL_COMPLETE);
@@ -2100,7 +2105,7 @@ ctl_write_using_token(struct ctl_scsiio 
 		return (CTL_RETVAL_COMPLETE);
 	}
 
-	mtx_lock(&softc->ctl_lock);
+	mtx_lock(&softc->tpc_lock);
 	TAILQ_FOREACH(token, &softc->tpc_tokens, links) {
 		if (memcmp(token->token, data->rod_token,
 		    sizeof(data->rod_token)) == 0)
@@ -2112,7 +2117,7 @@ ctl_write_using_token(struct ctl_scsiio 
 		if (data->flags & EC_WUT_DEL_TKN)
 			token->timeout = 0;
 	}
-	mtx_unlock(&softc->ctl_lock);
+	mtx_unlock(&softc->tpc_lock);
 	if (token == NULL) {
 		mtx_lock(&lun->lun_lock);
 		TAILQ_REMOVE(&lun->tpc_lists, list, links);
@@ -2254,10 +2259,10 @@ ctl_report_all_rod_tokens(struct ctl_scs
 	retval = CTL_RETVAL_COMPLETE;
 
 	tokens = 0;
-	mtx_lock(&softc->ctl_lock);
+	mtx_lock(&softc->tpc_lock);
 	TAILQ_FOREACH(token, &softc->tpc_tokens, links)
 		tokens++;
-	mtx_unlock(&softc->ctl_lock);
+	mtx_unlock(&softc->tpc_lock);
 	if (tokens > 512)
 		tokens = 512;
 
@@ -2282,7 +2287,7 @@ ctl_report_all_rod_tokens(struct ctl_scs
 
 	data = (struct scsi_report_all_rod_tokens_data *)ctsio->kern_data_ptr;
 	i = 0;
-	mtx_lock(&softc->ctl_lock);
+	mtx_lock(&softc->tpc_lock);
 	TAILQ_FOREACH(token, &softc->tpc_tokens, links) {
 		if (i >= tokens)
 			break;
@@ -2290,7 +2295,7 @@ ctl_report_all_rod_tokens(struct ctl_scs
 		    token->token, 96);
 		i++;
 	}
-	mtx_unlock(&softc->ctl_lock);
+	mtx_unlock(&softc->tpc_lock);
 	scsi_ulto4b(sizeof(*data) - 4 + i * 96, data->available_data);
 /*
 	printf("RART tokens=%d\n", i);



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