Hybrid Inference Based Scheduling Mechanism for Efﬁcient Real Time Task and Resource Management in Smart Cars for Safe Driving

: In recent years, the focus of the smart transportation industry has been shifting towards the research and development of smart cars with autonomous control. Smart cars are considered to be a smart investment, as they promote safe driving while focusing on an alternate transportation fuel resource, making them eco-friendly too. Safe driving is one of the crucial concerns in autonomous smart cars. The major issue for the better provision of safe driving is real time tasks management and an efﬁcient inference system for autonomous control. Real time task management is of huge signiﬁcance in smart cars control systems. An optimal control system consists of a knowledge base and a control unit; where the knowledge base contains the data and thresholds for rules and the control unit contains the functionality for smart vehicle autonomous control. In this work, we propose a hybrid of an inference engine and a real time task scheduler for an efﬁcient task management and resource consumption. Our proposed hybrid inference engine and task scheduler mechanism provides an efﬁcient way of controlling smart cars in different scenarios such as heavy rainfall, obstacle detection, driver’s focus diversion etc., while ensuring the practices of safe driving. For the performance analysis of our proposed hybrid inference based scheduling mechanism, we have simulated a non-hybrid version with the same system constraints and a basic implementation of inference engine. For performance evaluation, CPU time utilization, tasks’ missing rate, average response time are used as performance metrics. Increasing tasks’ load and priority inversion scenario.


Introduction
With the advancements towards autonomous driving vehicles, the focus of the smart transportation industry is being shifted towards the research and development of smart cars with autonomous control. Smart cars are considered to be a smart investment as they promote safe driving while focusing on an alternate transportation fuel resource, making them eco-friendly too. Driving a vehicle requires the utmost focus of the driver, as it is an extremely intricate task. Safe driving is tremendously important and must not be taken for granted as it could be a matter of life and death. Due to increasing number of vehicles on roads, traffic sometimes becomes extremely congested; requiring a complete focus and full awareness of the driver of their surroundings without being distracted by anything like mobile calls or radio, etc. According to a survey, around 3 million people suffer injuries and around 40 thousand people lose their lives due to car accidents in the United States every year [1]. Therefore, ensuring the safety of everyone is the most essential element while driving a vehicle. The major issue for better provision of safe driving is real time tasks management and an efficient inference system for autonomous control. Real time task management is of huge significance in smart cars control systems. As driving is a multitasking job, a driver must simultaneously control the speed, avoid hazards, set up directions and do strategic planning; an extremely experienced human being can also get distracted by environmental conditions or by any other elements. Hence, the need for some kind of automation in the transportation industry emerged, which can ensure the safety of vehicles and share responsibility with the drivers. Car companies responded to this need by vigorously supporting car safety features.
With the evolution of time and the development of smart technologies, automobiles or electrical vehicles being a predominant mean of transportation witnessed a boost in the emergence of advanced and innovative car models. The necessity of safe driving has resulted in the potential need for substitute technologies in automobiles such as smart cars. Internet of things (IoT) and the power of computer vision are the primary actors that enabled the existence of smart cars. These smart cars are autonomous vehicles; an autonomous vehicle takes over the driver's responsibilities by sensing the environment, and navigating on its own.
Design and implementation of the precise control systems in the smart cars is very crucial. The advanced control system collects data from different sensors and actuators; and interprets the information in order to accurately identify suitable navigation paths, hazards, and appropriate signage.
The control system of a smart car usually manages the decisions based on the inputs from different sensors e.g., GPS, rear camera, and radar sensors etc., and enables the actuators like distance control module, steering control, wipers control etc., to work accordingly ( Figure 1).
Electronics 2019, 8, x FOR PEER REVIEW 2 of 23 efficient inference system for autonomous control. Real time task management is of huge significance in smart cars control systems. As driving is a multitasking job, a driver must simultaneously control the speed, avoid hazards, set up directions and do strategic planning; an extremely experienced human being can also get distracted by environmental conditions or by any other elements. Hence, the need for some kind of automation in the transportation industry emerged, which can ensure the safety of vehicles and share responsibility with the drivers. Car companies responded to this need by vigorously supporting car safety features.
With the evolution of time and the development of smart technologies, automobiles or electrical vehicles being a predominant mean of transportation witnessed a boost in the emergence of advanced and innovative car models. The necessity of safe driving has resulted in the potential need for substitute technologies in automobiles such as smart cars. Internet of things (IoT) and the power of computer vision are the primary actors that enabled the existence of smart cars. These smart cars are autonomous vehicles; an autonomous vehicle takes over the driver's responsibilities by sensing the environment, and navigating on its own.
Design and implementation of the precise control systems in the smart cars is very crucial. The advanced control system collects data from different sensors and actuators; and interprets the information in order to accurately identify suitable navigation paths, hazards, and appropriate signage. The control system of a smart car usually manages the decisions based on the inputs from different sensors e.g., GPS, rear camera, and radar sensors etc., and enables the actuators like distance control module, steering control, wipers control etc., to work accordingly ( Figure 1). The overall flow of the system for a smart car is shown in Figure 1; the basic components are sensors, actuators and a control unit. The control unit works according to the environmental conditions, the sensors collect data from the environment e.g., temperature, location etc. and this information are passed on to the control unit to make control decisions and the controller implements the control commands to actuate different functionalities e.g., controlling speed, steering wheel etc. The driver gets alerts through a user interface. This implies that an interface bridges between the real world and the system, and thus an inference system must be proficient enough to plan and produce control commands. An inference engine is a component of the inference system that applies logical rules to the knowledge base to deduce new information. However, only a tiny percentage of cars on The overall flow of the system for a smart car is shown in Figure 1; the basic components are sensors, actuators and a control unit. The control unit works according to the environmental conditions, the sensors collect data from the environment e.g., temperature, location etc. and this information are passed on to the control unit to make control decisions and the controller implements the control commands to actuate different functionalities e.g., controlling speed, steering wheel etc. The driver gets alerts through a user interface. This implies that an interface bridges between the real world and the system, and thus an inference system must be proficient enough to plan and produce control commands. An inference engine is a component of the inference system that applies logical rules to the knowledge base to deduce new information. However, only a tiny percentage of cars on the road today have these driver alert systems and it will take a decade for this new technology to be commonplace in most cars across the globe.
Efficient control systems demand a precise interaction between lower level nodes and a reliable and robust data sharing between the sensing and control units for decision making with fast control loop update rates. Since every action taken by an autonomous vehicle system results in a new scenario, the action of each control function must be precisely synchronized. Previously, the inference engine for smart control and the scheduler has been separated in design, resulting in the use of more resources. In this work, we propose a hybrid of inference engine and task scheduler for efficient task management and resource consumption. Our proposed combined mechanism provides an efficient way of controlling smart cars in different scenarios and making them self-sufficient. Our proposed hybrid system provides complex task management in embedded IoT systems; giving flexible parameter setting options to consider all the system constraints for embedded IoT systems of different nature, and maximizing the performance.
The rest of the paper is divided as in the following way: Section 2 presents the related works, while Section 3 presents the proposed inference based scheduling mechanism. In Section 4, we provide the simulation of the proposed system. Simulation visualization is presented in Section 5, performance analysis is presented in Section 6 while Section 7 concludes the paper with discussions.

