1, Experimental purpose
Disk is a high-speed, high-capacity, rotating and directly accessible storage device. As the auxiliary memory of computer system, it undertakes heavy input and output work. In modern computer system, there are often several input and output requirements requiring access to disk at the same time. The system can adopt a strategy to execute requests to access disks in the best order possible. Since the disk access time is mainly affected by the seek time T, it is necessary to adopt an appropriate seek algorithm to reduce the seek time. This experiment requires students to simulate and design a disk scheduler and observe the dynamic running process of the scheduler. Let students understand and master the function of disk scheduling through experiments.
2, Experiment content:
Simulate the elevator scheduling algorithm to move the arm of the disk
3, Tips and requirements:
1. Suppose the disk has only one disk surface and the disk is a removable head disk.
2. A disk is a storage device that can be shared by multiple processes, but a disk can only serve one process at a time. When a process is accessing a disk, other processes that want to access the disk must wait until the disk is finished. When multiple processes put forward input and output requests and are in a waiting state, elevator scheduling algorithm can be used to select a process from several waiting visitors and let it access the disk. Set the "drive scheduling" process for this.
3. Because the disk and the processor work in parallel, when the disk is serving a process, other processes occupying the processor can propose to use the disk (here we only require access to the track), that is, dynamically apply for access to the track, and set the "accept request" process for this purpose.
4. In order to simulate the execution of the above two processes, it can be considered to use random numbers to determine the allowable order of the two processes. Refer to the attached figure for the program structure diagram:
5. The "accept request" process establishes a "process request I/O" table to indicate the tracks required by the process waiting to access the disk. The format of the table is as follows:
6. The function of "disk scheduling" is to check the "request I/O" table. When there are processes waiting for access, select a process waiting for access according to the elevator scheduling algorithm (SCAN algorithm) and access the track according to its specified requirements. SCAN algorithm refers to Chapter 9 of the textbook. Algorithm simulation block diagram.
7. The "initialization" work in the attached figure includes: initializing the "request I/O" table and setting the current arm moving direction; Current track number. It is assumed that several processes (4 ~ 8) have applied to access the corresponding track in the "request I/O" table before the program runs.
4, Experimental scheme
5, Experiment code (JAVA)
import java.util.Random; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("Please enter the number of access track numbers:"); final int x=in.nextInt(); System.out.println("Please select how to move the head(q->Small to large,w->Big to small): "); char dir = in.next().charAt(0); System.out.println("Please enter the initial head position(0-200): "); int start = in.nextInt(); int[] a = new int[x]; boolean[] b = new boolean[x]; //Determine whether it has been completed Random r = new Random(System.currentTimeMillis()); //Randomly generated sequence System.out.println("The following is the generated random sequence:"); for (int i = 0; i < x; i++) { a[i] = r.nextInt(200); System.out.print(a[i]+" "); //Output sequence } System.out.println(); /*System.out.println("Please enter the track access sequence (15 and between 0-200): "); / / manually enter the sequence for(int i=0;i<a.length;i++){ a[i]=in.nextInt(); }*/ for (int i = 0; i < x; i++) { //Bubble sorting for (int j = 0; j < x - i - 1; j++) { if (a[j] > a[j + 1]) { int temp = a[j + 1]; a[j + 1] = a[j]; a[j] = temp; } } } int ave = 0; switch (dir) { case 'q' -> { //Small to large System.out.println("Access track Moving distance"); for (int i = 0; i < x; i++) { if (a[i] >= start) { System.out.println(a[i] + " " + Math.abs(a[i] - start)); ave+=Math.abs(a[i] - start); start = a[i]; b[i] = true; } } for (int i = 0; i < x; i++) { if (!b[i]) { System.out.println(a[i] + " " + Math.abs(a[i] - start)); ave+=Math.abs(a[i] - start); start = a[i]; } } } case 'w' -> { //Big to small System.out.println("Access track Moving distance"); for (int i = x - 1; i >= 0; i--) { if (a[i] <= start) { System.out.println(a[i] + " " + Math.abs(start - a[i])); ave+=Math.abs(a[i] - start); start = a[i]; b[i] = true; } } for (int i = x - 1; i >= 0; i--) { if (!b[i]) { System.out.println(a[i] + " " + Math.abs(start - a[i])); ave+=Math.abs(a[i] - start); start = a[i]; } } } } System.out.print("The average moving distance is:"+ave/x); } }
6, Operation results
- Input:
two Generate random sequence:
3. Track access and average seek length: