예제 #1
0
    def _create_random_traffic(
        self,
        duration: str,
        rate: str,
        block_size: int,
        min_addr: int,
        max_addr: int,
        rd_perc: int,
        data_limit: int,
    ) -> None:
        """
        This function yields (creates) a random traffic based on the input
        params. Then it will yield (create) an exit traffic (exit traffic is
        used to exit the simulation).

        :param duration: The number of ticks for the generator core to generate
        traffic.
        :param rate: The rate at which the synthetic data is read/written.
        :param block_size: The number of bytes to be read/written with each
        request.
        :param min_addr: The lower bound of the address range the generator
        will read/write from/to.
        :param max_addr: The upper bound of the address range the generator
        will read/write from/to.
        :param rd_perc: The percentage of read requests among all the generated
        requests. The write percentage would be equal to 100 - rd_perc.
        :param data_limit: The amount of data in bytes to read/write by the
        generator before stopping generation.
        """
        duration = fromSeconds(toLatency(duration))
        rate = toMemoryBandwidth(rate)
        period = fromSeconds(block_size / rate)
        min_period = period
        max_period = period
        yield self.generator.createRandom(
            duration,
            min_addr,
            max_addr,
            block_size,
            min_period,
            max_period,
            rd_perc,
            data_limit,
        )
        yield self.generator.createExit(0)
예제 #2
0
def runSim(sim_time):
    """ Run the simulation.
        This will run the simulation ignoring exits for "Max Insts", but
        raising an exception for all other exit types.
        @param sim_time the amount of guest-time to simulate as a string
               (e.g., "10ms")
    """
    ticks = fromSeconds(toLatency(sim_time))
    abs_ticks = m5.curTick() + ticks

    exit_event = m5.simulate(ticks)
    while exit_event.getCause() != "simulate() limit reached":
        # It's possible (likely) there are a few max insts exit events still
        # scheduled. We should ignore these. See fastforward
        print "Exited:", exit_event.getCause()
        if not exit_event.getCause().startswith("Max Insts"):
            raise UnexpectedExit(exit_event.getCause())

        exit_event = m5.simulate(abs_ticks - m5.curTick())
예제 #3
0
    def _create_traffic(self) -> Iterator[BaseTrafficGen]:
        """
        A python generator that yields (creates) a linear traffic with the
        specified params in the generator core and then yields (creates) an
        exit traffic.

        :rtype: Iterator[BaseTrafficGen]
        """
        duration = fromSeconds(toLatency(self._duration))
        rate = toMemoryBandwidth(self._rate)
        period = fromSeconds(self._block_size / rate)
        min_period = period
        max_period = period
        yield self.generator.createLinear(
            duration,
            self._min_addr,
            self._max_addr,
            self._block_size,
            min_period,
            max_period,
            self._rd_perc,
            self._data_limit,
        )
        yield self.generator.createExit(0)
예제 #4
0
def simulateROI(system, instructions, samples):
    """ Do everything we need to do during the ROI.
        At a high-level, this function executes the entire ROI and takes
        a number of random sample points. At each point it may run multiple
        simulations.

        @param system the system we are running
        @param instructions total instructions in the ROI (summed over all
               CPUs)
        @param samples number of sample points in the ROI
    """
    from random import randint, sample, seed
    import signal
    import time

    seed()

    executed_insts = system.totalInsts()

    # We probably want to updated the max instructions by subtracting the
    # insts that we are going to execute in the last detailed sim.
    sample_secs = toLatency("10ms") + toLatency("10us") + toLatency("100us")
    # assume 1 IPC per CPU
    instructions -= int(sample_secs * system.clk_domain.clock[0].frequency *
                        len(system.cpu) * 1)

    # Get the instruction numbers that we want to exit at for our sample
    # points. It needs to be sorted, too.
    sample_insts = sample(
        xrange(executed_insts, executed_insts + instructions), samples)
    sample_insts.sort()

    # These are the currently running processes we have forked.
    pids = []

    # Signal handler for when the processes exit. This is how we know when
    # to remove the child from the list of pids.
    def handler(signum, frame):
        assert (signum == signal.SIGCHLD)
        try:
            while 1:
                pid, status = os.wait()
                if status != 0:
                    print "pid", pid, "failed!"
                    sys.exit(status)
                pids.remove(pid)
        except OSError:
            pass

    # install the signal handler
    signal.signal(signal.SIGCHLD, handler)

    # Here's the magic
    for i, insts in enumerate(sample_insts):
        print "Fast forwarding to sample", i, "stopping at", insts
        insts_past = fastforward(system, insts - system.totalInsts())
        if insts_past / insts > 0.01:
            print "WARNING: Went past the goal instructions by too much!"
            print "Goal: %d, Actual: %d" % (insts, system.totalInsts())

        # Max of 4 gem5 instances (-1 for this process). If we have this
        # number of gem5 processes running, we should wait until one finishes
        while len(pids) >= 4 - 1:
            time.sleep(1)

        # Fork gem5 and get a new PID. Save the stats in a folder based on
        # the instruction number.
        pid = m5.fork('%(parent)s/' + str(insts))
        if pid == 0:  # in child
            from m5.internal.core import seedRandom
            # Make sure each instance of gem5 starts with a different
            # random seed. Can't just use time, since this may occur
            # multiple times in the same second.
            rseed = int(time.time()) * os.getpid()
            seedRandom(rseed)
            print "Running detailed simulation for sample", i
            warmupAndRun(system, "10ms", "10us", "100us")
            print "Done with detailed simulation for sample", i
            # Just exit in the child. No need to do anything else.
            sys.exit(0)
        else:  # in parent
            # Append the child's PID and fast forward to the next point
            pids.append(pid)

    print "Waiting for children...", pids
    while pids:
        time.sleep(1)