[v4,1/9] rawdev: allow devices to skip extra memory allocation
Checks
Commit Message
Some device drivers want to allocate their own private memory, and should
be allowed to do so. Therefore skip memory allocation and associated error
checks if zero-length private memory is requested.
While adjusting the code for new indent level, fix incorrect error
message.
Cc: Shreyansh Jain <shreyansh.jain@nxp.com>
Cc: Hemant Agrawal <hemant.agrawal@nxp.com>
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
lib/librte_rawdev/rte_rawdev.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
Comments
Acked-by: Hemant Agrawal <hemant.agrawal@nxp.com
> -----Original Message-----
> From: Bruce Richardson <bruce.richardson@intel.com>
> Sent: Monday, July 1, 2019 9:26 PM
> To: dev@dpdk.org
> Cc: thomas@monjalon.net; jerinj@marvell.com; jiayu.hu@intel.com; Bruce
> Richardson <bruce.richardson@intel.com>; Shreyansh Jain
> <shreyansh.jain@nxp.com>; Hemant Agrawal <hemant.agrawal@nxp.com>
> Subject: [PATCH v4 1/9] rawdev: allow devices to skip extra memory
> allocation
>
> Some device drivers want to allocate their own private memory, and
> should
> be allowed to do so. Therefore skip memory allocation and associated
> error
> checks if zero-length private memory is requested.
Agree with this - rawdev was intended for flexibility and this (allowing them their own memory) is definitely better way ahead. Thanks for proposing.
But, I think the kind of caveat should also be added to the header declaring this function:
Probably something like this:
--->8--- lib/librte_rawdev/rte_rawdev_pmd.h ---
/**
* Allocates a new rawdev slot for an raw device and returns the pointer
* to that slot for the driver to use.
*
* @param name
* Unique identifier name for each device
* @param dev_private_size
* Private data allocated within rte_rawdev object.
* <b>Set to 0 to disable internal allocation and allow for self-allocation</b>
* @param socket_id
* Socket to allocate resources on.
* @return
* - Slot in the rte_dev_devices array for a new device;
*/
struct rte_rawdev *
rte_rawdev_pmd_allocate(const char *name, size_t dev_private_size,
int socket_id);
--->8---
>
> While adjusting the code for new indent level, fix incorrect error
> message.
>
> Cc: Shreyansh Jain <shreyansh.jain@nxp.com>
> Cc: Hemant Agrawal <hemant.agrawal@nxp.com>
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> ---
If you can update the header, please use my ACK in next version.
Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
[...]
On Tue, Jul 02, 2019 at 11:43:58AM +0000, Shreyansh Jain wrote:
> > -----Original Message-----
> > From: Bruce Richardson <bruce.richardson@intel.com>
> > Sent: Monday, July 1, 2019 9:26 PM
> > To: dev@dpdk.org
> > Cc: thomas@monjalon.net; jerinj@marvell.com; jiayu.hu@intel.com; Bruce
> > Richardson <bruce.richardson@intel.com>; Shreyansh Jain
> > <shreyansh.jain@nxp.com>; Hemant Agrawal <hemant.agrawal@nxp.com>
> > Subject: [PATCH v4 1/9] rawdev: allow devices to skip extra memory
> > allocation
> >
> > Some device drivers want to allocate their own private memory, and
> > should
> > be allowed to do so. Therefore skip memory allocation and associated
> > error
> > checks if zero-length private memory is requested.
>
> Agree with this - rawdev was intended for flexibility and this (allowing them their own memory) is definitely better way ahead. Thanks for proposing.
> But, I think the kind of caveat should also be added to the header declaring this function:
>
> Probably something like this:
>
> --->8--- lib/librte_rawdev/rte_rawdev_pmd.h ---
> /**
> * Allocates a new rawdev slot for an raw device and returns the pointer
> * to that slot for the driver to use.
> *
> * @param name
> * Unique identifier name for each device
> * @param dev_private_size
> * Private data allocated within rte_rawdev object.
> * <b>Set to 0 to disable internal allocation and allow for self-allocation</b>
> * @param socket_id
> * Socket to allocate resources on.
> * @return
> * - Slot in the rte_dev_devices array for a new device;
> */
> struct rte_rawdev *
> rte_rawdev_pmd_allocate(const char *name, size_t dev_private_size,
> int socket_id);
> --->8---
>
> >
> > While adjusting the code for new indent level, fix incorrect error
> > message.
> >
> > Cc: Shreyansh Jain <shreyansh.jain@nxp.com>
> > Cc: Hemant Agrawal <hemant.agrawal@nxp.com>
> > Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> > ---
>
> If you can update the header, please use my ACK in next version.
>
> Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
>
Thanks Shreyansh, will do.
/Bruce
@@ -496,16 +496,17 @@ rte_rawdev_pmd_allocate(const char *name, size_t dev_priv_size, int socket_id)
rawdev = &rte_rawdevs[dev_id];
- rawdev->dev_private = rte_zmalloc_socket("rawdev private",
+ if (dev_priv_size > 0) {
+ rawdev->dev_private = rte_zmalloc_socket("rawdev private",
dev_priv_size,
RTE_CACHE_LINE_SIZE,
socket_id);
- if (!rawdev->dev_private) {
- RTE_RDEV_ERR("Unable to allocate memory to Skeleton dev");
- return NULL;
+ if (!rawdev->dev_private) {
+ RTE_RDEV_ERR("Unable to allocate memory for rawdev");
+ return NULL;
+ }
}
-
rawdev->dev_id = dev_id;
rawdev->socket_id = socket_id;
rawdev->started = 0;