[2/4] net/failsafe: change back-reference from sub-device
Checks
Commit Message
In multiprocess context, the sub-device structure is shared
between processes. The reference to the failsafe device was
a per process pointer. It's changed to port id which is the
same for all processes.
Signed-off-by: Raslan Darawsheh <rasland@mellanox.com>
Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
drivers/net/failsafe/failsafe_eal.c | 2 +-
drivers/net/failsafe/failsafe_ether.c | 15 ++++++++-------
drivers/net/failsafe/failsafe_intr.c | 10 +++++-----
drivers/net/failsafe/failsafe_private.h | 11 ++++++++---
4 files changed, 22 insertions(+), 16 deletions(-)
Comments
On Thu, 28 Feb 2019 15:49:26 +0000
Raslan Darawsheh <rasland@mellanox.com> wrote:
> +/* sdev: (struct sub_device *) */
> +#define FSDEV_FROM_SUBDEV(sdev) \
> + (&rte_eth_devices[sdev->fs_port_id])
If at all possible, inline functions are preferable to macros because
inline functions don't allow side effects and keep the type checking.
This could just be an inline function without any impact to code
generation.
@@ -114,7 +114,7 @@ fs_bus_init(struct rte_eth_dev *dev)
}
ETH(sdev) = &rte_eth_devices[pid];
SUB_ID(sdev) = i;
- sdev->fs_dev = dev;
+ sdev->fs_port_id = dev->data->port_id;
sdev->dev = ETH(sdev)->device;
sdev->state = DEV_PROBED;
}
@@ -298,7 +298,7 @@ fs_dev_remove(struct sub_device *sdev)
break;
}
sdev->remove = 0;
- failsafe_hotplug_alarm_install(sdev->fs_dev);
+ failsafe_hotplug_alarm_install(FSDEV_FROM_SUBDEV(sdev));
}
static void
@@ -318,8 +318,9 @@ fs_dev_stats_save(struct sub_device *sdev)
WARN("Using latest snapshot taken before %"PRIu64" seconds.\n",
(rte_rdtsc() - timestamp) / rte_get_tsc_hz());
}
- failsafe_stats_increment(&PRIV(sdev->fs_dev)->stats_accumulator,
- err ? &sdev->stats_snapshot.stats : &stats);
+ failsafe_stats_increment
+ (&PRIV(FSDEV_FROM_SUBDEV(sdev))->stats_accumulator,
+ err ? &sdev->stats_snapshot.stats : &stats);
memset(&sdev->stats_snapshot, 0, sizeof(sdev->stats_snapshot));
}
@@ -566,17 +567,17 @@ failsafe_eth_rmv_event_callback(uint16_t port_id __rte_unused,
{
struct sub_device *sdev = cb_arg;
- fs_lock(sdev->fs_dev, 0);
+ fs_lock(FSDEV_FROM_SUBDEV(sdev), 0);
/* Switch as soon as possible tx_dev. */
- fs_switch_dev(sdev->fs_dev, sdev);
+ fs_switch_dev(FSDEV_FROM_SUBDEV(sdev), sdev);
/* Use safe bursts in any case. */
- failsafe_set_burst_fn(sdev->fs_dev, 1);
+ failsafe_set_burst_fn(FSDEV_FROM_SUBDEV(sdev), 1);
/*
* Async removal, the sub-PMD will try to unregister
* the callback at the source of the current thread context.
*/
sdev->remove = 1;
- fs_unlock(sdev->fs_dev, 0);
+ fs_unlock(FSDEV_FROM_SUBDEV(sdev), 0);
return 0;
}
@@ -274,14 +274,14 @@ failsafe_eth_rx_intr_ctl_subdevice(struct sub_device *sdev, int op)
int rc;
int ret = 0;
+ fsdev = FSDEV_FROM_SUBDEV(sdev);
if (sdev == NULL || (ETH(sdev) == NULL) ||
- sdev->fs_dev == NULL || (PRIV(sdev->fs_dev) == NULL)) {
+ fsdev == NULL || (PRIV(fsdev) == NULL)) {
ERROR("Called with invalid arguments");
return -EINVAL;
}
dev = ETH(sdev);
- fsdev = sdev->fs_dev;
- epfd = PRIV(sdev->fs_dev)->rxp.efd;
+ epfd = PRIV(fsdev)->rxp.efd;
pid = PORT_ID(sdev);
if (epfd <= 0) {
@@ -330,7 +330,7 @@ int failsafe_rx_intr_install_subdevice(struct sub_device *sdev)
const struct rte_intr_conf *const intr_conf =
Ð(sdev)->data->dev_conf.intr_conf;
- fsdev = sdev->fs_dev;
+ fsdev = FSDEV_FROM_SUBDEV(sdev);
rxq = (struct rxq **)fsdev->data->rx_queues;
if (intr_conf->rxq == 0)
return 0;
@@ -368,7 +368,7 @@ void failsafe_rx_intr_uninstall_subdevice(struct sub_device *sdev)
struct rte_eth_dev *fsdev;
struct rxq *fsrxq;
- fsdev = sdev->fs_dev;
+ fsdev = FSDEV_FROM_SUBDEV(sdev);
for (qid = 0; qid < ETH(sdev)->data->nb_rx_queues; qid++) {
if (qid < fsdev->data->nb_rx_queues) {
fsrxq = fsdev->data->rx_queues[qid];
@@ -117,7 +117,7 @@ struct sub_device {
/* Others are retrieved through a file descriptor */
char *fd_str;
/* fail-safe device backreference */
- struct rte_eth_dev *fs_dev;
+ uint16_t fs_port_id; /* shared between processes*/
/* flag calling for recollection */
volatile unsigned int remove:1;
/* flow isolation state */
@@ -251,6 +251,9 @@ extern int failsafe_mac_from_arg;
/* dev: (struct rte_eth_dev *) fail-safe device */
#define PRIV(dev) \
((struct fs_priv *)(dev)->data->dev_private)
+/* sdev: (struct sub_device *) */
+#define FSDEV_FROM_SUBDEV(sdev) \
+ (&rte_eth_devices[sdev->fs_port_id])
/* sdev: (struct sub_device *) */
#define ETH(sdev) \
@@ -324,7 +327,8 @@ extern int failsafe_mac_from_arg;
*/
#define FS_ATOMIC_RX(s, i) \
rte_atomic64_read( \
- &((struct rxq *)((s)->fs_dev->data->rx_queues[i]))->refcnt[(s)->sid] \
+ &((struct rxq *) \
+ (FSDEV_FROM_SUBDEV(s)->data->rx_queues[i]))->refcnt[(s)->sid] \
)
/**
* s: (struct sub_device *)
@@ -332,7 +336,8 @@ extern int failsafe_mac_from_arg;
*/
#define FS_ATOMIC_TX(s, i) \
rte_atomic64_read( \
- &((struct txq *)((s)->fs_dev->data->tx_queues[i]))->refcnt[(s)->sid] \
+ &((struct txq *) \
+ (FSDEV_FROM_SUBDEV(s)->data->tx_queues[i]))->refcnt[(s)->sid] \
)
#ifdef RTE_EXEC_ENV_BSDAPP