From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1Xtcyp-0005e9-2O for mharc-grub-devel@gnu.org; Wed, 26 Nov 2014 08:50:03 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40484) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xtcyi-0005d2-SY for grub-devel@gnu.org; Wed, 26 Nov 2014 08:50:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xtcye-0000Hx-1U for grub-devel@gnu.org; Wed, 26 Nov 2014 08:49:56 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58337) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xtcyd-0000Ht-Qz for grub-devel@gnu.org; Wed, 26 Nov 2014 08:49:51 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sAQDno64007205 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 26 Nov 2014 08:49:50 -0500 Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-63.ams2.redhat.com [10.36.116.63]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id sAQDnj8Z011879; Wed, 26 Nov 2014 08:49:47 -0500 Message-ID: <5475DA79.4070107@redhat.com> Date: Wed, 26 Nov 2014 14:49:45 +0100 From: Laszlo Ersek User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: Andrei Borzenkov , The development of GNU GRUB Subject: Re: [PATCH] calibrate_tsc(): use the Stall() EFI boot service on GRUB_MACHINE_EFI References: <1416992361-4167-1-git-send-email-lersek@redhat.com> In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: vkuznets@redhat.com, decui@microsoft.com X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Nov 2014 13:50:02 -0000 On 11/26/14 14:42, Andrei Borzenkov wrote: > On Wed, Nov 26, 2014 at 11:59 AM, Laszlo Ersek wrote: >> HyperV Gen2 virtual machines have no PIT; guest code should rely on UEFI >> services instead. >> > > Your patch affects all EFI systems; Which is intended -- No UEFI system guarantees the presence of the PIT, but they are all required to provide the gBS->Stall() boot service. So, the current PIT-based code may or may not work on a random UEFI system (and in fact it happens to fail in HyperV Gen2 guests, because those actually exploit the no-legacy liberty provided by the UEFI spec), but the proposed replacement (== rely on gBS->Stall()) *must* work on all UEFI systems. For example, the patch works on top of OVMF in a QEMU/KVM guest too (== different UEFI firmware implementation and different hypervisor). > is it possible to detect HyperV at > this level? Perhaps, but that should definitely not be done. Enlightenment is not the way to go about this. Thanks Laszlo >> RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=1150698 >> RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=1160128 >> Signed-off-by: Laszlo Ersek >> --- >> >> Notes: >> Please note that I'm not subscribed to the list. >> >> grub-core/kern/i386/tsc.c | 20 ++++++++++++++++---- >> 1 file changed, 16 insertions(+), 4 deletions(-) >> >> diff --git a/grub-core/kern/i386/tsc.c b/grub-core/kern/i386/tsc.c >> index 3a4cae6..e499648 100644 >> --- a/grub-core/kern/i386/tsc.c >> +++ b/grub-core/kern/i386/tsc.c >> @@ -26,9 +26,14 @@ >> #include >> #include >> #ifdef GRUB_MACHINE_XEN >> -#include >> +# include >> #else >> -#include >> +# ifdef GRUB_MACHINE_EFI >> +# include >> +# include >> +# else >> +# include >> +# endif >> #endif >> #include >> >> @@ -72,8 +77,14 @@ grub_cpu_is_tsc_supported (void) >> #ifndef GRUB_MACHINE_XEN >> >> static void >> -grub_pit_wait (grub_uint16_t tics) >> +grub_stall (grub_uint16_t tics) >> { >> +# ifdef GRUB_MACHINE_EFI >> + grub_uint64_t microseconds; >> + >> + microseconds = (grub_uint64_t)tics * 1000 * 1000 * 3 / 3579545; >> + efi_call_1 (grub_efi_system_table->boot_services->stall, microseconds); >> +# else >> /* Disable timer2 gate and speaker. */ >> grub_outb (grub_inb (GRUB_PIT_SPEAKER_PORT) >> & ~ (GRUB_PIT_SPK_DATA | GRUB_PIT_SPK_TMR2), >> @@ -97,6 +108,7 @@ grub_pit_wait (grub_uint16_t tics) >> grub_outb (grub_inb (GRUB_PIT_SPEAKER_PORT) >> & ~ (GRUB_PIT_SPK_DATA | GRUB_PIT_SPK_TMR2), >> GRUB_PIT_SPEAKER_PORT); >> +# endif >> } >> #endif >> >> @@ -119,7 +131,7 @@ calibrate_tsc (void) >> grub_uint64_t end_tsc; >> >> tsc_boot_time = grub_get_tsc (); >> - grub_pit_wait (0xffff); >> + grub_stall (0xffff); >> end_tsc = grub_get_tsc (); >> >> grub_tsc_rate = grub_divmod64 ((55ULL << 32), end_tsc - tsc_boot_time, 0); >> -- >> 1.8.3.1 >> >> >> _______________________________________________ >> Grub-devel mailing list >> Grub-devel@gnu.org >> https://lists.gnu.org/mailman/listinfo/grub-devel