# TSC-low wrong frequency slowing down time



## kommissar (May 14, 2020)

I noticed in the last boot up that my clock was slower than normal, ntp would not sync, and "sleep 10" would take over ten seconds of real wall clock time.

I debugged it down to TSC-low getting the wrong frequency. This fixed my problem:
sysctl kern.timecounter.hardware="HPET"

So I also put that in /etc/sysctl.conf

Looking at the last boot messages compared to older ones, I noticed this:


```
...
Apr 16 00:15:57 media kernel: Timecounter "TSC-low" frequency 1700046556 Hz quality 1000
Apr 24 15:11:17 media kernel: Timecounter "TSC-low" frequency 1700048888 Hz quality 1000
May  3 17:29:56 media kernel: Timecounter "TSC-low" frequency 1700049236 Hz quality 1000
May  9 00:17:54 media kernel: Timecounter "TSC-low" frequency 1700044866 Hz quality 1000
May 12 17:44:41 media kernel: Timecounter "TSC-low" frequency 1087886338 Hz quality 1000
```

So the TSC-low frequency was probably wrong on the last boot. 

I also see this:

```
...
Apr 16 00:15:57 media kernel: CPU: Intel(R) Core(TM) i3-3245 CPU @ 3.40GHz (3400.09-MHz K8-class CPU)
Apr 24 15:11:17 media kernel: CPU: Intel(R) Core(TM) i3-3245 CPU @ 3.40GHz (3400.10-MHz K8-class CPU)
May  3 17:29:56 media kernel: CPU: Intel(R) Core(TM) i3-3245 CPU @ 3.40GHz (3400.10-MHz K8-class CPU)
May  9 00:17:54 media kernel: CPU: Intel(R) Core(TM) i3-3245 CPU @ 3.40GHz (3400.09-MHz K8-class CPU)
May 12 17:44:41 media kernel: CPU: Intel(R) Core(TM) i3-3245 CPU @ 3.40GHz (17406.18-MHz K8-class CPU)
```

Any idea what might cause this? IIRC the change I made in the last boot was installing a new case fan and telling the BIOS to throttle the fan speed based on CPU temperature. But this is not frequency scaling or anything I think should be visible to the operating system. 

Any ideas on how to debug?


----------



## PMc (May 14, 2020)

kommissar said:


> Any idea what might cause this? IIRC the change I made in the last boot was installing a new case fan and telling the BIOS to throttle the fan speed based on CPU temperature. But this is not frequency scaling or anything I think should be visible to the operating system.



It sound like that BIOS got something seriously wrong during these changes, and now reports the wrong stuff up to the OS.



> Any ideas on how to debug?



Debugging the BIOS? Hm, that sounds quite difficult to me. What I would do is, if that doesn't go away by itself during the next BIOS edit anyway, one can do a reset of the BIOS (and then recreate the config) - the mainboard manual should explain that.


----------



## kommissar (May 17, 2020)

PMc said:


> It sound like that BIOS got something seriously wrong during these changes, and now reports the wrong stuff up to the OS.



I don't think that it is actually the BIOS reporting this. After a reboot, the frequency is reported properly again, and things are working.


```
May  9 00:17:54 media kernel: Timecounter "TSC-low" frequency 1700044866 Hz quality 1000
May 12 17:44:41 media kernel: Timecounter "TSC-low" frequency 1087886338 Hz quality 1000
May 16 23:04:56 media kernel: Timecounter "TSC-low" frequency 1700046370 Hz quality 1000
```

Usually, there is some sort of calibration in the kernel. I thought maybe there is a bug there. But if this is a transient issue, it will be much more difficult to figure out.


----------

