From 222a9594d51dbd5249e90fce1e0c8d3d77d80fc4 Mon Sep 17 00:00:00 2001 From: Nick Briggs Date: Sun, 19 Mar 2023 16:32:00 -0700 Subject: [PATCH] Speed up initial sysout loading by avoiding unnecessary lseek() calls. (#461) On slower filesystems/disks, an lseek() operation can consume noticeable time. During initial sysout loading we can avoid an unnecessary lseek() before each read() by tracking if the position it will seek to is the same position that the previous read() left us. --- src/ldsout.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/ldsout.c b/src/ldsout.c index 15726b1..5860a0a 100644 --- a/src/ldsout.c +++ b/src/ldsout.c @@ -17,6 +17,7 @@ #include // for memset #include // for mmap #include // for stat, fstat +#include // for off_t #include // for lseek, read, close, getpagesize #include "adr68k.h" // for NativeAligned2FromLAddr #ifdef BYTESWAP @@ -74,6 +75,7 @@ unsigned sysout_loader(const char *sysout_file_name, unsigned sys_size) { struct stat stat_buf; /* file stat buf */ char errmsg[255]; + off_t cfp = -1; /* tracks current file position in sysout, or -1 */ /* Checks for specifying the process size (phase I) */ /* If sys_size == 0 figure out the proper size later */ @@ -297,10 +299,14 @@ unsigned sysout_loader(const char *sysout_file_name, unsigned sys_size) { } #endif /* DOS */ if (GETPAGEOK(fptovp, i) != 0177777) { - if (lseek(sysout, i * BYTESPER_PAGE, SEEK_SET) == -1) { - perror("sysout_loader: can't seek sysout file"); - free(fptovp); - exit(-1); + /* only seek if not already at desired position */ + if (i * BYTESPER_PAGE != cfp) { + if (lseek(sysout, i * BYTESPER_PAGE, SEEK_SET) == -1) { + perror("sysout_loader: can't seek sysout file"); + free(fptovp); + exit(-1); + } + cfp = i * BYTESPER_PAGE; /* now at known position */ } lispworld_offset = GETFPTOVP(fptovp, i) * BYTESPER_PAGE; if (read(sysout, lispworld_scratch + lispworld_offset, BYTESPER_PAGE) == -1) { @@ -314,6 +320,7 @@ unsigned sysout_loader(const char *sysout_file_name, unsigned sys_size) { free(fptovp); exit(-1); } + cfp += BYTESPER_PAGE; /* new known position */ #ifdef BYTESWAP word_swap_page((DLword *)(lispworld_scratch + lispworld_offset), 128); #endif