From 386f69c7da4110ced89e1cf736b48b5c354a582a Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Mon, 12 Oct 2015 23:01:34 +0100 Subject: [PATCH] dragon-nx-32: use the new "reclaim discard as buffer cache feature" This gets me another 7 buffers on my build. --- Kernel/kernel09.def | 4 ++ Kernel/platform-dragon-nx32/config.h | 7 +- Kernel/platform-dragon-nx32/crt0.s | 1 - Kernel/platform-dragon-nx32/dragon.s | 95 +++++++++++++++----------- Kernel/platform-dragon-nx32/fuzix.link | 5 +- Kernel/platform-dragon-nx32/kernel.def | 2 + Kernel/platform-dragon-nx32/main.c | 21 ++++++ 7 files changed, 91 insertions(+), 44 deletions(-) diff --git a/Kernel/kernel09.def b/Kernel/kernel09.def index a627a847..d58fdbea 100644 --- a/Kernel/kernel09.def +++ b/Kernel/kernel09.def @@ -31,3 +31,7 @@ P_READY equ 2 ; value from include/kernel.h OS_BANK equ 0 ; value from include/kernel.h EAGAIN equ 11 ; value from include/kernel.h + + +; Keep in sync with struct blkbuf +BUFSIZE equ 521 diff --git a/Kernel/platform-dragon-nx32/config.h b/Kernel/platform-dragon-nx32/config.h index 4331c815..5444f6c1 100644 --- a/Kernel/platform-dragon-nx32/config.h +++ b/Kernel/platform-dragon-nx32/config.h @@ -25,6 +25,9 @@ /* Permit large I/O requests to bypass cache and go direct to userspace */ #define CONFIG_LARGE_IO_DIRECT +/* Reclaim the discard space for buffers */ +#define CONFIG_DYNAMIC_BUFPOOL + #define MAX_BLKDEV 3 /* 2 IDE drives + 1 SPI */ #define SD_DRIVE_COUNT 1 /* Could be higher with multiple CS used */ #define DEVICE_IDE /* enable if IDE interface present */ @@ -63,9 +66,9 @@ #define NDEVS 2 /* Devices 0..NDEVS-1 are capable of being mounted */ /* (add new mountable devices to beginning area.) */ #define TTYDEV BOOT_TTY /* Device used by kernel for messages, panics */ -#define NBUFS 6 /* Number of block buffers */ +#define NBUFS 5 /* Number of block buffers at boot time */ #define NMOUNTS 2 /* Number of mounts at a time */ #define swap_map(x) ((uint8_t *)(x)) -#define platform_discard() +/* Remember to update platform-dragon-nx32/kernel.defs to match */ diff --git a/Kernel/platform-dragon-nx32/crt0.s b/Kernel/platform-dragon-nx32/crt0.s index 43c09bc7..10ce72f6 100644 --- a/Kernel/platform-dragon-nx32/crt0.s +++ b/Kernel/platform-dragon-nx32/crt0.s @@ -46,4 +46,3 @@ identified: jsr _fuzix_main orcc #0x10 stop: bra stop - diff --git a/Kernel/platform-dragon-nx32/dragon.s b/Kernel/platform-dragon-nx32/dragon.s index d599696d..7fba7cce 100644 --- a/Kernel/platform-dragon-nx32/dragon.s +++ b/Kernel/platform-dragon-nx32/dragon.s @@ -2,48 +2,64 @@ ; common Dragon platform ; - .module dragon - - ; exported - .globl _mpi_present - .globl _mpi_set_slot - .globl _cart_hash - .globl _cart_analyze_hdb - .globl _hdb_offset - .globl _hdb_id - .globl _hdb_port - .globl _hdb_timeout - - ; imported - .globl unix_syscall_entry - .globl fd_nmi_handler - .globl size_ram - .globl null_handler - .globl _vid256x192 - .globl _vtoutput - - ; exported debugging tools - .globl _trap_monitor - .globl _trap_reboot - .globl outchar - .globl _di - .globl _ei - .globl _irqrestore - - include "kernel.def" - include "../kernel09.def" - - - .area .vectors + .module dragon + + ; exported + .globl _mpi_present + .globl _mpi_set_slot + .globl _cart_hash + .globl _cart_analyze_hdb + .globl _hdb_offset + .globl _hdb_id + .globl _hdb_port + .globl _hdb_timeout + .globl _bufpool + .globl _discard_size + + ; imported + .globl unix_syscall_entry + .globl fd_nmi_handler + .globl size_ram + .globl null_handler + .globl _vid256x192 + .globl _vtoutput + + ; exported debugging tools + .globl _trap_monitor + .globl _trap_reboot + .globl outchar + .globl _di + .globl _ei + .globl _irqrestore + + include "kernel.def" + include "../kernel09.def" + + + .area .vectors ; ; At 0x100 as required by the Dragon ROM ; - jmp badswi_handler ; 0x100 - jmp badswi_handler ; 0x103 - jmp unix_syscall_entry ; 0x106 - jmp fd_nmi_handler ; 0x109 - jmp interrupt_handler ; 0x10C - jmp firq_handler ; 0x10F + jmp badswi_handler ; 0x100 + jmp badswi_handler ; 0x103 + jmp unix_syscall_entry ; 0x106 + jmp fd_nmi_handler ; 0x109 + jmp interrupt_handler ; 0x10C + jmp firq_handler ; 0x10F + + .area .buffers + ; + ; We use the linker to place these just below + ; the discard area + ; +_bufpool: + .ds BUFSIZE*NBUFS + + ; And expose the discard buffer count to C - but in discard + ; so we can blow it away and precomputed at link time + .area .discard +_discard_size: + .db __sectionlen_.discard__/BUFSIZE .area .text @@ -86,6 +102,7 @@ init_hardware: _trap_reboot: orcc #0x10 clr 0xFFBE + clr 0x0071 jmp [0xFFFE] _trap_monitor: diff --git a/Kernel/platform-dragon-nx32/fuzix.link b/Kernel/platform-dragon-nx32/fuzix.link index 5d076d3e..4fffcd1e 100644 --- a/Kernel/platform-dragon-nx32/fuzix.link +++ b/Kernel/platform-dragon-nx32/fuzix.link @@ -3,10 +3,11 @@ define lensympat __sectionlen_%s__ section .vectors load 0x0100 section .start load 0x1c00 section .common -section .text2 +section .text +section .buffers section .discard section .udata load 0x7D00 -section .text load 0x8010 +section .text2 load 0x8010 section .bss high 0xFC00 section .data section .videodata diff --git a/Kernel/platform-dragon-nx32/kernel.def b/Kernel/platform-dragon-nx32/kernel.def index 2561fd7f..a10a5d91 100644 --- a/Kernel/platform-dragon-nx32/kernel.def +++ b/Kernel/platform-dragon-nx32/kernel.def @@ -21,6 +21,8 @@ SPICS equ 0x01 ; hardcode SEL0 for now PROGBASE equ 0x8000 ; programs and data start here +NBUFS equ 5 + ; Have these defined so that lowlevel-6809.s can be used as-is SAM_USER macro endm diff --git a/Kernel/platform-dragon-nx32/main.c b/Kernel/platform-dragon-nx32/main.c index 0c2007e5..b351c18d 100644 --- a/Kernel/platform-dragon-nx32/main.c +++ b/Kernel/platform-dragon-nx32/main.c @@ -12,6 +12,7 @@ uint8_t cartslots = 1; uint8_t carttype[4]; uint16_t cartaddr[4]; uint8_t bootslot = 0; +struct blkbuf *bufpool_end = bufpool + NBUFS; void platform_idle(void) { @@ -21,4 +22,24 @@ void do_beep(void) { } +/* + * Once we are about to load init we can throw the boot code away + * and convert it into disk cache. This gets us 7 or so buffer + * back which more than doubles our cache size ! + */ +void platform_discard(void) +{ + extern uint8_t discard_size; + bufptr bp = bufpool_end; + + kprintf("%d buffers reclaimed from discard\n", discard_size); + bufpool_end += discard_size; /* Reclaim the discard space */ + + memset(bp, 0, discard_size * sizeof(struct blkbuf)); + /* discard_size is in discard so it dies here */ + for (bp = bufpool + NBUFS; bp < bufpool_end; ++bp) { + bp->bf_dev = NO_DEVICE; + bp->bf_busy = BF_FREE; + } +} -- 2.34.1