Repo management & code cleanup
This commit is contained in:
parent
7a3a6bd256
commit
f8cbf9f064
2
Assignment7/.gitignore
vendored
Normal file
2
Assignment7/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
student_out\*.out
|
||||
a.out
|
7
Assignment7/.idea/runConfigurations/Test1.xml
Normal file
7
Assignment7/.idea/runConfigurations/Test1.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="Test1" type="CLionNativeAppRunConfigurationType" PROGRAM_PARAMS="3" REDIRECT_INPUT="true" REDIRECT_INPUT_PATH="$PROJECT_DIR$/in/algo-check.in" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="Assignment7" TARGET_NAME="all" CONFIG_NAME="all" version="1" RUN_PATH="$PROJECT_DIR$/a.out">
|
||||
<method v="2">
|
||||
<option name="CLION.COMPOUND.BUILD" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
</component>
|
Binary file not shown.
@ -1,6 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define OFFSETBITS 12
|
||||
#define PAGESIZE (1 << OFFSETBITS)
|
||||
#define PAGETABLEBITS 10
|
||||
@ -11,8 +12,6 @@ unsigned int pageHits = 0;
|
||||
unsigned int pagesSwapped = 0;
|
||||
int time = 0;
|
||||
|
||||
|
||||
|
||||
typedef struct frameEntry {
|
||||
unsigned int pageNumber;
|
||||
int lastUsed;
|
||||
@ -56,6 +55,8 @@ int isInFrames(int pageNumber){
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Swap out the least recently used frame
|
||||
// Returns the index of the frame that was swapped out
|
||||
int swapOut() {
|
||||
// Find the least recently used frame
|
||||
int leastRecentlyUsed = 0x7FFFFFFF;
|
||||
@ -67,6 +68,7 @@ int swapOut(){
|
||||
}
|
||||
}
|
||||
// Swap out is implied, so we increment pageSwapped
|
||||
// If the frame is dirty, we need to write it to disk, so we increment pagesSwapped
|
||||
if (frames[leastRecentlyUsedIndex].dirty) {
|
||||
pagesSwapped++;
|
||||
}
|
||||
@ -74,6 +76,8 @@ int swapOut(){
|
||||
return leastRecentlyUsedIndex;
|
||||
}
|
||||
|
||||
// Swap in a page
|
||||
// Returns the index of the frame that was swapped in
|
||||
int swapIn(int pageNumber) {
|
||||
// Find the first empty frame
|
||||
for (int i = 0; i < framesSize; i++) {
|
||||
@ -90,28 +94,26 @@ int swapIn(int pageNumber){
|
||||
return frameID;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Read from an address
|
||||
void readFromAddress(unsigned long logicalAddress) {
|
||||
unsigned int pageNumber = getPageNumber(logicalAddress);
|
||||
int frameID = isInFrames(pageNumber);
|
||||
if (isInFrames(pageNumber) == -1) {
|
||||
frameID = swapIn(pageNumber);
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
pageHits++;
|
||||
}
|
||||
frames[frameID].lastUsed = time;
|
||||
printPhysicalAddress(frameID, logicalAddress);
|
||||
}
|
||||
|
||||
// Write to an address, only difference is that we set the dirty bit to true
|
||||
void writeToAddress(unsigned long logicalAddress) {
|
||||
unsigned int pageNumber = getPageNumber(logicalAddress);
|
||||
int frameID = isInFrames(pageNumber);
|
||||
if (isInFrames(pageNumber) == -1) {
|
||||
frameID = swapIn(pageNumber);
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
pageHits++;
|
||||
}
|
||||
frames[frameID].dirty = true;
|
||||
@ -121,7 +123,7 @@ void writeToAddress(unsigned long logicalAddress){
|
||||
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
//Disable printf buffering
|
||||
//Disable printf buffering for easier debugging
|
||||
setbuf(stdout, NULL);
|
||||
|
||||
framesSize = atoi(argv[1]);
|
||||
@ -135,19 +137,20 @@ int main(int argc, char** argv){
|
||||
unsigned long logicalAddress;
|
||||
char operation;
|
||||
printf("Logical addresses -> Physical addresses:\n");
|
||||
while(EOF != scanf("%c %lu\n",&operation,&logicalAddress) )
|
||||
{
|
||||
if (operation == 'r')
|
||||
{
|
||||
while (EOF != scanf("%c %lu\n", &operation, &logicalAddress)) {
|
||||
if (operation == 'r') {
|
||||
readFromAddress(logicalAddress);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
writeToAddress(logicalAddress);
|
||||
}
|
||||
time++;
|
||||
}
|
||||
|
||||
printf("\nStats:\nmajor page faults = %u\npage hits = %u\npages swapped out = %u\nEffective Access Time = %.3lf\n",pageFault,pageHits,pagesSwapped, computeFormula());
|
||||
return 0;
|
||||
printf("\nStats:\nmajor page faults = %u\npage hits = %u\npages swapped out = %u\nEffective Access Time = %.3lf\n",
|
||||
pageFault,
|
||||
pageHits,
|
||||
pagesSwapped,
|
||||
computeFormula()
|
||||
);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
@ -1,14 +0,0 @@
|
||||
Logical addresses -> Physical addresses:
|
||||
1124955998 -> 1886
|
||||
794845611 -> 4523
|
||||
1540976830 -> 8382
|
||||
1081961846 -> 3446
|
||||
1124957700 -> 7684
|
||||
794845440 -> 8448
|
||||
1540976645 -> 5
|
||||
|
||||
Stats:
|
||||
major page faults = 7
|
||||
page hits = 0
|
||||
pages swapped out = 0
|
||||
Effective Access Time = 1000.000
|
@ -1,15 +0,0 @@
|
||||
Logical addresses -> Physical addresses:
|
||||
1622650073 -> 3289
|
||||
1144108930 -> 1922
|
||||
101027544 -> 3800
|
||||
1784484492 -> 652
|
||||
823378840 -> 920
|
||||
197493099 -> 363
|
||||
1954899097 -> 1177
|
||||
530511967 -> 2143
|
||||
|
||||
Stats:
|
||||
major page faults = 8
|
||||
page hits = 0
|
||||
pages swapped out = 0
|
||||
Effective Access Time = 1000.000
|
@ -1,15 +0,0 @@
|
||||
Logical addresses -> Physical addresses:
|
||||
1622650073 -> 3289
|
||||
1144108930 -> 6018
|
||||
101027544 -> 3800
|
||||
1784484492 -> 4748
|
||||
823378840 -> 920
|
||||
197493099 -> 4459
|
||||
1954899097 -> 1177
|
||||
530511967 -> 6239
|
||||
|
||||
Stats:
|
||||
major page faults = 8
|
||||
page hits = 0
|
||||
pages swapped out = 0
|
||||
Effective Access Time = 1000.000
|
@ -1,14 +0,0 @@
|
||||
Logical addresses -> Physical addresses:
|
||||
1124955998 -> 1886
|
||||
794845611 -> 4523
|
||||
1540976830 -> 8382
|
||||
1081961846 -> 3446
|
||||
1124957700 -> 7684
|
||||
794845440 -> 8448
|
||||
1540976645 -> 5
|
||||
|
||||
Stats:
|
||||
major page faults = 7
|
||||
page hits = 0
|
||||
pages swapped out = 1
|
||||
Effective Access Time = 1285.714
|
@ -1,15 +0,0 @@
|
||||
Logical addresses -> Physical addresses:
|
||||
1622650073 -> 3289
|
||||
1144108930 -> 1922
|
||||
101027544 -> 3800
|
||||
1784484492 -> 652
|
||||
823378840 -> 920
|
||||
197493099 -> 363
|
||||
1954899097 -> 1177
|
||||
530511967 -> 2143
|
||||
|
||||
Stats:
|
||||
major page faults = 8
|
||||
page hits = 0
|
||||
pages swapped out = 7
|
||||
Effective Access Time = 2750.000
|
@ -1,15 +0,0 @@
|
||||
Logical addresses -> Physical addresses:
|
||||
1622650073 -> 3289
|
||||
1144108930 -> 6018
|
||||
101027544 -> 3800
|
||||
1784484492 -> 4748
|
||||
823378840 -> 920
|
||||
197493099 -> 4459
|
||||
1954899097 -> 1177
|
||||
530511967 -> 6239
|
||||
|
||||
Stats:
|
||||
major page faults = 8
|
||||
page hits = 0
|
||||
pages swapped out = 6
|
||||
Effective Access Time = 2500.000
|
@ -1,15 +0,0 @@
|
||||
Logical addresses -> Physical addresses:
|
||||
1725896583 -> 1927
|
||||
1725896583 -> 1927
|
||||
1725898287 -> 3631
|
||||
1725894961 -> 305
|
||||
1725896008 -> 1352
|
||||
1725898705 -> 4049
|
||||
1725898485 -> 3829
|
||||
1725897033 -> 2377
|
||||
|
||||
Stats:
|
||||
major page faults = 1
|
||||
page hits = 7
|
||||
pages swapped out = 0
|
||||
Effective Access Time = 133.750
|
@ -1,14 +0,0 @@
|
||||
Logical addresses -> Physical addresses:
|
||||
1124955998 -> 1886
|
||||
794845611 -> 4523
|
||||
1540976830 -> 8382
|
||||
1124957700 -> 3588
|
||||
1081961846 -> 7542
|
||||
794845440 -> 8448
|
||||
1540976645 -> 5
|
||||
|
||||
Stats:
|
||||
major page faults = 6
|
||||
page hits = 1
|
||||
pages swapped out = 0
|
||||
Effective Access Time = 858.571
|
@ -1,14 +0,0 @@
|
||||
Logical addresses -> Physical addresses:
|
||||
1124955998 -> 1886
|
||||
794845611 -> 4523
|
||||
1540976830 -> 8382
|
||||
1124957700 -> 3588
|
||||
1081961846 -> 7542
|
||||
794845440 -> 8448
|
||||
1540976645 -> 5
|
||||
|
||||
Stats:
|
||||
major page faults = 6
|
||||
page hits = 1
|
||||
pages swapped out = 3
|
||||
Effective Access Time = 1715.714
|
Loading…
Reference in New Issue
Block a user