key input repeat speed too fast

classic Classic list List threaded Threaded
8 messages Options
prx
Reply | Threaded
Open this post in threaded view
|

key input repeat speed too fast

prx
>Synopsis: key input repeat speed too fast.
>Category: cwm
>Environment:
        System      : OpenBSD 6.6
        Details     : OpenBSD 6.6-beta (GENERIC.MP) #201: Sun Aug 11 23:13:55 MDT 2019
                         [hidden email]:/usr/src/sys/arch/amd64/compile/GENERIC.MP

        Architecture: OpenBSD.amd64
        Machine     : amd64
>Description:
        Since last snapshot, when opening an X session with cwm, a pressed key is
        repeated multiple times.
        Example : try to write "ls" in xterm produce "lllsss"

        Also, videos are played very fast (not sure it's related).
>How-To-Repeat:
        Open a new X session under cwm and write anything.
>Fix:
       


dmesg:
OpenBSD 6.6-beta (GENERIC.MP) #201: Sun Aug 11 23:13:55 MDT 2019
    [hidden email]:/usr/src/sys/arch/amd64/compile/GENERIC.MP
real mem = 4217094144 (4021MB)
avail mem = 4079132672 (3890MB)
mpath0 at root
scsibus0 at mpath0: 256 targets
mainbus0 at root
bios0 at mainbus0: SMBIOS rev. 2.8 @ 0xebf10 (55 entries)
bios0: vendor American Megatrends Inc. version "V30.6" date 12/15/2014
bios0: MSI MS-7721
acpi0 at bios0: ACPI 5.0
acpi0: sleep states S0 S3 S4 S5
acpi0: tables DSDT FACP APIC FPDT FIDT MCFG HPET UEFI IVRS SSDT SSDT CRAT SSDT SSDT SSDT
acpi0: wakeup devices SBAZ(S4) P0PC(S4) OHC1(S4) EHC1(S4) OHC2(S4) EHC2(S4) OHC3(S4) EHC3(S4) OHC4(S4) XHC0(S4) XHC1(S4) PE20(S4) PE21(S4) PE23(S4) PB2_(S4) PB3_(S4) [...]
acpitimer0 at acpi0: 3579545 Hz, 32 bits
acpimadt0 at acpi0 addr 0xfee00000: PC-AT compat
cpu0 at mainbus0: apid 16 (boot processor)
cpu0: AMD A8-6600K APU with Radeon(tm) HD Graphics, 4022.26 MHz, 15-13-01
cpu0: FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,MMX,FXSR,SSE,SSE2,HTT,SSE3,PCLMUL,MWAIT,SSSE3,FMA3,CX16,SSE4.1,SSE4.2,POPCNT,AES,XSAVE,AVX,F16C,NXE,MMXX,FFXSR,PAGE1GB,RDTSCP,LONG,LAHF,CMPLEG,SVM,EAPICSP,AMCR8,ABM,SSE4A,MASSE,3DNOWP,OSVW,IBS,XOP,SKINIT,WDT,FMA4,TCE,NODEID,TBM,TOPEXT,CPCTR,ITSC,BMI1
cpu0: 64KB 64b/line 2-way I-cache, 16KB 64b/line 4-way D-cache, 2MB 64b/line 16-way L2 cache
cpu0: ITLB 48 4KB entries fully associative, 24 4MB entries fully associative
cpu0: DTLB 64 4KB entries fully associative, 64 4MB entries fully associative
tsc_timecounter_init: TSC skew=0 observed drift=0
cpu0: smt 0, core 0, package 0
mtrr: Pentium Pro MTRR support, 8 var ranges, 88 fixed ranges
cpu0: apic clock running at 103MHz
cpu0: mwait min=64, max=64, IBE
cpu1 at mainbus0: apid 17 (application processor)
TSC skew=103
cpu1: AMD A8-6600K APU with Radeon(tm) HD Graphics, 4020.05 MHz, 15-13-01
cpu1: FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,MMX,FXSR,SSE,SSE2,HTT,SSE3,PCLMUL,MWAIT,SSSE3,FMA3,CX16,SSE4.1,SSE4.2,POPCNT,AES,XSAVE,AVX,F16C,NXE,MMXX,FFXSR,PAGE1GB,RDTSCP,LONG,LAHF,CMPLEG,SVM,EAPICSP,AMCR8,ABM,SSE4A,MASSE,3DNOWP,OSVW,IBS,XOP,SKINIT,WDT,FMA4,TCE,NODEID,TBM,TOPEXT,CPCTR,ITSC,BMI1
cpu1: 64KB 64b/line 2-way I-cache, 16KB 64b/line 4-way D-cache, 2MB 64b/line 16-way L2 cache
cpu1: ITLB 48 4KB entries fully associative, 24 4MB entries fully associative
cpu1: DTLB 64 4KB entries fully associative, 64 4MB entries fully associative
tsc_timecounter_init: TSC skew=103 observed drift=0
cpu1: smt 1, core 0, package 0
cpu2 at mainbus0: apid 18 (application processor)
TSC skew=-131
cpu2: AMD A8-6600K APU with Radeon(tm) HD Graphics, 4020.06 MHz, 15-13-01
cpu2: FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,MMX,FXSR,SSE,SSE2,HTT,SSE3,PCLMUL,MWAIT,SSSE3,FMA3,CX16,SSE4.1,SSE4.2,POPCNT,AES,XSAVE,AVX,F16C,NXE,MMXX,FFXSR,PAGE1GB,RDTSCP,LONG,LAHF,CMPLEG,SVM,EAPICSP,AMCR8,ABM,SSE4A,MASSE,3DNOWP,OSVW,IBS,XOP,SKINIT,WDT,FMA4,TCE,NODEID,TBM,TOPEXT,CPCTR,ITSC,BMI1
cpu2: 64KB 64b/line 2-way I-cache, 16KB 64b/line 4-way D-cache, 2MB 64b/line 16-way L2 cache
cpu2: ITLB 48 4KB entries fully associative, 24 4MB entries fully associative
cpu2: DTLB 64 4KB entries fully associative, 64 4MB entries fully associative
tsc_timecounter_init: TSC skew=-131 observed drift=0
cpu2: smt 0, core 1, package 0
cpu3 at mainbus0: apid 19 (application processor)
TSC skew=-159
cpu3: AMD A8-6600K APU with Radeon(tm) HD Graphics, 4020.06 MHz, 15-13-01
cpu3: FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,MMX,FXSR,SSE,SSE2,HTT,SSE3,PCLMUL,MWAIT,SSSE3,FMA3,CX16,SSE4.1,SSE4.2,POPCNT,AES,XSAVE,AVX,F16C,NXE,MMXX,FFXSR,PAGE1GB,RDTSCP,LONG,LAHF,CMPLEG,SVM,EAPICSP,AMCR8,ABM,SSE4A,MASSE,3DNOWP,OSVW,IBS,XOP,SKINIT,WDT,FMA4,TCE,NODEID,TBM,TOPEXT,CPCTR,ITSC,BMI1
cpu3: 64KB 64b/line 2-way I-cache, 16KB 64b/line 4-way D-cache, 2MB 64b/line 16-way L2 cache
cpu3: ITLB 48 4KB entries fully associative, 24 4MB entries fully associative
cpu3: DTLB 64 4KB entries fully associative, 64 4MB entries fully associative
tsc_timecounter_init: TSC skew=-159 observed drift=0
cpu3: smt 1, core 1, package 0
ioapic0 at mainbus0: apid 0 pa 0xfec00000, version 21, 24 pins
acpimcfg0 at acpi0
acpimcfg0: addr 0xe0000000, bus 0-255
acpihpet0 at acpi0: 14318180 Hz
acpiprt0 at acpi0: bus 0 (PCI0)
acpiprt1 at acpi0: bus 3 (P0PC)
acpiprt2 at acpi0: bus -1 (PE20)
acpiprt3 at acpi0: bus -1 (PE21)
acpiprt4 at acpi0: bus -1 (PE23)
acpiprt5 at acpi0: bus 1 (PB2_)
acpiprt6 at acpi0: bus -1 (PB3_)
acpiprt7 at acpi0: bus 2 (PB4_)
acpiprt8 at acpi0: bus -1 (PB5_)
acpiprt9 at acpi0: bus -1 (PB6_)
acpiprt10 at acpi0: bus -1 (PB7_)
acpiprt11 at acpi0: bus -1 (PE22)
acpicpu0 at acpi0: C2(0@100 io@0x1771), C1(@1 halt!), PSS
acpicpu1 at acpi0: C2(0@100 io@0x1771), C1(@1 halt!), PSS
acpicpu2 at acpi0: C2(0@100 io@0x1771), C1(@1 halt!), PSS
acpicpu3 at acpi0: C2(0@100 io@0x1771), C1(@1 halt!), PSS
acpipci0 at acpi0 PCI0: 0x00000000 0x00000011 0x00000001
acpicmos0 at acpi0
acpibtn0 at acpi0: PWRB
"pnp0c14" at acpi0 not configured
acpivideo0 at acpi0: VGA_
acpivideo1 at acpi0: VGA_
acpivideo2 at acpi0: VGA_
cpu0: 4022 MHz: speeds: 3900 3600 3000 2500 1900 MHz
pci0 at mainbus0 bus 0
pchb0 at pci0 dev 0 function 0 "AMD AMD64 15/1xh Host" rev 0x00
"AMD AMD64 15/1xh IOMMU" rev 0x00 at pci0 dev 0 function 2 not configured
ppb0 at pci0 dev 2 function 0 "AMD AMD64 15/1xh PCIE" rev 0x00: msi
pci1 at ppb0 bus 1
radeondrm0 at pci1 dev 0 function 0 "ATI Radeon HD 6850" rev 0x00
drm0 at radeondrm0
radeondrm0: msi
azalia0 at pci1 dev 0 function 1 vendor "ATI", unknown product 0xaa88 rev 0x00: msi
azalia0: no supported codecs
ppb1 at pci0 dev 4 function 0 "AMD AMD64 15/1xh PCIE" rev 0x00: msi
pci2 at ppb1 bus 2
re0 at pci2 dev 0 function 0 "Realtek 8168" rev 0x0c: RTL8168G/8111G (0x4c00), msi, address 44:8a:5b:d4:0f:a3
rgephy0 at re0 phy 7: RTL8251 PHY, rev. 0
xhci0 at pci0 dev 16 function 0 "AMD Bolton xHCI" rev 0x09: msi, xHCI 1.0
usb0 at xhci0: USB revision 3.0
uhub0 at usb0 configuration 1 interface 0 "AMD xHCI root hub" rev 3.00/1.00 addr 1
xhci1 at pci0 dev 16 function 1 "AMD Bolton xHCI" rev 0x09: msi, xHCI 1.0
usb1 at xhci1: USB revision 3.0
uhub1 at usb1 configuration 1 interface 0 "AMD xHCI root hub" rev 3.00/1.00 addr 1
ahci0 at pci0 dev 17 function 0 "AMD Hudson-2 SATA" rev 0x40: msi, AHCI 1.3
ahci0: port 0: 6.0Gb/s
ahci0: port 1: 3.0Gb/s
scsibus1 at ahci0: 32 targets
sd0 at scsibus1 targ 0 lun 0: <ATA, Samsung SSD 850, EMT0> SCSI3 0/direct fixed naa.5002538d41e6d54d
sd0: 238475MB, 512 bytes/sector, 488397168 sectors, thin
sd1 at scsibus1 targ 1 lun 0: <ATA, WDC WD5000AAKS-6, 06.0> SCSI3 0/direct fixed naa.50014ee15834bd34
sd1: 476940MB, 512 bytes/sector, 976773168 sectors
ohci0 at pci0 dev 18 function 0 "AMD Hudson-2 USB" rev 0x11: apic 0 int 18, version 1.0, legacy support
ehci0 at pci0 dev 18 function 2 "AMD Hudson-2 USB2" rev 0x11: apic 0 int 17
usb2 at ehci0: USB revision 2.0
uhub2 at usb2 configuration 1 interface 0 "AMD EHCI root hub" rev 2.00/1.00 addr 1
ohci1 at pci0 dev 19 function 0 "AMD Hudson-2 USB" rev 0x11: apic 0 int 18, version 1.0, legacy support
ehci1 at pci0 dev 19 function 2 "AMD Hudson-2 USB2" rev 0x11: apic 0 int 17
usb3 at ehci1: USB revision 2.0
uhub3 at usb3 configuration 1 interface 0 "AMD EHCI root hub" rev 2.00/1.00 addr 1
piixpm0 at pci0 dev 20 function 0 "AMD Hudson-2 SMBus" rev 0x16: polling
iic0 at piixpm0
spdmem0 at iic0 addr 0x52: 2GB DDR3 SDRAM PC3-10600
spdmem1 at iic0 addr 0x53: 2GB DDR3 SDRAM PC3-10600
azalia1 at pci0 dev 20 function 2 "AMD Hudson-2 HD Audio" rev 0x01: apic 0 int 16
azalia1: codecs: Realtek/0x0887
audio0 at azalia1
pcib0 at pci0 dev 20 function 3 "AMD Hudson-2 LPC" rev 0x11
ppb2 at pci0 dev 20 function 4 "AMD Hudson-2 PCI" rev 0x40
pci3 at ppb2 bus 3
ohci2 at pci0 dev 20 function 5 "AMD Hudson-2 USB" rev 0x11: apic 0 int 18, version 1.0, legacy support
pchb1 at pci0 dev 24 function 0 "AMD AMD64 15/1xh Link Cfg" rev 0x00
pchb2 at pci0 dev 24 function 1 "AMD AMD64 15/1xh Address Map" rev 0x00
pchb3 at pci0 dev 24 function 2 "AMD AMD64 15/1xh DRAM Cfg" rev 0x00
km0 at pci0 dev 24 function 3 "AMD AMD64 15/1xh Misc Cfg" rev 0x00
pchb4 at pci0 dev 24 function 4 "AMD AMD64 15/1xh CPU Power" rev 0x00
pchb5 at pci0 dev 24 function 5 "AMD AMD64 15/1xh NB Power" rev 0x00
usb4 at ohci0: USB revision 1.0
uhub4 at usb4 configuration 1 interface 0 "AMD OHCI root hub" rev 1.00/1.00 addr 1
usb5 at ohci1: USB revision 1.0
uhub5 at usb5 configuration 1 interface 0 "AMD OHCI root hub" rev 1.00/1.00 addr 1
isa0 at pcib0
isadma0 at isa0
com0 at isa0 port 0x3f8/8 irq 4: ns16550a, 16 byte fifo
com0: probed fifo depth: 15 bytes
pckbc0 at isa0 port 0x60/5 irq 1 irq 12
pckbd0 at pckbc0 (kbd slot)
wskbd0 at pckbd0: console keyboard
pcppi0 at isa0 port 0x61
spkr0 at pcppi0
lpt0 at isa0 port 0x378/4 irq 7
usb6 at ohci2: USB revision 1.0
uhub6 at usb6 configuration 1 interface 0 "AMD OHCI root hub" rev 1.00/1.00 addr 1
vmm0 at mainbus0: SVM/RVI
uhub7 at uhub5 port 1 configuration 1 interface 0 "ALCOR USB Hub 2.0" rev 2.00/7.02 addr 2
uhidev0 at uhub7 port 3 configuration 1 interface 0 " USB Keyboard" rev 1.10/4.06 addr 3
uhidev0: iclass 3/1
ukbd0 at uhidev0: 8 variable keys, 6 key codes
wskbd1 at ukbd0 mux 1
uhidev1 at uhub7 port 3 configuration 1 interface 1 " USB Keyboard" rev 1.10/4.06 addr 3
uhidev1: iclass 3/0, 2 report ids
uhid0 at uhidev1 reportid 1: input=1, output=0, feature=0
uhid1 at uhidev1 reportid 2: input=3, output=0, feature=0
uhidev2 at uhub7 port 4 configuration 1 interface 0 "Logitech USB Receiver" rev 2.00/29.01 addr 4
uhidev2: iclass 3/1
ukbd1 at uhidev2: 8 variable keys, 6 key codes
wskbd2 at ukbd1 mux 1
uhidev3 at uhub7 port 4 configuration 1 interface 1 "Logitech USB Receiver" rev 2.00/29.01 addr 4
uhidev3: iclass 3/1, 17 report ids
ums0 at uhidev3 reportid 2: 16 buttons, Z and W dir
wsmouse0 at ums0 mux 0
uhid2 at uhidev3 reportid 3: input=4, output=0, feature=0
uhid3 at uhidev3 reportid 4: input=1, output=0, feature=0
uhid4 at uhidev3 reportid 16: input=6, output=6, feature=0
uhid5 at uhidev3 reportid 17: input=19, output=19, feature=0
vscsi0 at root
scsibus2 at vscsi0: 256 targets
softraid0 at root
scsibus3 at softraid0: 256 targets
sd2 at scsibus3 targ 1 lun 0: <OPENBSD, SR CRYPTO, 006> SCSI2 0/direct fixed
sd2: 238472MB, 512 bytes/sector, 488391473 sectors
softraid0: volume sd2 is roaming, it used to be sd3, updating metadata
root on sd2a (ae15c17b9037e886.a) swap on sd2b dump on sd2b
initializing kernel modesetting (BARTS 0x1002:0x6739 0x174B:0x174B 0x00).
radeondrm0: 1440x900, 32bpp
wsdisplay0 at radeondrm0 mux 1: console (std, vt100 emulation), using wskbd0
wskbd1: connecting to wsdisplay0
wskbd2: connecting to wsdisplay0
wsdisplay0: screen 1-5 added (std, vt100 emulation)

usbdevs:
Controller /dev/usb0:
addr 01: 1022:0000 AMD, xHCI root hub
         super speed, self powered, config 1, rev 1.00
         driver: uhub0
Controller /dev/usb1:
addr 01: 1022:0000 AMD, xHCI root hub
         super speed, self powered, config 1, rev 1.00
         driver: uhub1
Controller /dev/usb2:
addr 01: 1022:0000 AMD, EHCI root hub
         high speed, self powered, config 1, rev 1.00
         driver: uhub2
Controller /dev/usb3:
addr 01: 1022:0000 AMD, EHCI root hub
         high speed, self powered, config 1, rev 1.00
         driver: uhub3
Controller /dev/usb4:
addr 01: 1022:0000 AMD, OHCI root hub
         full speed, self powered, config 1, rev 1.00
         driver: uhub4
Controller /dev/usb5:
addr 01: 1022:0000 AMD, OHCI root hub
         full speed, self powered, config 1, rev 1.00
         driver: uhub5
addr 02: 05e3:0606 ALCOR, USB Hub 2.0
         full speed, self powered, config 1, rev 7.02
         driver: uhub7
addr 03: 04d9:1702 , USB Keyboard
         low speed, power 100 mA, config 1, rev 4.06
         driver: uhidev0
         driver: uhidev1
addr 04: 046d:c534 Logitech, USB Receiver
         full speed, power 98 mA, config 1, rev 29.01
         driver: uhidev2
         driver: uhidev3
Controller /dev/usb6:
addr 01: 1022:0000 AMD, OHCI root hub
         full speed, self powered, config 1, rev 1.00
         driver: uhub6

Reply | Threaded
Open this post in threaded view
|

Re: key input repeat speed too fast

Theo Buehler-3
On Mon, Aug 12, 2019 at 02:34:55PM +0200, [hidden email] wrote:

> >Synopsis: key input repeat speed too fast.
> >Category: cwm
> >Environment:
> System      : OpenBSD 6.6
> Details     : OpenBSD 6.6-beta (GENERIC.MP) #201: Sun Aug 11 23:13:55 MDT 2019
> [hidden email]:/usr/src/sys/arch/amd64/compile/GENERIC.MP
>
> Architecture: OpenBSD.amd64
> Machine     : amd64
> >Description:
> Since last snapshot, when opening an X session with cwm, a pressed key is
> repeated multiple times.
> Example : try to write "ls" in xterm produce "lllsss"
>
> Also, videos are played very fast (not sure it's related).
> >How-To-Repeat:
> Open a new X session under cwm and write anything.
> >Fix:

Thanks for the report.

It would be helpful to know which commit triggered this issue. One of
the suspicious commits is the TSC change.  Could you apply the revert
below on top of a -current tree, compile and install a new kernel
(see release(8), step 2) and test if the problem persists?

Index: sys/arch/amd64/amd64/cpu.c
===================================================================
RCS file: /var/cvs/src/sys/arch/amd64/amd64/cpu.c,v
retrieving revision 1.139
diff -u -p -r1.139 cpu.c
--- sys/arch/amd64/amd64/cpu.c 9 Aug 2019 15:20:04 -0000 1.139
+++ sys/arch/amd64/amd64/cpu.c 12 Aug 2019 18:44:55 -0000
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.c,v 1.139 2019/08/09 15:20:04 pirofti Exp $ */
+/* $OpenBSD: cpu.c,v 1.138 2019/08/07 18:53:28 guenther Exp $ */
 /* $NetBSD: cpu.c,v 1.1 2003/04/26 18:39:26 fvdl Exp $ */
 
 /*-
@@ -800,10 +800,6 @@ cpu_init(struct cpu_info *ci)
  cr4 = rcr4();
  lcr4(cr4 & ~CR4_PGE);
  lcr4(cr4);
-
- /* Synchronize TSC */
- if (cold && !CPU_IS_PRIMARY(ci))
-      tsc_sync_ap(ci);
 #endif
 }
 
@@ -858,7 +854,6 @@ void
 cpu_start_secondary(struct cpu_info *ci)
 {
  int i;
- u_long s;
 
  ci->ci_flags |= CPUF_AP;
 
@@ -879,18 +874,6 @@ cpu_start_secondary(struct cpu_info *ci)
  printf("dropping into debugger; continue from here to resume boot\n");
  db_enter();
 #endif
- } else {
- /*
- * Synchronize time stamp counters. Invalidate cache and
- * synchronize twice (in tsc_sync_bp) to minimize possible
- * cache effects. Disable interrupts to try and rule out any
- * external interference.
- */
- s = intr_disable();
- wbinvd();
- tsc_sync_bp(ci);
- intr_restore(s);
- printf("TSC skew=%lld\n", (long long)ci->ci_tsc_skew);
  }
 
  if ((ci->ci_flags & CPUF_IDENTIFIED) == 0) {
@@ -915,8 +898,6 @@ void
 cpu_boot_secondary(struct cpu_info *ci)
 {
  int i;
- int64_t drift;
- u_long s;
 
  atomic_setbits_int(&ci->ci_flags, CPUF_GO);
 
@@ -929,17 +910,6 @@ cpu_boot_secondary(struct cpu_info *ci)
  printf("dropping into debugger; continue from here to resume boot\n");
  db_enter();
 #endif
- } else if (cold) {
- /* Synchronize TSC again, check for drift. */
- drift = ci->ci_tsc_skew;
- s = intr_disable();
- wbinvd();
- tsc_sync_bp(ci);
- intr_restore(s);
- drift -= ci->ci_tsc_skew;
- printf("TSC skew=%lld drift=%lld\n",
-    (long long)ci->ci_tsc_skew, (long long)drift);
- tsc_sync_drift(drift);
  }
 }
 
@@ -964,14 +934,7 @@ cpu_hatch(void *v)
  panic("%s: already running!?", ci->ci_dev->dv_xname);
 #endif
 
- /*
- * Synchronize the TSC for the first time. Note that interrupts are
- * off at this point.
- */
- wbinvd();
  ci->ci_flags |= CPUF_PRESENT;
- ci->ci_tsc_skew = 0; /* reset on resume */
- tsc_sync_ap(ci);
 
  lapic_enable();
  lapic_startclock();
Index: sys/arch/amd64/amd64/tsc.c
===================================================================
RCS file: /var/cvs/src/sys/arch/amd64/amd64/tsc.c,v
retrieving revision 1.13
diff -u -p -r1.13 tsc.c
--- sys/arch/amd64/amd64/tsc.c 9 Aug 2019 15:20:05 -0000 1.13
+++ sys/arch/amd64/amd64/tsc.c 12 Aug 2019 18:44:55 -0000
@@ -1,10 +1,8 @@
-/* $OpenBSD: tsc.c,v 1.13 2019/08/09 15:20:05 pirofti Exp $ */
+/* $OpenBSD: tsc.c,v 1.12 2019/08/03 14:57:51 jcs Exp $ */
 /*
- * Copyright (c) 2008 The NetBSD Foundation, Inc.
  * Copyright (c) 2016,2017 Reyk Floeter <[hidden email]>
  * Copyright (c) 2017 Adam Steen <[hidden email]>
  * Copyright (c) 2017 Mike Belopuhov <[hidden email]>
- * Copyright (c) 2019 Paul Irofti <[hidden email]>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -22,7 +20,6 @@
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/timetc.h>
-#include <sys/atomic.h>
 
 #include <machine/cpu.h>
 #include <machine/cpufunc.h>
@@ -36,12 +33,6 @@ int tsc_recalibrate;
 uint64_t tsc_frequency;
 int tsc_is_invariant;
 
-#define TSC_DRIFT_MAX 250
-int64_t tsc_drift_observed;
-
-volatile int64_t tsc_sync_val;
-volatile struct cpu_info *tsc_sync_cpu;
-
 uint tsc_get_timecount(struct timecounter *tc);
 
 #include "lapic.h"
@@ -190,8 +181,10 @@ calibrate_tsc_freq(void)
  return;
  tsc_frequency = freq;
  tsc_timecounter.tc_frequency = freq;
+#ifndef MULTIPROCESSOR
  if (tsc_is_invariant)
  tsc_timecounter.tc_quality = 2000;
+#endif
 }
 
 void
@@ -210,13 +203,14 @@ cpu_recalibrate_tsc(struct timecounter *
 uint
 tsc_get_timecount(struct timecounter *tc)
 {
- return rdtsc() + curcpu()->ci_tsc_skew;
+ return rdtsc();
 }
 
 void
 tsc_timecounter_init(struct cpu_info *ci, uint64_t cpufreq)
 {
- if (!(ci->ci_flags & CPUF_CONST_TSC) ||
+ if (!(ci->ci_flags & CPUF_PRIMARY) ||
+    !(ci->ci_flags & CPUF_CONST_TSC) ||
     !(ci->ci_flags & CPUF_INVAR_TSC))
  return;
 
@@ -226,7 +220,9 @@ tsc_timecounter_init(struct cpu_info *ci
  /* Newer CPUs don't require recalibration */
  if (tsc_frequency > 0) {
  tsc_timecounter.tc_frequency = tsc_frequency;
+#ifndef MULTIPROCESSOR
  tsc_timecounter.tc_quality = 2000;
+#endif
  } else {
  tsc_recalibrate = 1;
  tsc_frequency = cpufreq;
@@ -234,103 +230,5 @@ tsc_timecounter_init(struct cpu_info *ci
  calibrate_tsc_freq();
  }
 
- if (tsc_drift_observed > TSC_DRIFT_MAX) {
- printf("ERROR: %lld cycle TSC drift observed\n",
-    (long long)tsc_drift_observed);
- tsc_timecounter.tc_quality = -1000;
- tsc_is_invariant = 0;
- }
-
- printf("%s: TSC skew=%lld observed drift=%lld\n", __func__,
-    (long long)ci->ci_tsc_skew, (long long)tsc_drift_observed);
-
- if (ci->ci_flags & CPUF_PRIMARY)
- tc_init(&tsc_timecounter);
-}
-
-/*
- * Record drift (in clock cycles).  Called during AP startup.
- */
-void
-tsc_sync_drift(int64_t drift)
-{
- if (drift < 0)
- drift = -drift;
- if (drift > tsc_drift_observed)
- tsc_drift_observed = drift;
-}
-
-/*
- * Called during startup of APs, by the boot processor.  Interrupts
- * are disabled on entry.
- */
-void
-tsc_read_bp(struct cpu_info *ci, uint64_t *bptscp, uint64_t *aptscp)
-{
- uint64_t bptsc;
-
- if (atomic_swap_ptr(&tsc_sync_cpu, ci) != NULL)
- panic("tsc_sync_bp: 1");
-
- /* Flag it and read our TSC. */
- atomic_setbits_int(&ci->ci_flags, CPUF_SYNCTSC);
- bptsc = (rdtsc() >> 1);
-
- /* Wait for remote to complete, and read ours again. */
- while ((ci->ci_flags & CPUF_SYNCTSC) != 0)
- membar_consumer();
- bptsc += (rdtsc() >> 1);
-
- /* Wait for the results to come in. */
- while (tsc_sync_cpu == ci)
- CPU_BUSY_CYCLE();
- if (tsc_sync_cpu != NULL)
- panic("tsc_sync_bp: 2");
-
- *bptscp = bptsc;
- *aptscp = tsc_sync_val;
-}
-
-void
-tsc_sync_bp(struct cpu_info *ci)
-{
- uint64_t bptsc, aptsc;
-
- tsc_read_bp(ci, &bptsc, &aptsc); /* discarded - cache effects */
- tsc_read_bp(ci, &bptsc, &aptsc);
-
- /* Compute final value to adjust for skew. */
- ci->ci_tsc_skew = bptsc - aptsc;
-}
-
-/*
- * Called during startup of AP, by the AP itself.  Interrupts are
- * disabled on entry.
- */
-void
-tsc_post_ap(struct cpu_info *ci)
-{
- uint64_t tsc;
-
- /* Wait for go-ahead from primary. */
- while ((ci->ci_flags & CPUF_SYNCTSC) == 0)
- membar_consumer();
- tsc = (rdtsc() >> 1);
-
- /* Instruct primary to read its counter. */
- atomic_clearbits_int(&ci->ci_flags, CPUF_SYNCTSC);
- tsc += (rdtsc() >> 1);
-
- /* Post result.  Ensure the whole value goes out atomically. */
- (void)atomic_swap_64(&tsc_sync_val, tsc);
-
- if (atomic_swap_ptr(&tsc_sync_cpu, NULL) != ci)
- panic("tsc_sync_ap");
-}
-
-void
-tsc_sync_ap(struct cpu_info *ci)
-{
- tsc_post_ap(ci);
- tsc_post_ap(ci);
+ tc_init(&tsc_timecounter);
 }
Index: sys/arch/amd64/include/cpu.h
===================================================================
RCS file: /var/cvs/src/sys/arch/amd64/include/cpu.h,v
retrieving revision 1.132
diff -u -p -r1.132 cpu.h
--- sys/arch/amd64/include/cpu.h 9 Aug 2019 15:20:05 -0000 1.132
+++ sys/arch/amd64/include/cpu.h 12 Aug 2019 18:44:55 -0000
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.h,v 1.132 2019/08/09 15:20:05 pirofti Exp $ */
+/* $OpenBSD: cpu.h,v 1.131 2019/05/17 19:07:16 guenther Exp $ */
 /* $NetBSD: cpu.h,v 1.1 2003/04/26 18:39:39 fvdl Exp $ */
 
 /*-
@@ -206,8 +206,6 @@ struct cpu_info {
  union vmm_cpu_cap ci_vmm_cap;
  paddr_t ci_vmxon_region_pa;
  struct vmxon_region *ci_vmxon_region;
-
- int64_t ci_tsc_skew; /* counter skew vs cpu0 */
 };
 
 #define CPUF_BSP 0x0001 /* CPU is the original BSP */
