1 / 15

Joe McCarthy

Program 3 Implementing Java Monitors: Kernel support for SysLib methods join(), exit(), rawread(), rawwrite(), sync(). Joe McCarthy. File System (Ch. 11). File system interface provides applications with various system calls and commands such as open, write, read, seek, etc..

lane-heath
Download Presentation

Joe McCarthy

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Program 3Implementing Java Monitors: Kernel support for SysLib methodsjoin(), exit(), rawread(), rawwrite(), sync() Joe McCarthy CSS 430: Operating Systems - Program 3

  2. File System (Ch. 11) • File system interface provides applications with various system calls and commands such as open, write, read, seek, etc.. • File system maintains disk space in blocks and allocates available blocks to each stream-oriented file. • Basic file system (BIOS) maintains data in physical blocks • Device driver reads / writes disk blocks which consists of one (or more) sector(s). • Disk maintains physical block locations indexed by drive#, cylinder#, track# and sector# track sector cylinder CSS 430: Operating Systems - Program 3

  3. File System (Ch. 11) CSS 430: Operating Systems - Program 3

  4. SysLib.rawread(), Kernel.RAWREAD public class SysLib { … public static int rawread( int blkNumber, byte[] b ) { return Kernel.interrupt( Kernel.INTERRUPT_SOFTWARE, Kernel.RAWREAD, blkNumber, b ); } public class Kernel { … public static int interrupt( int irq, int cmd, int param, Object args ) { // Looks like myTcb is not used anywhere; newTcb declared & used below // TCB myTcb; switch( irq ) { case INTERRUPT_SOFTWARE: // System calls switch( cmd ) { … case RAWREAD: // read a block of data from disk while ( disk.read( param, ( byte[] )args ) == false ) ; // busy wait while ( disk.testAndResetReady() == false ) ; // busy wait; return OK; CSS 430: Operating Systems - Program 3

  5. SysLib.rawread(), Kernel.RAWREAD public class SysLib { … public static int rawread( int blkNumber, byte[] b ) { return Kernel.interrupt( Kernel.INTERRUPT_SOFTWARE, Kernel.RAWREAD, blkNumber, b ); } public class Kernel { … public static int interrupt( int irq, int cmd, int param, Object args ) { // Looks like myTcb is not used anywhere; newTcb declared & used below // TCB myTcb; switch( irq ) { case INTERRUPT_SOFTWARE: // System calls switch( cmd ) { … case RAWREAD: // read a block of data from disk while ( disk.read( param, ( byte[] )args ) == false ) ioQueue.enqueueAndSleep( COND_DISK_REQ ); while ( disk.testAndResetReady() == false ) ioQueue.enqueueAndSleep( CONDDISK_FIN ); return OK; CSS 430: Operating Systems - Program 3

  6. Disk.read(),Disk.testAndResetReady() public class Disk { … public synchronized boolean read( int blockId, byte buffer[] ) { if ( blockId < 0 || blockId > diskSize ) { SysLib.cerr( "threadOS: invalid blockId for read\n" ); return false; } if ( command == IDLE && readyBuffer == false ) { this.buffer = buffer; targetBlockId = blockId; command = READ; notify(); return true; } else return false; } … public synchronized boolean testAndResetReady( ) { if ( command == IDLE && readyBuffer == true ) { readyBuffer = false; return true; } else return false; } CSS 430: Operating Systems - Program 3

  7. Disk.run() public class Disk { … public void run () { while ( true ) { waitCommand(); seek( ); switch( command ) { case READ: System.arraycopy( data, targetBlockId * blockSize, buffer, 0, blockSize ); break; case WRITE: … case SYNC: … } finishCommand(); } } CSS 430: Operating Systems - Program 3

  8. Disk.waitCommand(), Disk.finishCommand() public class Disk { … private synchronized void waitCommand() { while ( command == IDLE ) { try { wait(); } catch ( InterruptedException e ) { SysLib.cerr( e.toString() + "\n" ); } readyBuffer = false; } } … private synchronized void finishCommand() { command = IDLE; readyBuffer = true; SysLib.disk(); // generate a disk interrupt } CSS 430: Operating Systems - Program 3

  9. SysLib.disk(), Kernel.INTERRUPT_DISK public class SysLib { … public static int disk() { return Kernel.interrupt( Kernel.INTERRUPT_DISK, 0, 0, null ); } public class Kernel { … public static int interrupt( int irq, int cmd, int param, Object args ) { // Looks like myTcb is not used anywhere; newTcb declared & used below // TCB myTcb; switch( irq ) { … case INTERRUPT_DISK: // Disk interrupts // wake up the thread waiting for a service completion first ioQueue.dequeueAndWakeup( COND_DISK_FIN ); // wake up a thread waiting for a request acceptance ioQueue.dequeueAndWakeup( COND_DISK_REQ ); return OK; … CSS 430: Operating Systems - Program 3

  10. Test2e class Test2e extends Thread { public void run() { String[] args1 = SysLib.stringToArgs( "TestThread2 a 5000 0" ); String[] args2 = SysLib.stringToArgs( "TestThread2 b 1000 0" ); String[] args3 = SysLib.stringToArgs( "TestThread2 c 3000 0" ); String[] args4 = SysLib.stringToArgs( "TestThread2 d 6000 0" ); String[] args5 = SysLib.stringToArgs( "TestThread2 e 500 0" ); SysLib.exec( args1 ); SysLib.exec( args2 ); SysLib.exec( args3 ); SysLib.exec( args4 ); SysLib.exec( args5 ); for (int i = 0; i < 5; i++ ) { int tid = SysLib.join(); SysLib.cout( "Thread tid=" + tid + " done\n” ); SysLib.cout( "Test2e finished; total time = " + totalTime + "\n" ); SysLib.exit(); } } CSS 430: Operating Systems - Program 3

  11. TestThread2 class TestThread2 extends Thread { … public void run() { long totalExecutionTime = 0; long totalWaitTime = 0; activationTime = new Date().getTime(); for ( int burst = cpuBurst; burst > 0; burst -= TIMEQUANTUM ) { totalExecutionTime += TIMEQUANTUM; SysLib.sleep( TIMEQUANTUM ); } completionTime = new Date().getTime( ); long responseTime = activationTime - submissionTime; totalWaitTime = completionTime - submissionTime - executionTime; long turnaroundTime = completionTime - submissionTime; SysLib.cout( String.format( "%05d: Thread[%s]: response: %5d; wait: %5d; execution: %5d; turnaround: %5d\n", completionTime % 100000, name, responseTime, totalWaitTime, totalExecutionTime, turnaroundTime ) ); SysLib.exit(); } } CSS 430: Operating Systems - Program 3

  12. Test2e output d-69-91-160-124:ThreadOS0 joe$ java Boot threadOS ver 1.0: Type ? for help threadOS: a new thread (thread=Thread[Thread-4,2,main] tid=0 pid=-1) -->l Shell l Shell threadOS: a new thread (thread=Thread[Thread-6,2,main] tid=1 pid=0) shell[1]% Test2e Test2e threadOS: a new thread (thread=Thread[Thread-9,2,main] tid=2 pid=1) threadOS: a new thread (thread=Thread[Thread-11,2,main] tid=3 pid=2) threadOS: a new thread (thread=Thread[Thread-13,2,main] tid=4 pid=2) threadOS: a new thread (thread=Thread[Thread-15,2,main] tid=5 pid=2) threadOS: a new thread (thread=Thread[Thread-17,2,main] tid=6 pid=2) threadOS: a new thread (thread=Thread[Thread-19,2,main] tid=7 pid=2) Thread[b]: response time = 3942 turnaround time = 4944 execution time = 1002 Thread tid=4 done Thread[e]: response time = 6944 turnaround time = 7445 execution time = 501 Thread tid=7 done Thread[a]: response time = 2941 turnaround time = 7948 execution time = 5007 Thread tid=3 done Thread[c]: response time = 4945 turnaround time = 7951 execution time = 3006 Thread tid=5 done Thread[d]: response time = 5944 turnaround time = 11953 execution time = 6009 Thread tid=6 done Test2e finished shell[2]% exit exit -->q b e d a c CSS 430: Operating Systems - Program 3

  13. SysLib.join(), Kernel.WAIT public class SysLib { … public static int join() { return Kernel.interrupt( Kernel.INTERRUPT_SOFTWARE, Kernel.WAIT, 0, null ); } public class Kernel { … public static int interrupt( int irq, int cmd, int param, Object args ) { // Looks like myTcb is not used anywhere; newTcb declared & used below // TCB myTcb; switch( irq ) { case INTERRUPT_SOFTWARE: // System calls switch( cmd ) { … case WAIT: // get the current thread id // let the current thread sleep in waitQueue under the // condition = this thread id // System.out.print( " * " ); return OK; // return a child thread id who woke me up … CSS 430: Operating Systems - Program 3

  14. enqueueAndSleep(),dequeueAndWakeup() CSS 430: Operating Systems - Program 3

  15. SysLib.exit(), Kernel.EXIT public class SysLib { … public static int exit( ) { return Kernel.interrupt( Kernel.INTERRUPT_SOFTWARE, Kernel.EXIT, 0, null ); } public class Kernel { … public static int interrupt( int irq, int cmd, int param, Object args ) { // Looks like myTcb is not used anywhere; newTcb declared & used below // TCB myTcb; switch( irq ) { case INTERRUPT_SOFTWARE: // System calls switch( cmd ) { … case EXIT: // get the current thread's parent id // search waitQueue for and wakes up the thread under the // condition = the current thread's parent id // tell the Scheduler to delete the current thread // (since it is exiting) return OK; CSS 430: Operating Systems - Program 3

More Related