Skip to content

API changes and normalization #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 0 additions & 55 deletions README

This file was deleted.

65 changes: 63 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,65 @@
-CSCI340-Virtual-Paging-Assignment
CSCI340 Virtual Paging Assignment
==================================

Files and Write up for CSCI340 Virtual Paging Assignment
CSCI340 (Operating Systems)
California State University, Chico
Public Code

Slight additions
By Bryan Dixon - 2014

Adopted from assignment
By Andy Sayler - 2012
http://www.andysayler.com

That was adopted from
assignment by Dr. Alva Couch
http://www.cs.tufts.edu/~couch/

With help from:
Junho Ahn - 2012

Folders
=================================
- handout - Assignment description and documentation

Files
=================================
- Makefile - GNU makefile to build all relevant code
- pager-basic.c - Basic paging strategy implementation that runs one process at a time.
- pager-lru.c - LRU paging strategy implementation (you code this).
- pager-predict.c - Predictive paging strategy implementation (you code this).
- api-test.c - A pageit() implmentation that tests that simulator state changes
- simulator.c - Core simualtor code (look but don't touch)
- simulator.h - Exported functions and structs for use with simulator
- programs.c - Defines test "programs" for simulator to run
- pgm*.pseudo - Pseudo code of test programs from which programs.c was generated.

Executables
=================================
- test-* - Runs simulator using "programs" defined in programs.c and paging strategy defined in pager-*.c. Includes various run-time options. Run with '-help' for details.
- test-api - Runs a test of the simulator state changes

Examples
=================================
Build:
```bash
$ make
```

Clean:
```bash
$ make clean
```
View test options:
```bash
$ ./test-* -help
```
Run pager-basic test:
```bash
$ ./test-basic
```
Run API test:
```bash
$ ./test-api
```
160 changes: 80 additions & 80 deletions paging-handout/api-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,86 +20,86 @@

#define MAXITERATIONS 5

void pageit(Pentry q[MAXPROCESSES]) {

/* Static Vars */
static int tick = 0;
static int outTestRun = 0;
static int inTestRun = 0;
static int iterations = 0;

/* Local vars */
int testProc = 0;
int testPage = 0;
int pageinret = -1;
int pageoutret = -1;

/* All pages are swapped out on start */
if(q[testProc].pages[testPage]){
/* Page is swapped in */
if(!inTestRun){
fprintf(stdout, "%4d - %d:%d is swapped in\n", tick, testProc, testPage);
fprintf(stdout, "%4d - q[%d].pages[%d] = %ld\n",
tick, testProc, testPage, q[testProc].pages[testPage]);

pageinret = pagein(testProc, testPage);
fprintf(stdout, "%4d - pagein(%d, %d) returns %d\n",
tick, testProc, testPage, pageinret);

fprintf(stdout, "%4d - q[%d].pages[%d] = %ld\n",
tick, testProc, testPage, q[testProc].pages[testPage]);

pageoutret = pageout(testProc, testPage);
fprintf(stdout, "%4d - pageout(%d, %d) returns %d\n",
tick, testProc, testPage, pageoutret);
if(pageoutret){
/* Wait for pageout to complete */
inTestRun = 1;
outTestRun = 0;
iterations++;
}

fprintf(stdout, "%4d - q[%d].pages[%d] = %ld\n",
tick, testProc, testPage, q[testProc].pages[testPage]);
}
}
else{
/* Page is swapped out */
if(!outTestRun){
fprintf(stdout, "%4d - %d:%d is swapped out\n", tick, testProc, testPage);
fprintf(stdout, "%4d - q[%d].pages[%d] = %ld\n",
tick, testProc, testPage, q[testProc].pages[testPage]);

pageoutret = pageout(testProc, testPage);
fprintf(stdout, "%4d - pageout(%d, %d) returns %d\n",
tick, testProc, testPage, pageoutret);

fprintf(stdout, "%4d - q[%d].pages[%d] = %ld\n",
tick, testProc, testPage, q[testProc].pages[testPage]);

pageinret = pagein(testProc, testPage);
fprintf(stdout, "%4d - pagein(%d, %d) returns %d\n",
tick, testProc, testPage, pageinret);
if(pageinret){
/* Wait for pagein to complete */
outTestRun = 1;
inTestRun = 0;
iterations++;
}else{
fprintf(stdout, "%4d - pageout in progress...\n", tick);
}

fprintf(stdout, "%4d - q[%d].pages[%d] = %ld\n",
tick, testProc, testPage, q[testProc].pages[testPage]);
void pageit(Pentry q[MAXPROCESSES]) {

/* Static Vars */
static int tick = 0;
static int outTestRun = 0;
static int inTestRun = 0;
static int iterations = 0;

/* Local vars */
int testProc = 0;
int testPage = 0;
int pageinret = -1;
int pageoutret = -1;

/* All pages are swapped out on start */
if (q[testProc].states[testPage]) {
/* Page is swapped in */
if (!inTestRun) {
fprintf(stdout, "%4d - %d:%d is swapped in\n", tick, testProc,
testPage);
fprintf(stdout, "%4d - q[%d].pages[%d] = %d\n", tick, testProc,
testPage, q[testProc].states[testPage]);

pageinret = pagein(testProc, testPage);
fprintf(stdout, "%4d - pagein(%d, %d) returns %d\n", tick, testProc,
testPage, pageinret);

fprintf(stdout, "%4d - q[%d].pages[%d] = %d\n", tick, testProc,
testPage, q[testProc].states[testPage]);

pageoutret = pageout(testProc, testPage);
fprintf(stdout, "%4d - pageout(%d, %d) returns %d\n", tick,
testProc, testPage, pageoutret);
if (pageoutret) {
/* Wait for pageout to complete */
inTestRun = 1;
outTestRun = 0;
iterations++;
}

fprintf(stdout, "%4d - q[%d].pages[%d] = %d\n", tick, testProc,
testPage, q[testProc].states[testPage]);
}
} else {
/* Page is swapped out */
if (!outTestRun) {
fprintf(stdout, "%4d - %d:%d is swapped out\n", tick, testProc,
testPage);
fprintf(stdout, "%4d - q[%d].pages[%d] = %d\n", tick, testProc,
testPage, q[testProc].states[testPage]);

pageoutret = pageout(testProc, testPage);
fprintf(stdout, "%4d - pageout(%d, %d) returns %d\n", tick,
testProc, testPage, pageoutret);

fprintf(stdout, "%4d - q[%d].pages[%d] = %d\n", tick, testProc,
testPage, q[testProc].states[testPage]);

pageinret = pagein(testProc, testPage);
fprintf(stdout, "%4d - pagein(%d, %d) returns %d\n", tick, testProc,
testPage, pageinret);
if (pageinret) {
/* Wait for pagein to complete */
outTestRun = 1;
inTestRun = 0;
iterations++;
} else {
fprintf(stdout, "%4d - pageout in progress...\n", tick);
}

fprintf(stdout, "%4d - q[%d].pages[%d] = %d\n", tick, testProc,
testPage, q[testProc].states[testPage]);
}
}
}

/* Run test for I state change iterations */
if(iterations > MAXITERATIONS){
fprintf(stdout, "API Test Exiting\n");
exit(EXIT_SUCCESS);
}

tick++;
/* Run test for I state change iterations */
if (iterations > MAXITERATIONS) {
fprintf(stdout, "API Test Exiting\n");
exit(EXIT_SUCCESS);
}

}
tick++;
}
90 changes: 54 additions & 36 deletions paging-handout/pager-basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,46 +13,64 @@
* implmentation at performs very poorly, but
* provided a basic idea of how to user the
* simulator interface. Your job is to improve
* upon this implmentation.
* upon this implementation.
*/

#include <stdio.h>
#include <stdlib.h>

#include "simulator.h"

void pageit(Pentry q[MAXPROCESSES]) {

/* Local vars */
int proc;
int pc;
int page;
int oldpage;

/* Trivial paging strategy */
/* Select first active process */
for(proc=0; proc<MAXPROCESSES; proc++) {
/* Is process active? */
if(q[proc].active) {
/* Dedicate all work to first active process*/
pc = q[proc].pc; // program counter for process
page = pc/PAGESIZE; // page the program counter needs
/* Is page swaped-out? */
if(!q[proc].pages[page]) {
/* Try to swap in */
if(!pagein(proc,page)) {
/* If swapping fails, swap out another page */
for(oldpage=0; oldpage < q[proc].npages; oldpage++) {
/* Make sure page isn't one I want */
if(oldpage != page) {
/* Try to swap-out */
if(pageout(proc,oldpage)) {
/* Break loop once swap-out starts*/
break;
}
void pageit(Pentry q[MAXPROCESSES]) {

/* Local vars */
int proc;
int pc;
int page;
int oldpage;

/* Trivial paging strategy */
/* Select first active process */
for (proc = 0; proc < MAXPROCESSES; proc++) {
/* Is process active? */
if (q[proc].active) {
/* Dedicate all work to first active process*/
pc = q[proc].pc; // program counter for process
page = pc / PAGESIZE; // page the program counter needs

/* Is page swapped out? */
if (q[proc].states[page] == OUT) {
/* Try to swap in */
page_operation_result pagein_result = pagein(proc, page);

if (pagein_result == MEMORYFULL) {
/* If swapping fails, swap out another page */
for (oldpage = 0; oldpage < q[proc].npages; oldpage++) {
/* Make sure page isn't one I want */
if (oldpage != page) {
/* Try to swap out */
if (pageout(proc, oldpage) == STARTED) {
/* Break loop once swap out starts*/
break;
}
}
}
} else if (pagein_result == INVALIDPAGE) {
fprintf(stderr,
"Invalid page specified during page-in operation.\n");
exit(EXIT_FAILURE);
} else if (pagein_result != STARTED
&& pagein_result != PAGINGIN
&& pagein_result != PAGINGOUT
&& pagein_result != STATEEXISTS) {
/* something is badly wrong */
fprintf(stderr, "Unrecognized page operation result.");
exit(EXIT_FAILURE);
}
}
}
/* Break loop after finding first active process */
break;
}
}
/* Break loop after finding first active process */
break;
}
}
}
}

Loading