43 lines
1.1 KiB
C++
43 lines
1.1 KiB
C++
#include <iostream>
|
|
#include <random>
|
|
|
|
#include "Kernel.h"
|
|
#include "MMU.h"
|
|
|
|
static int MAX_PROC = 10;
|
|
static int PAGE_N = 10;
|
|
|
|
int main() {
|
|
std::random_device rd;
|
|
std::mt19937 gen(rd());
|
|
std::uniform_int_distribution<unsigned int> distribution(500, 600), access_type_distr(1, 10);
|
|
|
|
List<PhysicalPage> free_pages, busy_pages;
|
|
Kernel kernel(MAX_PROC, free_pages, busy_pages);
|
|
|
|
for (int i = 1; i < PAGE_N; ++i) {
|
|
free_pages.insert_head(new PhysicalPage(i));
|
|
}
|
|
|
|
for (int i = 0; i < kernel.RunQ.capacity(); ++i) {
|
|
kernel.RunQ.emplace_back(new PageTable(distribution(gen)), distribution(gen));
|
|
}
|
|
|
|
for (int i = 0; i < 10000; ++i) {
|
|
if (kernel.RunQ.empty()) {
|
|
break;
|
|
}
|
|
for (int j = 0; j < 30; ++j) {
|
|
const AccessType type = access_type_distr(gen) == 1 ? WRITE : READ;
|
|
constexpr unsigned int index = 1;
|
|
MMU::access(&kernel, kernel.RunQ.at(0).pageTable, index, type);
|
|
}
|
|
++kernel.RunQ.at(0).elapsedTime;
|
|
if (kernel.RunQ.at(0).is_finished()) {
|
|
kernel.RunQ.erase(kernel.RunQ.begin());
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|