Fix several more minor bugs, add gen.sh which pre-runs the C preprocessor to generate...
authorNick Downing <nick.downing@lifx.co>
Thu, 11 Apr 2019 12:00:05 +0000 (22:00 +1000)
committerNick Downing <nick.downing@lifx.co>
Thu, 11 Apr 2019 12:00:05 +0000 (22:00 +1000)
19 files changed:
.gitignore
blank.py [new file with mode: 0755]
core.h
gen.sh [new file with mode: 0755]
indirect_core_indirect_swap/Makefile [new file with mode: 0644]
indirect_core_indirect_swap/o.sh [new file with mode: 0755]
indirect_core_inode_swap/Makefile [new file with mode: 0644]
indirect_core_inode_swap/o.sh [new file with mode: 0755]
indirect_core_preallocate_swap/Makefile [new file with mode: 0644]
indirect_core_preallocate_swap/o.sh [new file with mode: 0755]
moveable_core_indirect_swap/Makefile [new file with mode: 0644]
moveable_core_indirect_swap/o.sh [new file with mode: 0755]
moveable_core_inode_swap/Makefile [new file with mode: 0644]
moveable_core_inode_swap/o.sh [new file with mode: 0755]
moveable_core_preallocate_swap/Makefile [new file with mode: 0644]
moveable_core_preallocate_swap/o.sh [new file with mode: 0755]
pp.sh [new file with mode: 0755]
process.c
q.sh [new file with mode: 0755]

index 9ea066b..98ec250 100644 (file)
@@ -1,9 +1,35 @@
 *.o
 /fs.bin
 /mkfs
