unicorn-engine/unicorn

Does Unicorn still keep and use the cache after ending execution of uc_emu_start ?

pent0 opened this issue · 1 comments

pent0 commented

Context:

  • I'm emulating a type of OS and have to stop each 20000 ticks to reschedule emulated threads. It's something of this:
     while (!shutdown) {
         uc_emu_start(engine, pc, 1ULL << 63, 0, 20000);
         do_kernel_reschedule();
     }
  • If I try to run this without instructions limit, and do reschedule in code hook, it's super fast. But if I do like above, the performance drops are noticeable, especially when the emulated system enters a big loop.

  • It's not my reschedule that's slow, because there is another JIT backend I use, that although slower than Unicorn in general, but it keeps the cache and suprass Unicorn in loop situation.

  • So does Unicorn still keep cache after uc_emu_start done?

TLDR: Unicorn is slow when restarting continously. I want to ask if Unicorn stills keep cache after uc_emu_start done.

I'm happy to provide more information. Thanks.

Note: The build I'm using is release build on the web, but this question still relevant to master branch on github.

pent0 commented

I think I found the evil line:

unicorn/qemu/cpu-exec.c

Lines 279 to 282 in 19ffa83

// Unicorn: flush JIT cache to because emulation might stop in
// the middle of translation, thus generate incomplete code.
// TODO: optimize this for better performance
tb_flush(env);

Waiting for an optimization :)