From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1Iir7z-0005XS-Bx for mharc-grub-devel@gnu.org; Fri, 19 Oct 2007 08:38:59 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Iir7y-0005VR-0f for grub-devel@gnu.org; Fri, 19 Oct 2007 08:38:58 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Iir7w-0005Ts-R8 for grub-devel@gnu.org; Fri, 19 Oct 2007 08:38:57 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Iir7w-0005TZ-H0 for grub-devel@gnu.org; Fri, 19 Oct 2007 08:38:56 -0400 Received: from aybabtu.com ([69.60.117.155]) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Iir7v-0003dM-Lt for grub-devel@gnu.org; Fri, 19 Oct 2007 08:38:56 -0400 Received: from [192.168.10.6] (helo=thorin) by aybabtu.com with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.63) (envelope-from ) id 1Iir7p-0005dx-Jw for grub-devel@gnu.org; Fri, 19 Oct 2007 14:38:53 +0200 Received: from rmh by thorin with local (Exim 4.63) (envelope-from ) id 1Iir7J-0005KZ-VT for grub-devel@gnu.org; Fri, 19 Oct 2007 14:38:17 +0200 Date: Fri, 19 Oct 2007 14:38:17 +0200 From: Robert Millan To: The development of GRUB 2 Message-ID: <20071019123817.GA20469@thorin> References: <20071015143857.GA26571@thorin> <87wstnqhdb.fsf@xs4all.nl> <20071016183420.GA4335@thorin> <87odeyrj7r.fsf@xs4all.nl> <20071016200647.GA13827@thorin> <873awaqbci.fsf@xs4all.nl> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="pf9I7BMVVzbSWLtt" Content-Disposition: inline In-Reply-To: <873awaqbci.fsf@xs4all.nl> Organization: free as in freedom X-Message-Flag: Microsoft discourages use of Outlook. X-Debbugs-No-Ack: true User-Agent: Mutt/1.5.13 (2006-08-11) X-detected-kernel: by monty-python.gnu.org: Genre and OS details not recognized. Subject: Re: [PATCH] Implement grub_sleep() and grub_ticksleep() 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: Fri, 19 Oct 2007 12:38:58 -0000 --pf9I7BMVVzbSWLtt Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Oct 17, 2007 at 12:33:49PM +0200, Marco Gerards wrote: > > * kern/i386/efi/init.c: Include `grub/time.h'. > > is preferred. Fixed. > > +void > > +grub_millisleep_generic (grub_uint32_t ms) > > +{ > > + grub_uint32_t time; > > + int i; > > + > > + for (; ms > 0; ms -= TICK_DURATION_IN_MS) > > + /* wait for the lowest fraction of milliseconds we can (rounded up) */ > > + for (i = 0; i < TICK_DURATION_IN_MS; i++) > > + { > > + /* wait for next tick */ > > + time = grub_get_rtc (); > > + while (time == grub_get_rtc ()) > > + grub_cpu_idle (); > > + } > > +} > > The problem with this is when TICK_DURATION_IN_MS is not very > accurate. I think you can be more accurate if you use > TICKS_PER_SECOND and use it to calculate the total amount of ticks to > wait. This will avoid rounding problems. Accuracy is not always that > important, but I prefer to have it, if we can. Fixed, I think. Attached new patch. -- Robert Millan I know my rights; I want my phone call! What use is a phone call, if you are unable to speak? (as seen on /.) --pf9I7BMVVzbSWLtt Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="time.diff" 2007-10-19 Robert Millan * include/grub/time.h: New file. * include/grub/i386/time.h: Likewise. * include/grub/powerpc/time.h: Likewise. * include/grub/sparc64/time.h: Likewise. * include/grub/i386/pc/time.h (KERNEL_TIME_HEADER): Rename all instances to ... (KERNEL_MACHINE_TIME_HEADER): ... this. * include/grub/powerpc/ieee1275/time.h (KERNEL_TIME_HEADER): Rename all instances to ... (KERNEL_MACHINE_TIME_HEADER): ... this. * include/grub/sparc64/ieee1275/time.h (KERNEL_TIME_HEADER): Rename all instances to ... (KERNEL_MACHINE_TIME_HEADER): ... this. * kern/i386/efi/init.c: Include `'. (grub_millisleep): New function. * kern/i386/pc/init.c: Include `'. (grub_millisleep): New function. * kern/powerpc/ieee1275/init.c: Include `'. Remove `grub/machine/time.h' include. (grub_millisleep): New function. * kern/sparc64/ieee1275/init.c: Include `'. Remove `grub/machine/time.h' include. (grub_millisleep): New function. * include/grub/misc.h (grub_div_roundup): New function. * kern/misc.c: Include `'. (grub_millisleep_generic): New function. diff -Nurp grub2/include/grub/i386/pc/time.h grub2.time/include/grub/i386/pc/time.h --- grub2/include/grub/i386/pc/time.h 2007-07-22 01:32:24.000000000 +0200 +++ grub2.time/include/grub/i386/pc/time.h 2007-10-19 13:58:55.000000000 +0200 @@ -16,8 +16,8 @@ * along with GRUB. If not, see . */ -#ifndef KERNEL_TIME_HEADER -#define KERNEL_TIME_HEADER 1 +#ifndef KERNEL_MACHINE_TIME_HEADER +#define KERNEL_MACHINE_TIME_HEADER 1 #include @@ -26,4 +26,4 @@ /* Return the real time in ticks. */ grub_uint32_t EXPORT_FUNC (grub_get_rtc) (void); -#endif /* ! KERNEL_TIME_HEADER */ +#endif /* ! KERNEL_MACHINE_TIME_HEADER */ diff -Nurp grub2/include/grub/i386/time.h grub2.time/include/grub/i386/time.h --- grub2/include/grub/i386/time.h 1970-01-01 01:00:00.000000000 +0100 +++ grub2.time/include/grub/i386/time.h 2007-10-19 13:58:55.000000000 +0200 @@ -0,0 +1,28 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2007 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef KERNEL_CPU_TIME_HEADER +#define KERNEL_CPU_TIME_HEADER 1 + +static __inline void +grub_cpu_idle () +{ + __asm__ __volatile__ ("hlt"); +} + +#endif /* ! KERNEL_CPU_TIME_HEADER */ diff -Nurp grub2/include/grub/misc.h grub2.time/include/grub/misc.h --- grub2/include/grub/misc.h 2007-07-22 01:32:22.000000000 +0200 +++ grub2.time/include/grub/misc.h 2007-10-19 14:19:53.000000000 +0200 @@ -83,6 +83,7 @@ grub_uint64_t EXPORT_FUNC(grub_divmod64) grub_uint32_t d, grub_uint32_t *r); /* Inline functions. */ + static inline unsigned int grub_abs (int x) { @@ -92,4 +93,11 @@ grub_abs (int x) return (unsigned int) x; } +/* Rounded-up division */ +static inline unsigned int +grub_div_roundup (unsigned int x, unsigned int y) +{ + return (x + (y - 1) / y); +} + #endif /* ! GRUB_MISC_HEADER */ diff -Nurp grub2/include/grub/powerpc/ieee1275/time.h grub2.time/include/grub/powerpc/ieee1275/time.h --- grub2/include/grub/powerpc/ieee1275/time.h 2007-07-22 01:32:24.000000000 +0200 +++ grub2.time/include/grub/powerpc/ieee1275/time.h 2007-10-19 13:58:55.000000000 +0200 @@ -16,8 +16,8 @@ * along with GRUB. If not, see . */ -#ifndef KERNEL_TIME_HEADER -#define KERNEL_TIME_HEADER 1 +#ifndef KERNEL_MACHINE_TIME_HEADER +#define KERNEL_MACHINE_TIME_HEADER 1 #include @@ -26,4 +26,4 @@ /* Return the real time in ticks. */ grub_uint32_t EXPORT_FUNC (grub_get_rtc) (void); -#endif /* ! KERNEL_TIME_HEADER */ +#endif /* ! KERNEL_MACHINE_TIME_HEADER */ diff -Nurp grub2/include/grub/powerpc/time.h grub2.time/include/grub/powerpc/time.h --- grub2/include/grub/powerpc/time.h 1970-01-01 01:00:00.000000000 +0100 +++ grub2.time/include/grub/powerpc/time.h 2007-10-19 13:58:55.000000000 +0200 @@ -0,0 +1,28 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2007 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef KERNEL_CPU_TIME_HEADER +#define KERNEL_CPU_TIME_HEADER 1 + +static __inline void +grub_cpu_idle () +{ + /* FIXME: not implemented */ +} + +#endif /* ! KERNEL_CPU_TIME_HEADER */ diff -Nurp grub2/include/grub/sparc64/ieee1275/time.h grub2.time/include/grub/sparc64/ieee1275/time.h --- grub2/include/grub/sparc64/ieee1275/time.h 2007-07-22 01:32:25.000000000 +0200 +++ grub2.time/include/grub/sparc64/ieee1275/time.h 2007-10-19 13:58:55.000000000 +0200 @@ -16,8 +16,8 @@ * along with GRUB. If not, see . */ -#ifndef KERNEL_TIME_HEADER -#define KERNEL_TIME_HEADER 1 +#ifndef KERNEL_MACHINE_TIME_HEADER +#define KERNEL_MACHINE_TIME_HEADER 1 #include @@ -26,4 +26,4 @@ /* Return the real time in ticks. */ grub_uint32_t EXPORT_FUNC (grub_get_rtc) (void); -#endif /* ! KERNEL_TIME_HEADER */ +#endif /* ! KERNEL_MACHINE_TIME_HEADER */ diff -Nurp grub2/include/grub/sparc64/time.h grub2.time/include/grub/sparc64/time.h --- grub2/include/grub/sparc64/time.h 1970-01-01 01:00:00.000000000 +0100 +++ grub2.time/include/grub/sparc64/time.h 2007-10-19 13:58:55.000000000 +0200 @@ -0,0 +1,28 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2007 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef KERNEL_CPU_TIME_HEADER +#define KERNEL_CPU_TIME_HEADER 1 + +static __inline void +grub_cpu_idle () +{ + /* FIXME: not implemented */ +} + +#endif /* ! KERNEL_CPU_TIME_HEADER */ diff -Nurp grub2/include/grub/time.h grub2.time/include/grub/time.h --- grub2/include/grub/time.h 1970-01-01 01:00:00.000000000 +0100 +++ grub2.time/include/grub/time.h 2007-10-19 13:59:36.000000000 +0200 @@ -0,0 +1,35 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2007 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef KERNEL_TIME_HEADER +#define KERNEL_TIME_HEADER 1 + +#include +#include +#include + +void EXPORT_FUNC(grub_millisleep) (grub_uint32_t ms); +void EXPORT_FUNC(grub_millisleep_generic) (grub_uint32_t ms); + +static __inline void +grub_sleep (grub_uint32_t s) +{ + grub_millisleep (1000 * s); +} + +#endif /* ! KERNEL_TIME_HEADER */ diff -Nurp grub2/kern/i386/efi/init.c grub2.time/kern/i386/efi/init.c --- grub2/kern/i386/efi/init.c 2007-07-22 01:32:27.000000000 +0200 +++ grub2.time/kern/i386/efi/init.c 2007-10-19 13:58:55.000000000 +0200 @@ -25,6 +25,13 @@ #include #include #include +#include + +void +grub_millisleep (grub_uint32_t ms) +{ + grub_millisleep_generic (ms); +} void grub_machine_init (void) diff -Nurp grub2/kern/i386/pc/init.c grub2.time/kern/i386/pc/init.c --- grub2/kern/i386/pc/init.c 2007-09-07 23:55:26.000000000 +0200 +++ grub2.time/kern/i386/pc/init.c 2007-10-19 13:58:55.000000000 +0200 @@ -30,6 +30,7 @@ #include #include #include +#include struct mem_region { @@ -46,6 +47,12 @@ grub_addr_t grub_os_area_addr; grub_size_t grub_os_area_size; grub_size_t grub_lower_mem, grub_upper_mem; +void +grub_millisleep (grub_uint32_t ms) +{ + grub_millisleep_generic (ms); +} + void grub_arch_sync_caches (void *address __attribute__ ((unused)), grub_size_t len __attribute__ ((unused))) diff -Nurp grub2/kern/misc.c grub2.time/kern/misc.c --- grub2/kern/misc.c 2007-08-02 22:42:19.000000000 +0200 +++ grub2.time/kern/misc.c 2007-10-19 14:31:36.000000000 +0200 @@ -23,6 +23,7 @@ #include #include #include +#include void * grub_memmove (void *dest, const void *src, grub_size_t n) @@ -1041,6 +1042,17 @@ grub_utf8_to_ucs4 (grub_uint32_t *dest, return p - dest; } +void +grub_millisleep_generic (grub_uint32_t ms) +{ + grub_uint32_t end_at; + + end_at = grub_get_rtc () + grub_div_roundup (ms * GRUB_TICKS_PER_SECOND, 1000); + + while (grub_get_rtc () < end_at) + grub_cpu_idle (); +} + /* Abort GRUB. This function does not return. */ void grub_abort (void) diff -Nurp grub2/kern/powerpc/ieee1275/init.c grub2.time/kern/powerpc/ieee1275/init.c --- grub2/kern/powerpc/ieee1275/init.c 2007-10-12 12:22:27.000000000 +0200 +++ grub2.time/kern/powerpc/ieee1275/init.c 2007-10-19 13:58:55.000000000 +0200 @@ -27,8 +27,8 @@ #include #include #include +#include #include -#include #include #include #include @@ -47,6 +47,12 @@ extern char _start[]; extern char _end[]; void +grub_millisleep (grub_uint32_t ms) +{ + grub_millisleep_generic (ms); +} + +void grub_exit (void) { /* Trap to Open Firmware. */ diff -Nurp grub2/kern/sparc64/ieee1275/init.c grub2.time/kern/sparc64/ieee1275/init.c --- grub2/kern/sparc64/ieee1275/init.c 2007-07-22 01:32:28.000000000 +0200 +++ grub2.time/kern/sparc64/ieee1275/init.c 2007-10-19 13:58:55.000000000 +0200 @@ -27,8 +27,8 @@ #include #include #include +#include #include -#include #include #include #include @@ -66,6 +66,12 @@ _start (uint64_t r0 __attribute__((unuse /* Never reached. */ } +void +grub_millisleep (grub_uint32_t ms) +{ + grub_millisleep_generic (ms); +} + int grub_ieee1275_test_flag (enum grub_ieee1275_flag flag) { --pf9I7BMVVzbSWLtt--