1

Can you explain the difference between sc_spawn and another process (SC_METHOD, SC_THREAD, SC_CTHREAD )?

Thanks all. Hook

1 Answers1

4

To understand this, you have to get an idea of the phases of elaboration and simulation of SystemC first. The phases of elaboration and simulation shall run in the following sequence (from IEEE Std 1666-2011:

  1. Elaboration—Construction of the module hierarchy
  2. Elaboration—Callbacks to function before_end_of_elaboration
  3. Elaboration—Callbacks to function end_of_elaboration
  4. Simulation—Callbacks to function start_of_simulation
  5. Simulation—Initialization phase
  6. Simulation—Evaluation, update, delta notification, and timed notification phases (repeated)
  7. Simulation—Callbacks to function end_of_simulation
  8. Simulation—Destruction of the module hierarchy

Processes are objects derived from sc_object and are created by calling SC_METHOD, SC_THREAD, SC_CTHREAD, or the sc_spawn function.

If a process is created created during elaboration (1.) or the before_end_of_elaboration (2.) it is a static process. If it is created during the the end_of_elaboration (3.) callback or during simulation, it is a dynamic process.

A process instance created by the SC_METHOD, SC_THREAD, or SC_CTHREAD macro is an unspawned process instances and is typically a static process. Spawned process instances are processes created by calling sc_spawn. Typically, they are dynamic processes, but can be static if sc_spawn is called before the end_of_elaboration phase.

This means, to wrap this up in simple words, that sc_spawn enables you to dynamically add processes during simulation. For example: there can be cases where you only need a certain process, if a certain condition during your simulation becomes true.

Now let's take a look where the processes spawn during the simulation. The actual simulation of SystemC (6.) consists of these phases:

  1. Initialization Phase—Execute all processes (except SC_CTHREADS) in an unspecified order.
  2. Evaluation Phase—Select a process that is ready to run and resume its execution. This may cause immediate event notifications to occur, which may result in additional processes being made ready to run in this same phase. Repeat, as long as there are still processes ready to run.
  3. Update Phase—Execute any pending calls to update() resulting from request_uptdate() calls made in step 1 or 2.
  4. Delta notification phase—If there are pending delta notifications (result from calls to notify()), determine which processes are ready to run due to the delayed notifications and go to step 2.
  5. Timed notification phase—If pending timed notifications or time-outs exist:
    1. advance simulation time to the time of the earliest pending timed notification or time-out;
    2. determine which process instances are sensitive to the events notified and time-outs lapsing at this precise time;
    3. add all such process instances to the set of runnable processes;
    4. If no pending timed notifications or time-outs exist → end of simulation. Otherwise, go to evaluation phase.

If sc_spawn is called to create a spawned process instance, the new process will be added to the set of runnable processes (except if dont_initialize is called). If sc_spawn is called during the evaluation phase, it shall be runnable in the current evaluation phase (2.). If it is called during the update phase (3.), it shall be runnable in the next evaluation phase.

If sc_spawn is called during elaboration, the spawned process will be a child of the module instance which calls sc_spawn. If it is called during simulation, it will be a child of the process that called the function sc_spawn. You may call sc_spawn from a method process (SC_METHOD), a thread process (SC_THREAD), or a clocked thread process (SC_CTHREAD).

This tutorial shows the difference between implementing processes through SC_METHOD and SC_THREAD, and sc_spawn.

Silicon1602
  • 1,151
  • 1
  • 7
  • 18