The Implementation of Dynamic Priority Assignment on CVM Threading System Insik Shin Real-time Systems Group University of Pennsylvania
Dynamic Priority Assignment Dynamic Priority Assignment (DPA) –When a thread is ready for its execution, its priority is dynamically assigned. DPA Policy –Assign the highest priority to thread A s. t. threads of lower priorities than A have later deadlines than A
Agenda Demos on the priority scheduling on CVM Demos on the periodic thread executions on CVM Output of the DPA implementation on CVM How to implement the DPA on CVM
Demo1 : Realtime vs Non-realtime class Demo1 { NRT t1 = new NRT(“Non-realtime Thread ” );NRT RT t2 = new RT(“Realtime Thread”);RT t1.start(); for (int i=0; i< ; i++) ; /* busy waiting */ t2.start(); } class NRT extends Thread { void run() { for (int i=0;i<5;i++) { /* busy waiting */ for (int j=0; j< ; j++) ; println (i + “ – “ + name); } println (“DONE! – “ + name); } class RT extends RealtimeThread { void run() { for (int i=0;i<5;i++) { /* busy waiting */ for (int j=0; j< ; j++) ; println (i + “ – “ + name); } println (“DONE! – “ + name); }
Demo1 : Realtime vs Non-realtime OUTPUT [JVM] A new thread is created. 0 Non-realtime Thread Non-realtime Thread Non-realtime Thread [JVM] A new thread is created. 0 Realtime Thread Realtime Thread Realtime Thread Realtime Thread Realtime Thread DONE! - Realtime Thread 3 Non-realtime Thread Non-realtime Thread DONE! - Non-realtime Thread bin]# class Demo1 { NRT t1 = new NRT(“ Non-realtime Thread” );NRT RT t2 = new RT(“ Realtime Thread ”);RT t1.start(); /* busy waiting */ for (int i=0; i< ; i++) ; t2.start(); }
Demo2 : Priority Scheduling class Demo2 { PriorityParameters p15 = new PriorityParameters(15); PriorityParameters p25 = new PriorityParameters(25); RT t1 = new RT(“Priority 15 ”, p15);RT RT t2 = new RT(“Priority 25 ”, p25);RT t1.start(); for (int i=0; i< ; i++) ; /* busy waiting */ t2.start(); }
Demo2 : Priority Scheduling OUTPUT [JVM] A new thread is created. 0 – Priority 15 – – Priority – Priority – Priority – Priority DONE! – Priority 15 [JVM] A new thread is created. 0 – Priority 25 – – Priority 25 – – Priority 25 – – Priority 25 – – Priority 25 – 163 DONE! – Priority 25 class Demo2 { RT t1 = new RT(“P 15”, p15);RT RT t2 = new RT(“P 25”, p25”);RT t1.start(); /* busy waiting */ for (int i=0; i< ; i++) ; t2.start(); }
Demo3 : Periodic Thread class Demo3 { PriorityParameters p15 = new PriorityParameters(15); PeriodicParameters pp = new PeriodicParameters ( new RelativeTime (100, 0), // start time new RelativeTime (500, 0), // period new RelativeTime (200, 0), // cost new RelativeTime (500, 0), // deadline null, null); // handlers PRT t1 = new PRT(“Periodic”, p15, pp);PRT t1.start(); }
Demo3 : Periodic Thread OUTPUT [JVM] A new thread is created. [RT] wFNP 0 – Periodic – 672 [RT] wFNP 1– Periodic – 500 [RT] wFNP 2 – Periodic – 500 [RT] wFNP 3 – Periodic – 500 [RT] wFNP 4 – Periodic – 500 DONE! – Periodic class Demo3 { RT t1 = new PRT(“Periodic”, p15, pp);PRT t1.start(); } class PRT extends RealtimeThread { void run() { for (int i=0;i<5;i++) { waitForNextPeriod(); /* busy waiting */ for (int j=0; j< ; j++) ; println (i + “ – “ + name); } println (“DONE! – “ + name); }
Demo4 : Periodic Threads OUTPUT [JVM] A new thread is created. 0 – Priority 25 – – Priority 15 – 836 1– Priority 25 – 500 1– Priority 15 – 500 2– Priority 25 – 500 2– Priority 15 – 500 3– Priority 25 – 500 3– Priority 15 – 500 4– Priority 25 – 500 DONE! – Priority 25 5– Priority 15 – 500 DONE! – Priority 15 class Demo4 { RT t1 = new PRT(“P 15”, p15, pp);PRT RT t2 = new PRT(“P 25”, p25, pp);PRT t1.start(); t2.start(); } class PRT extends RealtimeThread { void run() { for (int i=0;i<5;i++) { waitForNextPeriod(); /* busy waiting */ for (int j=0; j< ; j++) ; println (i + “ – “ + name); } println (“DONE! – “ + name); }
Test : Dynamic Priority Assignment class Test { PriorityParameters p15 = new PriorityParameters(15); PriorityParameters p25 = new PriorityParameters(25); PriorityParameters p50 = new PriorityParameters(50); PeriodicParameters pp1; // period = deadline = 1500 PeriodicParameters pp2; // period = deadline = 800 PeriodicParameters pp3; // period = deadline = 1000 PRT t1 = new PRT(“FIX : P15”, p15, pp1);PRT PRT t2 = new PRT(“FIX : P25”, p25, pp2);PRT PRT t3 = new PRT(“Dynamic”, p50, pp3);PRT t1.start(); t2.start(); t3.start(); }