Related Work
Smart cars have been a hot topic in the past decade; we can observe that many researchers either from academia or from industry have been focusing their research efforts on smart cars. Inference engines, a primary and core measure of smart cars systems, are also being part of researcher efforts. In reference [2], an inference engine is being proposed that works for rule based expert systems. This inference engine is proved to be producing ideal, accurate and general rules according to time. The reasons for its accurate results are: the engine is being invoked when there is a change in any feature, conditions or rules are tested when values are assigned to features, every time a condition is altered, and the corresponding rule is examined, and actions will be performed once its rule is invoked. The predominant reason for producing optimal results is it does only the tasks which it is asked to perform, it does not do stuff which is not required. This means until and unless a features value is changed, and the rules are observed only if the corresponding conditions meet the criteria. Smart cars follow a complex mechanism, there might occur many complications and challenges if there happens to be malfunction or any failure; implying that inference engines must be capable of dealing with such failures. Some researchers have also focused on this area for proposing different tools or applications that can help avoid such circumstances.
In another study [3], guiding a vehicle on the limited access highways, is explored and the applicability of expert or inference systems is studied. The vehicle considered here is a smart car that takes input form sensors that are able to detect the surrounding traffic situations, signs, and road conditions etc. It has a control system and actuators. The proposed system is rule based and implements backward chaining inference engine for rules inference, and these inferred rules are then processed by a knowledge based compiler that performs reasoning. A simulator is also implemented to simulate a vehicle's behavior on limited access highways.
Researchers in reference [4] proposed Automated Car Failure Diagnosis Assistance (ACFDA); an agent-based inference engine for cars failure diagnosis expert system. The agent here tries to maximize the productivity and competence of the complete routine of the ACFDA system by completing a number of inferencing tasks and by tweaking the inferencing logical flow. This system or toolkit focuses on finding the reason for the failure. This helps the driver to know the exact source of the failure and act accordingly.
A smart car is a comprehensive integration of many different sensors, control modules, actuators, and so on. Many systems to support the purpose of smart cars were proposed e.g., a driver assistant system from BMW that assists in lane change warnings and parking [5], an intelligent driver's system proposed by Mercedes-Benz to monitor the car's surroundings using stereo cameras and radar sensors [6], a driver's assistant system based on traffic situation and conditions is proposed in reference [7], and a system focusing on progressive safety expertise with installations of a pre-collision system, dynamic driving, automated brake assistance and parking assistance is proposed in reference [8].
A general view of smart cars is presented in reference [9], focusing on context awareness; as a model focusing on the complex environment of driving is proposed that can learn the context in a hierarchal manner. In order to ensure safe driving, many studies have been done on the driver's distraction. The term driver's distraction can be defined as diversion of the driver's attention towards non-driving activities [10]. The distractions can be classified into four categories: visual distraction, auditory distraction, biochemical distraction and cognitive distraction [11]. The literature work from references [12][13][14][15][16][17][18][19][20][21] present driver's distraction detection systems based on different measures such as driving behavior, driver's physiological or the hybrid of both approaches.
The work in reference [22] surveys a cyber-physical vehicle system (CPVS) for cyber and physical schemes for resource consumption, time varying patterns, scheduling, vehicle control and task and motion planning. In reference [23], the safety level of roundabouts is evaluated for autonomous vehicles by simulating the roundabouts win combination to the conventional vehicles. The simulation highlights the differences in traffic parameters as queue length, average speed and delay in stopping. Safety is analyzed based on the potential conflicts at the roundabouts. A platform for safe autonomous driving is proposed in reference [24], with flexible architecture capable of integrating a wide variety of actuators and sensors for testing purposes. The work provides a complete navigation system for test scenario and two flexible routing algorithms are also proposed. The research work in reference [25] aims to solve the speed planning problems for autonomous vehicles. After summarizing the existing constraints in the speed planning, the work proposes a mathematical model for a general speed planning of autonomous vehicles based on the summarized constraints.

Inference based Scheduling Mechanism
In this section, we present our proposed inference based scheduling mechanism for the autonomous control of smart cars. Figure 2 below shows the conceptual model of the inference based scheduling mechanism in an optimal scheduling inference system for smart control of EVs. The main components of the model are a smart car sensing data unit, task modeling unit, scheduling unit, inference system unit, control system unit, and optimal output.
The smart car sensing data unit collects the input data from the smart car sensing environment. This data can be various kinds, e.g., environmental data, road state data, traffic state data, driver health state data, smart car physical self-state data etc. Task modeling unit models the smart car input data into periodic, event and complex nature tasks along with scheduling required parameters such as arrival time, execution time, deadline, priority and periodic/event tags. Scheduling unit implements a scheduling policy as per which the arrived tasks are to be executed at the CPU. The inference system unit implements the inference engine, where all the rules are to be followed according to different scenarios and threshold values are defined. The control system unit implements the control functions for the smart vehicle; which are triggered after firing the rules at inference engine. Optimal output generates the list of activated control output tasks and notifications/alert output tasks.
Our proposed hybrid inference based scheduling mechanism aims to meet all possible scenarios in a smart car environment with safety measures taken into account too. The proposed system satisfies the basic requirements of ISO26262, which is an international standard for functional safety of road vehicles [26], as explained in sub-sections below. In Section 3.1, the task model is given for the smart cars' task classification based on severity of the task or event. In Section 3.2, we give the scheduling policies, where we propose a custom made scheduler to best meet the scheduling of different priority tasks of different scenarios, ensuring that no chance is taken in critical scenarios in order to implement safe driving. In Section 3.3, we propose our inference engine's design, which defines the driving rules for controlling smart cars, along with exceptions to deal with unexpected events in best possible way. In Section 3.4, we present our hybrid agent which bridges the scheduling module with inference engine module.
The simulation highlights the differences in traffic parameters as queue length, average speed and delay in stopping. Safety is analyzed based on the potential conflicts at the roundabouts. A platform for safe autonomous driving is proposed in reference [24], with flexible architecture capable of integrating a wide variety of actuators and sensors for testing purposes. The work provides a complete navigation system for test scenario and two flexible routing algorithms are also proposed. The research work in reference [25] aims to solve the speed planning problems for autonomous vehicles. After summarizing the existing constraints in the speed planning, the work proposes a mathematical model for a general speed planning of autonomous vehicles based on the summarized constraints.

