WBINVD instruction usage

℡╲_俬逩灬. 提交于 2019-11-28 11:23:58
user786653

Quoting from Intel® 64 and IA-32 Architectures Software Developer's Manual Combined Volumes 2A and 2B: Instruction Set Reference, A-Z:

The WBINVD instruction is a privileged instruction. When the processor is running in protected mode, the CPL of a program or procedure must be 0 to execute this instruction.

In other words only kernel mode code is allowed to execute it.

EDIT: Previous SO discussion on clearing caches:

"C" programmatically clear L2 cache on Linux machines

How can I do a CPU cache flush in x86 Windows?

How to clear CPU L1 and L2 cache

https://stackoverflow.com/questions/3443130/how-to-clear-cpu-l1-and-l2-cache

As user786653 wrote, wbinvd it is an privileged instruction, which segfaults in non-kernel code.

You should avoid using wbinvd for benchmarking, because it forces all kind of bus locking cycles, pipeline serializing and adds the overhead from kernel to userspace etc., which most likely do not happen in you real world program.

Hence your measurement will not be more exact, it will contain all kinds of artifacts. Reading a data chunk in the size of the L2 cache will produce better results.

You can read the source code under Test programs for measuring clock cycles and performance monitoring to see how others got useful results.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!