From 6b832340f30403d0845db1929362401f407266a7 Mon Sep 17 00:00:00 2001 From: Nick Downing Date: Sun, 17 Mar 2019 01:03:15 +1100 Subject: [PATCH] Tidy up debugging code --- o.sh | 2 +- process.c | 37 +++++++++++++++---------------------- 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/o.sh b/o.sh index 9871ee5..95e207f 100755 --- a/o.sh +++ b/o.sh @@ -1,7 +1,7 @@ #!/bin/sh echo "generate test script" -./process_test_gen 16 224 1024 32 >process_test.txt +./process_test_gen 16 224 65536 32 >process_test.txt echo "run test" ./process_test_run 16 64 4 192 12 16 // temporary #include +#ifndef NDEBUG #include +#endif #include "core.h" #include "process.h" #include "rassert.h" @@ -17,6 +19,7 @@ struct process *victim; struct pool_item victim_core_item, victim_swap_item; #if 1 +// won't work when compiled with NDEBUG static void check_invariants() { int avail = core_head.item.base - @@ -27,18 +30,21 @@ static void check_invariants() { swap_head.spare - process_spare; if (victim) { - assert(victim_core_item.prev); - assert(victim_swap_item.prev); + assert(victim_core_item.prev && victim_core_item.next); + assert(victim_swap_item.prev && victim_core_item.next); } else { - assert(victim_core_item.prev == NULL); - assert(victim_swap_item.prev == NULL); + assert(victim_core_item.prev == NULL && victim_core_item.next == NULL); + assert(victim_swap_item.prev == NULL && victim_swap_item.prev == NULL); } for (int i = 0; i < n_processes; ++i) if (processes[i].size != -1) { if (processes + i == victim) { assert(processes[i].lru_item.prev == NULL); - assert(processes[i].pool_item.prev == NULL); + assert( + processes[i].pool_item.prev == NULL && + processes[i].pool_item.next == NULL + ); assert( processes[i].size == victim_core_item.limit - @@ -80,8 +86,10 @@ void process_init(int n, int spare) { lru_head.next = &lru_head; victim = NULL; +#ifndef NDEBUG memset(&victim_core_item, 0, sizeof(victim_core_item)); memset(&victim_swap_item, 0, sizeof(victim_swap_item)); +#endif check_invariants(); } @@ -98,11 +106,9 @@ static void do_swap_out(int swap_out) { printf("victimized %d\n", (int)(victim - processes)); // remove from core pool, using dedicated core item pool_free(&core_head, &victim_core_item); - victim_core_item.prev = NULL; // move dedicated to per-process swap item pool_move_item(&victim_swap_item, &victim->pool_item); - victim_swap_item.prev = NULL; no_victim: // take next least recently used process as victim @@ -117,7 +123,6 @@ static void do_swap_out(int swap_out) { // move per-process to dedicated core item pool_move_item(&victim->pool_item, &victim_core_item); - victim->pool_item.prev = NULL; // add to swap pool, using dedicated swap item rassert(pool_alloc_moveable(&swap_head, &victim_swap_item, 0)); @@ -232,25 +237,21 @@ void process_run(struct process *process) { } else { // no, need to swap some in +#ifndef NDEBUG memset(&process_core_item, 0, sizeof(process_core_item)); memset(&process_swap_item, 0, sizeof(process_swap_item)); +#endif // see whether victim or fully in swap if (process == victim) { // victim, take over the dedicated pool items victim = NULL; - pool_move_item(&victim_core_item, &process_core_item); - victim_core_item.prev = NULL; - pool_move_item(&victim_swap_item, &process_swap_item); - victim_swap_item.prev = NULL; } else { // fully in swap, take over only the per-process swap item pool_move_item(&process->pool_item, &process_swap_item); - process->pool_item.prev = NULL; - rassert(pool_alloc_moveable(&core_head, &process_core_item, 0)); } @@ -299,11 +300,9 @@ void process_run(struct process *process) { // move dedicated to per-process core item pool_move_item(&process_core_item, &process->pool_item); - //process_core_item.prev = NULL; // remove from swap pool, using dedicated swap item pool_free(&swap_head, &process_swap_item); - //process_swap_item.prev = NULL; } // insert at head of LRU list @@ -327,22 +326,16 @@ void process_free(struct process *process) { process->lru_item.next->prev = process->lru_item.prev; pool_free(&core_head, &process->pool_item); - process->pool_item.prev = NULL; } else if (process == victim) { // victim, free the dedicated pool items victim = NULL; - pool_free(&core_head, &victim_core_item); - victim_core_item.prev = NULL; - pool_free(&swap_head, &victim_swap_item); - victim_swap_item.prev = NULL; } else { // fully in swap, remove from swap pool pool_free(&swap_head, &process->pool_item); - process->pool_item.prev = NULL; } // track total allocation -- 2.34.1