106447ae5SOliver Hartkopp /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 206447ae5SOliver Hartkopp #ifndef _UAPI_LINUX_IOPRIO_H 306447ae5SOliver Hartkopp #define _UAPI_LINUX_IOPRIO_H 406447ae5SOliver Hartkopp 501584c1eSDamien Le Moal #include <linux/stddef.h> 601584c1eSDamien Le Moal #include <linux/types.h> 701584c1eSDamien Le Moal 806447ae5SOliver Hartkopp /* 906447ae5SOliver Hartkopp * Gives us 8 prio classes with 13-bits of data for each class 1006447ae5SOliver Hartkopp */ 11ba05200fSDamien Le Moal #define IOPRIO_CLASS_SHIFT 13 1201584c1eSDamien Le Moal #define IOPRIO_NR_CLASSES 8 1301584c1eSDamien Le Moal #define IOPRIO_CLASS_MASK (IOPRIO_NR_CLASSES - 1) 1406447ae5SOliver Hartkopp #define IOPRIO_PRIO_MASK ((1UL << IOPRIO_CLASS_SHIFT) - 1) 1506447ae5SOliver Hartkopp 16ba05200fSDamien Le Moal #define IOPRIO_PRIO_CLASS(ioprio) \ 17ba05200fSDamien Le Moal (((ioprio) >> IOPRIO_CLASS_SHIFT) & IOPRIO_CLASS_MASK) 18ba05200fSDamien Le Moal #define IOPRIO_PRIO_DATA(ioprio) ((ioprio) & IOPRIO_PRIO_MASK) 1906447ae5SOliver Hartkopp 2006447ae5SOliver Hartkopp /* 21eca20409SDamien Le Moal * These are the io priority classes as implemented by the BFQ and mq-deadline 2225bca50eSDamien Le Moal * schedulers. RT is the realtime class, it always gets premium service. For 2325bca50eSDamien Le Moal * ATA disks supporting NCQ IO priority, RT class IOs will be processed using 2425bca50eSDamien Le Moal * high priority NCQ commands. BE is the best-effort scheduling class, the 2525bca50eSDamien Le Moal * default for any process. IDLE is the idle scheduling class, it is only 2625bca50eSDamien Le Moal * served when no one else is using the disk. 2706447ae5SOliver Hartkopp */ 2806447ae5SOliver Hartkopp enum { 2901584c1eSDamien Le Moal IOPRIO_CLASS_NONE = 0, 3001584c1eSDamien Le Moal IOPRIO_CLASS_RT = 1, 3101584c1eSDamien Le Moal IOPRIO_CLASS_BE = 2, 3201584c1eSDamien Le Moal IOPRIO_CLASS_IDLE = 3, 3301584c1eSDamien Le Moal 3401584c1eSDamien Le Moal /* Special class to indicate an invalid ioprio value */ 3501584c1eSDamien Le Moal IOPRIO_CLASS_INVALID = 7, 3606447ae5SOliver Hartkopp }; 3706447ae5SOliver Hartkopp 3806447ae5SOliver Hartkopp /* 39eca20409SDamien Le Moal * The RT and BE priority classes both support up to 8 priority levels that 40eca20409SDamien Le Moal * can be specified using the lower 3-bits of the priority data. 4106447ae5SOliver Hartkopp */ 42eca20409SDamien Le Moal #define IOPRIO_LEVEL_NR_BITS 3 43eca20409SDamien Le Moal #define IOPRIO_NR_LEVELS (1 << IOPRIO_LEVEL_NR_BITS) 44eca20409SDamien Le Moal #define IOPRIO_LEVEL_MASK (IOPRIO_NR_LEVELS - 1) 45eca20409SDamien Le Moal #define IOPRIO_PRIO_LEVEL(ioprio) ((ioprio) & IOPRIO_LEVEL_MASK) 46eca20409SDamien Le Moal 47202bc942SDamien Le Moal #define IOPRIO_BE_NR IOPRIO_NR_LEVELS 4806447ae5SOliver Hartkopp 49eca20409SDamien Le Moal /* 50eca20409SDamien Le Moal * Possible values for the "which" argument of the ioprio_get() and 51eca20409SDamien Le Moal * ioprio_set() system calls (see "man ioprio_set"). 52eca20409SDamien Le Moal */ 5306447ae5SOliver Hartkopp enum { 5406447ae5SOliver Hartkopp IOPRIO_WHO_PROCESS = 1, 5506447ae5SOliver Hartkopp IOPRIO_WHO_PGRP, 5606447ae5SOliver Hartkopp IOPRIO_WHO_USER, 5706447ae5SOliver Hartkopp }; 5806447ae5SOliver Hartkopp 5906447ae5SOliver Hartkopp /* 60eca20409SDamien Le Moal * Fallback BE class priority level. 6106447ae5SOliver Hartkopp */ 62e70344c0SDamien Le Moal #define IOPRIO_NORM 4 63e70344c0SDamien Le Moal #define IOPRIO_BE_NORM IOPRIO_NORM 6406447ae5SOliver Hartkopp 656c913257SDamien Le Moal /* 666c913257SDamien Le Moal * The 10 bits between the priority class and the priority level are used to 676c913257SDamien Le Moal * optionally define I/O hints for any combination of I/O priority class and 686c913257SDamien Le Moal * level. Depending on the kernel configuration, I/O scheduler being used and 696c913257SDamien Le Moal * the target I/O device being used, hints can influence how I/Os are processed 706c913257SDamien Le Moal * without affecting the I/O scheduling ordering defined by the I/O priority 716c913257SDamien Le Moal * class and level. 726c913257SDamien Le Moal */ 736c913257SDamien Le Moal #define IOPRIO_HINT_SHIFT IOPRIO_LEVEL_NR_BITS 746c913257SDamien Le Moal #define IOPRIO_HINT_NR_BITS 10 756c913257SDamien Le Moal #define IOPRIO_NR_HINTS (1 << IOPRIO_HINT_NR_BITS) 766c913257SDamien Le Moal #define IOPRIO_HINT_MASK (IOPRIO_NR_HINTS - 1) 776c913257SDamien Le Moal #define IOPRIO_PRIO_HINT(ioprio) \ 786c913257SDamien Le Moal (((ioprio) >> IOPRIO_HINT_SHIFT) & IOPRIO_HINT_MASK) 796c913257SDamien Le Moal 806c913257SDamien Le Moal /* 816c913257SDamien Le Moal * I/O hints. 826c913257SDamien Le Moal */ 836c913257SDamien Le Moal enum { 846c913257SDamien Le Moal /* No hint */ 856c913257SDamien Le Moal IOPRIO_HINT_NONE = 0, 866c913257SDamien Le Moal 876c913257SDamien Le Moal /* 886c913257SDamien Le Moal * Device command duration limits: indicate to the device a desired 896c913257SDamien Le Moal * duration limit for the commands that will be used to process an I/O. 906c913257SDamien Le Moal * These will currently only be effective for SCSI and ATA devices that 916c913257SDamien Le Moal * support the command duration limits feature. If this feature is 926c913257SDamien Le Moal * enabled, then the commands issued to the device to process an I/O with 936c913257SDamien Le Moal * one of these hints set will have the duration limit index (dld field) 946c913257SDamien Le Moal * set to the value of the hint. 956c913257SDamien Le Moal */ 966c913257SDamien Le Moal IOPRIO_HINT_DEV_DURATION_LIMIT_1 = 1, 976c913257SDamien Le Moal IOPRIO_HINT_DEV_DURATION_LIMIT_2 = 2, 986c913257SDamien Le Moal IOPRIO_HINT_DEV_DURATION_LIMIT_3 = 3, 996c913257SDamien Le Moal IOPRIO_HINT_DEV_DURATION_LIMIT_4 = 4, 1006c913257SDamien Le Moal IOPRIO_HINT_DEV_DURATION_LIMIT_5 = 5, 1016c913257SDamien Le Moal IOPRIO_HINT_DEV_DURATION_LIMIT_6 = 6, 1026c913257SDamien Le Moal IOPRIO_HINT_DEV_DURATION_LIMIT_7 = 7, 1036c913257SDamien Le Moal }; 1046c913257SDamien Le Moal 10501584c1eSDamien Le Moal #define IOPRIO_BAD_VALUE(val, max) ((val) < 0 || (val) >= (max)) 10601584c1eSDamien Le Moal 10701584c1eSDamien Le Moal /* 10801584c1eSDamien Le Moal * Return an I/O priority value based on a class, a level and a hint. 10901584c1eSDamien Le Moal */ 110*c7b4b23bSDamien Le Moal static __always_inline __u16 ioprio_value(int prioclass, int priolevel, 111*c7b4b23bSDamien Le Moal int priohint) 11201584c1eSDamien Le Moal { 113*c7b4b23bSDamien Le Moal if (IOPRIO_BAD_VALUE(prioclass, IOPRIO_NR_CLASSES) || 114*c7b4b23bSDamien Le Moal IOPRIO_BAD_VALUE(priolevel, IOPRIO_NR_LEVELS) || 115*c7b4b23bSDamien Le Moal IOPRIO_BAD_VALUE(priohint, IOPRIO_NR_HINTS)) 11601584c1eSDamien Le Moal return IOPRIO_CLASS_INVALID << IOPRIO_CLASS_SHIFT; 11701584c1eSDamien Le Moal 118*c7b4b23bSDamien Le Moal return (prioclass << IOPRIO_CLASS_SHIFT) | 119*c7b4b23bSDamien Le Moal (priohint << IOPRIO_HINT_SHIFT) | priolevel; 12001584c1eSDamien Le Moal } 12101584c1eSDamien Le Moal 122*c7b4b23bSDamien Le Moal #define IOPRIO_PRIO_VALUE(prioclass, priolevel) \ 123*c7b4b23bSDamien Le Moal ioprio_value(prioclass, priolevel, IOPRIO_HINT_NONE) 124*c7b4b23bSDamien Le Moal #define IOPRIO_PRIO_VALUE_HINT(prioclass, priolevel, priohint) \ 125*c7b4b23bSDamien Le Moal ioprio_value(prioclass, priolevel, priohint) 12601584c1eSDamien Le Moal 12706447ae5SOliver Hartkopp #endif /* _UAPI_LINUX_IOPRIO_H */ 128