public int CompareTo(Task obj) { // The priority modifiers to add faux bias SchedulingBias currentBias = Program.currentBias; switch (currentBias) { case SchedulingBias.Default: return((Vruntime < obj.Vruntime) ? -1 : 1); case SchedulingBias.Energy: // powerConsumption needs to be lowest return((PowerConsumption < obj.PowerConsumption) ? -1 : 1); case SchedulingBias.Performance: // Priority focused return((Priority < obj.Priority) ? -1 : 1); case SchedulingBias.UserFocus: // if this task is a user process if (Priority < 1500 && Priority > 1250) { return(-1); } // if the other task is a user process else if (obj.Priority < 1500 && obj.Priority > 1250) { return(1); } // if neither is a user process else { return((Vruntime < obj.Vruntime) ? -1 : 1); } } return((this.Vruntime < obj.Vruntime) ? -1 : 1); }
static void Main(string[] args) { Console.WriteLine("Welcome to the Completely Fair Scheduler Simulator"); Console.WriteLine("Do you want to introduce a scheduling bias? (Y/n):"); String wantBias = Console.ReadLine().Trim().ToLower(); int schedulingBias; if (wantBias.Equals("y")) { Console.WriteLine("Pick your bias: "); Console.WriteLine("1. Energy"); Console.WriteLine("2. Performance"); Console.WriteLine("3. UserFocus"); schedulingBias = int.Parse(Console.ReadLine()); switch (schedulingBias) { case 1: currentBias = SchedulingBias.Energy; break; case 2: currentBias = SchedulingBias.Performance; break; case 3: currentBias = SchedulingBias.UserFocus; break; default: currentBias = SchedulingBias.Default; break; } } Timer taskTimer = new Timer { Interval = new Random().Next(1000), Enabled = true, AutoReset = true, }; taskTimer.Elapsed += GenerateTasks; Console.Clear(); Console.WriteLine("\tProcessID\tPriority\tvRuntime\tPower Consumption\n"); BinomialHeap <Task> schedulingHeap = new BinomialHeap <Task>(); Console.CancelKeyPress += new ConsoleCancelEventHandler(myHandler); while (true) { Task readyTask = null; processReadyQueue.TryPop(out readyTask); if (readyTask != null) { schedulingHeap.Insert(readyTask); if (!running) { running = true; Task currentTask = schedulingHeap.ExtractMin(); Thread cpuLoop = new Thread(() => CPUThread(currentTask)); cpuLoop.Start(); } } } }