[commit: ghc] master: Add hs_try_putmvar() (454033b)

git at git.haskell.org git at git.haskell.org
Mon Sep 12 07:33:51 UTC 2016


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/454033b54e2f7eef2354cc9d7ae7e7cba4dff09a/ghc

>---------------------------------------------------------------

commit 454033b54e2f7eef2354cc9d7ae7e7cba4dff09a
Author: Simon Marlow <marlowsd at gmail.com>
Date:   Tue Aug 30 20:55:10 2016 +0100

    Add hs_try_putmvar()
    
    Summary:
    This is a fast, non-blocking, asynchronous, interface to tryPutMVar that
    can be called from C/C++.
    
    It's useful for callback-based C/C++ APIs: the idea is that the callback
    invokes hs_try_putmvar(), and the Haskell code waits for the callback to
    run by blocking in takeMVar.
    
    The callback doesn't block - this is often a requirement of
    callback-based APIs.  The callback wakes up the Haskell thread with
    minimal overhead and no unnecessary context-switches.
    
    There are a couple of benchmarks in
    testsuite/tests/concurrent/should_run.  Some example results comparing
    hs_try_putmvar() with using a standard foreign export:
    
        ./hs_try_putmvar003 1 64 16 100 +RTS -s -N4     0.49s
        ./hs_try_putmvar003 2 64 16 100 +RTS -s -N4     2.30s
    
    hs_try_putmvar() is 4x faster for this workload (see the source for
    hs_try_putmvar003.hs for details of the workload).
    
    An alternative solution is to use the IO Manager for this.  We've tried
    it, but there are problems with that approach:
    * Need to create a new file descriptor for each callback
    * The IO Manger thread(s) become a bottleneck
    * More potential for things to go wrong, e.g. throwing an exception in
      an IO Manager callback kills the IO Manager thread.
    
    Test Plan: validate; new unit tests
    
    Reviewers: niteria, erikd, ezyang, bgamari, austin, hvr
    
    Subscribers: thomie
    
    Differential Revision: https://phabricator.haskell.org/D2501


>---------------------------------------------------------------

454033b54e2f7eef2354cc9d7ae7e7cba4dff09a
 docs/users_guide/ffi-chap.rst                      | 119 +++++++++++++++++++++
 includes/HsFFI.h                                   |   4 +
 libraries/base/GHC/Conc.hs                         |   2 +
 libraries/base/GHC/Conc/Sync.hs                    |  14 +++
 rts/Capability.c                                   |   1 +
 rts/Capability.h                                   |  13 ++-
 rts/Prelude.h                                      |   2 +
 rts/PrimOps.cmm                                    |   8 ++
 rts/RtsAPI.c                                       |  75 +++++++++++++
 rts/Schedule.c                                     |  15 ++-
 rts/Task.c                                         |  11 +-
 rts/Task.h                                         |  10 +-
 rts/Threads.c                                      |  79 ++++++++++++++
 rts/Threads.h                                      |   2 +
 rts/package.conf.in                                |   2 +
 testsuite/tests/concurrent/should_run/Makefile     |   6 ++
 testsuite/tests/concurrent/should_run/all.T        |  31 ++++++
 .../concurrent/should_run/hs_try_putmvar001.hs     |  34 ++++++
 .../should_run/hs_try_putmvar001.stdout}           |   0
 .../concurrent/should_run/hs_try_putmvar001_c.c    |  31 ++++++
 .../concurrent/should_run/hs_try_putmvar002.hs     |  66 ++++++++++++
 .../concurrent/should_run/hs_try_putmvar002_c.c    |  28 +++++
 .../concurrent/should_run/hs_try_putmvar003.hs     |  88 +++++++++++++++
 .../concurrent/should_run/hs_try_putmvar003_c.c    |  83 ++++++++++++++
 24 files changed, 714 insertions(+), 10 deletions(-)

Diff suppressed because of size. To see it, use:

    git diff-tree --root --patch-with-stat --no-color --find-copies-harder --ignore-space-at-eol --cc 454033b54e2f7eef2354cc9d7ae7e7cba4dff09a


More information about the ghc-commits mailing list