0

It seems I can annotate a function with __attribute__((target("rtm"))) (at least in clang), but I cannot check for RTM (Restricted Transactional Memory) presence at runtime:

useRTM_ = __builtin_cpu_supports("rtm");

gives a compiler error:

error: invalid cpu feature string for builtin useRTM_ = __builtin_cpu_supports("rtm");

I can't find anything here for TSX and for RTM there is only a flag to enable it in the whole codebase: -mrtm.

Can you please tell me how to check for the presence of RTM at runtime? Inline assembly is fine.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Serge Rogatch
  • 13,865
  • 7
  • 86
  • 158
  • 2
    Checking the relevant CPUID feature bit for RTM would be the obvious thing; https://www.felixcloutier.com/x86/xbegin#64-bit-mode-exceptions says which bit to check. See [How do I call "cpuid" in Linux?](https://stackoverflow.com/q/14266772) – Peter Cordes Jul 17 '22 at 11:33
  • You can overload functions with `target` attributes. So you define a "rtm" version and a normal one and the compiler will pick the right function for you at runtime. Seen that around last month or so but can't seem to find the url at the moment. Very nice compiler feature. – Goswin von Brederlow Jul 17 '22 at 15:35
  • Are there actually a meaningful number of CPUs out there that still support RTM? My understanding (mostly from Wikipedia) is that it is not being shipped on current Intel processors, and has been disabled in microcode (due to vulnerabilities) on most of those that previously did support it. – Nate Eldredge Jul 19 '22 at 04:50
  • @NateEldredge Google Cloud (GCP) machines `n2-*` support RTM, as I can tell from `lscpu` command. – Serge Rogatch Jul 19 '22 at 05:34

0 Answers0