#endif
void core_hash_init(int process, long base, long size, long offset) {
+ long i, addr;
+ long long hash;
+
//printf("core_hash_init %d %ld(%d) %ld(%d) %ld(%d)\n", process, base, (int)(base >> BLOCK_SHIFT), size, (int)((size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT), offset, (int)(offset >> BLOCK_SHIFT));
- for (long i = 0L; i < size; ++i) {
- long addr = base + i;
+ for (i = 0L; i < size; ++i) {
+ addr = base + i;
#ifdef INDIRECT_CORE
addr =
(core_table_mem[addr >> BLOCK_SHIFT] << BLOCK_SHIFT) |
(addr & (BLOCK_SIZE - 1));
#endif
- long long hash = process * 17 + (i + offset) * 29;
+ hash = process * 17 + (i + offset) * 29;
hash = (hash & 0xffffffffLL) + (hash >> 32);
hash = (hash & 0xffffLL) + (hash >> 16);
hash = (hash & 0xffLL) + (hash >> 8);
}
void core_hash_verify(int process, long base, long size, long offset) {
+ long i, addr;
+ long long hash;
+
//printf("core_hash_verify %d %ld(%d) %ld(%d) %ld(%d)\n", process, base, (int)(base >> BLOCK_SHIFT), size, (int)((size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT), offset, (int)(offset >> BLOCK_SHIFT));
- for (long i = 0L; i < size; ++i) {
- long addr = base + i;
+ for (i = 0L; i < size; ++i) {
+ addr = base + i;
#ifdef INDIRECT_CORE
addr =
(core_table_mem[addr >> BLOCK_SHIFT] << BLOCK_SHIFT) |
(addr & (BLOCK_SIZE - 1));
#endif
- long long hash = process * 17 + (i + offset) * 29;
+ hash = process * 17 + (i + offset) * 29;
hash = (hash & 0xffffffffLL) + (hash >> 32);
hash = (hash & 0xffffLL) + (hash >> 16);
hash = (hash & 0xffLL) + (hash >> 8);
#ifdef INODE_SWAP
void swap_hash_verify(int process, struct cinode *inode) {
- long count;
+ long offset, count;
+ uint8_t buf[TRANSFER_SIZE];
+ int i;
+ long long hash;
+
for (
- long offset = 0;
+ offset = 0;
(count = (long)inode->c_node.i_size - offset) > 0;
offset += count
) {
if (count > TRANSFER_SIZE)
count = TRANSFER_SIZE;
- uint8_t buf[TRANSFER_SIZE];
udata.u_base = (char *)buf;
udata.u_count = count;
udata.u_offset = offset;
udata.u_error = 0;
rassert(readi(inode) == count && udata.u_error == 0);
- for (int i = 0; i < count; ++i) {
- long long hash = process * 17 + (i + offset) * 29;
+ for (i = 0; i < count; ++i) {
+ hash = process * 17 + (i + offset) * 29;
hash = (hash & 0xffffffffLL) + (hash >> 32);
hash = (hash & 0xffffLL) + (hash >> 16);
hash = (hash & 0xffLL) + (hash >> 8);
}
#else
void swap_hash_verify(int process, long base, long size) {
+ long i, addr;
+ long long hash;
+
//printf("swap_hash_verify %d %ld(%d) %ld(%d)\n", process, base, (int)(base >> BLOCK_SHIFT), size, (int)((size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT));
- for (long i = 0L; i < size; ++i) {
- long addr = base + i;
+ for (i = 0L; i < size; ++i) {
+ addr = base + i;
#ifdef INDIRECT_SWAP
addr =
(swap_table_mem[addr >> BLOCK_SHIFT] << BLOCK_SHIFT) |
(addr & (BLOCK_SIZE - 1));
#endif
- long long hash = process * 17 + i * 29;
+ hash = process * 17 + i * 29;
hash = (hash & 0xffffffffLL) + (hash >> 32);
hash = (hash & 0xffffLL) + (hash >> 16);
hash = (hash & 0xffLL) + (hash >> 8);
#ifndef INDIRECT_CORE
void core_copy(long src_base, long dest_base, long size) {
+ long i;
+
//printf("core_copy %ld(%d) %ld(%d) %ld(%d)\n", src_base, (int)(src_base >> BLOCK_SHIFT), dest_base, (int)(dest_base >> BLOCK_SHIFT), size, (int)((size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT));
- for (long i = 0L; i < size; ++i) {
+ for (i = 0L; i < size; ++i) {
core_block_mem[dest_base + i] = core_block_mem[src_base + i];
#ifndef NDEBUG
core_block_mem[src_base + i] = 0xaa;
}
void core_copy_up(long src_limit, long dest_limit, long size) {
+ long i;
+
//printf("core_copy_up %ld(%d) %ld(%d) %ld(%d)\n", src_limit, (int)(src_limit >> BLOCK_SHIFT), dest_limit, (int)(dest_limit >> BLOCK_SHIFT), size, (int)((size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT));
size = -size;
- for (long i = -1L; i >= size; --i) {
+ for (i = -1L; i >= size; --i) {
core_block_mem[dest_limit + i] = core_block_mem[src_limit + i];
#ifndef NDEBUG
core_block_mem[src_limit + i] = 0xaa;
long core_base,
long size
) {
+ long i, count;
+
//printf("swap_read %d %ld %ld %ld\n", inode->c_num, offset, core_base, size);
- for (long i = 0; i < size; ++i)
+ for (i = 0; i < size; ++i)
rassert(core_block_mem[core_base + i] == 0xaa);
- long count;
- for (long i = 0; (count = size - i) > 0; i += count) {
+ for (i = 0; (count = size - i) > 0; i += count) {
if (count > TRANSFER_SIZE)
count = TRANSFER_SIZE;
long core_base,
long size
) {
+ long i, count;
+
//printf("swap_write %d %ld %ld %ld\n", inode->c_num, offset, core_base, size);
- long count;
- for (long i = 0; (count = size - i) > 0; i += count) {
+ for (i = 0; (count = size - i) > 0; i += count) {
if (count > TRANSFER_SIZE)
count = TRANSFER_SIZE;
#else
#ifndef INDIRECT_SWAP
void swap_copy(long src_base, long dest_base, long size) {
+ long i;
+
//printf("swap_copy %ld(%d) %ld(%d) %ld(%d)\n", src_base, (int)(src_base >> BLOCK_SHIFT), dest_base, (int)(dest_base >> BLOCK_SHIFT), size, (int)((size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT));
- for (long i = 0; i < size; ++i) {
+ for (i = 0; i < size; ++i) {
swap_block_mem[dest_base + i] = swap_block_mem[src_base + i];
#ifndef NDEBUG
swap_block_mem[src_base + i] = 0x55;
}
void swap_copy_up(long src_limit, long dest_limit, long size) {
+ long i;
+
//printf("swap_copy_up %ld(%d) %ld(%d) %ld(%d)\n", src_limit, (int)(src_limit >> BLOCK_SHIFT), dest_limit, (int)(dest_limit >> BLOCK_SHIFT), size, (int)((size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT));
size = -size;
- for (long i = -1; i >= size; --i) {
+ for (i = -1; i >= size; --i) {
swap_block_mem[dest_limit + i] = swap_block_mem[src_limit + i];
#ifndef NDEBUG
swap_block_mem[src_limit + i] = 0x55;
#endif
void core_to_swap_copy(long src_base, long dest_base, long size) {
+ long i;
+
//printf("core_to_swap_copy %ld(%d) %ld(%d) %ld(%d)\n", src_base, (int)(src_base >> BLOCK_SHIFT), dest_base, (int)(dest_base >> BLOCK_SHIFT), size, (int)((size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT));
- for (long i = 0; i < size; ++i)
+ for (i = 0; i < size; ++i)
assert(swap_block_mem[dest_base + i] == 0xaa);
memcpy(swap_block_mem + dest_base, core_block_mem + src_base, size);
memset(core_block_mem + src_base, 0xaa, size);
}
void swap_to_core_copy(long src_base, long dest_base, long size) {
+ long i;
+
//printf("swap_to_core_copy %ld(%d) %ld(%d) %ld(%d)\n", src_base, (int)(src_base >> BLOCK_SHIFT), dest_base, (int)(dest_base >> BLOCK_SHIFT), size, (int)((size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT));
- for (long i = 0; i < size; ++i)
+ for (i = 0; i < size; ++i)
assert(core_block_mem[dest_base + i] == 0xaa);
memcpy(core_block_mem + dest_base, swap_block_mem + src_base, size);
memset(swap_block_mem + src_base, 0xaa, size);
#endif
int main(int argc, char **argv) {
+ int n_processes;
+ int n_core_blocks;
+#ifdef INODE_SWAP
+ char *fs_path;
+#else
+ int n_swap_blocks;
+#endif
+ int spare;
+#ifdef INDIRECT_CORE
+ int core_table_blocks;
+#endif
+#ifdef INDIRECT_SWAP
+ int swap_table_blocks;
+#endif
+#if defined(INDIRECT_CORE) || defined(INDIRECT_SWAP)
+ int i, j, k;
+#else
+ int i, j;
+#endif
+ char buf[256];
+ int process;
+ bool success, result;
+ long old_size, size, actual_old_size;
+ int old_blocks, blocks, actual_old_blocks;
+ int swap_base, swap_blocks;
+ long swap_size;
+ int core_base, core_blocks;
+ long core_size;
+
if (argc < 5) {
printf(
"usage: %s n_processes n_core_blocks "
);
exit(EXIT_FAILURE);
}
- int n_processes = atoi(argv[1]);
- int n_core_blocks = atoi(argv[2]);
+ n_processes = atoi(argv[1]);
+ n_core_blocks = atoi(argv[2]);
#ifdef INODE_SWAP
- char *fs_path = argv[3];
+ fs_path = argv[3];
#else
- int n_swap_blocks = atoi(argv[3]);
+ n_swap_blocks = atoi(argv[3]);
#endif
- int spare = atoi(argv[4]);
+ spare = atoi(argv[4]);
#if defined(INDIRECT_CORE) && defined(INDIRECT_SWAP)
- int core_table_blocks = argc >= 6 ? atoi(argv[5]) : n_core_blocks;
- int swap_table_blocks = argc >= 7 ? atoi(argv[6]) : n_swap_blocks;
+ core_table_blocks = argc >= 6 ? atoi(argv[5]) : n_core_blocks;
+ swap_table_blocks = argc >= 7 ? atoi(argv[6]) : n_swap_blocks;
#elif defined(INDIRECT_CORE)
- int core_table_blocks = argc >= 6 ? atoi(argv[5]) : n_core_blocks;
+ core_table_blocks = argc >= 6 ? atoi(argv[5]) : n_core_blocks;
#elif defined(INDIRECT_SWAP)
- int swap_table_blocks = argc >= 6 ? atoi(argv[5]) : n_swap_blocks;
+ swap_table_blocks = argc >= 6 ? atoi(argv[5]) : n_swap_blocks;
#endif
#ifdef INDIRECT_CORE
#endif
process_init(n_processes, spare);
- for (int i = 0; i < n_processes; ++i)
+ for (i = 0; i < n_processes; ++i)
processes[i].size = -1L;
while (true) {
//printf("avail %d %d(%d) %d(%d)\n", process_avail, core_avail(), core_table.avail, swap_avail(), swap_table.avail);
- char buf[256];
switch (scanf("%s", buf)) {
case -1:
goto done;
rassert(false);
}
if (strcmp(buf, "alloc") == 0) {
- int process;
- long size;
rassert(scanf("%d %ld %s", &process, &size, buf) == 3);
rassert(process >= 0 && process < n_processes);
rassert(size >= 0);
- bool success;
if (strcmp(buf, "false") == 0)
success = false;
else if (strcmp(buf, "true") == 0)
success ? "true" : "false"
);
rassert(processes[process].size == -1L);
- bool result = process_alloc(processes + process, size);
+ result = process_alloc(processes + process, size);
printf(
"... %s\n",
result == success ?
processes[process].size = -1L;
}
else {
- int core_base = processes[process].core_item.base;
- int blocks = (int)((size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT);
+ core_base = processes[process].core_item.base;
+ blocks = (int)((size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT);
assert(
processes[process].core_item.limit ==
core_base + blocks
}
}
else if (strcmp(buf, "realloc") == 0) {
- int process;
- long old_size, size;
rassert(scanf("%d %ld %ld %s", &process, &old_size, &size, buf) == 4);
rassert(process >= 0 && process < n_processes);
rassert(old_size >= 0);
rassert(size >= 0);
- bool success;
if (strcmp(buf, "false") == 0)
success = false;
else if (strcmp(buf, "true") == 0)
if (processes[process].size == -1L)
printf("... not allocated, ignore\n");
else {
- int core_base = processes[process].core_item.base;
- long actual_old_size = processes[process].size;
- int actual_old_blocks =
+ core_base = processes[process].core_item.base;
+ actual_old_size = processes[process].size;
+ actual_old_blocks =
(int)((actual_old_size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT);
rassert(
processes[process].core_item.limit ==
core_base + actual_old_blocks
);
- int old_blocks = (int)((old_size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT);
+ old_blocks = (int)((old_size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT);
if (actual_old_blocks != old_blocks) {
printf(
"... old blocks %d, should be %d\n",
actual_old_size - size,
size
);
- bool result = process_realloc(processes + process, size);
+ result = process_realloc(processes + process, size);
printf(
"... %s\n",
result == success ?
}
else {
core_base = processes[process].core_item.base;
- int blocks = (int)((size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT);
+ blocks = (int)((size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT);
rassert(
processes[process].core_item.limit ==
core_base + blocks
}
}
else if (strcmp(buf, "run") == 0) {
- int process;
rassert(scanf("%d", &process) == 1);
rassert(process >= 0 && process < n_processes);
printf("run %d\n", process);
}
}
else if (strcmp(buf, "free") == 0) {
- int process;
- long old_size;
rassert(scanf("%d %ld", &process, &old_size) == 2);
rassert(process >= 0 && process < n_processes);
rassert(old_size >= 0);
if (processes[process].size == -1L)
printf("... not allocated, ignore\n");
else {
- int actual_old_blocks =
+ actual_old_blocks =
(int)((processes[process].size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT);
- int old_blocks =
+ old_blocks =
(int)((old_size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT);
if (actual_old_blocks != old_blocks) {
printf(
);
rassert(actual_old_blocks <= old_blocks);
}
- int swap_base, swap_blocks;
- long swap_size;
- int core_base, core_blocks;
- long core_size;
if (processes[process].lru_item.prev != NULL) { // fully in core
assert(processes + process != victim);
swap_base = -1;
done:
printf("final state:\n");
- for (int i = 0; i < n_processes; ++i) {
+ for (i = 0; i < n_processes; ++i) {
if (processes[i].size == -1L)
printf("process %d: not allocated\n", i);
else {
- int swap_base, swap_blocks;
- long swap_size;
- int core_base, core_blocks;
- long core_size;
if (processes[i].lru_item.prev != NULL) { // fully in core
assert(processes + i != victim);
swap_base = -1;
}
#ifdef INDIRECT_CORE
- for (int i = 0; i < core_table_blocks; ++i)
+ for (i = 0; i < core_table_blocks; ++i)
rassert(core_table_mem[i] == 0x55555555);
{
- 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;
+ k = n_core_blocks >> 3;
+ for (j = 0; j < k; ++j)
+ rassert(core_block_bitmap[j] == 0xff);
+ k = n_core_blocks & 7;
if (k)
rassert(core_block_bitmap[j] == (uint8_t)~(-1 << k));
}
#endif
- {
- int j = n_core_blocks << BLOCK_SHIFT;
- for (int i = 0; i < j; ++i)
- rassert(core_block_mem[i] == 0xaa);
- }
+ j = n_core_blocks << BLOCK_SHIFT;
+ for (i = 0; i < j; ++i)
+ rassert(core_block_mem[i] == 0xaa);
#ifdef INODE_SWAP
printf("free inodes %d blocks %d\n", fs_tab[0].s_tinode, fs_tab[0].s_tfree);
#else
#ifdef INDIRECT_SWAP
- for (int i = 0; i < swap_table_blocks; ++i)
+ for (i = 0; i < swap_table_blocks; ++i)
rassert(swap_table_mem[i] == 0x55555555);
{
- 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;
+ k = n_swap_blocks >> 3;
+ for (j = 0; j < k; ++j)
+ rassert(swap_block_bitmap[j] == 0xff);
+ k = n_swap_blocks & 7;
if (k)
rassert(swap_block_bitmap[j] == (uint8_t)~(-1 << k));
}
#endif
- {
- int j = n_swap_blocks << BLOCK_SHIFT;
- for (int i = 0; i < j; ++i)
- rassert(swap_block_mem[i] == 0xaa);
- }
+ j = n_swap_blocks << BLOCK_SHIFT;
+ for (i = 0; i < j; ++i)
+ rassert(swap_block_mem[i] == 0xaa);
#endif
return 0;