Handout 1, CS 133F “Introduction to Fortran Programming” csc 139 XXXXXXXXXXoperating systems XXXXXXXXXXSac State HM HW 3 HomeWork 3, Virtual Memory Manager (VMM) General rules: Create homework,...

1 answer below »
EVERYTHING IN ON HW3 FILE


Handout 1, CS 133F “Introduction to Fortran Programming” csc 139 operating systems Sac State HM HW 3 HomeWork 3, Virtual Memory Manager (VMM) General rules: Create homework, compose specifications or any text by using a common document-creation tool, such as Microsoft® Word. Program in C, C++ or Java. Refer to the wwweb or lecture notes for this class to design, implement, and debug solid SW solutions. Be complete, and precise. Summary: Design, implement, test, debug and document a simplified simulator for a demand-paged Virtual Memory Manager named Vmm. Vmm assumes a 32-bit, byte-addressable architecture with 4 kB sized, and 4 kB aligned page frames. Run your program with your own, well thought-out inputs. Also use the inputs mentioned here. Only submit inputs and outputs of your test runs, not your program source, and not the traces you used for your own debug! Abstract: Simulate a Virtual Memory Manager named Vmm that reads in textual form memory requests (AKA loads and stores) from stdin and simulates them. Vmm measures the number of CPU cycles of any simulated action. To simplify, the fixed cycles for memory accesses are defined via constants; they do not vary dynamically as they generally will in a real run-time system. Implement three levels of 32-bit VMM address mapping, using 10, 10 and 12 bits of any logical address. Except for the Page Directory (PD) which is implemented as a dedicated 4 kB-size cache, Vmm operates without caches. Accesses through the PD cost 1 cycle each. Track the exact number of cycles for each and for all memory accesses; also compute the number of cycles if no virtual memory mapping had been available. Track the number of page swap-ins, swap-outs, and all interesting demand paging related activities. Define the number of cycles for any swap operation to be fixed at 5000 cycles per swap. In reality this will be higher and does generally vary from one disk access to another. Output some text file to help you debug your code, showing the state of the memory subsystem at each swap-in and swap-out. This file can become large when the system is thrashing. Make sure you do run some thrashing case. Do not turn in these files. Only turn in the actual output of short simulations, do not turn in your debug information. For each simulation run show (and hand in) the actual input, including the initial p xx, with xx specifying the number of page frames available. Each time a new Page Table (PT) or user page is allocated, output the current status of the Page Directory (PD) and PT. For brevity it is OK only to dump valid table entries (with their respective index), not the complete table with more than 1000 possible entries; many of those may be NULL. Detailed Requirements: Simulate Vmm for a byte-addressable, 4-bytes per word architecture with 32 bit addresses, using demand paging. A page is 4 kB long, and 4 kB aligned. Write also a separate address-generating program to be used for your simulation inputs. Load- and store requests (in ASCII text form) are read by the simulator’s front-end (FE) and “executed” by the simulator. To start a simulation run, the first input tuple p of information is the number of page frames available; e.g. input p 9 indicates 9 physical page frames are available for this run; no more. Whenever the data space needed to execute your simulated program is larger than the available number of physical frames (like in case of p 9), some resident page will have to be swapped out. This is called the victim page. Careful, if the victim page is unmodified and already on disk, it can simply be overridden; no need to swap back (AKA write back) onto disk. Yet any page swapped out must be marked as being “no present” in its VMM data structure. Only user pages are swapped out, not Page Tables. The PD being implemented as a HW cache can never be swapped out. Use three levels of address mapping. Each logical 32-bit address is interpreted as a 10+10+12 bit string as follows: PD: The leftmost 10 bits of a logical address hold the index into the Page Directory PD. The PD is a 4 kB HW cache, having space for 1024 pointers to some PT. An entry in the PD is 4 bytes long, or 32 bits, sufficient to hold the frame-size aligned address of a PT. The remaining 12 bits in a PD entry are usable for administrative detail about the PT. You use some of these bits, to track present, modified, etc. PT: The next 10 bits of a logical address are the index into the Page Table PT. An entry in the PT is 4 bytes long, or 32 bits, each sufficient to hold the address of a user page. The remaining 12 bits are usable for further detail about the user page, such a present, modified, etc. User Page: Finally, the rightmost 12 bits of any logical address are the byte-offset into a user page. The start address of a user page is pointed to by the appropriate PT entry. Replacement: If a page must be swapped out, use a Random Replacement Policy. Define some fixed, arbitrary, small number of (simulated) machine cycles for selecting the victim page; e.g. 10 cycles would be an acceptable constant. This constitutes a simplification compared with a real demand paged system that must identify a victim page, sometimes at great cost. Note that only 20 address bits need to be stored in each of the 1024 PD and PT entries. While logical addresses are 32 bits long, all frames are aligned on 4 Kb boundaries, thus the rightmost 12 bits of any page address always happen to be 0. No need to store them! Instead, the remaining 12 bits can be used for: the P bit (present); D bit (dirty, set if written, clear initially; AKA M bit for modified); R bit for read-only pages; S bit for a shared page; and other data interesting to an Operating System about a page. Perhaps a few bits even remain unused. Summary Output after completion of a simulation: * * * Paging Activity Statistics * * * number of memory accesses = xx number of triples (1 + access) = xx number of swap ins (faults) = xx number of swap outs = xx total number of pages malloced = xx number of pages for Page Tables = xx number of page frames for user = xx total memory cycles = xx cycles w/o Vmm = xx cycles per swap_in = 5000 cycles per swap_out = 5000 last working set size = xx max working set size ever = xx max physical pages = xx page size = 4096 replacement algorithm = random Required Input and resulting output: P x at the beginning of the input specifies the maximum number x of physical page frames. Example above showed p 9. Other input samples to the simulator: w x y define that at address x the value y will be stored, i.e. written; in your actual simulation you may ignore the y value actually being stored. Tuple r x defines that memory address x is loaded (AKA read) into some register. Simulate and track the timing for each memory access. Sample Input, Required to be Tested with 9 Page Frames: p 9 w 1254 0 w 1250 4 w 2500 8 w 1252 7 w 2600 3 w 2650 2 w 1260 0 w 2800 0 w 1268 0 w 2700 8 w 0 1 r 0 r 1250 r 2500 w 0 0 r 0 r 1252 r 2550 w 0 0 r 0 r 1254 r 2600 w 0 0 r 0 r 1256 r 2650 w 0 0 r 0 r 1258 r 2700 w 0 0 r 0 r 1260 r 2750 w 0 0 r 0 r 1262 r 2800 w 0 0 r 0 r 1264 r 2850 w 0 0 r 0 r 1266 r 2900 w 0 0 r 0 r 1268 r 2950
Answered 13 days AfterOct 12, 2021

