On Wed, Sep 19, 2018 at 03:03:12AM +0200, Leo Unglaub wrote:
> > > The only big problem I have is that as soon as I start X I cannot use the
> > > keyboard correctly. Every time I type a character on the keyboard it gets
> > > repeated multiple times. Most often it gets repeated between 3 and 7 
> > > times.
> > > Do you have any idea what I could to in order to fix/debug this?
> > Could be tsc desync.
> > 
> > Try a non-mp kernel or sysctl kern.timecounter.hardware=acpihpet0
> > 
> 
> thank you very much! The sysctl kern.timecounter.hardware=acpih option fixed
> the issue for me!
> 
> Thank you very much!
> Greetings
> Leo
> 

I had hoped it was gone with zen/17h.  As it is very inconsistent as to
which systems have this problem (ie 16h apu laptop has the problem,
16h pcengines apu2 doesn't) we need to test if tsc is desynchronised
on boot.

Here is the old big hammer diff I had extended for 17h but I don't want
to force hpet in cases where tsc is not desynchronised between cores.

Index: tsc.c
===================================================================
RCS file: /cvs/src/sys/arch/amd64/amd64/tsc.c,v
retrieving revision 1.10
diff -u -p -r1.10 tsc.c
--- tsc.c       27 Jul 2018 21:11:31 -0000      1.10
+++ tsc.c       19 Sep 2018 01:16:24 -0000
@@ -32,6 +32,7 @@ int           tsc_recalibrate;
 
 uint64_t       tsc_frequency;
 int            tsc_is_invariant;
+int            tsc_desync;
 
 uint           tsc_get_timecount(struct timecounter *tc);
 
@@ -172,7 +173,7 @@ calibrate_tsc_freq(void)
                return;
        tsc_frequency = freq;
        tsc_timecounter.tc_frequency = freq;
-       if (tsc_is_invariant)
+       if (tsc_is_invariant && tsc_desync == 0)
                tsc_timecounter.tc_quality = 2000;
 }
 
@@ -206,10 +207,25 @@ tsc_timecounter_init(struct cpu_info *ci
        tsc_frequency = tsc_freq_cpuid(ci);
        tsc_is_invariant = 1;
 
+#ifdef MULTIPROCESSOR
+       /*
+        * TSC often desynchronised between cores on
+        * 15h (Bulldozer, Piledriver, Steamroller, Excavator)
+        * 16h (Jaguar, Puma)
+        * 17h (Zen)
+        */
+       if ((strcmp(cpu_vendor, "AuthenticAMD") == 0) &&
+           ((ci->ci_family == 0x15 && ci->ci_model <= 0x6f) ||
+            (ci->ci_family == 0x16 && ci->ci_model <= 0x3f) ||
+            (ci->ci_family == 0x17 && ci->ci_model <= 0x1f)))
+               tsc_desync = 1;
+#endif
+
        /* Newer CPUs don't require recalibration */
        if (tsc_frequency > 0) {
                tsc_timecounter.tc_frequency = tsc_frequency;
-               tsc_timecounter.tc_quality = 2000;
+               if (tsc_desync == 0)
+                       tsc_timecounter.tc_quality = 2000;
        } else {
                tsc_recalibrate = 1;
                tsc_frequency = cpufreq;

Reply via email to