How to implement a priority-based scheduler

Assignment Help Operating System
Reference no: EM131409714

Overview -

In this assignment, you will learn how to implement a priority-based scheduler for xv6. You'll do two things in this assignment:

  • You'll replace xv6's current round-robin scheduler with a priority-based scheduler.
  • You'll add a new syscall for a process to set its own priority.

Words of wisdom: first, please start early! Second, please make minimal changes to xv6; you do not want to make it hard for us to grade!

Part 1: Priority-based Scheduler for Xv6

In the first part, you will replace the round-robin scheduler for xv6 with a priority-based scheduler. The valid priority for a process is in the range of 0 to 200, inclusive. The smaller value represents the higher priority. For example, a process with a priority of 0 has the highest priority, while a process wall a priority of 200 has the lowest priority. The default priority for a process is 50. A priority-based scheduler always selects the process with the highest priority for execution. If there are multiple processes with the same highest priority, the scheduler uses round-robin to execute them in turn to avoid starvation. For example, if process A, B, C, D, E have the priority of 30, 30, 30, 40, 50 respectively, the scheduler should execute A, B, and C first in a round-robin fashion, then execute D, and execute E at last.

For this part, you will need to modify proc.h and proc.c. The change to proc.h is simple: just add an integer field called priority to struct proc. The changes to proc.c are more complicated. You first need to add a line of code in the allocproc function to set the default priority for a process to 50. Xv6's scheduler is implemented in the scheduler function in proc.c. The scheduler function is called by the main function in main.c as the last step of initialization. This function will never return. It loops forever to schedule the next available process for execution. If you are curious about how it works. In this part, you need to replace the scheduler function with your implementation of a priority-based scheduler. The major difference between your scheduler and the original one lies in how the next process is selected. Your scheduler loops through ail the processes to find a process with the highest priority (instead of locating the next runnable process). If there are multiple processes with the same priority, it schedules them in turn (round-robin). One way to do that is to save the last scheduled process and start from it to loop through all the processes.

A major issue of the priority scheduling is starvation in which a low priority process never gets CPU time due to the existence of runnable higher priority processes. A solution to this problem is called aging. You will also implement aging for you scheduler. Specifically, if the process uses up its CPU time, you are going to decrease its priority by 2 (i.e., add 2 to its priority since lower numbers represent higher priority); if a process is waken up from waiting, increase its priority by 2. Keep in mind that you should always keep the priority in its valid range (0 to 2040). In this part, you new to add some code to function wakeup1 in proc.c, and function trap in trap.c.

Part 2: Add a Syscall to Set Priority

The first part adds support of the priority-based scheduling. However, all the processes still have the same priority (50, the default priority). In the second part, you will add a new syscall (setpriority) for the process to change its priority. The syscall changes the current process's priority and returns the old priority. If the new priority is lower than the old priority (i.e., the value of new priority is larger), the syscall will call yield to reschedule.

In this part, you will need to change user.h usys.S, syscall.c and sysproc.c. Review project 2 to refresh the steps to add a new syscall. Here is a summery of what to do in each file:

  • syscall.h: add a new definition for SYS_setpriority.
  • user.h: declare the function for user-space applications to access the syscall by adding: int setpriority(int);
  • usys.S: implement the setpriority function by making a syscall to the kernel.
  • syscall.c: add the handler for SYS_setpriority to the syscalls table using this declaration: extern int sys_setpriority(void);
  • sysproc.c: implement the syscall handler sys_setpriority. In this function, you need to check that the new priority is valid (in the range of [0, 200]), update the process's priority. If the new priority is larger than the old priority, call yield to reschedule. You can use the proc pointer to access the process control block of the current process.

Deliverables -

As usual, the grading platform is linprog. Make sure your code works on linprog.

Please make sure your source code can compile. Absolutely no credit if it does not compile.

Please don't include the binary files. Do a make clean before submission. You'll make grading harder for us if you do.

Please don't leave out any files! You'll make grading harder for us if you do.

