1 #include <errno.h> 2 #include <unistd.h> 3 #include <sched.h> 4 #include <stdio.h> 5 6 #include <err.h> 7 #include <sysexits.h> 8 #include "prutil.h" 9 10 /* 11 * $FreeBSD$ 12 */ 13 void quit(const char *text) 14 { 15 err(errno, text); 16 } 17 18 char *sched_text(int scheduler) 19 { 20 switch(scheduler) 21 { 22 case SCHED_FIFO: 23 return "SCHED_FIFO"; 24 25 case SCHED_RR: 26 return "SCHED_RR"; 27 28 case SCHED_OTHER: 29 return "SCHED_OTHER"; 30 31 default: 32 return "Illegal scheduler value"; 33 } 34 } 35 36 int sched_is(int line, struct sched_param *p, int shouldbe) 37 { 38 int scheduler; 39 struct sched_param param; 40 41 /* What scheduler are we running now? 42 */ 43 errno = 0; 44 scheduler = sched_getscheduler(0); 45 if (sched_getparam(0, ¶m)) 46 quit("sched_getparam"); 47 48 if (p) 49 *p = param; 50 51 if (shouldbe != -1 && scheduler != shouldbe) 52 { 53 fprintf(stderr, 54 "At line %d the scheduler should be %s yet it is %s.\n", 55 line, sched_text(shouldbe), sched_text(scheduler)); 56 57 exit(-1); 58 } 59 60 return scheduler; 61 } 62