Answer To: Handout 1, CS 133F “Introduction to Fortran Programming” csc 139 XXXXXXXXXXoperating systems...

Swapnil answered on Oct 21 2021
115 Votes
93567/Solution/a.out
93567/Solution/gen.c
#include
#define DEBUG 1
#define MAX 4
#define BPW 4
#define A_A 0
#define A_B ( A_A + sizeof( a ) )
#define A_C ( A_B + sizeof( b ) )
#define S( a, v ) printf( "w %5d %5d ", a, v );
#define L( a ) printf( "r %5d ", a )

typedef int mat_tp[ MAX ][ MAX ];
mat_tp a, b, c;
void init()
{
for( int row = 0; row < MAX; ++row )
{
for( int col = 0; col < MAX; ++col )
{
a[ row ][ col ] = row + 10 * col;
b[ row ][ col ] = row + col + 77;
c[ row ][ col ] = 0;
}
}
}
void print( mat_tp m, char * msg )
{
printf( "%s\n", msg );
for( int row = 0; row < MAX; ++row )
{
for( int col = 0; col < MAX; ++col )
{
printf( "%5d ", m[ row ][ col ] );
}
printf( "\n" );
}
printf( "\n" );
}
#ifdef DEBUG
void print
_all()
{
print( a, "matrix a[][]" );
print( b, "matrix b[][]" );
print( c, "matrix c[][]" );
}
#endif
void mat_mult( mat_tp m )
{
for( int row = 0; row < MAX; ++row )
{
for( int col = 0; col < MAX; ++col )
{
m[ row ][ col ] = 0;
for( int x = 0; x < MAX; ++x )
{
m[ row ][ col ] += a[ row ][ x ] * b[ x ][ col ];
}
}
}
}
void gen( )
{
for( int row = 0; row < MAX; ++row )
{
for( int col = 0; col < MAX; ++col )
{
for( int i = 0; i < MAX; ++ i )
{
if( ( i % 2 ) == 0 ) printf( "\n" );
S( A_C + BPW * ( row * MAX + col ), i );
L( A_C + BPW * ( row * MAX + col ) );
L( A_A + BPW * ( row * MAX + i ) );
L( A_B + BPW * ( i * MAX + col ) );
}
}
}
printf( "\n" );
}
int main( void )
{
printf( "If want larger matrix, change MAX. Now it is %d.\n", MAX );
init();
# ifdef DEBUG
mat_mult( c );
# endif
gen();
return 0;
}
93567/Solution/input.txt
p 9
w 1254 0 w 1250 4 w 2500 8 w 1252 7 w 2600 3
w 2650 2 w 1260 0 w 2800 0 w 1268 0 w 2700 8
w 0 1 r 0 r 1250 r 2500 w 0 0
r 0 r 1252 r 2550 w 0 0 r 0
r 1254 r 2600 w 0 0 r 0 r 1256
r 2650 w 0 0 r 0 r 1258 r 2700
w 0 0 r 0 r 1260 r 2750 w 0 0
r 0 r 1262 r 2800 w 0 0 r 0
r 1264 r 2850 w 0 0 r 0 r 1266
r 2900 w 0 0 r 0 r 1268 r 2950
r 3298 w 0 6048 r 0 r 2482 r 3348
w 0 6528 r 0 r 2484 r 3398 w 0 7020
r 0 r 2486 r 3448 w 0 7524 r 0
r 2488 r 3498 w 0 8040 r 0 r 2490
r 3548 w 0 8568 r 0 r 2492 r 3598
w 0 9108 r 0 r 2494 r 3648 w 0 9660
r 0 r 2496 r 3698 w 0 10224 r 0
r 2498 r 3748 w 0 10800 r 0 w 4998 10800
93567/Solution/matrix_test
93567/Solution/matrix_test.c
#include
#define DEBUG 1
#define MAX 2
#define BPW 4
#define A_A 0
#define A_B ( A_A + sizeof( a ) )
#define A_C ( A_B + sizeof( b ) )
#define S( a, v ) printf( "w %5d %5d ", a, v );
#define L( a ) printf( "r %5d ", a )