+/indirect_core_indirect_swap/*.c
+/indirect_core_indirect_swap/*.h
+/indirect_core_indirect_swap/process_test.txt
+/indirect_core_indirect_swap/process_test_run
+/indirect_core_inode_swap/*.c
+/indirect_core_inode_swap/*.h
+/indirect_core_inode_swap/fs.bin
+/indirect_core_inode_swap/process_test.txt
+/indirect_core_inode_swap/process_test_run
+/indirect_core_preallocate_swap/*.c
+/indirect_core_preallocate_swap/*.h
+/indirect_core_preallocate_swap/process_test.txt
+/indirect_core_preallocate_swap/process_test_run
 /inode_test.txt
 /inode_test_gen
 /inode_test_run
+/moveable_core_indirect_swap/*.c
+/moveable_core_indirect_swap/*.h
+/moveable_core_indirect_swap/process_test.txt
+/moveable_core_indirect_swap/process_test_run
+/moveable_core_inode_swap/*.c
+/moveable_core_inode_swap/*.h
+/moveable_core_inode_swap/fs.bin
+/moveable_core_inode_swap/process_test.txt
+/moveable_core_inode_swap/process_test_run
+/moveable_core_preallocate_swap/*.c
+/moveable_core_preallocate_swap/*.h
+/moveable_core_preallocate_swap/process_test.txt
+/moveable_core_preallocate_swap/process_test_run
 /pool_test.txt
 /pool_test_gen
 /pool_test_run
diff --git a/blank.py b/blank.py
new file mode 100755 (executable)
index 0000000..ba68ce9
--- /dev/null
+++ b/blank.py
@@ -0,0 +1,21 @@
+#!/usr/bin/env python3
+
+import sys
+
+opens = set(['(', '{', '['])
+closes = set([')', '}', ']'])
+
+before = ''
+blank = False
+for i in sys.stdin:
+  i = i.rstrip()
+  if len(i) == 0:
+    blank = True
+  else:
+    after = i.lstrip()
+    if blank and before[-1:] not in opens and after[:1] not in closes:
+      sys.stdout.write('\n')
+    sys.stdout.write(i + '\n')
+    j = i.find('//')
+    before = i if j == -1 else i[:j].rstrip()
+    blank = False
diff --git a/core.h b/core.h
index e8a9eca..2bc3d74 100644 (file)
--- a/core.h
+++ b/core.h
@@ -4,9 +4,9 @@
 #include <stdint.h>
 #include "pool.h"
 
-#define PREALLOCATE_CORE 1
-#define INDIRECT_CORE 1
-//#define MOVEABLE_CORE 1
+//#define PREALLOCATE_CORE 1
+//#define INDIRECT_CORE 1
+#define MOVEABLE_CORE 1
 
 #ifdef MOVEABLE_CORE
 #define core_table_alloc(item, size) \
diff --git a/gen.sh b/gen.sh
new file mode 100755 (executable)
index 0000000..f1c9596
--- /dev/null
+++ b/gen.sh
@@ -0,0 +1,42 @@
+#!/bin/sh -e
+
+# we will only use non-moveable swap, so it must be preallocated,
+# this is because the swap-move routines are too hard to implement
+sed -e 's/^\/\/#define PREALLOCATE_SWAP 1/#define PREALLOCATE_SWAP 1/' -i swap.h
+sed -e 's/^#define MOVEABLE_SWAP 1/\/\/#define MOVEABLE_SWAP 1/' -i swap.h
+
+sed -e 's/^\/\/#define PREALLOCATE_CORE 1/#define PREALLOCATE_CORE 1/' -i core.h
+sed -e 's/^\/\/#define INDIRECT_CORE 1/#define INDIRECT_CORE 1/' -i core.h
+sed -e 's/^#define MOVEABLE_CORE 1/\/\/#define MOVEABLE_CORE 1/' -i core.h
+
+sed -e 's/^#define INODE_SWAP 1/\/\/#define INODE_SWAP 1/' -i process.h
+sed -e 's/^#define INDIRECT_SWAP 1/\/\/#define INDIRECT_SWAP 1/' -i swap.h
+./pp.sh indirect_core_preallocate_swap
+cp rassert.h indirect_core_preallocate_swap
+
+sed -e 's/^\/\/#define INDIRECT_SWAP 1/#define INDIRECT_SWAP 1/' -i swap.h
+./pp.sh indirect_core_indirect_swap
+cp rassert.h indirect_core_indirect_swap
+
+sed -e 's/^\/\/#define INODE_SWAP 1/#define INODE_SWAP 1/' -i process.h
+./pp.sh indirect_core_inode_swap
+rm indirect_core_inode_swap/swap.[ch]
+cp rassert.h fuzix_fs.[ch] util.[ch] indirect_core_inode_swap
+
+sed -e 's/^#define PREALLOCATE_CORE 1/\/\/#define PREALLOCATE_CORE 1/' -i core.h
+sed -e 's/^#define INDIRECT_CORE 1/\/\/#define INDIRECT_CORE 1/' -i core.h
+sed -e 's/^\/\/#define MOVEABLE_CORE 1/#define MOVEABLE_CORE 1/' -i core.h
+
+sed -e 's/^#define INODE_SWAP 1/\/\/#define INODE_SWAP 1/' -i process.h
+sed -e 's/^#define INDIRECT_SWAP 1/\/\/#define INDIRECT_SWAP 1/' -i swap.h
+./pp.sh moveable_core_preallocate_swap
+cp rassert.h moveable_core_preallocate_swap
+
+sed -e 's/^\/\/#define INDIRECT_SWAP 1/#define INDIRECT_SWAP 1/' -i swap.h
+./pp.sh moveable_core_indirect_swap
+cp rassert.h moveable_core_indirect_swap
+
+sed -e 's/^\/\/#define INODE_SWAP 1/#define INODE_SWAP 1/' -i process.h
+./pp.sh moveable_core_inode_swap
+rm moveable_core_inode_swap/swap.[ch]
+cp rassert.h fuzix_fs.[ch] util.[ch] moveable_core_inode_swap
diff --git a/indirect_core_indirect_swap/Makefile b/indirect_core_indirect_swap/Makefile
new file mode 100644 (file)
index 0000000..6cedec7
--- /dev/null
@@ -0,0 +1,12 @@
+CFLAGS=-g -Wall
+
+process_test_run: process_test_run.o process.o core.o swap.o pool.o
+       ${CC} ${CFLAGS} -o $@ $^
+
+process_test_run.o: process_test_run.c process.h core.h swap.h pool.h
+process.o: process.c process.h core.h swap.h pool.h
+core.o: core.c core.h pool.h
+swap.o: swap.c swap.h pool.h
+
+clean:
+       rm -f process_test_run
diff --git a/indirect_core_indirect_swap/o.sh b/indirect_core_indirect_swap/o.sh
new file mode 100755 (executable)
index 0000000..c68117c
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+echo "generate test script"
+../process_test_gen 16 248 1024 32 >process_test.txt
+
+echo "run test script"
+./process_test_run 16 64 192 8 384 384 <process_test.txt
diff --git a/indirect_core_inode_swap/Makefile b/indirect_core_inode_swap/Makefile
new file mode 100644 (file)
index 0000000..68692d9
--- /dev/null
@@ -0,0 +1,12 @@
+CFLAGS=-g -Wall
+
+process_test_run: process_test_run.o process.o core.o fuzix_fs.o util.o pool.o
+       ${CC} ${CFLAGS} -o $@ $^
+
+process_test_run.o: process_test_run.c process.h core.h fuzix_fs.h util.h pool.h
+process.o: process.c process.h core.h fuzix_fs.h util.h pool.h
+core.o: core.c core.h pool.h
+fuzix_fs.o: fuzix_fs.c fuzix_fs.h
+
+clean:
+       rm -f process_test_run
diff --git a/indirect_core_inode_swap/o.sh b/indirect_core_inode_swap/o.sh
new file mode 100755 (executable)
index 0000000..1e04eea
--- /dev/null
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+echo "generate test script"
+../process_test_gen 16 248 1024 32 >process_test.txt
+
+echo "run test script"
+rm -f fs.bin
+../mkfs fs.bin 256 16384
+./process_test_run 16 64 fs.bin 8 384 <process_test.txt
diff --git a/indirect_core_preallocate_swap/Makefile b/indirect_core_preallocate_swap/Makefile
new file mode 100644 (file)
index 0000000..6cedec7
--- /dev/null
@@ -0,0 +1,12 @@
+CFLAGS=-g -Wall
+
+process_test_run: process_test_run.o process.o core.o swap.o pool.o
+       ${CC} ${CFLAGS} -o $@ $^
+
+process_test_run.o: process_test_run.c process.h core.h swap.h pool.h
+process.o: process.c process.h core.h swap.h pool.h
+core.o: core.c core.h pool.h
+swap.o: swap.c swap.h pool.h
+
+clean:
+       rm -f process_test_run
diff --git a/indirect_core_preallocate_swap/o.sh b/indirect_core_preallocate_swap/o.sh
new file mode 100755 (executable)
index 0000000..c68117c
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+echo "generate test script"
+../process_test_gen 16 248 1024 32 >process_test.txt
+
+echo "run test script"
+./process_test_run 16 64 192 8 384 384 <process_test.txt
diff --git a/moveable_core_indirect_swap/Makefile b/moveable_core_indirect_swap/Makefile
new file mode 100644 (file)
index 0000000..6cedec7
--- /dev/null
@@ -0,0 +1,12 @@
+CFLAGS=-g -Wall
+
+process_test_run: process_test_run.o process.o core.o swap.o pool.o
+       ${CC} ${CFLAGS} -o $@ $^
+
+process_test_run.o: process_test_run.c process.h core.h swap.h pool.h
+process.o: process.c process.h core.h swap.h pool.h
+core.o: core.c core.h pool.h
+swap.o: swap.c swap.h pool.h
+
+clean:
+       rm -f process_test_run
diff --git a/moveable_core_indirect_swap/o.sh b/moveable_core_indirect_swap/o.sh
new file mode 100755 (executable)
index 0000000..a0a6ff0
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+echo "generate test script"
+../process_test_gen 16 248 1024 32 >process_test.txt
+
+echo "run test script"
+./process_test_run 16 64 192 8 384 <process_test.txt
diff --git a/moveable_core_inode_swap/Makefile b/moveable_core_inode_swap/Makefile
new file mode 100644 (file)
index 0000000..68692d9
--- /dev/null
@@ -0,0 +1,12 @@
+CFLAGS=-g -Wall
+
+process_test_run: process_test_run.o process.o core.o fuzix_fs.o util.o pool.o
+       ${CC} ${CFLAGS} -o $@ $^
+
+process_test_run.o: process_test_run.c process.h core.h fuzix_fs.h util.h pool.h
+process.o: process.c process.h core.h fuzix_fs.h util.h pool.h
+core.o: core.c core.h pool.h
+fuzix_fs.o: fuzix_fs.c fuzix_fs.h
+
+clean:
+       rm -f process_test_run
diff --git a/moveable_core_inode_swap/o.sh b/moveable_core_inode_swap/o.sh
new file mode 100755 (executable)
index 0000000..8788480
--- /dev/null
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+echo "generate test script"
+../process_test_gen 16 248 1024 32 >process_test.txt
+
+echo "run test script"
+rm -f fs.bin
+../mkfs fs.bin 256 16384
+./process_test_run 16 64 fs.bin 8 <process_test.txt
diff --git a/moveable_core_preallocate_swap/Makefile b/moveable_core_preallocate_swap/Makefile
new file mode 100644 (file)
index 0000000..6cedec7
--- /dev/null
@@ -0,0 +1,12 @@
+CFLAGS=-g -Wall
+
+process_test_run: process_test_run.o process.o core.o swap.o pool.o
+       ${CC} ${CFLAGS} -o $@ $^
+
+process_test_run.o: process_test_run.c process.h core.h swap.h pool.h
+process.o: process.c process.h core.h swap.h pool.h
+core.o: core.c core.h pool.h
+swap.o: swap.c swap.h pool.h
+
+clean:
+       rm -f process_test_run
diff --git a/moveable_core_preallocate_swap/o.sh b/moveable_core_preallocate_swap/o.sh
new file mode 100755 (executable)
index 0000000..a0a6ff0
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+echo "generate test script"
+../process_test_gen 16 248 1024 32 >process_test.txt
+
+echo "run test script"
+./process_test_run 16 64 192 8 384 <process_test.txt
diff --git a/pp.sh b/pp.sh
new file mode 100755 (executable)
index 0000000..36186c7
--- /dev/null
+++ b/pp.sh
@@ -0,0 +1,36 @@
+#!/bin/sh -e
+mkdir --parents $1
+sed -e 's/^#include </$include </; s/^#include "rassert\.h"/$include "rassert.h"/; s/^#define DISK_/$define DISK_/; s/^#define BLOCK_/$define BLOCK_/; s/^#define UCP/$define UCP/' -i *.[ch]
+for i in \
+core.c \
+core.h \
+pool.c \
+pool.h \
+process.c \
+process.h \
+process_test_run.c \
+swap.c \
+swap.h
+do
+  (echo END; sed -e "/\\\\$/{s/.\\n//; N}; s/^\\/\\/#define .*//; s/\\/\\/.*/\"&\"/; s/^\\(#.*\\)\"\\(\\/\\/.*\\)\"$/\\1\\2/; s/^#.*/BEGIN '&'\\n&\\nEND/" <$i; echo BEGIN) >a.c
+  gcc -E a.c |sed -ne "/^END/,/^BEGIN/{s/\"\\(\\/\\/.*\\)\"$/\\1/; s/^BEGIN '\\(#include .*\\)'$/\\1/; p}" |grep -v '^\(BEGIN\|END\)' |./blank.py >$1/$i
+done
+sed -e 's/^\$/#/' -i *.[ch] $1/*.[ch]
+for i in $1/*.h
+do
+  name=`basename $i |sed -e 'y/abcdefghijklmnopqrstuvwxyz\./ABCDEFGHIJKLMNOPQRSTUVWXYZ_/'`
+  (
+    cat <<EOF
+#ifndef _$name
+#define _$name 1
+
+EOF
+    cat $i
+    cat <<EOF
+
+#endif
+EOF
+  ) >a.h
+  mv a.h $i
+done
+rm -f a.c a.h
index fa6d8c5..197ae84 100644 (file)
--- a/process.c
+++ b/process.c
@@ -91,14 +91,6 @@ void process_init(int n, int spare) {
   lru_head.next = &lru_head;
 
   victim = NULL;
-#ifndef NDEBUG
-#ifdef PREALLOCATE_CORE
-  victim_core_blocks = 0;
-#endif
-#ifdef PREALLOCATE_SWAP
-  victim_swap_blocks = 0;
-#endif
-#endif
 }
 
 static void do_swap_out(int swap_out) {
@@ -165,7 +157,7 @@ static void do_swap_out(int swap_out) {
       blocks = swap_out < victim_core_blocks ? swap_out : victim_core_blocks;
  printf("new victim %d, swap out %d of %d\n", (int)(victim - processes), blocks, victim_core_blocks);
 
-      // add to swap pool, using dedicated swap item
+      // add to swap pool
       victim_swap_blocks = 0;
 #if !defined(INODE_SWAP) && !defined(PREALLOCATE_SWAP)
       rassert(swap_table_alloc(&victim->swap_item, blocks));
@@ -212,8 +204,8 @@ static void do_swap_out(int swap_out) {
       );
 #else
       core_to_swap_copy(
-        (long)core_block << BLOCK_SHIFT,
-        (long)swap_block << BLOCK_SHIFT,
+        (long)core_base << BLOCK_SHIFT,
+        (long)swap_base << BLOCK_SHIFT,
         size
       );
 #endif
@@ -292,7 +284,7 @@ static void do_swap_out(int swap_out) {
       // see if victim fully swapped out
       if (victim_core_blocks) {
 #ifndef PREALLOCATE_CORE
-        // no, reduce core allocation, using dedicated core item
+        // no, reduce core allocation
         rassert(
           core_table_realloc_base(&victim->core_item, victim_core_blocks)
         );
@@ -566,18 +558,12 @@ void process_run(struct process *process) {
     // victim, take over the dedicated pool items
 #ifdef PREALLOCATE_CORE
     process_core_blocks = victim_core_blocks;
-#ifndef NDEBUG
-    victim_core_blocks = 0;
-#endif
 #else
     process_core_blocks =
       victim->core_item.limit - victim->core_item.base;
 #endif
 #ifdef PREALLOCATE_SWAP
     process_swap_blocks = victim_swap_blocks;
-#ifndef NDEBUG
-    victim_swap_blocks = 0;
-#endif
 #else
     process_swap_blocks =
 #ifdef INODE_SWAP
@@ -673,8 +659,8 @@ void process_run(struct process *process) {
       );
 #else
       swap_to_core_copy(
-        (long)swap_block << BLOCK_SHIFT,
-        (long)core_block << BLOCK_SHIFT,
+        (long)swap_base << BLOCK_SHIFT,
+        (long)core_base << BLOCK_SHIFT,
         size
       );
 #endif
@@ -811,9 +797,7 @@ void process_free(struct process *process) {
 #endif
     swap_block_free(swap_table_mem + swap_base, victim_swap_blocks);
 #endif
-#ifdef PREALLOCATE_SWAP
-    victim_swap_blocks = 0;
-#elif !defined(INODE_SWAP)
+#if !defined(INODE_SWAP) && !defined(PREALLOCATE_SWAP)
     swap_table_free(&victim->swap_item);
 #endif
 #ifdef INDIRECT_CORE
@@ -836,9 +820,7 @@ void process_free(struct process *process) {
 #endif
     core_block_free(core_table_mem + core_base, victim_core_blocks);
 #endif
-#ifdef PREALLOCATE_CORE
-    victim_core_blocks = 0;
-#else
+#ifndef PREALLOCATE_CORE
     core_table_free(&victim->core_item);
 #endif
     victim = NULL;
diff --git a/q.sh b/q.sh
new file mode 100755 (executable)
index 0000000..0e71219
--- /dev/null
+++ b/q.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+(cd indirect_core_indirect_swap && make && ./o.sh)
+(cd indirect_core_inode_swap && make && ./o.sh)
+(cd indirect_core_preallocate_swap && make && ./o.sh)
+(cd moveable_core_indirect_swap && make && ./o.sh)
+(cd moveable_core_inode_swap && make && ./o.sh)
+(cd moveable_core_preallocate_swap && make && ./o.sh)