Skip to content

Commit

Permalink
[build] Add various options to optimize boot startup times
Browse files Browse the repository at this point in the history
  • Loading branch information
ghaerr committed Oct 14, 2024
1 parent 421c2a5 commit 18eb525
Show file tree
Hide file tree
Showing 16 changed files with 95 additions and 17 deletions.
8 changes: 6 additions & 2 deletions elks/arch/i86/drivers/block/bios.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define RESET_DISK_CHG 1 /* =1 to reset BIOS on drive change fixes QEMU retry */
#define IODELAY 0 /* emulate delay for floppy on QEMU */

#define abs(v) (((int)(v) >= 0)? (v): -(v))
/*
* Indices for fd_types array. Note these match the value returned
* by the BIOS in BL less 1, for INT 13h AH=8 (Get Disk Parms) for IBM PC.
Expand Down Expand Up @@ -125,9 +126,12 @@ int BFPROC bios_disk_rw(unsigned cmd, unsigned num_sectors, unsigned drive,
#if IODELAY
debug_bios("[%ur%u]", drive, num_sectors);
if (drive < 2) { /* emulate floppy delay for QEMU */
unsigned int ms = 10 + num_sectors; /* 1440k @ 300rpm = 100ms + ~10ms/sector */
static unsigned lastcyl;
unsigned ms = abs(cylinder - lastcyl) * 4 / 10;
lastcyl = cylinder;
ms += 10 + num_sectors; /* 1440k @300rpm = 100ms + ~10ms/sector + 4ms/tr */
if (drive == 1)
ms = 8 + (num_sectors<<1); /* 360k @ 360rpm = 83ms + ~20ms/sector */
ms += 8 + (num_sectors<<1); /* 360k @360rpm = 83ms + ~20ms/sector + 3ms/tr */
unsigned long timeout = jiffies + ms*HZ/100;
while (!time_after(jiffies, timeout)) continue;
}
Expand Down
22 changes: 18 additions & 4 deletions elks/arch/i86/drivers/block/bioshd.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
#define PER_DRIVE_INFO 1 /* =1 for per-line display of drive info at init */
#define DEBUG_PROBE 0 /* =1 to display more floppy probing information */
#define FORCE_PROBE 0 /* =1 to force floppy probing */
#define TRACK_SPLIT_BLK 0 /* =1 to read extra sector on track split block */
#define SPLIT_BLK 0 /* =1 to read extra sector on single split block */
#define FULL_TRACK 0 /* =1 to read full tracks when track caching */
#define MAX_ERRS 5 /* maximum sector read/write error retries */

Expand Down Expand Up @@ -499,17 +501,26 @@ static int bioshd_ioctl(struct inode *inode, struct file *file, unsigned int cmd
}

