dragon-nx-32: use the new "reclaim discard as buffer cache feature"
authorAlan Cox <alan@linux.intel.com>
Mon, 12 Oct 2015 22:01:34 +0000 (23:01 +0100)
committerAlan Cox <alan@linux.intel.com>
Mon, 12 Oct 2015 22:01:34 +0000 (23:01 +0100)
This gets me another 7 buffers on my build.

Kernel/kernel09.def
Kernel/platform-dragon-nx32/config.h
Kernel/platform-dragon-nx32/crt0.s
Kernel/platform-dragon-nx32/dragon.s
Kernel/platform-dragon-nx32/fuzix.link
Kernel/platform-dragon-nx32/kernel.def
Kernel/platform-dragon-nx32/main.c

index a627a84..d58fdbe 100644 (file)
@@ -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
index 4331c81..5444f6c 100644 (file)
@@ -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 */
 
index 43c09bc..10ce72f 100644 (file)
@@ -46,4 +46,3 @@ identified:
                jsr _fuzix_main
                orcc #0x10
 stop:          bra stop
-
index d599696..7fba7cc 100644 (file)
@@ -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:
index 5d076d3..4fffcd1 100644 (file)
@@ -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
index 2561fd7..a10a5d9 100644 (file)
@@ -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
index 0c2007e..b351c18 100644 (file)
@@ -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;
+  }
+}