Skip to content

Commit

Permalink
RELEASE: KISS 1Q 2022
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasanchez committed Jul 23, 2022
1 parent 3913846 commit fb8b5dc
Show file tree
Hide file tree
Showing 24 changed files with 466 additions and 57 deletions.
7 changes: 7 additions & 0 deletions base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import os

os.system("rm -fr /home/tosanchez/Dev/sski/config")
os.system("cp -r /home/tosanchez/Dev/sski/test/base/config /home/tosanchez/Dev/sski")
os.system("./build/console.out /home/tosanchez/Dev/sski/test/base/BASE_1.txt 10")
os.system("./build/console.out /home/tosanchez/Dev/sski/test/base/BASE_2.txt 20")
os.system("./build/console.out /home/tosanchez/Dev/sski/test/base/BASE_2.txt 20")
4 changes: 2 additions & 2 deletions config/cpu.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ENTRADAS_TLB=1
ENTRADAS_TLB=2
REEMPLAZO_TLB=LRU
RETARDO_NOOP=1000
RETARDO_NOOP=100
IP_MEMORIA=127.0.0.1
PUERTO_MEMORIA=8002
PUERTO_ESCUCHA_DISPATCH=8001
Expand Down
10 changes: 5 additions & 5 deletions config/kernel.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ IP_CPU=127.0.0.1
PUERTO_CPU_DISPATCH=8001
PUERTO_CPU_INTERRUPT=8005
PUERTO_ESCUCHA=8000
ALGORITMO_PLANIFICACION=FIFO
ESTIMACION_INICIAL=20000
ALFA=0.5
GRADO_MULTIPROGRAMACION=2
TIEMPO_MAXIMO_BLOQUEADO=5000
ALGORITMO_PLANIFICACION=SRT
ESTIMACION_INICIAL=50000
ALFA=0.2
GRADO_MULTIPROGRAMACION=6
TIEMPO_MAXIMO_BLOQUEADO=1000
8 changes: 4 additions & 4 deletions config/memory.cfg
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
PUERTO_ESCUCHA=8002
TAM_MEMORIA=2048
TAM_MEMORIA=10240
TAM_PAGINA=256
ENTRADAS_POR_TABLA=4
RETARDO_MEMORIA=1000
RETARDO_MEMORIA=500
ALGORITMO_REEMPLAZO=CLOCK-M
MARCOS_POR_PROCESO=3lk,
RETARDO_SWAP=5000
MARCOS_POR_PROCESO=4
RETARDO_SWAP=1000
PATH_SWAP=/home/tosanchez/Dev/sski/swap
4 changes: 4 additions & 0 deletions console.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import os

os.system("./build/console.out /home/tosanchez/Dev/sski/console/memoria.txt 10")
# os.system("./build/console.out /home/tosanchez/Dev/sski/console/instructions_test.txt 40")
19 changes: 12 additions & 7 deletions cpu/src/module/tlb.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ void replace_fifo(void *tlb, uint32_t nueva_pagina, uint32_t nuevo_frame)

if (self[i].pagina == PAGINA_VACIA)
{
LOG_DEBUG("[TLB] :=> New entry added");
LOG_DEBUG("[TLB-FIFO] :=> New entry added");
}
else
{
LOG_INFO("[TLB] :=> TLB[%d] Changed: [Page: %d, Frame: %d] -> [Page: %d, Frame: %d]", i, self[i].pagina, self[i].frame, nueva_pagina, nuevo_frame);
LOG_INFO("[TLB-FIFO] :=> TLB[%d] Changed: [Page: %d, Frame: %d] -> [Page: %d, Frame: %d]", i, self[i].pagina, self[i].frame, nueva_pagina, nuevo_frame);
}

self[i].pagina = nueva_pagina;
Expand All @@ -93,11 +93,11 @@ void replace_lru(void *tlb, uint32_t nueva_pagina, uint32_t nuevo_frame)

