Bug 241849 - lang/ghc: Enable USE_PTHREAD_FOR_ITIMER
Summary: lang/ghc: Enable USE_PTHREAD_FOR_ITIMER
Status: Open
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-haskell mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-11-10 02:27 UTC by Kevin Zheng
Modified: 2019-11-18 16:14 UTC (History)
2 users (show)

See Also:
bugzilla: maintainer-feedback? (haskell)


Attachments
Patch (719 bytes, patch)
2019-11-10 02:27 UTC, Kevin Zheng
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kevin Zheng 2019-11-10 02:27:52 UTC
Created attachment 209025 [details]
Patch

The GHC RTS has an interval timer that is apparently used both in the threaded (-threaded) and non-threaded runtime.

On some operating systems, rts/posix/Itimer.c sets USE_PTHREAD_FOR_ITIMER, which uses usleep() at regular intervals instead of SIGVALRM.

Per the comments about Darwin (macOS) above:

 * We want to avoid using the SIGALRM signals whenever possible as these signals
 * interrupt system calls (see #10840) and can be overridden by user code. On
 * Darwin we can use a dedicated thread and usleep.

The attached patch applies this for FreeBSD as well.

To see the difference, run 'truss' on a simple test program:

== test.hs ==
main = do
    c <- getChar
    putChar c

$ ghc test.hs
$ truss ./test.hs
... some stuff
SIGNAL 26 (SIGVTALRM) code=SI_TIMER value=0x0 timerid=3 overrun=0
sigprocmask(SIG_SETMASK,{ SIGVTALRM },0x0)       = 0 (0x0)
sigreturn(0x7fffffff9880)                        = 0 (0x0)
ioctl(0,TIOCGETA,0x7fffffffa270)                 = 0 (0x0)
poll({ 0/POLLIN },1,0)                           = 0 (0x0)
select(1,{ 0 },{ },0x0,0x0)                      ERR#4 'Interrupted system call'
SIGNAL 26 (SIGVTALRM) code=SI_TIMER value=0x0 timerid=3 overrun=0
sigprocmask(SIG_SETMASK,{ SIGVTALRM },0x0)       = 0 (0x0)
sigreturn(0x7fffffffd6c0)                        ERR#4 'Interrupted system call'
select(1,{ 0 },{ },0x0,0x0)                      ERR#4 'Interrupted system call'
... more of this

After this change:
... some stuff
ioctl(0,TIOCGETA,0x7fffffffa270)                 = 0 (0x0)
poll({ 0/POLLIN },1,0)                           = 0 (0x0)
nanosleep({ 0.010000000 })                       = 0 (0x0)
nanosleep({ 0.010000000 })                       = 0 (0x0)
nanosleep({ 0.010000000 })                       = 0 (0x0)
... more of this
select(1,{ 0 },{ },0x0,0x0)                      = 1 (0x1)
... more stuff
Comment 1 Kevin Zheng 2019-11-10 02:28:53 UTC
Perhaps a PORTREVISION bump is warranted. The RTS will need to be re-linked with any Haskell binaries.
Comment 2 Gleb Popov freebsd_committer 2019-11-10 07:03:18 UTC
Thanks. Did you upstream this?
Comment 3 Kevin Zheng 2019-11-10 09:23:58 UTC
(In reply to Gleb Popov from comment #2)
Not yet. I don't track upstream GHC, and wanted to get feedback from haskell@ first.
Comment 4 Gleb Popov freebsd_committer 2019-11-18 10:04:49 UTC
Kevin, your patch has been submitted upstream. Do you want me to add this patch to GHC 8.6.5 or you're OK with waiting for GHC 8.8.2, which already have it?
Comment 5 Kevin Zheng 2019-11-18 16:14:30 UTC
(In reply to Gleb Popov from comment #4)
Thank you!

It doesn't really matter to me, because I have the change applied locally. I understand if there's not really a desire to do a PORTREVISION bump.