From 7e45abcef494874f83923fdcd9e382c6cad2b214 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 15 Oct 2013 13:13:53 +0200 Subject: [PATCH] Move cpu time retrieval to separate grub_util_get_cpu_time_ms and remove export.h. --- ChangeLog | 5 +++++ grub-core/Makefile.am | 1 - grub-core/Makefile.core.def | 3 +++ grub-core/osdep/cputime.c | 5 +++++ grub-core/osdep/unix/cputime.c | 15 +++++++++++++++ grub-core/osdep/windows/cputime.c | 19 +++++++++++++++++++ grub-core/tests/video_checksum.c | 9 +-------- include/grub/emu/export.h | 7 ------- include/grub/emu/misc.h | 2 ++ 9 files changed, 50 insertions(+), 16 deletions(-) create mode 100644 grub-core/osdep/cputime.c create mode 100644 grub-core/osdep/unix/cputime.c create mode 100644 grub-core/osdep/windows/cputime.c delete mode 100644 include/grub/emu/export.h diff --git a/ChangeLog b/ChangeLog index 5aa1e8630..f650689c2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2013-10-15 Vladimir Serbinenko + + Move cpu time retrieval to separate grub_util_get_cpu_time_ms + and remove export.h. + 2013-10-15 Vladimir Serbinenko * grub-core/kern/emu/error.c: Removed. diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am index 630b866ee..c0ceb216f 100644 --- a/grub-core/Makefile.am +++ b/grub-core/Makefile.am @@ -217,7 +217,6 @@ endif if COND_emu KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/datetime.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/misc.h -KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/export.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/net.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/hostdisk.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 9bdb2bec1..8751adff8 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -258,6 +258,9 @@ kernel = { emu = osdep/emunet.c; extra_dist = osdep/linux/emunet.c; extra_dist = osdep/basic/emunet.c; + emu = osdep/cputime.c; + extra_dist = osdep/unix/cputime.c; + extra_dist = osdep/windows/cputime.c; videoinkernel = term/gfxterm.c; videoinkernel = font/font.c; diff --git a/grub-core/osdep/cputime.c b/grub-core/osdep/cputime.c new file mode 100644 index 000000000..d3ee4c865 --- /dev/null +++ b/grub-core/osdep/cputime.c @@ -0,0 +1,5 @@ +#ifdef __MINGW32__ +#include "windows/cputime.c" +#else +#include "unix/cputime.c" +#endif diff --git a/grub-core/osdep/unix/cputime.c b/grub-core/osdep/unix/cputime.c new file mode 100644 index 000000000..47e3abc77 --- /dev/null +++ b/grub-core/osdep/unix/cputime.c @@ -0,0 +1,15 @@ +#include +#include + +#include +#include +#include + +grub_uint64_t +grub_util_get_cpu_time_ms (void) +{ + struct tms tm; + + times (&tm); + return (tm.tms_utime * 1000ULL) / sysconf(_SC_CLK_TCK); +} diff --git a/grub-core/osdep/windows/cputime.c b/grub-core/osdep/windows/cputime.c new file mode 100644 index 000000000..3568aa2d3 --- /dev/null +++ b/grub-core/osdep/windows/cputime.c @@ -0,0 +1,19 @@ +#include +#include + +#include +#include + +grub_uint64_t +grub_util_get_cpu_time_ms (void) +{ + FILETIME cr, ex, ke, us; + ULARGE_INTEGER us_ul; + + GetProcessTimes (GetCurrentProcess (), &cr, &ex, &ke, &us); + us_ul.LowPart = us.dwLowDateTime; + us_ul.HighPart = us.dwHighDateTime; + + return us_ul.QuadPart / 10000; +} + diff --git a/grub-core/tests/video_checksum.c b/grub-core/tests/video_checksum.c index 33b32c051..865266f9f 100644 --- a/grub-core/tests/video_checksum.c +++ b/grub-core/tests/video_checksum.c @@ -485,11 +485,6 @@ grub_util_fd_t genfd = GRUB_UTIL_FD_INVALID; #include -#if defined (GRUB_MACHINE_EMU) && defined (COLLECT_TIME_STATISTICS) -#include -#include -#endif - static void write_time (void) { @@ -498,13 +493,11 @@ write_time (void) static grub_uint64_t prev; grub_uint64_t cur; static grub_util_fd_t tmrfd = GRUB_UTIL_FD_INVALID; - struct tms tm; if (!GRUB_UTIL_FD_IS_VALID (tmrfd)) tmrfd = grub_util_fd_open ("time.txt", GRUB_UTIL_FD_O_WRONLY | GRUB_UTIL_FD_O_CREATTRUNC); - times (&tm); - cur = (tm.tms_utime * 1000ULL) / sysconf(_SC_CLK_TCK); + cur = grub_util_get_cpu_time_ms (); grub_snprintf (buf, sizeof (buf), "%s_%dx%dx%s:%d: %" PRIuGRUB_UINT64_T " ms\n", basename, capt_mode_info.width, diff --git a/include/grub/emu/export.h b/include/grub/emu/export.h deleted file mode 100644 index bdeb10f9d..000000000 --- a/include/grub/emu/export.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifdef GRUB_SYMBOL_GENERATOR -void EXPORT_FUNC (sysconf) (void); -void EXPORT_FUNC (times) (void); -#else -#include -#include -#endif diff --git a/include/grub/emu/misc.h b/include/grub/emu/misc.h index 004ee5bfb..21b83e87c 100644 --- a/include/grub/emu/misc.h +++ b/include/grub/emu/misc.h @@ -50,6 +50,8 @@ void EXPORT_FUNC(grub_util_warn) (const char *fmt, ...) __attribute__ ((format ( void EXPORT_FUNC(grub_util_info) (const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); void EXPORT_FUNC(grub_util_error) (const char *fmt, ...) __attribute__ ((format (printf, 1, 2), noreturn)); +grub_uint64_t EXPORT_FUNC (grub_util_get_cpu_time_ms) (void); + extern char * canonicalize_file_name (const char *path); #ifdef HAVE_DEVICE_MAPPER