if (self[i].pagina == PAGINA_VACIA)
{
LOG_WARNING("[TLB] :=> Empty Page");
LOG_WARNING("[TLB-LRU] :=> Empty Page");
self[i].pagina = nueva_pagina;
self[i].frame = nuevo_frame;
self[i].tiempo_ult_acceso = 0;
LOG_INFO("[TLB] :=> ADDED TLB[%d]= [Page: %d| Frame: %d]", i, nueva_pagina, nuevo_frame);
LOG_INFO("[TLB-LRU] :=> ADDED TLB[%d]= [Page: %d| Frame: %d]", i, nueva_pagina, nuevo_frame);
return;
}
}
Expand All @@ -109,29 +109,34 @@ void replace_lru(void *tlb, uint32_t nueva_pagina, uint32_t nuevo_frame)
{
if (self[i].tiempo_ult_acceso > acceso_mas_antiguo)
{
LOG_TRACE("[TLB-LRU]: TLB[%d]=[Page: %d, Frame: %d] is last recently used", i, self[i].pagina, self[i].frame);
pag_index_max = i;
acceso_mas_antiguo = self[i].tiempo_ult_acceso;
}
}

LOG_WARNING("[TLB] :=> Replacing TLB[%d]", pag_index_max);
LOG_WARNING("[TLB-LRU] :=> Replacing TLB[%d]", pag_index_max);
LOG_INFO("[TLB-LRU] :=> TLB[%d] Changed: [Page: %d, Frame: %d] -> [Page: %d, Frame: %d]", pag_index_max, self[pag_index_max].pagina, self[pag_index_max].frame, nueva_pagina, nuevo_frame);
self[pag_index_max].frame = nuevo_frame;
self[pag_index_max].pagina = nueva_pagina;
self[pag_index_max].tiempo_ult_acceso = 0;
LOG_INFO("[TLB] :=> TLB[%d] Changed: [Page: %d, Frame: %d] -> [Page: %d, Frame: %d]", pag_index_max, self[pag_index_max].pagina, self[pag_index_max].frame, nueva_pagina, nuevo_frame);
}

