[Pkg-haskell-maintainers] Bug#677096: thread-using code built with current ghc's non-threaded runtime spins

Joey Hess joeyh at debian.org
Mon Jun 11 16:07:57 UTC 2012


Package: ghc
Version: 7.4.1-3
Severity: normal

Stracing xmonad, I see a rather tight loop like this:

--- SIGVTALRM (Virtual timer expired) @ 0 (0) ---
sigreturn()                             = ? (mask now [])
poll([{fd=3, events=POLLIN}], 1, -1)    = ? ERESTART_RESTARTBLOCK (To be restarted)
--- SIGVTALRM (Virtual timer expired) @ 0 (0) ---
sigreturn()                             = ? (mask now [])
poll([{fd=3, events=POLLIN}], 1, -1)    = ? ERESTART_RESTARTBLOCK (To be restarted)
--- SIGVTALRM (Virtual timer expired) @ 0 (0) ---
sigreturn()                             = ? (mask now [])
poll([{fd=3, events=POLLIN}], 1, -1)    = ? ERESTART_RESTARTBLOCK (To be restarted)
--- SIGVTALRM (Virtual timer expired) @ 0 (0) ---
sigreturn()                             = ? (mask now [])
poll([{fd=3, events=POLLIN}], 1, -1)    = ? ERESTART_RESTARTBLOCK (To be restarted)

This is probably bad for a daemon or long-running program, especially
on a laptop. It will probably keep the CPU from entering wait states.

Powertop seems to bear this out; when xmonad is running my laptop
enters the C1 idle state less than 10% of the time; when I
kill -STOP xmonad, this jumps to 20% or more. Also, xmonad is
at the top of powertop's list of offenders:

                Usage       Events/s    Category       Description
             11.0 ms/s      46.7        Process        /home/joey/.xmonad/xmonad

I can reproduce a similar tight loop in strace with this simple program,
when built with ghc 7.4, without the threaded runtime:

import Control.Monad
import Control.Concurrent

fooThread = forever $ threadDelay 100000000 -- 100 seconds

main = do
        forkIO fooThread
        fooThread

The strace is much the same as the xmonad one, only the condition the threads
are waiting on varies, but the constant waking up remains the same.

gettimeofday({1339429713, 896353}, NULL) = 0
select(0, [], [], NULL, {99, 540844})   = ? ERESTARTNOHAND (To be restarted)
--- SIGVTALRM (Virtual timer expired) @ 0 (0) ---
sigreturn()                             = ? (mask now [])
gettimeofday({1339429713, 906388}, NULL) = 0
select(0, [], [], NULL, {99, 532563})   = ? ERESTARTNOHAND (To be restarted)
--- SIGVTALRM (Virtual timer expired) @ 0 (0) ---
sigreturn()                             = ? (mask now [])
gettimeofday({1339429713, 917327}, NULL) = 0
select(0, [], [], NULL, {99, 524158})   = ? ERESTARTNOHAND (To be restarted)
--- SIGVTALRM (Virtual timer expired) @ 0 (0) ---
sigreturn()                             = ? (mask now [])
gettimeofday({1339429713, 926545}, NULL) = 0
select(0, [], [], NULL, {99, 516729})   = ? ERESTARTNOHAND (To be restarted)
--- SIGVTALRM (Virtual timer expired) @ 0 (0) ---

With the threaded runtime, this doesn't happen.

And, if I build it with ghc 6.12, nonthreaded runtime, the
strace looks like this:

gettimeofday({1339429071, 169771}, NULL) = 0
gettimeofday({1339429071, 169926}, NULL) = 0
select(0, [], [], NULL, {100, 20000}

If we're going to ship this GHC, then this bug should at least be cloned
to xmonad and it made to build with -threaded. That seems to work well
for me.

-- System Information:
Debian Release: wheezy/sid
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: i386 (i686)

Kernel: Linux 3.2.0-2-686-pae (SMP w/2 CPU cores)
Locale: LANG=en_US.utf8, LC_CTYPE=en_US.utf8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages ghc depends on:
ii  gcc          4:4.7.0-6
ii  libbsd-dev   0.3.0-2
ii  libc6        2.13-32
ii  libc6-dev    2.13-32
ii  libffi-dev   3.0.10-3
ii  libffi5      3.0.10-3
ii  libgmp-dev   2:5.0.5+dfsg-1.1
ii  libgmp10     2:5.0.5+dfsg-1.1
ii  libncurses5  5.9-7
ii  libtinfo5    5.9-7

ghc recommends no packages.

Versions of packages ghc suggests:
ii  ghc-doc      7.4.1-3
ii  ghc-prof     7.4.1-3
ii  haskell-doc  <none>
ii  llvm-3.0     <none>
ii  perl         5.14.2-10

-- no debconf information

-- 
see shy jo
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 828 bytes
Desc: Digital signature
URL: <http://lists.alioth.debian.org/pipermail/pkg-haskell-maintainers/attachments/20120611/19cea05d/attachment.pgp>


More information about the Pkg-haskell-maintainers mailing list