# Introduction

The timing analysis plugin uses **Cheddar** services to analyze temporal constraints on **AADL** models. 

Cheddar is a free real time scheduling tool. Cheddar is designed for checking task temporal constraints of a real time application or system. Systems to analyze are with the Cheddar architecture design language. It can help you for quick prototyping of real time schedulers. It can also be used for educational purpose. Cheddar is developed and maintained by a team composed of the *Lab-STICC* laboratory at *Université de Bretagne Occidentale* and *Ellidiss Technologies*.

Cheddar provides two kinds of features: a simulation engine (static simulation) and feasibility tests. Feasibility tests allow a user to study a real time application or system without computing a scheduling solution. In the contrary, the simulation engine can be used firstly for computing a scheduling solution, and secondly, to automatically looking for task constraint properties in the computed scheduling solution. Most of the times, feasibility tests are less complex tools but they are available only for few scheduling protocols and tasks models. To solve this problem, the Cheddar simulation engine provides tools to design specific schedulers and task models: the system is then analyzed according to a given scheduling. 

More information about Cheddar can be found on its dedicated [website](http://beru.univ-brest.fr/cheddar/).

In order to be able to perform advanced model processing in a homogeneous way and to reduce the effort of developing new analysis plug-ins, the timing analysis plugin services operates on a standardized *Architecture Analysis and Design Language* (AADL) declarative model. The formal definition of the *AADL* language can be found in the SAE AS-5506 document that is made available on the [official site](https://www.sae.org/standards/content/as5506d). More information about this language is available on the [Ellidiss wiki page](https://www.ellidiss.fr/public/wiki/AADL) and the [OpenAADL web site](http://www.openaadl.org). 

The timing analysis plugin performs the following actions:
* Automatic model transformation from the user model expressed in AADL,
* Execution of a command-line version of Cheddar (cheddarkernel),
* Return the result of the timing analysis in a json or original xml format in order to be displayed in a user interface application.

# Technical Aspects

## Supported AADL properties

The following properties are supported in AADLInspector Cheddar services:

### Supported processor properties

| Processor Property | Description |
| ----------- | ----------- |
| Scheduling_Protocol | This property specifies the processor scheduling protocol. See the [Supported Scheduling protocols table](#cheddarSchedulingProtocols). |
| Preemptive_Scheduler | This property specifies if a thread can be preempted during its execution time by a scheduler in order to run another thread. Can be True or False. | 
| Scheduler_Quantum | This property specifies the quantum of a given processor. The quantum is a maximum bound on the delay a thread can held the processor without being preempted. A quantum is typically used in time sharing scheduling and in POSIX 1003.1b scheduling (with the SCHED_RR policy for example). |

Specific Cheddar properties (the property set name is Cheddar_Properties) :

| Processor Cheddar Property | Description |
| ----------- | ----------- |
| Source_Text | Name of the parametric scheduler file (i.e. “rm.sc”). Used when the scheduling protocol is  Pipeline_User_Defined_Protocol. |


| Cheddar Scheduling Protocol <a name="cheddarSchedulingProtocols"/> | Description |
| ----------- | ----------- |
| Rate_Monotonic_Protocol (RM, RMA or RMS) | Threads have to be periodic, and their deadline must be equal to their period. Threads are scheduled according to their Period property (the shorter the period is, the higher is the thread's priority). |
| Deadline_Monotonic_Protocol (DM) | Threads have to be periodic and are scheduled according to their Deadline property (the shorter the deadline is, the higher is the thread's priority). |
| Earliest_Deadline_First_Protocol (EDF) | Threads can be periodic or not and are scheduled according to their deadline which is computed from the Deadline, the Period and the First_Dispatch_Time properties (the highest priority thread is the one closest to its deadline). |
| Least_Laxity_First_Protocol (LLF) | Threads can be periodic or not and are scheduled according to their laxity which is computed from the Deadline, the Period and the First_Dispatch_Time properties (the highest priority thread is the one with the lowest laxity). |
| POSIX_1003_Highest_Priority_First_Protocol (HPF) and queueing policies (SCHED_FIFO, SCHED_RR and SCHED_OTHERS) | Threads can be periodic or not. Threads are scheduled according to the priority and the policy of the threads. This scheduling protocol shares the processor according to the Priority, the POSIX_Scheduling_Policy and the First_Dispatch_Time properties. |
| Pipeline_User_Defined_Protocol | This scheduler allow users to define their own scheduler into Cheddar. A “*.sc” file, which contained the scheduler code must be provided through the Source_Text property. |

### Supported thread properties

| Thread property <a name="threadProperties"/> | Description |
| ----------- | ----------- |
| Period | Period of time between 2 thread dispatches. Required for Periodic and Sporadic threads. |
| Deadline | Deadline of the thread. |
| Priority | Required when the scheduling protocol is POSIX_1003_Highest_Priority_First_Protocol |
| Compute_Execution_Time | This is the worst case execution time of the thread. Required when no behaviour annex is specified. |
| POSIX_Scheduling_Policy | Queueing policies for POSIX_1003_Highest_Priority_First_Protocol. See the [Supported Queueing Policies table](#CheddarQueueingPolicies). | 
| Dispatch_Protocol | See the [Supported Dispatch Protocols table](#CheddarDispatchProtocols). |
| First_Dispatch_Time | Time of the first dispatch (default 0). |

Specific Cheddar properties (the property set name is Cheddar_Properties) :

|  Thread Cheddar Property | Description |
| ----------- | ----------- |
| Bound_On_Data_Blocking_Time | Maximum duration a thread has to wait for the access to a protected data. Used to compute the worst case response time of a thread (theoretical). |
| Dispatch_Seed_Value | This property specifies the seed value which is used by the Cheddar simulator engine. To compute a scheduling with Background, Poisson or Sporadic  threads, the simulator engine has to generate random dispatching time. If this property is omitted, the seed random generator is initialized to zero : it means that several simulations of an AADL specification will lead to the same computed scheduling. | 
| Dispatch_Seed_is_Predictable | This property specifies how the seed has to be initialized. If its value is true, the seed is initialized with the same value for all scheduling simulation. In this case, the successive simulations of an AADL specification leads to the same computed scheduling. If you plan to run several simulations of an AADL specification and if you plan to generate different scheduling for each simulation, then, this property must be initialized with false. If this property is omitted, the seed is randomly initialized. |

| Cheddar Dispatch Protocol <a name="CheddarDispatchProtocols"/> | Description |
| ----------- | ----------- |
| Periodic | The thread periodically runs a job. A periodic thread has a start time (First_Dispatch_Time). Its period (see the [Thread properties table](#threadProperties)) stores the fixed delay between two successive thread wakeup times. |
| Aperiodic (or Background) | The thread is dispatched at a time specified by the property First_Dispatch_Time, run a job and leaves the system. |
| Sporadic | The thread is dispatched with a minimal inter-waking up period delay. The minimum delay is stored in the Period property. |
| Poisson_Process | The thread periodically runs a job. The Period property stores the average delay between two successive threads wakeup times. The effective delay between two wakeup times is computed with an exponential random generator. |

| Cheddar Queueing Policy <a name="CheddarQueueingPolicies"/> | Description |
| ----------- | ----------- |
| SCHED_FIFO | Implements a FIFO scheduling protocol : a thread stays on the processor until it has terminated or until a highest priority thread is released. | 
| SCHED_RR | Is similar to SCHED_FIFO except that the quantum is used. At the end of the quantum, the running thread leaves the processor. | 
| SCHED_OTHERS | implements a time sharing scheduling. A thread with a SCHED_OTHERS policy must have a priority equal to zero. |

### Supported data properties

| Data Property | Description |
| ----------- | ----------- |
| Concurrency_Control_Protocol | Specifies the data access protocol. See the [Supported Shared Resource Protocols table](#sharedResourceProtocols). |

| Shared Resource Protocol <a name="sharedResourceProtocols"/> | Description |
| ----------- | ----------- |
| Priority Inheritance (PIP) | The Cheddar scheduling simulator increases the priority of a lower priority thread which blocks a higher priority thread. The Concurrency_Control_Protocol is set to Priority_Inheritance. |
| Priority Ceiling (PCP) | This protocol applies the priority inheritance of Priority Inheritance (PIP) and introduces a new thread blocking condition in order to avoid deadlock and to decrease thread blocking time. The Concurrency_Control_Protocol is set to Priority_Ceiling. |
| Immediate Priority Ceiling (IPCP or ICPP) | This last protocol is similar to Priority Ceiling.  The Concurrency_Control_Protocol is set to Immediate_Priority_Ceiling_Protocol. |
| None | No particular protocol is used when a data is accessed by threads. The Concurrency_Control_Protocol is set to None_Specified. |

### Cheddar Dependencies

A dependency models an interaction between two software entities which has an impact upon the scheduling of the system. Entities handled in a dependency component can either be threads, resources and/or buffers.

| Type of Dependency | Description |
| - | - |
| Precedence_Dependency | This dependency models a precedency relationship between two threads.<br><br>With this dependency, the sink thread must wait for completion of the source thread before being released by the scheduler. |
| Queuing_Buffer_Dependency | This dependency models a producer/consumer relationship between threads and a buffer. <br><br>When the source is a thread and the sink is a buffer, the dependency models the producer side. <br><br>When the sink  is a thread and the source is a buffer, the dependency models the consumer side. <br><br>This dependency assume a fixed buffer size. A message can be read one time only and we assume that no message can be lost. |
| Communication_Dependency | This dependency models the asynchronous exchange of a message between threads.<br><br>When the source is a thread and the sink is a buffer, the dependency models the emitter side.<br><br>When the sink is a thread and the source is a buffer, the dependency models the receiver side. |
| Time_Triggered_Communication_Dependency | This dependency models a  synchronous communication between two threads. Three protocols exist : <ul><li>Sampled_Timing :  emitters and receivers send/receive synchronous messages at their own rate. **From a scheduling point of view, those threads are independent.**</li><li>Immediate_Timing :  when an emitter completes its activation, the receiver thread is immediately released. **From a scheduling point of view, this dependency is equivalent to a precedence_dependency.**</li><li>Delayed_Timing :  when an emitter completes its activation, the protocol enforces that the receiver will be released on one of the next activation of the emitter task. This delay is expressed by the offset of the sink thread. **From a scheduling point of view, those threads are independent as we only change thread release times.**</li></ul>|
| Resource_Dependency | This dependency models a shared memory access  between several thread and a resource. |
| Black_Board_Buffer_Dependency | This dependency models a producer/consumer relationship between threads and a buffer.<br><br>When the source is a thread and the sink is a buffer, the dependency models the producer side.<br><br>When the sink is a thread and the source is a buffer, the dependency models the consumer side.<br><br>This dependency assumes a buffer size of 1. A message can be read several times or never, e.g. consumers read the last written message produced by producers. <br><br>**From a scheduling point of view, tasks accessing a black board are independent.** |

### Cheddar Framework Configuration

The cheddar framework configuration contains restrictions on the maximum number of items:

| Cheddar | AADL | Maximum | Comment |
| - | - | - | - |
| Processor | Processor | 100 |  |
| Core Unit |  | 100 |  |
| Task | Thread | 200 |  |
| Message |  | 100 |  |
| Buffer | Data | 100 |  |
| Tasks Per Buffer |  | 20 | Maximum number of tasks that can use a shared  buffer. Increasing this constant implies increasing cheddar memory footprint. |
| Resource | Data | 100 |  |
| Tasks Per Resource |  | 20 | Maximum number of tasks that can use a shared resource. Increasing this constant implies increasing cheddar memory footprint. |
| Address Space | Partition | 100 |  |
| Dependency |  | 150 | Maximum number of dependencies of a XML Cheddar project file. Increasing this constant implies increasing cheddar memory footprint. |
| Offset |  | 5 |  |
| Scheduling Period |  | 1000000 | Maximum scheduling period Cheddar can compute. |

## Prolog facts output (TODO)

Several prolog facts are generated by AADL Inspector containing information produced by Cheddar.

### Theoretical and Simulation Results

* **isWorstCaseResponseTime(hwRef,swRef,value,'')**

    | Parameter | Description |
    | - | - |
    | Hardware reference | Instance name of the hardware reference |
    | Software reference | Instance name of the software reference |
    | Value | Theoretical thread worst case response time |

    Example : 

    ```
    isWorstCaseResponseTime('root.my_platform.cpu','root.my_process.t1','8.0000','').
    ```

 * **isMaxCheddarResponseTime(hwRef,swRef,value,'')**

    | Parameter | Description |
    | - | - |
    | Hardware reference | Instance name of the hardware reference |
    | Software reference | Instance name of the software reference |
    | Value | Simulation thread maximum response time |

    Example :

    ```
    isMaxCheddarResponseTime('root.my_platform.cpu','root.my_process.t1','14.0000','').
    ```

 * **isAvgCheddarResponseTime(hwRef,swRef,value,'')**

    | Parameter | Description |
    | - | - |
    | Hardware reference | Instance name of the hardware reference |
    | Software reference | Instance name of the software reference |
    | Value | Simulation thread average response time |

    Example :

    ```
    isAvgCheddarResponseTime('root.my_platform.cpu','root.my_process.t1','10.4000','').
    ```

 * **isMinCheddarResponseTime(hwRef,swRef,value,'')**

    | Parameter | Description |
    | - | - |
    | Hardware reference | Instance name of the hardware reference |
    | Software reference | Instance name of the software reference |
    | Value | Simulation thread minimum response time |

    Example :

    ```
    isMinCheddarResponseTime('root.my_platform.cpu','root.my_process.t1','8.0000','')
    ```

 * **isCheddarTheoriticalResponseTimeError(hwRef,swRef,value,'')**

    | Parameter | Description |
    | - | - |
    | Hardware reference | Instance name of the hardware reference |
    | Software reference | Instance name of the software reference |
    | Value | Theoretical response time Error message |

    Example :

    ```
    isCheddarTheoriticalResponseTimeError('root.my_platform.cpu','root.my_process.t2','::root.my_platform.cpu.my_process.t2','')
    ```

 * **isCheddarSimulationResponseTimeError(hwRef,swRef,value,'')**

    | Parameter | Description |
    | - | - |
    | Hardware reference | Instance name of the hardware reference |
    | Software reference | Instance name of the software reference |
    | Value | Simulation response time Error message |

    Example :

    ```
    isCheddarSimulationResponseTimeError('root.my_platform.cpu','root.my_process.t2','','')
    ```

 * **isCheddarUtilization(hwRef,swRef,value,'')**

    | Parameter | Description |
    | - | - |
    | Hardware reference | Instance name of the hardware reference |
    | Software reference | Instance name of the software reference |
    | Value | Theoretical processor utilization |

    Example :

    ```
    isCheddarUtilization('root.my_platform.cpu','NIL','0.9333','')
    ```

 * **isCheddarTheoBasePeriod(hwRef,swRef,value,'')**

    | Parameter | Description |
    | - | - |
    | Hardware reference | Instance name of the hardware reference |
    | Software reference | Instance name of the software reference |
    | Value | Theoretical base period/hyper period |

    Example :

    ```
    isCheddarTheoBasePeriod('root.my_platform.cpu','NIL','75.0000','')
    ```

 * **isCheddarSimuNBOfPreemptions(hwRef,swRef,value,'')**

    | Parameter | Description |
    | - | - |
    | Hardware reference | Instance name of the hardware reference |
    | Software reference | Instance name of the software reference |
    | Value | Simulation number of thread preemptions |

    Example :

    ```
    isCheddarSimuNBOfPreemptions('root.my_platform.cpu','NIL','0.0000','')
    ```

 * **isCheddarSimuNBOfContextSwitches(hwRef,swRef,value,'')**

    | Parameter | Description |
    | - | - |
    | Hardware reference | Instance name of the hardware reference |
    | Software reference | Instance name of the software reference |
    | Value | Simulation number of thread context switches |

    Example :

    ```
    isCheddarSimuNBOfContextSwitches('root.my_platform.cpu','NIL','6.0000','')
    ```

 * **isCheddarSchedulabilityTest(hwRef,swRef,testName,result,explanation,'')**

    | Parameter | Description |
    | - | - |
    | Hardware reference | Instance name of the hardware reference |
    | Software reference | Instance name of the software reference |
    | Test name | Name of the test : <ul><li>processor utilization factor</li><li>worst case task response time</li><li>task response time computed from simulation</li> |
    | Result | The test has passed, true or false |
    | Explanation | A more detailed explanation is given |

    Example :

    ```
    isCheddarSchedulabilityTest('root.my_platform.cpu','NIL','Task response time computed from simulation','true','No deadline missed in the computed scheduling : the task set is schedulable if you computed the scheduling on the feasibility interval.','')
    ```

### Simulation event

The *isCheddarTraceEvent* prolog fact represents a state at time t of the Cheddar simulation.

* **isCheddarTraceEvent(timestamp,time,entity,hwRef,swRef,state,'NIL')**

    | Parameter | Description |
    | - | - |
    | timestamp | Yearmonthday-hourminutesecond <br><br>example :20220726-150743 |
    | time | Time in the simulation (0 to t) |
    | entity | The different entities are : <ul><li>PROCESSOR</li><li>PARTITION</li><li>THREAD</li><li>DATA</li></ul>
    | Hardware reference | Instance name of the hardware reference <br><br>example : root.my_platform.cpu |
    | Software reference | Instance name of the software reference <br><br>example : root.my_process.t1 |
    | Entity state | The different states are :<ul><li>RUNNING/READY/SUSPENDED : partition, thread</li><li>LOCK/UNLOCK : data</li><li>OCCUPIED/AVAILABLE : processor</li></ul> |

## VCD Output (TODO)

The Cheddar simulation events can also be saved as vcd file ([Value Change Dump format](https://web.archive.org/web/20120323132708/http:/www.beyondttl.com/vcd.php)).

## XML Output

The timing analysis plugin calls **Cheddar** services. One of the result output format is **XML** which can be interpreted by the ui application.

All results are encompassed between the parent `<results> ... </results>` tags.

Fore each feasibility test, computation results are between `<feasibilityTest> ... </feasibilityTest>` tags. This tag has the following attributes:

| Attribute | Description |
| - | - |
| name | The name of the feasibility test : <ul><li>Processor utilization factor,</li><li>Worst case task response time,</li><li>Task response time computed from simulation,</li><li>Set priorities according to Rate Monotonic,</li><li>Set priorities according to Deadline Monotonic.</li></ul> |
| reference | The name of the  entity concerned by the feasibility test. |

Inside a feasibility test tags, one can find several sub tags :

* `<computation>` with the following attributes :

    | Attribute | Description |
    | - | - |
    | name | Name of the computation for processor utilization factor test : <ul><li>base period,</li><li>processor utilization factor with deadline,</li><li>processor utilization factor with period.</li></ul>Name of the computation for worst case task response time test : <ul><li>response time.</li></ul>Name of the computation for Task response time computed from simulation test : <ul><li>Number of preemptions,</li><li>Number of context switches,</li><li>Task response time computed from simulation.</li></ul>Name of the computation for Set priorities according to Rate Monotonic and Set priorities according to Deadline Monotonic tests :<ul><li>Updated priorities.</li></ul>
    | reference | Name of the concerned entity. |
    | value | Computation results. |
    | worst<br>best<br>average | Specific values for Task response time computed from simulation computation. Replace the value attribute. |
    | unused | Specific for base period computation. Unused unit of time of the scheduling during the base period. |
    | biblio | Bibliographic reference(s). |

* `<schedulability>` which describes the test schedulabilty result. It has the following attributes :

    | Attribute | Description |
    | - | - |
    | scheduler | The scheduler concerned (See the [Supported Scheduling protocols table](#cheddarSchedulingProtocols)). | 
    | preemptive | Can be True or False. The scheduler is preemptive or not. |
    | result | Can be True or False. The scheduling is valid or not. |
    | explanation | A textual explanation of the results. |

An example is provided below :

```xml
<results>
  <feasibilityTest name="processor utilization factor" reference="hpf">
    <computation name="base period" reference="all" value=210.00000 biblio="[18], page 5" unused=170.00000/>
    <computation name="processor utilization factor with deadline" reference="all" value=0.19048 biblio="[1], page 6"/>
    <computation name="processor utilization factor with period" reference="all" value=0.19048 biblio="[1], page 6"/>
    <schedulability scheduler="POSIX_1003_HIGHEST_PRIORITY_FIRST_PROTOCOL" preemptive="true" result="false" explanation="Invalid scheduler : can not apply  the feasibility test on processor utilization factor." biblio=""/>
  </feasibilityTest>
  <feasibilityTest name="worst case task response time" reference="hpf">
    <computation name="response time" reference="ea_hpf.tq1" value=20.00000 biblio=""/>
    <computation name="response time" reference="ea_hpf.tq2" value=20.00000 biblio=""/>
    <schedulability scheduler="POSIX_1003_HIGHEST_PRIORITY_FIRST_PROTOCOL" preemptive="true" result="true" explanation="All task deadlines will be met : the task set is schedulable." biblio=""/>
  </feasibilityTest>
  <feasibilityTest name="Task response time computed from simulation" reference="hpf">
    <computation name="Number of preemptions" reference="hpf" value=18 biblio=""/>
    <computation name="Number of context switches" reference="hpf" value=19 biblio=""/>
    <computation name="Task response time computed from simulation" reference="ea_hpf.tq1" worst=38 best=38 average=38.00000 biblio=""/>
    <computation name="Task response time computed from simulation" reference="ea_hpf.tq2" worst=40 best=40 average=40.00000 biblio=""/>
    <schedulability scheduler="POSIX_1003_HIGHEST_PRIORITY_FIRST_PROTOCOL" preemptive="true" result="true" explanation="No deadline missed in the computed scheduling : the task set seems to be schedulable." biblio=""/>
  </feasibilityTest>
  <feasibilityTest name="Set priorities according to Rate Monotonic" reference="hpf">
    <computation name="Updated priorities" reference="ea_hpf.tq1" value=1 biblio=""/>
    <computation name="Updated priorities" reference="ea_hpf.tq2" value=2 biblio=""/>
  </feasibilityTest>
  <feasibilityTest name="Set priorities according to Deadline Monotonic" reference="hpf">
    <computation name="Updated priorities" reference="ea_hpf.tq1" value=1 biblio=""/>
    <computation name="Updated priorities" reference="ea_hpf.tq2" value=2 biblio=""/>
  </feasibilityTest>
</results>
```

# API Description

