kernel-mode #1

Manually merged
anton merged 69 commits from kernel-mode into master 2021-11-16 08:02:40 +01:00
Showing only changes of commit 3d07c97a52 - Show all commits

View File

@ -160,9 +160,8 @@ class PrivCPU(CPU):
def step(self, verbose=True): def step(self, verbose=True):
try: try:
if self.cycle % 1000 == 0:
self._perf_counters.append((time.perf_counter_ns(), self.cycle))
self.cycle += 1 self.cycle += 1
if self.cycle % 10 == 0:
self._timer_step() self._timer_step()
self._check_interrupt() self._check_interrupt()
ins = self.mmu.read_ins(self.pc) ins = self.mmu.read_ins(self.pc)
@ -207,6 +206,9 @@ class PrivCPU(CPU):
self.pc = mtvec self.pc = mtvec
if mtvec & 0b11 == 1: if mtvec & 0b11 == 1:
self.pc = (mtvec & 0b11111111111111111111111111111100) + (trap.code * 4) self.pc = (mtvec & 0b11111111111111111111111111111100) + (trap.code * 4)
self.record_perf_profile()
if len(self._perf_counters) % 100 == 0:
self.show_perf()
def show_perf(self): def show_perf(self):
timed = 0 timed = 0
@ -214,19 +216,23 @@ class PrivCPU(CPU):
cps_list = list() cps_list = list()
print(FMT_CPU + "[CPU] Performance overview:") print(FMT_CPU + "[CPU] Performance overview:")
for time_ns, cycle in self._perf_counters[-11:]: for time_ns, cycle in self._perf_counters:
if cycled == 0: if cycled == 0:
cycled = cycle cycled = cycle
timed = time_ns timed = time_ns
continue continue
cps = (cycle - cycled) / (time_ns - timed) * 1000000000 cps = (cycle - cycled) / (time_ns - timed) * 1000000000
print(" {:03d} cycles in {:08d}ns ({:.2f} cycles/s)".format( #print(" {:03d} cycles in {:08d}ns ({:.2f} cycles/s)".format(
cycle - cycled, # cycle - cycled,
time_ns - timed, # time_ns - timed,
cps # cps
)) #))
cycled = cycle cycled = cycle
timed = time_ns timed = time_ns
cps_list.append(cps) cps_list.append(cps)
print(" on average {:.0f} cycles/s".format(sum(cps_list) / len(cps_list)) + FMT_NONE) print(" on average {:.0f} cycles/s".format(sum(cps_list) / len(cps_list)) + FMT_NONE)
self._perf_counters = list()
def record_perf_profile(self):
self._perf_counters.append((time.perf_counter_ns(), self.cycle))