*.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
--- /dev/null
+#!/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
#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) \
--- /dev/null
+#!/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
--- /dev/null
+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
--- /dev/null
+#!/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
--- /dev/null
+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
--- /dev/null
+#!/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
--- /dev/null
+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
--- /dev/null
+#!/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
--- /dev/null
+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
--- /dev/null
+#!/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
--- /dev/null
+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
--- /dev/null
+#!/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
--- /dev/null
+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
--- /dev/null
+#!/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
--- /dev/null
+#!/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
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) {
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));
);
#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
// 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)
);
// 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
);
#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
#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
#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;
--- /dev/null
+#!/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)