bool page_in_TLB(tlb_t *self, uint32_t numero_pagina, uint32_t *marco)
{
for (uint32_t i = 0; i < self->size; i++)
{

if (self[i].pagina == numero_pagina)
{
// Si la pagina esta en la TLB, devuelvo True y el Marco correspondiente
*marco = self[i].frame;
self[i].tiempo_ult_acceso = 0;
return true;
}
else
{
self[i].tiempo_ult_acceso++;
}
}

return false;
Expand Down
8 changes: 8 additions & 0 deletions integral.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import os


os.system("./build/console.out /home/tosanchez/Dev/sski/test/integral/INTEGRAL_1.txt 2048")
os.system("./build/console.out /home/tosanchez/Dev/sski/test/integral/INTEGRAL_2.txt 2048")
os.system("./build/console.out /home/tosanchez/Dev/sski/test/integral/INTEGRAL_3.txt 2048")
os.system("./build/console.out /home/tosanchez/Dev/sski/test/integral/INTEGRAL_4.txt 2048")
os.system("./build/console.out /home/tosanchez/Dev/sski/test/integral/INTEGRAL_5.txt 2048")
4 changes: 2 additions & 2 deletions memory/src/module/algorithms.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ uint32_t clock_selector(void *self, uint32_t table_index)
// Wether a FRAME was matched or not
bool completed = false;

LOG_WARNING("\t---\tTABLE\tBEFORE\tALGORITHM\t---");
LOG_WARNING("\t---\tTABLE#%d\tBEFORE\tALGORITHM\t---", table_index);
LOG_TABLE(total_rows, big_table);

LOG_ERROR("{CLOCK}> %d", clock);
Expand Down Expand Up @@ -121,7 +121,7 @@ uint32_t improved_clock_selector(void *self, uint32_t table_index)
// Wether a FRAME was matched or not
bool completed = false;

LOG_WARNING("\t---\tTABLE\tBEFORE\tALGORITHM\t---");
LOG_WARNING("\t---\tTABLE#%d\tBEFORE\tALGORITHM\t---", table_index);
LOG_TABLE(total_rows, big_table);
LOG_ERROR("{CLOCK-I}> %d", clock);

Expand Down
48 changes: 29 additions & 19 deletions memory/src/module/os_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ uint32_t create_table(memory_t *memory, uint32_t rows, uint32_t *ids);
* @param list the list of tables
* @return an Id
*/
uint32_t find_id(safe_list_t *list);
uint32_t find_id(safe_list_t *safe_list, bool should_replace);

/**
* @brief Deletes a Process Related Tables
Expand Down Expand Up @@ -138,13 +138,10 @@ get_table_lvl2_number(memory_t *memory, uint32_t frame)
{
page_table_lvl_2_t *table = safe_list_get(memory->tables_lvl_2, i);

for (uint32_t j = 0; j < memory->max_rows; j++)
{
if (table[j].frame == frame)
{
return i;
}
}
if (table)
for (uint32_t j = 0; j < memory->max_rows; j++)
if (table[j].frame == frame)
return i;
}

return INVALID_FRAME;
Expand Down Expand Up @@ -246,9 +243,18 @@ uint32_t *create_lvl2_tables(memory_t *memory, uint32_t rows)
// Number of rows of the Level I Table (Equal to rows of Second Level Table)
for (uint32_t i = 0; i < rows; i++)
{
id = find_id(memory->tables_lvl_2);
id = find_id(memory->tables_lvl_2, false);
table = new_page_table_lvl2(rows);
safe_list_add_in_index(memory->tables_lvl_2, id, table);

if ((uint32_t)safe_list_size(memory->tables_lvl_2) > id)
{
safe_list_replace(memory->tables_lvl_2, id, table);
}
else
{
safe_list_add_in_index(memory->tables_lvl_2, id, table);
}

ids[i] = id;
}

Expand All @@ -257,7 +263,7 @@ uint32_t *create_lvl2_tables(memory_t *memory, uint32_t rows)

uint32_t create_table(memory_t *memory, uint32_t rows, uint32_t *ids)
{
uint32_t id = find_id(memory->tables_lvl_1);
uint32_t id = find_id(memory->tables_lvl_1, true);
page_table_lvl_1_t *table = new_page_table(rows);

for (uint32_t i = 0; i < rows; i++)
Expand All @@ -279,18 +285,19 @@ uint32_t create_table(memory_t *memory, uint32_t rows, uint32_t *ids)
return id;
}

uint32_t find_id(safe_list_t *safe_list)
uint32_t find_id(safe_list_t *safe_list, bool should_replace)
{
if (list_is_empty(safe_list->_list))
return 0;

for (uint32_t i = 0; i < (uint32_t)list_size(safe_list->_list); i++)
{
page_table_lvl_1_t *table = safe_list_get(safe_list, i);
if (should_replace)
for (uint32_t i = 0; i < (uint32_t)list_size(safe_list->_list); i++)
{
page_table_lvl_1_t *table = safe_list_get(safe_list, i);

if (table == NULL)
return i;
}
if (table == NULL)
return i;
}

return list_size(safe_list->_list);
}
Expand Down Expand Up @@ -327,6 +334,8 @@ void delete_level_2_table(memory_t *memory, uint32_t table_id)
// Destroy a Second page
page_table_lvl_2_t *lvl2_table = list_get(memory->tables_lvl_2->_list, table_id);

LOG_TRACE("[Memory] :=> Deleting Table#%d (LVL2)", table_id);

// Iterate over a LVL 2 Table
for (uint32_t j = 0; j < memory->max_rows && j < memory->max_frames; j++)
{
Expand All @@ -339,10 +348,11 @@ void delete_level_2_table(memory_t *memory, uint32_t table_id)
}

free(lvl2_table);
list_replace(memory->tables_lvl_2->_list, table_id, NULL);
}

void delete_frame(memory_t *memory, uint32_t id)
{
if (id <= memory->max_frames)
if (id <= memory->no_of_frames)
memory->frames[id] = false;
}
56 changes: 39 additions & 17 deletions memory/src/server/cpu_controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ void cpu_controller_write(int socket)
LOG_TRACE("[CPU-CONTROLLER] :=> Writting into the Physical Address <%d>, Value <%d>", physical_address, value);

uint32_t frame = get_frame(physical_address);
LOG_DEBUG("[CPU-CONTROLLER] :=> Frame <%d>", frame);
uint32_t table_number_2 = get_table_lvl2_number(&g_memory, frame);

// Frame DOES NOT EXIST
Expand Down Expand Up @@ -385,7 +386,6 @@ obtain_frame(uint32_t id_table_2, uint32_t index, uint32_t pid)
{
page_table_lvl_2_t *table_lvl2 = safe_list_get(g_memory.tables_lvl_2, id_table_2);

// TODO: VALIDAR QUE ESTO ESTA BIEN (Me huele mal)
if (index > g_memory.max_rows)
{
LOG_ERROR("[CPU-CONTROLLER] :=> Index out of bounds for FRAMES");
Expand All @@ -394,32 +394,45 @@ obtain_frame(uint32_t id_table_2, uint32_t index, uint32_t pid)

if (!table_lvl2[index].present)
{
LOG_ERROR("[CPU-CONTROLLER] :=> Page Fault: Frame not allocated");
LOG_ERROR("[CPU-CONTROLLER] :=> Page Fault: Frame not allocated [Index=%d]", index);
uint32_t new_frame = find_free_frame(&g_memory);
LOG_TRACE("[CPU-CONTROLLER] :=> FRAME FOUND: %d", new_frame);

if (should_replace_frame(&g_memory, index))
if (new_frame == UINT32_MAX)
{
LOG_ERROR("[CPU-CONTROLLER] :=> No free frames available (MAX=%d)", g_memory.no_of_frames);
}

if (should_replace_frame(&g_memory, id_table_2))
{
LOG_WARNING("[MEMORY] :=> Page replacement is required");
uint32_t id_table_1 = get_table_lvl1_number(&g_memory, id_table_2);
LOG_TRACE("[MEMORY] :=> Table#%d has Table_2 #%d", id_table_1, id_table_2);
uint32_t frame_to_replace = g_memory.frame_selector(&g_memory, id_table_1);
LOG_TRACE("[MEMORY] :=> Frame #%d should be replaced.", frame_to_replace);
replace_frame(pid, frame_to_replace);
LOG_INFO("[ALGORITHM] :=> Replaced Frame: #%d -> #%d", frame_to_replace, new_frame);
}
else
{
LOG_INFO("[MEMORY] :=> Page replacement is >NOT< required");
}

if (table_lvl2[index].frame == INVALID_FRAME)
{
uint32_t created_at = create_frame_for_table(&g_memory, index, new_frame);
LOG_TRACE("[MEMORY] :=> Frame #%d is free. Assigning", new_frame);
uint32_t created_at = create_frame_for_table(&g_memory, id_table_2, new_frame);
LOG_INFO("[Memory] :=> Table#%d[%d] = { Frame: %d ...}", id_table_2, created_at, new_frame);
}
else
{
LOG_WARNING("[MEMORY] :=> Frame already allocated, should unswap.");
delete_frame(&g_memory, new_frame);
unswap_frame_for_pcb(pid, table_lvl2[index].frame);
table_lvl2[index].use = true;
LOG_INFO("[Memory] :=> Table#%d[%d] = { Frame: %d ...} [UNSWAPPED]", id_table_2, index, table_lvl2[index].frame);
}

LOG_TRACE("[CPU-CONTROLLER] :=> RETURNING THE NEW FRAME: %d", new_frame);
return new_frame;
}
else
Expand Down Expand Up @@ -458,41 +471,50 @@ bool frame_is_present(memory_t *memory, uint32_t table_number, uint32_t frame)

bool should_replace_frame(memory_t *memory, uint32_t table_number_2)
{
LOG_TRACE("[Memory] :=> WE SHOULD REPLACE A FRAME ¡!");
uint32_t table_number = get_table_lvl1_number(memory, table_number_2);
LOG_DEBUG("[Memory] :=> TABLE NUMBER FOUND: %d", table_number);
page_table_lvl_1_t *table = safe_list_get(memory->tables_lvl_1, table_number);
print_table(memory, table_number);
uint32_t count = 0;

LOG_WARNING("[Memory] :=> Should a frame be replaced at Table#%d?", table_number);
for (uint32_t i = 0; i < memory->max_rows; i++)
{
page_table_lvl_2_t *table_2 = safe_list_get(memory->tables_lvl_2, table[i].second_page);
for (uint32_t j = 0; j < memory->max_rows; j++)
{
if (table_2[j].present == true)
if (table_2)
for (uint32_t j = 0; j < memory->max_rows; j++)
{
count++;
if (table_2[j].present == true)
{
LOG_TRACE("[Memory] :=> Table#%d[%d][%d] = { Frame: %d } is present", table_number, i, j, table_2[j].frame);
count++;
}
}
}
}

LOG_DEBUG("[Memory] :=> Frames in use: %d", count);

return count >= (uint32_t)marcos_por_proceso();
}

uint32_t
get_table_lvl1_number(memory_t *memory, uint32_t table_number_2)
{
uint32_t size = (uint32_t)list_size(memory->tables_lvl_2->_list);

uint32_t size = (uint32_t)safe_list_size(memory->tables_lvl_1);
LOG_DEBUG("MEMORY :=> THE SIZE IS: %d", size);
for (uint32_t i = 0; i < size; i++)
{
page_table_lvl_1_t *table = safe_list_get(memory->tables_lvl_1, i);

for (uint32_t j = 0; j < memory->max_rows; j++)
{
if (table[j].second_page == table_number_2)
if (table)
for (uint32_t j = 0; j < memory->max_rows; j++)
{
return i;
if (table[j].second_page == table_number_2)
{
return i;
}
}
}
}

return UINT32_MAX;
Expand Down
5 changes: 5 additions & 0 deletions mmemory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import os

os.system("rm -fr /home/tosanchez/Dev/sski/config")
os.system("cp -r /home/tosanchez/Dev/sski/test/memory/config /home/tosanchez/Dev/sski")
os.system("./build/console.out /home/tosanchez/Dev/sski/test/memory/MEMORIA_1.txt 2048")
7 changes: 7 additions & 0 deletions scheduling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import os

os.system("rm -fr /home/tosanchez/Dev/sski/config")
os.system("cp -r /home/tosanchez/Dev/sski/test/scheduling/config /home/tosanchez/Dev/sski")
os.system("./build/console.out /home/tosanchez/Dev/sski/test/scheduling/PLANI_1.txt 20")
os.system("./build/console.out /home/tosanchez/Dev/sski/test/scheduling/PLANI_1.txt 20")
os.system("./build/console.out /home/tosanchez/Dev/sski/test/scheduling/PLANI_2.txt 10")
7 changes: 7 additions & 0 deletions suspension.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import os

os.system("rm -fr /home/tosanchez/Dev/sski/config")
os.system("cp -r /home/tosanchez/Dev/sski/test/suspension/config /home/tosanchez/Dev/sski")
os.system("./build/console.out /home/tosanchez/Dev/sski/test/suspension/SUSPE_1.txt 20")
os.system("./build/console.out /home/tosanchez/Dev/sski/test/suspension/SUSPE_2.txt 20")
os.system("./build/console.out /home/tosanchez/Dev/sski/test/suspension/SUSPE_3.txt 10")
Loading

0 comments on commit fb8b5dc

Please sign in to comment.