typedef int mat_tp[ MAX ][ MAX ];
void init()
{
for( int row = 0; row < MAX; ++row )
{
for( int col = 0; col < MAX; ++col )
{
a[ row ][ col ] = row + 10 * col;
b[ row ][ col ] = row + col + 77;
c[ row ][ col ] = 0;
}
}
}
void print( mat_tp m, char * msg )
{
printf( "%s\n", msg );
for( int row = 0; row < MAX; ++row )
{
for( int col = 0; col < MAX; ++col )
{
printf( "%5d ", m[ row ][ col ] );
}
printf( "\n" );
}
printf( "\n" );
}
#ifdef DEBUG
void print_all()
{
print( a, "matrix a[][]" );
print( b, "matrix b[][]" );
print( c, "matrix c[][]" );
}
#endif
void mat_mult( mat_tp m )
{
for( int row = 0; row < MAX; ++row )
{
for( int col = 0; col < MAX; ++col )
{
m[ row ][ col ] = 0;
for( int x = 0; x < MAX; ++x )
{
m[ row ][ col ] += a[ row ][ x ] * b[ x ][ col ];
}
}
}
}
void gen( )
{
for( int row = 0; row < MAX; ++row )
{
for( int col = 0; col < MAX; ++col )
{
for( int i = 0; i < MAX; ++ i )
{
if( ( i % 2 ) == 0 ) printf( "\n" );
S( A_C + BPW * ( row * MAX + col ), i );
L( A_C + BPW * ( row * MAX + col ) );
L( A_A + BPW * ( row * MAX + i ) );
L( A_B + BPW * ( i * MAX + col ) );
}
}
}
printf( "\n" );
}
int main(int argc, char ** argv)
{
printf( "If want larger matrix, change MAX. Now it is %d.\n", MAX );
init();
# ifdef DEBUG
mat_mult( c );
print_all();
# endif
gen();
return 0;
}
93567/Solution/test.cpp
#include
bool isEven(int num)
{
return num % 2 == 0;
}
int main()
{
bool tst = isEven(2);
if(tst)
{
std::cout << "slfksdfj";
}
std::cout << tst;
return 0;
}
93567/Solution/trash
93567/Solution/vmm
93567/Solution/vmm.c
#include
#include
#define NULL 0
#define BpW 4
#define P_SZ 1024
#define MAX_PAGES P_SZ * P_SZ
#define P_OFF_MASK 0xfff
#define PT_X_MASK 0x3ff000
#define PD_X_MASK 0xffc00000
#define TWO32 0xffffffff
#define BITS22 22
#define BITS12 12
#define FALSE 0
#define TRUE 1
#define NO_VALUE -1
#define BOOL unsigned
#define CYC_MEM_ACC 10        
#define CYC_PAGE_FAULT_R 5000    
#define CYC_PAGE_FAULT_W 5000    
typedef struct page_e_tp            
{
int v;
unsigned lru;
BOOL dirty;
BOOL present;
} struct_page_e_tp;
typedef struct_page_e_tp page_tp[ P_SZ ];
#define PAGE_SIZE sizeof( page_tp )
typedef page_tp * page_ptr_tp;
page_tp pd;
typedef struct triple_tp {
char action;
int m_addr;
int m_val;
} struct_triple_tp;
#define TRIPLE_SIZE sizeof( struct_triple_tp )
struct_triple_tp triple;
unsigned access_cnt = 0;
int triple_cnt = -1;
unsigned swap_out_cnt = 0;
unsigned malloc_page_cnt = 0;
unsigned page_fault_cnt = 0;
unsigned cycles = 0;
unsigned cycles_no_vmm = 0;
unsigned max_phys_pages = 0;
unsigned max_pt_pages = 0;
unsigned max_real_pages = 0;
unsigned max_log_pages = MAX_PAGES;
unsigned ws = 0;
unsigned max_ws = 0;
BOOL want_trace = FALSE;
BOOL want_swap = FALSE;
BOOL want_dump = FALSE;
int indent = 0;
#define TRACE_CALL
#ifdef TRACE_CALL
void trace_in( fu_name )
char * fu_name;
{
int i;
indent++;
for ( i = 0; i < indent; i++ )
{
if ( ( i % 10 ) == 0 )
{
printf( "." );
}
else
{
printf( " " );
}
}
printf( " > %d %s\n", access_cnt, fu_name );
fflush( stdout );
}
void trace_out( fu_name )
char * fu_name;
{
int i;
for ( i = 0; i < indent; i++ )
{
if ( ( i % 10 ) == 0 )
{
printf( "." );
}
else
{
printf( " " );
}
}
printf( " < %d %s\n", access_cnt, fu_name );
indent--;
fflush( stdout );
}
#else
#define trace_in
#define trace_out
#endif
void error( msg )
char * msg;
{
printf( " **ERROR** %s. \n", msg );
}
void assert( cond, msg )
int cond;
char * msg;
{
if ( ! cond )
{
printf( "\n * * * Assertion error! * * *\n" );
error( msg );
}
}
void init_page( page )
page_tp page;
{
int p_x;
for ( p_x = 0; p_x < P_SZ; p_x++ )
{
page[ p_x ].v = NO_VALUE;
page[ p_x ].lru = 0;
page[ p_x ].dirty = FALSE;
page[ p_x ].present = FALSE;
}
}
FILE * swap;
void init_vm_system( )
{
trace_in( "init_vm_system" );
if ( ! ( swap = fopen( "swap", "w" ) ) )
{
error( "Cannot open file 'swap'" );
}
fprintf( swap, "swap information.\n" );
init_page( pd );
trace_out( "init_vm_system" );
}
void put_triple( )
{
if ( triple_cnt % 5 == 0 )
{
printf( "\n" );
}
printf( "%c ", triple.action );
printf( "%5d ", triple.m_addr );
if ( triple.action == 'w' )
{
printf( "%4d ", triple.m_val );
}
else
{
printf( " " );
}
}
unsigned get_triple( )
{
char action = ' ';
int ...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here