[Haskell-cafe] Compiled program using OpenGL fails to trigger GPU switch on Mac, but works in GHCi

Jesper Särnesjö sarnesjo at gmail.com
Wed Mar 20 14:02:01 CET 2013


On Tue, Mar 19, 2013 at 12:19 AM, Jesper Särnesjö <sarnesjo at gmail.com> wrote:
> As I final note, I did learn that the GHC runtime generates SIGVTALRM
> signals to cause the scheduler to switch contexts. Perhaps this
> prevents GLFW from running properly? Looks like I'll need to brush up
> on my dtrace.

A bit of googling turned up an thread on the glasgow-haskell-users
mailing list, discussing a similar problem with using the C MySQL
bindings [1]. One of the solutions mentioned there, was to disable the
timer signals generated by the runtime [2]. This can be done using the
-V RTS flag, described as follows in the documentation:

"Using a value of zero disables the RTS clock completely, and has the
effect of disabling timers that depend on it: the context switch timer
and the heap profiling timer. Context switches will still happen, but
deterministically and at a rate much faster than normal. Disabling the
interval timer is useful for debugging, because it eliminates a source
of non-determinism at runtime." [3]

Results:

    $ ghc -rtsopts -lglfw -framework OpenGL -fforce-recomp glfw_test.hs
    [...]
    $ ./glfw_test
    Apple Software Renderer
    $ ./glfw_test +RTS -V0
    NVIDIA GeForce GT 330M OpenGL Engine

Nice.

This solution seems to work perfectly for me. Since the foreign code
is allowed to run uninterrupted, the GPU switch happens, and since the
GUI actions stay on the main thread, the program's window responds to
keyboard and mouse input correctly.

Are there any downsides to disabling the timer signal? Why does the
documentation describe it primarily as a debugging aid?

-- 
Jesper Särnesjö
http://jesper.sarnesjo.org/

[1] http://www.haskell.org/pipermail/glasgow-haskell-users/2010-September/thread.html#19140
[2] http://www.haskell.org/pipermail/glasgow-haskell-users/2010-September/019156.html
[3] http://www.haskell.org/ghc/docs/7.4.2/html/users_guide/runtime-control.html#rts-options-misc



More information about the Haskell-Cafe mailing list