/* calculate CHS and sectors remaining for track read */
static void BFPROC get_chst(struct drive_infot *drivep, sector_t *start_sec, unsigned int *c,
unsigned int *h, unsigned int *s, unsigned int *t, int fulltrack)
static void BFPROC get_chst(struct drive_infot *drivep, sector_t *start_sec,
unsigned int *c, unsigned int *h, unsigned int *s, unsigned int *t, int fulltrack)
{
sector_t start = *start_sec;
sector_t tmp;
int extra = 0;

*s = (unsigned int) (start % drivep->sectors) + 1;
tmp = start / drivep->sectors;
*h = (unsigned int) (tmp % drivep->heads);
*c = (unsigned int) (tmp / drivep->heads);
*t = drivep->sectors - *s + 1;

#if TRACK_SPLIT_BLK
extra = (drivep->sectors & 1) && *h == 0;
if (extra) (*t)++;
#elif SPLIT_BLK
extra = (drivep->sectors & 1) && *h == 0 && *s == drivep->sectors;
if (extra) (*t)++;
#endif
#if FULL_TRACK
if (fulltrack) {
int save = *s;
Expand All @@ -524,7 +535,7 @@ static void BFPROC get_chst(struct drive_infot *drivep, sector_t *start_sec, uns
*start_sec -= save - *s;
}
#endif
debug_bios("bioshd: lba %ld is CHS %d/%d/%d remaining sectors %d\n",
if (extra) debug_cache("bioshd: lba %ld is CHS %d/%d/%d remaining sectors %d\n",
start, *c, *h, *s, *t);
}

Expand All @@ -547,7 +558,7 @@ static int BFPROC do_readwrite(struct drive_infot *drivep, sector_t start, char
if (cmd == READ) debug_bios("bioshd(%x): read lba %ld count %d\n",
drive, start, this_pass);

errs = MAX_ERRS; /* BIOS disk reads should be retried at least three times */
errs = MAX_ERRS; /* BIOS disk reads should be retried at least five times */
do {
#pragma GCC diagnostic ignored "-Wshift-count-overflow"
usedmaseg = seg >> 16; /* will be nonzero only if XMS configured and XMS buffer */
Expand Down Expand Up @@ -611,6 +622,8 @@ static void BFPROC do_readtrack(struct drive_infot *drivep, sector_t start)
num_sectors = DMASEGSZ / drivep->sector_size;

do {
debug_cache("\nTR %lu(CHS %u,%u,%u-%u) ", start>>1, cylinder, head, sector,
sector+num_sectors-1);
debug_bios("bioshd(%x): track read CHS %d/%d/%d count %d\n",
drive, cylinder, head, sector, num_sectors);

Expand Down Expand Up @@ -663,6 +676,7 @@ static int BFPROC do_cache_read(struct drive_infot *drivep, sector_t start, char
if (cmd == READ) {
cache_tries++;
if (cache_valid(drivep, start, buf, seg)) { /* try cache first*/
debug_cache("CH %lu ", start>>1);
cache_hits++;
return 1;
}
Expand Down
2 changes: 2 additions & 0 deletions elks/fs/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ struct buffer_head *getblk32(kdev_t dev, block32_t block)
ebh = EBH(bh);
ebh->b_dev = dev;
ebh->b_blocknr = block;
debug_cache("BM %lu ", block);
goto return_it;

found_it:
Expand All @@ -510,6 +511,7 @@ struct buffer_head *getblk32(kdev_t dev, block32_t block)
CLR_COUNT(en_bh);
en_bh->b_count = 0; /* Release previously created buffer head */
}
if (bh->b_data) debug_cache("L1 %lu ", block); else debug_cache("L2 %lu ", block);
ebh = EBH(bh);
INR_COUNT(ebh);
wait_on_buffer(bh);
Expand Down
2 changes: 1 addition & 1 deletion elks/fs/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ int sys_execve(const char *filename, char *sptr, size_t slen)
word_t magic;

/* Open the image */
dprintk("EXEC(%P): '%t' env %d\n", filename, slen);
debug_cache("\nEXEC(%P): '%t' env %d ", filename, slen);

retval = open_namei(filename, 0, 0, &inode, NULL);
debug("EXEC: open returned %d\n", -retval);
Expand Down
2 changes: 1 addition & 1 deletion elks/fs/open.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ int sys_open(const char *filename, int flags, mode_t mode)
if ((flags + 1) & O_ACCMODE) flag++;
if (flag & (O_TRUNC | O_CREAT)) flag |= FMODE_WRITE;

debug_file("OPEN '%t' flags %#x", filename, flags);
debug_cache("\nOPEN '%t' flags %02x ", filename, flags);
error = open_namei(filename, flag, mode, &inode, NULL);
if (!error) {
if ((error = open_fd(flags, inode)) < 0)
Expand Down
7 changes: 7 additions & 0 deletions elks/include/linuxmt/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define DEBUG_STARTDEF 0 /* default startup debug display*/
#define DEBUG_BIOS 0 /* BIOS driver*/
#define DEBUG_BLK 0 /* block i/o*/
#define DEBUG_CACHE 0 /* floppy track cache*/
#define DEBUG_ETH 0 /* ethernet*/
#define DEBUG_FAT 0 /* FAT filesystem*/
#define DEBUG_FILE 0 /* sys open and file i/o*/
Expand Down Expand Up @@ -54,6 +55,12 @@ void debug_setcallback(int evnum, void (*cbfunc)()); /* callback on debug event*
#define debug_blk(...)
#endif

#if DEBUG_CACHE
#define debug_cache PRINTK
#else
#define debug_cache(...)
#endif

#if DEBUG_ETH
#define debug_eth PRINTK
#else
Expand Down
10 changes: 10 additions & 0 deletions elks/include/linuxmt/trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@

#endif /* CONFIG_TRACE */

/*
* Additional options not requiring CONFIG_TRACE:
*
* DEBUG_CACHE - floppy track cache tracing
* IODELAY - emulate floppy disk I/O delays in QEMU (set in bios.c)
* TRACK_SPLIT_BLK - read extra sector on track split block (set in bioshd.c)
* SPLIT_BLK - read extra sector on single split block (set in bioshd.c)
* FULL_TRACK - read full track on cache refill (set in bioshd.c)
* SHOW_STARTUP - show startup time on boot (set in getty.c)
*/

/* internal flags for kernel */
#define TRACE_STRACE 0x01 /* system call tracing enabled */
Expand Down
9 changes: 6 additions & 3 deletions elks/tools/mfs/genfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ parse_filelist(char *filelist, inode_build_t *parent_inode, char *parent_path)
{
char *name = filename;

if (name[0] == '#')
if (name[0] == '#' || name[0] == '\n')
continue;
name[strlen(name)-1] = '\0'; /* remove lf*/
char *child_path = domalloc(strlen(parent_path) + 1 + strlen(name) + 1, -1);
Expand Down Expand Up @@ -488,7 +488,10 @@ void cmd_genfs(char *filename, int argc,char **argv) {
if (numblocks > req_blks)
fatalmsg("Blocks required %d, available %d\n", numblocks, req_blks);

fs = new_fs(filename,magic,req_blks,req_inos);
if (opt_appendifexists && access(filename, 0) == 0)
fs = open_fs(filename,opt_fsbad_fatal);
else
fs = new_fs(filename,magic,req_blks,req_inos);
err = compile_fs(fs);
if (opt_verbose) cmd_sysinfo(fs);
close_fs(fs);
Expand All @@ -515,7 +518,7 @@ void cmd_addfs(char *filename, int argc,char **argv) {
if (argc != 2) fatalmsg("Usage: addfs <file_of_filenames> <root_template>");

dirname = argv[1];
prefix = 0;
prefix = strlen(argv[1]);
if (opt_verbose) printf("Adding files from %s to %s\n", argv[0], dirname);
numblocks = 2; /* root inode and first mkdir*/
list_init(&inodes);
Expand Down
2 changes: 1 addition & 1 deletion elks/tools/mfs/iname.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ int make_node(struct minix_fs_dat *fs,char *fpath, int mode,
char *fname = strrchr(fpath,'/');
int dinode,ninode;

if (find_inode(fs,fpath) != -1) fatalmsg("%s: already exists",fpath);
if (find_inode(fs,fpath) != -1) printf("%s: already exists\n",fpath);
if (fname) {
*fname++ = 0;
} else {
Expand Down
4 changes: 2 additions & 2 deletions elks/tools/mfs/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ void usage(const char *name) {
"cmd:\n"
" mkfs [-1|2] [-i<#inodes>] [-n<#direntlen>] [-s<#blocks>]\n"
" boot <boot block image>\n"
" genfs [-1|2] [-i<#inodes>] [-n<#direntlen>] [-s<#blocks>] [-k] <directory>\n"
" addfs <file_of_filenames> <directory>\n"
" genfs [-1|2] [-i<#inodes>] [-n<#direntlen>] [-s<#blocks>] [-k] [-a] <directory>\n"
" addfs <file_of_relative_paths> <directory>\n"
" [stat]\n"
" ls [-ld] [filelist...]"
" cp source_file dest_dir_or_file\n"
Expand Down
6 changes: 5 additions & 1 deletion elks/tools/mfs/mkfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <stdlib.h>

int opt_nocopyzero = 0; /* don't copy zero-length files starting with . */
int opt_appendifexists = 0; /* don't create new fs on genfs if exists */

/**
* Parse mkfs/genfs command line arguments
Expand All @@ -54,7 +55,7 @@ void parse_mkfs(int argc,char **argv,int *magic_p,int *nblks_p,int *inodes_p) {

optind = 1;
while (1) {
c = getoptX(argc,argv,"12vi:n:s:k");
c = getoptX(argc,argv,"12vi:n:s:ka");
if (c == -1) break;
switch (c) {
case '1':
Expand All @@ -78,6 +79,9 @@ void parse_mkfs(int argc,char **argv,int *magic_p,int *nblks_p,int *inodes_p) {
case 'k':
opt_nocopyzero = 1;
break;
case 'a':
opt_appendifexists = 1;
break;
default:
usage(argv[0]);
}
Expand Down
1 change: 1 addition & 0 deletions elks/tools/mfs/protos.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ extern int opt_fsbad_fatal;
extern char *toolname;

extern int opt_nocopyzero;
extern int opt_appendifexists;

extern char *optarg;
extern int opterr;
Expand Down
3 changes: 2 additions & 1 deletion elkscmd/rootfs_template/bootopts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#root=hda1 ro
#kstack
#strace
#FTRACE=1
#net=ne0
#debug FTRACE=1
#debug
#console=ttyS0,19200 3
21 changes: 21 additions & 0 deletions image/Image.all
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# boot
dev
etc
bin
bin/init
etc/inittab
etc/rc.sys
bin/sh
etc/profile
bin/clock
etc/mount.cfg
bin/date
bin/getty
etc/issue
#etc/net.cfg
bootopts
linux
# login
bin/login
etc/passwd
root
4 changes: 4 additions & 0 deletions image/Make.devices
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

devices:

# $(MKDEV) /dev/console c 4 254 1 1 0600
# $(MKDEV) /dev/tty1 c 4 0
# $(MKDEV) /dev/ttyS0 c 4 64

##############################################################################
# Create memory devices.

Expand Down
9 changes: 8 additions & 1 deletion image/Make.image
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,14 @@ endif

minixfs:
rm -f $(TARGET_FILE)
mfs $(VERBOSE) $(TARGET_FILE) genfs $(MINIX_MKFSOPTS) $(DESTDIR)
mfs $(VERBOSE) $(TARGET_FILE) mkfs $(MINIX_MKFSOPTS)
# mfs -v $(VERBOSE) $(TARGET_FILE) addfs Image.all $(DESTDIR)
# rm -f Filelist
# for f in $$(cd $(DESTDIR); find * -name '*'); do \
# echo $$f >> FileList; \
# done
# mfs -v $(VERBOSE) $(TARGET_FILE) addfs Filelist $(DESTDIR)
mfs $(VERBOSE) $(TARGET_FILE) genfs -a $(MINIX_MKFSOPTS) $(DESTDIR)
ifdef CONFIG_IMG_DEV
# command to make char/block devices in image (no sudo required)
$(MAKE) -f Make.devices "MKDEV=mfs $(TARGET_FILE) mknod"
Expand Down

0 comments on commit 18eb525

Please sign in to comment.