From e8bb8088a7d62c9357b35a08a3db82dfcc1c5da1 Mon Sep 17 00:00:00 2001 From: 410 Date: Mon, 19 Jun 2017 19:48:30 -0500 Subject: [PATCH] Something wrong with get_frames. --- MP2/MP2_Sources/cont_frame_pool.C | 119 +++++++++++++++++++----------- MP2/MP2_Sources/kernel.C | 5 +- 2 files changed, 77 insertions(+), 47 deletions(-) diff --git a/MP2/MP2_Sources/cont_frame_pool.C b/MP2/MP2_Sources/cont_frame_pool.C index a0c4516..bbfde02 100644 --- a/MP2/MP2_Sources/cont_frame_pool.C +++ b/MP2/MP2_Sources/cont_frame_pool.C @@ -186,22 +186,23 @@ ContFramePool::ContFramePool(unsigned long _base_frame_no, { unsigned int i = info_frame_no / 4; unsigned int r = info_frame_no % 4; - unsigned char mask = 0xC0; + unsigned char mask = 0x80; mask = mask >> r*2; unsigned int c = 0; while(c < n_info_frames) { bitmap[i] = bitmap[i] ^ mask; + bitmap[i] = bitmap[i] ^ (mask >> 1); if(mask == 0x02) { i++; - mask = 0xC0; + mask = 0x80; } c++; + nFreeFrames--; } - nFreeFrames--; } Console::puts("Frame Pool initialized\n"); @@ -211,7 +212,7 @@ unsigned long ContFramePool::get_frames(unsigned int _n_frames) { // Are there enough frames left to allocate? assert(nFreeFrames > _n_frames); - + // Find a frame that is not being used and return its frame index. // Mark that frame as being used in the bitmap. // NOTE: Must be updated to find a sequence of contiguous frames @@ -226,78 +227,77 @@ unsigned long ContFramePool::get_frames(unsigned int _n_frames) unsigned int j = 0; unsigned int c = 0; - // used as a simple way to check if we failed to find a free - // frame for an index i in the bitmap. - bool failed = false; - while (true) { - unsigned char mask = 0x80; + //Console::puts("Entered first loop"); + unsigned char mask = 0x80 >> (j*2); // check every 2 bits for a free frame in the bitmap while((mask & bitmap[i]) == 0 || ((mask >> 1) & bitmap[i]) == 0) { + //Console::puti(i); + //Console::puts("\n"); + //Console::puti(j); + //Console::puts("\n"); + //Console::puts("Entered second loop"); if(mask != 0x02) { j++; - mask >> 2; + mask = mask >> 2; } else { - failed = true; i++; j = 0; - break; + mask = 0x80; } } // if frame is found, start checking for sequence - if(!failed) + unsigned int temp = i; + c++; + while(c < _n_frames) { - unsigned int temp = i; - c++; - while(c < _n_frames) + //Console::puts("Entered sequence check"); + if(mask != 0x02) { - if(mask != 0x02) - { - mask >> 2; - } - else - { - temp++; - mask = 0x80; - } - if((mask & bitmap[temp]) != 0 && ((mask >> 1) & bitmap[temp]) != 0) - { - c++; - } - else - { - c = 0; - break; - } + mask = mask >> 2; } - if(c == _n_frames) + else { - nFreeFrames -= _n_frames; + temp++; + mask = 0x80; + } + if((mask & bitmap[temp]) != 0 && ((mask >> 1) & bitmap[temp]) != 0) + { + c++; + } + else + { + c = 0; break; } } - failed = false; + if(c == _n_frames) + { + nFreeFrames -= _n_frames; + break; + } } frame_no += i*4 + j; // Update bitmap // First: clear most significant bit to mark head of sequence. - bitmap[i] = bitmap[i] ^ (0x80 >> j*2); + bitmap[i] = bitmap[i] ^ (0x80 >> (j*2)); // Second: clear both bits for all remaining frames in the sequence. c = 1; unsigned char mask = 0x80 >> j*2; unsigned int temp = i; while(c < _n_frames) { + //Console::puts("Entered bitmap update"); if(mask != 0x02) { - mask >> 2; + mask = mask >> 2; } else { @@ -346,7 +346,7 @@ void ContFramePool::release_frames(unsigned long _frame_no) unsigned int i = 0; while(i < nPools) { - if(_frame_no < pools[i].base_frame_no || _frame_no > (pools[i].base_frame_no + pools[i].nframes)) + if(_frame_no <= pools[i].base_frame_no || _frame_no > (pools[i].base_frame_no + pools[i].nframes)) { i++; } @@ -362,21 +362,36 @@ void ContFramePool::release_frames_here(unsigned long _first_frame_no) { unsigned char * bitmap = this->bitmap; + Console::puti(_first_frame_no); + Console::puts("\n"); + Console::puti(base_frame_no); + unsigned int bitmap_index = (_first_frame_no - base_frame_no) / 4; unsigned char mask = 0x80 >> ((_first_frame_no - base_frame_no) % 4) * 2; - - if((bitmap[bitmap_index] & mask) != 0 && (bitmap[bitmap_index] & (mask >> 1)) != 0) + + // + Console::puts("\n"); + Console::puti(bitmap[bitmap_index]); + Console::puts("\n"); + Console::puti(bitmap[bitmap_index + 1]); + // + if(!((bitmap[bitmap_index] & mask) == 0 && (bitmap[bitmap_index] & (mask >> 1)) != 0)) { - Console::puts("Error, Frame being released is not being used\n"); + if((bitmap[bitmap_index] & mask) != 0 && (bitmap[bitmap_index] & (mask >> 1)) != 0) + { + Console::puts("Error, Frame being released is not being used\n"); + assert(false); + } + Console::puts("Error, Frame being released is not head of sequence\n"); assert(false); } - + bitmap[bitmap_index] ^= mask; nFreeFrames++; if(mask != 0x02) { - mask >> 2; + mask = mask >> 2; } else { @@ -386,8 +401,22 @@ void ContFramePool::release_frames_here(unsigned long _first_frame_no) while(bitmap[bitmap_index] & mask == 0 && (bitmap[bitmap_index] & (mask >> 1)) == 0) { + Console::puts("\n"); + Console::puti(bitmap_index); + Console::puts("\n"); + Console::puti(mask); + Console::puts("\n"); bitmap[bitmap_index] ^= mask; bitmap[bitmap_index] ^= (mask >> 1); + if(mask != 0x02) + { + mask = mask >> 2; + } + else + { + mask = 0x80; + bitmap_index++; + } nFreeFrames++; } } diff --git a/MP2/MP2_Sources/kernel.C b/MP2/MP2_Sources/kernel.C index 6b4e301..51117d2 100755 --- a/MP2/MP2_Sources/kernel.C +++ b/MP2/MP2_Sources/kernel.C @@ -75,7 +75,6 @@ int main() { /* ---- PROCESS POOL -- */ -/* unsigned long n_info_frames = ContFramePool::needed_info_frames(PROCESS_POOL_SIZE); unsigned long process_mem_pool_info_frame = kernel_mem_pool.get_frames(n_info_frames); @@ -86,7 +85,7 @@ int main() { n_info_frames); process_mem_pool.mark_inaccessible(MEM_HOLE_START_FRAME, MEM_HOLE_SIZE); -*/ + /* -- MOST OF WHAT WE NEED IS SETUP. THE KERNEL CAN START. */ Console::puts("Hello World!\n"); @@ -111,6 +110,8 @@ void test_memory(ContFramePool * _pool, unsigned int _allocs_to_go) { Console::puts("alloc_to_go = "); Console::puti(_allocs_to_go); Console::puts("\n"); if (_allocs_to_go > 0) { int n_frames = _allocs_to_go % 4 + 1; + Console::puti(n_frames); + Console::puts("\n"); unsigned long frame = _pool->get_frames(n_frames); int * value_array = (int*)(frame * (4 KB)); for (int i = 0; i < (1 KB) * n_frames; i++) {