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

  Create a report based on the query

Increase the font size of the Total Purchases by Customer label (in the strCustomerNameFooter section) to 11 and the =Sum calculated control to 10 points. Change the font color of both to dark blue.

  Inventory tracking database

Construct a relational database of your choice. The DB should contain no more than six tables. Define three business requirements that this database will provide.

  Create a node structure

Create a Node structure. Initialize the number variable to -1 and the nextNode pointer to nullptr - Add the even numbers between 0 and 40 to the list. Your list will therefore have 20 numbers in it at that point.

  Compare the average behavior of insertion sort

Compare the average behavior of insertion sort for n elements with that of the n insertions into an initially-empty straight array implementation of a priority queue

  Your final project is a script which performs a fundamental

your final project will utilize many of the various skills that you have learned throughout this course. the final

  Efficient algorithm to achieve goal using few base stations

Certain points along the road, so that every house is within four miles of one of the base stations. Give an efficient algorithm that achieves this goal using as few base stations as possible.

  Java program to find largest and smallest numbers

Create a Java program that will search a text document of strings representing numbers of type int and will write the largest and the smallest numbers to screen.

  Transmitting image using raster scan order

If we were to transmit this image using raster scan order, after 15 seconds how many rows of the image will the user have received?

  Modify bellman ford algorithm to find negative weight cycle

Demonstrate how to modify the Bellman Ford algorithm to find and print a negative weight cycle in a weighted directed graph G if one exists.

  Design an adt for a two-color

Design an ADT for a two-color, double-stack ADT that consists of two stacks one "red" and one "blue" and has as its operations color-coded versions of the regular stack ADT operations.

  Prove that you should not also use the greedy strategy

Prove that you should not also use the greedy strategy. That is, show that thereis a game that you can win, but only if you do not follow the same greedy strategy as Elmo.

  Can you find the element of an array

We would like to determine whether a given array A has a majority element, and if so, find the element.

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