From 119ae6d13ac4dd21cf13214f4b86564b3e7896c7 Mon Sep 17 00:00:00 2001 From: Nick Downing Date: Thu, 11 Apr 2019 22:00:05 +1000 Subject: [PATCH] Fix several more minor bugs, add gen.sh which pre-runs the C preprocessor to generate 6 specialized versions of the code --- .gitignore | 26 +++++++++++++++ blank.py | 21 +++++++++++++ core.h | 6 ++-- gen.sh | 42 +++++++++++++++++++++++++ indirect_core_indirect_swap/Makefile | 12 +++++++ indirect_core_indirect_swap/o.sh | 7 +++++ indirect_core_inode_swap/Makefile | 12 +++++++ indirect_core_inode_swap/o.sh | 9 ++++++ indirect_core_preallocate_swap/Makefile | 12 +++++++ indirect_core_preallocate_swap/o.sh | 7 +++++ moveable_core_indirect_swap/Makefile | 12 +++++++ moveable_core_indirect_swap/o.sh | 7 +++++ moveable_core_inode_swap/Makefile | 12 +++++++ moveable_core_inode_swap/o.sh | 9 ++++++ moveable_core_preallocate_swap/Makefile | 12 +++++++ moveable_core_preallocate_swap/o.sh | 7 +++++ pp.sh | 36 +++++++++++++++++++++ process.c | 34 +++++--------------- q.sh | 7 +++++ 19 files changed, 261 insertions(+), 29 deletions(-) create mode 100755 blank.py create mode 100755 gen.sh create mode 100644 indirect_core_indirect_swap/Makefile create mode 100755 indirect_core_indirect_swap/o.sh create mode 100644 indirect_core_inode_swap/Makefile create mode 100755 indirect_core_inode_swap/o.sh create mode 100644 indirect_core_preallocate_swap/Makefile create mode 100755 indirect_core_preallocate_swap/o.sh create mode 100644 moveable_core_indirect_swap/Makefile create mode 100755 moveable_core_indirect_swap/o.sh create mode 100644 moveable_core_inode_swap/Makefile create mode 100755 moveable_core_inode_swap/o.sh create mode 100644 moveable_core_preallocate_swap/Makefile create mode 100755 moveable_core_preallocate_swap/o.sh create mode 100755 pp.sh create mode 100755 q.sh diff --git a/.gitignore b/.gitignore index 9ea066b..98ec250 100644 --- a/.gitignore +++ b/.gitignore @@ -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 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 --- a/core.h +++ b/core.h @@ -4,9 +4,9 @@ #include #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 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 index 0000000..6cedec7 --- /dev/null +++ b/indirect_core_indirect_swap/Makefile @@ -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 index 0000000..c68117c --- /dev/null +++ b/indirect_core_indirect_swap/o.sh @@ -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 + +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 + +echo "run test script" +./process_test_run 16 64 192 8 384 384 process_test.txt + +echo "run test script" +./process_test_run 16 64 192 8 384 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 + +echo "run test script" +./process_test_run 16 64 192 8 384 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 <a.h + mv a.h $i +done +rm -f a.c a.h diff --git a/process.c b/process.c index fa6d8c5..197ae84 100644 --- 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 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) -- 2.34.1