1

Is there a virtual/system clock running independently when a computer is booted?

How can we read that value?

p.campbell
  • 98,673
  • 67
  • 256
  • 322
pvaju896
  • 1,397
  • 6
  • 25
  • 46

1 Answers1

4

Use the RDTSC x86 instruction, it reads the clocks since the system-start.

Edit: On x86-64 targets the use of inline assembly is not possible anymore, use either intrinics or a external linked object file which was generated by an assembler. Do not forget to flush the processor pipeline before using this instruction.

Quonux
  • 2,975
  • 1
  • 24
  • 32
  • can i use that for my intel x86 board..?/ – pvaju896 Jul 15 '10 at 08:12
  • x86 is no board, its the instructionset of the cpu. And yes, its an x86 instruction. – Quonux Jul 15 '10 at 08:22
  • +1 I use the processor time counter very frequently to benchmark code. It's much more precise than the system time functions. – Borealid Jul 15 '10 at 08:34
  • @Quonox: rdtsc is not just "an x86 instruction" it first appeared with either the Pentium or the Pentium MMX processor, I can't remember which (Wikipedia knows). It did not exist for anything before that, including the 32-bit processors 80386 and 80486. – Olof Forshell Feb 28 '11 at 13:55
  • oh this is so old but, it is still an instruction, doesn't matter when it was added. x86 is just the cpu family as far as I know. – Quonux Oct 27 '15 at 17:59