All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexandre Boeglin <alex@boeglin.org>
To: grub-devel@gnu.org
Subject: Re: [PATCH] fix GRUB_TICKS_PER_SECOND in include/grub/efi/time.h
Date: Thu, 21 Feb 2008 19:53:48 +0100	[thread overview]
Message-ID: <20080221185348.GA6558@boeglin.org> (raw)
In-Reply-To: <20080217145514.GA10562@boeglin.org>

[-- Attachment #1: Type: text/plain, Size: 684 bytes --]

Le dim 17 fév 2008 à 15:55:14 +0100, Alexandre Boeglin a écrit :
> This one seems to work (returning unix time), but I don't know if it's
> acceptable.

Hi, here is the candidate for inclusion, including Changelog.

It has a resolution of 1 second, which is OK I think, as afaik grub_get_rtc is
only used to display timeout counters.

And my machine, for example, does not even report more precise information
(the struct returned by the EFI call has a nanosecond member, but it's content
is always 0) ...

And for more precise time related operations, EFI offers a stall() call, which
takes a number of microseconds as a parameters, IIRC.


Any objection ?

Alex

[-- Attachment #2: grub2_efitime.patch --]
[-- Type: text/x-diff, Size: 3214 bytes --]

Index: ChangeLog
===================================================================
RCS file: /sources/grub/grub2/ChangeLog,v
retrieving revision 1.596
diff -u -p -r1.596 ChangeLog
--- ChangeLog	19 Feb 2008 19:52:41 -0000	1.596
+++ ChangeLog	21 Feb 2008 18:43:57 -0000
@@ -1,3 +1,10 @@
+2008-02-21  Alexandre Boeglin  <alex@boeglin.org>
+
+	* kern/efi/efi.c (grub_get_rtc): New implementation that returns POSIX time.
+
+	* include/grub/efi/time.h (GRUB_TICKS_PER_SECOND): POSIX time has a
+	resolution of 1 second.
+
 2008-02-19  Pavel Roskin  <proski@gnu.org>
 
 	* kern/rescue.c (grub_enter_rescue_mode): Improve initial
Index: include/grub/efi/time.h
===================================================================
RCS file: /sources/grub/grub2/include/grub/efi/time.h,v
retrieving revision 1.2
diff -u -p -r1.2 time.h
--- include/grub/efi/time.h	21 Jul 2007 23:32:23 -0000	1.2
+++ include/grub/efi/time.h	21 Feb 2008 18:43:57 -0000
@@ -1,6 +1,6 @@
 /*
  *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 2006,2007  Free Software Foundation, Inc.
+ *  Copyright (C) 2006,2007,2008  Free Software Foundation, Inc.
  *
  *  GRUB is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -21,8 +21,7 @@
 
 #include <grub/symbol.h>
 
-/* This is destined to overflow when one minute passes by.  */
-#define GRUB_TICKS_PER_SECOND	((1UL << 31) / 60 / 60 * 2)
+#define GRUB_TICKS_PER_SECOND	1
 
 /* Return the real time in ticks.  */
 grub_uint32_t EXPORT_FUNC (grub_get_rtc) (void);
Index: kern/efi/efi.c
===================================================================
RCS file: /sources/grub/grub2/kern/efi/efi.c,v
retrieving revision 1.10
diff -u -p -r1.10 efi.c
--- kern/efi/efi.c	12 Feb 2008 23:47:07 -0000	1.10
+++ kern/efi/efi.c	21 Feb 2008 18:43:57 -0000
@@ -194,15 +194,46 @@ grub_get_rtc (void)
 {
   grub_efi_time_t time;
   grub_efi_runtime_services_t *r;
+  grub_uint32_t rtc_time;
+  grub_uint16_t cur_year;
 
   r = grub_efi_system_table->runtime_services;
   if (r->get_time (&time, 0) != GRUB_EFI_SUCCESS)
     /* What is possible in this case?  */
     return 0;
 
-  return (((time.minute * 60 + time.second) * 1000
-	   + time.nanosecond / 1000000)
-	  * GRUB_TICKS_PER_SECOND / 1000);
+  rtc_time = 0;
+  for (cur_year = time.year - 1; cur_year >= 1970; cur_year--)
+    {
+      if (!(cur_year % 400) || ((cur_year % 100) && !(cur_year % 4)))
+	rtc_time += 366;
+      else
+	rtc_time += 365;
+    }
+  /* Months have 30 days by default.  */
+  rtc_time += (time.month - 1) * 30;
+  /* February has fewer days.  */
+  if (time.month > 2)
+    {
+      if (!(time.year % 400) || ((time.year % 100) && !(time.year % 4)))
+	rtc_time -= 1;
+      else
+	rtc_time -= 2;
+    }
+  /* Odd months have 31 days.  */
+  rtc_time += time.month / 2;
+  /* August also has 31 days.  */
+  if (time.month == 9 || time.month == 11)
+    rtc_time += 1;
+  rtc_time += (time.day - 1);
+  rtc_time *= 24;
+  rtc_time += time.hour;
+  rtc_time *= 60;
+  rtc_time += time.minute;
+  rtc_time *= 60;
+  rtc_time += time.second;
+
+  return rtc_time;
 }
 
 /* Search the mods section from the PE32/PE32+ image. This code uses

  reply	other threads:[~2008-02-21 18:52 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-17 11:52 [PATCH] fix GRUB_TICKS_PER_SECOND in include/grub/efi/time.h Alexandre Boeglin
2008-02-17 12:15 ` Alexandre Boeglin
2008-02-17 14:55   ` Alexandre Boeglin
2008-02-21 18:53     ` Alexandre Boeglin [this message]
2008-02-21 21:16       ` Yoshinori K. Okuji
2008-02-21 21:08 ` Yoshinori K. Okuji
2008-02-22  7:49   ` Alexandre Boeglin
2008-02-22  8:24     ` Yoshinori K. Okuji
2008-02-29 12:52       ` Alexandre Boeglin
2008-03-01 17:30         ` Yoshinori K. Okuji

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080221185348.GA6558@boeglin.org \
    --to=alex@boeglin.org \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.