Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1JzpvK-0004B1-Qu for mharc-grub-devel@gnu.org; Sat, 24 May 2008 05:20:22 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JzpvH-00049x-IG for grub-devel@gnu.org; Sat, 24 May 2008 05:20:19 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JzpvE-000497-Md for grub-devel@gnu.org; Sat, 24 May 2008 05:20:18 -0400 Received: from [199.232.76.173] (port=40595 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JzpvE-000494-6S for grub-devel@gnu.org; Sat, 24 May 2008 05:20:16 -0400 Received: from smtp-vbr3.xs4all.nl ([194.109.24.23]:4589) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1JzpvD-0008Mv-JC for grub-devel@gnu.org; Sat, 24 May 2008 05:20:15 -0400 Received: from localhost.localdomain (249-174.surfsnel.dsl.internl.net [145.99.174.249]) by smtp-vbr3.xs4all.nl (8.13.8/8.13.8) with ESMTP id m4O9KBJD038259 for ; Sat, 24 May 2008 11:20:12 +0200 (CEST) (envelope-from mgerards@xs4all.nl) From: Marco Gerards To: The development of GRUB 2 References: <20080512093354.2770e1cf@gibibit.com> <20080520104646.18dfaf47@gibibit.com> <87bq2x8cba.fsf@xs4all.nl> <20080523072844.3189b53a@gibibit.com> Mail-Copies-To: mgerards@xs4all.nl Date: Sat, 24 May 2008 11:23:14 +0200 In-Reply-To: <20080523072844.3189b53a@gibibit.com> (Colin D. Bennett's message of "Fri, 23 May 2008 07:28:44 -0700") Message-ID: <87iqx4awe5.fsf@xs4all.nl> User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by XS4ALL Virus Scanner X-detected-kernel: by monty-python.gnu.org: FreeBSD 4.6-4.9 Subject: Re: Higher resolution timers X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 24 May 2008 09:20:20 -0000 Colin D Bennett writes: > On Fri, 23 May 2008 13:55:21 +0200 > Marco Gerards wrote: > >> Colin D Bennett writes: >> >> > On Mon, 12 May 2008 09:33:54 -0700 >> > Colin D Bennett wrote: >> > >> >> I think that using the TSC (w/ RDTSC instruction) and calibrating >> >> it with a quick 2-3 RTC tick loop at startup might be the easiest >> >> option. >> > >> > Just wondered if something like this would be a practical way to go: >> >> Well, I only had a quick look and this might be a good way to measure >> the clock speed. BTW, can you please make sure you use our coding >> style? Are the 2-3 loops based on some calculations or only a guess? > > Of course I will adhere to the GRUB coding style. The snippet I posted > was just basically just quick pseudocode (not actually compiled) based > on 10 minutes of thought. I did not take time to format the code style > but surely I would before submitting an actual patch. Great. I hope you didn't mind that I asked. I always feel evil after asking this question when someone sends in a great amount of code, so I rather ask it now :-) > I think we only need 1 full RTC timer tick (i.e. 1/18 of a > second) to figure out how many TSC cycles correspond to one second of > real time. The code has to first synchronize to the starting edge of > an RTC tick, so that is the loop: > do { ... } while (start_tick == initial_tick); > Then the number of elapsed TSC cycles until the next RTC tick is > calculated and the TSC cycles per second is calculated. I agree! :-) > (As I said, this is untested and incomplete scratch work as a starting > point for a discussion, and it might not even compile.) It's perfectly clear for discussion. >> There might be a problem with using this instruction. Are clock >> cycles actually measured after using the "halt" instruction? If not, >> the use of such instruction might not generally used in GRUB :-/ > > Thanks for thinking of that. According to > , the TSC > continues counting even when the CPU executes the HLT instruction: > > The TSC is set to 0 at system reset. It presently increments once per > processor cycle, and is 64 bits wide. Only CPL = 0 can modify TSC, > and then only the lower 32 bits can be set, while the upper 32 bits > are cleared. We do not recommend changing TSC, and the library does > not permit it. The TSC will continue to increment in the halt state > (HLT instruction). > > Therefore, I think that that the HLT instruction in GRUB will not > negatively impact the use of RDTSC. Great! Will you keep in mind that we have to switch back the RTC in case this instruction is not available? In that case this patch will not work perfectly on older hardware, but it will at least not crash the computer. -- Marco