Please don't modify any files you don't need to! You'll make grading harder for us if you do.

Please don't send us the meta-information from vow revision control system! You'll make grading harder for us.

Reference no: EM131409714

Questions Cloud

Reaction of elemental iron and oxygen : The reaction above shows two possible products that can result from the reaction of elemental iron and oxygen. Given the following empirical data, answer questions a-c.
Construct a graph of the time series along with the equation : Construct a graph of the time series along with the equations fitted in parts (a) and (b). Which equation appears to better fit the data?
Combined mass of carbon dioxide and water : An automobile gasoline tank holds 21 kg of gasoline. When the gasoline burns, 84 kg of oxygen is consumed, and carbon dioxide and water are produced. What is the total combined mass of carbon dioxide and water that is produced?
What does each painting tell us about the artist who drew it : Find a minimum of three (3) resources on the Internet that will help you answer the above four questions. Be sure to copy the title page and URL of each web site you found. Be sure your links are ACTIVE. Briefly describe EACH resource and tell wha..
How to implement a priority-based scheduler : In this assignment, you will learn how to implement a priority-based scheduler for xv6. You'll do two things in this assignment: You'll replace xv6's current round-robin scheduler with a priority-based scheduler
Develop an algorithm for an alternative startborder method : Develop an algorithm for an alternative StartBorder method, createMultipleToads, which generates a Toad agent with probability 0.3 as long as the number of toads is less than 50. Multiple toads can be in a cell.
Which of the reactants is the limiting reactant : If 5.42 g of nitrogen gas are reacted with 5.42 g of hydrogen gas, which of the reactants is the limiting reactant? Use the molar mass data below if necessary. Show all your work to explain your answer.
What are the maximum amounts that can be contributed : BUS-121: What are the maximum amounts that can be contributed to a Traditional IRA, Roth IRA and 401(k) per year? What is the maximum amount of capital loss that can be deducted from your income taxes per year?
Does the overall trend appear to be upward or downward : Determine the three-month and five-month centered moving average curves and superimpose each on the original time series.

Reviews

Write a Review

Operating System Questions & Answers

  Web system deployed on campus has a failure rate

A web system deployed on campus has a failure rate of 10-3 failures per hour. What is the likeihood that the system will continue operating without failure throughout the duration of one week (Monday to Friday)?

  What are the major challenges that an os designer faces in

1.concurrency of course is a requirement for modern operating systems. what are the major challenges that an os

  Inter process communication services implementation

You will provide a diagram illustrating the Linux kernel architecture and various components and classify it according to what we discussed in class, Inter Process Communication services implementation

  Write a research on evaluation of education system

Write  a  Research  on  evaluation of education system  Literature review Analyzing the problem

  How much physical memory is needed iif shared text is used

How much physical memory is needed (a) is shared text is used, and (b) if it is not?

  Compare and contrast proprietary and open-source

Explain why your company's proprietary operating system will have to be upgraded. Explain why other operating systems may or may not fit.

  Are there any drawbacks to using embedded operating systems

An embedded computer system runs nearly every electronic device available today. Are there any drawbacks to using embedded operating systems

  In this assignment you will implement a deadlock avoidance

in this assignment you will implement a deadlock avoidance algorithm as part of the process manager to avoid deadlocks

  Develop a technology proposal

You have been hired by Crete LLC as an Information Technology consultant to develop a technology proposal. Crete LLC manufactures and distributes solar panel for the consumer market. Your job is to submit a proposal that meets their criteria.

  Point to point and end to end security models

Argue differences in point to point and end to end security models and security problems they address. Are they redundant?

  Identify at least two advantages that host-based firewalls

From the e-Activity, identify at least two advantages that host-based firewalls have over network (i.e., perimeter-based) firewalls. Use one example that demonstrates the superiority of host-based firewalls in order to justify your response.

  Identify the levels in the file hierarchy

Identify the levels in the file hierarchy and identify the order in which the directories need to be created and identify the commands used for creating the file hierarchy.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd