From owner-freebsd-stable@freebsd.org Sat Feb 13 17:02:51 2016 Return-Path: Delivered-To: freebsd-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 923BFAA6B02 for ; Sat, 13 Feb 2016 17:02:51 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 1212F1597 for ; Sat, 13 Feb 2016 17:02:50 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.15.2/8.15.2) with ESMTPS id u1DH2eVm015308 (version=TLSv1 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Sat, 13 Feb 2016 19:02:40 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua u1DH2eVm015308 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id u1DH2doh015307; Sat, 13 Feb 2016 19:02:39 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Sat, 13 Feb 2016 19:02:39 +0200 From: Konstantin Belousov To: Mark Dixon Cc: freebsd-stable@freebsd.org Subject: Re: Is UEFI required for ZFS? Message-ID: <20160213170239.GD91220@kib.kiev.ua> References: <56BDFAA4.17139.1EEE35@lausts.acm.org> <20160212185659.GC26283@home.opsec.eu> <20160213100936.GY91220@kib.kiev.ua> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on tom.home X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 13 Feb 2016 17:02:51 -0000 On Sat, Feb 13, 2016 at 03:46:16PM +0000, Mark Dixon wrote: > I don't think I can clock it down, although the UEFI bios screens are > massively confusing so I could be wrong. > > Verbose dmesg: Might be, try the following (mostly debugging) change. diff --git a/sys/boot/i386/libi386/time.c b/sys/boot/i386/libi386/time.c index c27dcf6..592d64a 100644 --- a/sys/boot/i386/libi386/time.c +++ b/sys/boot/i386/libi386/time.c @@ -97,8 +97,8 @@ time(time_t *t) * Resolution of this function is variable, but typically around * 1ms. */ -void -delay(int period) +static void +delay_bios(int period) { v86.ctl = 0; v86.addr = 0x15; /* int 0x15, function 0x86 */ @@ -107,3 +107,53 @@ delay(int period) v86.edx = period & 0xffff; v86int(); } + +static uint64_t rd; + +static __inline uint64_t +rdtsc(void) +{ + uint64_t rv; + + __asm __volatile("rdtsc" : "=A" (rv)); + return (rv); +} + +static void +delay_rdtsc_calibrate(void) +{ + int x1, x2; + uint64_t s, f; + + for (x1 = bios_seconds(); x1 == (x2 = bios_seconds());) + ; + s = rdtsc(); + for (; x2 == (x1 = bios_seconds());) + ; + f = rdtsc(); + rd = f - s; + printf("rd %llx\n", rd); +} + +static void +delay_rdtsc(int period) +{ + uint64_t x; + + x = rdtsc() + rd / 1000000; + while (rdtsc() < x) + ; +} + +void +delay(int period) +{ + + if (0) { + delay_bios(period); + } else { + if (rd == 0) + delay_rdtsc_calibrate(); + delay_rdtsc(period); + } +}