CTSRD-CHERI / qemu

QEMU with support for CHERI
Other
53 stars 28 forks source link

Time behaves funny #55

Open trasz opened 7 years ago

trasz commented 7 years ago

Sometimes - I'm not sure what it depends on, it kind of seems to occur on a freshly booted system, I can observe this:

root@qemu-cheri256-en322:~ # openssl speed          
Doing mdc2 for 3s on 16 size blocks: 261185 mdc2's in 17.26s                                            
Doing mdc2 for 3s on 64 size blocks: 73792 mdc2's in 22.44s                                             
Doing mdc2 for 3s on 256 size blocks: 21042 mdc2's in 22.23s                                            
Doing mdc2 for 3s on 1024 size blocks: 627 mdc2's in 1.63s                                              
Doing mdc2 for 3s on 8192 size blocks: 80 mdc2's in 1.79s                                               
Doing md4 for 3s on 16 size blocks: 93682 md4's in 1.75s                                                
Doing md4 for 3s on 64 size blocks: 75587 md4's in 1.76s                                                
Doing md4 for 3s on 256 size blocks: 57932 md4's in 1.92s
Doing md4 for 3s on 1024 size blocks: 27391 md4's in 1.87s
Doing md4 for 3s on 8192 size blocks: 35787 md4's in 22.10s
Doing md5 for 3s on 16 size blocks: 74512 md5's in 1.98s

At the same time in another terminal:

# while :; do date; sleep 10; done                  
Thu Jan  1 00:01:12 UTC 1970                        
Thu Jan  1 00:01:43 UTC 1970                        
Thu Jan  1 00:02:06 UTC 1970                        
Thu Jan  1 00:02:30 UTC 1970                        
Thu Jan  1 00:02:40 UTC 1970                        
Thu Jan  1 00:03:10 UTC 1970                        
Thu Jan  1 00:03:20 UTC 1970     

Also this, there was about 10 seconds between invocations; observe how clock0 has rate 566, but the actual value doesn't change at all:

# vmstat -i                                         
interrupt                          total       rate 
int0 pcib0                          2605         12 
int5 clock0                       118852        566 
Total                             121457        579 
# vmstat -i                                         
interrupt                          total       rate 
int0 pcib0                          2612         12 
int5 clock0                       118852        567 
Total                             121464        580 
trasz commented 7 years ago

Looks like it's caused by b79c3d9.

trasz commented 7 years ago

A plausible explanation (proposed by Alex) is that the Qemu timer interrupt fires from the host's virtual timer, and thus its frequency depends on how much host CPU time the qemu process is using at the moment. At the same time the Counter CP0 register is updated from the host's monotonic clock (a wallclock), so the guest time keeps being updated correctly.