[x265] [PATCH] Fix for threadpooling to use all available threads on windows, and build fix

Pradeep Ramachandran pradeep at multicorewareinc.com
Tue Sep 8 16:05:59 CEST 2015


Please ignore this patch - it has a bug that I've fixed in the subsequent
patch that I sent out.

Pradeep Ramachandran, PhD
Solution Architect,
Multicoreware Inc.
Ph:   +91 99627 82018

On Tue, Sep 8, 2015 at 11:50 AM, <pradeep at multicorewareinc.com> wrote:

> # HG changeset patch
> # User Pradeep Ramachandran <pradeep at multicorewareinc.com>
> # Date 1441692185 -19800
> #      Tue Sep 08 11:33:05 2015 +0530
> # Node ID 48b00cc32bc5cd77970db4776637a127a6e5d848
> # Parent  e1adac00dce8e5641cbe9aec3d50a72261c308d9
> Fix for threadpooling to use all available threads on windows, and build
> fix
> to remove warning for windows machines older than Win7 and linux machines
> without NUMA support
>
> diff -r e1adac00dce8 -r 48b00cc32bc5 source/common/threadpool.cpp
> --- a/source/common/threadpool.cpp      Thu Sep 03 14:41:06 2015 +0530
> +++ b/source/common/threadpool.cpp      Tue Sep 08 11:33:05 2015 +0530
> @@ -378,8 +378,15 @@
>      X265_CHECK(numThreads <= MAX_POOL_THREADS, "a single thread pool
> cannot have more than MAX_POOL_THREADS threads\n");
>
>  #if defined(_WIN32_WINNT) && _WIN32_WINNT >= _WIN32_WINNT_WIN7
> -    m_winNodemask = nodeMask & ~(0x1 << getNumaNodeCount());
> -    m_numaNodeMask = &m_winNodemask;
> +    int numaNode = -1;
> +    GROUP_AFFINITY groupAffinity;
> +    for (int i = 0; i < getNumaNodeCount(); i++)
> +    {
> +        numaNode = (nodeMask & (0x1 << i)) - 1;
> +        if (GetNumaNodeProcessorMaskEx((USHORT)numaNode, &groupAffinity))
> +            m_winCpuMask |= groupAffinity.Mask;
> +    }
> +    m_numaMask = &m_winCpuMask;
>  #elif HAVE_LIBNUMA
>      if (numa_available() >= 0)
>      {
> @@ -387,11 +394,13 @@
>          if (nodemask)
>          {
>              *(nodemask->maskp) = nodeMask;
> -            m_numaNodeMask = nodemask;
> +            m_numaMask = nodemask;
>          }
>          else
>              x265_log(NULL, X265_LOG_ERROR, "unable to get NUMA node mask
> for %lx\n", nodeMask);
>      }
> +#else
> +    (void)nodeMask;
>  #endif
>
>      m_numWorkers = numThreads;
> @@ -449,33 +458,35 @@
>      X265_FREE(m_jpTable);
>
>  #if HAVE_LIBNUMA
> -    if(m_numaNodeMask)
> -        numa_free_nodemask((struct bitmask*)m_numaNodeMask);
> +    if(m_numaMask)
> +        numa_free_nodemask((struct bitmask*)m_numaMask);
>  #endif
>  }
>
>  void ThreadPool::setCurrentThreadAffinity()
>  {
> -    setThreadNodeAffinity(m_numaNodeMask);
> +    setThreadNodeAffinity(m_numaMask);
>  }
>
>  /* static */
> -void ThreadPool::setThreadNodeAffinity(void *numaNodeMask)
> +void ThreadPool::setThreadNodeAffinity(void *numaMask)
>  {
>  #if defined(_WIN32_WINNT) && _WIN32_WINNT >= _WIN32_WINNT_WIN7
> -    if (SetThreadAffinityMask(GetCurrentThread(),
> (DWORD_PTR)(*((DWORD*)numaNodeMask))))
> +    if (SetThreadAffinityMask(GetCurrentThread(),
> (DWORD_PTR)(*((DWORD*)numaMask))))
>          return;
>      else
>          x265_log(NULL, X265_LOG_ERROR, "unable to set thread affinity for
> NUMA node mask\n");
>  #elif HAVE_LIBNUMA
>      if (numa_available() >= 0)
>      {
> -        numa_run_on_node_mask((struct bitmask*)numaNodeMask);
> -        numa_set_interleave_mask((struct bitmask*)numaNodeMask);
> +        numa_run_on_node_mask((struct bitmask*)numaMask);
> +        numa_set_interleave_mask((struct bitmask*)numaMask);
>          numa_set_localalloc();
>          return;
>      }
>      x265_log(NULL, X265_LOG_ERROR, "unable to set thread affinity for
> NUMA node mask\n");
> +#else
> +    (void)numaMask;
>  #endif
>      return;
>  }
> diff -r e1adac00dce8 -r 48b00cc32bc5 source/common/threadpool.h
> --- a/source/common/threadpool.h        Thu Sep 03 14:41:06 2015 +0530
> +++ b/source/common/threadpool.h        Tue Sep 08 11:33:05 2015 +0530
> @@ -83,9 +83,9 @@
>      sleepbitmap_t m_sleepBitmap;
>      int           m_numProviders;
>      int           m_numWorkers;
> -    void*         m_numaNodeMask;
> +    void*         m_numaMask; // node mask in linux, cpu mask in windows
>  #if defined(_WIN32_WINNT) && _WIN32_WINNT >= _WIN32_WINNT_WIN7
> -    DWORD         m_winNodemask;
> +    DWORD         m_winCpuMask;
>  #endif
>      bool          m_isActive;
>
> @@ -106,7 +106,7 @@
>
>      static int  getCpuCount();
>      static int  getNumaNodeCount();
> -    static void setThreadNodeAffinity(void *numaNodeMask);
> +    static void setThreadNodeAffinity(void *numaMask);
>  };
>
>  /* Any worker thread may enlist the help of idle worker threads from the
> same
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20150908/40f38179/attachment.html>


More information about the x265-devel mailing list