Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 581 Vote(s) - 3.4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
WBINVD instruction usage

#1
I'm trying to use the WBINV instruction on linux to clear the processor's L1 cache.

The following program compiles, but produces a segmentation fault when I try to run it.

`int main() {asm ("wbinvd"); return 1;}`

I'm using gcc 4.4.3 and run Linux kernel 2.6.32-33 on my x86 box.

Processor info: Intel® Core™2 Duo CPU T5270 @ 1.40GHz

I built the program as follows:

$ gcc <program_name>

$ ./a.out

Segmentation Fault



Can somebody tell me what I'm doing wrong? How do I get this to run?


P.S: I'm running a few performance tests and want to ensure that the previous content of the processor cache does not influence the results.
Reply

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

> 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:

[To see links please register here]


[To see links please register here]


[To see links please register here]


[To see links please register here]



[1]:

[To see links please register here]

Reply

#3
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][1] to see how others got useful results.


[1]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through