NJU-ProjectN / nemu

NJU EMUlator, a full system x86/mips32/riscv32/riscv64 emulator for teaching
Other
858 stars 184 forks source link

Slightly improve performance of init_mem #73

Closed FurryAcetylCoA closed 1 year ago

FurryAcetylCoA commented 1 year ago

The advantage of using getrandom is that it allows bulk filling of pmem , as opposed to the byte-by-byte filling required by rand.

This change has led to a tiny optimization. Reducing the runtime about 200 milliseconds.

However, a side effect of this change is that when TARGET_AM is set. init_mem will no longer fill pmem with exact same random bytes every time. Given that getrandom is not affect by srand. (I am not sure if it matters.)

I can add a #ifdef CONFIG_TARGET_AM if necessary.

sashimi-yzh commented 1 year ago

Inspired by your goal, I change the randomization code to improve the performance by 100X. The key idea is that it is not necessary to randomize each memory entry with different values. See 4fbe3ab3ba70a2cc6af0e2698a4041e89ac4dfc0.

Thank you for your contribution!