[mini] Introduce job control to the JIT. Limits by active and duplicate jobs.
authorRodrigo Kumpera <kumpera@gmail.com>
Thu, 8 Dec 2016 00:10:41 +0000 (16:10 -0800)
committerRodrigo Kumpera <kumpera@gmail.com>
Thu, 6 Apr 2017 23:09:00 +0000 (16:09 -0700)
commit9b97962a043b0b583462d5e5234612e4d73a317c
tree97733344c4cd30f9d7db9c2a23ac6130dd4588f5
parentc66af2563ef5b77190abfa1ac34773c7f9329520
[mini] Introduce job control to the JIT. Limits by active and duplicate jobs.

This shown up as a problem under parallel roslyn.

We hit frequently the case of multiple threads compiling the same method in parallel
and wasting all but one.

Another issue that happens, but infrequently, is having more threads JITing than there
are cores in the machine. Such thrashing doesn't help.

Test setup. 4/8 macbook pro compiling corlib.

Baseline:
real 0m7.665s
user 0m20.078s
sys 0m2.653s
Methods JITted using mono JIT       : 22422
Total time spent JITting (sec)      : 18.5365

With this patch:
real 0m6.149s
user 0m18.504s
sys 0m1.487s
Methods JITted using mono JIT       : 16619
Total time spent JITting (sec)      : 4.9420

New counters
JIT compile waited others           : 7681
JIT compile 1+ jobs                 : 1
JIT compile overload wait           : 67
JIT compile spurious wakeups        : 14469

This results in a 20% wall clock reduction but only a 8% reduction on user.

We JIT 26% less methods, with very few duplications. Showing this drastically improves the situation.

JIT compilation time metrics are bogus due to .cctors and other sources of interference. So take it with a grain of salt.

Future work:

Based on the new counters, it's clear that the current wakeup design is suboptimal and we could further improve it by cutting on spurious wakeups.
mono/mini/mini-runtime.c
mono/mini/mini.h