Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows improvements #453

Merged
merged 21 commits into from
Mar 20, 2019
Merged

Commits on Mar 18, 2019

  1. shims: correct indirection on Windows

    The `_dispatch_sema4_t` type is a pointer to the handle of the
    semaphore, so we need to indirect through the pointer before using it.
    This site was incorrectly using it directly.
    compnerd committed Mar 18, 2019
    Configuration menu
    Copy the full SHA
    dd6d93a View commit details
    Browse the repository at this point in the history

Commits on Mar 19, 2019

  1. event: plumb partial timer support for Windows

    This sets up the event loop for Windows to run and schedule timers.
    This allows us to start running some of the timer sources.
    compnerd committed Mar 19, 2019
    Configuration menu
    Copy the full SHA
    b6ff007 View commit details
    Browse the repository at this point in the history
  2. remove last few __LP64__ usage

    This cleans up the __LP64__ usage to allow libdispatch to work correctly
    on LLP64 targets (like Windows x64).
    compnerd committed Mar 19, 2019
    Configuration menu
    Copy the full SHA
    f7a0cbb View commit details
    Browse the repository at this point in the history
  3. simplify preprocessor checks

    Linux, FreeBSD already define DISPATCH_COCOA_COMPAT, and Windows was
    defining that in a couple of places in an unstructured haphazard manner.
    Define it similarly and clean up the other sites.
    compnerd committed Mar 19, 2019
    Configuration menu
    Copy the full SHA
    6481203 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    41678df View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    00c62df View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    c0a2e84 View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    3c912a4 View commit details
    Browse the repository at this point in the history
  8. TSD: correct FlsAlloc check

    FlsAlloc returns FLS_OUT_OF_INDEXES in an error scenario, everything
    else is a valid result.  Correct the assertion.
    compnerd committed Mar 19, 2019
    Configuration menu
    Copy the full SHA
    84e7a03 View commit details
    Browse the repository at this point in the history
  9. shims: correct _dispatch_get_nanoseconds on Windows

    The NT time representation uses 1/1/1601 as epoch as opposed to Unix
    which uses 1/1/1970.  Account for the offset in the calculation.  This
    corrects the calculation of now.
    compnerd committed Mar 19, 2019
    Configuration menu
    Copy the full SHA
    e92ca67 View commit details
    Browse the repository at this point in the history
  10. event: support CLOCK_WALL on Windows

    This is needed for XCTest to run its test suite.
    compnerd committed Mar 19, 2019
    Configuration menu
    Copy the full SHA
    c82c26b View commit details
    Browse the repository at this point in the history
  11. time: use GetSystemTimePreceiseAsFileTime on Windows

    Use the `GetSystemTimePreciseAsFileTime` rather than
    `GetSystemTimeAsFileTime` as we may otherwise get a cached value from
    the last context switch.
    compnerd committed Mar 19, 2019
    Configuration menu
    Copy the full SHA
    37ac7c6 View commit details
    Browse the repository at this point in the history
  12. lock: adopt the POSIX behaviour on Windows

    Ideally we would do the lazy semaphore approach that Mach does.
    Unfortunately, the queue wasn't getting drained as in that case.  A
    follow up should investigate and fix the lazy allocation.
    compnerd committed Mar 19, 2019
    Configuration menu
    Copy the full SHA
    bbde530 View commit details
    Browse the repository at this point in the history
  13. queue: expose _dispatch_get_main_queue_port_4CF

    This was being re-implemented in CF by means of a macro.  Just expose
    the function instead.
    compnerd committed Mar 19, 2019
    Configuration menu
    Copy the full SHA
    c3b9b8e View commit details
    Browse the repository at this point in the history
  14. Optimize Windows contention performance

    The dispatch_cascade test is very slow on Windows right now (often taking 4-5
    minutes to execute on my machine and sometimes locking it up entirely) because
    contention is not being handled correctly.
    
    `_dispatch_contention_usleep()` is expected to put the thread to sleep, but on
    Windows it spins on `QueryPerformanceCounter()`. This is causing a huge amount
    of starvation in the dispatch_cascade test. Implement it using `Sleep()`, and
    accordingly adjust `DISPATCH_CONTENTION_USLEEP_START` to be 1ms on Windows.
    
    Additionally, `_dispatch_contention_spins()` is currently implemented using the
    `rand_s()` function. This is slow (and experimentally seems to be slower than
    not randomizing the spin count at all!) because `rand_s()` guarantees
    cryptographic security, which is unnecessary for dispatch's use case. Replace it
    with a basic linear congruential generator (from K&R) since there isn't any
    other `rand_r()` equivalent. Based on the average wall clock times reported by
    bsdtestharness, this is around 35% faster on my PC (i7-8700K).
    
    These changes bring the runtime of the dispatch_cascade test down to around 1-2s
    at most for me. (It's even faster than this if stdout isn't a console window
    because that slows down the histogram display.)
    adierking authored and compnerd committed Mar 19, 2019
    Configuration menu
    Copy the full SHA
    fdc684b View commit details
    Browse the repository at this point in the history
  15. shims: flesh out generic_sys_queue.h further

    The 1121 merge introduced additional usage of sys/queue.h.  Flesh out
    the shims header further to repair the build on Windows.
    compnerd committed Mar 19, 2019
    Configuration menu
    Copy the full SHA
    1428c6d View commit details
    Browse the repository at this point in the history
  16. semaphore: correct the size of semaphore for LLP64

    The `dsema_value` field was marked as long which is incorrect for LLP64
    environments.  Update the type to `intptr_t` which is the portable type
    for this value.
    compnerd committed Mar 19, 2019
    Configuration menu
    Copy the full SHA
    55195b7 View commit details
    Browse the repository at this point in the history
  17. shims: correct _dispatch_uptime for Windows

    This should use `QueryUnbiasedInterruptTime`  `QueryPerformanceCounter`
    is roughly in units of of TSC frequency.  We would need to use
    `QueryPerformanceFrequency` to convert that into nanoseconds.
    Additionally, `QueryPerformanceCounter` includes time spent during
    suspend, which is not what is desired.  Switch to
    `QueryUnbiasedInterruptTime` to get something close to `CLOCK_MONOTONIC`
    on Linux.
    compnerd committed Mar 19, 2019
    Configuration menu
    Copy the full SHA
    766d647 View commit details
    Browse the repository at this point in the history
  18. benchmark: disable 128-bit math on Windows

    Windows does not support 128-bit division, disable the support for now.
    One option is to statically link compiler-rt to provide `__udivti3`.
    compnerd committed Mar 19, 2019
    Configuration menu
    Copy the full SHA
    346785c View commit details
    Browse the repository at this point in the history
  19. resolve 1121 merge conflicts

    This addresses the updates that were not applied to the Windows port but
    were applied to the Linux port and the macOS port.
    compnerd committed Mar 19, 2019
    Configuration menu
    Copy the full SHA
    b6b1975 View commit details
    Browse the repository at this point in the history
  20. tests: support the timer source tests on Windows

    PR apple#453 provides an initial implementation for timer support on Windows. Support
    building and running the `DISPATCH_SOURCE_TYPE_TIMER` tests so we can easily
    verify that timers work correctly.
    
    These tests should pass on Windows with this and apple#453 applied:
    
    - dispatch_drift
    - dispatch_suspend_timer
    - dispatch_timer
    - dispatch_timer_bit31
    - dispatch_timer_bit63
    - dispatch_timer_set_time
    - dispatch_timer_short
    - dispatch_timer_timeout
    adierking authored and compnerd committed Mar 19, 2019
    Configuration menu
    Copy the full SHA
    3085ae0 View commit details
    Browse the repository at this point in the history