[GHC] #12999: Investigate use of floating-point arithmetic in I/O Event-handler

#12999: Investigate use of floating-point arithmetic in I/O Event-handler -------------------------------------+------------------------------------- Reporter: hvr | Owner: Type: task | Status: new Priority: normal | Milestone: 8.2.1 Component: | Version: 8.0.1 libraries/base | Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- I was asked/made aware of some questionable use of floating-point arithmetic in `GHC.Event.TimerManager`; Specifically, I can't explain why `getMonotonicTime` first gets a timestamp as `Word64`, only to perform a not-necessarily cheap floating- point division, and returns a `Double`... {{{#!hs -- | Return monotonic time in seconds, since some unspecified starting point getMonotonicTime :: IO Double getMonotonicTime = do w <- getMonotonicNSec return (fromIntegral w / 1000000000) foreign import ccall unsafe "getMonotonicNSec" getMonotonicNSec :: IO Word64 }}} which then gets used e.g. by {{{#!hs updateTimeout :: TimerManager -> TimeoutKey -> Int -> IO () updateTimeout mgr (TK key) us = do now <- getMonotonicTime let expTime = fromIntegral us / 1000000.0 + now editTimeouts mgr (Q.adjust (const expTime) key) wakeManager mgr }}} Whereas, the priority queue (`GHC.Event.PSQ`) then uses `Double`s for its priorities... For correctness and performance reasons, I'd expect the use of fixed-width integers (i.e. `Word64` or `Int64`) for such codepaths... -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12999 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12999: Investigate use of floating-point arithmetic in I/O Event-handler -------------------------------------+------------------------------------- Reporter: hvr | Owner: Type: task | Status: new Priority: normal | Milestone: 8.2.1 Component: libraries/base | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by winter): Recently when i'm digging into RTS's code, this design confused me too. After some research it seems there's a much better plan: [https://www.reddit.com/r/haskell/comments/28vev9/announcing_psqueues_faster_...]. I'll looking into it when i got time. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12999#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12999: Investigate use of floating-point arithmetic in I/O Event-handler -------------------------------------+------------------------------------- Reporter: hvr | Owner: Type: task | Status: new Priority: normal | Milestone: 8.2.1 Component: libraries/base | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by davean): That is just a faster version of the wrong thing. This bug was filed because I was working on fixing it correctly. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12999#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12999: Investigate use of floating-point arithmetic in I/O Event-handler -------------------------------------+------------------------------------- Reporter: hvr | Owner: Type: task | Status: new Priority: normal | Milestone: 8.2.1 Component: libraries/base | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by winter): Replying to [comment:2 davean]:
That is just a faster version of the wrong thing.
Can you explain what is the problem with an IntPSQ?
This bug was filed because I was working on fixing it correctly.
Nice! If there any possibility we can get a stripped TimerManager(like the IOManager) which use a PSQ per core? It will help under high contention situation s. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12999#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12999: Investigate use of floating-point arithmetic in I/O Event-handler -------------------------------------+------------------------------------- Reporter: hvr | Owner: Type: task | Status: new Priority: normal | Milestone: 8.2.1 Component: libraries/base | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by winter): * cc: winter (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12999#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12999: Investigate use of floating-point arithmetic in I/O Event-handler -------------------------------------+------------------------------------- Reporter: hvr | Owner: Type: task | Status: new Priority: normal | Milestone: 8.2.1 Component: libraries/base | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by winter): Replying to [comment:2 davean]: I think i understand your comments now :) It seems structures in psqueues package doesn't provide a key function `atMost`, which prevent us from find expired timers. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12999#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12999: Investigate use of floating-point arithmetic in I/O Event-handler -------------------------------------+------------------------------------- Reporter: hvr | Owner: (none) Type: task | Status: new Priority: normal | Milestone: 8.4.1 Component: libraries/base | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by nh2): Commit http://github.com/ghc/ghc/commit/ab2dcb1c474d918efdc875f3cca7ef5b6ebdce1a exports `getMonotonicTimeNSec :: IO Word64` so it can be used directly without conversion, and uses it to fix some PSQ timeout code. It updated the code mentioned in the issue description. Please take another look if this bug is fixed now. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12999#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12999: Investigate use of floating-point arithmetic in I/O Event-handler -------------------------------------+------------------------------------- Reporter: hvr | Owner: (none) Type: task | Status: closed Priority: normal | Milestone: 8.6.1 Component: libraries/base | Version: 8.0.1 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: new => closed * resolution: => fixed Comment: I fixed this in ab2dcb1c474d918efdc875f3cca7ef5b6ebdce1a. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12999#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC