Extending Code Genera/on to � Support Pla6orm-Independent Event-B Models Asieh Salehi, Michael Butler, Colin Snook University of Southampton, Southampton, United Kingdom 6th Rodin User and Developer Workshop, 23 May, 2016, Linz, Austria
Overview • MoHvaHon • Background: • Code GeneraHon (CG) with Tasking Event-B • Branching Control Flow • Case Study (PRiME project*): • Embedded Run-Time Management (RTM) system • PlaVorm Dependencies • Modelling and Tasking by Restricted CG • Modelling and Tasking by Extended CG • Extending Code GeneraHon Plugin • Case Study Overview • Summary and Future work * Power-efficient, Reliable, Many-core Embedded systems. h[p://www.prime-project.org 1
Mo/va/on Platform)I+Dependent Platform)II+Dependent Platform)Independent Event+B)Model Event+B)Model Event)B2Model Extended CG approach Previous CG approach Code)Generation Code)Generation Instantiation2and2 Code2Generation Platform2II2)Specific Platform)I)+Specific Platform)II)+Specific Platform2I2)Specific Implementation)Code Implementation)Code Implementation2Code Implementation2Code • a single implementaHon for the Event-B model • different plaVorm-specific implementaHons • dependency between the Event-B model and from the same Event-B model target plaVorm architecture • plaVorm-independent Event-B model plaVorm-specific implementaHons Extending Code GeneraHon to Support PlaVorm-Independent Event-B Models 2
Background:� Code Genera/on with Tasking Event-B • Code generaHon in Event-B addresses the gap between Abstraction the lowest level Event-B refinement and an implementa7on . Refinements • Tasking Event-B is an extension of Event-B to introduce Tasking control flows: • Sequence Implementation • Branch • Loop Extending Code GeneraHon to Support PlaVorm-Independent Event-B Models 3
Background (cont.):� Branching Control Flow • Task body: if evt_1 [ elseif evt_i ]* else evt_n • TranslaHon (pseudocode): if (g_1) then a_1 [else (g_i) then a_i end ]* else a_n end (where g_i and a_i indicate guard and acHon of the evt_i respecHvely) Extending Code GeneraHon to Support PlaVorm-Independent Event-B Models 4
Case Study: � Embedded Run-Time Management (RTM) system � • ApplicaHon provides the required Application* Video&Decoder deadline (frame-per-second (FPS)) Layer • RTM decides about the opHmal value of FPS Voltage-Frequency (VF) • The workload (cpu-cycles) to decode the OS frame is monitored. Run-Time&Manager Layer • RTM aims to choose the opHmal value of VF which meets deadline while saving VF&setting CPU&cycles power. Hardware CPU Layer Extending Code GeneraHon to Support PlaVorm-Independent Event-B Models 5
Case Study (cont.):� Predic/on and Machine Learning at Run-/me RTM uses predic7on and machine Abstract8Model RTM learning algorithms to decide about the opHmal value of VF. read_deadline select_vf control_vf monitor_workload Prediction8 • First Refinement: PredicHon Refinement select_vf monitor_workload update_prediction predict_workload • Second Refinement: Machine Learning (using a learning table) Decision8Making8 Refinement xor ran8>8 ε ran8≤8ε ranGenerator VFGenerator explore exploit updateE monitor_workload update_qTable Extending Code GeneraHon to Support PlaVorm-Independent Event-B Models 6
Case Study(Cont.):� Pla6orm Dependencies • An RTM model can require adjustments across different hardware plaVorms due to the diversity of architecture characteris7cs . • The number of supported frequencies by Frequencies freq1 freq2 freq3 freq4 each plaVorm determines the number of 1 0.8 0.2 0.2 0.1 columns in the learning table used to workload 2 ,0.1 0.6 0.4 0.2 record the rewards and penalHes for each 3 ,0.4 ,0.2 0.7 0.3 VF seing decision. 4 ,1.0 ,0.8 ,0.1 0.8 Extending Code GeneraHon to Support PlaVorm-Independent Event-B Models 7
Modelling and Tasking by Restricted CG EventAB&actions&to&modify&the&learning&table& generated&C&code&for&a& (dependent on&the&number&of&frequencies) platform&with&n&number&of&frequencies … update_col1_qTable � if (&freq =&FREQ1&)& WHERE freq =&FREQ1 {& THEN qTable[row][0]&=&value; qTable � updateArray( qTable,&row, 0,&value ) tasking&body } … update_col2_qTable � … code& else5if (&freq =&FREQi )& WHERE freq =&FREQ2 if update_col1_qTable tasking generation {& THEN [& elseif update_coli_qTable ] * qTable � updateArray( qTable,&row, 1,&value ) qTable[row][i]&=&value; else update_coln_qTable }& … … … else update_coln_qTable � {& WHERE freq =&FREQn qTable[row][NA1]&=&value;& THEN } qTable � updateArray( qTable,&row, NA1,&value ) … Extending Code GeneraHon to Support PlaVorm-Independent Event-B Models 8
Modelling and Tasking by Extended CG generated$C$code$for$platform$ARM8 with$4$frequencies$ … if ($freq =$FREQ1$)$ qTable[row][0]$=$value; else/if ($freq =$FREQ2$)$ qTable[row][1]$=$value$; else/if ($freq =$FREQ3$)$ EventCB$action$to$modify$the$learning$table$ qTable[row][2]$=$value$; (independent on$the$number$of$frequencies) N$=$4 else qTable[row][3]$=$value$; update_qTable � tasking$body … ANY i … tasking code$ WHERE i � 1 � N$ expanding generated$C$code$for$platform$ARM7 update_qTable generation &$ freq = F(i) with$13$frequencies$ … THEN … qTable � updateArray( qTable,$row, i,$value ) if ($freq =$FREQ1$)$ qTable[row][0]$=$value; N$=$13 . . else/if ($freq =$FREQ12$)$ qTable[row][11]$=$value$; else qTable[row][12]$=$value$; … Extending Code GeneraHon to Support PlaVorm-Independent Event-B Models 9
Extending Code Genera/on Plugin • Expanding Guard: • indexed by a constant (N) • N is instanHated during translaHon • Task body TranslaHon tasking.body expanded.tasking.body generated.C.code … … if evt_1 if (.g_1.).{.a_1.} … expanding_evt (indexed.by.n). [. elseif evt_i ]* [. else&if (.g_i ).{.a_i }.]* … else evt_n else {.a_n } … … UI.view Extending Code GeneraHon to Support PlaVorm-Independent Event-B Models 10
Event&B(Design(Level Case Study Overview Context:0Platform0 Abstract0Model Parameters Interaction0interfaces between0 N:0number0of0VF application,0RTM0and0hardware VF:0set0of0VF0values Wl: maximum0workload refines Latency:0DVFS0switch0Latency Prediction0Refinement • One abstract, two refinements Prediction0algorithm0details • Model DecomposiHon: refines Decision0Making0Refinement • Controller: RTM algorithms Machine0learning0algorithm0details • Environment: InteracHon Interfaces decompose Controller Environment • Code GeneraHon RTM0algorithms: Prediction, ML Interaction0Interfaces • Theory definiHons refines refines Environment0Refinement Controller0Refinement Tasking0Environment Tasking0controller Automatic$ Automatic$code$generation$& Instantiation$& code$generation interaction$APIs$call$replacement Automatic$code$generation Implementation(Level Interaction$Interfaces$ Data$Definition RTM$Controller$ (Environment.c) (Common.c) (Controller.c) 11
Case Study Overview: Theories • Array theory to specify the learning table • EWMA* theory to specify the predicHon operators and translaHons • ML theory to specify the machine learning operators and translaHons 12 * ExponenHally Weighted Moving Average
Case Study Overview: Proving • Abstract specificaHon of the predicHon*: • Refined specificaHon of the predicHon: * 13
Case Study Overview: Proving (cont.) • Abstract specificaHon of the predicHon*: • Refined specificaHon of the predicHon: * 14
Summary and Future Work Extending Code GeneraHon technique in the Event-B formal method provides an approach to manage pla$orm diversity by shiming the focus away from hand- wri4en pla$orm-specific code to pla$orm-independent verified models from which plaVorm-specific implementaHons are automa8cally generated . • In the PRiME project, we are extending our RTM modelling, translaHon to support more run-Hme algorithms: • Extend the code generaHon in-line • New plugin release Extending Code GeneraHon to Support PlaVorm-Independent Event-B Models 15
Thank you� Any Ques/on?� Extending Code GeneraHon to Support PlaVorm-Independent Event-B Models 16
Recommend
More recommend