[ofw] [PATCH 10/?] Don't allocate memory just to make a copy...

Fab Tillier ftillier at microsoft.com
Mon Jun 18 19:38:08 PDT 2012


During the query interface IRP handling, the HCA driver:
1. allocates a CI interface
2. populates it
3. copies it into the provided interface struct
4. frees it

This patch simplifies this by simply populating the interface passed in directly, without allocating or freeing an intermediate buffer.

Signed-off-by: Fab Tillier <ftillier at microsoft.com>

Index: hw/mlx4/kernel/hca/drv.c
===================================================================
--- hw/mlx4/kernel/hca/drv.c	(revision 3414)
+++ hw/mlx4/kernel/hca/drv.c	(working copy)
@@ -66,24 +66,13 @@
 	return 0;
 }
 
-static ci_interface_t*
-__alloc_hca_ifc(
-	IN				PFDO_DEVICE_DATA const		p_fdo )
+static void
+__setup_hca_ifc(
+    IN              PFDO_DEVICE_DATA const      p_fdo,
+    OUT             ci_interface_t*             pIfc )
 {
-	ci_interface_t	*pIfc;
-
 	HCA_ENTER( HCA_DBG_PNP );
 
-	pIfc =
-		(ci_interface_t*)ExAllocatePoolWithTag( NonPagedPool, sizeof(ci_interface_t), MT_TAG_KERNEL );
-	if( !pIfc )
-	{
-		HCA_PRINT( TRACE_LEVEL_ERROR,HCA_DBG_PNP, 
-			("Failed to allocate ci_interface_t (%d bytes).\n",
-			sizeof(ci_interface_t)));
-		return NULL;
-	}
-
 	setup_ci_interface( p_fdo->hca.guid, pIfc );
 
 	pIfc->p_hca_obj = &p_fdo->hca;
@@ -92,21 +81,18 @@
 	pIfc->dev_revision = (uint16_t)p_fdo->hca.hw_ver;
 
 	HCA_EXIT( HCA_DBG_PNP );
-	return pIfc;
 }
 
 static void
 __unmap_hca_memory(
 	IN				PFDO_DEVICE_DATA const p_fdo )
 {
-	struct pci_dev *pdev;
+    struct pci_dev *pdev = p_fdo->bus_ib_ifc.pdev;
 	int				i;
 
 	HCA_ENTER( HCA_DBG_PNP );
 
 	if (p_fdo->bus_ib_ifc_taken) {
-		pdev = p_fdo->bus_ib_ifc.pdev;
-
 		for( i = 0; i < HCA_BAR_TYPE_MAX; i++ ) {
 			if (pdev->bar[i].virt) {
 				MmUnmapIoSpace( pdev->bar[i].virt, pdev->bar[i].size );
@@ -118,6 +104,7 @@
 	HCA_EXIT( HCA_DBG_PNP );
 }
 
+
 /* release the resources, allocated in hca_start */
 static void
 __hca_release_resources(
@@ -296,6 +283,7 @@
 	return STATUS_SUCCESS;
 }
 
+
 NTSTATUS
 EvtDeviceD0Exit(
 	IN WDFDEVICE  Device,
@@ -356,7 +344,6 @@
 	NTSTATUS status;
 	PFDO_DEVICE_DATA p_fdo  = FdoGetData(Device);
 	BUS_INTERFACE_STANDARD	bus_pci_ifc;
-	ci_interface_t *p_hca_ifc;
 	RDMA_INTERFACE_VERBS rdma_ifc, *p_ifc = &rdma_ifc;
 	WDF_QUERY_INTERFACE_CONFIG qiConfig;
 	RDMA_INTERFACE_VERBS_EX rdma_ifc_ex;
@@ -427,11 +414,6 @@
 	mlnx_hca_insert( &p_fdo->hca );
 
 	/* Allocate and populate our HCA interface structure. */
-	p_hca_ifc = __alloc_hca_ifc( p_fdo );
-	if( !p_hca_ifc ) {
-		HCA_PRINT( TRACE_LEVEL_ERROR  ,HCA_DBG_PNP  ,("__alloc_hca_ifc failed.\n"));
-		return STATUS_NO_MEMORY;
-	}
 
 	/* fill interface fields */
 	p_ifc->InterfaceHeader.Size = sizeof(RDMA_INTERFACE_VERBS);
@@ -439,8 +421,7 @@
 	p_ifc->InterfaceHeader.Context = p_fdo->p_dev_obj;
 	p_ifc->InterfaceHeader.InterfaceReference = __ref_ifc;
 	p_ifc->InterfaceHeader.InterfaceDereference = __deref_ifc;
-	p_ifc->Verbs = *p_hca_ifc;
-	ExFreePool( p_hca_ifc );
+    __setup_hca_ifc( p_fdo, &p_ifc->Verbs );
 
 	/* create an upper interface */
 	WDF_QUERY_INTERFACE_CONFIG_INIT( &qiConfig, (PINTERFACE)p_ifc,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 10.alloc_ifc.patch
Type: application/octet-stream
Size: 2806 bytes
Desc: 10.alloc_ifc.patch
URL: <http://lists.openfabrics.org/pipermail/ofw/attachments/20120619/60e334de/attachment.obj>


More information about the ofw mailing list