## 5 Method and Design
### Modular Approach
#### 5.2.1 Single CPU  
The initial approach involves modeling a single CPU with minimal requirements, equivalent to an FCFS scheduler. The objective was to create a model with two modules--one for the local queue and another for the CPU--and assign all the scheduling responsibilities to a single transition in the local queue module. This ensures that the overall model flow remains consistent, regardless of the implemented scheduling algorithm. The initial model, depicted in Figure 4, comprises two modules: _Local Queue_ and _CPU1_. Additionally, it includes _inter-modular connectors_ (IMC) that integrate the various modules, enabling the simulation. When using Petri modules, there are four distinct elements [23]:  
* **Input ports:** these are the transitions where tokens can arrive in the module from an IMC, such as tcpuQueue in the local queue module in Figure 4.
* **Output ports:** these are the transitions where tokens can go from a module to a place in an IMC, like tInitJob in the local queue module in Figure 4.
* **Local transitions:** these are only accessible from inside the module as they are not input or output ports. * **Local places:** these are only accessible from inside the module as they cannot receive tokens from an outside transition, and an external transition cannot take tokens from them. The input and output ports in Figure 4 are transitions that overlap between a module and IMC. **System flow**: the model shown in Figure 4 is described in the bullet points below. 1. The first transition in the model, tJobGenerator, is responsible for placing tokens inside the place pGlobalQueue, with a color corresponding to its job ID. All the jobs that arrive in pGlobalQueue wait to be placed in the place pLQ. Although the place  
Figure 4: Utilizing a place as a resource to prevent multiple jobs from running simultaneously in the model. pGlobalQueue is not necessary for a single CPU, it is a component of the soon-to-come multiprocessor model. 2. The local queue pLQ is where the scheduling algorithm chooses the next job to be scheduled. The transition tSteaLQ is deactivated in the single CPU model but is used in the multiprocessor model to redistribute jobs. The MLFQ scheduler includes an additional transition, tBoostLQ, which boosts jobs that have been in the local queue for an extended period without being scheduled. 3. Transition tInitJob is where the scheduling algorithm runs to decide the next job to be scheduled. Additionally, there is a place pResource that is consumed by tInitJob, ensuring that only a single job can run at any given time. Without this place, having multiple jobs in the job loop would have been possible. This place enables mutual exclusion of pJobLoop. 4. Upon the job's arrival at the pJobLoop location, it will execute for a specified time slice determined by the implemented scheduling algorithm. If the time slice is non-zero, the tDecrement transition will execute the job for 1 time unit and decrease the time slice by 1 time unit. When the time slice reaches zero, the tTimeSliceOver transition will execute. 5. If the job is not completed, it returns to the pLQ place and awaits rescheduling. Upon job completion, the tTimeSliceOver transition assigns a color _\"Done\"_ to the token. Transition tJobDone verifies if any tokens in pJobBuffer bear the color _\"Done\"_ signifying job completion and enabling placement into pCompleted location. 6. Once a job is requeued or completed, the acquired resource in pResource is returned, facilitating the scheduling of a new job. **Updated model**: the model detailed above employs a single token in place pResource to emulate a shared resource, preventing multiple jobs from running simultaneously. GPenSIM features a built-in resource mechanism explicitly designed for such scenarios. Rather than delegating resource allocation to the Petri net, a higher abstraction within GPenSIM assumes this responsibility. Figure 5 depicts the same model as the previous section but utilizing GPenSIM's built-in resources.