base: use setjmp to speed up fiber
authorEarl Ou <shunhsingou@google.com>
Fri, 11 Sep 2020 01:21:52 +0000 (09:21 +0800)
committerEarl Ou <shunhsingou@google.com>
Wed, 16 Sep 2020 07:57:40 +0000 (07:57 +0000)
commit429b828e7b72906241698536ae6b797a63c6749c
tree9d1942f1b64499909f6a173f4145fadbe36ff2f8
parent8864c2ea24e274accdd0562d6854930a7130a325
base: use setjmp to speed up fiber

ucontext is an order of magnitude slower compared to most of the fiber
implementation, mainly due to the additional signal mask operation.

This change applies the trick provided in
http://www.1024cores.net/home/lock-free-algorithms/tricks/fibers,
which uses _setjmp/_longjmp to switch between contexts created by
ucontext.

Combine with NodeList improvement, we see 81% speed improvement with the
example provided by Matthias Jung:
https://gist.github.com/myzinsky/557200aa04556de44a317e0a10f51840

Compared with Accellera's SystemC, gem5 SystemC was originally 10x
slower, and with this change it's about 1.8x.

Change-Id: I0ffb6978e83dc8be049b750dc1baebb3d251601c
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/34356
Reviewed-by: Gabe Black <gabeblack@google.com>
Maintainer: Gabe Black <gabeblack@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
src/base/fiber.cc
src/base/fiber.hh