Inference based Scheduling Mechanism
In this section, we present our proposed inference based scheduling mechanism for the autonomous control of smart cars. Figure 2 below shows the conceptual model of the inference based scheduling mechanism in an optimal scheduling inference system for smart control of EVs. The main components of the model are a smart car sensing data unit, task modeling unit, scheduling unit, inference system unit, control system unit, and optimal output. The smart car sensing data unit collects the input data from the smart car sensing environment. This data can be various kinds, e.g., environmental data, road state data, traffic state data, driver

Task Model
There are two main types of tasks as periodic tasks and event-driven tasks. Each task must have a start time, execution time, deadline, priority/urgency value and period (if periodic task).
A periodic task and its nth periodic execution are denoted by PTi (AT, ET, D, P, PB) and PTin, respectively. An event driven task and its nth execution are denoted by ETi (e, AT, ET, D, U) and ETin, respectively. Table 1 below presents the task set parameters for periodic and event driven tasks. Table 1. Task set parameters for periodic and event driven tasks.

Parameters
Detail i Identifier of a task.
AT Arrival time of a task.
ET Execution time of a task.

D
Deadline of a task.
P Period of a periodic task.

PB
Priority bit for a periodic task. -PB = 1 indicates task has priority over other periodic task with PB = 0 -PB = 0 indicates task is a normal periodic task e The event that triggers an event driven task.

U
Urgency factor of an event driven task -U = 1 indicates task is urgent and should be executed ASAP -U = 0 indicates non-urgent event driven tasks

Scheduling Model
In this sub-section, we elaborate the scheduling model for smart car safety driving ( Figure 3). The scheduling model has sensor tasks, system tasks and actuator tasks as input. Sensor tasks are the tasks received from the sensor with sensing data readings, system tasks are the tasks in the inference engine to generate action commands in response, and actuator tasks are the response tasks which are generated at the inference engine in order to control the smart car. The tasks are either periodic tasks or event driven tasks. In our scheduling model design with efficient task execution for smart cars, we aim to add three scheduling algorithms: fair emergency first, fixed priority preemptive and earliest deadline first scheduling. or event driven tasks. In our scheduling model design with efficient task execution for smart cars, we aim to add three scheduling algorithms: fair emergency first, fixed priority preemptive and earliest deadline first scheduling.

Fair Emergency First Scheduling Policy
We have designed a customized scheduling algorithm for our rule based smart control inference system for smart cars. We have improvised the priority based scheduling algorithm with the basic design goal to run high priority tasks (emergency tasks) first, and additional design goals being to minimize the task starvation rate and fair allocation of CPU resources.
The tasks in fair emergency first scheduling policy are classified into four categories: high urgency event driven tasks, normal event driven tasks, high priority periodic tasks and normal periodic tasks. A default high priority is given to the event driven tasks over the periodic tasks. Urgent event driven tasks have priority over normal event driven tasks and priority periodic tasks have priority over normal periodic tasks.
The designed priority policy aims to run the high priority and urgent tasks first while making sure that no other tasks are starved unnecessarily, consuming the CPU time as efficiently as possible in the given input scenarios. The task starvation is addressed by consuming the free CPU slots for starving tasks, and by pushing the execution of normal event driven tasks and periodic tasks to make room for possibly missed tasks without compromising the performance of the system.

Priority Based Scheduling Policy
Priority based scheduling is a scheduling system commonly used in real-time systems. With a priority associated with all given task, the scheduler ensures that at any given time, the processor executes the highest priority task of all those tasks that are currently ready to execute. Since priority is given to higher-priority tasks, the lower-priority tasks could wait an indefinite amount of time before being implemented, leading to a higher starvation rate [27].

Earliest Deadline First Scheduling Policy
Earliest deadline first (EDF) or least time to go is a dynamic priority scheduling algorithm used in real-time operating systems to place processes in a priority queue. Whenever a scheduling event occurs (task finishes, new task released, etc.) the queue will be searched for the process closest to its deadline. This process is the next one to be scheduled for execution [28].

Inference Engine Model for Safe Driving
In this sub-section, we present an inference model for safe driving in a smart car. The inference engine model has the inference engine and the control unit.

Fair Emergency First Scheduling Policy
We have designed a customized scheduling algorithm for our rule based smart control inference system for smart cars. We have improvised the priority based scheduling algorithm with the basic design goal to run high priority tasks (emergency tasks) first, and additional design goals being to minimize the task starvation rate and fair allocation of CPU resources.
The tasks in fair emergency first scheduling policy are classified into four categories: high urgency event driven tasks, normal event driven tasks, high priority periodic tasks and normal periodic tasks. A default high priority is given to the event driven tasks over the periodic tasks. Urgent event driven tasks have priority over normal event driven tasks and priority periodic tasks have priority over normal periodic tasks.
The designed priority policy aims to run the high priority and urgent tasks first while making sure that no other tasks are starved unnecessarily, consuming the CPU time as efficiently as possible in the given input scenarios. The task starvation is addressed by consuming the free CPU slots for starving tasks, and by pushing the execution of normal event driven tasks and periodic tasks to make room for possibly missed tasks without compromising the performance of the system.

