1. Homepage
  2. Programming
  3. CS537 Introduction to Operating Systems - Project 4: Dynamic Stride Scheduler with Dynamic Ticket Modification

CS537 Introduction to Operating Systems - Project 4: Dynamic Stride Scheduler with Dynamic Ticket Modification

Engage in a Conversation
WISCCS537Introduction to Operating SystemsLetter BoxedCDynamic Stride Schedulerxv6

CS537 Fall 2024, Project 4

Updates

  • global_tickets - this is the sum of tickets of all processes wanting the resource (CPU in our case), this includes the process that is running as well as all processes ready to be run. CourseNana.COM

  • getpinfo should return -1 in the case it fails. CourseNana.COM

  • A helpful explanation of scheduling in xv6 https://www.youtube.com/watch?v=eYfeOT1QYmg CourseNana.COM

  • Clarification on remain. Why do I need it?

    Think about stride as speed each process is running at, and pass as the total distance the process has covered. The goal of the stride scheduler in our analogy is to keep the processes as close as possible. We don't want any process to be left behind. We always pick the process which is the farthest behind. CourseNana.COM

    One way to think about it is the scheduler is trying to get it each process to atleast a threshold before letting any process run ahead. This value is the global_pass. CourseNana.COM

    Thinking in terms of speed will also clarify why we calculate global_pass as STRIDE1/global_tickets instead of taking an average of all strides. (Think back to when you needed to calculate the average speed in your physics class, you cannot just take the average of speeds). CourseNana.COM

    Because each process has a different speed, a process can cover variable amount of distance in one time unit. So a process with speed (stride) 100 will cover 100 units in one tick, while a process with speed (stride) 1, will just cover 1. CourseNana.COM

    For this reason, a process may be ahead or behind the average of the entire system at the time it goes to sleep. Let us consider 2 processes, A with stride 100 and B with stride 1, both of them have pass 0 at the start. CourseNana.COM

    Process A is scheduled first. Making its pass 100, now ideally we will schedule B 100 times before process A is scheduled again. After 20 times, B goes to sleep. Now when B is runnable again, we need to boost its pass value. We cannot use the same logic as setting it to the system average i.e. global_pass as it will be unfair as B was behind the average when it went to sleep. It should get more preference after being awake. This advantage/disadvantage compared to the global average is now encoded in terms of remain. CourseNana.COM

Dynamic Stride Scheduler with Dynamic Ticket Modification

In this project, you will implement a dynamic stride scheduler in xv6, incorporating dynamic ticket modification based on process behavior. The stride scheduler ensures that processes receive CPU time proportional to their assigned tickets, providing deterministic scheduling behavior. By dynamically adjusting tickets, the scheduler can adapt to changing process workloads, priorities, or resource usage. CourseNana.COM

Learning Objectives: CourseNana.COM

  • Understand and implement a stride scheduling algorithm.
  • Gain experience modifying and extending the xv6 operating system.
  • Understand how system calls, scheduler and process state are modified.

Project Details

Overview of Basic Stride Scheduling

The stride scheduler maintains a few additional pieces of information for each process: CourseNana.COM

  • tickets -- a value assigned upon process creation. It can be modified by a system call. It should default to 8.
  • stride -- a value that is inversely proportional to a process' tickets. stride = STRIDE1 / tickets where STRIDE1 is a constant (for this project: 1<<10).
  • pass -- initially set to 0. This gets updated every time the process runs.

When the stride scheduler runs, it selects the runnable process with the lowest pass value to run for the next tick. After the process runs, the scheduler increments its pass value by its stride: pass += stride. These steps ensures that over time, each process receives CPU time proportional to its tickets. CourseNana.COM

Dynamic Process Participation

The Basic Stride Algorithm does not account for changes to the total number of processes waiting to be scheduled. CourseNana.COM

Consider the case when we have 2 long running processes which have already been running and they all currently have a stride value of 1 and pass value of 100. A new process, let us say A now joins our system with stride value of 1. CourseNana.COM

What happens in the case of Basic Stride Scheduling? CourseNana.COM

