Change process_get_state() calling convention slightly, replaces core_base and swap_b...
authorNick Downing <nick@ndcode.org>
Mon, 3 Jun 2019 11:30:47 +0000 (21:30 +1000)
committerNick Downing <nick@ndcode.org>
Mon, 3 Jun 2019 13:28:19 +0000 (23:28 +1000)
core.c
process.c
process.h
process_test_run.c

diff --git a/core.c b/core.c
index df069bf..4a937af 100644 (file)
--- a/core.c
+++ b/core.c
@@ -18,7 +18,6 @@ static void core_move(struct pool_item *item, int new_base) {
 #ifndef INDIRECT_CORE
   struct process *process;
   struct process_state state;
-  int para;
 #else /* INDIRECT_CORE */
   int i;
 #endif /* INDIRECT_CORE */
@@ -41,15 +40,11 @@ static void core_move(struct pool_item *item, int new_base) {
     (char *)item - offsetof(struct process, core_item)
   );
   process_get_state(process, &state);
- printf("old core [%d,%d) swap occupation [%d,%d)\n", state.core_base, state.core_base + state.core_blocks, state.swap_base, state.swap_base + state.swap_blocks);
 
   // copy valid part by abstract routine
-  para =
-    (state.core_base << BLOCK_PARAS_SHIFT) +
-    state.core_para;
   core_copy(
-    para,  
-    para + ((new_base - base) << BLOCK_PARAS_SHIFT),
+    state.core_para,
+    state.core_para + ((new_base - base) << BLOCK_PARAS_SHIFT),
     state.core_paras
   );
 #endif
@@ -89,15 +84,11 @@ static void core_move_up(struct pool_item *item, int new_limit) {
     (char *)item - offsetof(struct process, core_item)
   );
   process_get_state(process, &state);
- printf("old core [%d,%d) swap occupation [%d,%d)\n", state.core_base, state.core_base + state.core_blocks, state.swap_base, state.swap_base + state.swap_blocks);
 
   // copy valid part by abstract routine
-  para =
-    (state.core_base << BLOCK_PARAS_SHIFT) +
-    state.core_para +
-    state.core_paras;
+  para = state.core_para + state.core_paras;
   core_copy_up(
-    para,  
+    para,
     para + ((new_limit - limit) << BLOCK_PARAS_SHIFT),
     state.core_paras
   );
index 02acc2c..b9b639d 100644 (file)
--- a/process.c
+++ b/process.c
@@ -59,17 +59,17 @@ static void do_swap_read_write(
     dir
   );
 #else /* INDIRECT_SWAP */
-  int core_base, swap_base, i;
+  int core_block, swap_block, i;
 
-  core_base = process->core_item.base + block,
-  swap_base = process->swap_item.base + block,
+  core_block = process->core_item.base + block;
+  swap_block = process->swap_item.base + block;
  printf("blocks");
   for (i = 0; i < blocks; ++i)
  {
-  printf(" %s%d", dir ? "->" : "<-", swap_table_mem[swap_base + i]);
+  printf(" %s%d", dir ? "->" : "<-", swap_table_mem[swap_block + i]);
     swap_read_write(
-      core_base + i,
-      swap_table_mem[swap_base + i],
+      core_block + i,
+      swap_table_mem[swap_block + i],
       1,
       dir
     );
@@ -77,24 +77,24 @@ static void do_swap_read_write(
  printf("\n");
 #endif /* INDIRECT_SWAP */
 #else /* INDIRECT_CORE */
-  int core_base, swap_base, i;
+  int core_block, swap_block, i;
 
-  core_base = process->core_item.base + block,
-  swap_base = process->swap_item.base + block,
+  core_block = process->core_item.base + block;
+  swap_block = process->swap_item.base + block;
  printf("blocks");
   for (i = 0; i < blocks; ++i)
  {
 #ifndef INDIRECT_SWAP
-  printf(" %d%s", core_table_mem[core_base + i], dir ? "->" : "<-");
+  printf(" %d%s", core_table_mem[core_block + i], dir ? "->" : "<-");
 #else /* INDIRECT_SWAP */
-  printf(" %d%s%d", core_table_mem[core_base + i], dir ? "->" : "<-", swap_table_mem[swap_base + i]);
+  printf(" %d%s%d", core_table_mem[core_block + i], dir ? "->" : "<-", swap_table_mem[swap_block + i]);
 #endif
     swap_read_write(
-      core_table_mem[core_base + i],
+      core_table_mem[core_block + i],
 #ifndef INDIRECT_SWAP
-      swap_base + i,
+      swap_block + i,
 #else /* INDIRECT_SWAP */
-      swap_table_mem[swap_base + i],
+      swap_table_mem[swap_block + i],
 #endif
       1,
       dir
@@ -544,24 +544,25 @@ void process_free(struct process *process) {
   process->flags = 0;
 }
 
-// improve this later
+// ugh. improve this later
 void process_get_state(struct process *process, struct process_state *state) {
   int para;
 
 #ifndef INDIRECT_CORE
   if (process->flags & PROCESS_FLAGS_CORE_ITEM) {
-    state->core_base = process->core_item.base;
+    state->core_block = process->core_item.base;
     state->core_blocks = process->core_item.limit - process->core_item.base;
   }
   else {
-    state->core_base = -1;
+    state->core_block = -1;
     state->core_blocks = 0;
   }
 #else /* INDIRECT_CORE */
-  state->core_base = process->core_item.base;
+  state->core_block = process->core_item.base;
   state->core_blocks = process->core_blocks;
 #endif /* INDIRECT_CORE */
-  state->core_para = process->para;
+  state->core_para =
+    (state->core_block << BLOCK_PARAS_SHIFT) + process->para;
   state->core_paras =
     (state->core_blocks << BLOCK_PARAS_SHIFT) - process->para;
   if (state->core_paras < 0)
@@ -569,7 +570,7 @@ void process_get_state(struct process *process, struct process_state *state) {
   if (state->core_paras > process->paras)
     state->core_paras = process->paras;
 
-  state->swap_base =
+  state->swap_block =
     process->swap_item.base + state->core_blocks;
   state->swap_blocks =
     process->swap_item.limit - process->swap_item.base - state->core_blocks;
@@ -586,6 +587,9 @@ void process_get_state(struct process *process, struct process_state *state) {
   if (state->swap_paras > process->paras)
     state->swap_paras = process->paras;
   state->swap_para =
-    (state->swap_blocks << BLOCK_PARAS_SHIFT) - para - state->swap_paras;
+    (state->swap_block << BLOCK_PARAS_SHIFT) +
+    (state->swap_blocks << BLOCK_PARAS_SHIFT) -
+    para -
+    state->swap_paras;
  //printf("b %d+%d+%d=%d*%d\n", state->swap_para, state->swap_paras, para, process->swap_blocks, BLOCK_PARAS);
 }
index 81bfa3a..f93f3d4 100644 (file)
--- a/process.h
+++ b/process.h
@@ -41,11 +41,11 @@ struct process {
 
 // improve this later
 struct process_state {
-  int core_base;
+  int core_block;
   int core_blocks;
   int core_para;
   int core_paras;
-  int swap_base;
+  int swap_block;
   int swap_blocks;
   int swap_para;
   int swap_paras;
@@ -66,6 +66,6 @@ void process_free(struct process *process);
 void process_get_state(struct process *process, struct process_state *state);
  
 // abstract
-void swap_read_write(int core_base, int swap_base, int blocks, bool dir);
+void swap_read_write(int core_block, int swap_block, int blocks, bool dir);
 
 #endif
index 86387d4..72881c4 100644 (file)
@@ -90,33 +90,33 @@ void core_copy_up(int src_limit, int dest_limit, int paras) {
 #endif /* ! INDIRECT_CORE */
 
 // dir == false for read, true for write
-void swap_read_write(int core_base, int swap_base, int blocks, bool dir) {
+void swap_read_write(int core_block, int swap_block, int blocks, bool dir) {
   int i;
 
- //printf("swap_read_write core [%d,%d) %s swap [%d,%d)\n", core_base, core_base + blocks, dir ? "->" : "<-", swap_base, swap_base + blocks);
-  core_base <<= BLOCK_PARAS_SHIFT;
-  swap_base <<= BLOCK_PARAS_SHIFT;
+ //printf("swap_read_write core [%d,%d) %s swap [%d,%d)\n", core_block, core_block + blocks, dir ? "->" : "<-", swap_block, swap_block + blocks);
+  core_block <<= BLOCK_PARAS_SHIFT;
+  swap_block <<= BLOCK_PARAS_SHIFT;
   blocks <<= BLOCK_PARAS_SHIFT;
 #define paras blocks
   if (dir) {
     for (i = 0; i < paras; ++i)
-      rassert(swap_block_mem[swap_base + i] == 0xaaaaaaaa);
+      rassert(swap_block_mem[swap_block + i] == 0xaaaaaaaa);
     memcpy(
-      swap_block_mem + swap_base,
-      core_block_mem + core_base,
+      swap_block_mem + swap_block,
+      core_block_mem + core_block,
       paras * sizeof(int)
     );
-    memset(core_block_mem + core_base, 0xaa, paras * sizeof(int));
+    memset(core_block_mem + core_block, 0xaa, paras * sizeof(int));
   }
   else {
     for (i = 0; i < paras; ++i)
-      rassert(core_block_mem[core_base + i] == 0xaaaaaaaa);
+      rassert(core_block_mem[core_block + i] == 0xaaaaaaaa);
     memcpy(
-      core_block_mem + core_base,
-      swap_block_mem + swap_base,
+      core_block_mem + core_block,
+      swap_block_mem + swap_block,
       paras * sizeof(int)
     );
-    memset(swap_block_mem + swap_base, 0xaa, paras * sizeof(int));
+    memset(swap_block_mem + swap_block, 0xaa, paras * sizeof(int));
   }
 #undef paras
 }
@@ -674,16 +674,16 @@ int main(int argc, char **argv) {
           );
         }
         process_get_state(processes + test.process, &state);
- printf("old core [%d,%d) swap occupation [%d,%d)\n", state.core_base, state.core_base + state.core_blocks, state.swap_base, state.swap_base + state.swap_blocks);
+ printf("old core [%d,%d) swap occupation [%d,%d)\n", state.core_block, state.core_block + state.core_blocks, state.swap_block, state.swap_block + state.swap_blocks);
         core_hash_verify(
           test.process,
-          (state.core_base << BLOCK_PARAS_SHIFT) + state.core_para,
+          state.core_para,
           state.core_paras,
           0 
         );
         swap_hash_verify(
           test.process,
-          (state.swap_base << BLOCK_PARAS_SHIFT) + state.swap_para,
+          state.swap_para,
           state.swap_paras,
           state.core_paras
         );
@@ -707,34 +707,34 @@ done:
       printf(
         "process %d: core [%d,%d) swap occupation [%d,%d)\n",
         i,
-        state.core_base,
-        state.core_base + state.core_blocks,
-        state.swap_base,
-        state.swap_base + state.swap_blocks
+        state.core_block,
+        state.core_block + state.core_blocks,
+        state.swap_block,
+        state.swap_block + state.swap_blocks
       );
       core_hash_verify(
         i,
-        (state.core_base << BLOCK_PARAS_SHIFT) + state.core_para,
+        state.core_para,
         state.core_paras,
         0
       );
 #ifdef INDIRECT_CORE
       block_pool_free(
         &core_block_pool,
-        core_table_mem + state.core_base,
+        core_table_mem + state.core_block,
         state.core_blocks
       );
 #endif /* INDIRECT_CORE */
       swap_hash_verify(
         i,
-        (state.swap_base << BLOCK_PARAS_SHIFT) + state.swap_para,
+        state.swap_para,
         state.swap_paras,
         state.core_paras
       );
 #ifdef INDIRECT_SWAP
       block_pool_free(
         &swap_block_pool,
-        swap_table_mem + state.swap_base,
+        swap_table_mem + state.swap_block,
         state.swap_blocks
       );
 #endif /* INDIRECT_SWAP */