1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 29ccd27ccSIngo Molnar #ifndef _LINUX_SCHED_PRIO_H 39ccd27ccSIngo Molnar #define _LINUX_SCHED_PRIO_H 45c228079SDongsheng Yang 53ee237ddSDongsheng Yang #define MAX_NICE 19 63ee237ddSDongsheng Yang #define MIN_NICE -20 73ee237ddSDongsheng Yang #define NICE_WIDTH (MAX_NICE - MIN_NICE + 1) 83ee237ddSDongsheng Yang 95c228079SDongsheng Yang /* 105c228079SDongsheng Yang * Priority of a process goes from 0..MAX_PRIO-1, valid RT 115c228079SDongsheng Yang * priority is 0..MAX_RT_PRIO-1, and SCHED_NORMAL/SCHED_BATCH 125c228079SDongsheng Yang * tasks are in the range MAX_RT_PRIO..MAX_PRIO-1. Priority 135c228079SDongsheng Yang * values are inverted: lower p->prio value means higher priority. 145c228079SDongsheng Yang */ 155c228079SDongsheng Yang 16*ae18ad28SDietmar Eggemann #define MAX_RT_PRIO 100 175c228079SDongsheng Yang 183ee237ddSDongsheng Yang #define MAX_PRIO (MAX_RT_PRIO + NICE_WIDTH) 193ee237ddSDongsheng Yang #define DEFAULT_PRIO (MAX_RT_PRIO + NICE_WIDTH / 2) 205c228079SDongsheng Yang 216b6350f1SDongsheng Yang /* 226b6350f1SDongsheng Yang * Convert user-nice values [ -20 ... 0 ... 19 ] 236b6350f1SDongsheng Yang * to static priority [ MAX_RT_PRIO..MAX_PRIO-1 ], 246b6350f1SDongsheng Yang * and back. 256b6350f1SDongsheng Yang */ 267e298d60SDongsheng Yang #define NICE_TO_PRIO(nice) ((nice) + DEFAULT_PRIO) 277e298d60SDongsheng Yang #define PRIO_TO_NICE(prio) ((prio) - DEFAULT_PRIO) 286b6350f1SDongsheng Yang 296b6350f1SDongsheng Yang /* 307aa2c016SDongsheng Yang * Convert nice value [19,-20] to rlimit style value [1,40]. 317aa2c016SDongsheng Yang */ nice_to_rlimit(long nice)327aa2c016SDongsheng Yangstatic inline long nice_to_rlimit(long nice) 337aa2c016SDongsheng Yang { 347aa2c016SDongsheng Yang return (MAX_NICE - nice + 1); 357aa2c016SDongsheng Yang } 367aa2c016SDongsheng Yang 377aa2c016SDongsheng Yang /* 387aa2c016SDongsheng Yang * Convert rlimit style value [1,40] to nice value [-20, 19]. 397aa2c016SDongsheng Yang */ rlimit_to_nice(long prio)407aa2c016SDongsheng Yangstatic inline long rlimit_to_nice(long prio) 417aa2c016SDongsheng Yang { 427aa2c016SDongsheng Yang return (MAX_NICE - prio + 1); 437aa2c016SDongsheng Yang } 447aa2c016SDongsheng Yang 459ccd27ccSIngo Molnar #endif /* _LINUX_SCHED_PRIO_H */ 46