--- /dev/null
+// -----------------------------------------------------------------------\r
+// Copyright (C) 2006 - 2007 by the FRESCOR consortium:\r
+//\r
+// Universidad de Cantabria, SPAIN\r
+// University of York, UK\r
+// Scuola Superiore Sant'Anna, ITALY\r
+// Kaiserslautern University, GERMANY\r
+// Univ. Politecnica Valencia, SPAIN\r
+// Czech Technical University in Prague, CZECH REPUBLIC\r
+// ENEA SWEDEN\r
+// Thales Communication S.A. FRANCE\r
+// Visual Tools S.A. SPAIN\r
+// Rapita Systems Ltd UK\r
+// Evidence ITALY\r
+//\r
+// See http://www.frescor.org\r
+//\r
+// The FRESCOR project (FP6/2005/IST/5-034026) is funded\r
+// in part by the European Union Sixth Framework Programme\r
+// The European Union is not liable of any use that may be\r
+// made of this code.\r
+//\r
+// All rights reserved.\r
+//\r
+// Redistribution and use in source and binary forms, with or \r
+// without modification, are permitted provided that the \r
+// following conditions are met:\r
+//\r
+// * Redistributions of source code must retain the above \r
+// copyright notice, this list of conditions and the \r
+// following disclaimer.\r
+// * Redistributions in binary form must reproduce the above \r
+// copyright notice, this list of conditions and the \r
+// following disclaimer in the documentation and/or other \r
+// materials provided with the distribution.\r
+// * Neither the name of FRESCOR nor the names of its \r
+// contributors may be used to endorse or promote products \r
+// derived from this software without specific prior \r
+// written permission.\r
+//\r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND \r
+// CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, \r
+// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF \r
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE \r
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR \r
+// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, \r
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES \r
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE \r
+// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR \r
+// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF \r
+// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT \r
+// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE \r
+// POSSIBILITY OF SUCH DAMAGE.\r
+// -----------------------------------------------------------------------\r
+\r
+/**\r
+ * @file fosa_ose_exe_time.c\r
+ * @brief: Using swap handlers to measure execution time for \r
+ * individual ose processes. Time is measured in system ticks + a \r
+ * number of micro seconds. The temporary slice start time is saved in\r
+ * the process specific user area and the elapsed execution time is \r
+ * saved in a shared memory linked list.\r
+ * \r
+ * $Author: xmlin $$Date: 19/06/07 \r
+ * \r
+ */\r
+\r
+#include "ose.h"\r
+#include "stdlib.h"\r
+#include "malloc.h"\r
+#include "ramlog.h" \r
+#include "heapapi.h" \r
+#include "ose_heap.h"\r
+\r
+#include "string.h"\r
+#include "fosa_ose_types.h"\r
+\r
+extern fosa_ose_process_info_t* fosa_ose_processes;\r
+OSTIME micros_per_tick;\r
+\r
+/*Create handler is called when a process is to be created\r
+ * -set inital values to user_area variables\r
+ */\r
+void fosa_ose_create_handler(user_area_t *user_area_ptr, PROCESS id){\r
+ \r
+ if(fosa_ose_processes == NULL){ \r
+ /*Start up process*/\r
+ user_area_ptr->fosa_process = FALSE;\r
+ return;\r
+ }\r
+ else{\r
+ /*Possible FOSA Process*/\r
+ user_area_ptr->fosa_process = TRUE;\r
+ \r
+ /*initialize user area*/\r
+ user_area_ptr->pid = id;\r
+ user_area_ptr->list_position_ptr = NULL;\r
+ user_area_ptr->tick_slice_start_time = 0;\r
+ user_area_ptr->micro_slice_start_time = 0;\r
+ \r
+ micros_per_tick = system_tick();\r
+ ramlog_printf("FOSA HANDLERS: Create %x\n", id); \r
+ return;\r
+ }\r
+}\r
+\r
+\r
+/*Swap in handler is called when a process execution is started\r
+ * -If first time in swap in find the node of interest\r
+ * -If the node is not found it is not a fosa process\r
+ * -If a node is found save a pointer to that node in the user_area\r
+ * -also save the process slice swap in time\r
+ */\r
+void fosa_ose_swap_in_handler(user_area_t *user_area_ptr){\r
+ \r
+ if(user_area_ptr->fosa_process == FALSE){\r
+ /*if(test_app_started == 1)\r
+ ramlog_printf("FOSA HANDLERS: PREEMPTION by %x\n", user_area_ptr->pid);*/\r
+ return;\r
+ }\r
+ \r
+ if(fosa_ose_processes == NULL){\r
+ user_area_ptr->fosa_process = FALSE;\r
+ /*if(test_app_started == 1)\r
+ ramlog_printf("FOSA HANDLERS: PREEMPTION by %x\n", user_area_ptr->pid);*/\r
+ return;\r
+ }\r
+ \r
+ OSTICK ticks;\r
+ OSTICK micros;\r
+ ticks = get_systime(µs);\r
+ user_area_ptr->tick_slice_start_time = ticks;\r
+ user_area_ptr->micro_slice_start_time = micros;\r
+ \r
+ if(user_area_ptr->list_position_ptr != NULL){\r
+ /*Not first time in swap in*/\r
+ //ramlog_printf("FOSA HANDLERS: PREEMPTION - fosa process %x SWAPPED BACK IN\n", user_area_ptr->pid);\r
+ return;\r
+ }\r
+ \r
+ /*First time in swap in --- user_area_ptr->list_position_ptr == NULL*/\r
+ //ramlog_printf("FOSA HANDLERS: %x SWAPPED IN\n", user_area_ptr->pid);\r
+ fosa_ose_process_info_t *tmp_node_ptr = fosa_ose_processes;\r
+ \r
+ for(;;){\r
+ if(tmp_node_ptr->pid == user_area_ptr->pid){\r
+ \r
+ //ramlog_printf("FOSA HANDLERS: NODE found for: %x %x\n", \r
+ //tmp_node_ptr->pid, user_area_ptr->pid);\r
+ \r
+ user_area_ptr->list_position_ptr = tmp_node_ptr;\r
+ user_area_ptr->fosa_process = TRUE;\r
+ break;\r
+ }\r
+ \r
+ if(tmp_node_ptr->NextProcess != NULL){\r
+ \r
+ tmp_node_ptr = tmp_node_ptr->NextProcess;\r
+ }\r
+ else{\r
+ ramlog_printf("FOSA HANDLERS: NO node found with pid: %x => IGNORE process\n", \r
+ user_area_ptr->pid);\r
+ user_area_ptr->fosa_process = FALSE;\r
+ break;\r
+ }\r
+ }\r
+}\r
+\r
+\r
+\r
+/*Swap out handler is called when a process slice is to terminate\r
+ * - calculate slice execution time\r
+ * - add to previous execution time for the process\r
+ * - save new total execution time value in the linked list\r
+ */\r
+void fosa_ose_swap_out_handler(user_area_t *user_area_ptr){\r
+ \r
+ if(user_area_ptr->fosa_process == FALSE){\r
+ /*if(test_app_started == 1)\r
+ ramlog_printf("FOSA HANDLERS: DISPATCH process: %x\n", user_area_ptr->pid);*/\r
+ return;\r
+ }\r
+ //ramlog_printf("FOSA HANDLERS: DISPATCH fosa process: %x\n", user_area_ptr->list_position_ptr->pid);\r
+ \r
+ OSTICK ticks;\r
+ signed long micros;\r
+ ticks = get_systime(µs);\r
+ \r
+ ticks = ticks-(user_area_ptr->tick_slice_start_time);\r
+ micros = micros-(user_area_ptr->micro_slice_start_time);\r
+ (user_area_ptr->list_position_ptr)->nr_of_ticks += ticks;\r
+ (user_area_ptr->list_position_ptr)->nr_of_micros += micros; \r
+ \r
+ while((user_area_ptr->list_position_ptr)->nr_of_micros < 0){\r
+ (user_area_ptr->list_position_ptr)->nr_of_ticks--;\r
+ (user_area_ptr->list_position_ptr)->nr_of_micros = micros_per_tick + (user_area_ptr->list_position_ptr)->nr_of_micros; \r
+ }\r
+ while((user_area_ptr->list_position_ptr)->nr_of_micros >= micros_per_tick){\r
+ (user_area_ptr->list_position_ptr)->nr_of_ticks++;\r
+ (user_area_ptr->list_position_ptr)->nr_of_micros =(user_area_ptr->list_position_ptr)->nr_of_micros - micros_per_tick;\r
+ }\r
+ user_area_ptr->tick_slice_start_time = 0;\r
+ user_area_ptr->micro_slice_start_time = 0;\r
+ return;\r
+}\r
+\r
+\r
+/*Delete node function\r
+ * -Redirect list pointers past the node\r
+ * -Free memory space for node\r
+ */\r
+/*void delete_node(PROCESS pid){\r
+ \r
+ fosa_ose_list_node_t *tmp_node_ptr = NULL;\r
+ \r
+ if(fosa_ose_processes->NextProcess != NULL){\r
+ tmp_node_ptr = fosa_ose_processes->NextProcess;\r
+ }\r
+ else if(fosa_ose_processes->NextProcess == NULL){\r
+ ramlog_printf("FOSA HANDLERS: ERROR: list empty %x not found\n", pid);\r
+ return;\r
+ }\r
+ \r
+ for(;;){\r
+ \r
+ if(tmp_node_ptr->pid == pid){ \r
+ if(tmp_node_ptr->NextProcess == NULL)\r
+ (tmp_node_ptr->prev_ptr)->NextProcess = NULL;\r
+ else{\r
+ (tmp_node_ptr->prev_ptr)->NextProcess = \r
+ tmp_node_ptr->NextProcess;\r
+ \r
+ (tmp_node_ptr->NextProcess)->prev_ptr = \r
+ tmp_node_ptr->prev_ptr;\r
+ }\r
+ \r
+ heap_free_shared(tmp_node_ptr);*/\r
+ /*ramlog_printf("FOSA HANDLERS: Deleted node, redirected pointers and freed memory for %x \n", pid);*/\r
+ /*break;\r
+ }\r
+ \r
+ if(tmp_node_ptr->NextProcess != NULL)\r
+ tmp_node_ptr = tmp_node_ptr->NextProcess;\r
+ else{*/\r
+ /*ramlog_printf("FOSA HANDLERS: ERROR: node not found for %x \n", pid);*/\r
+ /*break;\r
+ }\r
+ }\r
+}*/\r
+\r
+\r
+\r
+\r