On Tue, Oct 17, 2017 at 7:43 PM, Mike Belopuhov <[email protected]> wrote:
>
> Looks like your acpitimer takes a bit too much to obtain the value
> and exceeds the threshold that we've imposed.  Adam, I'd like to
> commit the diff below but unsure how many successes should we consider
> before accepting the value.

That is a very good question, i am am sorry i don't
have any information on number of failed/successful attempts, so i can not
offer any great insights.

My original code was loosely base on the links you gave me in my inital thread
about a tsc based timer. [0]

> Any particular reason you've picked the
> minimum frequency out of all?

I pick the minimum mostly due to the lines 773-775 [1] and line 834 [2]
of tsc.c in the linux kernel and it was cleaner code than doing an average.

> Should we consider increasing the
> threshold as well?

Linux uses a 10% leeway [3], either side of the expected value. I think that,
increasing the threadhold would be worth testing, i didn't play with the figure
much, as it seemed to just work for me.

Or do we need todo something similar to [4], but adapted to our code.

/*
* Check whether PIT failed more than once. This
* happens in virtualized environments. We need to
* give the virtual PC a slightly longer timeframe for
* the HPET/PMTIMER to make the result precise.
*/

Please let me know if you would like me to look into and test
somethings further.

Adam

[0] https://marc.info/?l=openbsd-misc&m=150148792804747&w=2
[1] 
http://elixir.free-electrons.com/linux/v4.12.4/source/arch/x86/kernel/tsc.c#L773
[2] 
http://elixir.free-electrons.com/linux/v4.12.4/source/arch/x86/kernel/tsc.c#L834
[3] 
http://elixir.free-electrons.com/linux/v4.12.4/source/arch/x86/kernel/tsc.c#L841
[4] 
http://elixir.free-electrons.com/linux/v4.12.4/source/arch/x86/kernel/tsc.c#L852

