Introduction

A Resource can be used to simulate an item that is shared, such as main memory in a computer or the processing power of a CPU. In MLDesigner, resources are divided into Quantity Resources and Server Resources.

CPU Demo

An excellent example of how Resources work in MLDesigner can be found in MLD Examples→Computer Architectur→CPU Demo and is called CpuSystem. In this example packets are competing for both Memory and CPU resources. A packet must first obtain Memory, before it goes to the CPU module where it is processed. After being processed, the packet releases its memory, which can be allocated to pending packets. The Memory is modeled with a Quantity Resource, called MemoryResource. The CPU is modeled with a Server Resource, called CPUResource.

The depiction above shows a linked resource over three levels in a hierarchical model. The following table illustrates the chain of linked resources.

The chain of the linked resources in CPU Demo

Resource name

Primtive/Block

Linked to

Scope

resource

Allocate

 

External

resource

Allocate#1

Resource

External

Resource

AllocateBasic#1

MemoryResource

Internal

The Resource of the Allocate primitive named resource has its scope set to external. When instantiated in the AllocateBasic module this Resource is linked to the Resource named Resource which also has an external scope. The AllocateBasic module is then instantiated as AllocateBasic#1 in the CpuSystem and is linked to the internal resource named MemoryResource.

A quick way to link resources is to Export the resource to the next level of the hierarchy. To export a resource select the instantiated model instance whose resource needs to be shared with other levels of the system or module and right-click the resource property in the Instance Properties editor. Choose Export or Export As..., if a more descriptive name is required for the resource.

Brief explanation

The packet that leaves the PacketSource has its memory and CPU requirements fields set. Then, the packet enters the AllocateBasic block to obtain the memory requirement (packet length). When the required memory is allocated, the packet moves to the CPU block. The packet is processed by the CPU block based on the priority and CPU requirement. Preemtive is allowed with a switching overhead of 0.1. There are 10 servers active in the CPU. The mode of operation is based on dedicated server.

Once the packet processing is completed by the CPU block, the packet invokes the FreeBasic block to return the allocated memory back to the memory pool.

The StatisticReporter collects and plots various different statistics for the system.

Defining Resource elements

To add a resource to the model use the tool button Add Resource, the menu item Edit → Add Resource or the hot key R. In the Resource Properties window set the field Scope to Internal. The following elements can be defined for a resource:

Quantity Resource attributes

Attribute

Default value

Number of Dimensions

1

Initial Capacity

1

Maximum Queue Occupancy

100

Blocking Mechanism

Wait_For_Resource

Queue Discipline

First_In_First_Out

Queue Reject Mechanism

Incoming_DS_Rejected

Addressing Mode

NonIndexed

Addressed Fit Policy

FirstFit

Server Resource attributes

Attribute

Default value

Number of Dimensions

1

Initial Number of Servers

1

Initial Service Rate Multiplier

1.0

Server Mechanism

Dedicated_Server

Maximum Occupancy

100

Context Switching Overhead

0.0

Preempt Discipline

Allow_Preemption

Queue Discipline

First_In_First_Out

Queue Reject Mechanism

Incoming_DS_Rejected

Resource attributes are settings which affect the overall operation of the resource. They are specified for the resource whose scope is set to Internal. A Resource cannot be External in a System. For every chain of Resources linked together (that is, sharing the same information) there is a single memory that has an Internal scope.

Some resource attributes can be varied during simulation. For a Quantity Resource, the number of resource units can be changed. For a Server Resource, the processing rate multiplier (the processing power of each processor) can be modified during simulation. Special blocks allow the capacity of a Quantity Resource and the processing rate multiplier of a Server Resource to be changed during execution of a model. The resource attributes for these two items specify the capacity and service rate multiplier at the beginning of execution. Resources can be used only in timed domains.

The Quantity Resource represents elements which must be possessed by a transaction (a data structure). After a transaction receives resource units, it continues through the model, holding the resource units for an arbitrary amount of time. At a later point in the model the resource units are released and can then be allocated to other transactions. Transactions can be queued to wait for the release of resource units. A Quantity Resource is passive, that is, it contains units which must be possessed for a transaction to continue through the model.

On the other hand, a Server Resource is active, that is, it actively processes transactions. Each transaction requests a certain amount of processing time. The Server Resource actively allocates processing time to the transactions, and releases transactions which have received their requested service time. A number of resource attributes control how the resource processes transactions, such as the number of processors, how processors are shared among transactions, and the possibility for higher priority transactions to preempt lower priority transactions. The Server Resource also allows queuing of transactions to wait for service.