Speed up test suite by avoiding fsync

Add grub_util_disable_fd_syncs call to turn grub_util_fd_sync calls into
no-ops, and use it in programs that copy files but do not need to take
special care to sync writes (grub-mknetdir, grub-rescue,
grub-mkstandalone).

On my laptop, this reduces partmap_test's runtime from 1236 seconds to
204 seconds.
This commit is contained in:
Colin Watson 2013-11-27 10:06:07 +00:00
parent fc3f2b72cd
commit 5c7206e45e
9 changed files with 52 additions and 11 deletions

View file

@ -1,3 +1,10 @@
2013-11-27 Colin Watson <cjwatson@ubuntu.com>
Add grub_util_disable_fd_syncs call to turn grub_util_fd_sync calls
into no-ops, and use it in programs that copy files but do not need
to take special care to sync writes (grub-mknetdir, grub-rescue,
grub-mkstandalone).
2013-11-26 Colin Watson <cjwatson@ubuntu.com> 2013-11-26 Colin Watson <cjwatson@ubuntu.com>
* tests/util/grub-fs-tester.in: Execute xorriso from $PATH rather * tests/util/grub-fs-tester.in: Execute xorriso from $PATH rather

View file

@ -455,6 +455,8 @@ grub_util_fd_close (grub_util_fd_t fd)
} }
} }
static int allow_fd_syncs = 1;
static void static void
grub_util_fd_sync_volume (grub_util_fd_t fd) grub_util_fd_sync_volume (grub_util_fd_t fd)
{ {
@ -469,6 +471,8 @@ grub_util_fd_sync_volume (grub_util_fd_t fd)
void void
grub_util_fd_sync (grub_util_fd_t fd) grub_util_fd_sync (grub_util_fd_t fd)
{ {
if (allow_fd_syncs)
{
switch (fd->type) switch (fd->type)
{ {
case GRUB_UTIL_FD_FILE: case GRUB_UTIL_FD_FILE:
@ -478,6 +482,13 @@ grub_util_fd_sync (grub_util_fd_t fd)
grub_util_fd_sync_volume (fd); grub_util_fd_sync_volume (fd);
return; return;
} }
}
}
void
grub_util_disable_fd_syncs (void)
{
allow_fd_syncs = 0;
} }
void void

View file

@ -191,12 +191,21 @@ grub_util_fd_strerror (void)
return strerror (errno); return strerror (errno);
} }
static int allow_fd_syncs = 1;
void void
grub_util_fd_sync (grub_util_fd_t fd) grub_util_fd_sync (grub_util_fd_t fd)
{ {
if (allow_fd_syncs)
fsync (fd); fsync (fd);
} }
void
grub_util_disable_fd_syncs (void)
{
allow_fd_syncs = 0;
}
void void
grub_util_fd_close (grub_util_fd_t fd) grub_util_fd_close (grub_util_fd_t fd)
{ {

View file

@ -240,12 +240,21 @@ grub_util_fd_write (grub_util_fd_t fd, const char *buf, size_t len)
return real_read; return real_read;
} }
static int allow_fd_syncs = 1;
void void
grub_util_fd_sync (grub_util_fd_t fd) grub_util_fd_sync (grub_util_fd_t fd)
{ {
if (allow_fd_syncs)
FlushFileBuffers (fd); FlushFileBuffers (fd);
} }
void
grub_util_disable_fd_syncs (void)
{
allow_fd_syncs = 0;
}
void void
grub_util_fd_close (grub_util_fd_t fd) grub_util_fd_close (grub_util_fd_t fd)
{ {

View file

@ -50,6 +50,8 @@ EXPORT_FUNC(grub_util_fd_strerror) (void);
void void
grub_util_fd_sync (grub_util_fd_t fd); grub_util_fd_sync (grub_util_fd_t fd);
void void
grub_util_disable_fd_syncs (void);
void
EXPORT_FUNC(grub_util_fd_close) (grub_util_fd_t fd); EXPORT_FUNC(grub_util_fd_close) (grub_util_fd_t fd);
grub_uint64_t grub_uint64_t

View file

@ -492,7 +492,7 @@ grub_install_make_image_wrap (const char *dir, const char *prefix,
memdisk_path, config_path, memdisk_path, config_path,
mkimage_target, note, comp); mkimage_target, note, comp);
fflush (fp); fflush (fp);
fsync (fileno (fp)); grub_util_fd_sync (fileno (fp));
fclose (fp); fclose (fp);
} }

View file

@ -171,6 +171,7 @@ main (int argc, char *argv[])
const char *pkglibdir; const char *pkglibdir;
grub_util_host_init (&argc, &argv); grub_util_host_init (&argc, &argv);
grub_util_disable_fd_syncs ();
rootdir = xstrdup ("/srv/tftp"); rootdir = xstrdup ("/srv/tftp");
pkglibdir = grub_util_get_pkglibdir (); pkglibdir = grub_util_get_pkglibdir ();

View file

@ -369,6 +369,7 @@ main (int argc, char *argv[])
const char *pkgdatadir; const char *pkgdatadir;
grub_util_host_init (&argc, &argv); grub_util_host_init (&argc, &argv);
grub_util_disable_fd_syncs ();
pkgdatadir = grub_util_get_pkgdatadir (); pkgdatadir = grub_util_get_pkgdatadir ();
@ -529,7 +530,7 @@ main (int argc, char *argv[])
GRUB_COMPRESSION_AUTO); GRUB_COMPRESSION_AUTO);
sz = ftello (sa); sz = ftello (sa);
fflush (sa); fflush (sa);
fsync (fileno (sa)); grub_util_fd_sync (fileno (sa));
fclose (sa); fclose (sa);
if (sz > 32768) if (sz > 32768)

View file

@ -305,6 +305,7 @@ main (int argc, char *argv[])
int i; int i;
grub_util_host_init (&argc, &argv); grub_util_host_init (&argc, &argv);
grub_util_disable_fd_syncs ();
files = xmalloc ((argc + 1) * sizeof (files[0])); files = xmalloc ((argc + 1) * sizeof (files[0]));