Expand out the swap_read()/swap_write() functions inline, since they were only called...
authorNick Downing <nick@ndcode.org>
Tue, 9 Apr 2019 10:13:52 +0000 (20:13 +1000)
committerNick Downing <nick@ndcode.org>
Tue, 9 Apr 2019 10:13:52 +0000 (20:13 +1000)
core.c
core.h
process.c
process.h
swap.c
swap.h

diff --git a/core.c b/core.c
index 43d6a46..f9dd489 100644 (file)
--- a/core.c
+++ b/core.c
@@ -203,4 +203,3 @@ void core_block_free(int *table, int size) {
   core_block_avail += size;
 }
 #endif
-
diff --git a/core.h b/core.h
index 2eaf017..2bc3d74 100644 (file)
--- a/core.h
+++ b/core.h
@@ -7,8 +7,6 @@
 //#define PREALLOCATE_CORE 1
 //#define INDIRECT_CORE 1
 #define MOVEABLE_CORE 1
-#define BLOCK_SIZE 0x1000
-#define BLOCK_SHIFT 12
 
 #ifdef MOVEABLE_CORE
 #define core_table_alloc(item, size) \
index 4abeb37..be68d10 100644 (file)
--- a/process.c
+++ b/process.c
@@ -169,6 +169,9 @@ static void do_swap_out(int swap_out) {
 #endif
   int blocks, swap_base, core_base;
   long size;
+#if defined(INDIRECT_CORE) || defined(INDIRECT_SWAP)
+  int i, j;
+#endif
 
   // loop entry code for the case of an existing victim
   if (swap_out > 0) {
@@ -242,7 +245,62 @@ static void do_swap_out(int swap_out) {
 #ifdef INDIRECT_SWAP
       rassert(swap_block_alloc(swap_table_mem + swap_base, blocks));
 #endif
-      swap_write(core_base, swap_base, size);
+ printf("swap_write core [%d,%d) to swap [%d,%d)\n", core_base, core_base + blocks, swap_base, swap_base + blocks);
+#if !defined(INDIRECT_CORE) && !defined(INDIRECT_SWAP)
+      core_to_swap_copy(
+        (long)core_block << BLOCK_SHIFT,
+        (long)swap_block << BLOCK_SHIFT,
+        size
+      );
+#else
+      j = (int)(size >> BLOCK_SHIFT);
+ printf("blocks");
+      for (i = 0; i < j; ++i) {
+        int core_block = core_base + i;
+#ifdef INDIRECT_CORE
+        core_block = core_table_mem[core_block];
+ printf(" %d", core_block);
+#endif
+        int swap_block = swap_base + i;
+#ifdef INDIRECT_SWAP
+        swap_block = swap_table_mem[swap_block];
+#ifdef INDIRECT_CORE
+ printf(",%d", swap_block);
+#else
+ printf(" %d", swap_block);
+#endif
+#endif
+        core_to_swap_copy(
+          (long)core_block << BLOCK_SHIFT,
+          (long)swap_block << BLOCK_SHIFT,
+          BLOCK_SIZE
+        );
+      }
+      j = (int)size & (BLOCK_SIZE - 1);
+      if (j) {
+        int core_block = core_base + i;
+#ifdef INDIRECT_CORE
+        core_block = core_table_mem[core_block];
+ printf(" %d", core_block);
+#endif
+        int swap_block = swap_base + i;
+#ifdef INDIRECT_SWAP
+        swap_block = swap_table_mem[swap_block];
+#ifdef INDIRECT_CORE
+ printf(",%d", swap_block);
+#else
+ printf(" %d", swap_block);
+#endif
+#endif
+ putchar('*');
+        core_to_swap_copy(
+          (long)core_block << BLOCK_SHIFT,
+          (long)swap_block << BLOCK_SHIFT,
+          j
+        );
+      }
+ printf("\n");
+#endif
 #ifdef INDIRECT_CORE
       core_block_free(core_table_mem + core_base, blocks);
 #endif
@@ -409,6 +467,9 @@ void process_run(struct process *process) {
   int process_core_blocks, process_swap_blocks;
   int swap_base, core_base;
   long size;
+#if defined(INDIRECT_CORE) || defined(INDIRECT_SWAP)
+  int i, j;
+#endif
 
   // must be already allocated
   assert(process->size != -1L);
@@ -532,7 +593,62 @@ void process_run(struct process *process) {
 #ifdef INDIRECT_CORE
       core_block_alloc(core_table_mem + core_base, blocks);
 #endif
-      swap_read(swap_base, core_base, size);
+ printf("swap_read swap [%d,%d) to core [%d,%d)\n", swap_base, swap_base + blocks, core_base, core_base + blocks);
+#if !defined(INDIRECT_CORE) && !defined(INDIRECT_SWAP)
+      swap_to_core_copy(
+        (long)swap_block << BLOCK_SHIFT,
+        (long)core_block << BLOCK_SHIFT,
+        size
+      );
+#else
+      j = (int)(size >> BLOCK_SHIFT);
+ printf("blocks");
+      for (i = 0; i < j; ++i) {
+        int swap_block = swap_base + i;
+#ifdef INDIRECT_SWAP
+        swap_block = swap_table_mem[swap_block];
+ printf(" %d", swap_block);
+#endif
+        int core_block = core_base + i;
+#ifdef INDIRECT_CORE
+        core_block = core_table_mem[core_block];
+#ifdef INDIRECT_SWAP
+ printf(",%d", core_block);
+#else
+ printf(" %d", core_block);
+#endif
+#endif
+        swap_to_core_copy(
+          (long)swap_block << BLOCK_SHIFT,
+          (long)core_block << BLOCK_SHIFT,
+          BLOCK_SIZE
+        );
+      }
+      j = (int)size & (BLOCK_SIZE - 1);
+      if (j) {
+        int swap_block = swap_base + i;
+#ifdef INDIRECT_SWAP
+        swap_block = swap_table_mem[swap_block];
+ printf(" %d", swap_block);
+#endif
+        int core_block = core_base + i;
+#ifdef INDIRECT_CORE
+        core_block = core_table_mem[core_block];
+#ifdef INDIRECT_SWAP
+ printf(",%d", core_block);
+#else
+ printf(" %d", core_block);
+#endif
+#endif
+ putchar('*');
+        swap_to_core_copy(
+          (long)swap_block << BLOCK_SHIFT,
+          (long)core_block << BLOCK_SHIFT,
+          j 
+        );
+      }
+ printf("\n");
+#endif
 #ifdef INDIRECT_SWAP
       swap_block_free(swap_table_mem + swap_base, blocks);
 #endif
index 10b9a33..aa82c82 100644 (file)
--- a/process.h
+++ b/process.h
@@ -3,6 +3,9 @@
 
 #include "pool.h"
 
+#define BLOCK_SIZE 0x1000
+#define BLOCK_SHIFT 12
+
 struct lru_item {
   struct lru_item *prev;
   struct lru_item *next;
@@ -28,4 +31,8 @@ bool process_realloc(struct process *process, long size);
 void process_run(struct process *process);
 void process_free(struct process *process);
  
+// abstract
+void core_to_swap_copy(long src_base, long dest_base, long size);
+void swap_to_core_copy(long src_base, long dest_base, long size);
+
 #endif
diff --git a/swap.c b/swap.c
index db6c120..20b76ae 100644 (file)
--- a/swap.c
+++ b/swap.c
@@ -2,9 +2,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include "core.h"
-#include "process.h"
 #include "swap.h"
+#include "process.h"
 #include "rassert.h"
 
 struct pool_head swap_table;
@@ -204,128 +203,3 @@ void swap_block_free(int *table, int size) {
   swap_block_avail += size;
 }
 #endif
-
-// bases are in blocks, size is in bytes (allows incomplete last block)
-void swap_read(int swap_base, int core_base, long size) {
-#if !defined(INDIRECT_CORE) && !defined(INDIRECT_SWAP)
- int blocks = (int)(size >> BLOCK_SHIFT);
- int partial = (int)size & (BLOCK_SIZE - 1);
- printf("swap_read swap [%d,%d) to core [%d,%d)\n", swap_base, swap_base + blocks + (partial != 0), core_base, core_base + blocks + (partial != 0));
-  swap_to_core_copy(
-    (long)swap_block << BLOCK_SHIFT,
-    (long)core_block << BLOCK_SHIFT,
-    size
-  );
-#else
-  int blocks = (int)(size >> BLOCK_SHIFT);
-  int partial = (int)size & (BLOCK_SIZE - 1);
- printf("swap_read swap [%d,%d) to core [%d,%d)\n", swap_base, swap_base + blocks + (partial != 0), core_base, core_base + blocks + (partial != 0));
- printf("blocks");
-  for (int i = 0; i < blocks; ++i) {
-    int swap_block = swap_base + i;
-#ifdef INDIRECT_SWAP
-    swap_block = swap_table_mem[swap_block];
- printf(" %d", swap_block);
-#endif
-    int core_block = core_base + i;
-#ifdef INDIRECT_CORE
-    core_block = core_table_mem[core_block];
-#ifdef INDIRECT_SWAP
- printf(",%d", core_block);
-#else
- printf(" %d", core_block);
-#endif
-#endif
-    swap_to_core_copy(
-      (long)swap_block << BLOCK_SHIFT,
-      (long)core_block << BLOCK_SHIFT,
-      BLOCK_SIZE
-    );
-  }
-  if (partial) {
-    int swap_block = swap_base + blocks;
-#ifdef INDIRECT_SWAP
-    swap_block = swap_table_mem[swap_block];
- printf(" %d", swap_block);
-#endif
-    int core_block = core_base + blocks;
-#ifdef INDIRECT_CORE
-    core_block = core_table_mem[core_block];
-#ifdef INDIRECT_SWAP
- printf(",%d", core_block);
-#else
- printf(" %d", core_block);
-#endif
-#endif
- putchar('*');
-    swap_to_core_copy(
-      (long)swap_block << BLOCK_SHIFT,
-      (long)core_block << BLOCK_SHIFT,
-      partial
-    );
-  }
- printf("\n");
-#endif
-}
-
-void swap_write(int core_base, int swap_base, long size) {
-#if !defined(INDIRECT_CORE) && !defined(INDIRECT_SWAP)
- int blocks = (int)(size >> BLOCK_SHIFT);
- int partial = (int)size & (BLOCK_SIZE - 1);
- printf("swap_write core [%d,%d) to swap [%d,%d)\n", core_base, core_base + blocks + (partial != 0), swap_base, swap_base + blocks + (partial != 0));
-  core_to_swap_copy(
-    (long)core_block << BLOCK_SHIFT,
-    (long)swap_block << BLOCK_SHIFT,
-    size
-  );
-#else
-  int blocks = (int)(size >> BLOCK_SHIFT);
-  int partial = (int)size & (BLOCK_SIZE - 1);
- printf("swap_write core [%d,%d) to swap [%d,%d)\n", core_base, core_base + blocks + (partial != 0), swap_base, swap_base + blocks + (partial != 0));
- printf("blocks");
-  for (int i = 0; i < blocks; ++i) {
-    int core_block = core_base + i;
-#ifdef INDIRECT_CORE
-    core_block = core_table_mem[core_block];
- printf(" %d", core_block);
-#endif
-    int swap_block = swap_base + i;
-#ifdef INDIRECT_SWAP
-    swap_block = swap_table_mem[swap_block];
-#ifdef INDIRECT_CORE
- printf(",%d", swap_block);
-#else
- printf(" %d", swap_block);
-#endif
-#endif
-    core_to_swap_copy(
-      (long)core_block << BLOCK_SHIFT,
-      (long)swap_block << BLOCK_SHIFT,
-      BLOCK_SIZE
-    );
-  }
-  if (partial) {
-    int core_block = core_base + blocks;
-#ifdef INDIRECT_CORE
-    core_block = core_table_mem[core_block];
- printf(" %d", core_block);
-#endif
-    int swap_block = swap_base + blocks;
-#ifdef INDIRECT_SWAP
-    swap_block = swap_table_mem[swap_block];
-#ifdef INDIRECT_CORE
- printf(",%d", swap_block);
-#else
- printf(" %d", swap_block);
-#endif
-#endif
- putchar('*');
-    core_to_swap_copy(
-      (long)core_block << BLOCK_SHIFT,
-      (long)swap_block << BLOCK_SHIFT,
-      partial
-    );
-  }
- printf("\n");
-#endif
-}
diff --git a/swap.h b/swap.h
index ba77844..15352ff 100644 (file)
--- a/swap.h
+++ b/swap.h
@@ -58,11 +58,4 @@ void swap_copy(long src_base, long dest_base, long size);
 void swap_copy_up(long src_limit, long dest_limit, long size);
 #endif
 
-void swap_read(int swap_base, int core_base, long size);
-void swap_write(int core_base, int swap_base, long size);
-
-// abstract
-void core_to_swap_copy(long src_base, long dest_base, long size);
-void swap_to_core_copy(long src_base, long dest_base, long size);
-
 #endif