[Mesa-dev] [PATCH mesa 1/2] Add processor topology calculation implementation for Darwin/OSX targets.

Cherniak, Bruce bruce.cherniak at intel.com
Thu Mar 15 03:13:39 UTC 2018


Code looks good.  I'm not able to test it, but it's isolated within #defined( __APPLE__).
Thanks for the contribution.

Reviewed-by: Bruce Cherniak <bruce.cherniak at intel.com> 

> On Mar 14, 2018, at 6:19 PM, Jeremy Huddleston Sequoia <jeremyhu at apple.com> wrote:
> 
> From: Apple SWE <jeremyhu at apple.com>
> 
> The implementation for bootstrapping SWR on Darwin targets is based on the Linux version.
> Instead of reading the output of /proc/cpuinfo, sysctlbyname is used to determine the
> physical identifiers, processor identifiers, core counts and thread-processor affinities.
> 
> With this patch, it is possible to use SWR as an alternate renderer on OSX to softpipe and
> llvmpipe.
> 
> Reviewed-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
> Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
> ---
> .../drivers/swr/rasterizer/core/threads.cpp        | 56 +++++++++++++++++++++-
> 1 file changed, 55 insertions(+), 1 deletion(-)
> 
> diff --git a/src/gallium/drivers/swr/rasterizer/core/threads.cpp b/src/gallium/drivers/swr/rasterizer/core/threads.cpp
> index 4d79168d2d..3eb20abcbf 100644
> --- a/src/gallium/drivers/swr/rasterizer/core/threads.cpp
> +++ b/src/gallium/drivers/swr/rasterizer/core/threads.cpp
> @@ -36,6 +36,11 @@
> #include <unistd.h>
> #endif
> 
> +#ifdef __APPLE__
> +#include <sys/types.h>
> +#include <sys/sysctl.h>
> +#endif
> +
> #include "common/os.h"
> #include "context.h"
> #include "frontend.h"
> @@ -219,6 +224,56 @@ void CalculateProcessorTopology(CPUNumaNodes& out_nodes, uint32_t& out_numThread
> 
> #elif defined(__APPLE__)
> 
> +    auto numProcessors = 0;
> +    auto numCores = 0;
> +    auto numPhysicalIds = 0;
> +
> +    int value;
> +    size_t size = sizeof(value);
> +
> +    int result = sysctlbyname("hw.packages", &value, &size, NULL, 0);
> +    SWR_ASSERT(result == 0);
> +    numPhysicalIds = value;
> +
> +    result = sysctlbyname("hw.logicalcpu", &value, &size, NULL, 0);
> +    SWR_ASSERT(result == 0);
> +    numProcessors = value;
> +
> +    result = sysctlbyname("hw.physicalcpu", &value, &size, NULL, 0);
> +    SWR_ASSERT(result == 0);
> +    numCores = value;
> +
> +    out_nodes.resize(numPhysicalIds);
> +
> +    for (auto physId = 0; physId < numPhysicalIds; ++physId)
> +    {
> +        auto &numaNode = out_nodes[physId];
> +        auto procId = 0;
> +
> +        numaNode.cores.resize(numCores);
> +
> +        while (procId < numProcessors)
> +        {
> +            for (auto coreId = 0; coreId < numaNode.cores.size(); ++coreId, ++procId)
> +            {
> +                auto &core = numaNode.cores[coreId];
> +
> +                core.procGroup = coreId;
> +                core.threadIds.push_back(procId);
> +            }
> +        }
> +    }
> +
> +    out_numThreadsPerProcGroup = 0;
> +
> +    for (auto &node : out_nodes)
> +    {
> +        for (auto &core : node.cores)
> +        {
> +            out_numThreadsPerProcGroup += core.threadIds.size();
> +        }
> +    }
> +
> #else
> 
> #error Unsupported platform
> @@ -253,7 +308,6 @@ void CalculateProcessorTopology(CPUNumaNodes& out_nodes, uint32_t& out_numThread
>     }
> }
> 
> -
> void bindThread(SWR_CONTEXT* pContext, uint32_t threadId, uint32_t procGroupId = 0, bool bindProcGroup=false)
> {
>     // Only bind threads when MAX_WORKER_THREADS isn't set.
> -- 
> 2.16.1 (Apple Git-102)
> 
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev



More information about the mesa-dev mailing list