1

When I was using Hyper-Threading, a very strange phenomenon appeared. I was using c language to measure the time of l2 hit. I wrote the test time in a program A. When I run it alone, it showed that it takes about 26 cycles each time. When I wrote another program B. Binded B and A to the same core and run in the form of hyperthreading. Even if only a useless loop was written in B, for example:

for(;;){
}

I found that, in this case, when I run program A again, the displayed L2 hit time becomes about 10.

The code is very long. The pseudo-code of the test looks like this.

A:

    Select 16 cache lines (line 0 -16)in a set.  // l1 cache is VIPT structure
    Organize the disordered sequence of line0 to line8 into a linked list to prevent prefetching.
    Organize the disordered sequence of line9 to line15 into a linked list to prevent prefetching.
    load line 0 - 8   //Because it is a linked list, it is read serially
    fence()
    t1= rdtscp()
    load line 9 - 15  //Because it is a linked list, it is read serially
     t2 = rdtscp()
    print t2 - t1

B : for(;;){
}

When only A is running, the output result is 200 on average. When B and A are run with the same core hyperthreading, the output result of A is 90.

If the effect of hyperthreading makes the time longer, I can understand it, maybe it is interference, but what is the reason for the shorter time?

The configuration of my server is as follows:

 Linux version 4.15.0-122-generic (buildd@lcy01-amd64-010) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.12)) #124~16.04.1-Ubuntu SMP
Gerrie
  • 736
  • 3
  • 18
  • 1
    Skylake L2 hit latency is about 12 cycles. If you were measuring 26, maybe your CPU hadn't ramped up to a core clock speed similar to the RDTSC reference clock speed? (Even then, it's not exact.) Starting another thread (and running an infinite loop) might give more time for the CPU to ramp up. – Peter Cordes Dec 30 '20 at 02:52
  • I think you are right. When I re-run A alone, I reset it to bind it to a core, and now the result is normal. – Gerrie Dec 30 '20 at 03:07

0 Answers0