From: Adrien Mazarguil <adrien.mazarguil@6wind.com>
To: Shahaf Shuler <shahafs@mellanox.com>,
Yongseok Koh <yskoh@mellanox.com>,
Slava Ovsiienko <viacheslavo@mellanox.com>
Cc: dev@dpdk.org
Subject: [dpdk-dev] [PATCH 1/8] net/mlx5: speed up interface index retrieval for flow rules
Date: Fri, 31 Aug 2018 11:57:28 +0200 [thread overview]
Message-ID: <20180831092038.23051-2-adrien.mazarguil@6wind.com> (raw)
In-Reply-To: <20180831092038.23051-1-adrien.mazarguil@6wind.com>
rte_eth_dev_info_get() can be avoided since the underlying device type and
data structure are known.
Caching the index before creating any flow rules avoids a number of
redundant system calls later since users are not expected to destroy the
associated network interface while PMD is bound and running.
Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
---
drivers/net/mlx5/mlx5.c | 48 ++++++++++++++++++-------------------
drivers/net/mlx5/mlx5.h | 1 +
drivers/net/mlx5/mlx5_ethdev.c | 4 +---
drivers/net/mlx5/mlx5_flow.c | 6 ++---
drivers/net/mlx5/mlx5_nl.c | 9 +++----
5 files changed, 32 insertions(+), 36 deletions(-)
diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c
index a8ae2b5d3..55b73a03b 100644
--- a/drivers/net/mlx5/mlx5.c
+++ b/drivers/net/mlx5/mlx5.c
@@ -736,6 +736,7 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
struct ether_addr mac;
char name[RTE_ETH_NAME_MAX_LEN];
int own_domain_id = 0;
+ struct rte_flow_error flow_error;
unsigned int i;
/* Determine if this port representor is supposed to be spawned. */
@@ -959,6 +960,8 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
priv->domain_id = RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID;
priv->representor_id =
switch_info->representor ? switch_info->port_name : -1;
+ /* Interface index will be known once eth_dev is allocated. */
+ priv->ifindex = 0;
/*
* Look for sibling devices in order to reuse their switch domain
* if any, otherwise allocate one.
@@ -1087,6 +1090,16 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
err = rte_errno;
goto error;
}
+ /*
+ * Cache associated interface index since lookups are expensive.
+ * It is not expected to change while a PMD instance is bound and
+ * running.
+ */
+ priv->ifindex = mlx5_ifindex(eth_dev);
+ if (!priv->ifindex)
+ DRV_LOG(WARNING,
+ "cannot retrieve network interface index: %s",
+ strerror(rte_errno));
/* Configure the first MAC address by default. */
if (mlx5_get_mac(eth_dev, &mac.addr_bytes)) {
DRV_LOG(ERR,
@@ -1131,32 +1144,19 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
if (vf && config.vf_nl_en)
mlx5_nl_mac_addr_sync(eth_dev);
priv->mnl_socket = mlx5_nl_flow_socket_create();
- if (!priv->mnl_socket) {
- err = -rte_errno;
+ if (!priv->mnl_socket ||
+ !priv->ifindex ||
+ mlx5_nl_flow_init(priv->mnl_socket, priv->ifindex, &flow_error)) {
+ if (!priv->mnl_socket) {
+ flow_error.message = "cannot open libmnl socket";
+ } else if (!priv->ifindex) {
+ rte_errno = ENXIO;
+ flow_error.message = "unknown network interface index";
+ }
DRV_LOG(WARNING,
"flow rules relying on switch offloads will not be"
- " supported: cannot open libmnl socket: %s",
- strerror(rte_errno));
- } else {
- struct rte_flow_error error;
- unsigned int ifindex = mlx5_ifindex(eth_dev);
-
- if (!ifindex) {
- err = -rte_errno;
- error.message =
- "cannot retrieve network interface index";
- } else {
- err = mlx5_nl_flow_init(priv->mnl_socket, ifindex,
- &error);
- }
- if (err) {
- DRV_LOG(WARNING,
- "flow rules relying on switch offloads will"
- " not be supported: %s: %s",
- error.message, strerror(rte_errno));
- mlx5_nl_flow_socket_destroy(priv->mnl_socket);
- priv->mnl_socket = NULL;
- }
+ " supported: %s: %s",
+ flow_error.message, strerror(rte_errno));
}
TAILQ_INIT(&priv->flows);
TAILQ_INIT(&priv->ctrl_flows);
diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index 35a196e76..4c2dec644 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -183,6 +183,7 @@ struct priv {
unsigned int representor:1; /* Device is a port representor. */
uint16_t domain_id; /* Switch domain identifier. */
int32_t representor_id; /* Port representor identifier. */
+ unsigned int ifindex; /* Interface index associated with device. */
/* RX/TX queues. */
unsigned int rxqs_n; /* RX queues array size. */
unsigned int txqs_n; /* TX queues array size. */
diff --git a/drivers/net/mlx5/mlx5_ethdev.c b/drivers/net/mlx5/mlx5_ethdev.c
index 34c5b95ee..cf0b415b2 100644
--- a/drivers/net/mlx5/mlx5_ethdev.c
+++ b/drivers/net/mlx5/mlx5_ethdev.c
@@ -511,7 +511,6 @@ mlx5_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info)
struct priv *priv = dev->data->dev_private;
struct mlx5_dev_config *config = &priv->config;
unsigned int max;
- char ifname[IF_NAMESIZE];
/* FIXME: we should ask the device for these values. */
info->min_rx_bufsize = 32;
@@ -532,8 +531,7 @@ mlx5_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info)
info->rx_offload_capa = (mlx5_get_rx_port_offloads() |
info->rx_queue_offload_capa);
info->tx_offload_capa = mlx5_get_tx_port_offloads(dev);
- if (mlx5_get_ifname(dev, &ifname) == 0)
- info->if_index = if_nametoindex(ifname);
+ info->if_index = priv->ifindex;
info->reta_size = priv->reta_idx_n ?
priv->reta_idx_n : config->ind_table_max_size;
info->hash_key_size = MLX5_RSS_HASH_KEY_LEN;
diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c
index 3f548a9a4..f093a5ed0 100644
--- a/drivers/net/mlx5/mlx5_flow.c
+++ b/drivers/net/mlx5/mlx5_flow.c
@@ -2466,13 +2466,13 @@ mlx5_flow_merge_switch(struct rte_eth_dev *dev,
n = RTE_MIN(mlx5_dev_to_port_id(dev->device, port_id, n), n);
}
for (i = 0; i != n; ++i) {
- struct rte_eth_dev_info dev_info;
+ struct rte_eth_dev *i_dev = &rte_eth_devices[port_id[i]];
+ struct priv *i_priv = i_dev->data->dev_private;
- rte_eth_dev_info_get(port_id[i], &dev_info);
if (port_id[i] == dev->data->port_id)
own = i;
ptoi[i].port_id = port_id[i];
- ptoi[i].ifindex = dev_info.if_index;
+ ptoi[i].ifindex = i_priv->ifindex;
}
/* Ensure first entry of ptoi[] is the current device. */
if (own) {
diff --git a/drivers/net/mlx5/mlx5_nl.c b/drivers/net/mlx5/mlx5_nl.c
index d61826aea..a298db68c 100644
--- a/drivers/net/mlx5/mlx5_nl.c
+++ b/drivers/net/mlx5/mlx5_nl.c
@@ -362,7 +362,6 @@ mlx5_nl_mac_addr_list(struct rte_eth_dev *dev, struct ether_addr (*mac)[],
int *mac_n)
{
struct priv *priv = dev->data->dev_private;
- unsigned int iface_idx = mlx5_ifindex(dev);
struct {
struct nlmsghdr hdr;
struct ifinfomsg ifm;
@@ -374,7 +373,7 @@ mlx5_nl_mac_addr_list(struct rte_eth_dev *dev, struct ether_addr (*mac)[],
},
.ifm = {
.ifi_family = PF_BRIDGE,
- .ifi_index = iface_idx,
+ .ifi_index = priv->ifindex,
},
};
struct mlx5_nl_mac_addr data = {
@@ -421,7 +420,6 @@ mlx5_nl_mac_addr_modify(struct rte_eth_dev *dev, struct ether_addr *mac,
int add)
{
struct priv *priv = dev->data->dev_private;
- unsigned int iface_idx = mlx5_ifindex(dev);
struct {
struct nlmsghdr hdr;
struct ndmsg ndm;
@@ -437,7 +435,7 @@ mlx5_nl_mac_addr_modify(struct rte_eth_dev *dev, struct ether_addr *mac,
.ndm = {
.ndm_family = PF_BRIDGE,
.ndm_state = NUD_NOARP | NUD_PERMANENT,
- .ndm_ifindex = iface_idx,
+ .ndm_ifindex = priv->ifindex,
.ndm_flags = NTF_SELF,
},
.rta = {
@@ -600,7 +598,6 @@ static int
mlx5_nl_device_flags(struct rte_eth_dev *dev, uint32_t flags, int enable)
{
struct priv *priv = dev->data->dev_private;
- unsigned int iface_idx = mlx5_ifindex(dev);
struct {
struct nlmsghdr hdr;
struct ifinfomsg ifi;
@@ -613,7 +610,7 @@ mlx5_nl_device_flags(struct rte_eth_dev *dev, uint32_t flags, int enable)
.ifi = {
.ifi_flags = enable ? flags : 0,
.ifi_change = flags,
- .ifi_index = iface_idx,
+ .ifi_index = priv->ifindex,
},
};
int fd;
--
2.11.0
next prev parent reply other threads:[~2018-08-31 9:57 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-31 9:57 [dpdk-dev] [PATCH 0/8] net/mlx5: add switch offload for VXLAN encap/decap Adrien Mazarguil
2018-08-31 9:57 ` Adrien Mazarguil [this message]
2018-08-31 9:57 ` [dpdk-dev] [PATCH 2/8] net/mlx5: clean up redundant interface name getters Adrien Mazarguil
2018-08-31 9:57 ` [dpdk-dev] [PATCH 3/8] net/mlx5: rename internal function Adrien Mazarguil
2018-08-31 9:57 ` [dpdk-dev] [PATCH 4/8] net/mlx5: enhance TC flow rule send/ack function Adrien Mazarguil
2018-08-31 9:57 ` [dpdk-dev] [PATCH 5/8] net/mlx5: prepare switch flow rule parser for encap offloads Adrien Mazarguil
2018-08-31 9:57 ` [dpdk-dev] [PATCH 6/8] net/mlx5: add convenience macros to switch flow rule engine Adrien Mazarguil
2018-08-31 9:57 ` [dpdk-dev] [PATCH 7/8] net/mlx5: add VXLAN encap support to switch flow rules Adrien Mazarguil
2018-08-31 9:57 ` [dpdk-dev] [PATCH 8/8] net/mlx5: add VXLAN decap " Adrien Mazarguil
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180831092038.23051-2-adrien.mazarguil@6wind.com \
--to=adrien.mazarguil@6wind.com \
--cc=dev@dpdk.org \
--cc=shahafs@mellanox.com \
--cc=viacheslavo@mellanox.com \
--cc=yskoh@mellanox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).