Date: Sat, 20 Jun 2015 11:20:25 +0000 (UTC) From: Alexander Motin <mav@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r284639 - head/sys/cam/ctl Message-ID: <201506201120.t5KBKPwY079942@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: mav Date: Sat Jun 20 11:20:25 2015 New Revision: 284639 URL: https://svnweb.freebsd.org/changeset/base/284639 Log: Introduce separate lock for tokens to reduce ctl_lock scope. Modified: head/sys/cam/ctl/ctl_private.h head/sys/cam/ctl/ctl_tpc.c Modified: head/sys/cam/ctl/ctl_private.h ============================================================================== --- head/sys/cam/ctl/ctl_private.h Sat Jun 20 11:11:13 2015 (r284638) +++ head/sys/cam/ctl/ctl_private.h Sat Jun 20 11:20:25 2015 (r284639) @@ -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: head/sys/cam/ctl/ctl_tpc.c ============================================================================== --- head/sys/cam/ctl/ctl_tpc.c Sat Jun 20 11:11:13 2015 (r284638) +++ head/sys/cam/ctl/ctl_tpc.c Sat Jun 20 11:20:25 2015 (r284639) @@ -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?201506201120.t5KBKPwY079942>