[v4,1/9] rawdev: allow devices to skip extra memory allocation

Message ID 20190701155600.43695-2-bruce.richardson@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series raw/ioat: driver for Intel QuickData Technology |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Performance-Testing fail build patch failure
ci/Intel-compilation fail apply issues

Commit Message

Bruce Richardson July 1, 2019, 3:55 p.m. UTC
  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

Hemant Agrawal July 2, 2019, 11:34 a.m. UTC | #1
Acked-by: Hemant Agrawal <hemant.agrawal@nxp.com
  
Shreyansh Jain July 2, 2019, 11:43 a.m. UTC | #2
> -----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>

[...]
  
Bruce Richardson July 2, 2019, 12:41 p.m. UTC | #3
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
  

Patch

diff --git a/lib/librte_rawdev/rte_rawdev.c b/lib/librte_rawdev/rte_rawdev.c
index 15de2d413..b6f1e1c77 100644
--- a/lib/librte_rawdev/rte_rawdev.c
+++ b/lib/librte_rawdev/rte_rawdev.c
@@ -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;