From e8cf8b25f7b5e51c747b9979cbb39b6769862c52 Mon Sep 17 00:00:00 2001 From: Greg Haerr Date: Wed, 16 Oct 2024 17:16:55 -0600 Subject: [PATCH 1/4] Properly calculate IODELAY sector count Add debug_cache to DF driver Add debug_cache for drive-to-drive transfers --- elks/arch/i86/drivers/block/bioshd.c | 9 +++++---- elks/arch/i86/drivers/block/directfd.c | 15 ++++++++++----- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/elks/arch/i86/drivers/block/bioshd.c b/elks/arch/i86/drivers/block/bioshd.c index 779edc34a..230fbe03e 100644 --- a/elks/arch/i86/drivers/block/bioshd.c +++ b/elks/arch/i86/drivers/block/bioshd.c @@ -106,6 +106,7 @@ static struct gendisk bioshd_gendisk = { static void BFPROC set_cache_invalid(void) { + if (cache_drive) debug_cache("INV%d ", cache_drive - drive_info); cache_drive = NULL; } @@ -580,8 +581,8 @@ static int BFPROC do_readwrite(struct drive_infot *drivep, sector_t start, char segment = (seg_t)seg; offset = (unsigned) buf; } - debug_bios("bioshd(%x): cmd %d CHS %d/%d/%d count %d\n", - drive, cmd, cylinder, head, sector, this_pass); + debug_cache("bioshd(%x): %s CHS %d/%d/%d count %d\n", + drive, cmd==WRITE? "WR": "RD", cylinder, head, sector, this_pass); bios_set_ddpt(drivep->sectors); error = bios_disk_rw(cmd == WRITE? BIOSHD_WRITE: BIOSHD_READ, this_pass, @@ -622,8 +623,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_cache("\nTR%d %lu(CHS %u,%u,%u-%u) ", drive, 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); diff --git a/elks/arch/i86/drivers/block/directfd.c b/elks/arch/i86/drivers/block/directfd.c index ae8ae729b..770385194 100644 --- a/elks/arch/i86/drivers/block/directfd.c +++ b/elks/arch/i86/drivers/block/directfd.c @@ -773,10 +773,11 @@ static void rw_interrupt(void) static void DFPROC setup_rw_floppy(void) { DEBUG("setup_rw-"); +#if IODELAY || DEBUG_CACHE + int num_sectors = read_track + ? floppy->sect + (floppy->sect & 1 && !head) - sector + : CURRENT->rq_nr_sectors; #if IODELAY - int num_sectors = read_track? floppy->sect + (floppy->sect & 1 && !head) - : CURRENT->rq_nr_sectors; - DEBUG("[%ur%u]", current_drive, num_sectors); static unsigned lasttrack; unsigned ms = abs(track - lasttrack) * 4 / 10; lasttrack = track; @@ -786,6 +787,10 @@ static void DFPROC setup_rw_floppy(void) 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; +#endif + debug_cache("%s%d %lu(CHS %u,%u,%u-%u)\n", + read_track? "TR": (command == FD_WRITE? "WR": "RD"), + current_drive, CURRENT->rq_sector>>1, track, head, sector+1, sector+num_sectors); #endif do_floppy = rw_interrupt; setup_DMA(); @@ -1184,7 +1189,7 @@ static void DFPROC redo_fd_request(void) goto repeat; } floppy = &minor_types[tmp]; - if (!recalibrate) + if (!recalibrate && probing) printk("df%d: auto-probe #%d %s\n", drive, probing, floppy->name); } } @@ -1209,7 +1214,7 @@ static void DFPROC redo_fd_request(void) command = (req->rq_cmd == READ)? FD_READ: FD_WRITE; DEBUG("df%d: %s sector %d CHS %d/%d/%d max %d stretch %d seek %d\n", DEVICE_NR(req->rq_dev), req->rq_cmd==READ? "read": "write", - start, track, head, sector, floppy->sect, floppy->stretch, seek_track); + start, track, head, sector+1, floppy->sect, floppy->stretch, seek_track); /* restart timer for hung operations, 6 secs probably too long ... */ del_timer(&fd_timeout); From 683e6342b9fb6895faa760c08485700ce3319ae6 Mon Sep 17 00:00:00 2001 From: Greg Haerr Date: Wed, 16 Oct 2024 17:39:23 -0600 Subject: [PATCH 2/4] Introduce debug=N in /bootopts for multilevel debug statements Add debug_cache2 second level debug --- elks/arch/i86/drivers/block/bioshd.c | 12 +++++++----- elks/fs/buffer.c | 5 +++-- elks/include/linuxmt/debug.h | 6 ++++-- elks/include/linuxmt/kernel.h | 2 +- elks/init/main.c | 8 ++++---- elks/kernel/printk.c | 8 ++++---- elks/kernel/sysctl.c | 2 +- elkscmd/rootfs_template/bootopts | 2 +- 8 files changed, 25 insertions(+), 20 deletions(-) diff --git a/elks/arch/i86/drivers/block/bioshd.c b/elks/arch/i86/drivers/block/bioshd.c index 230fbe03e..667a7dea6 100644 --- a/elks/arch/i86/drivers/block/bioshd.c +++ b/elks/arch/i86/drivers/block/bioshd.c @@ -106,7 +106,7 @@ static struct gendisk bioshd_gendisk = { static void BFPROC set_cache_invalid(void) { - if (cache_drive) debug_cache("INV%d ", cache_drive - drive_info); + if (cache_drive) debug_cache2("INV%d ", cache_drive - drive_info); cache_drive = NULL; } @@ -536,7 +536,7 @@ static void BFPROC get_chst(struct drive_infot *drivep, sector_t *start_sec, *start_sec -= save - *s; } #endif - if (extra) debug_cache("bioshd: lba %ld is CHS %d/%d/%d remaining sectors %d\n", + if (extra) debug_cache2("bioshd: lba %ld is CHS %d/%d/%d remaining sectors %d\n", start, *c, *h, *s, *t); } @@ -581,8 +581,10 @@ static int BFPROC do_readwrite(struct drive_infot *drivep, sector_t start, char segment = (seg_t)seg; offset = (unsigned) buf; } - debug_cache("bioshd(%x): %s CHS %d/%d/%d count %d\n", - drive, cmd==WRITE? "WR": "RD", cylinder, head, sector, this_pass); + debug_cache("%s%d CHS %d/%d/%d count %d\n", + cmd==WRITE? "WR": "RD", drive, cylinder, head, sector, this_pass); + debug_bios("bioshd(%x): cmd %d CHS %d/%d/%d count %d\n", + drive, cmd, cylinder, head, sector, this_pass); bios_set_ddpt(drivep->sectors); error = bios_disk_rw(cmd == WRITE? BIOSHD_WRITE: BIOSHD_READ, this_pass, @@ -677,7 +679,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); + debug_cache2("CH %lu ", start>>1); cache_hits++; return 1; } diff --git a/elks/fs/buffer.c b/elks/fs/buffer.c index 94f8bd0eb..18879d663 100644 --- a/elks/fs/buffer.c +++ b/elks/fs/buffer.c @@ -501,7 +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); + debug_cache2("BM %lu ", block); goto return_it; found_it: @@ -511,7 +511,8 @@ 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); + if (bh->b_data) { debug_cache2("L1 %lu ", block); } + else { debug_cache2("L2 %lu ", block); } ebh = EBH(bh); INR_COUNT(ebh); wait_on_buffer(bh); diff --git a/elks/include/linuxmt/debug.h b/elks/include/linuxmt/debug.h index 99e7e3a3c..239404ebc 100644 --- a/elks/include/linuxmt/debug.h +++ b/elks/include/linuxmt/debug.h @@ -13,10 +13,10 @@ * Kernel debug options, set =1 to turn on. Works across multiple files. */ #define DEBUG_EVENT 1 /* generate debug events on CTRLN-CTRLP*/ -#define DEBUG_STARTDEF 0 /* default startup debug display*/ +#define DEBUG_LEVEL 0 /* default startup debug level*/ #define DEBUG_BIOS 0 /* BIOS driver*/ #define DEBUG_BLK 0 /* block i/o*/ -#define DEBUG_CACHE 0 /* floppy track cache*/ +#define DEBUG_CACHE 1 /* floppy track cache*/ #define DEBUG_ETH 0 /* ethernet*/ #define DEBUG_FAT 0 /* FAT filesystem*/ #define DEBUG_FILE 0 /* sys open and file i/o*/ @@ -57,8 +57,10 @@ void debug_setcallback(int evnum, void (*cbfunc)()); /* callback on debug event* #if DEBUG_CACHE #define debug_cache PRINTK +#define debug_cache2 if (debug_level > 1) PRINTK #else #define debug_cache(...) +#define debug_cache2(...) #endif #if DEBUG_ETH diff --git a/elks/include/linuxmt/kernel.h b/elks/include/linuxmt/kernel.h index 55eeb0f6a..61dbd368f 100644 --- a/elks/include/linuxmt/kernel.h +++ b/elks/include/linuxmt/kernel.h @@ -19,7 +19,7 @@ extern char running_qemu; extern dev_t dev_console; -extern int dprintk_on; +extern int debug_level; extern void do_exit(int) noreturn; diff --git a/elks/init/main.c b/elks/init/main.c index 9e692eeb7..9d02091bb 100644 --- a/elks/init/main.c +++ b/elks/init/main.c @@ -491,10 +491,6 @@ static int INITPROC parse_options(void) root_mountflags &= ~MS_RDONLY; continue; } - if (!strcmp(line,"debug")) { - dprintk_on = 1; - continue; - } if (!strcmp(line,"strace")) { tracing |= TRACE_STRACE; continue; @@ -520,6 +516,10 @@ static int INITPROC parse_options(void) parse_nic(line+4, &netif_parms[ETH_EL3]); continue; } + if (!strncmp(line,"debug=", 6)) { + debug_level = (int)simple_strtol(line+6, 10); + continue; + } if (!strncmp(line,"buf=",4)) { nr_ext_bufs = (int)simple_strtol(line+4, 10); continue; diff --git a/elks/kernel/printk.c b/elks/kernel/printk.c index cf4c20ad3..861b0fa85 100644 --- a/elks/kernel/printk.c +++ b/elks/kernel/printk.c @@ -326,7 +326,7 @@ void panic(const char *error, ...) halt(); } -int dprintk_on = DEBUG_STARTDEF; /* toggled by debug events*/ +int debug_level = DEBUG_LEVEL; /* set with debug= or toggled by debug events */ #if DEBUG_EVENT static void (*debug_cbfuncs[3])(); /* debug event callback function*/ @@ -338,8 +338,8 @@ void debug_setcallback(int evnum, void (*cbfunc)()) void debug_event(int evnum) { - if (evnum == 2) { /* CTRLP toggles dprintk*/ - dprintk_on = !dprintk_on; + if (evnum == 2) { /* CTRLP toggles debug */ + debug_level = !debug_level; kill_all(SIGURG); } if (debug_cbfuncs[evnum]) @@ -350,7 +350,7 @@ void dprintk(const char *fmt, ...) { va_list p; - if (!dprintk_on) + if (!debug_level) return; va_start(p, fmt); vprintk(fmt, p); diff --git a/elks/kernel/sysctl.c b/elks/kernel/sysctl.c index e4c1a26ff..76dccb39e 100644 --- a/elks/kernel/sysctl.c +++ b/elks/kernel/sysctl.c @@ -15,7 +15,7 @@ static int malloc_debug; static int net_debug; struct sysctl sysctl[] = { - { "kern.debug", &dprintk_on }, /* debug (^P) on/off */ + { "kern.debug", &debug_level }, /* debug level (^P toggled) */ { "kern.strace", &tracing }, /* strace=1, kstack=2 */ { "kern.console", (int *)&dev_console }, /* console */ { "malloc.debug", &malloc_debug }, diff --git a/elkscmd/rootfs_template/bootopts b/elkscmd/rootfs_template/bootopts index 0ea554d82..3114650fe 100644 --- a/elkscmd/rootfs_template/bootopts +++ b/elkscmd/rootfs_template/bootopts @@ -19,5 +19,5 @@ #strace #FTRACE=1 #net=ne0 -#debug +#debug=1 #console=ttyS0,19200 3 From be66adcfc3e147e8b0bd888c6f9c200a3d5c57ad Mon Sep 17 00:00:00 2001 From: Greg Haerr Date: Wed, 16 Oct 2024 17:55:01 -0600 Subject: [PATCH 3/4] Fixup CH display --- elks/arch/i86/drivers/block/bioshd.c | 2 +- elks/arch/i86/drivers/block/directfd.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/elks/arch/i86/drivers/block/bioshd.c b/elks/arch/i86/drivers/block/bioshd.c index 667a7dea6..21954cf28 100644 --- a/elks/arch/i86/drivers/block/bioshd.c +++ b/elks/arch/i86/drivers/block/bioshd.c @@ -679,7 +679,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_cache2("CH %lu ", start>>1); + debug_cache2("CH %lu ", start >> 1); cache_hits++; return 1; } diff --git a/elks/arch/i86/drivers/block/directfd.c b/elks/arch/i86/drivers/block/directfd.c index 770385194..72cfc7d6a 100644 --- a/elks/arch/i86/drivers/block/directfd.c +++ b/elks/arch/i86/drivers/block/directfd.c @@ -1229,7 +1229,8 @@ static void DFPROC redo_fd_request(void) * number of sectors (full blocks). When head=1 we read the entire track * and ignore the first sector. */ - DEBUG("bufrd chs %d/%d/%d\n", seek_track, head, sector); + DEBUG("cache CHS %d/%d/%d\n", seek_track, head, sector); + debug_cache2("CH %d ", start >> 1); char *buf_ptr = (char *) (sector << 9); if (command == FD_READ) { /* requested data is in buffer */ xms_fmemcpyw(req->rq_buffer, req->rq_seg, buf_ptr, DMASEG, BLOCK_SIZE/2); From 5493f9ff5f605225b654290b1d07cc59ff91b599 Mon Sep 17 00:00:00 2001 From: Greg Haerr Date: Wed, 16 Oct 2024 18:04:57 -0600 Subject: [PATCH 4/4] Display request queue size > 1 on DEBUG_CACHE --- elks/arch/i86/drivers/block/ll_rw_blk.c | 8 ++++++++ elks/include/linuxmt/debug.h | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/elks/arch/i86/drivers/block/ll_rw_blk.c b/elks/arch/i86/drivers/block/ll_rw_blk.c index 8c96cf766..0ad819620 100644 --- a/elks/arch/i86/drivers/block/ll_rw_blk.c +++ b/elks/arch/i86/drivers/block/ll_rw_blk.c @@ -161,6 +161,14 @@ static void add_request(struct blk_dev_struct *dev, struct request *req) req->rq_next = tmp->rq_next; tmp->rq_next = req; set_irq(); +#if DEBUG_CACHE + if (debug_level) { + int n = 0; + for (tmp = dev->current_request; tmp->rq_next; tmp = tmp->rq_next) + n++; + if (n > 1) printk("REQS %d ", n); + } +#endif #else panic("add_request"); /* non-empty request queue */ #endif diff --git a/elks/include/linuxmt/debug.h b/elks/include/linuxmt/debug.h index 239404ebc..9d900c1e5 100644 --- a/elks/include/linuxmt/debug.h +++ b/elks/include/linuxmt/debug.h @@ -16,7 +16,7 @@ #define DEBUG_LEVEL 0 /* default startup debug level*/ #define DEBUG_BIOS 0 /* BIOS driver*/ #define DEBUG_BLK 0 /* block i/o*/ -#define DEBUG_CACHE 1 /* floppy track cache*/ +#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*/