@@ -123,8 +123,7 @@ import Data.Set (Set)
123123import GHC.Conc (ThreadId(..))
124124import GHC.Exts
125125import GHC.IO (IO(..))
126−import System.Clock
127− (TimeSpec, Clock(Monotonic), getTime, toNanoSecs, fromNanoSecs)
126+import System.Clock (TimeSpec, Clock(Monotonic), getTime, toNanoSecs)
128127
129128import qualified Data.Heap as H
130129import qualified Data.Set as S
@@ -311,12 +310,6 @@ data YieldRateInfo = YieldRateInfo
311310
312311 -- Latency as measured by workers, aggregated for the last period.
313312 , workerMeasuredLatency :: IORef NanoSecs
314−
315− -- When the last worker exits it updates this timestamp. We use this to
316− -- adjust svarAllTimeLatency so that we do not account the idle time in
317− -- that. XXX Note that not all workers stop at the same time therefore
318− -- there is a certain inaccuracy in this mechanism.
319− , workerStopTimeStamp :: IORef TimeSpec
320313 }
321314
322315data SVarStats = SVarStats {
@@ -922,21 +915,18 @@ sendYield sv winfo msg = do
922915 return $ r && rateLimitOk
923916
924917{-# INLINE workerStopUpdate #-}
925−workerStopUpdate :: WorkerInfo -> YieldRateInfo -> Int -> IO ()
926−workerStopUpdate winfo info n = do
918+workerStopUpdate :: WorkerInfo -> YieldRateInfo -> IO ()
919+workerStopUpdate winfo info = do
927920 i <- readIORef (workerPollingInterval info)
928921 when (i /= 0) $ workerUpdateLatency info winfo
929− when (n == 1) $ do
930− t <- getTime Monotonic
931− writeIORef (workerStopTimeStamp info) t
932922
933923{-# INLINABLE sendStop #-}
934924sendStop :: SVar t m a -> WorkerInfo -> IO ()
935925sendStop sv winfo = do
936− n <- liftIO $ atomicModifyIORefCAS (workerCount sv) $ \n -> (n - 1, n)
926+ atomicModifyIORefCAS_ (workerCount sv) $ \n -> n - 1
937927 case yieldRateInfo sv of
938928 Nothing -> return ()
939− Just info -> workerStopUpdate winfo info n
929+ Just info -> workerStopUpdate winfo info
940930 myThreadId >>= \tid -> void $ send sv (ChildStop tid Nothing)
941931
942932-------------------------------------------------------------------------------
@@ -1518,16 +1508,6 @@ collectLatency _ss yinfo = do
15181508 return $ tripleWith prev
15191509 else return $ tripleWith prev
15201510
1521−-- This takes away the time when the producer is idle because the consumer
1522−-- not consuming or consuming slowly.
1523−adjustLatencies :: YieldRateInfo -> IO ()
1524−adjustLatencies yinfo = do
1525− let longTerm = svarAllTimeLatency yinfo
1526− t0 <- readIORef (workerStopTimeStamp yinfo)
1527− t1 <- getTime Monotonic
1528− modifyIORef longTerm $ \(cnt, time) -> (cnt, time + t1 - t0)
1529− return ()
1530−
15311511-- XXX in case of ahead style stream we need to take the heap size into account
15321512-- because we return the workers on the basis of that which causes a condition
15331513-- where we keep dispatching and they keep returning. So we must have exactly
@@ -1829,8 +1809,6 @@ postProcessPaced sv = do
18291809 then do
18301810 r <- liftIO $ isWorkDone sv
18311811 when (not r) $ do
1832− let yinfo = fromJust $ yieldRateInfo sv
1833− liftIO $ adjustLatencies yinfo
18341812 void $ dispatchWorkerPaced sv
18351813 -- Note that we need to guarantee a worker since the work is not
18361814 -- finished, therefore we cannot just rely on dispatchWorkerPaced
@@ -1861,7 +1839,6 @@ getYieldRateInfo st = do
18611839 now <- getTime Monotonic
18621840 wlong <- newIORef (0,now)
18631841 period <- newIORef 1
1864− stopTime <- newIORef $ fromNanoSecs 0
18651842 gainLoss <- newIORef (Count 0)
18661843
18671844 return $ Just YieldRateInfo
@@ -1873,7 +1850,6 @@ getYieldRateInfo st = do
18731850 , workerPollingInterval = period
18741851 , workerMeasuredLatency = measured
18751852 , workerPendingLatency = wcur
1876− , workerStopTimeStamp = stopTime
18771853 , workerCollectedLatency = wcol
18781854 , svarAllTimeLatency = wlong
18791855 }