From 60847a3b080a9ce61404501732c90ed33a0ab1b8 Mon Sep 17 00:00:00 2001 From: Jos Collin Date: Wed, 3 May 2017 12:48:23 -0700 Subject: [PATCH] port: updated PhysicalCoreID() Summary: Checked the return value of __get_cpuid(). Implemented the else case where the arch is different from i386 and x86_64. Pulled By: ajkr Differential Revision: D4973496 fbshipit-source-id: c40fdef5840364c2a79b1d11df0db5d4ec3d6a4a --- port/port_posix.cc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/port/port_posix.cc b/port/port_posix.cc index cdeae65e7..96be2c059 100644 --- a/port/port_posix.cc +++ b/port/port_posix.cc @@ -142,11 +142,18 @@ int PhysicalCoreID() { // if you ever find that this function is hot on Linux, you can go from // ~200 nanos to ~20 nanos by adding the machinery to use __vdso_getcpu unsigned eax, ebx = 0, ecx, edx; - __get_cpuid(1, &eax, &ebx, &ecx, &edx); + if (!__get_cpuid(1, &eax, &ebx, &ecx, &edx)) { + return -1; + } return ebx >> 24; #else - // getcpu or sched_getcpu could work here - return -1; + int cpuno = sched_getcpu(); + if (cpuno < 0) { + return -1; + } + else { + return cpuno; + } #endif }