Make enable of disk cache statistics code configurable.

* configure.ac: --enable-cache-stats added.
	* config.h.in (DISK_CACHE_STATS): New define.
	* grub-core/Makefile.core.def (cacheinfo): New command.
	* include/grub/disk.h(grub_disk_cache_get_performance): New function.
	* grub-core/commands/cacheinfo.c: New file.
	* grub-core/commands/minicmd.c (grub_rescue_cmd_info): Updated and
	moved to cacheinfo.c.
	* grub-core/kern/disk.c: Use DISK_CACHE_STATS to disable disk cache
	debug code.
	* include/grub/disk.h: Likewise.
This commit is contained in:
Szymon Janc 2010-10-06 19:57:01 +02:00
parent a61499a1c3
commit c5dc16905a
8 changed files with 106 additions and 23 deletions

View File

@ -1,3 +1,18 @@
2010-10-05 Szymon Janc <szymon@janc.net.pl>
Make enable of disk cache statistics code configurable.
* configure.ac: --enable-cache-stats added.
* config.h.in (DISK_CACHE_STATS): New define.
* grub-core/Makefile.core.def (cacheinfo): New command.
* include/grub/disk.h(grub_disk_cache_get_performance): New function.
* grub-core/commands/cacheinfo.c: New file.
* grub-core/commands/minicmd.c (grub_rescue_cmd_info): Updated and
moved to cacheinfo.c.
* grub-core/kern/disk.c: Use DISK_CACHE_STATS to disable disk cache
debug code.
* include/grub/disk.h: Likewise.
2010-10-02 Aleš Nesrsta <starous@volny.cz>
* include/grub/scsi.h:

View File

@ -32,6 +32,8 @@
#define NEED_ENABLE_EXECUTE_STACK @NEED_ENABLE_EXECUTE_STACK@
/* Define to 1 if GCC generates calls to __register_frame_info(). */
#define NEED_REGISTER_FRAME_INFO @NEED_REGISTER_FRAME_INFO@
/* Define to 1 to enable disk cache statistics. */
#define DISK_CACHE_STATS @DISK_CACHE_STATS@
#if defined(__i386__)
#define NESTED_FUNC_ATTR __attribute__ ((__regparm__ (1)))

View File