Priority Based Scheduling Policy
Priority based scheduling is a scheduling system commonly used in real-time systems. With a priority associated with all given task, the scheduler ensures that at any given time, the processor executes the highest priority task of all those tasks that are currently ready to execute. Since priority is given to higher-priority tasks, the lower-priority tasks could wait an indefinite amount of time before being implemented, leading to a higher starvation rate [27].

Earliest Deadline First Scheduling Policy
Earliest deadline first (EDF) or least time to go is a dynamic priority scheduling algorithm used in real-time operating systems to place processes in a priority queue. Whenever a scheduling event occurs (task finishes, new task released, etc.) the queue will be searched for the process closest to its deadline. This process is the next one to be scheduled for execution [28].

Inference Engine Model for Safe Driving
In this sub-section, we present an inference model for safe driving in a smart car. The inference engine model has the inference engine and the control unit.
The inference engine is the component where rules are defined for the autonomous control of smart cars. The inference engine is where all the safe driving rules are listed along with the thresholds and if-else conditionings. A rule is based on three elements: arriving task type, condition associated with the task and the contextual scenario of the task (Figure 4). In the task type we have four task types: urgent event, normal event, priority periodic and normal periodic type tasks. Each condition associated with a task to fire rule will have threshold and value ranges to be met. Each scenario will have some associated dependencies and described relations.
The inference engine is the component where rules are defined for the autonomous control of smart cars. The inference engine is where all the safe driving rules are listed along with the thresholds and if-else conditionings. A rule is based on three elements: arriving task type, condition associated with the task and the contextual scenario of the task [ Figure 4]. In the task type we have four task types: urgent event, normal event, priority periodic and normal periodic type tasks. Each condition associated with a task to fire rule will have threshold and value ranges to be met. Each scenario will have some associated dependencies and described relations. In case of an inference engine, contexts and scenarios are considered to follow rules and generate further tasks. The combination of different sensor readings makes a context for smart vehicle scenarios. In the case of an event, different contexts data can be combined in order to make more sense of the situation and scenario to make better control decisions for the smart cars.
A contextual scenario is based on contextual data and events are generated from the scenario context and the data available. For example from the context scenario such as the driver being detected will have input contextual data dependency on factors such as camera and the pressure sensor. In response, it will have an event control task "perform seat adjustment" generated to adjust the car's performance according to the driver's requirements. Similarly other context scenarios can be pedestrian detected, heavy rainfall, strong wind, speed jump detected etc. with each depending on different contextual data collection and generating different tasks in response of firing rules. The inference engine model also considers a set of exceptions for the decision making and rule firing process depending on the scenarios for better provision of safe driving for smart cars. Exceptions are listed and mapped when such scenarios occur where a special step needs to be taken ( Figure 5). In case of an inference engine, contexts and scenarios are considered to follow rules and generate further tasks. The combination of different sensor readings makes a context for smart vehicle scenarios. In the case of an event, different contexts data can be combined in order to make more sense of the situation and scenario to make better control decisions for the smart cars.
A contextual scenario is based on contextual data and events are generated from the scenario context and the data available. For example from the context scenario such as the driver being detected will have input contextual data dependency on factors such as camera and the pressure sensor. In response, it will have an event control task "perform seat adjustment" generated to adjust the car's performance according to the driver's requirements. Similarly other context scenarios can be pedestrian detected, heavy rainfall, strong wind, speed jump detected etc. with each depending on different contextual data collection and generating different tasks in response of firing rules. The inference engine model also considers a set of exceptions for the decision making and rule firing process depending on the scenarios for better provision of safe driving for smart cars. Exceptions are listed and mapped when such scenarios occur where a special step needs to be taken ( Figure 5).
In order to make safe driving inference engine system for smart cars, we have to design scenarios against each input sensing data values. In our case, we have six input environment sensors, one human data input sensor, and four smart car data input sensors. In environment sensors we have rainfall sensor, noise sensor, wind sensor, blurriness sensor and temperature sensor. In human data sensor, we have cameras. In smart car sensors, we have tire check, speed check, brake check and distance from nearby cars as input sensing data. Table 2 below explains the environment sensing data scenario  classifications, Table 3 explains the human sensing data scenario classifications and Table 4 explains the sensing data scenario. In order to make safe driving inference engine system for smart cars, we have to design scenarios against each input sensing data values. In our case, we have six input environment sensors, one human data input sensor, and four smart car data input sensors. In environment sensors we have rainfall sensor, noise sensor, wind sensor, blurriness sensor and temperature sensor. In human data sensor, we have cameras. In smart car sensors, we have tire check, speed check, brake check and distance from nearby cars as input sensing data. Table 2 below explains the environment sensing data scenario classifications, Table 3 explains the human sensing data scenario classifications and Table 4 explains the sensing data scenario.    In order to ensure safe driving conditions and environments, we define rules for each sensing value. The rules are built by first classifying the sensor value into some range, setting thresholds and determining an action opposite to each class range being true or false. As described in Tables 2-4 above, each sensing data has its own scenario classes corresponding to the sensor value readings. After classifying the incoming data based on threshold values, the next step for an inference engine is to determine the actions against the thresholds and fire rules accordingly ( Figure 6).
The control unit has all the control tasks' logic for the smart vehicle's autonomous control. The actions to be performed in safe driving case fall into two types. First are the control functions to keep the car controlled in every scenario and maintain the safe driving environment. Second is to generate appropriate notifications and warnings for the user and system. Figure 7 below elaborates the control functions involved in the safe driving of a smart car. The smart car controller functionality includes window control, radio control, wipers control, lights control, distance control, brakes control, speed control, steering control, fan control and temperature control.

