Skip to content

Commit 8e06178

Browse files
nmtadamhtejun
authored andcommitted
ata: Enabling ATA Command Priorities
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. tj: Removed trivial ata_ncq_prio_enabled() and open-coded the test. Signed-off-by: Adam Manzanares <adam.manzanares@hgst.com> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent 5dc8b36 commit 8e06178

5 files changed

Lines changed: 49 additions & 3 deletions

File tree

‎drivers/ata/libata-core.c‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,7 @@ u64 ata_tf_read_block(const struct ata_taskfile *tf, struct ata_device *dev)
739739
* @n_block: Number of blocks
740740
* @tf_flags: RW/FUA etc...
741741
* @tag: tag
742+
* @class: IO priority class
742743
*
743744
* LOCKING:
744745
* None.
@@ -753,7 +754,7 @@ u64 ata_tf_read_block(const struct ata_taskfile *tf, struct ata_device *dev)
753754
*/
754755
int ata_build_rw_tf(struct ata_taskfile *tf, struct ata_device *dev,
755756
u64 block, u32 n_block, unsigned int tf_flags,
756-
unsigned int tag)
757+
unsigned int tag, int class)
757758
{
758759
tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
759760
tf->flags |= tf_flags;
@@ -785,6 +786,12 @@ int ata_build_rw_tf(struct ata_taskfile *tf, struct ata_device *dev,
785786
tf->device = ATA_LBA;
786787
if (tf->flags & ATA_TFLAG_FUA)
787788
tf->device |= 1 << 7;
789+
790+
if (dev->flags & ATA_DFLAG_NCQ_PRIO) {
791+
if (class == IOPRIO_CLASS_RT)
792+
tf->hob_nsect |= ATA_PRIO_HIGH <<
793+
ATA_SHIFT_PRIO;
794+
}
788795
} else if (dev->flags & ATA_DFLAG_LBA) {
789796
tf->flags |= ATA_TFLAG_LBA;
790797

@@ -2156,6 +2163,30 @@ static void ata_dev_config_ncq_non_data(struct ata_device *dev)
21562163
}
21572164
}
21582165

2166+
static void ata_dev_config_ncq_prio(struct ata_device *dev)
2167+
{
2168+
struct ata_port *ap = dev->link->ap;
2169+
unsigned int err_mask;
2170+
2171+
err_mask = ata_read_log_page(dev,
2172+
ATA_LOG_SATA_ID_DEV_DATA,
2173+
ATA_LOG_SATA_SETTINGS,
2174+
ap->sector_buf,
2175+
1);
2176+
if (err_mask) {
2177+
ata_dev_dbg(dev,
2178+
"failed to get Identify Device data, Emask 0x%x\n",
2179+
err_mask);
2180+
return;
2181+
}
2182+
2183+
if (ap->sector_buf[ATA_LOG_NCQ_PRIO_OFFSET] & BIT(3))
2184+
dev->flags |= ATA_DFLAG_NCQ_PRIO;
2185+
else
2186+
ata_dev_dbg(dev, "SATA page does not support priority\n");
2187+
2188+
}
2189+
21592190
static int ata_dev_config_ncq(struct ata_device *dev,
21602191
char *desc, size_t desc_sz)
21612192
{
@@ -2205,6 +2236,8 @@ static int ata_dev_config_ncq(struct ata_device *dev,
22052236
ata_dev_config_ncq_send_recv(dev);
22062237
if (ata_id_has_ncq_non_data(dev->id))
22072238
ata_dev_config_ncq_non_data(dev);
2239+
if (ata_id_has_ncq_prio(dev->id))
2240+
ata_dev_config_ncq_prio(dev);
22082241
}
22092242

22102243
return 0;

‎drivers/ata/libata-scsi.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include <linux/uaccess.h>
5151
#include <linux/suspend.h>
5252
#include <asm/unaligned.h>
53+
#include <linux/ioprio.h>
5354

5455
#include "libata.h"
5556
#include "libata-transport.h"
@@ -1755,6 +1756,8 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc)
17551756
{
17561757
struct scsi_cmnd *scmd = qc->scsicmd;
17571758
const u8 *cdb = scmd->cmnd;
1759+
struct request *rq = scmd->request;
1760+
int class = IOPRIO_PRIO_CLASS(req_get_ioprio(rq));
17581761
unsigned int tf_flags = 0;
17591762
u64 block;
17601763
u32 n_block;
@@ -1821,7 +1824,8 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc)
18211824
qc->nbytes = n_block * scmd->device->sector_size;
18221825

18231826
rc = ata_build_rw_tf(&qc->tf, qc->dev, block, n_block, tf_flags,
1824-
qc->tag);
1827+
qc->tag, class);
1828+
18251829
if (likely(rc == 0))
18261830
return 0;
18271831

‎drivers/ata/libata.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ extern u64 ata_tf_to_lba48(const struct ata_taskfile *tf);
6666
extern struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev, int tag);
6767
extern int ata_build_rw_tf(struct ata_taskfile *tf, struct ata_device *dev,
6868
u64 block, u32 n_block, unsigned int tf_flags,
69-
unsigned int tag);
69+
unsigned int tag, int class);
7070
extern u64 ata_tf_read_block(const struct ata_taskfile *tf,
7171
struct ata_device *dev);
7272
extern unsigned ata_exec_internal(struct ata_device *dev,

‎include/linux/ata.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ enum {
348348
ATA_LOG_DEVSLP_DETO = 0x01,
349349
ATA_LOG_DEVSLP_VALID = 0x07,
350350
ATA_LOG_DEVSLP_VALID_MASK = 0x80,
351+
ATA_LOG_NCQ_PRIO_OFFSET = 0x09,
351352

352353
/* NCQ send and receive log */
353354
ATA_LOG_NCQ_SEND_RECV_SUBCMDS_OFFSET = 0x00,
@@ -940,6 +941,11 @@ static inline bool ata_id_has_ncq_non_data(const u16 *id)
940941
return id[ATA_ID_SATA_CAPABILITY_2] & BIT(5);
941942
}
942943

944+
static inline bool ata_id_has_ncq_prio(const u16 *id)
945+
{
946+
return id[ATA_ID_SATA_CAPABILITY] & BIT(12);
947+
}
948+
943949
static inline bool ata_id_has_trim(const u16 *id)
944950
{
945951
if (ata_id_major_version(id) >= 7 &&

‎include/linux/libata.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ enum {
166166
ATA_DFLAG_NO_UNLOAD = (1 << 17), /* device doesn't support unload */
167167
ATA_DFLAG_UNLOCK_HPA = (1 << 18), /* unlock HPA */
168168
ATA_DFLAG_NCQ_SEND_RECV = (1 << 19), /* device supports NCQ SEND and RECV */
169+
ATA_DFLAG_NCQ_PRIO = (1 << 20), /* device supports NCQ priority */
169170
ATA_DFLAG_INIT_MASK = (1 << 24) - 1,
170171

171172
ATA_DFLAG_DETACH = (1 << 24),
@@ -342,7 +343,9 @@ enum {
342343
ATA_SHIFT_PIO = 0,
343344
ATA_SHIFT_MWDMA = ATA_SHIFT_PIO + ATA_NR_PIO_MODES,
344345
ATA_SHIFT_UDMA = ATA_SHIFT_MWDMA + ATA_NR_MWDMA_MODES,
346+
ATA_SHIFT_PRIO = 6,
345347

348+
ATA_PRIO_HIGH = 2,
346349
/* size of buffer to pad xfers ending on unaligned boundaries */
347350
ATA_DMA_PAD_SZ = 4,
348351

0 commit comments

Comments
 (0)