Changeset 105270 in webkit


Ignore:
Timestamp:
Jan 18, 2012 6:15:05 AM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Cross-platform processor core counter
https://bugs.webkit.org/show_bug.cgi?id=76530

Patch by Roland Takacs <takacs.roland@stud.u-szeged.hu> on 2012-01-18
Reviewed by Zoltan Herczeg.

Source/JavaScriptCore:

Two files have been created that include the processor core counter function.
It used to be in ParallelJobsGeneric.h/cpp before.

(JSC::Options::initializeOptions):

  • wtf/CMakeLists.txt:
  • wtf/NumberOfCores.cpp: Added.

(WTF::numberOfProcessorCores):

  • wtf/NumberOfCores.h: Added.
  • wtf/ParallelJobsGeneric.cpp:

(WTF::ParallelEnvironment::ParallelEnvironment):

  • wtf/ParallelJobsGeneric.h:

Source/WTF:

Two files have been added to the project, namely NumberOfCores.h/cpp,
that include a CPU core number determining function.

  • WTF.pro:
Location:
trunk/Source
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r105267 r105270  
     12012-01-18  Roland Takacs  <takacs.roland@stud.u-szeged.hu>
     2
     3        Cross-platform processor core counter
     4        https://bugs.webkit.org/show_bug.cgi?id=76530
     5
     6        Reviewed by Zoltan Herczeg.
     7
     8        Two files have been created that include the processor core counter function.
     9        It used to be in ParallelJobsGeneric.h/cpp before.
     10
     11        * GNUmakefile.list.am:
     12        * JavaScriptCore.gypi:
     13        * JavaScriptCore.vcproj/WTF/WTF.vcproj:
     14        * JavaScriptCore.xcodeproj/project.pbxproj:
     15        * runtime/Options.cpp:
     16        (JSC::Options::initializeOptions):
     17        * wtf/CMakeLists.txt:
     18        * wtf/NumberOfCores.cpp: Added.
     19        (WTF::numberOfProcessorCores):
     20        * wtf/NumberOfCores.h: Added.
     21        * wtf/ParallelJobsGeneric.cpp:
     22        (WTF::ParallelEnvironment::ParallelEnvironment):
     23        * wtf/ParallelJobsGeneric.h:
     24
    1252012-01-18  Balazs Kelemen  <kbalazs@webkit.org>
    226
  • trunk/Source/JavaScriptCore/GNUmakefile.list.am

    r105217 r105270  
    619619        Source/JavaScriptCore/wtf/NotFound.h \
    620620        Source/JavaScriptCore/wtf/NullPtr.h \
     621        Source/JavaScriptCore/wtf/NumberOfCores.cpp \
     622        Source/JavaScriptCore/wtf/NumberOfCores.h \
    621623        Source/JavaScriptCore/wtf/OSAllocator.h \
    622624        Source/JavaScriptCore/wtf/OSRandomSource.cpp \
  • trunk/Source/JavaScriptCore/JavaScriptCore.gypi

    r105028 r105270  
    572572            'wtf/MallocZoneSupport.h',
    573573            'wtf/NullPtr.cpp',
     574            'wtf/NumberOfCores.cpp',
     575            'wtf/NumberOfCores.h',
    574576            'wtf/OSAllocatorPosix.cpp',
    575577            'wtf/OSAllocatorWin.cpp',
  • trunk/Source/JavaScriptCore/JavaScriptCore.vcproj/WTF/WTF.vcproj

    r104315 r105270  
    950950                </File>
    951951                <File
     952                        RelativePath="..\..\wtf\NumberOfCores.cpp"
     953                        >
     954                </File>
     955                <File
     956                        RelativePath="..\..\wtf\NumberOfCores.h"
     957                        >
     958                </File>
     959                <File
    952960                        RelativePath="..\..\wtf\OSAllocatorWin.cpp"
    953961                        >
  • trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj

    r105217 r105270  
    732732                E4D8CEFB12FC439600BC9F5A /* BloomFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = E4D8CE9B12FC42E100BC9F5A /* BloomFilter.h */; settings = {ATTRIBUTES = (Private, ); }; };
    733733                F3BD31ED126735770065467F /* TextPosition.h in Headers */ = {isa = PBXBuildFile; fileRef = F3BD31D0126730180065467F /* TextPosition.h */; settings = {ATTRIBUTES = (Private, ); }; };
     734                F69E86C314C6E551002C2C62 /* NumberOfCores.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F69E86C114C6E551002C2C62 /* NumberOfCores.cpp */; };
     735                F69E86C414C6E551002C2C62 /* NumberOfCores.h in Headers */ = {isa = PBXBuildFile; fileRef = F69E86C214C6E551002C2C62 /* NumberOfCores.h */; };
    734736                FDA15C1E12B0305C003A583A /* Complex.h in Headers */ = {isa = PBXBuildFile; fileRef = FDA15C1612B03028003A583A /* Complex.h */; settings = {ATTRIBUTES = (Private, ); }; };
    735737                FE1B447A0ECCD73B004F4DD1 /* StdLibExtras.h in Headers */ = {isa = PBXBuildFile; fileRef = FE1B44790ECCD73B004F4DD1 /* StdLibExtras.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    15431545                F692A8860255597D01FF60F7 /* UString.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = UString.h; sourceTree = "<group>"; tabWidth = 8; };
    15441546                F692A8870255597D01FF60F7 /* JSValue.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSValue.cpp; sourceTree = "<group>"; tabWidth = 8; };
     1547                F69E86C114C6E551002C2C62 /* NumberOfCores.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NumberOfCores.cpp; path = wtf/NumberOfCores.cpp; sourceTree = "<group>"; };
     1548                F69E86C214C6E551002C2C62 /* NumberOfCores.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NumberOfCores.h; path = wtf/NumberOfCores.h; sourceTree = "<group>"; };
    15451549                FDA15C1612B03028003A583A /* Complex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Complex.h; sourceTree = "<group>"; };
    15461550                FE1B44790ECCD73B004F4DD1 /* StdLibExtras.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StdLibExtras.h; sourceTree = "<group>"; };
     
    16231627                        isa = PBXGroup;
    16241628                        children = (
     1629                                F69E86C114C6E551002C2C62 /* NumberOfCores.cpp */,
     1630                                F69E86C214C6E551002C2C62 /* NumberOfCores.h */,
    16251631                                8604F4F2143A6C4400B295F5 /* ChangeLog */,
    16261632                                A718F8211178EB4B002465A7 /* create_regex_tables */,
     
    30403046                                0F7B294D14C3CD4C007C3DB1 /* DFGCommon.h in Headers */,
    30413047                                91A3905614C0F47200F67901 /* Uint8ClampedArray.h in Headers */,
     3048                                F69E86C414C6E551002C2C62 /* NumberOfCores.h in Headers */,
    30423049                        );
    30433050                        runOnlyForDeploymentPostprocessing = 0;
     
    35773584                                0F0B83B014BCF71600885B4F /* CallLinkInfo.cpp in Sources */,
    35783585                                0F0B83B414BCF86000885B4F /* MethodCallLinkInfo.cpp in Sources */,
     3586                                F69E86C314C6E551002C2C62 /* NumberOfCores.cpp in Sources */,
    35793587                        );
    35803588                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/Source/JavaScriptCore/runtime/Options.cpp

    r103286 r105270  
    2828
    2929#include <limits>
     30#include <wtf/NumberOfCores.h>
    3031#include <wtf/PageBlock.h>
    3132
     
    175176
    176177    int cpusToUse = 1;
    177 #if OS(DARWIN) && ENABLE(PARALLEL_GC)
    178     int name[2];
    179     size_t valueSize = sizeof(cpusToUse);
    180     name[0] = CTL_HW;
    181     name[1] = HW_AVAILCPU;
    182     sysctl(name, 2, &cpusToUse, &valueSize, 0, 0);
     178#if ENABLE(PARALLEL_GC)
     179    cpusToUse = WTF::numberOfProcessorCores();
    183180#endif
    184181    // We don't scale so well beyond 4.
  • trunk/Source/JavaScriptCore/wtf/CMakeLists.txt

    r104468 r105270  
    5454    NotFound.h
    5555    NullPtr.h
     56    NumberOfCores.h
    5657    OSAllocator.h
    5758    OSRandomSource.h
     
    147148    MD5.cpp
    148149    OSRandomSource.cpp
     150    NumberOfCores.cpp
    149151    PageAllocationAligned.cpp
    150152    PageBlock.cpp
  • trunk/Source/JavaScriptCore/wtf/ParallelJobsGeneric.cpp

    r103003 r105270  
    3232#include "ParallelJobs.h"
    3333#include "UnusedParam.h"
     34#include <wtf/NumberOfCores.h>
    3435
    3536#if OS(DARWIN) || OS(OPENBSD) || OS(NETBSD)
     
    4647Vector< RefPtr<ParallelEnvironment::ThreadPrivate> >* ParallelEnvironment::s_threadPool = 0;
    4748
    48 int ParallelEnvironment::s_maxNumberOfParallelThreads = -1;
    49 
    5049ParallelEnvironment::ParallelEnvironment(ThreadFunction threadFunction, size_t sizeOfParameter, int requestedJobNumber) :
    5150    m_threadFunction(threadFunction),
     
    5453    ASSERT_ARG(requestedJobNumber, requestedJobNumber >= 1);
    5554
    56     if (s_maxNumberOfParallelThreads == -1)
    57         determineMaxNumberOfParallelThreads();
     55    int maxNumberOfCores = numberOfProcessorCores();
    5856
    59     if (!requestedJobNumber || requestedJobNumber > s_maxNumberOfParallelThreads)
    60         requestedJobNumber = static_cast<unsigned>(s_maxNumberOfParallelThreads);
     57    if (!requestedJobNumber || requestedJobNumber > maxNumberOfCores)
     58        requestedJobNumber = static_cast<unsigned>(maxNumberOfCores);
    6159
    6260    if (!s_threadPool)
     
    6664    int maxNumberOfNewThreads = requestedJobNumber - 1;
    6765
    68     for (int i = 0; i < s_maxNumberOfParallelThreads && m_threads.size() < static_cast<unsigned>(maxNumberOfNewThreads); ++i) {
     66    for (int i = 0; i < maxNumberOfCores && m_threads.size() < static_cast<unsigned>(maxNumberOfNewThreads); ++i) {
    6967        if (s_threadPool->size() < static_cast<unsigned>(i) + 1U)
    7068            s_threadPool->append(ThreadPrivate::create());
     
    9290    for (i = 0; i < m_threads.size(); ++i)
    9391        m_threads[i]->waitForFinish();
    94 }
    95 
    96 void ParallelEnvironment::determineMaxNumberOfParallelThreads()
    97 {
    98     const int defaultIfUnavailable = 2;
    99 #if OS(DARWIN) || OS(OPENBSD) || OS(NETBSD)
    100     unsigned result;
    101     size_t length = sizeof(result);
    102     int name[] = {
    103         CTL_HW,
    104         HW_NCPU
    105     };
    106     int sysctlResult = sysctl(name, sizeof(name) / sizeof(int), &result, &length, 0, 0);
    107     s_maxNumberOfParallelThreads = sysctlResult < 0 ? defaultIfUnavailable : result;
    108 #elif OS(LINUX) || OS(AIX) || OS(SOLARIS)
    109     long sysconfResult = sysconf(_SC_NPROCESSORS_ONLN);
    110     s_maxNumberOfParallelThreads = sysconfResult < 0 ? defaultIfUnavailable : static_cast<int>(sysconfResult);
    111 #elif OS(WINDOWS)
    112     UNUSED_PARAM(defaultIfUnavailable);
    113 
    114     SYSTEM_INFO sysInfo;
    115     GetSystemInfo(&sysInfo);
    116     s_maxNumberOfParallelThreads = sysInfo.dwNumberOfProcessors;
    117 #else
    118     s_maxNumberOfParallelThreads = defaultIfUnavailable;
    119 #endif
    12092}
    12193
  • trunk/Source/JavaScriptCore/wtf/ParallelJobsGeneric.h

    r102132 r105270  
    8585
    8686private:
    87     static void determineMaxNumberOfParallelThreads();
    88 
    8987    ThreadFunction m_threadFunction;
    9088    size_t m_sizeOfParameter;
     
    9391    Vector< RefPtr<ThreadPrivate> > m_threads;
    9492    static Vector< RefPtr<ThreadPrivate> >* s_threadPool;
    95     static int s_maxNumberOfParallelThreads;
    9693};
    9794
  • trunk/Source/WTF/ChangeLog

    r105217 r105270  
     12012-01-18  Roland Takacs  <takacs.roland@stud.u-szeged.hu>
     2
     3        Cross-platform processor core counter
     4        https://bugs.webkit.org/show_bug.cgi?id=76530
     5
     6        Reviewed by Zoltan Herczeg.
     7
     8        Two files have been added to the project, namely NumberOfCores.h/cpp,
     9        that include a CPU core number determining function.
     10
     11        * WTF.pro:
     12
    1132012-01-17  Caio Marcelo de Oliveira Filho  <caio.oliveira@openbossa.org>
    214
  • trunk/Source/WTF/WTF.pro

    r105217 r105270  
    8383    NotFound.h \
    8484    NullPtr.h \
     85    NumberOfCores.h \
    8586    OSAllocator.h \
    8687    OSRandomSource.h \
     
    189190    MetaAllocator.cpp \
    190191    NullPtr.cpp \
     192    NumberOfCores.cpp \
    191193    OSRandomSource.cpp \
    192194    qt/MainThreadQt.cpp \
Note: See TracChangeset for help on using the changeset viewer.