-
Notifications
You must be signed in to change notification settings - Fork 1
/
Scheduling.java
155 lines (144 loc) · 5.6 KB
/
Scheduling.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// This file contains the main() function for the Scheduling
// simulation. Init() initializes most of the variables by
// reading from a provided file. SchedulingAlgorithm.Run() is
// called from main() to run the simulation. Summary-Results
// is where the summary results are written, and Summary-Processes
// is where the process scheduling summary is written.
// Created by Alexander Reeder, 2001 January 06
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.StringTokenizer;
import java.util.Vector;
/*import sProcess;
import Common;
import Results;
import SchedulingAlgorithm;*/
public class Scheduling {
private static int processnum = 5;
private static int meanDev = 1000;
private static int standardDev = 100;
private static int runtime = 1000;
private static Vector processVector = new Vector();
private static Results result = new Results("null","null",0);
private static String resultsFile = "Summary-Results";
private static void Init(String file) {
File f = new File(file);
String line;
String tmp;
int cputime = 0;
int ioblocking = 0;
double X = 0.0;
try {
//BufferedReader in = new BufferedReader(new FileReader(f));
DataInputStream in = new DataInputStream(new FileInputStream(f));
while ((line = in.readLine()) != null) {
if (line.startsWith("numprocess")) {
StringTokenizer st = new StringTokenizer(line);
st.nextToken();
processnum = Common.s2i(st.nextToken());
}
if (line.startsWith("meandev")) {
StringTokenizer st = new StringTokenizer(line);
st.nextToken();
meanDev = Common.s2i(st.nextToken());
}
if (line.startsWith("standdev")) {
StringTokenizer st = new StringTokenizer(line);
st.nextToken();
standardDev = Common.s2i(st.nextToken());
}
if (line.startsWith("process")) {
StringTokenizer st = new StringTokenizer(line);
st.nextToken();
ioblocking = Common.s2i(st.nextToken());
X = Common.R1();
while (X == -1.0) {
X = Common.R1();
}
X = X * standardDev;
cputime = (int) X + meanDev;
processVector.addElement(new sProcess(cputime, ioblocking, 0, 0, 0));
}
if (line.startsWith("runtime")) {
StringTokenizer st = new StringTokenizer(line);
st.nextToken();
runtime = Common.s2i(st.nextToken());
}
}
in.close();
} catch (IOException e) { /* Handle exceptions */ }
}
private static void debug() {
int i = 0;
System.out.println("processnum " + processnum);
System.out.println("meandevm " + meanDev);
System.out.println("standdev " + standardDev);
int size = processVector.size();
for (i = 0; i < size; i++) {
sProcess process = (sProcess) processVector.elementAt(i);
System.out.println("process " + i + " " + process.cputime + " " + process.ioblocking + " " + process.cpudone + " " + process.numblocked);
}
System.out.println("runtime " + runtime);
}
public static void main(String[] args) {
int i = 0;
SchedulingAlgorithm scheduler = new PreemptiveScheduler();
if (args.length != 1) {
System.out.println("Usage: 'java Scheduling <INIT FILE>'");
System.exit(-1);
}
File f = new File(args[0]);
if (!(f.exists())) {
System.out.println("Scheduling: error, file '" + f.getName() + "' does not exist.");
System.exit(-1);
}
if (!(f.canRead())) {
System.out.println("Scheduling: error, read of " + f.getName() + " failed.");
System.exit(-1);
}
System.out.println("Working...");
Init(args[0]);
if (processVector.size() < processnum) {
i = 0;
while (processVector.size() < processnum) {
double X = Common.R1();
while (X == -1.0) {
X = Common.R1();
}
X = X * standardDev;
int cputime = (int) X + meanDev;
processVector.addElement(new sProcess(cputime,i*100,0,0,0));
i++;
}
}
result = scheduler.Run(runtime, processVector, result);
try {
//BufferedWriter out = new BufferedWriter(new FileWriter(resultsFile));
PrintStream out = new PrintStream(new FileOutputStream(resultsFile));
out.println("Scheduling Type: " + result.schedulingType);
out.println("Scheduling Name: " + result.schedulingName);
out.println("Simulation Run Time: " + result.compuTime);
out.println("Mean: " + meanDev);
out.println("Standard Deviation: " + standardDev);
out.println("Process #\tCPU Time\tIO Blocking\tCPU Completed\tCPU Blocked");
for (i = 0; i < processVector.size(); i++) {
sProcess process = (sProcess) processVector.elementAt(i);
out.print(Integer.toString(i));
if (i < 100) { out.print("\t\t"); } else { out.print("\t"); }
out.print(Integer.toString(process.cputime));
if (process.cputime < 100) { out.print(" (ms)\t\t"); } else { out.print(" (ms)\t"); }
out.print(Integer.toString(process.ioblocking));
if (process.ioblocking < 100) { out.print(" (ms)\t\t"); } else { out.print(" (ms)\t"); }
out.print(Integer.toString(process.cpudone));
if (process.cpudone < 100) { out.print(" (ms)\t\t"); } else { out.print(" (ms)\t"); }
out.println(process.numblocked + " times");
}
out.close();
} catch (IOException e) { /* Handle exceptions */ }
System.out.println("Completed.");
}
}