Because the pass value of A is so small compared to the other processes, it will now be scheduled for the next 100 ticks before any other process is allowed to run. This is not the behavior we want. Given each process has equal tickets, we want the CPU to be shared equally among all of the processes including the newly arrived process. In this particular case we would want all processes to take turns. CourseNana.COM

How do we do that?

Let us maintain aggregate information about the set of processes waiting to be scheduled and use that information when a process enters or leaves. CourseNana.COM

  • global_tickets -- the sum of all runnable process's tickets.
  • global_stride -- inversely proportional to the global_tickets, specifically STRIDE1 / global_tickets
  • global_pass -- incremented by the current global_stride at every tick.

Now, when a process is created, its pass value will begin at global_pass. In the case of process A above, the global_stride and number of ticks that have occurred will make A's starting pass value be the same as the other 2 processes. CourseNana.COM

The global variables will need to be recalculated whenever a process enters or leaves to create the intended behaviour. CourseNana.COM

The final piece of information the scheduler will need to keep track for each process is the remain value which will store the remaining portion of its stride when a dynamic change occurs. The remain field represents the number of passes that are left before a process' next selection. When a process leaves the scheduler queue, remain is computed as the difference between the process' pass and the global_pass. Then when a process rejoins the system, its pass value is recomputed by adding its remain value to the global_pass. CourseNana.COM

This mechanism handles situations involving either positive or negative error between the specified and actual number of allocations. CourseNana.COM

  • If remain < stride, then the process is effectively given credit when it rejoins for having previously waited for part of its stride without receiving a timeslice tick to run.
  • If remain > stride, then the process is effectively penalized when it rejoins for having previously received a timeslice tick without waiting for its entire stride.

Let us consider an example, process A currently has a pass of 1000, where the global_pass is 600. Now process A decides to sleep on keyboard inturrupt. After a few ticks, when the interrupt occurs, the global_pass has updated to a 1400. We only want to increment A's pass for the time it was asleep, so we cannot just add 1400 to 1000. Instead we measure remain at the time process left the scheduler queue, in this case 1000-600=400, and when process A rejoins we will calculate the new pass as remain+global_pass that is 400+1400= 1800. CourseNana.COM

Dynamic Ticket Modification

We also want to support dynamically changing a process’ ticket allocation. CourseNana.COM

When a process’ allocation is dynamically changed from ticketsto tickets', its stride and pass values must be recomputed. The new stride' is computed as usual, inversely proportional to tickets. CourseNana.COM

To compute the new pass', the remaining portion of the client’s current stride, denoted by remain, is adjusted to reflect the new stride'. This is accomplished CourseNana.COM

by scaling remain by stride'/stride CourseNana.COM

Implementation

We will be using a modular scheduler for our implementation. Take a look at the Makefile and the SCHED_MACRO variable, your implementation should support both RR and Stride scheduler based on the flag passed. CourseNana.COM

We will only be implementing the dynamic stride scheduler for a single CPU. Also for this project, consider the timeslice equal to a tick in xv6. We will measure all our time in tick granuality. CourseNana.COM

Task 1 CourseNana.COM

Add appropriate fields in proc struct and get the number of ticks a process has been running for. Populate and maintain these values. CourseNana.COM

(Think about where is remain modified? How do you maintain the global values?) CourseNana.COM

Task 2 CourseNana.COM

Pick the process with the lowest pass value among all processes waiting to be scheduled. CourseNana.COM

(What is the process state here?). CourseNana.COM

For tie breaking, use the total runtime. That is the process which has spent lower number of ticks running will be scheduled first. If both the comparisions are equal fall back on pid. The process with smaller pid goes first. CourseNana.COM

The process' pass is updated everytime it is scheduled. CourseNana.COM

Task 3 CourseNana.COM

Create a new system call to allow a process to set its own number of tickets. CourseNana.COM

int settickets(int n);

The max tickets allowed to be set for a process is 1<<5. CourseNana.COM

The minimum tickets allowed is 1. CourseNana.COM

