Example #1
0
    def set_device_rate(self, pci_slot, rate_type, rate_kbps):
        """Set device rate: rate (max_tx_rate), min_tx_rate

        @param pci_slot: Virtual Function address
        @param rate_type: device rate name type. Could be 'rate' and
                          'min_tx_rate'.
        @param rate_kbps: device rate in kbps
        """
        vf_index = self._get_vf_index(pci_slot)
        #NOTE(ralonsoh): ip link sets rate in Mbps therefore we need to convert
        #the rate_kbps value from kbps to Mbps.
        #Zero means to disable the rate so the lowest rate available is 1Mbps.
        #Floating numbers are not allowed
        if rate_kbps > 0 and rate_kbps < 1000:
            rate_mbps = 1
        else:
            rate_mbps = helpers.round_val(rate_kbps / 1000.0)

        log_dict = {
            'rate_mbps': rate_mbps,
            'rate_kbps': rate_kbps,
            'vf_index': vf_index,
            'rate_type': rate_type
        }
        if rate_kbps % 1000 != 0:
            LOG.debug(
                "'%(rate_type)s' for SR-IOV ports is counted in Mbps; "
                "setting %(rate_mbps)s Mbps limit for port %(vf_index)s "
                "instead of %(rate_kbps)s kbps", log_dict)
        else:
            LOG.debug("Setting %(rate_mbps)s Mbps limit for port %(vf_index)s",
                      log_dict)

        return self.pci_dev_wrapper.set_vf_rate(vf_index, rate_type, rate_mbps)
Example #2
0
    def set_device_rate(self, pci_slot, rate_type, rate_kbps):
        """Set device rate: rate (max_tx_rate), min_tx_rate

        @param pci_slot: Virtual Function address
        @param rate_type: device rate name type. Could be 'rate' and
                          'min_tx_rate'.
        @param rate_kbps: device rate in kbps
        """
        vf_index = self._get_vf_index(pci_slot)
        # NOTE(ralonsoh): ip link sets rate in Mbps therefore we need to convert
        # the rate_kbps value from kbps to Mbps.
        # Zero means to disable the rate so the lowest rate available is 1Mbps.
        # Floating numbers are not allowed
        if rate_kbps > 0 and rate_kbps < 1000:
            rate_mbps = 1
        else:
            rate_mbps = helpers.round_val(rate_kbps / 1000.0)

        log_dict = {"rate_mbps": rate_mbps, "rate_kbps": rate_kbps, "vf_index": vf_index, "rate_type": rate_type}
        if rate_kbps % 1000 != 0:
            LOG.debug(
                "'%(rate_type)s' for SR-IOV ports is counted in Mbps; "
                "setting %(rate_mbps)s Mbps limit for port %(vf_index)s "
                "instead of %(rate_kbps)s kbps",
                log_dict,
            )
        else:
            LOG.debug("Setting %(rate_mbps)s Mbps limit for port %(vf_index)s", log_dict)

        return self.pci_dev_wrapper.set_vf_rate(vf_index, rate_type, rate_mbps)
Example #3
0
 def test_round_val_ok(self):
     for expected, value in ((0, 0),
                             (0, 0.1),
                             (1, 0.5),
                             (1, 1.49),
                             (2, 1.5)):
         self.assertEqual(expected, helpers.round_val(value))
Example #4
0
    def set_device_rate(self, pci_slot, rates):
        """Set device rate: max_tx_rate, min_tx_rate

        @param pci_slot: Virtual Function address
        @param rates: dictionary with rate type (str) and the value (int)
                      in Kbps. Example:
                        {'max_tx_rate': 20000, 'min_tx_rate': 10000}
                        {'max_tx_rate': 30000}
                        {'min_tx_rate': 5000}

        """
        vf_index = self._get_vf_index(pci_slot)
        # NOTE(ralonsoh): ip link sets rate in Mbps therefore we need to
        # convert the rate_kbps value from kbps to Mbps.
        # Zero means to disable the rate so the lowest rate available is 1Mbps.
        # Floating numbers are not allowed
        rates_mbps = {}
        for rate_type, rate_kbps in rates.items():
            if 0 < rate_kbps < 1000:
                rate_mbps = 1
            else:
                rate_mbps = helpers.round_val(rate_kbps / 1000.0)

            rates_mbps[rate_type] = rate_mbps

        missing_rate_types = set(IP_LINK_CAPABILITY_RATES) - rates.keys()
        if missing_rate_types:
            # A key is missing. As explained in LP#1962844, in order not to
            # delete an existing rate ('max_tx_rate', 'min_tx_rate'), it is
            # needed to read the current VF rates and set the same value again.
            vf = self._get_vfs()[int(vf_index)]
            # Devices without 'min_tx_rate' support will return None in this
            # value. If current value is 0, there is no need to set it again.
            for _type in (_type for _type in missing_rate_types if vf[_type]):
                rates_mbps[_type] = vf[_type]

        LOG.debug('Setting %s limits (in Mbps) for port VF %s', rates_mbps,
                  vf_index)
        return self.pci_dev_wrapper.set_vf_rate(vf_index, rates_mbps)
Example #5
0
def round_val(val):
    return helpers.round_val(val)
Example #6
0
 def test_round_val_ok(self):
     for expected, value in ((0, 0), (0, 0.1), (1, 0.5), (1, 1.49), (2,
                                                                     1.5)):
         self.assertEqual(expected, helpers.round_val(value))
Example #7
0
def round_val(val):
    return helpers.round_val(val)