#endif
#ifdef INDIRECT_CORE
-void core_init(int table_size, int n_blocks)
+void core_init(int n_blocks, int table_size)
#else
-void core_init(int table_size)
+void core_init(int n_blocks)
#endif
{
pool_init(
&core_table,
0,
+#ifdef INDIRECT_CORE
table_size,
+#else
+ n_blocks,
+#endif
core_move,
#ifdef MOVEABLE_CORE
core_move_up
);
#ifdef INDIRECT_CORE
+ core_table_mem = malloc(table_size * sizeof(int));
+ rassert(core_table_mem);
+ memset(core_table_mem, 0x55, table_size * sizeof(int));
+
n_core_blocks = n_blocks;
n_core_block_bitmap = (n_core_blocks + 7) >> 3;
core_block_bitmap = malloc(n_core_block_bitmap);
core_block_bitmap[n_core_blocks >> 3] = ~masks[n_core_blocks & 7];
core_block_next = 0;
core_block_avail = n_core_blocks;
-
- core_table_mem = malloc(table_size * sizeof(int));
- rassert(core_table_mem);
- memset(core_table_mem, 0x55, table_size * sizeof(int));
+#endif
core_block_mem = malloc(n_blocks * sizeof(int));
rassert(core_block_mem);
memset(core_block_mem, 0xaa, n_blocks * sizeof(int));
-#else
- core_block_mem = malloc(table_size * sizeof(int));
- rassert(core_block_mem);
- memset(core_block_mem, 0xaa, table_size * sizeof(int));
-#endif
}
#ifdef INDIRECT_CORE
int main(int argc, char **argv) {
if (argc < 5) {
#if defined(INDIRECT_CORE) && defined(INDIRECT_SWAP)
- printf("usage: %s n_processes core_table_size swap_table_size spare [n_core_blocks [n_swap_blocks]]\n", argv[0]);
+ printf("usage: %s n_processes n_core_blocks n_swap_blocks spare [core_table_size [swap_table_size]]\n", argv[0]);
#elif defined(INDIRECT_CORE)
- printf("usage: %s n_processes core_table_size swap_table_size spare [n_core_blocks]\n", argv[0]);
+ printf("usage: %s n_processes n_core_blocks n_swap_blocks spare [core_table_size]\n", argv[0]);
#elif defined(INDIRECT_SWAP)
- printf("usage: %s n_processes core_table_size swap_table_size spare [n_swap_blocks]\n", argv[0]);
+ printf("usage: %s n_processes n_core_blocks n_swap_blocks spare [swap_table_size]\n", argv[0]);
#else
- printf("usage: %s n_processes core_table_size swap_table_size spare\n", argv[0]);
+ printf("usage: %s n_processes n_core_blocks n_swap_blocks spare\n", argv[0]);
#endif
exit(EXIT_FAILURE);
}
int n_processes = atoi(argv[1]);
- int core_table_size = atoi(argv[2]);
- int swap_table_size = atoi(argv[3]);
+ int n_core_blocks = atoi(argv[2]);
+ int n_swap_blocks = atoi(argv[3]);
int spare = atoi(argv[4]);
#if defined(INDIRECT_CORE) && defined(INDIRECT_SWAP)
- int n_core_blocks = argc >= 6 ? atoi(argv[5]) : core_table_size;
- int n_swap_blocks = argc >= 7 ? atoi(argv[6]) : swap_table_size;
+ int core_table_size = argc >= 6 ? atoi(argv[5]) : n_core_blocks;
+ int swap_table_size = argc >= 7 ? atoi(argv[6]) : n_swap_blocks;
#elif defined(INDIRECT_CORE)
- int n_core_blocks = argc >= 6 ? atoi(argv[5]) : core_table_size;
+ int core_table_size = argc >= 6 ? atoi(argv[5]) : n_core_blocks;
#elif defined(INDIRECT_SWAP)
- int n_swap_blocks = argc >= 6 ? atoi(argv[5]) : swap_table_size;
+ int swap_table_size = argc >= 6 ? atoi(argv[5]) : n_swap_blocks;
#endif
#ifdef INDIRECT_CORE
- core_init(core_table_size, n_core_blocks);
+ core_init(n_core_blocks, core_table_size);
#else
- core_init(core_table_size);
+ core_init(n_core_blocks);
#endif
#ifdef INDIRECT_SWAP
- swap_init(swap_table_size, n_swap_blocks);
+ swap_init(n_swap_blocks, swap_table_size);
#else
- swap_init(swap_table_size);
+ swap_init(n_swap_blocks);
#endif
process_init(n_processes, spare);
for (int i = 0; i < n_processes; ++i)
swap_base + swap_size
);
core_hash_verify(i, core_base, 0, core_size);
+#ifdef INDIRECT_CORE
+ core_block_free(core_table_mem + core_base, core_size);
+#endif
swap_hash_verify(i, swap_base, 0, swap_size, core_size);
+#ifdef INDIRECT_SWAP
+ swap_block_free(swap_table_mem + swap_base, swap_size);
+#endif
}
}
- for (int i = 0; i < core_table.item.base; ++i)
#ifdef INDIRECT_CORE
+ for (int i = 0; i < core_table_size; ++i)
rassert(core_table_mem[i] == 0x55555555);
- for (int i = 0; i < n_core_blocks; ++i)
+ {
+ int j = n_core_blocks >> 3;
+ for (int i = 0; i < j; ++i)
+ rassert(core_block_bitmap[i] == 0xff);
+ int k = n_core_blocks & 7;
+ if (k)
+ rassert(core_block_bitmap[j] == (uint8_t)~(-1 << k));
+ }
#endif
+ for (int i = 0; i < n_core_blocks; ++i)
rassert(core_block_mem[i] == 0xaaaaaaaa);
- int swap_limit = ~swap_table.item.base;
- for (int i = 0; i < swap_limit; ++i)
#ifdef INDIRECT_SWAP
+ for (int i = 0; i < swap_table_size; ++i)
rassert(swap_table_mem[i] == 0x55555555);
- for (int i = 0; i < n_swap_blocks; ++i)
+ {
+ int j = n_swap_blocks >> 3;
+ for (int i = 0; i < j; ++i)
+ rassert(swap_block_bitmap[i] == 0xff);
+ int k = n_swap_blocks & 7;
+ if (k)
+ rassert(swap_block_bitmap[j] == (uint8_t)~(-1 << k));
+ }
#endif
+ for (int i = 0; i < n_swap_blocks; ++i)
rassert(swap_block_mem[i] == 0xaaaaaaaa);
return 0;
#endif
#ifdef INDIRECT_SWAP
-void swap_init(int table_size, int n_blocks)
+void swap_init(int n_blocks, int table_size)
#else
-void swap_init(int table_size)
+void swap_init(int n_blocks)
#endif
{
pool_init(
&swap_table,
+#ifdef INDIRECT_SWAP
~table_size,
+#else
+ ~n_blocks,
+#endif
-1,
swap_move,
#ifdef MOVEABLE_SWAP
);
#ifdef INDIRECT_SWAP
+ swap_table_mem = malloc(table_size * sizeof(int));
+ rassert(swap_table_mem);
+ memset(swap_table_mem, 0x55, table_size * sizeof(int));
+
n_swap_blocks = n_blocks;
n_swap_block_bitmap = (n_swap_blocks + 7) >> 3;
swap_block_bitmap = malloc(n_swap_block_bitmap);
swap_block_bitmap[n_swap_blocks >> 3] = ~masks[n_swap_blocks & 7];
swap_block_next = 0;
swap_block_avail = n_swap_blocks;
-
- swap_table_mem = malloc(table_size * sizeof(int));
- rassert(swap_table_mem);
- memset(swap_table_mem, 0x55, table_size * sizeof(int));
+#endif
swap_block_mem = malloc(n_blocks * sizeof(int));
rassert(swap_block_mem);
memset(swap_block_mem, 0xaa, n_blocks * sizeof(int));
-#else
- swap_block_mem = malloc(table_size * sizeof(int));
- rassert(swap_block_mem);
- memset(swap_block_mem, 0xaa, table_size * sizeof(int));
-#endif
}
#ifdef INDIRECT_SWAP