High Alert
In order to ensure safe driving conditions and environments, we define rules for each sensing value. The rules are built by first classifying the sensor value into some range, setting thresholds and determining an action opposite to each class range being true or false. As described in Tables 2, 3 and 4 above, each sensing data has its own scenario classes corresponding to the sensor value readings. After classifying the incoming data based on threshold values, the next step for an inference engine is to determine the actions against the thresholds and fire rules accordingly [ Figure 6]. Figure 6. Workflow of firing a rule in inference engine. Figure 6. Workflow of firing a rule in inference engine. The control unit has all the control tasks' logic for the smart vehicle's autonomous control. The actions to be performed in safe driving case fall into two types. First are the control functions to keep the car controlled in every scenario and maintain the safe driving environment. Second is to generate appropriate notifications and warnings for the user and system. Figure 7 below elaborates the control functions involved in the safe driving of a smart car. The smart car controller functionality includes window control, radio control, wipers control, lights control, distance control, brakes control, speed control, steering control, fan control and temperature control.

Hybrid Agent
The hybrid agent provides a flexible and robust interaction platform between the scheduler and the inference engine in order to have a more reliable system which executes the tasks of the overall system more efficiently with minimum resources being used. Figure 8 shows the detailed system modules interaction with inclusion of the hybrid agent. The hybrid agent sends and receives the messages containing tasks data between scheduling module, inference engine module and the control module. It performs the configurations for the arriving tasks, depending on their types, scenario dependencies and priority tags. It parses the message in order to apply specific configurations and resource management actions. The hybrid agent maintains online

Hybrid Agent
The hybrid agent provides a flexible and robust interaction platform between the scheduler and the inference engine in order to have a more reliable system which executes the tasks of the overall system more efficiently with minimum resources being used. Figure 8 shows the detailed system modules interaction with inclusion of the hybrid agent. The hybrid agent sends and receives the messages containing tasks data between scheduling module, inference engine module and the control module. It performs the configurations for the arriving tasks, depending on their types, scenario dependencies and priority tags. It parses the message in order to apply specific configurations and resource management actions. The hybrid agent maintains online information of the complete tasks flow among all system modules to manage the resources and keep the resources available for any high priority tasks. The sensing input data, after modeling into task format and task type, is passed onto the scheduler. At scheduler, upon receiving the list of tasks, the scheduling policy is applied to schedule the execution order of the tasks. For extracting the execution rules attached with each/any task, the tasks are forwarded to the inference engine via hybrid agent. The task ID mappings to match the rules are done. After mappings, the rule is extracted from the inference engine and sent to the control unit, where the control task opposite to the fired rule is generated. The control task is modeled along with its start time, execution time, deadline and other parameters and sent back to the scheduler via hybrid agent. The scheduler then executes the control task along with other running tasks based on its selected scheduling policy.
The hybrid agent has the vital role, as it bridges between the sub-modules in the system and also copes with the resource management based on the tasks load.

Simulation of Inference based Scheduling Mechanism for Safe Driving in Smart Cars
In this section we present our data set of smart cars and the simulation setup.

Task Data
We have used smart cars data collected after intervals of 0.1 s, 0.5 s, 1 s, 5 s and 10 s. The collected data is divided into three input task categories as environmental data, vehicular data and human data ( Figure 9). The sensing input data, after modeling into task format and task type, is passed onto the scheduler. At scheduler, upon receiving the list of tasks, the scheduling policy is applied to schedule the execution order of the tasks. For extracting the execution rules attached with each/any task, the tasks are forwarded to the inference engine via hybrid agent. The task ID mappings to match the rules are done. After mappings, the rule is extracted from the inference engine and sent to the control unit, where the control task opposite to the fired rule is generated. The control task is modeled along with its start time, execution time, deadline and other parameters and sent back to the scheduler via hybrid agent. The scheduler then executes the control task along with other running tasks based on its selected scheduling policy.
The hybrid agent has the vital role, as it bridges between the sub-modules in the system and also copes with the resource management based on the tasks load.

Simulation of Inference based Scheduling Mechanism for Safe Driving in Smart Cars
In this section we present our data set of smart cars and the simulation setup.

Task Data
We have used smart cars data collected after intervals of 0.1 s, 0.5 s, 1 s, 5 s and 10 s. The collected data is divided into three input task categories as environmental data, vehicular data and human data ( Figure 9). Electronics 2019, 8, x FOR PEER REVIEW 12 of 23 Figure 9. Tasks data.
The environment sensing data tasks have light, rain, temperature, location, blurriness, wind and noise sensing data. The human sensing data task has camera angle for the driver's head angle. The vehicular sensing data has car tire, car brake, and car speed and car distance sensing data. Data preprocessing is performed in order to remove any noise from the collected data and make the data understandable for the system.

Implementation Environment
We have used Python for implementing the core programming logic of the task scheduling algorithms. Python is a very popular general purpose programming language that is widely used for developing desktop based and web based applications. In order to develop our inference engine, we have used Drools libraries. Drools is a Business Rules Management System (BRMS) solution. It provides a core Business Rules Engine (BRE). The development environment for the system is shown in Table 5 below and in the simulation and testing phase; we have tested our built task scheduler on an embedded IoT testbed (Table 6). Raspberry-pi is used in simulation and testing scenarios as it best suited our system requirements.  The environment sensing data tasks have light, rain, temperature, location, blurriness, wind and noise sensing data. The human sensing data task has camera angle for the driver's head angle. The vehicular sensing data has car tire, car brake, and car speed and car distance sensing data. Data pre-processing is performed in order to remove any noise from the collected data and make the data understandable for the system.

Implementation Environment
We have used Python for implementing the core programming logic of the task scheduling algorithms. Python is a very popular general purpose programming language that is widely used for developing desktop based and web based applications. In order to develop our inference engine, we have used Drools libraries. Drools is a Business Rules Management System (BRMS) solution. It provides a core Business Rules Engine (BRE). The development environment for the system is shown in Table 5 below and in the simulation and testing phase; we have tested our built task scheduler on an embedded IoT testbed (Table 6). Raspberry-pi is used in simulation and testing scenarios as it best suited our system requirements.

