How to implement a priority-based scheduler

Assignment Help Data Structure & Algorithms
Reference no: EM131306828

1 Overview

In this assignment, you will learn how to implement a priority-based scheduler forxv6. To get started, download a new copy of the xv6 source code fromhere.

Do NOT use the source code of project 1. 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 with 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 mpmain 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, read Xv6 book/commentary, Chapter 5. 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 all 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 your 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 200). In this part, you need 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.h, syscall.c, and sysproc.c. Review project 1 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.

Reference no: EM131306828

Questions Cloud

Design a perceptron network to solve this problem : Consider again the four-class decision problem that we introduced in Problem P4.3. Train a perceptron network to solve this problem using the perceptron learning rule.
What are some projects in place that will address problem : What are some projects in place that will address the problem (suggest one if none exist yet)? Why did you choose your topic? How has learning about the topic affected your ideas going into this assignment?
Compute the gross profit margin and operating income margin : On the same spreadsheet, compute the gross profit margin, operating income margin, and net profit margin for 2012, showing the numerator and denominator for all ratios.
Submit your topic of interest and tell how it relate to race : In a Word document, submit your topic of interest, tell how it relates to race and ethnicity or social change, and explain what you hope to learn from this topic. You will also provide a brief summary of the article.
How to implement a priority-based scheduler : COP4610: Introduction to Operating Systems - Project 4: Priority-based Scheduler - you will learn how to implement a priority-based scheduler forxv6. To get started, download a new copy of the xv6 source code fromhere.
How do you think you will feel after the reactions : Is it a formal norm or an informal one? What reactions by others do you expect? If published, might these reactions affect your life chances? How do you think you will feel after the reactions?
What implications does imperfect nature of type of research : What implications does the imperfect nature of this type of research have for social psychological science? How can these two competing views (by the same person) be reconciled?
Determine the fundamental the castle doctrine : Specify the key points involved in the court determining the lawfulness of the use of force. Next, evaluate the level of objectivity inherent in each point that you have specified.Determine the fundamental difference between the castle doctrine an..
Evaluate the main points of the reading in three paragraphs : Summarize, explain, and evaluate the main points of the reading in a minimum of 3 paragraphs. Do not simply cut and paste from the reading, but summarize the main points in your own words.

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Doubly linked list

Write a class that maintains the top 10 scores for a game application, implementing the add and remove methods but using a doubly linked list instead of an array. Program has to be written in java

  Ford-fulkerson algorithm on capacities

Write code that finds a maximum flow in a directed graph, using the Ford-Fulkerson algorithm on capacities given as matrix void maximum flow(

  Two phase routing algorithm

Two Phase Routing Algorithm: use the analysis of the first phase to give a full analysis (no "symmetry" argument) of the second phase.

  Find the minimum cost path from a designated node

Find the Minimum Cost Path from a designated start node to a designated destination node in a graph.

  Explain in words a linear-time algorithm

The max subsequence product problem for an array a = a1,a2,...,an of integers is the problem of determining the largest product E(summation)k=1(bottom) j(top) ak formed by a subsequence of a.

  Which actions would be inappropriate for program to take

If the user types an invalid value into a TextBox and moves focus to another TextBox, which of the following actions would be inappropriate for the program to take?

  Why xml is important in structuring and exchanging data

As a SQL developer, explain how do you enforce the following types of constraints in SQL-based database systems? Use English to explain. You may explain using an example.

  Identify classes, functions, and algorithms

Detailed requirements. Using guidance provided in the text, (specifically chapters 12 and 13) develop your detailed requirements. Develop as many as possible but you must cover some detailed requirements for each of your high level requirements.

  Create a class whose main method creates three arrays

Create a class whose main method creates three arrays. The first array will contain five kinds of flowers - petunia, pansy, rose, violet, and carnation.

  Write a recursive solution to towers of hanoi problem

Write a recursive solution to Towers of Hanoi problem - This child''s toy is actually an example of a classic mathematical puzzle called the Towers of Hanoi problem.

  Modify the algorithm to print the sales amount

Study the algorithm below and then modify the algorithm to print the sales amount for all ten salespersons. Review the algorithm, identify the inaccuracies, insert the corrections, save the document, and submit the document for grading.

  The class linked bag did not have the data member itemcount

the class LinkedBag did not have the data member itemCount. Revise the method getCurrentSize so that it counts the number of nodes in the linked chain

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