0

I am using a Docker container to run a C++ compiled executable. The Docker container is built using the latest Linux Debian distribution, while the host is a MacOS system (MacOS 12.6, on MacBook Pro 16 Latest 2019).

Within the C++ code, I call the function __rdtscp(unsigned int *__A) including x86intrin.h for monitoring purpose. Compiling and executing the application on the MacOS host it works correctly. But if I try to run it within the Docker container, I obtain a Illegal instruction error (it is compiled on another physical Linux host, I need this: anyway, I can run the same executable on different Linux machines and also on the container generated by the same Docker image I use if executed on another host).

Looking deeper into the issue, I found that __rdtscp(unsigned int *__A) must be supported by the CPU. It should be supported by all the CPUs after 2010/2011. In fact, it seems that flag is reported within the host CPU's features (RDTSCP). The problem is that I cannot find it within the container CPU's features.

Note that using __rdtsc() it works correctly, but this is not serializable, so I want to use __rdtscp(unsigned int *__A).

Following the MacOS host output of sysctl -a | grep machdep.cpu

enter image description here

And this is the output of the Debian docker container of lscpu

enter image description here

Could you help me to figure out the reason of this difference? Is there a way to force Docker to provide the same host CPU's features?

Thank you!

markigno
  • 64
  • 3
  • 1
    Isn't Docker using a shared Linux VM when running on macOS? Once this was true, not sure about today. – Margaret Bloom Feb 14 '23 at 09:49
  • RDTSC isn't seriali**zing**, but you can use `lfence` to serialize its execution so it is serlializ**able**. Of course, none of the instructions, including RDTSCP, are "serializing" in technical meaning of that term, like `cpuid` or (in future CPUs) `serialize`, because that also implies draining the store buffer, not just the ROB. And if there's anything besides ROB and SB, serializing that, too. – Peter Cordes Feb 15 '23 at 05:53
  • Also note that on paper, RDTSCP only guarantees one-way ordering. In practice it's probably microcoded as basically `lfence` + `rdtsc`. See also [Is there any difference in between (rdtsc + lfence + rdtsc) and (rdtsc + rdtscp) in measuring execution time?](https://stackoverflow.com/q/59759596) – Peter Cordes Feb 15 '23 at 05:54

0 Answers0