[PATCH v2] drivers/bus: set device NUMA node to unknown by default
Olivier Matz
olivier.matz at 6wind.com
Wed Oct 5 11:04:41 CEST 2022
Hi David,
On Wed, Oct 05, 2022 at 10:52:49AM +0200, David Marchand wrote:
> On Tue, Oct 4, 2022 at 4:59 PM Olivier Matz <olivier.matz at 6wind.com> wrote:
> >
> > The dev->device.numa_node field is set by each bus driver for
> > every device it manages to indicate on which NUMA node this device lies.
> >
> > When this information is unknown, the assigned value is not consistent
> > across the bus drivers.
> >
> > Set the default value to SOCKET_ID_ANY (-1) by all bus drivers
> > when the NUMA information is unavailable. This change impacts
> > rte_eth_dev_socket_id() in the same manner.
> >
> > Signed-off-by: Olivier Matz <olivier.matz at 6wind.com>
> > ---
> >
> > v2
> > * use SOCKET_ID_ANY instead of -1 in drivers/dma/idxd (David)
> > * document the behavior change of rte_eth_dev_socket_id()
> > * fix few examples where rte_eth_dev_socket_id() was expected to
> > return 0 on unknown socket
>
> Cc: ethdev maintainers.
>
> [snip]
>
> > diff --git a/doc/guides/rel_notes/release_22_11.rst b/doc/guides/rel_notes/release_22_11.rst
> > index 53fe21453c..d52f823694 100644
> > --- a/doc/guides/rel_notes/release_22_11.rst
> > +++ b/doc/guides/rel_notes/release_22_11.rst
> > @@ -317,6 +317,12 @@ ABI Changes
> > * eventdev: Added ``weight`` and ``affinity`` fields
> > to ``rte_event_queue_conf`` structure.
> >
> > +* bus: Changed the device numa node to -1 when NUMA information is unavailable.
> > + The ``dev->device.numa_node`` field is set by each bus driver for
> > + every device it manages to indicate on which NUMA node this device lies.
> > + When this information is unknown, the assigned value was not consistent
> > + across the bus drivers. This similarly impacts ``rte_eth_dev_socket_id()``.
> > +
> >
> > Known Issues
> > ------------
>
> [snip]
>
> > diff --git a/lib/ethdev/rte_ethdev.h b/lib/ethdev/rte_ethdev.h
> > index a21f58b9cd..dd8d25d6d4 100644
> > --- a/lib/ethdev/rte_ethdev.h
> > +++ b/lib/ethdev/rte_ethdev.h
> > @@ -2445,8 +2445,8 @@ int rte_eth_hairpin_unbind(uint16_t tx_port, uint16_t rx_port);
> > * The port identifier of the Ethernet device
> > * @return
> > * The NUMA socket ID to which the Ethernet device is connected or
> > - * a default of zero if the socket could not be determined.
> > - * -1 is returned is the port_id value is out of range.
> > + * a default of -1 (SOCKET_ID_ANY) if the socket could not be determined.
> > + * -1 is also returned if the port_id is invalid.
> > */
> > int rte_eth_dev_socket_id(uint16_t port_id);
>
> It would be better to distinguish the two cases, using rte_errno.
> Something like:
>
> diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c
> index 2821770e2d..1baf302804 100644
> --- a/lib/ethdev/rte_ethdev.c
> +++ b/lib/ethdev/rte_ethdev.c
> @@ -562,8 +562,16 @@ rte_eth_dev_owner_get(const uint16_t port_id,
> struct rte_eth_dev_owner *owner)
> int
> rte_eth_dev_socket_id(uint16_t port_id)
> {
> - RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -1);
> - return rte_eth_devices[port_id].data->numa_node;
> + int socket_id = SOCKET_ID_ANY;
> +
> + if (!rte_eth_dev_is_valid_port(port_id))
> + rte_errno = EINVAL;
> + } else {
> + socket_id = rte_eth_devices[port_id].data->numa_node;
> + if (socket_id == SOCKET_ID_ANY)
> + rte_errno = 0;
> + }
> + return socket_id;
> }
>
> void *
> diff --git a/lib/ethdev/rte_ethdev.h b/lib/ethdev/rte_ethdev.h
> index dd8d25d6d4..03456b2dbb 100644
> --- a/lib/ethdev/rte_ethdev.h
> +++ b/lib/ethdev/rte_ethdev.h
> @@ -2444,9 +2444,11 @@ int rte_eth_hairpin_unbind(uint16_t tx_port,
> uint16_t rx_port);
> * @param port_id
> * The port identifier of the Ethernet device
> * @return
> - * The NUMA socket ID to which the Ethernet device is connected or
> - * a default of -1 (SOCKET_ID_ANY) if the socket could not be determined.
> - * -1 is also returned if the port_id is invalid.
> + * - The NUMA socket ID which the Ethernet device is connected to.
> + * - -1 (which translates to SOCKET_ID_ANY) if the socket could not be
> + * determined. rte_errno is then set to:
> + * - EINVAL is the port_id is invalid,
> + * - 0 is the socket could not be determined,
> */
> int rte_eth_dev_socket_id(uint16_t port_id);
>
> WDYT?
As discussed off-list, it is indeed better.
Thanks for the review
Olivier
More information about the dev
mailing list