Skip to content

Commit

Permalink
port: updated PhysicalCoreID()
Browse files Browse the repository at this point in the history
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
  • Loading branch information
joscollin authored and facebook-github-bot committed May 3, 2017
1 parent b551104 commit 60847a3
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions port/port_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 60847a3

Please sign in to comment.