From owner-dev-commits-src-branches@freebsd.org Wed Mar 24 01:26:07 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 9DC4A57C5D3; Wed, 24 Mar 2021 01:26:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4F4rCz44M4z4mVb; Wed, 24 Mar 2021 01:26:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 7EA6A378D; Wed, 24 Mar 2021 01:26:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 12O1Q7Le000740; Wed, 24 Mar 2021 01:26:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 12O1Q7rl000739; Wed, 24 Mar 2021 01:26:07 GMT (envelope-from git) Date: Wed, 24 Mar 2021 01:26:07 GMT Message-Id: <202103240126.12O1Q7rl000739@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Alexander Motin Subject: git: ed407c92e43f - stable/13 - nvme: Replace potentially long DELAY() with pause(). MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mav X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: ed407c92e43f88652365c84dc54098a7ed479471 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Mar 2021 01:26:07 -0000 The branch stable/13 has been updated by mav: URL: https://cgit.FreeBSD.org/src/commit/?id=ed407c92e43f88652365c84dc54098a7ed479471 commit ed407c92e43f88652365c84dc54098a7ed479471 Author: Alexander Motin AuthorDate: 2021-03-17 14:30:40 +0000 Commit: Alexander Motin CommitDate: 2021-03-24 01:26:00 +0000 nvme: Replace potentially long DELAY() with pause(). In some cases like broken hardware nvme(4) may wait minutes for controller response before timeout. Doing so in a tight spin loop made whole system unresponsive. Reviewed by: imp MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D29309 Sponsored by: iXsystems, Inc. (cherry picked from commit 4fbbe523653b6d2a0186aca38224efcab941deaa) --- sys/dev/nvme/nvme_ctrlr.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/sys/dev/nvme/nvme_ctrlr.c b/sys/dev/nvme/nvme_ctrlr.c index 351c6839a6f6..9f86e3a8c846 100644 --- a/sys/dev/nvme/nvme_ctrlr.c +++ b/sys/dev/nvme/nvme_ctrlr.c @@ -255,10 +255,9 @@ nvme_ctrlr_fail_req_task(void *arg, int pending) static int nvme_ctrlr_wait_for_ready(struct nvme_controller *ctrlr, int desired_val) { - int ms_waited; + int timeout = ticks + (uint64_t)ctrlr->ready_timeout_in_ms * hz / 1000; uint32_t csts; - ms_waited = 0; while (1) { csts = nvme_mmio_read_4(ctrlr, csts); if (csts == NVME_GONE) /* Hot unplug. */ @@ -266,12 +265,12 @@ nvme_ctrlr_wait_for_ready(struct nvme_controller *ctrlr, int desired_val) if (((csts >> NVME_CSTS_REG_RDY_SHIFT) & NVME_CSTS_REG_RDY_MASK) == desired_val) break; - if (ms_waited++ > ctrlr->ready_timeout_in_ms) { + if (timeout - ticks < 0) { nvme_printf(ctrlr, "controller ready did not become %d " "within %d ms\n", desired_val, ctrlr->ready_timeout_in_ms); return (ENXIO); } - DELAY(1000); + pause("nvmerdy", 1); } return (0); @@ -410,7 +409,7 @@ nvme_ctrlr_hw_reset(struct nvme_controller *ctrlr) nvme_ctrlr_disable_qpairs(ctrlr); - DELAY(100*1000); + pause("nvmehwreset", hz / 10); err = nvme_ctrlr_disable(ctrlr); if (err != 0) @@ -1538,27 +1537,26 @@ nvme_ctrlr_shutdown(struct nvme_controller *ctrlr) { uint32_t cc; uint32_t csts; - int ticks = 0, timeout; + int timeout; cc = nvme_mmio_read_4(ctrlr, cc); cc &= ~(NVME_CC_REG_SHN_MASK << NVME_CC_REG_SHN_SHIFT); cc |= NVME_SHN_NORMAL << NVME_CC_REG_SHN_SHIFT; nvme_mmio_write_4(ctrlr, cc, cc); - timeout = ctrlr->cdata.rtd3e == 0 ? 5 * hz : - ((uint64_t)ctrlr->cdata.rtd3e * hz + 999999) / 1000000; + timeout = ticks + (ctrlr->cdata.rtd3e == 0 ? 5 * hz : + ((uint64_t)ctrlr->cdata.rtd3e * hz + 999999) / 1000000); while (1) { csts = nvme_mmio_read_4(ctrlr, csts); if (csts == NVME_GONE) /* Hot unplug. */ break; if (NVME_CSTS_GET_SHST(csts) == NVME_SHST_COMPLETE) break; - if (ticks++ > timeout) { - nvme_printf(ctrlr, "did not complete shutdown within" - " %d ticks of notification\n", timeout); + if (timeout - ticks < 0) { + nvme_printf(ctrlr, "shutdown timeout\n"); break; } - pause("nvme shn", 1); + pause("nvmeshut", 1); } } @@ -1635,7 +1633,7 @@ nvme_ctrlr_suspend(struct nvme_controller *ctrlr) */ nvme_ctrlr_delete_qpairs(ctrlr); nvme_ctrlr_disable_qpairs(ctrlr); - DELAY(100*1000); + pause("nvmesusp", hz / 10); nvme_ctrlr_shutdown(ctrlr); return (0);