summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsongyanchao <[email protected]>2022-12-21 03:39:28 +0000
committersongyanchao <[email protected]>2022-12-21 03:39:28 +0000
commite36dc15ee97ad00fc2ef04f540e284baa907ff8b (patch)
tree8143fae281a32d3acc3a1eb0dd5c212be35afb01
parent74bd5ec46ba90ca2ceb4718893b2d5389cd762b1 (diff)
✨ feat(TSG-13124): 更新devbind.py,并根据配置的RX队列数决定是否配置RSS
更新devbind.py,并根据配置的RX队列数决定是否配置RSS
-rw-r--r--service/src/phydev.c14
-rw-r--r--tools/devbind/devbind.py137
2 files changed, 95 insertions, 56 deletions
diff --git a/service/src/phydev.c b/service/src/phydev.c
index 7d7c98a..f5fefa5 100644
--- a/service/src/phydev.c
+++ b/service/src/phydev.c
@@ -31,7 +31,7 @@
static struct rte_eth_conf eth_conf_default = {
.rxmode =
{
- .mq_mode = ETH_MQ_RX_RSS,
+ .mq_mode = ETH_MQ_RX_NONE,
.split_hdr_size = 0,
},
.txmode =
@@ -174,11 +174,11 @@ static int gen_phydev_qconf(struct phydev * dev, struct rte_eth_rxconf * rxconf,
}
/* 用户参数解析:网卡参数设置 */
-static int gen_phydev_ethconf(struct phydev * dev, struct rte_eth_conf * out_eth_conf)
+static int gen_phydev_ethconf(struct phydev * dev, unsigned nr_rxq_use, struct rte_eth_conf * out_eth_conf)
{
struct rte_eth_conf eth_conf = eth_conf_default;
- if (dev->info.type == __PHYDEV_INFO_TYPE_PCI)
+ if ((dev->info.type == __PHYDEV_INFO_TYPE_PCI) && (nr_rxq_use > 1))
{
/* only PCI devices can run at RSS mode. */
eth_conf.rxmode.mq_mode = ETH_MQ_RX_RSS;
@@ -490,10 +490,6 @@ static int phydev_setup(struct sc_main * sc, struct phydev_main * ctx, struct ph
return RT_ERR;
}
- // 配置端口信息
- struct rte_eth_conf local_eth_conf;
- gen_phydev_ethconf(dev, &local_eth_conf);
-
unsigned nr_rxq_use = 0;
unsigned nr_txq_use = 0;
@@ -528,6 +524,10 @@ static int phydev_setup(struct sc_main * sc, struct phydev_main * ctx, struct ph
dev->nr_hairpin_q = dev->en_smartoffload ? 1 : 0;
calc_phydev_queue(dev, &nr_rxq_use, &nr_txq_use);
+ // 配置端口信息
+ struct rte_eth_conf local_eth_conf;
+ gen_phydev_ethconf(dev, nr_rxq_use, &local_eth_conf);
+
retval = rte_eth_dev_configure(dev->port_id, nr_rxq_use, nr_txq_use, &local_eth_conf);
if (retval != 0)
{
diff --git a/tools/devbind/devbind.py b/tools/devbind/devbind.py
index 1243f0e..a51e435 100644
--- a/tools/devbind/devbind.py
+++ b/tools/devbind/devbind.py
@@ -39,7 +39,10 @@ import getopt
import subprocess
import json
import argparse
+import platform
from os.path import exists, abspath, dirname, basename
+from glob import glob
+from os.path import join as path_join
# The PCI base class for NETWORK devices
NETWORK_BASE_CLASS = "02"
@@ -101,6 +104,7 @@ def check_modules():
# change DPDK driver list to only contain drivers that are loaded
dpdk_drivers = [mod["Name"] for mod in mods if mod["Found"]]
+ print dpdk_drivers
def has_driver(devices, dev_id):
@@ -227,29 +231,27 @@ def dev_id_from_dev_name(devices, dev_name, quite=False):
return None
-
def unbind_one(devices, dev_id, force):
'''Unbind the device identified by "dev_id" from its current driver'''
dev = devices[dev_id]
- if not has_driver(devices, dev_id):
- print("%s %s %s is not currently managed by any driver\n" %
+ if not has_driver(devices,dev_id):
+ print("Notice: %s %s %s is not currently managed by any driver" %
(dev["Slot"], dev["Device_str"], dev["Interface"]))
return
# prevent us disconnecting ourselves
if dev["Ssh_if"] and not force:
- print("Routing table indicates that interface %s is active. "
- "Skipping unbind" % (dev_id))
+ print("Warning: routing table indicates that interface %s is active. "
+ "Skipping unbind" % dev_id)
return
# write to /sys to unbind
filename = "/sys/bus/pci/drivers/%s/unbind" % dev["Driver_str"]
try:
f = open(filename, "a")
- except:
- print("Error: unbind failed for %s - Cannot open %s"
- % (dev_id, filename))
- sys.exit(1)
+ except OSError as err:
+ sys.exit("Error: unbind failed for %s - Cannot open %s: %s" %
+ (dev_id, filename, err))
f.write(dev_id)
f.close()
@@ -261,76 +263,112 @@ def is_mlx_dev(dev,devices):
else:
return False
-def bind_one(devices, dev_id, driver, force):
+
+def bind_one(devices,dev_id, driver, force):
'''Bind the device given by "dev_id" to the driver "driver". If the device
is already bound to a different driver, it will be unbound first'''
-
dev = devices[dev_id]
saved_driver = None # used to rollback any unbind in case of failure
- if driver == '' or driver == None:
- return
-
# prevent disconnection of our ssh session
if dev["Ssh_if"] and not force:
- print("Routing table indicates that interface %s is active. "
- "Not modifying" % (dev_id))
+ print("Warning: routing table indicates that interface %s is active. "
+ "Not modifying" % dev_id)
return
# unbind any existing drivers we don't want
- if has_driver(devices, dev_id):
+ if has_driver(devices,dev_id):
if dev["Driver_str"] == driver:
- print("%s already bound to driver %s, skipping\n"
- % (dev_id, driver))
+ print("Notice: %s already bound to driver %s, skipping" %
+ (dev_id, driver))
return
- else:
- saved_driver = dev["Driver_str"]
- unbind_one(devices, dev_id, force)
- dev["Driver_str"] = "" # clear driver string
-
- # if we are binding to one of DPDK drivers, add PCI id's to that driver
+ saved_driver = dev["Driver_str"]
+ unbind_one(devices,dev_id, force)
+ dev["Driver_str"] = "" # clear driver string
+
+ # For kernels >= 3.15 driver_override can be used to specify the driver
+ # for a device rather than relying on the driver to provide a positive
+ # match of the device. The existing process of looking up
+ # the vendor and device ID, adding them to the driver new_id,
+ # will erroneously bind other devices too which has the additional burden
+ # of unbinding those devices
if driver in dpdk_drivers:
- filename = "/sys/bus/pci/drivers/%s/new_id" % driver
- try:
- f = open(filename, "w")
- except:
- print("Error: bind failed for %s - Cannot open %s"
- % (dev_id, filename))
- return
- try:
- f.write("%04x %04x" % (dev["Vendor"], dev["Device"]))
- f.close()
- except:
- print("Error: bind failed for %s - Cannot write new PCI ID to "
- "driver %s" % (dev_id, driver))
- return
+ filename = "/sys/bus/pci/devices/%s/driver_override" % dev_id
+ if exists(filename):
+ try:
+ f = open(filename, "w")
+ except OSError as err:
+ print("Error: bind failed for %s - Cannot open %s: %s"
+ % (dev_id, filename, err))
+ return
+ try:
+ f.write("%s" % driver)
+ f.close()
+ except OSError as err:
+ print("Error: bind failed for %s - Cannot write driver %s to "
+ "PCI ID: %s" % (dev_id, driver, err))
+ return
+ # For kernels < 3.15 use new_id to add PCI id's to the driver
+ else:
+ filename = "/sys/bus/pci/drivers/%s/new_id" % driver
+ try:
+ f = open(filename, "w")
+ except OSError as err:
+ print("Error: bind failed for %s - Cannot open %s: %s"
+ % (dev_id, filename, err))
+ return
+ try:
+ # Convert Device and Vendor Id to int to write to new_id
+ f.write("%04x %04x" % (int(dev["Vendor"], 16),
+ int(dev["Device"], 16)))
+ f.close()
+ except OSError as err:
+ print("Error: bind failed for %s - Cannot write new PCI ID to "
+ "driver %s: %s" % (dev_id, driver, err))
+ return
# do the bind by writing to /sys
filename = "/sys/bus/pci/drivers/%s/bind" % driver
try:
f = open(filename, "a")
- except:
- print("Error: bind failed for %s - Cannot open %s"
- % (dev_id, filename))
+ except OSError as err:
+ print("Error: bind failed for %s - Cannot open %s: %s"
+ % (dev_id, filename, err))
if saved_driver is not None: # restore any previous driver
- bind_one(devices, dev_id, saved_driver, force)
+ bind_one(devices,dev_id, saved_driver, force)
return
try:
f.write(dev_id)
- f.close()
- except:
+ f.close ()
+ except OSError as err:
# for some reason, closing dev_id after adding a new PCI ID to new_id
# results in IOError. however, if the device was successfully bound,
# we don't care for any errors and can safely ignore IOError
- tmp = get_pci_device_details(dev_id)
+ tmp = get_pci_device_details(dev_id, True)
if "Driver_str" in tmp and tmp["Driver_str"] == driver:
return
- print("Error: bind failed for %s - Cannot bind to driver %s"
- % (dev_id, driver))
+ print("Error: bind failed for %s - Cannot bind to driver %s: %s"
+ % (dev_id, driver, err))
if saved_driver is not None: # restore any previous driver
- bind_one(devices, dev_id, saved_driver, force)
+ bind_one(devices,dev_id, saved_driver, force)
return
+ # For kernels > 3.15 driver_override is used to bind a device to a driver.
+ # Before unbinding it, overwrite driver_override with empty string so that
+ # the device can be bound to any other driver
+ filename = "/sys/bus/pci/devices/%s/driver_override" % dev_id
+ if exists(filename):
+ try:
+ f = open(filename, "w")
+ except OSError as err:
+ sys.exit("Error: unbind failed for %s - Cannot open %s: %s"
+ % (dev_id, filename, err))
+ try:
+ f.write("\00")
+ f.close()
+ except OSError as err:
+ sys.exit("Error: unbind failed for %s - Cannot write %s: %s"
+ % (dev_id, filename, err))
def unbind_all(devices, dev_list, force=False):
"""Unbind method, takes a list of device locations"""
@@ -400,6 +438,7 @@ def global_configure_parser(g_file):
def nics_bind(hwinfo, niclist):
devices_info = get_nic_details()
+ print dpdk_drivers
bind_all(devices_info, niclist, dpdk_drivers[0], True)
return