7.7.2 Scheduler API - use cases and implementation

This section describes uses of the Scheduler API.

Accessing the SchedulerInterfaceForComponents from within a modeling component

This section describes ways of accessing the global interfaces.

LISA component for accessing the SchedulerInterfaceForComponents

A way to access the global interfaces with getGlobalInterface().

includes
{
	#include "sg/SGSchedulerInterfaceForComponents.h"
	#include "sg/SGComponentRegistry.h"
}

behavior init
{
	sg::SchedulerInterfaceForComponents *scheduler =
	  sg::obtainComponentInterfacePointer<sg::SchedulerInterfaceForComponents>
	    (getGlobalInterface(), "scheduler");
}
C++ component for accessing the SchedulerInterfaceForComponents

A way to access the global interfaces with simulationContext->getGlobalInterface(). C++ components have an sg::SimulationContext pointer passed into their constructor.

#include "sg/SGSchedulerInterfaceForComponents.h"
#include "sg/SGComponentRegistry.h"

sg::SchedulerInterfaceForComponents *scheduler =
  sg::obtainComponentInterfacePointer<sg::SchedulerInterfaceForComponents>
    (simulationContext->getGlobalInterface(), "scheduler");
SystemC component for accessing the SchedulerInterfaceForComponents

A way to access the global interfaces with scx::scx_get_global_interface().

#include "sg/SGSchedulerInterfaceForComponents.h"
#include "sg/SGComponentRegistry.h"

sg::SchedulerInterfaceForComponents *scheduler =
  sg::obtainComponentInterfacePointer<sg::SchedulerInterfaceForComponents>
    (scx::scx_get_global_interface(), "scheduler");

Using the default scheduler mapping in the SystemC export use case

Call the global function scx_initialize() to initialize the simulation infrastructure.

scx_initialize(const std::string & id,
			   scx_simcontrol_if *ctrl = scx_get_default_simcontrol());

If you do not specify the ctrl parameter, the default implementations of the simulation controller and of the scheduler mapping onto SystemC apply.

Note:

The namespace for interfaces, classes, and functions in this SystemC export case is scx, except for those of the Scheduler API.

Providing a custom mapping of the scheduler functionality onto SystemC

This section describes how to map the SchedulerInterfaceForComponents onto SystemC scheduling primitives by passing a custom system controller, scx::scx_simcontrol_if, as the second parameter, ctrl, into scx_initialize(). The system controller must return the custom scheduler mapping in get_scheduler().

Minimalistic example of a custom mapping of the scheduler functionality onto SystemC

This section describes how to register a custom scheduler mapping, using the default scheduler mapping for simplicity. A realistic scheduler mapper would reimplement all functionality.

It consists of:

  • A custom scheduler mapping implementation, my_scheduler_mapping.
    • Forwards all calls to the default scheduler mapping.
    • The wait() function prints a verbose message in addition, to make the effect visible.
  • A custom simulation controller implementation, my_simulation_controller.
    • Forwards all calls to the default scx::scx_simcontrol_if implementation.
    • Implements only get_scheduler()differently and returns an instance of my_scheduler_mapping.
  • Creating an instance of my_simulation_controller, my_sim_controller.
  • Passing a pointer to my_sim_controller to scx_initialize() as the second parameter, ctrl.

This example adds a verbose message to sg::SchedulerInterfaceForComponents::wait() calls.

Intended mapping of the Scheduler API onto SystemC/TLM

How Scheduler API functionality might map onto SystemC functionality.

sg::SchedulerInterfaceForComponents::wait(time)
Call sc_core::wait(time) and handle all pending asynchronous events that are scheduled with sg::SchedulerInterfaceForComponents::addCallback() before waiting.
sg::SchedulerInterfaceForComponents::wait(sg::ThreadSignal)
Call sc_core::wait(sc_event) on the sc_event in sg::ThreadSignal and handle all pending asynchronous events that are scheduled with sg::SchedulerInterfaceForComponents::addCallback() before waiting.
sg::SchedulerInterfaceForComponents::getCurrentSimulatedTime()
Return the current SystemC scheduler time in seconds as in sc_core::sc_time_stamp().to_seconds().
sg::SchedulerInterfaceForComponents::addCallback(), removeCallback()
SystemC has no way to trigger simulation events from alien (non-SystemC) host threads in a thread-safe way: buffer and handle these asynchronous events in all regularly re-occurring scheduler events. Handling regular simulation wait() and timerCallback()calls is sufficient.
sg::SchedulerInterfaceForComponents::stopRequest(), stopAcknowledge()
Pause and resume the SystemC scheduler. This function is out of scope of SystemC/TLM functionality, but in practice every debuggable SystemC implementation has ways to pause and resume the scheduler. Do not confuse these functions with sc_core::sc_stop(), which exits the SystemC simulation loop. They work with the sg::SchedulerRunnable instances and the scx::scx_simcontrol_if interface.
sg::SchedulerInterfaceForComponents::createThread(), createThreadSignal(), createTimer()
Map these functions onto SystemC threads created with sc_spawn() and sc_events. You can create and destroy sg::SchedulerThread, sg::ThreadSignal, and sg::Timer objects during elaboration, and delete them at runtime, unlike their SystemC counterparts. This process requires careful mapping. For example, consider what happens when you remove a waited-for sc_event.
sg::ThreadSignal
Map onto sc_event, which is notifiable and waitable.
sg::SchedulerThread
Map onto a SystemC thread that was spawned with sc_core::sc_spawn(). The thread function can call sg::SchedulerThread::threadProc().
sg::QuantumKeeper
Map onto the tlm_quantumkeeper utility class because the semantics of these classes are similar. Arm deprecates this class.
sg::Timer
Map onto a SystemC thread that, after the timer is set(), issues calls to the call-backs in the intervals (according to the set() interval).
Non-ConfidentialPDF file icon PDF version100965_1180_00_en
Copyright © 2014–2019 Arm Limited or its affiliates. All rights reserved.