When I cat /proc/cpuinfo
, I see 8 cores, with ID\'s from 0
to 7
.
Is there an x86
instruction that will report th
taskset
+ __rdtscp
runnable example
And at last, for those that want to have some fun with x86 intrinsics + taskset
:
rdtscp.c
#include
#include
#include
#include
#include
int main(void) {
uint32_t pid;
printf("0x%016" PRIX64 "\n", (uint64_t)__rdtscp(&pid));
printf("0x%08" PRIX32 "\n", pid);
return EXIT_SUCCESS;
}
GitHub upstream.
then compile and run while controlling which core it runs on with taskset:
gcc -ggdb3 -O0 -std=c99 -Wall -Wextra -pedantic -o rdtscp.out rdtscp.c
./taskset -c 0 ./rdtscp.out
./taskset -c 1 ./rdtscp.out
then for each run, the second line, which shows the CPU ID, matches the value set by taskset.
Tested in Ubuntu 19.04 amd64 with an Intel Core i7-7820HQ.