[ofa-general] [PATCH 2/3] opensm: use malloc instead of cl_qlock_pool in osm_mad_pool.c
Sasha Khapyorsky
sashak at voltaire.com
Thu Jan 3 01:41:54 PST 2008
Use regular malloc/free instead of cl_qlock_pool allocator in
osm_mad_pool.c. malloc() is more than twice faster than cl_qlock_pool
analogs and using this doesn't require any locking.
Signed-off-by: Sasha Khapyorsky <sashak at voltaire.com>
---
opensm/include/opensm/osm_mad_pool.h | 7 +---
opensm/include/opensm/osm_madw.h | 80 +++-------------------------------
opensm/opensm/osm_mad_pool.c | 56 ++++--------------------
opensm/opensm/osm_vl15intf.c | 6 +-
4 files changed, 20 insertions(+), 129 deletions(-)
diff --git a/opensm/include/opensm/osm_mad_pool.h b/opensm/include/opensm/osm_mad_pool.h
index 9ec0a7a..b8421b9 100644
--- a/opensm/include/opensm/osm_mad_pool.h
+++ b/opensm/include/opensm/osm_mad_pool.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2004, 2005 Voltaire, Inc. All rights reserved.
+ * Copyright (c) 2004-2007 Voltaire, Inc. All rights reserved.
* Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
* Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
*
@@ -50,7 +50,6 @@
#include <iba/ib_types.h>
#include <complib/cl_atomic.h>
-#include <complib/cl_qlockpool.h>
#include <opensm/osm_base.h>
#include <vendor/osm_vendor.h>
#include <opensm/osm_madw.h>
@@ -97,7 +96,6 @@ BEGIN_C_DECLS
*/
typedef struct _osm_mad_pool {
osm_log_t *p_log;
- cl_qlock_pool_t madw_pool;
atomic32_t mads_out;
} osm_mad_pool_t;
/*
@@ -105,9 +103,6 @@ typedef struct _osm_mad_pool {
* p_log
* Pointer to the log object.
*
-* lock
-* Spinlock guarding the pool.
-*
* mads_out
* Running total of the number of MADs outstanding.
*
diff --git a/opensm/include/opensm/osm_madw.h b/opensm/include/opensm/osm_madw.h
index d4bcbc1..31707ad 100644
--- a/opensm/include/opensm/osm_madw.h
+++ b/opensm/include/opensm/osm_madw.h
@@ -409,7 +409,7 @@ typedef struct _osm_mad_addr {
* SYNOPSIS
*/
typedef struct _osm_madw {
- cl_pool_item_t pool_item;
+ cl_list_item_t list_item;
osm_bind_handle_t h_bind;
osm_vend_wrap_t vend_wrap;
osm_mad_addr_t mad_addr;
@@ -423,8 +423,8 @@ typedef struct _osm_madw {
} osm_madw_t;
/*
* FIELDS
-* pool_item
-* List linkage for pools and lists. MUST BE FIRST MEMBER!
+* list_item
+* List linkage for lists. MUST BE FIRST MEMBER!
*
* h_bind
* Bind handle for the port on which this MAD will be sent
@@ -467,72 +467,6 @@ typedef struct _osm_madw {
* SEE ALSO
*********/
-/****f* OpenSM: MAD Wrapper/osm_madw_construct
-* NAME
-* osm_madw_construct
-*
-* DESCRIPTION
-* This function constructs a MAD Wrapper object.
-*
-* SYNOPSIS
-*/
-static inline void osm_madw_construct(IN osm_madw_t * const p_madw)
-{
- /*
- Don't touch the pool_item since that is an opaque object.
- Clear all other objects in the mad wrapper.
- */
- memset(((uint8_t *) p_madw) + sizeof(cl_pool_item_t), 0,
- sizeof(*p_madw) - sizeof(cl_pool_item_t));
-}
-
-/*
-* PARAMETERS
-* p_madw
-* [in] Pointer to a MAD Wrapper object to construct.
-*
-* RETURN VALUE
-* This function does not return a value.
-*
-* NOTES
-* Allows calling osm_madw_init, osm_madw_destroy
-*
-* Calling osm_madw_construct is a prerequisite to calling any other
-* method except osm_madw_init.
-*
-* SEE ALSO
-* MAD Wrapper object, osm_madw_init, osm_madw_destroy
-*********/
-
-/****f* OpenSM: MAD Wrapper/osm_madw_destroy
-* NAME
-* osm_madw_destroy
-*
-* DESCRIPTION
-* The osm_madw_destroy function destroys a node, releasing
-* all resources.
-*
-* SYNOPSIS
-*/
-void osm_madw_destroy(IN osm_madw_t * const p_madw);
-/*
-* PARAMETERS
-* p_madw
-* [in] Pointer to a MAD Wrapper object to destroy.
-*
-* RETURN VALUE
-* This function does not return a value.
-*
-* NOTES
-* Performs any necessary cleanup of the specified MAD Wrapper object.
-* Further operations should not be attempted on the destroyed object.
-* This function should only be called after a call to osm_madw_construct or
-* osm_madw_init.
-*
-* SEE ALSO
-* MAD Wrapper object, osm_madw_construct, osm_madw_init
-*********/
-
/****f* OpenSM: MAD Wrapper/osm_madw_init
* NAME
* osm_madw_init
@@ -548,7 +482,7 @@ osm_madw_init(IN osm_madw_t * const p_madw,
IN const uint32_t mad_size,
IN const osm_mad_addr_t * const p_mad_addr)
{
- osm_madw_construct(p_madw);
+ memset(p_madw, 0, sizeof(*p_madw));
p_madw->h_bind = h_bind;
p_madw->fail_msg = CL_DISP_MSGID_NONE;
p_madw->mad_size = mad_size;
@@ -602,7 +536,7 @@ static inline ib_smp_t *osm_madw_get_smp_ptr(IN const osm_madw_t * const p_madw)
* NOTES
*
* SEE ALSO
-* MAD Wrapper object, osm_madw_construct, osm_madw_destroy
+* MAD Wrapper object
*********/
/****f* OpenSM: MAD Wrapper/osm_madw_get_sa_mad_ptr
@@ -631,7 +565,7 @@ static inline ib_sa_mad_t *osm_madw_get_sa_mad_ptr(IN const osm_madw_t *
* NOTES
*
* SEE ALSO
-* MAD Wrapper object, osm_madw_construct, osm_madw_destroy
+* MAD Wrapper object
*********/
/****f* OpenSM: MAD Wrapper/osm_madw_get_perfmgt_mad_ptr
@@ -657,7 +591,7 @@ static inline ib_perfmgt_mad_t *osm_madw_get_perfmgt_mad_ptr(IN const osm_madw_t
* NOTES
*
* SEE ALSO
-* MAD Wrapper object, osm_madw_construct, osm_madw_destroy
+* MAD Wrapper object
*********/
/****f* OpenSM: MAD Wrapper/osm_madw_get_ni_context_ptr
diff --git a/opensm/opensm/osm_mad_pool.c b/opensm/opensm/osm_mad_pool.c
index c3f3f2a..f9ef54c 100644
--- a/opensm/opensm/osm_mad_pool.c
+++ b/opensm/opensm/osm_mad_pool.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2004-2006 Voltaire, Inc. All rights reserved.
+ * Copyright (c) 2004-2007 Voltaire, Inc. All rights reserved.
* Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
* Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
*
@@ -56,24 +56,6 @@
#include <opensm/osm_log.h>
#include <vendor/osm_vendor_api.h>
-#define OSM_MAD_POOL_MIN_SIZE 256
-#define OSM_MAD_POOL_GROW_SIZE 256
-
-/**********************************************************************
- **********************************************************************/
-cl_status_t
-__osm_mad_pool_ctor(IN void *const p_object,
- IN void *context, OUT cl_pool_item_t ** const pp_pool_item)
-{
- osm_madw_t *p_madw = p_object;
-
- UNUSED_PARAM(context);
- osm_madw_construct(p_madw);
- /* CHECK THIS. DOCS DON'T DESCRIBE THIS OUT PARAM. */
- *pp_pool_item = &p_madw->pool_item;
- return (CL_SUCCESS);
-}
-
/**********************************************************************
**********************************************************************/
void osm_mad_pool_construct(IN osm_mad_pool_t * const p_pool)
@@ -81,7 +63,6 @@ void osm_mad_pool_construct(IN osm_mad_pool_t * const p_pool)
CL_ASSERT(p_pool);
memset(p_pool, 0, sizeof(*p_pool));
- cl_qlock_pool_construct(&p_pool->madw_pool);
}
/**********************************************************************
@@ -89,9 +70,6 @@ void osm_mad_pool_construct(IN osm_mad_pool_t * const p_pool)
void osm_mad_pool_destroy(IN osm_mad_pool_t * const p_pool)
{
CL_ASSERT(p_pool);
-
- /* HACK: we still rarely see some mads leaking - so ignore this */
- /* cl_qlock_pool_destroy( &p_pool->madw_pool ); */
}
/**********************************************************************
@@ -99,29 +77,12 @@ void osm_mad_pool_destroy(IN osm_mad_pool_t * const p_pool)
ib_api_status_t
osm_mad_pool_init(IN osm_mad_pool_t * const p_pool, IN osm_log_t * const p_log)
{
- ib_api_status_t status;
-
OSM_LOG_ENTER(p_log, osm_mad_pool_init);
p_pool->p_log = p_log;
- status = cl_qlock_pool_init(&p_pool->madw_pool,
- OSM_MAD_POOL_MIN_SIZE,
- 0,
- OSM_MAD_POOL_GROW_SIZE,
- sizeof(osm_madw_t),
- __osm_mad_pool_ctor, NULL, p_pool);
- if (status != IB_SUCCESS) {
- osm_log(p_log, OSM_LOG_ERROR,
- "osm_mad_pool_init: ERR 0702: "
- "Grow pool initialization failed (%s)\n",
- ib_get_err_str(status));
- goto Exit;
- }
-
- Exit:
OSM_LOG_EXIT(p_log);
- return (status);
+ return IB_SUCCESS;
}
/**********************************************************************
@@ -142,7 +103,7 @@ osm_madw_t *osm_mad_pool_get(IN osm_mad_pool_t * const p_pool,
/*
First, acquire a mad wrapper from the mad wrapper pool.
*/
- p_madw = (osm_madw_t *) cl_qlock_pool_get(&p_pool->madw_pool);
+ p_madw = malloc(sizeof(*p_madw));
if (p_madw == NULL) {
osm_log(p_pool->p_log, OSM_LOG_ERROR,
"osm_mad_pool_get: ERR 0703: "
@@ -162,8 +123,7 @@ osm_madw_t *osm_mad_pool_get(IN osm_mad_pool_t * const p_pool,
"Unable to acquire wire MAD\n");
/* Don't leak wrappers! */
- cl_qlock_pool_put(&p_pool->madw_pool,
- (cl_pool_item_t *) p_madw);
+ free(p_madw);
p_madw = NULL;
goto Exit;
}
@@ -202,7 +162,7 @@ osm_madw_t *osm_mad_pool_get_wrapper(IN osm_mad_pool_t * const p_pool,
/*
First, acquire a mad wrapper from the mad wrapper pool.
*/
- p_madw = (osm_madw_t *) cl_qlock_pool_get(&p_pool->madw_pool);
+ p_madw = malloc(sizeof(*p_madw));
if (p_madw == NULL) {
osm_log(p_pool->p_log, OSM_LOG_ERROR,
"osm_mad_pool_get_wrapper: ERR 0705: "
@@ -234,7 +194,9 @@ osm_madw_t *osm_mad_pool_get_wrapper_raw(IN osm_mad_pool_t * const p_pool)
OSM_LOG_ENTER(p_pool->p_log, osm_mad_pool_get_wrapper_raw);
- p_madw = (osm_madw_t *) cl_qlock_pool_get(&p_pool->madw_pool);
+ p_madw = malloc(sizeof(*p_madw));
+ if (!p_madw)
+ return NULL;
osm_log(p_pool->p_log, OSM_LOG_DEBUG,
"osm_mad_pool_get_wrapper_raw: "
@@ -270,7 +232,7 @@ osm_mad_pool_put(IN osm_mad_pool_t * const p_pool, IN osm_madw_t * const p_madw)
/*
Return the mad wrapper to the wrapper pool
*/
- cl_qlock_pool_put(&p_pool->madw_pool, (cl_pool_item_t *) p_madw);
+ free(p_madw);
cl_atomic_dec(&p_pool->mads_out);
OSM_LOG_EXIT(p_pool->p_log);
diff --git a/opensm/opensm/osm_vl15intf.c b/opensm/opensm/osm_vl15intf.c
index 74e749f..5d10ed6 100644
--- a/opensm/opensm/osm_vl15intf.c
+++ b/opensm/opensm/osm_vl15intf.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2004-2006 Voltaire, Inc. All rights reserved.
+ * Copyright (c) 2004-2007 Voltaire, Inc. All rights reserved.
* Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
* Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
*
@@ -340,10 +340,10 @@ void osm_vl15_post(IN osm_vl15_t * const p_vl, IN osm_madw_t * const p_madw)
*/
cl_spinlock_acquire(&p_vl->lock);
if (p_madw->resp_expected == TRUE) {
- cl_qlist_insert_tail(&p_vl->rfifo, (cl_list_item_t *) p_madw);
+ cl_qlist_insert_tail(&p_vl->rfifo, &p_madw->list_item);
cl_atomic_inc(&p_vl->p_stats->qp0_mads_outstanding);
} else
- cl_qlist_insert_tail(&p_vl->ufifo, (cl_list_item_t *) p_madw);
+ cl_qlist_insert_tail(&p_vl->ufifo, &p_madw->list_item);
cl_spinlock_release(&p_vl->lock);
if (osm_log_is_active(p_vl->p_log, OSM_LOG_DEBUG))
--
1.5.3.4.206.g58ba4
More information about the general
mailing list