-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnewClassDesign
More file actions
201 lines (176 loc) · 5.84 KB
/
newClassDesign
File metadata and controls
201 lines (176 loc) · 5.84 KB
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
class ConfigInput
// this is supposed to read from the configuration file
// config file contains the number of I/O modules and amount of memory and max_processes
// SystemConfig class will contain this info, load the information onto that
class SystemConfig
int max_proc;
int PSG; //granularity
int numI/O;
int memory;
class ReadJobs
// this reads from the Jobs file, initializes the InputEntry
// initializes only start_time, name
// initialize outputentry in the Output class
class ReadModelFiles
// reads the processname from each InputEntry initialized from ReadJobs
// initializes io_module_num, io_module_time, mem_req
class RunSpec
int type; // 0 for CpuSpec and 1 for IOSpec
class IOSpec extends RunSpec
int time_req;
int io_module_num;
// have a constructor here, remember to say super.type=1
class CpuSpec extends RunSpec
int time_req;
int mem_req;
// have a constructor here, remember to say super.type=1
class InputEntry
String pname;
int start_time;
LinkedList<RunSpec> reqs;
int exists; // this is 1 if it is in the PCB, 0 if it doesn't, -1 if it is done executing
//constructor taking pname and start_time
void add_cpuspec(int time, int mem)
/*
RunSpec obj = new CpuSpec(time, mem);
reqs.add(obj)
*/
void add_IOspec(int num, int time)
/*
RunSpec obj = new IOSpec(num, time);
reqs.add(obj)
*/
class Output
int output_times[] // array of times at which output must be printed
int current_index ; // current outputentry it is on
int nextOutputTime() // returns the time at which display_Output() will be called next
void display_Output() // displays the current process table
class InputTable
static InputEntry entries[]; // could be an ArrayList if you want it to dynamically grow and stuff, this is your headache
static checkfornewprocess(int current_time); //any process with start_time < current_time should be added to the PCB
/* if (start_time < current_time && entries[i].exists!=1)
if (PCB.addNewEntry(entries[i])==1 )
entries[i].exists=1 // this means it succeeded
*/
static addnewInputEntry(); // creates a new InputEntry
// if any other function is required, add it yourself
class Process
int pid;
int tableIndex;
int state;
LinkedList<RunSpec> specifications
int current_exec;
init()
/* state - -1 for execution done
0 for running
1 for waiting on I/O
2 for waiting on memory
3 for Ready */
//constructor
Process(InputEntry entry)
/*
//assign pid
specifications = entry.specifications
*/
int chkforIO()
/*
// -1 - complete 0 - added to I/O 1 - needs to be added to CPU
current_exec=0
specifications=specifications.getNext()
if (specifications==null)
state=-1
return -1
else if (specifications.head.type==1)
IOQueues.addnewProc(this)
return 0
else
return 1
*/
class PCB
static Process entries[] // make this an ArrayList
static int addNewEntry(InputEntry entry) // this should check if the max_proc is exceeded, if it is, then do nothing and return -1 for fail
/* also add to memory queue or IOqueue or ReadyQueue based on current system parameters */
static addtoQueue(int index, int type)
/*
//this should decide which queue to add to and call that respective queue's function
if (type==0)
{
check=entries[i].chkforIO()
if (check==1)
// we need to schedule the thing, so we check for memory
current_spec = (CpuSpec) entries[index].specifications;
if (Memory.current_free_memory>=current_spec.head.mem_req)
// we add to Ready queue
Ready.enqueue(entries[index])
else
// we add to memory waiting
Memory.enqueue(entries[index])
}
else if (type==1)
Ready.enqueue(entries[index])
*/
static removeDoneProcesses() // any entry that has it's state as -1 should be removed and it should be printed as finished in the log file
static getProcessByID(int pid) // returns the entry that matches the pid
static printProcessTable() // for output
class IOModuleEntry
Queue<Process> waiting;
Queue<Process> done;
addnewProcess(Process obj) //adds a new thing to the queue
update(int granularity) //updates the current_exec of the process at the head of the queue
/*
proc.current_exec+=granularity;
current_spec= (IOSpec)proc.specifications
if (proc.current_exec>=current_spec.head.time_req)
proc=dequeue()
proc.specifications=proc.specifications.getNext()
PCB.addtoQueue(proc.tableIndex, 0)
*/
class IOQueues
static IOModuleEntry queues[]
static addNewProc(ProcessTableEntry proc)
/*
queues[proc.specifications.head.io_module_num].addnewProcess(proc);
*/
static update(int psg)
/* for (i from 0 to queues.length)
queues[i].update(psg) */
class MemQueue
static Queue<Process> waiting;
static int current_free_memory;
static enqueue(ProcessTableEntry proc)
static update()
/*
// traverse through the queue, for each element
if (current_free_memory>=proc.specifications.head.mem_req)
proc=dequeue()
PCB.addtoQueue(proc.tableIndex,1)
updateCurrentFreeMem(proc.specifications.head.mem_req,-1)
*/
static updateCurrentFreeMem(int size, int incr) // if increment, incr = +1, else -1
class Ready
static Queue<Process> ReadyProcs;
static Process running;
static enqueue(Process proc)
static update(int psg)
/*
// this guy dequeues the head of the queue to Running and enqueues Running to the Ready Queue
PCB.entries[running.tableIndex].current_exec+=psg
PCB.addtoQueue(running.tableIndex,1)
running = ReadyProcs.dequeue()
*/
class Main
PSVM()
/*
ConfigInput
ReadJobs
ReadModelFiles
current_time=0
// initialization is done, InputTable by now will have all InputEntries and PCB will have all values initialized
while ()
/*
InputTable.checkfornewprocess(current_time)
Ready.update(SystemConfig.psg)
IOQueues.update(SystemConfig.psg)
PCB.removeDoneProcesses()
Memory.update()
*/