On Wed, Dec 23, 2020 at 08:43:10PM +0000, James Cook wrote:
> On Wed, Dec 23, 2020 at 11:47:05PM +1100, Jonathan Gray wrote:
> > On Wed, Dec 23, 2020 at 12:31:10PM +1100, Jonathan Gray wrote:
> > > On Tue, Dec 22, 2020 at 06:30:48PM +0000, James Cook wrote:
> > > > > + case 0xa6: /* Coffeelake mobile */
> > > >
> > > > The laptop's CPU is an i7-10710U, which I think is in the Comet Lake
> > > > series, not Coffee Lake.
> > >
> > > Yes 0xa6 is comet lake.
> > >
> > > But we should really do what FreeBSD and Linux do and fallback to
> > > cpuid 0x16 as Intel keeps creating new skylake variants.
> > >
> > > The frequency from cpuid 0x15 is Hz, from 0x16 it is MHz.
> > >
> > > Untested as I don't have any >= skylake machines.
> > > If you can add a printf to check the value is sane that would
> > > be helpful.
> >
> > As noticed by tb@ the last diff wasn't quite right:
> >
> > Index: sys/arch/amd64/amd64/tsc.c
> > ===================================================================
> > RCS file: /cvs/src/sys/arch/amd64/amd64/tsc.c,v
> > retrieving revision 1.21
> > diff -u -p -r1.21 tsc.c
> > --- sys/arch/amd64/amd64/tsc.c 6 Sep 2020 20:50:00 -0000 1.21
> > +++ sys/arch/amd64/amd64/tsc.c 23 Dec 2020 12:25:32 -0000
> > @@ -66,14 +66,16 @@ tsc_freq_cpuid(struct cpu_info *ci)
> > eax = ebx = khz = dummy = 0;
> > CPUID(0x15, eax, ebx, khz, dummy);
> > khz /= 1000;
> > - if (khz == 0) {
> > + /*
> > + * Fallback to 'Processor Base Frequency' from cpuid 0x16 when
> > + * 'nominal frequency of the core crystal clock' from cpuid 0x15
> > + * is 0 on >= Skylake
> > + */
> > + if (khz == 0 && cpuid_level >= 0x16) {
> > + CPUID(0x16, khz, dummy, dummy, dummy);
> > + khz = khz * 1000 * eax / ebx;
> > + } else if (khz == 0) {
> > switch (ci->ci_model) {
> > - case 0x4e: /* Skylake mobile */
> > - case 0x5e: /* Skylake desktop */
> > - case 0x8e: /* Kabylake mobile */
> > - case 0x9e: /* Kabylake desktop */
> > - khz = 24000; /* 24.0 MHz */
> > - break;
> > case 0x5f: /* Atom Denverton */
> > khz = 25000; /* 25.0 MHz */
> > break;
>
> The patch works (I tested bsd.rd; sleep and date both behave right).
>
> Based on added printfs, it ends up with a khz of 23880, computed as
> 1600 * 1000 * 2 / 134.
>
> For reference, I've attached dmesg, and the diff (applied on top of
> your diff) with the relevant printfs.
>
> I notice the upper 16 bits of EAX for leaf 0x16 are described as
> "Reserved=0" in the intel manual. Should they be masked out?
Thanks for testing again. I committed case additions instead of
this as kettenis@ could not get a Skylake machine to sync the clock
with it and there is reason to believe future processors won't report
a frequency of 0 as Cannon Lake, Ice Lake, and Tiger Lake don't.
Index: sys/arch/amd64/amd64/tsc.c
===================================================================
RCS file: /cvs/src/sys/arch/amd64/amd64/tsc.c,v
retrieving revision 1.21
diff -u -p -r1.21 tsc.c
--- sys/arch/amd64/amd64/tsc.c 6 Sep 2020 20:50:00 -0000 1.21
+++ sys/arch/amd64/amd64/tsc.c 24 Dec 2020 01:59:19 -0000
@@ -72,6 +72,8 @@ tsc_freq_cpuid(struct cpu_info *ci)
case 0x5e: /* Skylake desktop */
case 0x8e: /* Kabylake mobile */
case 0x9e: /* Kabylake desktop */
+ case 0xa5: /* CML-H CML-S62 CML-S102 */
+ case 0xa6: /* CML-U62 */
khz = 24000; /* 24.0 MHz */
break;
case 0x5f: /* Atom Denverton */
i5-10210U 000806EC 06-8e-0c CML-U42
http://users.atw.hu/instlatx64/GenuineIntel/GenuineIntel00806EC_CometLake_CPUID2.txt
CPUID 00000015: 00000002-000000B0-00000000-00000000 [88.00x / 0]
CPUID 00000016: 00000834-00001068-00000064-00000000 [2100 / 4200 / 100]
i7-10710U 000A0660 06-a6-00 CML-U62
http://users.atw.hu/instlatx64/GenuineIntel/GenuineIntel00A0660_CometLake_CPUID1.txt
CPUID 00000015: 00000002-00000086-00000000-00000000 [67.00x / 0]
CPUID 00000016: 00000640-0000125C-00000064-00000000 [1600 / 4700 / 100]
i5-10600K 000A0655 06-a5-05 CML-S102
http://users.atw.hu/instlatx64/GenuineIntel/GenuineIntel00A0655_CometLake_CPUID3.txt
CPUID 00000015: 00000002-00000156-00000000-00000000 [171 / 0]
CPUID 00000016: 00000000-00000000-00000000-00000000 [0 / 0 / 0]
---
i3-8121U 00060663 06-66-03 CNL-U
http://users.atw.hu/instlatx64/GenuineIntel/GenuineIntel0060663_CannonLake_CPUID2.txt
CPUID 00000015: 00000002-000000B8-016E3600-00000000 [92.00x / 24000000]
CPUID 00000016: 00000898-00000C80-00000064-00000000 [2200 / 3200 / 100]
i5-1035G4 000706E5 06-7e-05 ICL-U/Y
http://users.atw.hu/instlatx64/GenuineIntel/GenuineIntel00706E5_IceLakeY_CPUID2.txt
CPUID 00000015: 00000002-0000004E-0249F000-00000000 [39.00x / 38400000]
CPUID 00000016: 000005DC-00000E74-00000064-00000000 [1500 / 3700 / 100]
i5-1135G7 000806C1 06-8c-01 TGL
http://users.atw.hu/instlatx64/GenuineIntel/GenuineIntel00806C1_TigerLake_CPUID.txt
CPUID 00000015: 00000002-0000007E-0249F000-00000000 [63.00x / 38400000]
CPUID 00000016: 00000960-00001068-00000064-00000000 [2400 / 4200 / 100]