def __init__(self): """The complex generator core interface. This class defines the interface for a generator core that will create a series of different types of traffic. This core uses PyTrafficGen to create and inject the synthetic traffic. This generator could be used to create more complex traffics that consist of linear and random traffic in different phases. """ super().__init__() self.generator = PyTrafficGen() self._traffic_params = [] self._traffic = [] self._traffic_set = False
def __init__(self): """ Create an AbstractCore with the CPUType of Timing. Also, setup a dummy generator object to connect to icache """ # TODO: Remove the CPU Type parameter. This not needed. # Jira issue here: https://gem5.atlassian.net/browse/GEM5-1031 super(AbstractGeneratorCore, self).__init__(CPUTypes.TIMING) self.dummy_generator = PyTrafficGen()
def __init__( self, duration: str, rate: str, block_size: int, min_addr: int, max_addr: int, rd_perc: int, data_limit: int, ) -> None: super(LinearGeneratorCore, self).__init__() """ The linear generator core interface. This class defines the interface for a generator core that will create a linear (stream) traffic specific to the parameters below. This core uses PyTrafficGen to create and inject the synthetic traffic. :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. """ self.generator = PyTrafficGen() self._duration = duration self._rate = rate self._block_size = block_size self._min_addr = min_addr self._max_addr = max_addr self._rd_perc = rd_perc self._data_limit = data_limit
class ComplexGeneratorCore(AbstractGeneratorCore): def __init__(self): """The complex generator core interface. This class defines the interface for a generator core that will create a series of different types of traffic. This core uses PyTrafficGen to create and inject the synthetic traffic. This generator could be used to create more complex traffics that consist of linear and random traffic in different phases. """ super().__init__() self.generator = PyTrafficGen() self._traffic_params = [] self._traffic = [] self._traffic_set = False @overrides(AbstractCore) def connect_dcache(self, port: Port) -> None: self.generator.port = port def add_linear( self, duration: str, rate: str, block_size: int, min_addr: int, max_addr: int, rd_perc: int, data_limit: int, ) -> None: """ This function will add the params for a linear traffic to the list of traffic params in this generator core. These params will be later resolved by the start_traffic call. This core uses a PyTrafficGen to create the traffic based on the specified params below. :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. """ param = ComplexTrafficParams( TrafficModes.linear, duration, rate, block_size, min_addr, max_addr, rd_perc, data_limit, ) self._traffic_params = self._traffic_params + [param] self._traffic_set = False def add_random( self, duration: str, rate: str, block_size: int, min_addr: int, max_addr: int, rd_perc: int, data_limit: int, ) -> None: """ This function will add the params for a random traffic to the list of traffic params in this generator core. These params will be later resolved by the start_traffic call. This core uses a PyTrafficGen to create the traffic based on the specified params below. :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. """ param = ComplexTrafficParams( TrafficModes.random, duration, rate, block_size, min_addr, max_addr, rd_perc, data_limit, ) self._traffic_params = self._traffic_params + [param] self._traffic_set = False def start_traffic(self) -> None: """ This function first checks if there are any pending traffics that require creation, if so it will create the pending traffics based on traffic_params list and adds them to the traffic list, then it starts generating the traffic at the top of the traffic list. It also pops the first element in the list so that every time this function is called a new traffic is generated, each instance of a call to this function should happen before each instance of the call to m5.simulate(). All the instances of calls to this function should happen after m5.instantiate() """ if not self._traffic_set: self._set_traffic() if self._traffic: self.generator.start(self._traffic.pop(0)) else: print("No phases left to generate!") def _set_traffic(self) -> None: """ This function will pop params from traffic params list and create their respective traffic and adds the traffic to the core's traffic list. """ while self._traffic_params: param = self._traffic_params.pop(0) mode = param._mode duration = param._duration rate = param._rate block_size = param._block_size min_addr = param._min_addr max_addr = param._max_addr rd_perc = param._rd_perc data_limit = param._data_limit if mode == TrafficModes.linear: traffic = self._create_linear_traffic( duration, rate, block_size, min_addr, max_addr, rd_perc, data_limit, ) self._traffic = self._traffic + [traffic] if mode == TrafficModes.random: traffic = self._create_random_traffic( duration, rate, block_size, min_addr, max_addr, rd_perc, data_limit, ) self._traffic = self._traffic + [traffic] self._traffic_set = True def _create_linear_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 linear 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.createLinear( duration, min_addr, max_addr, block_size, min_period, max_period, rd_perc, data_limit, ) yield self.generator.createExit(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)
class LinearGeneratorCore(AbstractGeneratorCore): def __init__( self, duration: str, rate: str, block_size: int, min_addr: int, max_addr: int, rd_perc: int, data_limit: int, ) -> None: super(LinearGeneratorCore, self).__init__() """ The linear generator core interface. This class defines the interface for a generator core that will create a linear (stream) traffic specific to the parameters below. This core uses PyTrafficGen to create and inject the synthetic traffic. :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. """ self.generator = PyTrafficGen() self._duration = duration self._rate = rate self._block_size = block_size self._min_addr = min_addr self._max_addr = max_addr self._rd_perc = rd_perc self._data_limit = data_limit @overrides(AbstractCore) def connect_dcache(self, port: Port) -> None: self.generator.port = port def _set_traffic(self) -> None: """ This private function will set the traffic to be generated. """ self._traffic = self._create_traffic() 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) def start_traffic(self) -> None: """ A call to this function will start generating the traffic, this call should happen before m5.simulate() and after m5.instantiate() """ self._set_traffic() self.generator.start(self._traffic)