Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758636AbcJQS3l (ORCPT ); Mon, 17 Oct 2016 14:29:41 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:11975 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758219AbcJQS1u (ORCPT ); Mon, 17 Oct 2016 14:27:50 -0400 X-IronPort-AV: E=Sophos;i="5.31,358,1473091200"; d="scan'";a="25774219" Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Adam.Manzanares@wdc.com; From: Adam Manzanares To: , , , , , , , , , , CC: , , , , , Adam Manzanares Subject: [PATCH v6 2/3] ata: Enabling ATA Command Priorities Date: Mon, 17 Oct 2016 11:27:29 -0700 Message-ID: <1476728850-2309-3-git-send-email-adam.manzanares@hgst.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1476728850-2309-1-git-send-email-adam.manzanares@hgst.com> References: <1476728850-2309-1-git-send-email-adam.manzanares@hgst.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [199.255.44.173] X-ClientProxiedBy: CY1PR21CA0045.namprd21.prod.outlook.com (10.163.250.141) To SN1PR0401MB1728.namprd04.prod.outlook.com (10.162.131.18) X-MS-Office365-Filtering-Correlation-Id: 8761bd52-6047-41ae-74b4-08d3f6bb4b6b X-Microsoft-Exchange-Diagnostics: 1;SN1PR0401MB1728;2:D1msOlRuRgWzk8umgCN7DkoRceKGIHbRHQ4CvmvyJ5XZMSB36jbSy8wZQ7m7k3NnQzgo4LQyIxd7RsEKVcfIgegU9TBW3KqsQJHHOyW+PhcbjVuncDppwwc7euks3Hgt0qOtsZ/iFZ7iMIYKyBJg2q2+tMxhM/Ir7Cy7GxU4KadLqt0e93uJOSm7/NDIwgIgmiM+fa2x9sB6CkVRxxhnJg==;3:GXf8mEBWcpwOeH52ozXt/wBXUSszVPWF0L7GFxBTAm2YTvjuRAnLeaBqnaBj5fhAEkjkZYR+SAJ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RTn63lZSlRRjRwMnPofyjPp2RsczN48Si3FeG7kxUa38MwxMwrcV1wRU2hmo5Q/InFx8e+l8J21c3rUC3XQaBCb+QhF3rbUdof655m4iyS81fAsJBKPchg5TE2JelGpJAQSQyqpQ2whF9KQFaQ4suZ2vUbY6fHRNVkGb877w5+t3PzHXy4xoscs7QMPNGPxUhLfRiTbNJRIBFz9ycszZuPcxx+Z8nbp34mIhiwwzxyxoJ9fi3q+caJyb9IMXQz8rffb6V1xjH1BJs5jh4YnHxP0My/BcxIaZf+pgi74vFxm3p8yttgMtoalvj7TR X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(79135771888625); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040176)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6055026);SRVR:SN1PR0401MB1728;BCL:0;PCL:0;RULEID:;SRVR:SN1PR0401MB1728; X-Microsoft-Exchange-Diagnostics: 1;SN1PR0401MB1728;4:x39Nv/OS6HHnYZTxHNWr7PWwl43jkiI8Tg8vfBNbw05sH2/LrhlobG8nYhc+BFJGQasCIg1m7kQwDb23SB7Jem8yC2XAnZ3QBLmgJ239No315/6FjTSdF/0pqZRb9Mf3ARIcvlaYiU5wU85h7NdjSYDz3z0HnATyKF7slVJt8K2KjishN0dpMoUxw08WB6+W5kcpU75S8ARczR77OJYnsoMlJgFWoa6KiveZNw6eso9J3QTP8cSOCvc25LWGT1LUPaXNbOfG8lXpl49obQPCACjbFBZcJYnU2m4RLR4QKICTzfPEG0NMf7hao7Upy4o89ubP8DPdi99sClZ91+cE82AYyojdjEqzPB01d/wQDz5B34Npg/bgVMFwFLJVo19BgpwsfvGOu6/teiIjfkgCzaE4LVVhYj7aN//BMUQ1fZeGtQgBimfLYZHIC6dc/dlrBOliAmVRroaKGAghMRuRyA== X-Forefront-PRVS: 0098BA6C6C X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6009001)(7916002)(189002)(199003)(5001770100001)(6116002)(77096005)(8676002)(97736004)(305945005)(6666003)(7846002)(7736002)(81156014)(7416002)(3846002)(81166006)(5003940100001)(19580405001)(66066001)(107886002)(19580395003)(586003)(189998001)(4326007)(92566002)(36756003)(4001430100002)(50986999)(42186005)(76176999)(105586002)(106356001)(5660300001)(50226002)(47776003)(229853001)(2906002)(68736007)(48376002)(2201001)(42882006)(2950100002)(33646002)(101416001)(50466002)(7099028)(921003)(2101003)(83996005)(1121003);DIR:OUT;SFP:1102;SCL:1;SRVR:SN1PR0401MB1728;H:penguito.sanjose.hgst.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;SN1PR0401MB1728;23:82U9S/zmdQ16E+QHs7jb44dmbXcloU6w0RkVeMa?= =?us-ascii?Q?lReMdMvn37t80ROrAe2yxeb2iNBAqN7CzWOskB1EI5+TjygS5HlhJKFaoJeP?= =?us-ascii?Q?XG3tQ7nOwFIwXOQtPXGwVDaeK0r47ddLBeNhCXIv21rjkAowb4D31iKBj4ct?= =?us-ascii?Q?VqwzdCMOFwUmZvXz0vazIi2/4XW7GrOkzC3seKNYw40o57FXRw0fQGoAIvuS?= =?us-ascii?Q?DPVYxjNTrZaMDlKigt/Y/N1CXaM2XaIsJ+Kt+rd+Pnpffi4T/jfTMG1VSD/U?= =?us-ascii?Q?tnROp4IS0swFw2DbVzCILs/+tLh0FYMZv7rMVVSYAE9hH0e4iu4EPiqm6vat?= =?us-ascii?Q?H8P/oWkrkTmOz01F2c4Z+wPv9bViG4jEvdSaVgnjKHqOKbMN+IFZPUgvvaJr?= =?us-ascii?Q?UhWX5oU/x+8/Rd9QhY+oY6hQ8F8FC7Uj+InEiLwjlgsBxIx+uErx8yPyAkiu?= =?us-ascii?Q?gIaZk56mVAxPdCdxPi2y0+BhGBPsanJWysi3EW7FWMYtS0RrK40BeJ389guT?= =?us-ascii?Q?B9dsWC4pWGeSxqDww0RZER3/G4u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560/3Rb8RTThOdWGA3gj9o3lNbcDDEzoxzzw3nTDLOeIy3aCc9B93UfJ6SvYQBaqpIldBq6gKBRwXpXzZEvI6aSco6tk/ub4tYlo8trHhgGL9Os2K65KQA6L55M9+xV0ZFfJu0/CZI52bjnIcTbO6PMaV9uiF3+D15pRYSG11ge9it/N08aR7SS2CPbFtbTfcFeDcQBMQUdEu8Y=;5:kJBGMrFBqkoeE9jaewgFCY4vf82Z7S0mqhGQFZKzHluKjIRY27B7yePiTmnFi6H13qbwPOpTDrpB9lEADI4+A6zg7aViubz8h/i68Qgge7ErVl6YYJDXjDbO+3SKnv1ZuTpU0YmUGIX5QeIXzM44AaiBXbXOZYiabW49m3K5jO0=;24:eetZOYrinotdSga+wdPcw5/aIuLYvtOAB7JvCsmPky9fB/YRleybC8x0E7H2aRB5+qrOHB2z9oOcdO3ZfhudIMRGXg1Je8VcmPAT017qoaw= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;SN1PR0401MB1728;7:GQTWPXow0SDijKW2hnnYXgKGXbeq8gIbtREs4vz4rxjGlL7USgR6bAzvsk0e43iFFR7ZvwgxfMZ/HjqUru1IW94kqevTkVNwntabxxy5GFfMx1UUcD3IyrgmnbpuxEUmzuzYUSm0ajmmDUf8QLVF+LGmdWUhETeS3sJkAf/3Z+y2A7oTrP9FneheiZX5vENu8YsjonR02lCGGMWsmuU/GgrZElpNU30NH0pihzSh8DD8NjIyXUi7gVtfopzXr2d8Db9PI/IBO02meRIyTEpmkzLTMctMsYLviceA8aofSuKE5CKwX7O0c/4oUIqPTTZVlSdG4ZnRbJroEifDrMKbPp55UJQRo0q3t4VNouUuyOs=;20:Y/wrSyS7QCBwTilDju7VwFh9t95ShApR1JVNmSQT/FRkzmSP8uH2eQ1hi87YF102alLMlYQB6umkVXYZngGWwLy4C3rxL5Cl3PiPiajwvdy298+QZyTA5p5A7b6IWLg60uZP911atUxVcj8aukxWi6QY1w2UDYcSSbt+jRU/Vmi2Ag+czFyGVC255VYARr3Ne+mZgROH/hpwSDKWz6eoIZILg+Lw82XHK/Ms9Uv5SZEQ90jDw2jKOt9x3+tMVfjr X-OriginatorOrg: hgst.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Oct 2016 18:27:46.3173 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR0401MB1728 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 6614 Lines: 204 This patch checks to see if an ATA device supports NCQ command priorities. If so and the user has specified an iocontext that indicates IO_PRIO_CLASS_RT then we build a tf with a high priority command. This is done to improve the tail latency of commands that are high priority by passing priority to the device. Signed-off-by: Adam Manzanares --- drivers/ata/libata-core.c | 35 ++++++++++++++++++++++++++++++++++- drivers/ata/libata-scsi.c | 6 +++++- drivers/ata/libata.h | 2 +- include/linux/ata.h | 6 ++++++ include/linux/libata.h | 18 ++++++++++++++++++ 5 files changed, 64 insertions(+), 3 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 223a770..181b530 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -739,6 +739,7 @@ u64 ata_tf_read_block(const struct ata_taskfile *tf, struct ata_device *dev) * @n_block: Number of blocks * @tf_flags: RW/FUA etc... * @tag: tag + * @class: IO priority class * * LOCKING: * None. @@ -753,7 +754,7 @@ u64 ata_tf_read_block(const struct ata_taskfile *tf, struct ata_device *dev) */ int ata_build_rw_tf(struct ata_taskfile *tf, struct ata_device *dev, u64 block, u32 n_block, unsigned int tf_flags, - unsigned int tag) + unsigned int tag, int class) { tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; tf->flags |= tf_flags; @@ -785,6 +786,12 @@ int ata_build_rw_tf(struct ata_taskfile *tf, struct ata_device *dev, tf->device = ATA_LBA; if (tf->flags & ATA_TFLAG_FUA) tf->device |= 1 << 7; + + if (ata_ncq_prio_enabled(dev)) { + if (class == IOPRIO_CLASS_RT) + tf->hob_nsect |= ATA_PRIO_HIGH << + ATA_SHIFT_PRIO; + } } else if (dev->flags & ATA_DFLAG_LBA) { tf->flags |= ATA_TFLAG_LBA; @@ -2156,6 +2163,30 @@ static void ata_dev_config_ncq_non_data(struct ata_device *dev) } } +static void ata_dev_config_ncq_prio(struct ata_device *dev) +{ + struct ata_port *ap = dev->link->ap; + unsigned int err_mask; + + err_mask = ata_read_log_page(dev, + ATA_LOG_SATA_ID_DEV_DATA, + ATA_LOG_SATA_SETTINGS, + ap->sector_buf, + 1); + if (err_mask) { + ata_dev_dbg(dev, + "failed to get Identify Device data, Emask 0x%x\n", + err_mask); + return; + } + + if (ap->sector_buf[ATA_LOG_NCQ_PRIO_OFFSET] & BIT(3)) + dev->flags |= ATA_DFLAG_NCQ_PRIO; + else + ata_dev_dbg(dev, "SATA page does not support priority\n"); + +} + static int ata_dev_config_ncq(struct ata_device *dev, char *desc, size_t desc_sz) { @@ -2205,6 +2236,8 @@ static int ata_dev_config_ncq(struct ata_device *dev, ata_dev_config_ncq_send_recv(dev); if (ata_id_has_ncq_non_data(dev->id)) ata_dev_config_ncq_non_data(dev); + if (ata_id_has_ncq_prio(dev->id)) + ata_dev_config_ncq_prio(dev); } return 0; diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index 9cceb4a..2bccc3c 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -50,6 +50,7 @@ #include #include #include +#include #include "libata.h" #include "libata-transport.h" @@ -1755,6 +1756,8 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc) { struct scsi_cmnd *scmd = qc->scsicmd; const u8 *cdb = scmd->cmnd; + struct request *rq = scmd->request; + int class = IOPRIO_PRIO_CLASS(req_get_ioprio(rq)); unsigned int tf_flags = 0; u64 block; u32 n_block; @@ -1821,7 +1824,8 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc) qc->nbytes = n_block * scmd->device->sector_size; rc = ata_build_rw_tf(&qc->tf, qc->dev, block, n_block, tf_flags, - qc->tag); + qc->tag, class); + if (likely(rc == 0)) return 0; diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h index 3b301a4..8f3a559 100644 --- a/drivers/ata/libata.h +++ b/drivers/ata/libata.h @@ -66,7 +66,7 @@ extern u64 ata_tf_to_lba48(const struct ata_taskfile *tf); extern struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev, int tag); extern int ata_build_rw_tf(struct ata_taskfile *tf, struct ata_device *dev, u64 block, u32 n_block, unsigned int tf_flags, - unsigned int tag); + unsigned int tag, int class); extern u64 ata_tf_read_block(const struct ata_taskfile *tf, struct ata_device *dev); extern unsigned ata_exec_internal(struct ata_device *dev, diff --git a/include/linux/ata.h b/include/linux/ata.h index fdb1803..af6859b 100644 --- a/include/linux/ata.h +++ b/include/linux/ata.h @@ -348,6 +348,7 @@ enum { ATA_LOG_DEVSLP_DETO = 0x01, ATA_LOG_DEVSLP_VALID = 0x07, ATA_LOG_DEVSLP_VALID_MASK = 0x80, + ATA_LOG_NCQ_PRIO_OFFSET = 0x09, /* NCQ send and receive log */ ATA_LOG_NCQ_SEND_RECV_SUBCMDS_OFFSET = 0x00, @@ -940,6 +941,11 @@ static inline bool ata_id_has_ncq_non_data(const u16 *id) return id[ATA_ID_SATA_CAPABILITY_2] & BIT(5); } +static inline bool ata_id_has_ncq_prio(const u16 *id) +{ + return id[ATA_ID_SATA_CAPABILITY] & BIT(12); +} + static inline bool ata_id_has_trim(const u16 *id) { if (ata_id_major_version(id) >= 7 && diff --git a/include/linux/libata.h b/include/linux/libata.h index 616eef4..1a524cf 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -166,6 +166,7 @@ enum { ATA_DFLAG_NO_UNLOAD = (1 << 17), /* device doesn't support unload */ ATA_DFLAG_UNLOCK_HPA = (1 << 18), /* unlock HPA */ ATA_DFLAG_NCQ_SEND_RECV = (1 << 19), /* device supports NCQ SEND and RECV */ + ATA_DFLAG_NCQ_PRIO = (1 << 20), /* device supports NCQ priority */ ATA_DFLAG_INIT_MASK = (1 << 24) - 1, ATA_DFLAG_DETACH = (1 << 24), @@ -342,7 +343,9 @@ enum { ATA_SHIFT_PIO = 0, ATA_SHIFT_MWDMA = ATA_SHIFT_PIO + ATA_NR_PIO_MODES, ATA_SHIFT_UDMA = ATA_SHIFT_MWDMA + ATA_NR_MWDMA_MODES, + ATA_SHIFT_PRIO = 6, + ATA_PRIO_HIGH = 2, /* size of buffer to pad xfers ending on unaligned boundaries */ ATA_DMA_PAD_SZ = 4, @@ -1610,6 +1613,21 @@ static inline int ata_ncq_enabled(struct ata_device *dev) ATA_DFLAG_NCQ)) == ATA_DFLAG_NCQ; } +/** + * ata_ncq_prio_enabled - Test whether NCQ prio is enabled + * @dev: ATA device to test for + * + * LOCKING: + * spin_lock_irqsave(host lock) + * + * RETURNS: + * 1 if NCQ prio is enabled for @dev, 0 otherwise. + */ +static inline int ata_ncq_prio_enabled(struct ata_device *dev) +{ + return (dev->flags & ATA_DFLAG_NCQ_PRIO) == ATA_DFLAG_NCQ_PRIO; +} + static inline bool ata_fpdma_dsm_supported(struct ata_device *dev) { return (dev->flags & ATA_DFLAG_NCQ_SEND_RECV) && -- 2.1.4