Hybrid Scheduling and Inference Engine Model
In this sub-section we present the implementation of our hybrid approach of task scheduler and inference engine. Sensing input tasks as explained above in Section 4.1 are given input to the scheduler.
Initially a set of sensing input tasks arrive at the scheduling model, which has scheduling logic implemented at one end with different scheduling algorithms and hybrid agent interactions at the other end. The input tasks are periodic sensor readings, collected after a set interval of time. The sensing tasks are initially scheduled and forwarded to the hybrid agent accordingly; the hybrid agent then passes them onto the inference engine based on the priorities and levels of urgency. The process tasks are executed at the inference engine, resulting into generation of output tasks which are smart control tasks or the notifications/alerts for the smart car. Hybrid agent gets the output tasks and manages the execution depending on the existing resources and priority orders. Our inference engine is drools based, and a set of rules to be fired is defined in a drl file, in accordance with all input data scenarios and smart car's safety control functionality ( Figure 10).
In Table 7 below, we consider an example scenario for smart car input data as rainfall, noise and temperature. The table explains the total number of tasks to be executed along with each task's name, its required CPU consumption demand and the priority of the task at the scheduler.
The simulation system in this example scenario will have rainfall sensing data, noise sensing data and temperature sensing data as periodic sensing data input tasks. The system task involved will be rule firing task, for each time a rule goal is matched and a rule is followed. The actuator tasks involved in the given scenario are window control task, wiper control task, radio control task, temperature control task, speed control task and steering control task.
The Figure 11 above shows the simulation execution flow from the input sensor readings to the scheduler. At the scheduler, the sensing tasks are executed based on priorities and sent to the hybrid agent for further processing. The hybrid agent based on the incoming tasks, sets the configurations and forwards the parsed content to the inference engine. The inference engine classifies the incoming data sensing values, matches the rules and follows the rules when the goal is met. The followed rules contain the response control tasks to be executed for the safe driving of a smart car. The fired control tasks are lined at control unit and communicated back to scheduler via hybrid agent and executed at control unit when scheduled to execute. then passes them onto the inference engine based on the priorities and levels of urgency. The process tasks are executed at the inference engine, resulting into generation of output tasks which are smart control tasks or the notifications/alerts for the smart car. Hybrid agent gets the output tasks and manages the execution depending on the existing resources and priority orders. Our inference engine is drools based, and a set of rules to be fired is defined in a drl file, in accordance with all input data scenarios and smart car's safety control functionality ( Figure 10).   Urgent Event Driven The simulation system in this example scenario will have rainfall sensing data, noise sensing data and temperature sensing data as periodic sensing data input tasks. The system task involved will be rule firing task, for each time a rule goal is matched and a rule is followed. The actuator tasks involved in the given scenario are window control task, wiper control task, radio control task, temperature control task, speed control task and steering control task. Figure 11. Simulation execution of the task scheduling and inference module for the example scenario.
The Figure 11 above shows the simulation execution flow from the input sensor readings to the scheduler. At the scheduler, the sensing tasks are executed based on priorities and sent to the hybrid agent for further processing. The hybrid agent based on the incoming tasks, sets the configurations and forwards the parsed content to the inference engine. The inference engine classifies the incoming data sensing values, matches the rules and follows the rules when the goal is met. The followed rules Figure 11. Simulation execution of the task scheduling and inference module for the example scenario.

Simulation Visualization
We have developed a web-based task simulation visualization tool using flask, which is an MVC based framework. As part of visualization we implemented FEF, Priority based and EDF scheduling policies for all different scenarios and presented several interfaces in a very neat and clear way. Similarly to all other algorithms, we have certain tabs like General Summary, Tasks Timeline, Performance Visualization, Overall Metrics Visualization and CPU Timeline.
The Figure 12 below shows the CPU timeline of scheduled tasks. Various color codes represent various categories of the tasks. For instance, Task 1 with pink color is normal periodic task which is received at time 0. At this particular moment, no other high priority task has arrived yet, so it gets CPU eventually. For next couple of cycles the CPU is free, which is indicated by dark green color. Clock cycle 3 to 9 is assigned to event-driven task 1.1 and this goes on till the hyper period amount of time. After this the same pattern gets executed. contain the response control tasks to be executed for the safe driving of a smart car. The fired control tasks are lined at control unit and communicated back to scheduler via hybrid agent and executed at control unit when scheduled to execute.

Simulation Visualization
We have developed a web-based task simulation visualization tool using flask, which is an MVC based framework. As part of visualization we implemented FEF, Priority based and EDF scheduling policies for all different scenarios and presented several interfaces in a very neat and clear way. Similarly to all other algorithms, we have certain tabs like General Summary, Tasks Timeline, Performance Visualization, Overall Metrics Visualization and CPU Timeline.
The Figure 12 below shows the CPU timeline of scheduled tasks. Various color codes represent various categories of the tasks. For instance, Task 1 with pink color is normal periodic task which is received at time 0. At this particular moment, no other high priority task has arrived yet, so it gets CPU eventually. For next couple of cycles the CPU is free, which is indicated by dark green color. Clock cycle 3 to 9 is assigned to event-driven task 1.1 and this goes on till the hyper period amount of time. After this the same pattern gets executed.

Performance Analysis
In this section we present a performance analysis of our proposed rule based scheduling for smart cars autonomous control. In Section 6.1, we perform comparisons analysis of our proposed system with non-hybrid rule engine and basic rule engine. In Section 6.2, we perform the implemented scheduling schemes comparisons at the proposed system.

Performance Analysis
In this section we present a performance analysis of our proposed rule based scheduling for smart cars autonomous control. In Section 6.1, we perform comparisons analysis of our proposed system with non-hybrid rule engine and basic rule engine. In Section 6.2, we perform the implemented scheduling schemes comparisons at the proposed system.
For the purpose of performance evaluations, we have considered 9 scenarios compromising of different input data combinations. The Table 8 below shows the list of our considered input data combinations' scenarios. Each scenario is a combination of many sub-tasks based on the scenario dependencies.

Comparison Analysis between Hybrid, Non-Hybrid and Basic Rule Engine Approaches
In this sub-section, we present the performance analysis comparisons for the proposed hybrid system of inference engine based scheduling mechanism with a non-hybrid system and a basic rule engine. We have simulated the non-hybrid approach with the same environment constraints as our proposed hybrid approach. The non-hybrid system does not have the implementation features of the hybrid agent, which in a hybrid approach system are better resource management and a robust execution of tasks execution. We have also simulated a basic rule engine with FIFO scheduling and priority rule firing for detailed comparison purposes. In the comparisons and graphs, for the sake of ease, we will refer to our proposed inference engine based scheduling mechanism as a hybrid system.

