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 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");
@ -226,39 +227,39 @@ 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)
{
//Console::puts("Entered sequence check");
if(mask != 0x02)
{
mask >> 2;
mask = mask >> 2;
}
else
{
@ -281,23 +282,22 @@ unsigned long ContFramePool::get_frames(unsigned int _n_frames)
break;
}
}
failed = false;
}
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;
//
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))
{
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++;
}
}

View file

@ -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++) {