add working set change chance for processes

This commit is contained in:
ІО-23 Шмуляр Олег 2025-03-08 12:21:06 +02:00
parent 819379055d
commit 585c820853
3 changed files with 19 additions and 2 deletions

View File

@ -13,7 +13,7 @@ kernel.o: src/kernel.c config.h
mmu.o: src/mmu.c
gcc $(CCFLAGS) -c -o mmu.o src/mmu.c
process.o: src/process.c
process.o: src/process.c config.h
gcc $(CCFLAGS) -c -o process.o src/process.c
random.o: src/random.c

View File

@ -3,3 +3,5 @@
#define WSCLOCK_TIME_WINDOW 1500
#define VERBOSE_SANITY_CHECK 0
#define WS_CHANGE_INVERSE_CHANCE 1000

View File

@ -5,6 +5,8 @@
#include "mmu.h"
#include "random.h"
#include "config.h"
struct Process *
Process(size_t proc_id, size_t max_accesses, size_t total_pages_owned, size_t ws_size)
{
@ -27,7 +29,8 @@ Process(size_t proc_id, size_t max_accesses, size_t total_pages_owned, size_t ws
return p;
}
size_t PROCESS_run_for(struct Process *p, size_t time_bits)
size_t
PROCESS_run_for(struct Process *p, size_t time_bits)
{
if (!p) {
printf("[process ?] p == NULL, something is very wrong\n");
@ -49,7 +52,19 @@ size_t PROCESS_run_for(struct Process *p, size_t time_bits)
printf("[process %d] Reading from page #%d\n", p->id, accessed_page_no);
MMU_read(p->pt, accessed_page_no);
}
if (!randint(WS_CHANGE_INVERSE_CHANCE))
PROCESS_change_working_set(p);
}
return p->pages_accessed >= p->max_accesses;
}
void
PROCESS_change_working_set(struct Process *p)
{
printf("[process %d] Changing working set after %d accesses\n", p->id, p->pages_accessed);
for (size_t i = 0; i < p->ws_size; i++)
p->ws[i] = randint(p->total_pages_owned);
}