CPU Time Utilization
CPU time utilization (or process time) is the amount of time for which a central processing unit (CPU) was used for processing the tasks on its core/cores. In this context, we refer to CPU time Utilization as usage of CPU time slots in the most efficient manner; high CPU utilization translates into more tasks being handled and less CPU slots being wasted. Figure 13 above shows the average CPU time utilization for the smart car's tasks set at y-axis with varying sampling intervals on x-axis. The proposed hybrid system performs better than the non-hybrid system and basic inference engine as the hybrid system target to utilize the free CPU slots by priority shifting in order to increase throughput. The non-hybrid system though lacks the efficient resource allocation and thus results in more free slots, which would eventually result in a high tasks' missing rate. The basic inference engine has the minimum CPU slots consumption as it follows the FIFO scheme with single queue and basic priority scheme in comparison to the non-hybrid system which has a fully featured multi-priority scheduling end implemented.
with varying sampling intervals on x-axis. The proposed hybrid system performs better than the nonhybrid system and basic inference engine as the hybrid system target to utilize the free CPU slots by priority shifting in order to increase throughput. The non-hybrid system though lacks the efficient resource allocation and thus results in more free slots, which would eventually result in a high tasks' missing rate. The basic inference engine has the minimum CPU slots consumption as it follows the FIFO scheme with single queue and basic priority scheme in comparison to the non-hybrid system which has a fully featured multi-priority scheduling end implemented.

Missing Rate (Percentage)
Missing rate is the percentage of tasks which missed their deadline and are executed after their deadline. As in Section 6.1.1, we have observed that more free CPU slots are utilized by a hybrid system in comparison to a non-hybrid system and basic inference engine system. An efficient and optimized usage of free CPU slots would definitely result into a higher throughput and lower missing rate for the tasks. Hence the average missing rate is lowest for the hybrid system, followed by the non-hybrid system and basic inference engine having the maximum tasks' missing rate. The missing rate for the tasks increases with the decrease in the sampling interval, as the tasks load on the system increase in smaller sampling intervals. In the case of a hybrid approach, the tasks' missing rate is 0% for sampling interval of 10 and 5 but it increases to around 7%, 13% and 19% for the sampling intervals 1, 0.5 and 0.1 s respectively ( Figure 14). system in comparison to a non-hybrid system and basic inference engine system. An efficient and optimized usage of free CPU slots would definitely result into a higher throughput and lower missing rate for the tasks. Hence the average missing rate is lowest for the hybrid system, followed by the non-hybrid system and basic inference engine having the maximum tasks' missing rate. The missing rate for the tasks increases with the decrease in the sampling interval, as the tasks load on the system increase in smaller sampling intervals. In the case of a hybrid approach, the tasks' missing rate is 0% for sampling interval of 10 and 5 but it increases to around 7%, 13% and 19% for the sampling intervals 1, 0.5 and 0.1 s respectively ( Figure 14). An essential concern in the Figure 14 above is whether the inevitable missing tasks with the high task load are of a critical nature or a non-critical nature. In the scenarios where the total tasks load becomes higher than the total available capacity, the hybrid agent in the proposed system manages an efficient trade-off between the critical tasks and non-critical tasks. The Figure 15 below shows the missing tasks rate for varying load in a basic inference engine system while Figure 16 shows the missing tasks rate for varying load in hybrid system. By comparing Figures 15 and 16  An essential concern in the Figure 14 above is whether the inevitable missing tasks with the high task load are of a critical nature or a non-critical nature. In the scenarios where the total tasks load becomes higher than the total available capacity, the hybrid agent in the proposed system manages an efficient trade-off between the critical tasks and non-critical tasks. The Figure 15 below shows the missing tasks rate for varying load in a basic inference engine system while Figure 16 shows the missing tasks rate for varying load in hybrid system. By comparing Figures 15 and 16, we can conclude that the non-hybrid system might miss a higher number of critical tasks as compared to the hybrid system. The combination of hybrid agent and FEF scheduling mechanism modifications allows the hybrid system to reduce the tasks starvation rate. In this way, the only critical tasks missing at the hybrid system would be those which fall into the lower priority at the ongoing CPU time slots and running those would mean causing bigger damage to the system eventually.

Response Time
The response time is the time taken from the release of a task to its first execution. In this context we refer to the response time as the first sub-task execution return of a larger task scenario (Table 7).
In the Figure 17 below, average response time for varying sampling intervals is shown. The nonhybrid system has a slightly better response time than the basic inference engine system whereas the hybrid approach significantly improves the response time. The main difference between the hybrid and non-hybrid systems is the implementation layer for the hybrid agent with better resource

Response Time
The response time is the time taken from the release of a task to its first execution. In this context we refer to the response time as the first sub-task execution return of a larger task scenario (Table 7).
In the Figure 17 below, average response time for varying sampling intervals is shown. The nonhybrid system has a slightly better response time than the basic inference engine system whereas the hybrid approach significantly improves the response time. The main difference between the hybrid and non-hybrid systems is the implementation layer for the hybrid agent with better resource allocation, fast tasks processing, minimizing delay and avoiding unnecessary system tasks.

Avg. Tasks' Missing Rate for Varying Load in Hybrid Inference Engine
Critical Tasks Non-Critical Tasks Figure 16. Hybrid inference engine.

Response Time
The response time is the time taken from the release of a task to its first execution. In this context we refer to the response time as the first sub-task execution return of a larger task scenario (Table 7).
In the Figure 17 below, average response time for varying sampling intervals is shown. The non-hybrid system has a slightly better response time than the basic inference engine system whereas the hybrid approach significantly improves the response time. The main difference between the hybrid and non-hybrid systems is the implementation layer for the hybrid agent with better resource allocation, fast tasks processing, minimizing delay and avoiding unnecessary system tasks.

Comparisons between FEF, EDF and Priority based Scheduling Algorithms
In this sub-section we provide the comparisons between the implementation of hybrid system with three different scheduling policies: FEF (Fair Emergency First) scheduling algorithm, EDF (Earliest Deadline First) scheduling algorithm and Priority based scheduling algorithm.
In EDF the task scheduler directly executes the task with nearest deadline first while in the Priority based scheduling algorithm, the task scheduler executes the tasks based on their priority (i.e. highest priority first). The FEF scheduling algorithm takes into account the system and user priorities and also other factors such as current missing rate and delay rates along with the total tasks load on the system. Hence the hybrid system with FEF scheduler implementation shows more promising results in comparison to the priority based on EDF based implementation. Figure 18 above shows the response time comparison of the three scheduling algorithms and their implementation of the proposed hybrid system for the nine scenarios tasks set. The figure clearly indicates that hybrid FEF implementation outperforms the priority based and EDF based implementations.

