Time counter

I use a time counter in my C ++ program, asking for a register. However, one of the problems that I am facing is that the function for obtaining the timestamp will be acquired from different CPUs. How can I guarantee that my function will always receive a timestamp from the same CPU or synchronize the CPU anyway? By the way, my program runs on a server with 4 cores in Fedora 13 64 bit.

Thank.

+3
source share
3 answers

Check out the following excerpt from the Intel manual. According to section 16.12, I think that β€œnewer processors” below refer to any processor, but to Pentium 4. You can simultaneously atomically determine the value of tsc and the kernel identifier using the rdtscp command, if supported. However, I have not tried. Good luck.

Intel 64 and IA-32 Software Developer Guide

Volume 3 (3A and 3B): System Programming Guide:

Chapter 16.12.1 Invariant TSC

The timestamp counter in new processors may support the extension indicated as invariant TSC. Processor support for invariant TSC is indicated by CPUID.80000007H :. EDX [8]

TSC ACPI P-, C-. T-. . TSC , OS TSC ( ACPI HPET). TSC .

Intel , cpu rdtsc - http://download.intel.com/embedded/software/IA/324264.pdf

+4

TSC , /.

TSC:

  • . ...
  • / ( - , ). ​​
  • CPU/ ( ).

, TSC ( ) , .

. ( Unix/Mac) gettimeofday(), . clock_gettime(), , . Windows QueryPerformanceCounter().

+1

You can use the function sched_setaffinityor cpuset, which allows you to create cpuset and assign tasks to dial.

0
source

Source: https://habr.com/ru/post/1772602/


All Articles