Changeset 205600 in webkit


Ignore:
Timestamp:
Sep 8, 2016, 12:56:05 AM (9 years ago)
Author:
Carlos Garcia Campos
Message:

Merge r205210 - bmalloc: speed up the lock slow path
https://bugs.webkit.org/show_bug.cgi?id=161058

Unreviewed roll-in - with regression fixed.

Revert to using yield() instead of swtch() because very low priority
background tasks can cause priority inversion and deadlock. In the
network process, that happened with com.apple.WebKit.Cache.Storage.serialBackground.

Still a big speedup on MallocBench.

  • bmalloc.xcodeproj/project.pbxproj:
  • bmalloc/ScopeExit.h: Added.

(bmalloc::ScopeExit::ScopeExit):
(bmalloc::ScopeExit::~ScopeExit):
(bmalloc::makeScopeExit):

  • bmalloc/StaticMutex.cpp:

(bmalloc::StaticMutex::lockSlowCase):

  • bmalloc/StaticMutex.h:

(bmalloc::StaticMutex::init):

Location:
releases/WebKitGTK/webkit-2.14/Source/bmalloc
Files:
4 edited
1 copied

Legend:

Unmodified
Added
Removed
  • releases/WebKitGTK/webkit-2.14/Source/bmalloc/ChangeLog

    r205045 r205600  
     12016-08-30  Geoffrey Garen  <ggaren@apple.com>
     2
     3        bmalloc: speed up the lock slow path
     4        https://bugs.webkit.org/show_bug.cgi?id=161058
     5
     6        Unreviewed roll-in - with regression fixed.
     7
     8        Revert to using yield() instead of swtch() because very low priority
     9        background tasks can cause priority inversion and deadlock. In the
     10        network process, that happened with com.apple.WebKit.Cache.Storage.serialBackground.
     11
     12        Still a big speedup on MallocBench.
     13
     14        * bmalloc.xcodeproj/project.pbxproj:
     15        * bmalloc/ScopeExit.h: Added.
     16        (bmalloc::ScopeExit::ScopeExit):
     17        (bmalloc::ScopeExit::~ScopeExit):
     18        (bmalloc::makeScopeExit):
     19        * bmalloc/StaticMutex.cpp:
     20        (bmalloc::StaticMutex::lockSlowCase):
     21        * bmalloc/StaticMutex.h:
     22        (bmalloc::StaticMutex::init):
     23
    1242016-08-26  Geoffrey Garen  <ggaren@apple.com>
    225
  • releases/WebKitGTK/webkit-2.14/Source/bmalloc/bmalloc.xcodeproj/project.pbxproj

    r205032 r205600  
    2525                14895D911A3A319C0006235D /* Environment.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14895D8F1A3A319C0006235D /* Environment.cpp */; };
    2626                14895D921A3A319C0006235D /* Environment.h in Headers */ = {isa = PBXBuildFile; fileRef = 14895D901A3A319C0006235D /* Environment.h */; settings = {ATTRIBUTES = (Private, ); }; };
     27                148EFAE81D6B953B008E721E /* ScopeExit.h in Headers */ = {isa = PBXBuildFile; fileRef = 148EFAE61D6B953B008E721E /* ScopeExit.h */; };
    2728                14C8992B1CC485E70027A057 /* Map.h in Headers */ = {isa = PBXBuildFile; fileRef = 14C8992A1CC485E70027A057 /* Map.h */; settings = {ATTRIBUTES = (Private, ); }; };
    2829                14C8992D1CC578330027A057 /* LargeRange.h in Headers */ = {isa = PBXBuildFile; fileRef = 14C8992C1CC578330027A057 /* LargeRange.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    111112                14895D8F1A3A319C0006235D /* Environment.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Environment.cpp; path = bmalloc/Environment.cpp; sourceTree = "<group>"; };
    112113                14895D901A3A319C0006235D /* Environment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Environment.h; path = bmalloc/Environment.h; sourceTree = "<group>"; };
     114                148EFAE61D6B953B008E721E /* ScopeExit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ScopeExit.h; path = bmalloc/ScopeExit.h; sourceTree = "<group>"; };
    113115                14B650C518F39F4800751968 /* Base.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Base.xcconfig; sourceTree = "<group>"; };
    114116                14B650C618F39F4800751968 /* bmalloc.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = bmalloc.xcconfig; sourceTree = "<group>"; };
     
    263265                                144469FD17A61F1F00F9EA1D /* PerThread.h */,
    264266                                145F6878179E3A4400D65598 /* Range.h */,
     267                                148EFAE61D6B953B008E721E /* ScopeExit.h */,
    265268                                143CB81A19022BC900B16A45 /* StaticMutex.cpp */,
    266269                                143CB81B19022BC900B16A45 /* StaticMutex.h */,
     
    317320                                1400274A18F89C2300115C97 /* VMHeap.h in Headers */,
    318321                                1400274918F89C1300115C97 /* Heap.h in Headers */,
     322                                148EFAE81D6B953B008E721E /* ScopeExit.h in Headers */,
    319323                                140FA00319CE429C00FFD3C8 /* BumpRange.h in Headers */,
    320324                                4426E2811C838EE0008EB042 /* Logging.h in Headers */,
  • releases/WebKitGTK/webkit-2.14/Source/bmalloc/bmalloc/ScopeExit.h

    r205599 r205600  
    11/*
    2  * Copyright (C) 2014 Apple Inc. All rights reserved.
     2 * Copyright (C) 2016 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 #include "StaticMutex.h"
    27 #include <thread>
     26#include <type_traits>
     27#include <utility>
    2828
    2929namespace bmalloc {
    3030
    31 void StaticMutex::lockSlowCase()
     31template<typename ExitFunction>
     32class ScopeExit {
     33public:
     34    explicit ScopeExit(ExitFunction&& exitFunction)
     35        : m_exitFunction(exitFunction)
     36    {
     37    }
     38
     39    ~ScopeExit()
     40    {
     41        m_exitFunction();
     42    }
     43
     44private:
     45    ExitFunction m_exitFunction;
     46};
     47
     48template<typename ExitFunction>
     49ScopeExit<ExitFunction> makeScopeExit(ExitFunction&& exitFunction)
    3250{
    33     while (!try_lock())
    34         std::this_thread::yield();
     51    return ScopeExit<ExitFunction>(std::forward<ExitFunction>(exitFunction));
    3552}
    36 
     53   
    3754} // namespace bmalloc
  • releases/WebKitGTK/webkit-2.14/Source/bmalloc/bmalloc/StaticMutex.cpp

    r205022 r205600  
    2424 */
    2525
     26#include "ScopeExit.h"
    2627#include "StaticMutex.h"
    2728#include <thread>
     
    3132void StaticMutex::lockSlowCase()
    3233{
     34    // The longest critical section in bmalloc is much shorter than the
     35    // time it takes to make a system call to yield to the OS scheduler.
     36    // So, we try again a lot before we yield.
     37    static const size_t aLot = 256;
     38   
     39    if (!m_isSpinning.test_and_set()) {
     40        auto clear = makeScopeExit([&] { m_isSpinning.clear(); });
     41
     42        for (size_t i = 0; i < aLot; ++i) {
     43            if (try_lock())
     44                return;
     45        }
     46    }
     47
     48    // Avoid spinning pathologically.
    3349    while (!try_lock())
    3450        std::this_thread::yield();
  • releases/WebKitGTK/webkit-2.14/Source/bmalloc/bmalloc/StaticMutex.h

    r205022 r205600  
    5353
    5454    std::atomic_flag m_flag;
     55    std::atomic_flag m_isSpinning;
    5556};
    5657
     
    7980{
    8081    m_flag.clear();
     82    m_isSpinning.clear();
    8183}
    8284
Note: See TracChangeset for help on using the changeset viewer.