If a process sets a value lower than 1, set the number of tickets to default = 8. This is also the number of tickets a new process in your system should have. CourseNana.COM

Task 4 CourseNana.COM

Implement a system call CourseNana.COM

int getpinfo(struct pstat*);

To retrieve scheduling information for all processes. CourseNana.COM

struct pstat {
  int inuse[NPROC];      // Whether this slot of the process table is in use (1 or 0)
  int tickets[NPROC];    // Number of tickets for each process
  int pid[NPROC];        // PID of each process
  int pass[NPROC];       // Pass value of each process
  int remain[NPROC];     // Remain value of each process
  int stride[NPROC];     // Stride value for each process
  int rtime[NPROC];      // Total running time of each process
};

Note that you need to add this struct definition to a header file named pstat.h. The tests will include this header to work with the struct. CourseNana.COM

Task 5 CourseNana.COM

Yayy! You now have a running Stride scheduler. CourseNana.COM

To verify the difference in behavior we described above let us test both the RR and Stride scheduler on a CPU intensive workload, and use getpinfo to retrieve the scheduling information for them. CourseNana.COM

There is a workload.c file in the initial xv6 implementation, ensure you have _workload target in your UPROGS in the Makefile. CourseNana.COM

run the RR scheduler first (without modifying the scheduler flag) CourseNana.COM

make qemu-nox 

Now in xv6 run the workload with the following command: CourseNana.COM

workload &

Notice the & here, the workload runs for a long time so make sure to run it in the background or you may need to wait a substantial time before you can see your results. CourseNana.COM

You should now see periodic snapshots of the pstat of all the processes in the system. CourseNana.COM

Once you see "Done Measuring" printed to the output, run CourseNana.COM

cat rr_process_stats.csv

Copy this file to your lab machine. CourseNana.COM

Now repeat the process for your xv6 with compiled with CourseNana.COM

make qemu-nox SCHEDULER=STRIDE  

The final results this time will be visible by: CourseNana.COM

cat stride_process_stats.csv

Add both stride_process_stats.csv and rr_process_stats.csv inside your P4 directory. CourseNana.COM

Task 6 CourseNana.COM

Analyze the results of the workloads in your csvs to compare how processes with different tickets are scheduled in both cases. What is the advantage of stride scheduling? What is the behavior/pattern of process runtimes observed because of dynamic process participation? CourseNana.COM

Add this brief explaination to your README.md. CourseNana.COM

Here is what CourseNana.COM

ls p4

Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
WISC代写,CS537代写,Introduction to Operating Systems代写,Letter Boxed代写,C代写,Dynamic Stride Scheduler代写,xv6代写,WISC代编,CS537代编,Introduction to Operating Systems代编,Letter Boxed代编,C代编,Dynamic Stride Scheduler代编,xv6代编,WISC代考,CS537代考,Introduction to Operating Systems代考,Letter Boxed代考,C代考,Dynamic Stride Scheduler代考,xv6代考,WISChelp,CS537help,Introduction to Operating Systemshelp,Letter Boxedhelp,Chelp,Dynamic Stride Schedulerhelp,xv6help,WISC作业代写,CS537作业代写,Introduction to Operating Systems作业代写,Letter Boxed作业代写,C作业代写,Dynamic Stride Scheduler作业代写,xv6作业代写,WISC编程代写,CS537编程代写,Introduction to Operating Systems编程代写,Letter Boxed编程代写,C编程代写,Dynamic Stride Scheduler编程代写,xv6编程代写,WISCprogramming help,CS537programming help,Introduction to Operating Systemsprogramming help,Letter Boxedprogramming help,Cprogramming help,Dynamic Stride Schedulerprogramming help,xv6programming help,WISCassignment help,CS537assignment help,Introduction to Operating Systemsassignment help,Letter Boxedassignment help,Cassignment help,Dynamic Stride Schedulerassignment help,xv6assignment help,WISCsolution,CS537solution,Introduction to Operating Systemssolution,Letter Boxedsolution,Csolution,Dynamic Stride Schedulersolution,xv6solution,