<div dir="ltr">Yeah, it's not like a big deal or anything. Here's all the places which grep told me use chains of || (or long switch statements which can't be turned into tables) to compare these values:<br><br>
ghc/rts//win32/AsyncIO.c:280<br>ghc/rts//Threads.c:286<br>ghc/rts//Threads.c:257<br>ghc/rts//sm/Scav.c:73<br>ghc/rts//sm/Sanity.c:521<br>ghc/rts//sm/Compact.c:436<br>ghc/rts//Schedule.c:2617<br>ghc/rts//Schedule.c:2605<br>
ghc/rts//Schedule.c:946<br>ghc/rts//RaiseAsync.h:54<br>ghc/rts//RaiseAsync.c:416<br><br><br>I didn't include all the ones in the profiler because they probably don't get hot.<div><br></div><div>Kyle<br><div class="gmail_extra">
<br><br><div class="gmail_quote">On Sun, Jul 20, 2014 at 4:43 AM, Jost Berthold <span dir="ltr"><<a href="mailto:berthold@mathematik.uni-marburg.de" target="_blank">berthold@mathematik.uni-marburg.de</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Message: 2<br>
Date: Sat, 19 Jul 2014 15:00:17 +1000<br>
From: Kyle Van Berendonck <<a href="mailto:kvanberendonck@gmail.com" target="_blank">kvanberendonck@gmail.com</a>><br>
To: "<a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a>" <<a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a>><br>
Subject: Thread status constants<br>
Message-ID:<br>
        <CAFSvR6A3maSWngY=<u></u>GJdATvGPjTAyuPokXZ5=rLtLT=<a href="mailto:EbYdSLKA@mail.gmail.com" target="_blank">EbYd<u></u>SLKA@mail.gmail.com</a>><br>
Content-Type: text/plain; charset="utf-8"<br>
<br>
Hi,<br>
<br>
I found these:<br>
<a href="https://github.com/ghc/ghc/blob/5f3c5384df59717ca8013c5df8d1f65692867825/includes/rts/Constants.h#L194" target="_blank">https://github.com/ghc/ghc/<u></u>blob/<u></u>5f3c5384df59717ca8013c5df8d1f6<u></u>5692867825/includes/rts/<u></u>Constants.h#L194</a><br>

<br>
They go only 0-14, so there's some long chains of branches and stuff in hot<br>
paths that could be cleaned up into single &-masked branches by changing<br>
these into a set of flags.<br>
<br>
And then I saw these:<br>
<a href="https://github.com/ghc/ghc/blob/master/libraries/base/GHC/Conc/Sync.lhs#L483" target="_blank">https://github.com/ghc/ghc/<u></u>blob/master/libraries/base/<u></u>GHC/Conc/Sync.lhs#L483</a><br>
<br>
Where does 16 and 17 come from -- I couldn't find them in the header files<br>
anywhere?<br>
<br>
Kyle<br>
</blockquote>
<br>
Hi Kyle,<br>
<br>
I had a look at these constants just recently.<br>
<br>
About 16 and 17, see here:<br>
  <a href="https://github.com/ghc/ghc/blob/master/rts/PrimOps.cmm#L853" target="_blank">https://github.com/ghc/ghc/<u></u>blob/master/rts/PrimOps.cmm#<u></u>L853</a><br>
<br>
About the others:The block reasons received two updates just recently.<br>
Turns out that the eventlog (GHC's post-mortem tracing for threadscope et al.) expects these states to have particular values (those in includes/rts/Constants.h, consider them a fixed ABI for the time being).<br>
See here for the story:<br>
  <a href="https://ghc.haskell.org/trac/ghc/ticket/9003" target="_blank">https://ghc.haskell.org/trac/<u></u>ghc/ticket/9003</a><br>
<br>
NB: Darn... base still uses GHC-7.8.2 constants. Thanks for the pointer!<br>
<br>
About your proposal to use bit masks:<br>
<br>
Did you find some of those hot paths?<br>
I believe (believe, unchecked...) that there are not too many places where a complete switch over all possible reasons is done (apart from debug output maybe); the typical use is rather to compare to one single constant than to all. So the performance might not increase too much from optimisations. Again, just a hunch, not verified.<br>

<br>
If the RTS contains code specialised to the current constants, these places need to be kept symbolic, to avoid future breakage when new states are added.<br>
<br>
A fix which removes the tight implicit dependency of ghc-events from the constants in includes/rts/Constants.h is pending, btw.<span class="HOEnZb"><font color="#888888"><br>
<br>
/ Jost<br>
<br>
</font></span></blockquote></div><br></div></div></div>