stdlib,python: Allow setting of to tick exits via m5

This commit adds the following functions to the `m5` python module:

- setMaxTick(tick) -> None
- getMaxTick() -> int
- getTicksUntilMax() -> int
- scheduleTickExitFromCurrent(tick, exit_string) -> None
- scheduleTickExitAbsolute(tick, exit_string) -> None

Until this patch the only way to set an exit at a particular tick was
via `simulate.run` which would reschedule the maximum tick. This
functionality has been explicity exposed via the new `setMaxTick`
function. However, as this is only rescheduling the maximum tick, it
stops scheduling exits at multiple different ticks.

To get around this problem the `scheduleTickExit` functions have been
added. These allow a user to schedule multiple exit events. The
functions contain a `exit_string` parameter that provides the string
the simulator is to return when the specified tick is met. By default
this string is "Tick exit reached" which is used by the stdlib
Simulator module to declare a new `SCHEDULED_TICK` exit event (Note:
this has been deliberatly kept seperate from the `MAX_TICK` exit event.
This commit serves as an attempt to decouple these are two concepts).

Tests are provided in this patch to ensure these new functions work as
intended.

Additional notes:
- The `simulate` function has been fixed to match the documentation. If
  the `num_cycles` is -1 then the maximum ticks is set to MaxTicks.
  Otherwise the max ticks is set to `curTicks() + num_cycles`. The
  functionality of this function will remain unchanged to the end-user.
- Full integration into the Simulator module is not complete as of this
  patch. Users must us the m5 python module to set these exit events.

Change-Id: I6c92b31dd409dc866152224600ea8166cfcba38b
Issue-on: https://gem5.atlassian.net/browse/GEM5-1131
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/66231
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Maintainer: Jason Lowe-Power <power.jg@gmail.com>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/66331
Reviewed-by: Bobby Bruce <bbruce@ucdavis.edu>
Maintainer: Bobby Bruce <bbruce@ucdavis.edu>
This commit is contained in:
Bobby R. Bruce
2022-11-30 15:02:05 -08:00
committed by Bobby Bruce
parent ea3f13ff3b
commit 005049f548
14 changed files with 561 additions and 10 deletions

View File

@@ -45,7 +45,37 @@ namespace gem5
class GlobalSimLoopExitEvent;
GlobalSimLoopExitEvent *simulate(Tick num_cycles = MaxTick);
GlobalSimLoopExitEvent *simulate(Tick num_cycles = -1);
/**
* @brief Set the maximum tick.
*
* This function will schedule, or reschedule, the maximum tick for the
* simulation.
*
* This will setup the GlobalSimLoopExitEvent if it does not already exist.
*
* @param tick The maximum tick.
*/
void set_max_tick(Tick tick);
/**
* @brief Get the maximum simulation tick.
*
*
* @returns The maximum simulation tick.
*/
Tick get_max_tick();
/**
* @brief Schedule an exit event at a particular tick.
*
* Schedule a tick with a particular exit string.
*
* @param tick The tick at which the simulation loop should exit.
* @param exit_string The exit string explaining the exit.
*/
void schedule_tick_exit(Tick tick, std::string exit_string);
/**
* Terminate helper threads when running in parallel mode.