#include /* sched.h */ #define MAX_USER_RT_PRIO 100 #define MAX_RT_PRIO MAX_USER_RT_PRIO #define MAX_PRIO (MAX_RT_PRIO + 40) /* sched.c */ #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) #define USER_PRIO(p) ((p)-MAX_RT_PRIO) #define MAX_USER_PRIO (USER_PRIO(MAX_PRIO)) #define PRIO_BONUS_RATIO 45 /* Between 45 and 49 */ #define INTERACTIVE_DELTA 2 #define SCALE(v1,v1_max,v2_max) \ (v1) * (v2_max) / (v1_max) #define DELTA(p) \ (SCALE(TASK_NICE(p), 40, MAX_USER_PRIO*PRIO_BONUS_RATIO/100) + \ INTERACTIVE_DELTA) #define TASK_INTERACTIVE(p) \ ((p)->prio <= (p)->static_prio - DELTA(p)) /*****************/ #define MAX_BONUS (MAX_USER_PRIO * PRIO_BONUS_RATIO / 100 / 2) #define MIN_BONUS (-MAX_BONUS) typedef struct { int static_prio; int prio; } mini_task_t; static void write_values(int nice) { int bonus; mini_task_t p; p.static_prio = NICE_TO_PRIO(nice); p.prio = p.static_prio + MIN_BONUS; printf("TASK_INTERACTIVE(%3d): [%d", nice, TASK_INTERACTIVE(&p)); for (bonus = MIN_BONUS + 1; bonus <= MAX_BONUS; bonus++) { p.prio = p.static_prio + bonus; printf(",%d", TASK_INTERACTIVE(&p)); } puts("]"); } int main(void) { printf("Interactivity bonus between %d and %d\n\n", MIN_BONUS, MAX_BONUS); write_values(-20); write_values(-10); write_values(0); write_values(10); write_values(19); puts(""); printf("nice +19 interactive tasks : %d\n", NICE_TO_PRIO(19) - MAX_BONUS); printf("nice 0 CPU hogs : %d\n", NICE_TO_PRIO(0) - MIN_BONUS); puts(""); printf("nice -20 CPU hogs : %d\n", NICE_TO_PRIO(-20) - MIN_BONUS); printf("nice 0 interactive tasks : %d\n", NICE_TO_PRIO(0) - MAX_BONUS); return 0; }