@ -669,6 +669,17 @@ AC_ARG_ENABLE([mm-debug],
[AC_DEFINE([MM_DEBUG], [1],
[Define to 1 if you enable memory manager debugging.])])
AC_ARG_ENABLE([cache-stats],
AS_HELP_STRING([--enable-cache-stats],
[enable disk cache statistics collection])])
if test x$enable_cache_stats = xyes; then
DISK_CACHE_STATS=1
else
DISK_CACHE_STATS=0
fi
AC_SUBST([DISK_CACHE_STATS])
AC_ARG_ENABLE([grub-emu-usb],
[AS_HELP_STRING([--enable-grub-emu-usb],
[build and install the `grub-emu' debugging utility with USB support (default=guessed)])])
@ -922,6 +933,7 @@ AM_CONDITIONAL([COND_HAVE_FONT_SOURCE], [test x$FONT_SOURCE != x])
AM_CONDITIONAL([COND_GRUB_PE2ELF], [test x$TARGET_OBJ2ELF != x])
AM_CONDITIONAL([COND_APPLE_CC], [test x$TARGET_APPLE_CC = x1])
AM_CONDITIONAL([COND_ENABLE_EFIEMU], [test x$enable_efiemu = xyes])
AM_CONDITIONAL([COND_ENABLE_CACHE_STATS], [test x$DISK_CACHE_STATS = x1])
AM_CONDITIONAL([COND_HAVE_ASM_USCORE], [test x$HAVE_ASM_USCORE = x1])
@ -983,6 +995,11 @@ echo With memory debugging: Yes
else
echo With memory debugging: No
fi
if [ x"$enable_cache_stats" = xyes ]; then
echo With disk cache statistics: Yes
else
echo With disk cache statistics: No
fi
if [ x"$efiemu_excuse" = x ]; then
echo efiemu runtime: Yes
else

View File

@ -1502,3 +1502,9 @@ module = {
common = commands/keylayouts.c;
enable = videomodules;
};
module = {
name = cacheinfo;
common = commands/cacheinfo.c;
condition = COND_ENABLE_CACHE_STATS;
};

View File

@ -0,0 +1,58 @@
/* cacheinfo.c - disk cache statistics */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2008,2010 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 <http://www.gnu.org/licenses/>.
*/
#include <grub/dl.h>
#include <grub/misc.h>
#include <grub/command.h>
#include <grub/i18n.h>
#include <grub/disk.h>
static grub_err_t
grub_rescue_cmd_info (struct grub_command *cmd __attribute__ ((unused)),
int argc __attribute__ ((unused)),
char *argv[] __attribute__ ((unused)))
{
unsigned long hits, misses;
grub_disk_cache_get_performance (&hits, &misses);
grub_printf ("Disk cache: hits = %lu, misses = %lu ", hits, misses);
if (hits + misses)
{
unsigned long ratio = hits * 10000 / (hits + misses);
grub_printf ("(%lu.%lu%%)\n", ratio / 100, ratio % 100);
}
else
grub_printf ("(N/A)\n");
return 0;
}
static grub_command_t cmd_cacheinfo;
GRUB_MOD_INIT(cacheinfo)
{
cmd_cacheinfo =
grub_register_command ("cacheinfo", grub_rescue_cmd_info,
0, N_("Get disk cache info."));
}
GRUB_MOD_FINI(cacheinfo)
{
grub_unregister_command (cmd_cacheinfo);
}

View File

@ -88,26 +88,6 @@ grub_mini_cmd_help (struct grub_command *cmd __attribute__ ((unused)),
return 0;
}
#if 0
static void
grub_rescue_cmd_info (void)
{
extern void grub_disk_cache_get_performance (unsigned long *,
unsigned long *);
unsigned long hits, misses;
grub_disk_cache_get_performance (&hits, &misses);
grub_printf ("Disk cache: hits = %u, misses = %u ", hits, misses);
if (hits + misses)
{
unsigned long ratio = hits * 10000 / (hits + misses);
grub_printf ("(%u.%u%%)\n", ratio / 100, ratio % 100);
}
else
grub_printf ("(N/A)\n");
}
#endif
/* dump ADDRESS [SIZE] */
static grub_err_t
grub_mini_cmd_dump (struct grub_command *cmd __attribute__ ((unused)),

View File

@ -50,7 +50,7 @@ grub_err_t (* grub_disk_ata_pass_through) (grub_disk_t,
struct grub_disk_ata_pass_through_parms *);
#if 0
#if DISK_CACHE_STATS
static unsigned long grub_disk_cache_hits;
static unsigned long grub_disk_cache_misses;
@ -123,13 +123,13 @@ grub_disk_cache_fetch (unsigned long dev_id, unsigned long disk_id,
&& cache->sector == sector)
{
cache->lock = 1;
#if 0
#if DISK_CACHE_STATS
grub_disk_cache_hits++;
#endif
return cache->data;
}
#if 0
#if DISK_CACHE_STATS
grub_disk_cache_misses++;
#endif

View File

@ -160,6 +160,11 @@ grub_err_t EXPORT_FUNC(grub_disk_write) (grub_disk_t disk,
grub_uint64_t EXPORT_FUNC(grub_disk_get_size) (grub_disk_t disk);
#if DISK_CACHE_STATS
void
EXPORT_FUNC(grub_disk_cache_get_performance) (unsigned long *hits, unsigned long *misses);
#endif
extern void (* EXPORT_VAR(grub_disk_firmware_fini)) (void);
extern int EXPORT_VAR(grub_disk_firmware_is_tainted);