From nobody Fri Jan 14 23:24:56 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 510F01961518; Fri, 14 Jan 2022 23:24:57 +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 4JbHT51Q2tz3NWD; Fri, 14 Jan 2022 23:24:57 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642202697; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=x/vs64UG+uuGewHgU18J1nKcA4oHXe5/G9mRLQrNk1g=; b=coIMDRJuDUk79rsJEtYoVt9AV8AST3RrjI8J/FnALdhm5VJDKkx/RQFMUUUYaHkua69X+c W04JXO/NXvJsMlhi9Ewwd5j1s6vfffdng5EHNSH+4FqS4eR2uPdiluqG4n9wfvlUzZnvkm OYs1NhvlkU8+eeO5D3Af9vDsuMfQgCD7MbVQ9AzBbbZUoT2eB18HwSAOUTJ4ypyNVLmV86 2NCydLETgogx3qFRlm6xaIDps9BRCwRBXgQl/qFX8hmuYHmW0TfVEVGjeSfbJrI1NjQ46J MEM1GNHOaIeC1k5+QV2VRo3aRpgNUqt8bDlQ7ekRN55o08GgaiB5BSGpjlBiGA== 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 120A01CA45; Fri, 14 Jan 2022 23:24:57 +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 20ENOuHM013975; Fri, 14 Jan 2022 23:24:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20ENOuMg013974; Fri, 14 Jan 2022 23:24:56 GMT (envelope-from git) Date: Fri, 14 Jan 2022 23:24:56 GMT Message-Id: <202201142324.20ENOuMg013974@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Alexander Motin Subject: git: a9a2cdaf3c19 - main - cam: Optimize write protection MODE SENSE in da(4). List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org 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/main X-Git-Reftype: branch X-Git-Commit: a9a2cdaf3c193ee1b597d0eef51544636421d973 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642202697; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=x/vs64UG+uuGewHgU18J1nKcA4oHXe5/G9mRLQrNk1g=; b=tY+ewLdj192JWT76lVBOKX8aWEcwqw8MmrCFoTtT/y9BrgnpqAoVaqLU6obfp6k6L09HFi JR7ENu1TH6SB+Vh1BjrMGDBrpNDfkuB40+XT3CletV/UbZ5S5efQVDUX+ABQll9csb7k6m 5DSKWaZcm4X7GjxqXnpI+HxqVXhpMUdW7LAI/x9pKdB2v4Q8o4fqS6QPW00fa86qoiHlKW 3ZyGhLw88bIzQGskKGWPByc/LSXUBzCawxseGg2dr5OFVAIKYrfEsiO1lvi8lEL2XRf1Gg dZwZzO9E7IuZzIsnR/TXcyD9r2jYB6wWIJi/RK6XolWvPdz1p1WfHQWSOkvgoQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1642202697; a=rsa-sha256; cv=none; b=U7VY66ZGAgsVpTfOP5sQl4Y22snBobHER+456d2+OLVm1064lc/x2HtgTh/V0KRZ5tKdol myxbVhljJ+Ldi7bTsHhnQW66eG7K+tivAoiV9hGHEDm13/Sr43x8MipvhKxKgSiE88dWzG eweF9Hf3ylL4a2c0jg+BPtZemmRCDTjoifMKksk1zdJjg003br7nd7Jk6w4ulZUSJgynM+ wB/Uy7GMoAEGxLGwQeE8HNZNmfneGCdsVWGS4aOS7W7ocyqy3cpwxhHcu9hElpVUxfhd+1 8iix3LQHt1xIfiYOLQ+4+diV5szNEBQ2A4ABrdRAlHKdnkgRLnO/6pH2/CEamg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mav: URL: https://cgit.FreeBSD.org/src/commit/?id=a9a2cdaf3c193ee1b597d0eef51544636421d973 commit a9a2cdaf3c193ee1b597d0eef51544636421d973 Author: Alexander Motin AuthorDate: 2022-01-14 22:48:19 +0000 Commit: Alexander Motin CommitDate: 2022-01-14 23:24:52 +0000 cam: Optimize write protection MODE SENSE in da(4). Before this change on every open da(4) driver read all mode pages to use only one bit. It was done so to not depend on the list of pages supported by the disk. But I've found that at least for SATL of LSI/ Broadcom HBAs with WD HDDs Power Condition mode page reading may take significant amount of time, much more than any other mode page, that visibly increased disk retaste time by GEOM. Address that by using data returned by the first MODE SENSE request to limit the following ones to only one (the first for now) mode page. With the change simultaneous retaste of 39 SATA disks takes about 2.5s instead of more than 4s before, and I no longer see "dareprobe" status on GEOM event thread. MFC after: 2 weeks Sponsored by: iXsystems, Inc. --- sys/cam/scsi/scsi_da.c | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/sys/cam/scsi/scsi_da.c b/sys/cam/scsi/scsi_da.c index 2a7b09adc21e..6531a7fa9d12 100644 --- a/sys/cam/scsi/scsi_da.c +++ b/sys/cam/scsi/scsi_da.c @@ -346,6 +346,7 @@ struct da_softc { da_flags flags; da_quirks quirks; int minimum_cmd_size; + int mode_page; int error_inject; int trim_max_ranges; int delete_available; /* Delete methods possibly available */ @@ -2908,6 +2909,9 @@ daregister(struct cam_periph *periph, void *arg) else softc->minimum_cmd_size = 6; + /* On first PROBE_WP request all more pages, then adjust. */ + softc->mode_page = SMS_ALL_PAGES_PAGE; + /* Predict whether device may support READ CAPACITY(16). */ if (SID_ANSI_REV(&cgd->inq_data) >= SCSI_REV_SPC3 && (softc->quirks & DA_Q_NO_RC16) == 0) { @@ -3501,7 +3505,7 @@ out: void *mode_buf; int mode_buf_len; - if (da_disable_wp_detection) { + if (da_disable_wp_detection || softc->mode_page < 0) { if ((softc->flags & DA_FLAG_CAN_RC16) != 0) softc->state = DA_STATE_PROBE_RC16; else @@ -3525,7 +3529,7 @@ out: /*tag_action*/ MSG_SIMPLE_Q_TAG, /*dbd*/ FALSE, /*pc*/ SMS_PAGE_CTRL_CURRENT, - /*page*/ SMS_ALL_PAGES_PAGE, + /*page*/ softc->mode_page, /*param_buf*/ mode_buf, /*param_len*/ mode_buf_len, /*minimum_cmd_size*/ softc->minimum_cmd_size, @@ -4685,12 +4689,9 @@ dadone(struct cam_periph *periph, union ccb *done_ccb) static void dadone_probewp(struct cam_periph *periph, union ccb *done_ccb) { - struct scsi_mode_header_6 *mode_hdr6; - struct scsi_mode_header_10 *mode_hdr10; struct da_softc *softc; struct ccb_scsiio *csio; u_int32_t priority; - uint8_t dev_spec; CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone_probewp\n")); @@ -4708,18 +4709,31 @@ dadone_probewp(struct cam_periph *periph, union ccb *done_ccb) (unsigned long)csio->ccb_h.ccb_state & DA_CCB_TYPE_MASK, periph, done_ccb)); - if (softc->minimum_cmd_size > 6) { - mode_hdr10 = (struct scsi_mode_header_10 *)csio->data_ptr; - dev_spec = mode_hdr10->dev_spec; - } else { - mode_hdr6 = (struct scsi_mode_header_6 *)csio->data_ptr; - dev_spec = mode_hdr6->dev_spec; - } if (cam_ccb_status(done_ccb) == CAM_REQ_CMP) { + int len, off; + uint8_t dev_spec; + + if (csio->cdb_len > 6) { + struct scsi_mode_header_10 *mh = + (struct scsi_mode_header_10 *)csio->data_ptr; + len = 2 + scsi_2btoul(mh->data_length); + off = sizeof(*mh) + scsi_2btoul(mh->blk_desc_len); + dev_spec = mh->dev_spec; + } else { + struct scsi_mode_header_6 *mh = + (struct scsi_mode_header_6 *)csio->data_ptr; + len = 1 + mh->data_length; + off = sizeof(*mh) + mh->blk_desc_len; + dev_spec = mh->dev_spec; + } if ((dev_spec & 0x80) != 0) softc->disk->d_flags |= DISKFLAG_WRITE_PROTECT; else softc->disk->d_flags &= ~DISKFLAG_WRITE_PROTECT; + + /* Next time request only the first of returned mode pages. */ + if (off < len && off < csio->dxfer_len - csio->resid) + softc->mode_page = csio->data_ptr[off] & SMPH_PC_MASK; } else { int error; @@ -4736,6 +4750,9 @@ dadone_probewp(struct cam_periph *periph, union ccb *done_ccb) /*timeout*/0, /*getcount_only*/0); } + + /* We don't depend on it, so don't try again. */ + softc->mode_page = -1; } }