Comparisons between FEF, EDF and Priority based Scheduling Algorithms
In this sub-section we provide the comparisons between the implementation of hybrid system with three different scheduling policies: FEF (Fair Emergency First) scheduling algorithm, EDF (Earliest Deadline First) scheduling algorithm and Priority based scheduling algorithm.
In EDF the task scheduler directly executes the task with nearest deadline first while in the Priority based scheduling algorithm, the task scheduler executes the tasks based on their priority (i.e. highest priority first). The FEF scheduling algorithm takes into account the system and user priorities and also other factors such as current missing rate and delay rates along with the total tasks load on the system. Hence the hybrid system with FEF scheduler implementation shows more promising results in comparison to the priority based on EDF based implementation. Figure 18 above shows the response time comparison of the three scheduling algorithms and their implementation of the proposed hybrid system for the nine scenarios tasks set. The figure clearly indicates that hybrid FEF implementation outperforms the priority based and EDF based implementations. Now, we consider other crucial scenarios in the real-time scheduling, e.g., over flow of tasks at the scheduler, low-priority tasks not being able to get executed due to high flow of high priority tasks and large number of unexpected interrupts. Our tailored FEF algorithm makes best use of its resources and capacity to deal with such scenarios. The urgency and PB factors, introduced in task modeling (Section 3.1), help the scheduler to take the best scheduling decision. The PB factor is ideally introduced to invert the priority to the low priority tasks when their executed can no longer be delayed. Figure 19 below elaborates a scenario where the real-time system is overflown with its tasks load, and a low priority task has to wait forever for its turn. In such cases the PB for a low priority task is set to 1 if it's obligatory to run the low priority task after a definite time period, otherwise it might cause a superior loss to the system. Now, we consider other crucial scenarios in the real-time scheduling, e.g., over flow of tasks at the scheduler, low-priority tasks not being able to get executed due to high flow of high priority tasks and large number of unexpected interrupts. Our tailored FEF algorithm makes best use of its resources and capacity to deal with such scenarios. The urgency and PB factors, introduced in task modeling (Section 3.1), help the scheduler to take the best scheduling decision. The PB factor is ideally introduced to invert the priority to the low priority tasks when their executed can no longer be delayed. Figure 19 below elaborates a scenario where the real-time system is overflown with its tasks load, and a low priority task has to wait forever for its turn. In such cases the PB for a low priority task is set to 1 if it's obligatory to run the low priority task after a definite time period, otherwise it might cause a superior loss to the system.

Discussions
In this work, we have studied the importance of safe driving in smart cars and the importance of a robust inference engine for smart cars' control. Owing to advances in transportation industry and IoT, smart cars have become intelligent enough to deliver numerous expedient functions for drivers. With convenience, there comes complexity as a side effect; smart cars are embedded with smart modules performing complex tasks. These complex functions have led to an increase in the complexity of controls. For the smart cars to be more accurate and situation aware, it requires a task scheduler for the controller. Previously, smart cars were using a separate task scheduler which prioritizes the tasks for the controller; and brings an additional level of complexity in the system. In order for the smart cars to be more efficient, safe and lightweight, complexity needs to be reduced. Thus in this paper, we introduced a hybrid module which combines the task scheduler with the

Discussions
In this work, we have studied the importance of safe driving in smart cars and the importance of a robust inference engine for smart cars' control. Owing to advances in transportation industry and IoT, smart cars have become intelligent enough to deliver numerous expedient functions for drivers. With convenience, there comes complexity as a side effect; smart cars are embedded with smart modules performing complex tasks. These complex functions have led to an increase in the complexity of controls. For the smart cars to be more accurate and situation aware, it requires a task scheduler for the controller. Previously, smart cars were using a separate task scheduler which prioritizes the tasks for the controller; and brings an additional level of complexity in the system. In order for the smart cars to be more efficient, safe and lightweight, complexity needs to be reduced. Thus in this paper, we introduced a hybrid module which combines the task scheduler with the inference engine via hybrid agent. The hybrid agent aims to facilitate the real-time task management and the resource management for provision of an efficient inference engine for smart cars. An improvised version of a priority based scheduler is introduced to be installed at task scheduler level named as an FEF scheduler. For the purpose of performance analysis, a non-hybrid version of the system with priority scheduling is simulated and a basic inference engine with priority rule firing and FIFO scheduler is also implemented. The comparisons are made between the three implementation based on performance metrics of CPU Usage, Tasks' Missing Rate and Response Time. At the scheduler level for the proposed hybrid system, three scheduling techniques as FEF, Priority based and EDF are implemented to draw the performance comparisons between them. All three scheduling techniques (FEF, Fixed priority and EDF) come under the definition of preemptive scheduling in OSEK/VDX task scheduling. In OSEK/VDX preemptive scheduling, the running task might be rescheduled at the occurrence of any pre-set event or condition [29]. In FEF, pre-set conditions are based on task urgencies and PB conditions. In EDF the pre-set condition is based on another task arriving with an earlier deadline than the currently running task and in fixed priority the pre-set condition would be if another task arrives with a higher priority than the currently running task.
It can be clearly observed from the results that our proposed hybrid approach outperformed the non-hybrid and basic inference engine systems. We observed a significant reduction of 25% to 75% in the number of task instances missed and the number of high priority tasks missed. As the combination of better resource management at hybrid agent and improvised FEF scheduler results in a significant reduction in the task starvation rate and maximum CPU time slots utilization; as low priority tasks are saved from unnecessary starvation and CPU unit times are used wisely. To the best of our knowledge, our proposed hybrid system is first of its kind. Hence, our proposed hybrid inference based scheduling mechanism is recommended for smart cars in safe driving environments; where constraints and requirements vary depending on the scenarios. This is because it is flexible, adaptive and allows setting system constraints based on independent priorities when the input is of a diverse nature.