Introduce separate lock for tokens to reduce ctl_lock scope.

This commit is contained in:
Alexander Motin 2015-06-20 11:20:25 +00:00
parent ffe11f412d
commit 2d8b28765c
2 changed files with 19 additions and 13 deletions

View File

@ -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

View File

@ -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 @@ tpc_process(struct tpc_list *list)
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 *ctsio)
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 *ctsio)
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 *ctsio)
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_scsiio *ctsio)
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_scsiio *ctsio)
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_scsiio *ctsio)
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);