Skip to content

Commit

Permalink
fixed off by one bug for cpu count and stats
Browse files Browse the repository at this point in the history
  • Loading branch information
Campanha house authored and Campanha house committed Jul 21, 2020
1 parent ca688b7 commit d521681
Showing 1 changed file with 8 additions and 23 deletions.
31 changes: 8 additions & 23 deletions cpu-intro/process-run.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,6 @@ def new_process(self):
self.proc_info[proc_id][PROC_STATE] = STATE_READY
return proc_id

# is this dead code? why is it here? no one knows...
def load_file(self, progfile):
fd = open(progfile)
proc_id = self.new_process()

for line in fd:
tmp = line.split()
if len(tmp) == 0:
continue
opcode = tmp[0]
if opcode == 'compute':
assert(len(tmp) == 2)
for i in range(int(tmp[1])):
self.proc_info[proc_id][PROC_CODE].append(DO_COMPUTE)
elif opcode == 'io':
assert(len(tmp) == 1)
self.proc_info[proc_id][PROC_CODE].append(DO_IO)
fd.close()
return

# program looks like this:
# c7,i,c1,i
# which means
Expand Down Expand Up @@ -105,6 +85,7 @@ def load(self, program_description):
exit(1)

num_instructions, chance_cpu = int(tmp[0]), float(tmp[1])/100.0
print("DEBUG > {}".format(num_instructions))
for i in range(num_instructions):
if random.random() < chance_cpu:
self.proc_info[proc_id][PROC_CODE].append(DO_COMPUTE)
Expand Down Expand Up @@ -266,18 +247,22 @@ def run(self):
print('%10s' % ('RUN:'+instruction_to_execute), end='')
else:
print('%10s' % (self.proc_info[pid][PROC_STATE]), end='')
if instruction_to_execute == '':
if instruction_to_execute == '' and \
self.proc_info[self.curr_proc][PROC_STATE] != STATE_DONE:
print('%10s' % ' ', end='')
else:
# Update table with CPU process for RUN:io or DONE
print('%10s' % 1, end='')
num_outstanding = self.get_ios_in_flight(clock_tick)
if num_outstanding > 0:
print('%10s' % str(num_outstanding), end='')
io_busy += 1
else:
elif num_outstanding <=0 and self.proc_info[self.curr_proc][PROC_STATE] != STATE_DONE:
print('%10s' % ' ', end='')
# Exit condition set PID to DONE and incrememnt cpu_busy to refelct cpu terminating process
if self.proc_info[self.curr_proc][PROC_STATE] == STATE_DONE:
cpu_busy += 1
print('')

# if this is an IO instruction, switch to waiting state
# and add an io completion in the future
if instruction_to_execute == DO_IO:
Expand Down

0 comments on commit d521681

Please sign in to comment.