------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- Cheddar is a GNU GPL real-time scheduling analysis tool. -- This program provides services to automatically check schedulability and -- other performance criteria of real-time architecture models. -- -- Copyright (C) 2002-2016, Frank Singhoff, Alain Plantec, Jerome Legrand -- -- The Cheddar project was started in 2002 by -- Frank Singhoff, Lab-STICC UMR 6285 laboratory, Université de Bretagne Occidentale -- -- Cheddar has been published in the "Agence de Protection des Programmes/France" in 2008. -- Since 2008, Ellidiss technologies also contributes to the development of -- Cheddar and provides industrial support. -- -- The full list of contributors and sponsors can be found in AUTHORS.txt and SPONSORS.txt -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2 of the License, or -- (at your option) any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; if not, write to the Free Software -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -- -- -- Contact : cheddar@listes.univ-brest.fr -- ------------------------------------------------------------------------------ -- Last update : -- $Rev: 1249 $ -- $Date: 2014-08-28 07:02:15 +0200 (Fri, 28 Aug 2014) $ -- $Author: singhoff $ ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ with Gtk; use Gtk; with Gtk.Main; use Gtk.Main; with Gtk.Menu_Item; use Gtk.Menu_Item; with Gtk.Widget; use Gtk.Widget; with Gtk.Handlers; use Gtk.Handlers; with Gtk.Dialog; use Gtk.Dialog; with Gtk.About_Dialog; use Gtk.About_Dialog; with Gtk.Check_Button; use Gtk.Check_Button; with Gtk.Text_Buffer; use Gtk.Text_Buffer; with Gtk.Label; use Gtk.Label; with Gtk.Text_Iter; use Gtk.Text_Iter; with Glib; use Glib; with Glib.Error; use Glib.Error; with Glib.Object; use Glib.Object; with Gdk.Drawable; use Gdk.Drawable; with Gdk.font; use Gdk.font; with Gdk.Color; use Gdk.Color; with Gdk.GC; use Gdk.GC; with Gdk.Event; use Gdk.Event; with Gdk.Window; use Gdk.Window; with pango.font; use pango.font; with graphical_editor.generic_package_widget; use graphical_editor.generic_package_widget; with Ada.Text_IO; use Ada.Text_IO; with Framework; use Framework; with Call_Framework; use Call_Framework; with Call_Framework_Interface; use Call_Framework_Interface; use Call_Framework_Interface.Framework_Request_Package; use Call_Framework_Interface.Framework_Response_Package; with Editor_Config; use Editor_Config; with time_unit_events.extended; use time_unit_events.extended; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; with Parameters; use Parameters; with Parameters.extended; use Parameters.extended; use Parameters.Framework_Parameters_Table_Package; with Call_Scheduling_Framework; use Call_Scheduling_Framework; with Multiprocessor_Services; use Multiprocessor_Services; with Multiprocessor_Services_Interface; use Multiprocessor_Services_Interface; use Multiprocessor_Services_Interface.Scheduling_Result_Per_Processor_Package; with Framework_Config; use Framework_Config; with Editor_Config; use Editor_Config; with strings; use strings; with unbounded_strings; use unbounded_strings; with Translate; use Translate; with Processors; use Processors; with Processor_Set; use Processor_Set; use Processor_Set.Generic_Processor_Set; with Task_Set; use Task_Set; use Task_Set.Generic_Task_Set; with Resource_Set; use Resource_Set; use Resource_Set.Generic_Resource_Set; with Message_Set; use Message_Set; use Message_Set.Generic_Message_Set; with Buffer_Set; use Buffer_Set; use Buffer_Set.Generic_Buffer_Set; with time_unit_events; use time_unit_events; with time_unit_events.extended; use time_unit_events.extended; with graphical_editor.scheduling_simulation_callbacks; use graphical_editor.scheduling_simulation_callbacks; with graphical_editor.user_message; use graphical_editor.user_message; with graphical_editor.Select_Time_Line; use graphical_editor.Select_Time_Line; with graphical_editor.Draw_Scheduling; use graphical_editor.Draw_Scheduling; with graphical_editor.message_text; use graphical_editor.message_text; package body graphical_editor.scheduling_simulation_draw_callbacks is Draw_From, Draw_Upto, Schedule_To : Unbounded_String; Last_Period : constant Natural := Framework_Config.Max_Scheduling_Period - 1; Max_Period : Integer := 0; Start_Draw : Integer := 0; Stop_Draw : Integer := 0; Max_Draw : Natural := 1500; Ok : Boolean; line_Number : integer := 0; procedure Read_scheduling_Duration_And_Draw_Scheduling (Object : access Gtkada_Builder_Record'Class) is Object_Number : Natural := 0; begin Draw_From := suppress_space(get_value_buffer_string(Gtk_Text_Buffer(Get_Object(Object, "textbuffer2")))); Draw_Upto := suppress_space(get_value_buffer_string(Gtk_Text_Buffer(Get_Object(Object, "textbuffer3")))); Schedule_To := suppress_space(get_value_buffer_string(Gtk_Text_Buffer(Get_Object(Object, "textbuffer1")))); graphical_editor.scheduling_simulation_draw_callbacks.Close_Widget(Object); to_integer (Draw_Upto, Stop_Draw, Ok); if not Ok then Show_Message_Box (Lb_Double_Quote & Lb_Draw_To (Current_Language) & Lb_Double_Quote & Lb_Must_Be_Numeric (Current_Language)); return; end if; to_integer (Draw_From, Start_Draw, Ok); if not Ok then Show_Message_Box (Lb_Double_Quote & Lb_Draw_From (Current_Language) & Lb_Double_Quote & Lb_Must_Be_Numeric (Current_Language)); return; end if; to_integer (Schedule_To, Max_Period, Ok); if not Ok then Show_Message_Box (Lb_Double_Quote & Lb_Schedule_To (Current_Language) & Lb_Double_Quote & Lb_Must_Be_Numeric (Current_Language)); return; end if; if (Max_Period > integer(Last_Period)) then Show_Message_Box (Lb_Double_Quote & Lb_Schedule_To (Current_Language) & Lb_Double_Quote & Lb_Must_Be (Current_Language) & Lb_less_or_equal_than (current_language) & Last_Period'Img); return; end if; if (Max_Period <= 0) then Show_Message_Box (Lb_Double_Quote & Lb_Schedule_To (Current_Language) & Lb_Double_Quote & Lb_Must_Be (Current_Language) & Lb_greater_than (current_language) & To_Unbounded_String (" 0")); return; end if; if (Start_Draw < 0) then Show_Message_Box (Lb_Double_Quote & Lb_Draw_From (Current_Language) & Lb_Double_Quote & Lb_Must_Be (Current_Language) & Lb_greater_or_equal_than (current_language) & To_Unbounded_String (" 0")); return; end if; if (Stop_Draw < 0) then Show_Message_Box (Lb_Double_Quote & Lb_Draw_To (Current_Language) & Lb_Double_Quote & Lb_Must_Be (Current_Language) & Lb_greater_or_equal_than (current_language) & To_Unbounded_String (" 0")); return; end if; if (Start_Draw > Max_Period) then Show_Message_Box (Lb_Double_Quote & Lb_Draw_From (Current_Language) & Lb_Double_Quote & Lb_Must_Be (Current_Language) & Lb_less_or_equal_than (current_language) & Lb_Double_Quote & Lb_Schedule_To (Current_Language) & Lb_Double_Quote); return; end if; if (Stop_Draw - Start_Draw > Max_Draw) then Show_Message_Box (Lb_Draw_Time_Line_Too_Large (Current_Language)); return; end if; -- Check if we need to select which tasks/messages/buffers -- to display with time lines -- Object_Number := Natural (get_number_of_elements (Sys.Tasks)) + Natural (get_number_of_elements (Sys.Messages)) + Natural (get_number_of_elements (Sys.Buffers)); if Schedule_With_Resources then Object_Number := Object_Number + Natural (get_number_of_elements (Sys.Resources)); end if; if Customized_Simulation then if Object_Number > Editor_Config.Max_Time_Line_To_Display then graphical_editor.Select_Time_Line.Gtk_New (graphical_editor.Select_Time_Line.Select_Time_Line, Sys, Call_Customized_Simulation'Access); Show_All (graphical_editor.Select_Time_Line.Select_Time_Line); else Call_Customized_Simulation; end if; else if Object_Number > Editor_Config.Max_Time_Line_To_Display then graphical_editor.Select_Time_Line.Gtk_New (graphical_editor.Select_Time_Line.Select_Time_Line, Sys, Call_Uncustomized_Simulation'Access); Show_All (graphical_editor.Select_Time_Line.Select_Time_Line); else Call_Uncustomized_Simulation; end if; end if; Customized_Simulation := False; end Read_scheduling_Duration_And_Draw_Scheduling; function Expose (W : access Gtk.Drawing_Area.Gtk_Drawing_Area_Record'Class) return boolean is begin Draw_Time_Line(Stop_Draw, Start_Draw, Framework.Sched); return false; end Expose; procedure Call_Processor_Analysis (Name : Unbounded_String) is Response_List : Framework_Response_Table; Request_List : Framework_Request_Table; A_Request : Framework_Request; A_Param : Parameter_Ptr; begin if Preemption_From_Simulation then initialize (Response_List); initialize (Request_List); Initialize (A_Request); Initialize (A_Request.param); A_Request.target := Name; A_Request.statement := Scheduling_Simulation_Preemption_Number; add (Request_List, A_Request); Sequential_Framework_Request (Sys, Request_List, Response_List); Write_Title(Response_List); Write_Text(Response_List); end if; if Context_Switch_From_Simulation then initialize (Response_List); initialize (Request_List); Initialize (A_Request); Initialize (A_Request.param); A_Request.target := Name; A_Request.statement := Scheduling_Simulation_Context_Switch_Number; add (Request_List, A_Request); Sequential_Framework_Request (Sys, Request_List, Response_List); Write_Title(Response_List); Write_Text(Response_List); end if; if (Response_Time_From_Simulation (Worst_Case) or Response_Time_From_Simulation (Best_Case) or Response_Time_From_Simulation (Average_Case) or Response_Time_From_Simulation (Plot_Case)) then Initialize (A_Request); Initialize (A_Request.param); initialize (Response_List); initialize (Request_List); A_Param := new Parameter (Boolean_Parameter); A_Param.parameter_name := To_Unbounded_String ("worst_case"); if Response_Time_From_Simulation (Worst_Case) then A_Param.boolean_value := True; else A_Param.boolean_value := False; end if; add (A_Request.param, A_Param); A_Param := new Parameter (Boolean_Parameter); A_Param.parameter_name := To_Unbounded_String ("best_case"); if Response_Time_From_Simulation (Best_Case) then A_Param.boolean_value := True; else A_Param.boolean_value := False; end if; add (A_Request.param, A_Param); A_Param := new Parameter (Boolean_Parameter); A_Param.parameter_name := To_Unbounded_String ("average_case"); if Response_Time_From_Simulation (Average_Case) then A_Param.boolean_value := True; else A_Param.boolean_value := False; end if; add (A_Request.param, A_Param); A_Request.target := Name; A_Request.statement := Scheduling_Simulation_Response_Time; add (Request_List, A_Request); Sequential_Framework_Request (Sys, Request_List, Response_List); Write_Title(Response_List); Write_Text(Response_List); end if; if (Blocking_Time_From_Simulation (Worst_Case) or Blocking_Time_From_Simulation (Best_Case) or Blocking_Time_From_Simulation (Average_Case) or Blocking_Time_From_Simulation (Plot_Case)) then Initialize (A_Request); Initialize (A_Request.param); initialize (Response_List); initialize (Request_List); A_Param := new Parameter (Boolean_Parameter); A_Param.parameter_name := To_Unbounded_String ("worst_case"); if Blocking_Time_From_Simulation (Worst_Case) then A_Param.boolean_value := True; else A_Param.boolean_value := False; end if; add (A_Request.param, A_Param); A_Param := new Parameter (Boolean_Parameter); A_Param.parameter_name := To_Unbounded_String ("best_case"); if Blocking_Time_From_Simulation (Best_Case) then A_Param.boolean_value := True; else A_Param.boolean_value := False; end if; add (A_Request.param, A_Param); A_Param := new Parameter (Boolean_Parameter); A_Param.parameter_name := To_Unbounded_String ("average_case"); if Blocking_Time_From_Simulation (Average_Case) then A_Param.boolean_value := True; else A_Param.boolean_value := False; end if; add (A_Request.param, A_Param); A_Request.target := Name; A_Request.statement := Scheduling_Simulation_Blocking_Time; add (Request_List, A_Request); Sequential_Framework_Request (Sys, Request_List, Response_List); Write_Title(Response_List); Write_Text(Response_List); end if; end Call_Processor_Analysis; procedure Call_Uncustomized_Simulation is Response_List : Framework_Response_Table; Request_List : Framework_Request_Table; A_Request : Framework_Request; A_Param : Parameter_Ptr; begin Initialize (A_Request); Initialize (A_Request.param); A_Request.statement := Scheduling_Simulation_Time_Line; A_Param := new Parameter (Integer_Parameter); A_Param.parameter_name := To_Unbounded_String ("period"); A_Param.integer_value := Max_Period; add (A_Request.param, A_Param); A_Param := new Parameter (Boolean_Parameter); A_Param.parameter_name := To_Unbounded_String ("schedule_with_offsets"); A_Param.boolean_value := Schedule_With_Offsets; add (A_Request.param, A_Param); A_Param := new Parameter (Boolean_Parameter); A_Param.parameter_name := To_Unbounded_String ("schedule_with_precedencies"); A_Param.boolean_value := Schedule_With_Precedencies; add (A_Request.param, A_Param); A_Param := new Parameter (Boolean_Parameter); A_Param.parameter_name := To_Unbounded_String ("minimize_preemption"); A_Param.boolean_value := minimize_preemption; add (A_Request.param, A_Param); A_Param := new Parameter (Boolean_Parameter); A_Param.parameter_name := To_Unbounded_String ("schedule_with_jitters"); A_Param.boolean_value := schedule_with_jitters; add (A_Request.param, A_Param); A_Param := new Parameter (Boolean_Parameter); A_Param.parameter_name := To_Unbounded_String ("schedule_with_resources"); A_Param.boolean_value := Schedule_With_Resources; add (A_Request.param, A_Param); A_Param := new Parameter (Boolean_Parameter); A_Param.parameter_name := To_Unbounded_String ("schedule_with_crpd"); A_Param.boolean_value := Schedule_With_crpd; add (A_Request.param, A_Param); A_Param := new Parameter (Boolean_Parameter); A_Param.parameter_name := To_Unbounded_String ("predictable"); A_Param.boolean_value := Is_Global_Predictable_Seed; add (A_Request.param, A_Param); if Has_Global_Seed then A_Param := new Parameter (Integer_Parameter); A_Param.parameter_name := To_Unbounded_String ("seed_value"); A_Param.integer_value := Global_Seed_Value; add (A_Request.param, A_Param); end if; for I in Time_Unit_Event_Type'Range loop A_Param := new Parameter (Boolean_Parameter); A_Param.parameter_name := To_Unbounded_String (to_lower (I'Img)); if Generate_Events (I) then A_Param.boolean_value := True; else A_Param.boolean_value := False; end if; add (A_Request.param, A_Param); end loop; add (Request_List, A_Request); Sequential_Framework_Request (Sys, Request_List, Response_List); Write_Title_And_Text (Response_List); Initialize (A_Request); Initialize (A_Request.param); initialize (Response_List); initialize (Request_List); A_Request.target := empty_string; A_Request.statement := Scheduling_Simulation_Basics; add (Request_List, A_Request); Sequential_Framework_Request (Sys, Request_List, Response_List); Write_Title_And_Text (Response_List); cb.Connect (Gtk_Drawing_Area(my_area), "expose_event", cb.To_Marshaller(Expose'Access)); Draw_Time_Line(Stop_Draw, Start_Draw, Framework.Sched); end Call_Uncustomized_Simulation; procedure Call_Customized_Simulation is A_Processor : Generic_Processor_Ptr; My_Processor_Iterator : Processors_Iterator; Response_List : Framework_Response_Table; Request_List : Framework_Request_Table; A_Request : Framework_Request; A_Param : Parameter_Ptr; begin Initialize (A_Request); Initialize (A_Request.param); A_Request.statement := Scheduling_Simulation_Time_Line; A_Param := new Parameter (Integer_Parameter); A_Param.parameter_name := To_Unbounded_String ("period"); A_Param.integer_value := Max_Period; add (A_Request.param, A_Param); A_Param := new Parameter (Boolean_Parameter); A_Param.parameter_name := To_Unbounded_String ("schedule_with_offsets"); A_Param.boolean_value := Schedule_With_Offsets; add (A_Request.param, A_Param); A_Param := new Parameter (Boolean_Parameter); A_Param.parameter_name := To_Unbounded_String ("minimize_preemption"); A_Param.boolean_value := minimize_preemption; add (A_Request.param, A_Param); A_Param := new Parameter (Boolean_Parameter); A_Param.parameter_name := To_Unbounded_String ("schedule_with_jitters"); A_Param.boolean_value := schedule_with_jitters; add (A_Request.param, A_Param); A_Param := new Parameter (Boolean_Parameter); A_Param.parameter_name := To_Unbounded_String ("schedule_with_precedencies"); A_Param.boolean_value := Schedule_With_Precedencies; add (A_Request.param, A_Param); A_Param := new Parameter (Boolean_Parameter); A_Param.parameter_name := To_Unbounded_String ("schedule_with_resources"); A_Param.boolean_value := Schedule_With_Resources; add (A_Request.param, A_Param); A_Param := new Parameter (Boolean_Parameter); A_Param.parameter_name := To_Unbounded_String ("schedule_with_crpd"); A_Param.boolean_value := Schedule_With_crpd; add (A_Request.param, A_Param); A_Param := new Parameter (Boolean_Parameter); A_Param.parameter_name := To_Unbounded_String ("predictable"); A_Param.boolean_value := Is_Global_Predictable_Seed; add (A_Request.param, A_Param); if Has_Global_Seed then A_Param := new Parameter (Integer_Parameter); A_Param.parameter_name := To_Unbounded_String ("seed_value"); A_Param.integer_value := Global_Seed_Value; add (A_Request.param, A_Param); end if; for I in Time_Unit_Event_Type'Range loop A_Param := new Parameter (Boolean_Parameter); A_Param.parameter_name := To_Unbounded_String (to_lower (I'Img)); if Generate_Events (I) then A_Param.boolean_value := True; else A_Param.boolean_value := False; end if; add (A_Request.param, A_Param); end loop; add (Request_List, A_Request); Sequential_Framework_Request (Sys, Request_List, Response_List); -- Put to the screen the resulting event table -- if Schedule_And_Display_Event_Table then Display_Scheduling (Framework.Sched); end if; Write_Title_And_Text(Response_List); cb.Connect (Gtk_Drawing_Area(my_area), "expose_event", cb.To_Marshaller(Expose'Access)); Draw_Time_Line(Stop_Draw, Start_Draw, Framework.Sched); -- export event table in the targeted XML file -- if Schedule_And_Export_Event_Table then Write_To_Xml_File (Framework.Sched, Sys, Xml_Event_Table_File_Name); end if; if Schedule_All_Processeurs = False then Call_Processor_Analysis (Last_Selected_Processor); else reset_iterator (Sys.Processors, My_Processor_Iterator); loop current_element (Sys.Processors, A_Processor, My_Processor_Iterator); Call_Processor_Analysis (A_Processor.name); exit when is_last_element (Sys.Processors, My_Processor_Iterator); next_element (Sys.Processors, My_Processor_Iterator); end loop; end if; -- Now run, event analyzers, -- if Run_Event_Analyzer_From_Simulation then initialize (Response_List); initialize (Request_List); Initialize (A_Request); A_Request.statement := Scheduling_Simulation_Run_Event_Handler; add (Request_List, A_Request); Sequential_Framework_Request (Sys, Request_List, Response_List); Write_Title_And_Text(Response_List); end if; end Call_Customized_Simulation; procedure Close_Widget(Object : access Gtkada_Builder_Record'Class) is my_widget : GObject; begin my_widget:=Get_Object(Object, "window1"); Destroy_cb(Gtk_Widget(my_widget)); gtk.main.main_quit; end Close_Widget; end graphical_editor.scheduling_simulation_draw_callbacks;