@@ -223,7 +221,6 @@ struct cpu_info {
 #define CPUF_INVAR_TSC 0x0100 /* CPU has invariant TSC */
 #define CPUF_USERXSTATE 0x0200 /* CPU has curproc's xsave state */
 
-#define CPUF_SYNCTSC 0x0800 /* Synchronize TSC */
 #define CPUF_PRESENT 0x1000 /* CPU is present */
 #define CPUF_RUNNING 0x2000 /* CPU is running */
 #define CPUF_PAUSE 0x4000 /* CPU is paused in DDB */
Index: sys/arch/amd64/include/cpuvar.h
===================================================================
RCS file: /var/cvs/src/sys/arch/amd64/include/cpuvar.h,v
retrieving revision 1.10
diff -u -p -r1.10 cpuvar.h
--- sys/arch/amd64/include/cpuvar.h 9 Aug 2019 15:20:05 -0000 1.10
+++ sys/arch/amd64/include/cpuvar.h 12 Aug 2019 18:44:55 -0000
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpuvar.h,v 1.10 2019/08/09 15:20:05 pirofti Exp $ */
+/* $OpenBSD: cpuvar.h,v 1.9 2017/10/06 13:33:53 mikeb Exp $ */
 /* $NetBSD: cpuvar.h,v 1.1 2003/03/01 18:29:28 fvdl Exp $ */
 
 /*-
@@ -97,9 +97,5 @@ void identifycpu(struct cpu_info *);
 void cpu_init(struct cpu_info *);
 void cpu_init_first(void);
 void cpu_adjust_tsc_freq(uint64_t (*)());
-
-void tsc_sync_drift(int64_t);
-void tsc_sync_bp(struct cpu_info *);
-void tsc_sync_ap(struct cpu_info *);
 
 #endif

prx
Reply | Threaded
Open this post in threaded view
|

Re: key input repeat speed too fast

prx
* Theo Buehler <[hidden email]> le [14-08-2019 07:23:01 +0200]:

> On Mon, Aug 12, 2019 at 02:34:55PM +0200, [hidden email] wrote:
> > >Synopsis: key input repeat speed too fast.
> > >Category: cwm
> > >Environment:
> > System      : OpenBSD 6.6
> > Details     : OpenBSD 6.6-beta (GENERIC.MP) #201: Sun Aug 11 23:13:55 MDT 2019
> > [hidden email]:/usr/src/sys/arch/amd64/compile/GENERIC.MP
> >
> > Architecture: OpenBSD.amd64
> > Machine     : amd64
> > >Description:
> > Since last snapshot, when opening an X session with cwm, a pressed key is
> > repeated multiple times.
> > Example : try to write "ls" in xterm produce "lllsss"
> >
> > Also, videos are played very fast (not sure it's related).
> > >How-To-Repeat:
> > Open a new X session under cwm and write anything.
> > >Fix:
>
> Thanks for the report.
>
> It would be helpful to know which commit triggered this issue. One of
> the suspicious commits is the TSC change.  Could you apply the revert
> below on top of a -current tree, compile and install a new kernel
> (see release(8), step 2) and test if the problem persists?
>

No tested the patch yet, but some more information gathered thanks to @phessler

- When starting the ntpd without "constraints" in ntpd.conf, there is no issue
  until a while, when ntpd is mistaken and set the time way in the past
  according to logs in /var/log/daemon :

        adjusting local clock by -904.535135s

- Using ``xset r rate 1550`` make X session usable but doesn't solve the issue
- Adding in /etc/sysctl.conf fix the issue :
        kern.timecounter.hardware=acpihpet0

Regards
--
    prx

Reply | Threaded
Open this post in threaded view
|

Re: key input repeat speed too fast

Paul Irofti-4
On Wed, Aug 14, 2019 at 02:00:37PM +0200, prx wrote:

> * Theo Buehler <[hidden email]> le [14-08-2019 07:23:01 +0200]:
> > On Mon, Aug 12, 2019 at 02:34:55PM +0200, [hidden email] wrote:
> > > >Synopsis: key input repeat speed too fast.
> > > >Category: cwm
> > > >Environment:
> > > System      : OpenBSD 6.6
> > > Details     : OpenBSD 6.6-beta (GENERIC.MP) #201: Sun Aug 11 23:13:55 MDT 2019
> > > [hidden email]:/usr/src/sys/arch/amd64/compile/GENERIC.MP
> > >
> > > Architecture: OpenBSD.amd64
> > > Machine     : amd64
> > > >Description:
> > > Since last snapshot, when opening an X session with cwm, a pressed key is
> > > repeated multiple times.
> > > Example : try to write "ls" in xterm produce "lllsss"
> > >
> > > Also, videos are played very fast (not sure it's related).
> > > >How-To-Repeat:
> > > Open a new X session under cwm and write anything.
> > > >Fix:
> >
> > Thanks for the report.
> >
> > It would be helpful to know which commit triggered this issue. One of
> > the suspicious commits is the TSC change.  Could you apply the revert
> > below on top of a -current tree, compile and install a new kernel
> > (see release(8), step 2) and test if the problem persists?
> >
>
> No tested the patch yet, but some more information gathered thanks to @phessler

Hi,

Could you please let us know once you tested the patch?

Reverting will probably fix your machine as acpihpet0 fixes your issue,
and reverting the diff will make it the default choice. So, could you
please also try forcing tsc as default with the reverted diff
(just like you are doing now in sysctl.conf for acpihpet0) and let us
know if that also breaks the machine?

Thank you,
Paul Irofti

prx
Reply | Threaded
Open this post in threaded view
|

Re: key input repeat speed too fast

prx
In reply to this post by Theo Buehler-3
* Theo Buehler <[hidden email]> le [14-08-2019 07:23:01 +0200]:

> On Mon, Aug 12, 2019 at 02:34:55PM +0200, [hidden email] wrote:
> > >Synopsis: key input repeat speed too fast.
> > >Category: cwm
> > >Environment:
> > System      : OpenBSD 6.6
> > Details     : OpenBSD 6.6-beta (GENERIC.MP) #201: Sun Aug 11 23:13:55 MDT 2019
> > [hidden email]:/usr/src/sys/arch/amd64/compile/GENERIC.MP
> >
> > Architecture: OpenBSD.amd64
> > Machine     : amd64
> > >Description:
> > Since last snapshot, when opening an X session with cwm, a pressed key is
> > repeated multiple times.
> > Example : try to write "ls" in xterm produce "lllsss"
> >
> > Also, videos are played very fast (not sure it's related).
> > >How-To-Repeat:
> > Open a new X session under cwm and write anything.
> > >Fix:
>
> Thanks for the report.
>
> It would be helpful to know which commit triggered this issue. One of
> the suspicious commits is the TSC change.  Could you apply the revert
> below on top of a -current tree, compile and install a new kernel
> (see release(8), step 2) and test if the problem persists?
>
> Index: sys/arch/amd64/amd64/cpu.c
> ===================================================================
> RCS file: /var/cvs/src/sys/arch/amd64/amd64/cpu.c,v
> retrieving revision 1.139
> diff -u -p -r1.139 cpu.c
> --- sys/arch/amd64/amd64/cpu.c 9 Aug 2019 15:20:04 -0000 1.139
> +++ sys/arch/amd64/amd64/cpu.c 12 Aug 2019 18:44:55 -0000
> @@ -1,4 +1,4 @@
> -/* $OpenBSD: cpu.c,v 1.139 2019/08/09 15:20:04 pirofti Exp $ */
> +/* $OpenBSD: cpu.c,v 1.138 2019/08/07 18:53:28 guenther Exp $ */
>  /* $NetBSD: cpu.c,v 1.1 2003/04/26 18:39:26 fvdl Exp $ */
>  
>  /*-
> @@ -800,10 +800,6 @@ cpu_init(struct cpu_info *ci)
>   cr4 = rcr4();
>   lcr4(cr4 & ~CR4_PGE);
>   lcr4(cr4);
> -
> - /* Synchronize TSC */
> - if (cold && !CPU_IS_PRIMARY(ci))
> -      tsc_sync_ap(ci);
>  #endif
>  }
>  
> @@ -858,7 +854,6 @@ void
>  cpu_start_secondary(struct cpu_info *ci)
>  {
>   int i;
> - u_long s;
>  
>   ci->ci_flags |= CPUF_AP;
>  
> @@ -879,18 +874,6 @@ cpu_start_secondary(struct cpu_info *ci)
>   printf("dropping into debugger; continue from here to resume boot\n");
>   db_enter();
>  #endif
> - } else {
> - /*
> - * Synchronize time stamp counters. Invalidate cache and
> - * synchronize twice (in tsc_sync_bp) to minimize possible
> - * cache effects. Disable interrupts to try and rule out any
> - * external interference.
> - */
> - s = intr_disable();
> - wbinvd();
> - tsc_sync_bp(ci);
> - intr_restore(s);
> - printf("TSC skew=%lld\n", (long long)ci->ci_tsc_skew);
>   }
>  
>   if ((ci->ci_flags & CPUF_IDENTIFIED) == 0) {
> @@ -915,8 +898,6 @@ void
>  cpu_boot_secondary(struct cpu_info *ci)
>  {
>   int i;
> - int64_t drift;
> - u_long s;
>  
>   atomic_setbits_int(&ci->ci_flags, CPUF_GO);
>  
> @@ -929,17 +910,6 @@ cpu_boot_secondary(struct cpu_info *ci)
>   printf("dropping into debugger; continue from here to resume boot\n");
>   db_enter();
>  #endif
> - } else if (cold) {
> - /* Synchronize TSC again, check for drift. */
> - drift = ci->ci_tsc_skew;
> - s = intr_disable();
> - wbinvd();
> - tsc_sync_bp(ci);
> - intr_restore(s);
> - drift -= ci->ci_tsc_skew;
> - printf("TSC skew=%lld drift=%lld\n",
> -    (long long)ci->ci_tsc_skew, (long long)drift);
> - tsc_sync_drift(drift);
>   }
>  }
>  
> @@ -964,14 +934,7 @@ cpu_hatch(void *v)
>   panic("%s: already running!?", ci->ci_dev->dv_xname);
>  #endif
>  
> - /*
> - * Synchronize the TSC for the first time. Note that interrupts are
> - * off at this point.
> - */
> - wbinvd();
>   ci->ci_flags |= CPUF_PRESENT;
> - ci->ci_tsc_skew = 0; /* reset on resume */
> - tsc_sync_ap(ci);
>  
>   lapic_enable();
>   lapic_startclock();
> Index: sys/arch/amd64/amd64/tsc.c
> ===================================================================
> RCS file: /var/cvs/src/sys/arch/amd64/amd64/tsc.c,v
> retrieving revision 1.13
> diff -u -p -r1.13 tsc.c
> --- sys/arch/amd64/amd64/tsc.c 9 Aug 2019 15:20:05 -0000 1.13
> +++ sys/arch/amd64/amd64/tsc.c 12 Aug 2019 18:44:55 -0000
> @@ -1,10 +1,8 @@
> -/* $OpenBSD: tsc.c,v 1.13 2019/08/09 15:20:05 pirofti Exp $ */
> +/* $OpenBSD: tsc.c,v 1.12 2019/08/03 14:57:51 jcs Exp $ */
>  /*
> - * Copyright (c) 2008 The NetBSD Foundation, Inc.
>   * Copyright (c) 2016,2017 Reyk Floeter <[hidden email]>
>   * Copyright (c) 2017 Adam Steen <[hidden email]>
>   * Copyright (c) 2017 Mike Belopuhov <[hidden email]>
> - * Copyright (c) 2019 Paul Irofti <[hidden email]>
>   *
>   * Permission to use, copy, modify, and distribute this software for any
>   * purpose with or without fee is hereby granted, provided that the above
> @@ -22,7 +20,6 @@
>  #include <sys/param.h>
>  #include <sys/systm.h>
>  #include <sys/timetc.h>
> -#include <sys/atomic.h>
>  
>  #include <machine/cpu.h>
>  #include <machine/cpufunc.h>
> @@ -36,12 +33,6 @@ int tsc_recalibrate;
>  uint64_t tsc_frequency;
>  int tsc_is_invariant;
>  
> -#define TSC_DRIFT_MAX 250
> -int64_t tsc_drift_observed;
> -
> -volatile int64_t tsc_sync_val;
> -volatile struct cpu_info *tsc_sync_cpu;
> -
>  uint tsc_get_timecount(struct timecounter *tc);
>  
>  #include "lapic.h"
> @@ -190,8 +181,10 @@ calibrate_tsc_freq(void)
>   return;
>   tsc_frequency = freq;
>   tsc_timecounter.tc_frequency = freq;
> +#ifndef MULTIPROCESSOR
>   if (tsc_is_invariant)
>   tsc_timecounter.tc_quality = 2000;
> +#endif
>  }
>  
>  void
> @@ -210,13 +203,14 @@ cpu_recalibrate_tsc(struct timecounter *
>  uint
>  tsc_get_timecount(struct timecounter *tc)
>  {
> - return rdtsc() + curcpu()->ci_tsc_skew;
> + return rdtsc();
>  }
>  
>  void
>  tsc_timecounter_init(struct cpu_info *ci, uint64_t cpufreq)
>  {
> - if (!(ci->ci_flags & CPUF_CONST_TSC) ||
> + if (!(ci->ci_flags & CPUF_PRIMARY) ||
> +    !(ci->ci_flags & CPUF_CONST_TSC) ||
>      !(ci->ci_flags & CPUF_INVAR_TSC))
>   return;
>  
> @@ -226,7 +220,9 @@ tsc_timecounter_init(struct cpu_info *ci
>   /* Newer CPUs don't require recalibration */
>   if (tsc_frequency > 0) {
>   tsc_timecounter.tc_frequency = tsc_frequency;
> +#ifndef MULTIPROCESSOR
>   tsc_timecounter.tc_quality = 2000;
> +#endif
>   } else {
>   tsc_recalibrate = 1;
>   tsc_frequency = cpufreq;
> @@ -234,103 +230,5 @@ tsc_timecounter_init(struct cpu_info *ci
>   calibrate_tsc_freq();
>   }
>  
> - if (tsc_drift_observed > TSC_DRIFT_MAX) {
> - printf("ERROR: %lld cycle TSC drift observed\n",
> -    (long long)tsc_drift_observed);
> - tsc_timecounter.tc_quality = -1000;
> - tsc_is_invariant = 0;
> - }
> -
> - printf("%s: TSC skew=%lld observed drift=%lld\n", __func__,
> -    (long long)ci->ci_tsc_skew, (long long)tsc_drift_observed);
> -
> - if (ci->ci_flags & CPUF_PRIMARY)
> - tc_init(&tsc_timecounter);
> -}
> -
> -/*
> - * Record drift (in clock cycles).  Called during AP startup.
> - */
> -void
> -tsc_sync_drift(int64_t drift)
> -{
> - if (drift < 0)
> - drift = -drift;
> - if (drift > tsc_drift_observed)
> - tsc_drift_observed = drift;
> -}
> -
> -/*
> - * Called during startup of APs, by the boot processor.  Interrupts
> - * are disabled on entry.
> - */
> -void
> -tsc_read_bp(struct cpu_info *ci, uint64_t *bptscp, uint64_t *aptscp)
> -{
> - uint64_t bptsc;
> -
> - if (atomic_swap_ptr(&tsc_sync_cpu, ci) != NULL)
> - panic("tsc_sync_bp: 1");
> -
> - /* Flag it and read our TSC. */
> - atomic_setbits_int(&ci->ci_flags, CPUF_SYNCTSC);
> - bptsc = (rdtsc() >> 1);
> -
> - /* Wait for remote to complete, and read ours again. */
> - while ((ci->ci_flags & CPUF_SYNCTSC) != 0)
> - membar_consumer();
> - bptsc += (rdtsc() >> 1);
> -
> - /* Wait for the results to come in. */
> - while (tsc_sync_cpu == ci)
> - CPU_BUSY_CYCLE();
> - if (tsc_sync_cpu != NULL)
> - panic("tsc_sync_bp: 2");
> -
> - *bptscp = bptsc;
> - *aptscp = tsc_sync_val;
> -}
> -
> -void
> -tsc_sync_bp(struct cpu_info *ci)
> -{
> - uint64_t bptsc, aptsc;
> -
> - tsc_read_bp(ci, &bptsc, &aptsc); /* discarded - cache effects */
> - tsc_read_bp(ci, &bptsc, &aptsc);
> -
> - /* Compute final value to adjust for skew. */
> - ci->ci_tsc_skew = bptsc - aptsc;
> -}
> -
> -/*
> - * Called during startup of AP, by the AP itself.  Interrupts are
> - * disabled on entry.
> - */
> -void
> -tsc_post_ap(struct cpu_info *ci)
> -{
> - uint64_t tsc;
> -
> - /* Wait for go-ahead from primary. */
> - while ((ci->ci_flags & CPUF_SYNCTSC) == 0)
> - membar_consumer();
> - tsc = (rdtsc() >> 1);
> -
> - /* Instruct primary to read its counter. */
> - atomic_clearbits_int(&ci->ci_flags, CPUF_SYNCTSC);
> - tsc += (rdtsc() >> 1);
> -
> - /* Post result.  Ensure the whole value goes out atomically. */
> - (void)atomic_swap_64(&tsc_sync_val, tsc);
> -
> - if (atomic_swap_ptr(&tsc_sync_cpu, NULL) != ci)
> - panic("tsc_sync_ap");
> -}
> -
> -void
> -tsc_sync_ap(struct cpu_info *ci)
> -{
> - tsc_post_ap(ci);
> - tsc_post_ap(ci);
> + tc_init(&tsc_timecounter);
>  }
> Index: sys/arch/amd64/include/cpu.h
> ===================================================================
> RCS file: /var/cvs/src/sys/arch/amd64/include/cpu.h,v
> retrieving revision 1.132
> diff -u -p -r1.132 cpu.h
> --- sys/arch/amd64/include/cpu.h 9 Aug 2019 15:20:05 -0000 1.132
> +++ sys/arch/amd64/include/cpu.h 12 Aug 2019 18:44:55 -0000
> @@ -1,4 +1,4 @@
> -/* $OpenBSD: cpu.h,v 1.132 2019/08/09 15:20:05 pirofti Exp $ */
> +/* $OpenBSD: cpu.h,v 1.131 2019/05/17 19:07:16 guenther Exp $ */
>  /* $NetBSD: cpu.h,v 1.1 2003/04/26 18:39:39 fvdl Exp $ */
>  
>  /*-
> @@ -206,8 +206,6 @@ struct cpu_info {
>   union vmm_cpu_cap ci_vmm_cap;
>   paddr_t ci_vmxon_region_pa;
>   struct vmxon_region *ci_vmxon_region;
> -
> - int64_t ci_tsc_skew; /* counter skew vs cpu0 */
>  };
>  
>  #define CPUF_BSP 0x0001 /* CPU is the original BSP */
> @@ -223,7 +221,6 @@ struct cpu_info {
>  #define CPUF_INVAR_TSC 0x0100 /* CPU has invariant TSC */
>  #define CPUF_USERXSTATE 0x0200 /* CPU has curproc's xsave state */
>  
> -#define CPUF_SYNCTSC 0x0800 /* Synchronize TSC */
>  #define CPUF_PRESENT 0x1000 /* CPU is present */
>  #define CPUF_RUNNING 0x2000 /* CPU is running */
>  #define CPUF_PAUSE 0x4000 /* CPU is paused in DDB */
> Index: sys/arch/amd64/include/cpuvar.h
> ===================================================================
> RCS file: /var/cvs/src/sys/arch/amd64/include/cpuvar.h,v
> retrieving revision 1.10
> diff -u -p -r1.10 cpuvar.h
> --- sys/arch/amd64/include/cpuvar.h 9 Aug 2019 15:20:05 -0000 1.10
> +++ sys/arch/amd64/include/cpuvar.h 12 Aug 2019 18:44:55 -0000
> @@ -1,4 +1,4 @@
> -/* $OpenBSD: cpuvar.h,v 1.10 2019/08/09 15:20:05 pirofti Exp $ */
> +/* $OpenBSD: cpuvar.h,v 1.9 2017/10/06 13:33:53 mikeb Exp $ */
>  /* $NetBSD: cpuvar.h,v 1.1 2003/03/01 18:29:28 fvdl Exp $ */
>  
>  /*-
> @@ -97,9 +97,5 @@ void identifycpu(struct cpu_info *);
>  void cpu_init(struct cpu_info *);
>  void cpu_init_first(void);
>  void cpu_adjust_tsc_freq(uint64_t (*)());
> -
> -void tsc_sync_drift(int64_t);
> -void tsc_sync_bp(struct cpu_info *);
> -void tsc_sync_ap(struct cpu_info *);
>  
>  #endif
>

Patch applied, no more issue now.

However, even if /etc/sysctl.conf is empty, I notice :

        # sysctl |grep timecoun.*hard  
        kern.timecounter.hardware=acpihpet0

So, by default, @phessler solution seems to be applied.

Of course, telle me if I can provide any further data.
--
    prx

Reply | Threaded
Open this post in threaded view
|

Re: key input repeat speed too fast

Paul Irofti-4
On Wed, Aug 14, 2019 at 03:19:28PM +0200, prx wrote:

> * Theo Buehler <[hidden email]> le [14-08-2019 07:23:01 +0200]:
> > On Mon, Aug 12, 2019 at 02:34:55PM +0200, [hidden email] wrote:
> > > >Synopsis: key input repeat speed too fast.
> > > >Category: cwm
> > > >Environment:
> > > System      : OpenBSD 6.6
> > > Details     : OpenBSD 6.6-beta (GENERIC.MP) #201: Sun Aug 11 23:13:55 MDT 2019
> > > [hidden email]:/usr/src/sys/arch/amd64/compile/GENERIC.MP
> > >
> > > Architecture: OpenBSD.amd64
> > > Machine     : amd64
> > > >Description:
> > > Since last snapshot, when opening an X session with cwm, a pressed key is
> > > repeated multiple times.
> > > Example : try to write "ls" in xterm produce "lllsss"
> > >
> > > Also, videos are played very fast (not sure it's related).
> > > >How-To-Repeat:
> > > Open a new X session under cwm and write anything.
> > > >Fix:
> >
> > Thanks for the report.
> >
> > It would be helpful to know which commit triggered this issue. One of
> > the suspicious commits is the TSC change.  Could you apply the revert
> > below on top of a -current tree, compile and install a new kernel
> > (see release(8), step 2) and test if the problem persists?
> >
> > Index: sys/arch/amd64/amd64/cpu.c
> > ===================================================================
> > RCS file: /var/cvs/src/sys/arch/amd64/amd64/cpu.c,v
> > retrieving revision 1.139
> > diff -u -p -r1.139 cpu.c
> > --- sys/arch/amd64/amd64/cpu.c 9 Aug 2019 15:20:04 -0000 1.139
> > +++ sys/arch/amd64/amd64/cpu.c 12 Aug 2019 18:44:55 -0000
> > @@ -1,4 +1,4 @@
> > -/* $OpenBSD: cpu.c,v 1.139 2019/08/09 15:20:04 pirofti Exp $ */
> > +/* $OpenBSD: cpu.c,v 1.138 2019/08/07 18:53:28 guenther Exp $ */
> >  /* $NetBSD: cpu.c,v 1.1 2003/04/26 18:39:26 fvdl Exp $ */
> >  
> >  /*-
> > @@ -800,10 +800,6 @@ cpu_init(struct cpu_info *ci)
> >   cr4 = rcr4();
> >   lcr4(cr4 & ~CR4_PGE);
> >   lcr4(cr4);
> > -
> > - /* Synchronize TSC */
> > - if (cold && !CPU_IS_PRIMARY(ci))
> > -      tsc_sync_ap(ci);
> >  #endif
> >  }
> >  
> > @@ -858,7 +854,6 @@ void
> >  cpu_start_secondary(struct cpu_info *ci)
> >  {
> >   int i;
> > - u_long s;
> >  
> >   ci->ci_flags |= CPUF_AP;
> >  
> > @@ -879,18 +874,6 @@ cpu_start_secondary(struct cpu_info *ci)
> >   printf("dropping into debugger; continue from here to resume boot\n");
> >   db_enter();
> >  #endif
> > - } else {
> > - /*
> > - * Synchronize time stamp counters. Invalidate cache and
> > - * synchronize twice (in tsc_sync_bp) to minimize possible
> > - * cache effects. Disable interrupts to try and rule out any
> > - * external interference.
> > - */
> > - s = intr_disable();
> > - wbinvd();
> > - tsc_sync_bp(ci);
> > - intr_restore(s);
> > - printf("TSC skew=%lld\n", (long long)ci->ci_tsc_skew);
> >   }
> >  
> >   if ((ci->ci_flags & CPUF_IDENTIFIED) == 0) {
> > @@ -915,8 +898,6 @@ void
> >  cpu_boot_secondary(struct cpu_info *ci)
> >  {
> >   int i;
> > - int64_t drift;
> > - u_long s;
> >  
> >   atomic_setbits_int(&ci->ci_flags, CPUF_GO);
> >  
> > @@ -929,17 +910,6 @@ cpu_boot_secondary(struct cpu_info *ci)
> >   printf("dropping into debugger; continue from here to resume boot\n");
> >   db_enter();
> >  #endif
> > - } else if (cold) {
> > - /* Synchronize TSC again, check for drift. */
> > - drift = ci->ci_tsc_skew;
> > - s = intr_disable();
> > - wbinvd();
> > - tsc_sync_bp(ci);
> > - intr_restore(s);
> > - drift -= ci->ci_tsc_skew;
> > - printf("TSC skew=%lld drift=%lld\n",
> > -    (long long)ci->ci_tsc_skew, (long long)drift);
> > - tsc_sync_drift(drift);
> >   }
> >  }
> >  
> > @@ -964,14 +934,7 @@ cpu_hatch(void *v)
> >   panic("%s: already running!?", ci->ci_dev->dv_xname);
> >  #endif
> >  
> > - /*
> > - * Synchronize the TSC for the first time. Note that interrupts are
> > - * off at this point.
> > - */
> > - wbinvd();
> >   ci->ci_flags |= CPUF_PRESENT;
> > - ci->ci_tsc_skew = 0; /* reset on resume */
> > - tsc_sync_ap(ci);
> >  
> >   lapic_enable();
> >   lapic_startclock();
> > Index: sys/arch/amd64/amd64/tsc.c
> > ===================================================================
> > RCS file: /var/cvs/src/sys/arch/amd64/amd64/tsc.c,v
> > retrieving revision 1.13
> > diff -u -p -r1.13 tsc.c
> > --- sys/arch/amd64/amd64/tsc.c 9 Aug 2019 15:20:05 -0000 1.13
> > +++ sys/arch/amd64/amd64/tsc.c 12 Aug 2019 18:44:55 -0000
> > @@ -1,10 +1,8 @@
> > -/* $OpenBSD: tsc.c,v 1.13 2019/08/09 15:20:05 pirofti Exp $ */
> > +/* $OpenBSD: tsc.c,v 1.12 2019/08/03 14:57:51 jcs Exp $ */
> >  /*
> > - * Copyright (c) 2008 The NetBSD Foundation, Inc.
> >   * Copyright (c) 2016,2017 Reyk Floeter <[hidden email]>
> >   * Copyright (c) 2017 Adam Steen <[hidden email]>
> >   * Copyright (c) 2017 Mike Belopuhov <[hidden email]>
> > - * Copyright (c) 2019 Paul Irofti <[hidden email]>
> >   *
> >   * Permission to use, copy, modify, and distribute this software for any
> >   * purpose with or without fee is hereby granted, provided that the above
> > @@ -22,7 +20,6 @@
> >  #include <sys/param.h>
> >  #include <sys/systm.h>
> >  #include <sys/timetc.h>
> > -#include <sys/atomic.h>
> >  
> >  #include <machine/cpu.h>
> >  #include <machine/cpufunc.h>
> > @@ -36,12 +33,6 @@ int tsc_recalibrate;
> >  uint64_t tsc_frequency;
> >  int tsc_is_invariant;
> >  
> > -#define TSC_DRIFT_MAX 250
> > -int64_t tsc_drift_observed;
> > -
> > -volatile int64_t tsc_sync_val;
> > -volatile struct cpu_info *tsc_sync_cpu;
> > -
> >  uint tsc_get_timecount(struct timecounter *tc);
> >  
> >  #include "lapic.h"
> > @@ -190,8 +181,10 @@ calibrate_tsc_freq(void)
> >   return;
> >   tsc_frequency = freq;
> >   tsc_timecounter.tc_frequency = freq;
> > +#ifndef MULTIPROCESSOR
> >   if (tsc_is_invariant)
> >   tsc_timecounter.tc_quality = 2000;
> > +#endif
> >  }
> >  
> >  void
> > @@ -210,13 +203,14 @@ cpu_recalibrate_tsc(struct timecounter *
> >  uint
> >  tsc_get_timecount(struct timecounter *tc)
> >  {
> > - return rdtsc() + curcpu()->ci_tsc_skew;
> > + return rdtsc();
> >  }
> >  
> >  void
> >  tsc_timecounter_init(struct cpu_info *ci, uint64_t cpufreq)
> >  {
> > - if (!(ci->ci_flags & CPUF_CONST_TSC) ||
> > + if (!(ci->ci_flags & CPUF_PRIMARY) ||
> > +    !(ci->ci_flags & CPUF_CONST_TSC) ||
> >      !(ci->ci_flags & CPUF_INVAR_TSC))
> >   return;
> >  
> > @@ -226,7 +220,9 @@ tsc_timecounter_init(struct cpu_info *ci
> >   /* Newer CPUs don't require recalibration */
> >   if (tsc_frequency > 0) {
> >   tsc_timecounter.tc_frequency = tsc_frequency;
> > +#ifndef MULTIPROCESSOR
> >   tsc_timecounter.tc_quality = 2000;
> > +#endif
> >   } else {
> >   tsc_recalibrate = 1;
> >   tsc_frequency = cpufreq;
> > @@ -234,103 +230,5 @@ tsc_timecounter_init(struct cpu_info *ci
> >   calibrate_tsc_freq();
> >   }
> >  
> > - if (tsc_drift_observed > TSC_DRIFT_MAX) {
> > - printf("ERROR: %lld cycle TSC drift observed\n",
> > -    (long long)tsc_drift_observed);
> > - tsc_timecounter.tc_quality = -1000;
> > - tsc_is_invariant = 0;
> > - }
> > -
> > - printf("%s: TSC skew=%lld observed drift=%lld\n", __func__,
> > -    (long long)ci->ci_tsc_skew, (long long)tsc_drift_observed);
> > -
> > - if (ci->ci_flags & CPUF_PRIMARY)
> > - tc_init(&tsc_timecounter);
> > -}
> > -
> > -/*
> > - * Record drift (in clock cycles).  Called during AP startup.
> > - */
> > -void
> > -tsc_sync_drift(int64_t drift)
> > -{
> > - if (drift < 0)
> > - drift = -drift;
> > - if (drift > tsc_drift_observed)
> > - tsc_drift_observed = drift;
> > -}
> > -
> > -/*
> > - * Called during startup of APs, by the boot processor.  Interrupts
> > - * are disabled on entry.
> > - */
> > -void
> > -tsc_read_bp(struct cpu_info *ci, uint64_t *bptscp, uint64_t *aptscp)
> > -{
> > - uint64_t bptsc;
> > -
> > - if (atomic_swap_ptr(&tsc_sync_cpu, ci) != NULL)
> > - panic("tsc_sync_bp: 1");
> > -
> > - /* Flag it and read our TSC. */
> > - atomic_setbits_int(&ci->ci_flags, CPUF_SYNCTSC);
> > - bptsc = (rdtsc() >> 1);
> > -
> > - /* Wait for remote to complete, and read ours again. */
> > - while ((ci->ci_flags & CPUF_SYNCTSC) != 0)
> > - membar_consumer();
> > - bptsc += (rdtsc() >> 1);
> > -
> > - /* Wait for the results to come in. */
> > - while (tsc_sync_cpu == ci)
> > - CPU_BUSY_CYCLE();
> > - if (tsc_sync_cpu != NULL)
> > - panic("tsc_sync_bp: 2");
> > -
> > - *bptscp = bptsc;
> > - *aptscp = tsc_sync_val;
> > -}
> > -
> > -void
> > -tsc_sync_bp(struct cpu_info *ci)
> > -{
> > - uint64_t bptsc, aptsc;
> > -
> > - tsc_read_bp(ci, &bptsc, &aptsc); /* discarded - cache effects */
> > - tsc_read_bp(ci, &bptsc, &aptsc);
> > -
> > - /* Compute final value to adjust for skew. */
> > - ci->ci_tsc_skew = bptsc - aptsc;
> > -}
> > -
> > -/*
> > - * Called during startup of AP, by the AP itself.  Interrupts are
> > - * disabled on entry.
> > - */
> > -void
> > -tsc_post_ap(struct cpu_info *ci)
> > -{
> > - uint64_t tsc;
> > -
> > - /* Wait for go-ahead from primary. */
> > - while ((ci->ci_flags & CPUF_SYNCTSC) == 0)
> > - membar_consumer();
> > - tsc = (rdtsc() >> 1);
> > -
> > - /* Instruct primary to read its counter. */
> > - atomic_clearbits_int(&ci->ci_flags, CPUF_SYNCTSC);
> > - tsc += (rdtsc() >> 1);
> > -
> > - /* Post result.  Ensure the whole value goes out atomically. */
> > - (void)atomic_swap_64(&tsc_sync_val, tsc);
> > -
> > - if (atomic_swap_ptr(&tsc_sync_cpu, NULL) != ci)
> > - panic("tsc_sync_ap");
> > -}
> > -
> > -void
> > -tsc_sync_ap(struct cpu_info *ci)
> > -{
> > - tsc_post_ap(ci);
> > - tsc_post_ap(ci);
> > + tc_init(&tsc_timecounter);
> >  }
> > Index: sys/arch/amd64/include/cpu.h
> > ===================================================================
> > RCS file: /var/cvs/src/sys/arch/amd64/include/cpu.h,v
> > retrieving revision 1.132
> > diff -u -p -r1.132 cpu.h
> > --- sys/arch/amd64/include/cpu.h 9 Aug 2019 15:20:05 -0000 1.132
> > +++ sys/arch/amd64/include/cpu.h 12 Aug 2019 18:44:55 -0000
> > @@ -1,4 +1,4 @@
> > -/* $OpenBSD: cpu.h,v 1.132 2019/08/09 15:20:05 pirofti Exp $ */
> > +/* $OpenBSD: cpu.h,v 1.131 2019/05/17 19:07:16 guenther Exp $ */
> >  /* $NetBSD: cpu.h,v 1.1 2003/04/26 18:39:39 fvdl Exp $ */
> >  
> >  /*-
> > @@ -206,8 +206,6 @@ struct cpu_info {
> >   union vmm_cpu_cap ci_vmm_cap;
> >   paddr_t ci_vmxon_region_pa;
> >   struct vmxon_region *ci_vmxon_region;
> > -
> > - int64_t ci_tsc_skew; /* counter skew vs cpu0 */
> >  };
> >  
> >  #define CPUF_BSP 0x0001 /* CPU is the original BSP */
> > @@ -223,7 +221,6 @@ struct cpu_info {
> >  #define CPUF_INVAR_TSC 0x0100 /* CPU has invariant TSC */
> >  #define CPUF_USERXSTATE 0x0200 /* CPU has curproc's xsave state */
> >  
> > -#define CPUF_SYNCTSC 0x0800 /* Synchronize TSC */
> >  #define CPUF_PRESENT 0x1000 /* CPU is present */
> >  #define CPUF_RUNNING 0x2000 /* CPU is running */
> >  #define CPUF_PAUSE 0x4000 /* CPU is paused in DDB */
> > Index: sys/arch/amd64/include/cpuvar.h
> > ===================================================================
> > RCS file: /var/cvs/src/sys/arch/amd64/include/cpuvar.h,v
> > retrieving revision 1.10
> > diff -u -p -r1.10 cpuvar.h
> > --- sys/arch/amd64/include/cpuvar.h 9 Aug 2019 15:20:05 -0000 1.10
> > +++ sys/arch/amd64/include/cpuvar.h 12 Aug 2019 18:44:55 -0000
> > @@ -1,4 +1,4 @@
> > -/* $OpenBSD: cpuvar.h,v 1.10 2019/08/09 15:20:05 pirofti Exp $ */
> > +/* $OpenBSD: cpuvar.h,v 1.9 2017/10/06 13:33:53 mikeb Exp $ */
> >  /* $NetBSD: cpuvar.h,v 1.1 2003/03/01 18:29:28 fvdl Exp $ */
> >  
> >  /*-
> > @@ -97,9 +97,5 @@ void identifycpu(struct cpu_info *);
> >  void cpu_init(struct cpu_info *);
> >  void cpu_init_first(void);
> >  void cpu_adjust_tsc_freq(uint64_t (*)());
> > -
> > -void tsc_sync_drift(int64_t);
> > -void tsc_sync_bp(struct cpu_info *);
> > -void tsc_sync_ap(struct cpu_info *);
> >  
> >  #endif
> >
>
> Patch applied, no more issue now.
>
> However, even if /etc/sysctl.conf is empty, I notice :
>
> # sysctl |grep timecoun.*hard  
> kern.timecounter.hardware=acpihpet0
>
> So, by default, @phessler solution seems to be applied.
>
> Of course, telle me if I can provide any further data.

See my message from 5 minutes ago :)

With the patch applied, try and force the timecounter to tsc.

prx
Reply | Threaded
Open this post in threaded view
|

Re: key input repeat speed too fast

prx
* Paul Irofti <[hidden email]> le [14-08-2019 15:43:19 +0300]:

> On Wed, Aug 14, 2019 at 03:19:28PM +0200, prx wrote:
> > * Theo Buehler <[hidden email]> le [14-08-2019 07:23:01 +0200]:
> > > On Mon, Aug 12, 2019 at 02:34:55PM +0200, [hidden email] wrote:
> > > > >Synopsis: key input repeat speed too fast.
> > > > >Category: cwm
> > > > >Environment:
> > > > System      : OpenBSD 6.6
> > > > Details     : OpenBSD 6.6-beta (GENERIC.MP) #201: Sun Aug 11 23:13:55 MDT 2019
> > > > [hidden email]:/usr/src/sys/arch/amd64/compile/GENERIC.MP
> > > >
> > > > Architecture: OpenBSD.amd64
> > > > Machine     : amd64
> > > > >Description:
> > > > Since last snapshot, when opening an X session with cwm, a pressed key is
> > > > repeated multiple times.
> > > > Example : try to write "ls" in xterm produce "lllsss"
> > > >
> > > > Also, videos are played very fast (not sure it's related).
> > > > >How-To-Repeat:
> > > > Open a new X session under cwm and write anything.
> > > > >Fix:
> > >
> > > Thanks for the report.
> > >
> > > It would be helpful to know which commit triggered this issue. One of
> > > the suspicious commits is the TSC change.  Could you apply the revert
> > > below on top of a -current tree, compile and install a new kernel
> > > (see release(8), step 2) and test if the problem persists?
> > >
> > > Index: sys/arch/amd64/amd64/cpu.c
> > > ===================================================================
> > > RCS file: /var/cvs/src/sys/arch/amd64/amd64/cpu.c,v
> > > retrieving revision 1.139
> > > diff -u -p -r1.139 cpu.c
> > > --- sys/arch/amd64/amd64/cpu.c 9 Aug 2019 15:20:04 -0000 1.139
> > > +++ sys/arch/amd64/amd64/cpu.c 12 Aug 2019 18:44:55 -0000
> > > @@ -1,4 +1,4 @@
> > > -/* $OpenBSD: cpu.c,v 1.139 2019/08/09 15:20:04 pirofti Exp $ */
> > > +/* $OpenBSD: cpu.c,v 1.138 2019/08/07 18:53:28 guenther Exp $ */
> > >  /* $NetBSD: cpu.c,v 1.1 2003/04/26 18:39:26 fvdl Exp $ */
> > >  
> > >  /*-
> > > @@ -800,10 +800,6 @@ cpu_init(struct cpu_info *ci)
> > >   cr4 = rcr4();
> > >   lcr4(cr4 & ~CR4_PGE);
> > >   lcr4(cr4);
> > > -
> > > - /* Synchronize TSC */
> > > - if (cold && !CPU_IS_PRIMARY(ci))
> > > -      tsc_sync_ap(ci);
> > >  #endif
> > >  }
> > >  
> > > @@ -858,7 +854,6 @@ void
> > >  cpu_start_secondary(struct cpu_info *ci)
> > >  {
> > >   int i;
> > > - u_long s;
> > >  
> > >   ci->ci_flags |= CPUF_AP;
> > >  
> > > @@ -879,18 +874,6 @@ cpu_start_secondary(struct cpu_info *ci)
> > >   printf("dropping into debugger; continue from here to resume boot\n");
> > >   db_enter();
> > >  #endif
> > > - } else {
> > > - /*
> > > - * Synchronize time stamp counters. Invalidate cache and
> > > - * synchronize twice (in tsc_sync_bp) to minimize possible
> > > - * cache effects. Disable interrupts to try and rule out any
> > > - * external interference.
> > > - */
> > > - s = intr_disable();
> > > - wbinvd();
> > > - tsc_sync_bp(ci);
> > > - intr_restore(s);
> > > - printf("TSC skew=%lld\n", (long long)ci->ci_tsc_skew);
> > >   }
> > >  
> > >   if ((ci->ci_flags & CPUF_IDENTIFIED) == 0) {
> > > @@ -915,8 +898,6 @@ void
> > >  cpu_boot_secondary(struct cpu_info *ci)
> > >  {
> > >   int i;
> > > - int64_t drift;
> > > - u_long s;
> > >  
> > >   atomic_setbits_int(&ci->ci_flags, CPUF_GO);
> > >  
> > > @@ -929,17 +910,6 @@ cpu_boot_secondary(struct cpu_info *ci)
> > >   printf("dropping into debugger; continue from here to resume boot\n");
> > >   db_enter();
> > >  #endif
> > > - } else if (cold) {
> > > - /* Synchronize TSC again, check for drift. */
> > > - drift = ci->ci_tsc_skew;
> > > - s = intr_disable();
> > > - wbinvd();
> > > - tsc_sync_bp(ci);
> > > - intr_restore(s);
> > > - drift -= ci->ci_tsc_skew;
> > > - printf("TSC skew=%lld drift=%lld\n",
> > > -    (long long)ci->ci_tsc_skew, (long long)drift);
> > > - tsc_sync_drift(drift);
> > >   }
> > >  }
> > >  
> > > @@ -964,14 +934,7 @@ cpu_hatch(void *v)
> > >   panic("%s: already running!?", ci->ci_dev->dv_xname);
> > >  #endif
> > >  
> > > - /*
> > > - * Synchronize the TSC for the first time. Note that interrupts are
> > > - * off at this point.
> > > - */
> > > - wbinvd();
> > >   ci->ci_flags |= CPUF_PRESENT;
> > > - ci->ci_tsc_skew = 0; /* reset on resume */
> > > - tsc_sync_ap(ci);
> > >  
> > >   lapic_enable();
> > >   lapic_startclock();
> > > Index: sys/arch/amd64/amd64/tsc.c
> > > ===================================================================
> > > RCS file: /var/cvs/src/sys/arch/amd64/amd64/tsc.c,v
> > > retrieving revision 1.13
> > > diff -u -p -r1.13 tsc.c
> > > --- sys/arch/amd64/amd64/tsc.c 9 Aug 2019 15:20:05 -0000 1.13
> > > +++ sys/arch/amd64/amd64/tsc.c 12 Aug 2019 18:44:55 -0000
> > > @@ -1,10 +1,8 @@
> > > -/* $OpenBSD: tsc.c,v 1.13 2019/08/09 15:20:05 pirofti Exp $ */
> > > +/* $OpenBSD: tsc.c,v 1.12 2019/08/03 14:57:51 jcs Exp $ */
> > >  /*
> > > - * Copyright (c) 2008 The NetBSD Foundation, Inc.
> > >   * Copyright (c) 2016,2017 Reyk Floeter <[hidden email]>
> > >   * Copyright (c) 2017 Adam Steen <[hidden email]>
> > >   * Copyright (c) 2017 Mike Belopuhov <[hidden email]>
> > > - * Copyright (c) 2019 Paul Irofti <[hidden email]>
> > >   *
> > >   * Permission to use, copy, modify, and distribute this software for any
> > >   * purpose with or without fee is hereby granted, provided that the above
> > > @@ -22,7 +20,6 @@
> > >  #include <sys/param.h>
> > >  #include <sys/systm.h>
> > >  #include <sys/timetc.h>
> > > -#include <sys/atomic.h>
> > >  
> > >  #include <machine/cpu.h>
> > >  #include <machine/cpufunc.h>
> > > @@ -36,12 +33,6 @@ int tsc_recalibrate;
> > >  uint64_t tsc_frequency;
> > >  int tsc_is_invariant;
> > >  
> > > -#define TSC_DRIFT_MAX 250
> > > -int64_t tsc_drift_observed;
> > > -
> > > -volatile int64_t tsc_sync_val;
> > > -volatile struct cpu_info *tsc_sync_cpu;
> > > -
> > >  uint tsc_get_timecount(struct timecounter *tc);
> > >  
> > >  #include "lapic.h"
> > > @@ -190,8 +181,10 @@ calibrate_tsc_freq(void)
> > >   return;
> > >   tsc_frequency = freq;
> > >   tsc_timecounter.tc_frequency = freq;
> > > +#ifndef MULTIPROCESSOR
> > >   if (tsc_is_invariant)
> > >   tsc_timecounter.tc_quality = 2000;
> > > +#endif
> > >  }
> > >  
> > >  void
> > > @@ -210,13 +203,14 @@ cpu_recalibrate_tsc(struct timecounter *
> > >  uint
> > >  tsc_get_timecount(struct timecounter *tc)
> > >  {
> > > - return rdtsc() + curcpu()->ci_tsc_skew;
> > > + return rdtsc();
> > >  }
> > >  
> > >  void
> > >  tsc_timecounter_init(struct cpu_info *ci, uint64_t cpufreq)
> > >  {
> > > - if (!(ci->ci_flags & CPUF_CONST_TSC) ||
> > > + if (!(ci->ci_flags & CPUF_PRIMARY) ||
> > > +    !(ci->ci_flags & CPUF_CONST_TSC) ||
> > >      !(ci->ci_flags & CPUF_INVAR_TSC))
> > >   return;
> > >  
> > > @@ -226,7 +220,9 @@ tsc_timecounter_init(struct cpu_info *ci
> > >   /* Newer CPUs don't require recalibration */
> > >   if (tsc_frequency > 0) {
> > >   tsc_timecounter.tc_frequency = tsc_frequency;
> > > +#ifndef MULTIPROCESSOR
> > >   tsc_timecounter.tc_quality = 2000;
> > > +#endif
> > >   } else {
> > >   tsc_recalibrate = 1;
> > >   tsc_frequency = cpufreq;
> > > @@ -234,103 +230,5 @@ tsc_timecounter_init(struct cpu_info *ci
> > >   calibrate_tsc_freq();
> > >   }
> > >  
> > > - if (tsc_drift_observed > TSC_DRIFT_MAX) {
> > > - printf("ERROR: %lld cycle TSC drift observed\n",
> > > -    (long long)tsc_drift_observed);
> > > - tsc_timecounter.tc_quality = -1000;
> > > - tsc_is_invariant = 0;
> > > - }
> > > -
> > > - printf("%s: TSC skew=%lld observed drift=%lld\n", __func__,
> > > -    (long long)ci->ci_tsc_skew, (long long)tsc_drift_observed);
> > > -
> > > - if (ci->ci_flags & CPUF_PRIMARY)
> > > - tc_init(&tsc_timecounter);
> > > -}
> > > -
> > > -/*
> > > - * Record drift (in clock cycles).  Called during AP startup.
> > > - */
> > > -void
> > > -tsc_sync_drift(int64_t drift)
> > > -{
> > > - if (drift < 0)
> > > - drift = -drift;
> > > - if (drift > tsc_drift_observed)
> > > - tsc_drift_observed = drift;
> > > -}
> > > -
> > > -/*
> > > - * Called during startup of APs, by the boot processor.  Interrupts
> > > - * are disabled on entry.
> > > - */
> > > -void
> > > -tsc_read_bp(struct cpu_info *ci, uint64_t *bptscp, uint64_t *aptscp)
> > > -{
> > > - uint64_t bptsc;
> > > -
> > > - if (atomic_swap_ptr(&tsc_sync_cpu, ci) != NULL)
> > > - panic("tsc_sync_bp: 1");
> > > -
> > > - /* Flag it and read our TSC. */
> > > - atomic_setbits_int(&ci->ci_flags, CPUF_SYNCTSC);
> > > - bptsc = (rdtsc() >> 1);
> > > -
> > > - /* Wait for remote to complete, and read ours again. */
> > > - while ((ci->ci_flags & CPUF_SYNCTSC) != 0)
> > > - membar_consumer();
> > > - bptsc += (rdtsc() >> 1);
> > > -
> > > - /* Wait for the results to come in. */
> > > - while (tsc_sync_cpu == ci)
> > > - CPU_BUSY_CYCLE();
> > > - if (tsc_sync_cpu != NULL)
> > > - panic("tsc_sync_bp: 2");
> > > -
> > > - *bptscp = bptsc;
> > > - *aptscp = tsc_sync_val;
> > > -}
> > > -
> > > -void
> > > -tsc_sync_bp(struct cpu_info *ci)
> > > -{
> > > - uint64_t bptsc, aptsc;
> > > -
> > > - tsc_read_bp(ci, &bptsc, &aptsc); /* discarded - cache effects */
> > > - tsc_read_bp(ci, &bptsc, &aptsc);
> > > -
> > > - /* Compute final value to adjust for skew. */
> > > - ci->ci_tsc_skew = bptsc - aptsc;
> > > -}
> > > -
> > > -/*
> > > - * Called during startup of AP, by the AP itself.  Interrupts are
> > > - * disabled on entry.
> > > - */
> > > -void
> > > -tsc_post_ap(struct cpu_info *ci)
> > > -{
> > > - uint64_t tsc;
> > > -
> > > - /* Wait for go-ahead from primary. */
> > > - while ((ci->ci_flags & CPUF_SYNCTSC) == 0)
> > > - membar_consumer();
> > > - tsc = (rdtsc() >> 1);
> > > -
> > > - /* Instruct primary to read its counter. */
> > > - atomic_clearbits_int(&ci->ci_flags, CPUF_SYNCTSC);
> > > - tsc += (rdtsc() >> 1);
> > > -
> > > - /* Post result.  Ensure the whole value goes out atomically. */
> > > - (void)atomic_swap_64(&tsc_sync_val, tsc);
> > > -
> > > - if (atomic_swap_ptr(&tsc_sync_cpu, NULL) != ci)
> > > - panic("tsc_sync_ap");
> > > -}
> > > -
> > > -void
> > > -tsc_sync_ap(struct cpu_info *ci)
> > > -{
> > > - tsc_post_ap(ci);
> > > - tsc_post_ap(ci);
> > > + tc_init(&tsc_timecounter);
> > >  }
> > > Index: sys/arch/amd64/include/cpu.h
> > > ===================================================================
> > > RCS file: /var/cvs/src/sys/arch/amd64/include/cpu.h,v
> > > retrieving revision 1.132
> > > diff -u -p -r1.132 cpu.h
> > > --- sys/arch/amd64/include/cpu.h 9 Aug 2019 15:20:05 -0000 1.132
> > > +++ sys/arch/amd64/include/cpu.h 12 Aug 2019 18:44:55 -0000
> > > @@ -1,4 +1,4 @@
> > > -/* $OpenBSD: cpu.h,v 1.132 2019/08/09 15:20:05 pirofti Exp $ */
> > > +/* $OpenBSD: cpu.h,v 1.131 2019/05/17 19:07:16 guenther Exp $ */
> > >  /* $NetBSD: cpu.h,v 1.1 2003/04/26 18:39:39 fvdl Exp $ */
> > >  
> > >  /*-
> > > @@ -206,8 +206,6 @@ struct cpu_info {
> > >   union vmm_cpu_cap ci_vmm_cap;
> > >   paddr_t ci_vmxon_region_pa;
> > >   struct vmxon_region *ci_vmxon_region;
> > > -
> > > - int64_t ci_tsc_skew; /* counter skew vs cpu0 */
> > >  };
> > >  
> > >  #define CPUF_BSP 0x0001 /* CPU is the original BSP */
> > > @@ -223,7 +221,6 @@ struct cpu_info {
> > >  #define CPUF_INVAR_TSC 0x0100 /* CPU has invariant TSC */
> > >  #define CPUF_USERXSTATE 0x0200 /* CPU has curproc's xsave state */
> > >  
> > > -#define CPUF_SYNCTSC 0x0800 /* Synchronize TSC */
> > >  #define CPUF_PRESENT 0x1000 /* CPU is present */
> > >  #define CPUF_RUNNING 0x2000 /* CPU is running */
> > >  #define CPUF_PAUSE 0x4000 /* CPU is paused in DDB */
> > > Index: sys/arch/amd64/include/cpuvar.h
> > > ===================================================================
> > > RCS file: /var/cvs/src/sys/arch/amd64/include/cpuvar.h,v
> > > retrieving revision 1.10
> > > diff -u -p -r1.10 cpuvar.h
> > > --- sys/arch/amd64/include/cpuvar.h 9 Aug 2019 15:20:05 -0000 1.10
> > > +++ sys/arch/amd64/include/cpuvar.h 12 Aug 2019 18:44:55 -0000
> > > @@ -1,4 +1,4 @@
> > > -/* $OpenBSD: cpuvar.h,v 1.10 2019/08/09 15:20:05 pirofti Exp $ */
> > > +/* $OpenBSD: cpuvar.h,v 1.9 2017/10/06 13:33:53 mikeb Exp $ */
> > >  /* $NetBSD: cpuvar.h,v 1.1 2003/03/01 18:29:28 fvdl Exp $ */
> > >  
> > >  /*-
> > > @@ -97,9 +97,5 @@ void identifycpu(struct cpu_info *);
> > >  void cpu_init(struct cpu_info *);
> > >  void cpu_init_first(void);
> > >  void cpu_adjust_tsc_freq(uint64_t (*)());
> > > -
> > > -void tsc_sync_drift(int64_t);
> > > -void tsc_sync_bp(struct cpu_info *);
> > > -void tsc_sync_ap(struct cpu_info *);
> > >  
> > >  #endif
> > >
> >
> > Patch applied, no more issue now.
> >
> > However, even if /etc/sysctl.conf is empty, I notice :
> >
> > # sysctl |grep timecoun.*hard  
> > kern.timecounter.hardware=acpihpet0
> >
> > So, by default, @phessler solution seems to be applied.
> >
> > Of course, telle me if I can provide any further data.
>
> See my message from 5 minutes ago :)
>
> With the patch applied, try and force the timecounter to tsc.
>

Just read it.
patch applied, timecounter to tsc in sysctl.conf, rebooted, and so
far, everything seems fine.

--
    prx

Reply | Threaded
Open this post in threaded view
|

Re: key input repeat speed too fast

Paul Irofti-4
Hi,

Thank you for the report!

I will send you a diff to test later today. In the meantime you can go back to -current as the diff will be on top of what's in the tree.

So revert the revert :)

Paul