Skip to content

Commit 6c91325

Browse files
damien-lemoalmartinkpetersen
authored andcommitted
scsi: block: Introduce ioprio hints
I/O priorities currently only use 6-bits of the 16-bits ioprio value: the 3-upper bits are used to define up to 8 priority classes (4 of which are valid) and the 3 lower bits of the value are used to define a priority level for the real-time and best-effort class. The remaining 10-bits between the I/O priority class and level are unused, and in fact, cannot be used by the user as doing so would either result in the value being completely ignored, or in an error returned by ioprio_check_cap(). Use these 10-bits of an ioprio value to allow a user to specify I/O hints. An I/O hint is defined as a 10-bitsvalue, allowing up to 1023 different hints to be specified, with the value 0 being reserved as the "no hint" case. An I/O hint can apply to any I/O that specifies a valid priority class other than NONE, regardless of the I/O priority level specified. To do so, the macros IOPRIO_PRIO_HINT() and IOPRIO_PRIO_VALUE_HINT() are introduced in include/uapi/linux/ioprio.h to respectively allow a user to get and set a hint in an ioprio value. To support the ATA and SCSI command duration limits feature, 7 hints are defined: IOPRIO_HINT_DEV_DURATION_LIMIT_1 to IOPRIO_HINT_DEV_DURATION_LIMIT_7, allowing a user to specify which command duration limit descriptor should be applied to the commands serving an I/O. Specifying these hints has for now no effect whatsoever if the target block devices do not support the command duration limits feature. However, in the future, block I/O schedulers can be modified to optimize I/O issuing order based on these hints, even for devices that do not support the command duration limits feature. Given that the 7 duration limits hints defined have no effect on any block layer component, the actual definition of the duration limits implied by these hints remains at the device level. Signed-off-by: Damien Le Moal <[email protected]> Reviewed-by: Hannes Reinecke <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Niklas Cassel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Martin K. Petersen <[email protected]>
1 parent eca2040 commit 6c91325

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

include/uapi/linux/ioprio.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,53 @@ enum {
5858
#define IOPRIO_NORM 4
5959
#define IOPRIO_BE_NORM IOPRIO_NORM
6060

61+
/*
62+
* The 10 bits between the priority class and the priority level are used to
63+
* optionally define I/O hints for any combination of I/O priority class and
64+
* level. Depending on the kernel configuration, I/O scheduler being used and
65+
* the target I/O device being used, hints can influence how I/Os are processed
66+
* without affecting the I/O scheduling ordering defined by the I/O priority
67+
* class and level.
68+
*/
69+
#define IOPRIO_HINT_SHIFT IOPRIO_LEVEL_NR_BITS
70+
#define IOPRIO_HINT_NR_BITS 10
71+
#define IOPRIO_NR_HINTS (1 << IOPRIO_HINT_NR_BITS)
72+
#define IOPRIO_HINT_MASK (IOPRIO_NR_HINTS - 1)
73+
#define IOPRIO_PRIO_HINT(ioprio) \
74+
(((ioprio) >> IOPRIO_HINT_SHIFT) & IOPRIO_HINT_MASK)
75+
76+
/*
77+
* Alternate macro for IOPRIO_PRIO_VALUE() to define an I/O priority with
78+
* a class, level and hint.
79+
*/
80+
#define IOPRIO_PRIO_VALUE_HINT(class, level, hint) \
81+
((((class) & IOPRIO_CLASS_MASK) << IOPRIO_CLASS_SHIFT) | \
82+
(((hint) & IOPRIO_HINT_MASK) << IOPRIO_HINT_SHIFT) | \
83+
((level) & IOPRIO_LEVEL_MASK))
84+
85+
/*
86+
* I/O hints.
87+
*/
88+
enum {
89+
/* No hint */
90+
IOPRIO_HINT_NONE = 0,
91+
92+
/*
93+
* Device command duration limits: indicate to the device a desired
94+
* duration limit for the commands that will be used to process an I/O.
95+
* These will currently only be effective for SCSI and ATA devices that
96+
* support the command duration limits feature. If this feature is
97+
* enabled, then the commands issued to the device to process an I/O with
98+
* one of these hints set will have the duration limit index (dld field)
99+
* set to the value of the hint.
100+
*/
101+
IOPRIO_HINT_DEV_DURATION_LIMIT_1 = 1,
102+
IOPRIO_HINT_DEV_DURATION_LIMIT_2 = 2,
103+
IOPRIO_HINT_DEV_DURATION_LIMIT_3 = 3,
104+
IOPRIO_HINT_DEV_DURATION_LIMIT_4 = 4,
105+
IOPRIO_HINT_DEV_DURATION_LIMIT_5 = 5,
106+
IOPRIO_HINT_DEV_DURATION_LIMIT_6 = 6,
107+
IOPRIO_HINT_DEV_DURATION_LIMIT_7 = 7,
108+
};
109+
61110
#endif /* _UAPI_LINUX_IOPRIO_H */

0 commit comments

Comments
 (0)