-
Notifications
You must be signed in to change notification settings - Fork 0
/
schedulerpolicy.py
44 lines (37 loc) · 1.21 KB
/
schedulerpolicy.py
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
#!/usr/bin/env pypy
from job import Job
'''
Author: Inigo, Cheng
'''
class SchedulerPolicy:
class Type:
SJF = 0
FIFO = 1
FIFOPR = 2
def __init__(self):
# Jobs
self.jobs = {}
self.jobsQueue = []
self.jobsDone = []
self.schedType = SchedulerPolicy.Type.FIFOPR
'''
Scheduling policies.
Returns the order of 2 jobs according to the scheduling policy
'''
def schedulingPolicy(self, jobId1, jobId2):
if self.schedType == SchedulerPolicy.Type.SJF:
return self.schedulingSJF(jobId1, jobId2)
elif self.schedType == SchedulerPolicy.Type.FIFOPR:
return self.schedulingFIFOprior(jobId1, jobId2)
def schedulingFIFO(self, jobId1, jobId2):
return self.jobs[jobId1].submit-self.jobs[jobId2].submit
def schedulingFIFOprior(self, jobId1, jobId2):
if self.jobs[jobId1].priority==self.jobs[jobId2].priority:
return self.jobs[jobId1].submit-self.jobs[jobId2].submit
else:
return self.jobs[jobId2].priority-self.jobs[jobId1].priority
def schedulingSJF(self, jobId1, jobId2):
# TODO cheng
# One approach can be to check length of the jobs in the queue
# Sort it according to the length
return self.jobs[jobId2].nmaps*self.jobs[jobId2].lmap - self.jobs[jobId1].nmaps*self.jobs[jobId1].lmap