#include<linux/sched.h>#include<linux/sched/sysctl.h>#include<linux/sched/rt.h>#include<linux/mutex.h>#include<linux/spinlock.h>#include<linux/stop_machine.h>#include<linux/tick.h>#include<linux/slab.h>#include"cpupri.h"#include"cpuacct.h"structrq;extern__read_mostlyintscheduler_running;externunsignedlongcalc_load_update;externatomic_long_tcalc_load_tasks;externlongcalc_load_fold_active(structrq*this_rq);externvoidupdate_cpu_load_active(structrq*this_rq);/* * Convert user-nice values [ -20 ... 0 ... 19 ] * to static priority [ MAX_RT_PRIO..MAX_PRIO-1 ], * and back. */#define NICE_TO_PRIO(nice) (MAX_RT_PRIO + (nice) + 20)#define PRIO_TO_NICE(prio) ((prio) - MAX_RT_PRIO - 20)#define TASK_NICE(p) PRIO_TO_NICE((p)->static_prio)/* * 'User priority' is the nice value converted to something we * can work with better when scaling various scheduler parameters, * it's a [ 0 ... 39 ] range. */#define USER_PRIO(p) ((p)-MAX_RT_PRIO)#define TASK_USER_PRIO(p) USER_PRIO((p)->static_prio)#define MAX_USER_PRIO (USER_PRIO(MAX_PRIO))/* * Helpers for converting nanosecond timing to jiffy resolution */#define NS_TO_JIFFIES(TIME) ((unsigned long)(TIME) / (NSEC_PER_SEC / HZ))/* * Increase resolution of nice-level calculations for 64-bit architectures. * The extra resolution improves shares distribution and load balancing of * low-weight task groups (eg. nice +19 on an autogroup), deeper taskgroup * hierarchies, especially on larger systems. This is not a user-visible change * and does not change the user-interface for setting shares/weights. * * We increase resolution only if we have enough bits to allow this increased * resolution (i.e. BITS_PER_LONG > 32). The costs for increasing resolution * when BITS_PER_LONG <= 32 are pretty high and the returns do not justify the * increased costs. */#if 0 /* BITS_PER_LONG > 32 -- currently broken: it increases power usage under light load */# define SCHED_LOAD_RESOLUTION 10# define scale_load(w) ((w) << SCHED_LOAD_RESOLUTION)# define scale_load_down(w) ((w) >> SCHED_LOAD_RESOLUTION)#else# define SCHED_LOAD_RESOLUTION 0# define scale_load(w) (w)# define scale_load_down(w) (w)#endif#define SCHED_LOAD_SHIFT (10 + SCHED_LOAD_RESOLUTION)#define SCHED_LOAD_SCALE (1L << SCHED_LOAD_SHIFT)#define NICE_0_LOAD SCHED_LOAD_SCALE#define NICE_0_SHIFT SCHED_LOAD_SHIFT/* * These are the 'tuning knobs' of the scheduler: *//* * single value that denotes runtime == period, ie unlimited time. */#define RUNTIME_INF ((u64)~0ULL)staticinlineintrt_policy(intpolicy){if(policy==SCHED_FIFO||policy==SCHED_RR)return1;return0;}staticinlineinttask_has_rt_policy(structtask_struct*p){returnrt_policy(p->policy);}/* * This is the priority-queue data structure of the RT scheduling class: */structrt_prio_array{DECLARE_BITMAP(