mirror of
https://github.com/Interlisp/maiko.git
synced 2026-01-15 15:57:13 +00:00
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.
This commit is contained in:
parent
525b9c94d8
commit
222a9594d5
15
src/ldsout.c
15
src/ldsout.c
@ -17,6 +17,7 @@
|
||||
#include <string.h> // for memset
|
||||
#include <sys/mman.h> // for mmap
|
||||
#include <sys/stat.h> // for stat, fstat
|
||||
#include <sys/types.h> // for off_t
|
||||
#include <unistd.h> // 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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user