Something wrong with get_frames.

This commit is contained in:
410 2017-06-19 19:48:30 -05:00
parent 5387962424
commit e8bb8088a7
2 changed files with 77 additions and 47 deletions

View file

@ -186,22 +186,23 @@ ContFramePool::ContFramePool(unsigned long _base_frame_no,
{ {
unsigned int i = info_frame_no / 4; unsigned int i = info_frame_no / 4;
unsigned int r = info_frame_no % 4; unsigned int r = info_frame_no % 4;
unsigned char mask = 0xC0; unsigned char mask = 0x80;
mask = mask >> r*2; mask = mask >> r*2;
unsigned int c = 0; unsigned int c = 0;
while(c < n_info_frames) while(c < n_info_frames)
{ {
bitmap[i] = bitmap[i] ^ mask; bitmap[i] = bitmap[i] ^ mask;
bitmap[i] = bitmap[i] ^ (mask >> 1);
if(mask == 0x02) if(mask == 0x02)
{ {
i++; i++;
mask = 0xC0; mask = 0x80;
} }
c++; c++;
nFreeFrames--;
} }
nFreeFrames--;
} }
Console::puts("Frame Pool initialized\n"); Console::puts("Frame Pool initialized\n");
@ -226,78 +227,77 @@ unsigned long ContFramePool::get_frames(unsigned int _n_frames)
unsigned int j = 0; unsigned int j = 0;
unsigned int c = 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) 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 // check every 2 bits for a free frame in the bitmap
while((mask & bitmap[i]) == 0 || ((mask >> 1) & bitmap[i]) == 0) 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) if(mask != 0x02)
{ {
j++; j++;
mask >> 2; mask = mask >> 2;
} }
else else
{ {
failed = true;
i++; i++;
j = 0; j = 0;
break; mask = 0x80;
} }
} }
// if frame is found, start checking for sequence // if frame is found, start checking for sequence
if(!failed) unsigned int temp = i;
c++;
while(c < _n_frames)
{ {
unsigned int temp = i; //Console::puts("Entered sequence check");
c++; if(mask != 0x02)
while(c < _n_frames)
{ {
if(mask != 0x02) mask = mask >> 2;
{
mask >> 2;
}
else
{
temp++;
mask = 0x80;
}
if((mask & bitmap[temp]) != 0 && ((mask >> 1) & bitmap[temp]) != 0)
{
c++;
}
else
{
c = 0;
break;
}
} }
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; break;
} }
} }
failed = false; if(c == _n_frames)
{
nFreeFrames -= _n_frames;
break;
}
} }
frame_no += i*4 + j; frame_no += i*4 + j;
// Update bitmap // Update bitmap
// First: clear most significant bit to mark head of sequence. // 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. // Second: clear both bits for all remaining frames in the sequence.
c = 1; c = 1;
unsigned char mask = 0x80 >> j*2; unsigned char mask = 0x80 >> j*2;
unsigned int temp = i; unsigned int temp = i;
while(c < _n_frames) while(c < _n_frames)
{ {
//Console::puts("Entered bitmap update");
if(mask != 0x02) if(mask != 0x02)
{ {
mask >> 2; mask = mask >> 2;
} }
else else
{ {
@ -346,7 +346,7 @@ void ContFramePool::release_frames(unsigned long _frame_no)
unsigned int i = 0; unsigned int i = 0;
while(i < nPools) 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++; i++;
} }
@ -362,12 +362,27 @@ void ContFramePool::release_frames_here(unsigned long _first_frame_no)
{ {
unsigned char * bitmap = this->bitmap; 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 int bitmap_index = (_first_frame_no - base_frame_no) / 4;
unsigned char mask = 0x80 >> ((_first_frame_no - base_frame_no) % 4) * 2; 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); assert(false);
} }
@ -376,7 +391,7 @@ void ContFramePool::release_frames_here(unsigned long _first_frame_no)
if(mask != 0x02) if(mask != 0x02)
{ {
mask >> 2; mask = mask >> 2;
} }
else 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) 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;
bitmap[bitmap_index] ^= (mask >> 1); bitmap[bitmap_index] ^= (mask >> 1);
if(mask != 0x02)
{
mask = mask >> 2;
}
else
{
mask = 0x80;
bitmap_index++;
}
nFreeFrames++; nFreeFrames++;
} }
} }

View file

@ -75,7 +75,6 @@ int main() {
/* ---- PROCESS POOL -- */ /* ---- PROCESS POOL -- */
/*
unsigned long n_info_frames = ContFramePool::needed_info_frames(PROCESS_POOL_SIZE); 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); unsigned long process_mem_pool_info_frame = kernel_mem_pool.get_frames(n_info_frames);
@ -86,7 +85,7 @@ int main() {
n_info_frames); n_info_frames);
process_mem_pool.mark_inaccessible(MEM_HOLE_START_FRAME, MEM_HOLE_SIZE); process_mem_pool.mark_inaccessible(MEM_HOLE_START_FRAME, MEM_HOLE_SIZE);
*/
/* -- MOST OF WHAT WE NEED IS SETUP. THE KERNEL CAN START. */ /* -- MOST OF WHAT WE NEED IS SETUP. THE KERNEL CAN START. */
Console::puts("Hello World!\n"); 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"); Console::puts("alloc_to_go = "); Console::puti(_allocs_to_go); Console::puts("\n");
if (_allocs_to_go > 0) { if (_allocs_to_go > 0) {
int n_frames = _allocs_to_go % 4 + 1; int n_frames = _allocs_to_go % 4 + 1;
Console::puti(n_frames);
Console::puts("\n");
unsigned long frame = _pool->get_frames(n_frames); unsigned long frame = _pool->get_frames(n_frames);
int * value_array = (int*)(frame * (4 KB)); int * value_array = (int*)(frame * (4 KB));
for (int i = 0; i < (1 KB) * n_frames; i++) { for (int i = 0; i < (1 KB) * n_frames; i++) {