[x265] [PATCH 1 of 7] threadpool.cpp: get correct CPU count for multisocket machines -> windows system fix

Praveen Tiwari praveen at multicorewareinc.com
Mon May 23 12:17:14 CEST 2016


Hi,
    I am combining these patches into a single patch along with some
updates, so please ignore these patches. On top of this I will update
Mateusz patch (CLI: new logic for '--pools <int>' option ) to avoid
merge conflicts. Thanks.


.

Regards,
Praveen

On Fri, May 20, 2016 at 4:31 PM, <praveen at multicorewareinc.com> wrote:

> # HG changeset patch
> # User Praveen Tiwari <praveen at multicorewareinc.com>
> # Date 1463655478 -19800
> #      Thu May 19 16:27:58 2016 +0530
> # Node ID 9a6ab28b736e1167ac26977d7da8ab2d23cc296f
> # Parent  aca781339b4c8dae94ff7da73f18cd4439757e87
> threadpool.cpp: get correct CPU count for multisocket machines -> windows
> system fix
>
> diff -r aca781339b4c -r 9a6ab28b736e source/common/threadpool.cpp
> --- a/source/common/threadpool.cpp      Tue May 10 15:33:17 2016 +0530
> +++ b/source/common/threadpool.cpp      Thu May 19 16:27:58 2016 +0530
> @@ -64,6 +64,19 @@
>  # define strcasecmp _stricmp
>  #endif
>
> +const uint64_t m1 = 0x5555555555555555; //binary: 0101...
> +const uint64_t m2 = 0x3333333333333333; //binary: 00110011..
> +const uint64_t m3 = 0x0f0f0f0f0f0f0f0f; //binary:  4 zeros,  4 ones ...
> +const uint64_t h01 = 0x0101010101010101; //the sum of 256 to the power of
> 0,1,2,3...
> +
> +int popCount(uint64_t x)
> +{
> +    x -= (x >> 1) & m1;
> +    x = (x & m2) + ((x >> 2) & m2);
> +    x = (x + (x >> 4)) & m3;
> +    return (x * h01) >> 56;
> +}
> +
>  namespace X265_NS {
>  // x265 private namespace
>
> @@ -525,9 +538,17 @@
>  int ThreadPool::getCpuCount()
>  {
>  #if _WIN32
> -    SYSTEM_INFO sysinfo;
> -    GetSystemInfo(&sysinfo);
> -    return sysinfo.dwNumberOfProcessors;
> +    enum { MAX_NODE_NUM = 127 };
> +    int cpus = 0;
> +    int numNumaNodes = X265_MIN(getNumaNodeCount(), MAX_NODE_NUM);
> +    PGROUP_AFFINITY groupAffinityPointer = new GROUP_AFFINITY;
> +    for (int i = 0; i < numNumaNodes; i++)
> +    {
> +        GetNumaNodeProcessorMaskEx((UCHAR)i, groupAffinityPointer);
> +        cpus += popCount(groupAffinityPointer->Mask);
> +    }
> +    delete groupAffinityPointer;
> +    return cpus;
>  #elif __unix__ && X265_ARCH_ARM
>      /* Return the number of processors configured by OS. Because, most
> embedded linux distributions
>       * uses only one processor as the scheduler doesn't have enough work
> to utilize all processors */
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20160523/8d693001/attachment.html>


More information about the x265-devel mailing list