> On Mon, Oct 16, 2017 at 14:28 -0400, Joe Gidi wrote:
>> Hi Mike,
>>
>> I see your first printf here but not the second?
>>
>> dmesg:
>>
>> OpenBSD 6.2-current (GENERIC.MP) #1: Mon Oct 16 14:12:25 EDT 2017
>>     [email protected]:/usr/src/sys/arch/amd64/compile/GENERIC.MP
>> real mem = 4192956416 (3998MB)
>> avail mem = 4059013120 (3870MB)
>> mpath0 at root
>> scsibus0 at mpath0: 256 targets
>> mainbus0 at root
>> bios0 at mainbus0: SMBIOS rev. 2.8 @ 0xedcb0 (49 entries)
>> bios0: vendor Intel Corp. version "PYBSWCEL.86A.0064.2017.0815.1055" date
>> 08/15/2017
>> bios0: Intel Corporation NUC5CPYB
>> acpi0 at bios0: rev 2
>> acpi0: sleep states S0 S3 S4 S5
>> acpi0: tables DSDT FACP APIC FPDT FIDT MCFG SSDT SSDT SSDT UEFI LPIT TPM2
>> CSRT SSDT
>> acpi0: wakeup devices BRCM(S0) XHC1(S4) HDEF(S4) PXSX(S4) RP01(S4)
>> PXSX(S4) RP02(S4) PXSX(S4) RP03(S4) PXSX(S4) RP04(S4)
>> acpitimer0 at acpi0: 3579545 Hz, 24 bits
>> acpimadt0 at acpi0 addr 0xfee00000: PC-AT compat
>> cpu0 at mainbus0: apid 0 (boot processor)
>> cpu0: Intel(R) Celeron(R) CPU N3050 @ 1.60GHz, 1680.47 MHz
>> cpu0:
>> FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,SSE4.1,SSE4.2,MOVBE,POPCNT,DEADLINE,AES,RDRAND,NXE,RDTSCP,LONG,LAHF,3DNOWP,PERF,ITSC,SMEP,ERMS,SENSOR,ARAT
>> cpu0: 1MB 64b/line 16-way L2 cache
>> usec 100045 tsc1 35958728300 tsc2 36118795820 count1 13341437 count2 13699553
>> usec 100045 tsc1 36119540340 tsc2 36279608540 count1 13701219 count2 14059337
>> usec 100046 tsc1 36280348700 tsc2 36440417660 count1 14060993 count2 14419115
>> cpu0: smt 0, core 0, package 0
>> mtrr: Pentium Pro MTRR support, 8 var ranges, 88 fixed ranges
>> cpu0: apic clock running at 79MHz
>> cpu0: mwait min=64, max=64, C-substates=0.2.0.0.0.0.3.3, IBE
>> cpu1 at mainbus0: apid 4 (application processor)
>> cpu1: Intel(R) Celeron(R) CPU N3050 @ 1.60GHz, 1600.00 MHz
>> cpu1:
>> FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,SSE4.1,SSE4.2,MOVBE,POPCNT,DEADLINE,AES,RDRAND,NXE,RDTSCP,LONG,LAHF,3DNOWP,PERF,ITSC,SMEP,ERMS,SENSOR,ARAT
>> cpu1: 1MB 64b/line 16-way L2 cache
>> cpu1: smt 0, core 2, package 0
>> ioapic0 at mainbus0: apid 1 pa 0xfec00000, version 20, 115 pins
>> acpimcfg0 at acpi0 addr 0xe0000000, bus 0-255
>> acpiprt0 at acpi0: bus 0 (PCI0)
>> acpiprt1 at acpi0: bus 1 (RP01)
>> acpiprt2 at acpi0: bus 2 (RP02)
>> acpiprt3 at acpi0: bus 3 (RP03)
>> acpiprt4 at acpi0: bus -1 (RP04)
>> acpiec0 at acpi0: not present
>> acpicpu0 at acpi0: C1(1000@1 mwait.1), PSS
>> acpicpu1 at acpi0: C1(1000@1 mwait.1), PSS
>> acpipwrres0 at acpi0: ID3C, resource for ISP3
>> acpipwrres1 at acpi0: CLK0, resource for CAMD
>> acpipwrres2 at acpi0: CLK0
>> acpipwrres3 at acpi0: CLK1, resource for CAM3
>> acpipwrres4 at acpi0: USBC, resource for XHC1
>> acpipwrres5 at acpi0: FN00, resource for FAN0
>> acpitz0 at acpi0: critical temperature is 115 degC
>> chvgpio0 at acpi0: GPO1 uid 2 addr 0xfed88000/0x8000 irq 48, 59 pins
>> "ITE8713" at acpi0 not configured
>> "BCM43241" at acpi0 not configured
>> sdhc0 at acpi0: SDHC addr 0x81429000/0x1000 irq 47
>> sdhc0: SDHC 3.0, 200 MHz base clock
>> sdmmc0 at sdhc0: 4-bit, sd high-speed, mmc high-speed, dma
>> "INTL9C60" at acpi0 not configured
>> "INTL9C60" at acpi0 not configured
>> "8086228A" at acpi0 not configured
>> "8086228A" at acpi0 not configured
>> dwiic0 at acpi0: I2C6 addr 0x81425000/0x1000 irq 37
>> iic0 at dwiic0
>> dwiic1 at acpi0: I2C7 addr 0x81423000/0x1000 irq 38
>> iic1 at dwiic1
>> acpibtn0 at acpi0: LID0
>> acpibtn1 at acpi0: SLPB
>> chvgpio1 at acpi0: GPO0 uid 1 addr 0xfed80000/0x8000 irq 49, 56 pins
>> chvgpio2 at acpi0: GPO2 uid 3 addr 0xfed90000/0x8000 irq 50, 24 pins
>> chvgpio3 at acpi0: GPO3 uid 4 addr 0xfed98000/0x8000 irq 91, 55 pins
>> "MSFT0101" at acpi0 not configured
>> "INT3398" at acpi0 not configured
>> "PNP0C0B" at acpi0 not configured
>> acpivideo0 at acpi0: GFX0
>> cpu0: Enhanced SpeedStep 1680 MHz: speeds: 1601, 1600, 1520, 1440, 1360,
>> 1280, 1200, 1120, 1040, 960, 880, 800, 720, 640, 560, 480 MHz
>> pci0 at mainbus0 bus 0
>> pchb0 at pci0 dev 0 function 0 "Intel Braswell Host" rev 0x21
>> inteldrm0 at pci0 dev 2 function 0 "Intel HD Graphics" rev 0x21
>> drm0 at inteldrm0
>> inteldrm0: msi
>> inteldrm0: 1920x1080, 32bpp
>> wsdisplay0 at inteldrm0 mux 1: console (std, vt100 emulation)
>> wsdisplay0: screen 1-5 added (std, vt100 emulation)
>> ahci0 at pci0 dev 19 function 0 "Intel Braswell AHCI" rev 0x21: msi, AHCI
>> 1.3.1
>> ahci0: port 0: 3.0Gb/s
>> ahci0: PHY offline on port 1
>> scsibus1 at ahci0: 32 targets
>> sd0 at scsibus1 targ 0 lun 0: <ATA, ST9640320AS, 0001> SCSI3 0/direct
>> fixed naa.5000c50024852fc6
>> sd0: 610480MB, 512 bytes/sector, 1250263728 sectors
>> xhci0 at pci0 dev 20 function 0 "Intel Braswell xHCI" rev 0x21: msi
>> usb0 at xhci0: USB revision 3.0
>> uhub0 at usb0 configuration 1 interface 0 "Intel xHCI root hub" rev
>> 3.00/1.00 addr 1
>> "Intel Braswell TXE" rev 0x21 at pci0 dev 26 function 0 not configured
>> azalia0 at pci0 dev 27 function 0 "Intel Braswell HD Audio" rev 0x21: msi
>> azalia0: codecs: Realtek/0x0283, Intel/0x2883, using Realtek/0x0283
>> audio0 at azalia0
>> ppb0 at pci0 dev 28 function 0 "Intel Braswell PCIE" rev 0x21: msi
>> pci1 at ppb0 bus 1
>> ppb1 at pci0 dev 28 function 1 "Intel Braswell PCIE" rev 0x21: msi
>> pci2 at ppb1 bus 2
>> iwm0 at pci2 dev 0 function 0 "Intel Dual Band Wireless AC 3165" rev 0x81,
>> msi
>> ppb2 at pci0 dev 28 function 2 "Intel Braswell PCIE" rev 0x21: msi
>> pci3 at ppb2 bus 3
>> re0 at pci3 dev 0 function 0 "Realtek 8168" rev 0x15: RTL8168H/8111H
>> (0x5400), msi, address f4:4d:30:66:6c:71
>> rgephy0 at re0 phy 7: RTL8251 PHY, rev. 0
>> pcib0 at pci0 dev 31 function 0 "Intel Braswell PCU LPC" rev 0x21
>> ichiic0 at pci0 dev 31 function 3 "Intel Braswell SMBus" rev 0x21: apic 1
>> int 18
>> iic2 at ichiic0
>> spdmem0 at iic2 addr 0x50: 4GB DDR3 SDRAM PC3-12800 SO-DIMM
>> isa0 at pcib0
>> isadma0 at isa0
>> pckbc0 at isa0 port 0x60/5 irq 1 irq 12
>> pckbd0 at pckbc0 (kbd slot)
>> wskbd0 at pckbd0: console keyboard, using wsdisplay0
>> pcppi0 at isa0 port 0x61
>> spkr0 at pcppi0
>> vmm0 at mainbus0: VMX/EPT
>> sdmmc0: can't enable card
>> uhub1 at uhub0 port 1 configuration 1 interface 0 "Logitech Logitech BT
>> Mini-Receiver" rev 2.00/2.00 addr 2
>> uhidev0 at uhub1 port 2 configuration 1 interface 0 "Logitech Logitech BT
>> Mini-Receiver" rev 2.00/2.00 addr 3
>> uhidev0: iclass 3/1
>> ukbd0 at uhidev0: 8 variable keys, 6 key codes
>> wskbd1 at ukbd0 mux 1
>> wskbd1: connecting to wsdisplay0
>> uhidev1 at uhub1 port 3 configuration 1 interface 0 "Logitech Logitech BT
>> Mini-Receiver" rev 2.00/2.00 addr 4
>> uhidev1: iclass 3/1, 18 report ids
>> ums0 at uhidev1 reportid 2: 12 buttons, Z and W dir
>> wsmouse0 at ums0 mux 0
>> uhid0 at uhidev1 reportid 3: input=4, output=0, feature=0
>> uhid1 at uhidev1 reportid 4: input=1, output=0, feature=0
>> ums1 at uhidev1 reportid 5: 8 buttons, Z and W dir
>> wsmouse1 at ums1 mux 0
>> uhid2 at uhidev1 reportid 8: input=1, output=0, feature=0
>> uhid3 at uhidev1 reportid 16: input=6, output=6, feature=0
>> uhid4 at uhidev1 reportid 17: input=19, output=19, feature=0
>> uhid5 at uhidev1 reportid 18: input=45, output=45, feature=0
>> uhidev2 at uhub0 port 2 configuration 1 interface 0 "RDing TEMPERHUM1V1.2"
>> rev 2.00/0.01 addr 5
>> uhidev2: iclass 3/1, 1 report id
>> ukbd1 at uhidev2 reportid 1: 8 variable keys, 5 key codes
>> wskbd2 at ukbd1 mux 1
>> wskbd2: connecting to wsdisplay0
>> uhidev3 at uhub0 port 2 configuration 1 interface 1 "RDing TEMPERHUM1V1.2"
>> rev 2.00/0.01 addr 5
>> uhidev3: iclass 3/1
>> ugold0 at uhidev3
>> uhub2 at uhub0 port 5 configuration 1 interface 0 "Genesys Logic USB2.0
>> Hub" rev 2.00/32.98 addr 6
>> ugen0 at uhub2 port 1 "Intel Bluetooth" rev 2.00/0.01 addr 7
>> vscsi0 at root
>> scsibus2 at vscsi0: 256 targets
>> softraid0 at root
>> scsibus3 at softraid0: 256 targets
>> root on sd0a (de339e3c63ba70d0.a) swap on sd0b dump on sd0b
>> iwm0: hw rev 0x210, fw ver 16.242414.0, address 84:ef:18:5d:99:fe
>> ugold0: 2 sensors type si7006 (temperature and humidity)
>>
>>
>> > On Mon, Oct 16, 2017 at 16:10 +0000, Joe Gidi wrote:
>> >> Hi Mike,
>> >>
>> >> Thanks for the patch; it appears to fix the clock:
>> >>
>> >> acpitimer0 at acpi0: 3579545 Hz, 24 bits
>> >> acpimadt0 at acpi0 addr 0xfee00000: PC-AT compat
>> >>
>> >> System time is advancing at the expected rate :-)
>> >>
>> >
>> > No, nothing is fixed yet.  I'm trying to understand what's
>> > going on.  Please try this new one instead.
>> >
>> > diff --git sys/arch/amd64/amd64/tsc.c sys/arch/amd64/amd64/tsc.c
>> > index ce91d5b95df..40e35defb16 100644
>> > --- sys/arch/amd64/amd64/tsc.c
>> > +++ sys/arch/amd64/amd64/tsc.c
>> > @@ -148,18 +148,24 @@ measure_tsc_freq(struct timecounter *tc)
>> >                     continue;
>> >
>> >             usec = calculate_tc_delay(tc, count1, count2);
>> >
>> >             if ((usec < (delay_usec - RECALIBRATE_DELAY_THRESHOLD)) ||
>> > -               (usec > (delay_usec + RECALIBRATE_DELAY_THRESHOLD)))
>> > +               (usec > (delay_usec + RECALIBRATE_DELAY_THRESHOLD))) {
>> > +                   printf("usec %d tsc1 %llu tsc2 %llu count1 %llu "
>> > +                       "count2 %llu\n", usec, tsc1, tsc2, count1, count2);
>> >                     continue;
>> > +           }
>> >
>> >             frequency = calculate_tsc_freq(tsc1, tsc2, usec);
>> >
>> >             min_freq = MIN(min_freq, frequency);
>> > +           printf("tsc1 %llu tsc2 %llu freq %llu\n", tsc1, tsc2,
>> > +               frequency);
>> >     }
>> >
>> > +   min_freq = 0;
>> >     return (min_freq);
>> >  }
>> >
>> >  void
>> >  calibrate_tsc_freq(void)
>> >
>>
>>
>> --
>>
>> Joe Gidi
>> [email protected]
>>
>> "You cannot buy skill." -- Ross Seyfried
>>
>
> Index: sys/arch/amd64/amd64/tsc.c
> ===================================================================
> RCS file: /home/cvs/src/sys/arch/amd64/amd64/tsc.c,v
> retrieving revision 1.2
> diff -u -p -r1.2 tsc.c
> --- sys/arch/amd64/amd64/tsc.c  14 Oct 2017 04:44:43 -0000      1.2
> +++ sys/arch/amd64/amd64/tsc.c  16 Oct 2017 21:46:45 -0000
> @@ -122,7 +122,7 @@ measure_tsc_freq(struct timecounter *tc)
>  {
>         uint64_t count1, count2, frequency, min_freq, tsc1, tsc2;
>         u_long ef;
> -       int delay_usec, i, err1, err2, usec;
> +       int delay_usec, i, err1, err2, usec, success = 0;
>
>         /* warmup the timers */
>         for (i = 0; i < 3; i++) {
> @@ -155,9 +155,10 @@ measure_tsc_freq(struct timecounter *tc)
>                 frequency = calculate_tsc_freq(tsc1, tsc2, usec);
>
>                 min_freq = MIN(min_freq, frequency);
> +               success++;
>         }
>
> -       return (min_freq);
> +       return (success > 0 ? min_freq : 0);
>  }
>
>  void
> @@ -176,7 +177,7 @@ calibrate_tsc_freq(void)
>         if (tsc_is_invariant)
>                 tsc_timecounter.tc_quality = 2000;
>
> -       printf("%s: recalibrated TSC frequency %lld Hz\n",
> +       printf("%s: recalibrated TSC frequency %llu Hz\n",
>             reference->tc_name, tsc_timecounter.tc_frequency);
>  }
>

Reply via email to