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