void osmv_txn_abort_rmpp_txns(osm_bind_handle_t h_bind) { osmv_bind_obj_t *p_bo = (osmv_bind_obj_t *) h_bind; cl_map_item_t *p_item; cl_map_obj_t *p_obj; osmv_txn_ctx_t *p_txn; osmv_rmpp_send_ctx_t *p_send_ctx; cl_qmap_t *p_map = p_bo->txn_mgr.p_txn_map; OSM_LOG_ENTER(p_bo->p_vendor->p_log); while (FALSE == cl_is_qmap_empty(p_map)) { p_item = cl_qmap_head(p_map); p_obj = PARENT_STRUCT(p_item, cl_map_obj_t, item); p_txn = (osmv_txn_ctx_t *) cl_qmap_obj(p_obj); p_send_ctx = osmv_txn_get_rmpp_send_ctx(p_txn); if (NULL != p_send_ctx) { p_send_ctx->status = IB_INTERRUPTED; /* Wake up the sender thread to let it break out */ cl_event_signal(&p_send_ctx->event); } cl_qmap_remove_item(p_map, p_item); } OSM_LOG_EXIT(p_bo->p_vendor->p_log); }
void cl_event_wheel_unreg(IN cl_event_wheel_t * const p_event_wheel, IN uint64_t key) { cl_event_wheel_reg_info_t *p_event; cl_map_item_t *p_map_item; CL_DBG("cl_event_wheel_unreg: " "Removing key:0x%" PRIx64 "\n", key); cl_spinlock_acquire(&p_event_wheel->lock); p_map_item = cl_qmap_get(&p_event_wheel->events_map, key); if (p_map_item != cl_qmap_end(&p_event_wheel->events_map)) { /* we found such an item. */ p_event = PARENT_STRUCT(p_map_item, cl_event_wheel_reg_info_t, map_item); /* remove the item from the qlist */ cl_qlist_remove_item(&p_event_wheel->events_wheel, &(p_event->list_item)); /* remove the item from the qmap */ cl_qmap_remove_item(&p_event_wheel->events_map, &(p_event->map_item)); CL_DBG("cl_event_wheel_unreg: Removed key:0x%" PRIx64 "\n", key); /* free the item */ free(p_event); } else { CL_DBG("cl_event_wheel_unreg: did not find key:0x%" PRIx64 "\n", key); } cl_spinlock_release(&p_event_wheel->lock); }
ib_api_status_t __osmv_txnmgr_remove_txn(IN osmv_txn_mgr_t * p_tx_mgr, IN uint64_t key, OUT osmv_txn_ctx_t ** pp_txn) { cl_map_obj_t *p_obj; cl_map_item_t *p_item; OSM_LOG_ENTER(p_tx_mgr->p_log); CL_ASSERT(p_tx_mgr); CL_ASSERT(pp_txn); p_item = cl_qmap_remove(p_tx_mgr->p_txn_map, key); if (p_item == cl_qmap_end(p_tx_mgr->p_txn_map)) { osm_log(p_tx_mgr->p_log, OSM_LOG_ERROR, "__osmv_txnmgr_remove_txn: ERR 6701: " "Could not remove the transaction 0x%llX - " "something is really wrong!\n", key); OSM_LOG_EXIT(p_tx_mgr->p_log); return IB_NOT_FOUND; } p_obj = PARENT_STRUCT(p_item, cl_map_obj_t, item); *pp_txn = cl_qmap_obj(p_obj); free(p_obj); OSM_LOG_EXIT(p_tx_mgr->p_log); return IB_SUCCESS; }
void osm_vendor_unbind(IN osm_bind_handle_t h_bind) { osmv_bind_obj_t *p_bo = (osmv_bind_obj_t *) h_bind; osm_log_t *p_log = p_bo->p_vendor->p_log; cl_list_obj_t *p_obj = NULL; cl_list_item_t *p_item, *p_item_tmp; cl_qlist_t *const p_bh_list = (cl_qlist_t * const)&p_bo->p_vendor->bind_handles; OSM_LOG_ENTER(p_log); /* go over all the items in the list and remove the specific item */ p_item = cl_qlist_head(p_bh_list); while (p_item != cl_qlist_end(p_bh_list)) { p_obj = PARENT_STRUCT(p_item, cl_list_obj_t, list_item); if (cl_qlist_obj(p_obj) == h_bind) { break; } p_item_tmp = cl_qlist_next(p_item); p_item = p_item_tmp; } CL_ASSERT(p_item != cl_qlist_end(p_bh_list)); cl_qlist_remove_item(p_bh_list, p_item); if (p_obj) free(p_obj); if (h_bind != 0) { __osm_vendor_internal_unbind(h_bind); } OSM_LOG_EXIT(p_log); }
/********************************************************************** * Return a MAD by providing it's wrapper object. **********************************************************************/ void osm_vendor_put(IN osm_bind_handle_t h_bind, IN osm_vend_wrap_t * const p_vw) { osm_ts_bind_info_t *p_bind = (osm_ts_bind_info_t *) h_bind; osm_vendor_t *p_vend = p_bind->p_vend; osm_madw_t *p_madw; OSM_LOG_ENTER(p_vend->p_log); CL_ASSERT(p_vw); CL_ASSERT(p_vw->p_mad_buf); if (osm_log_get_level(p_vend->p_log) >= OSM_LOG_DEBUG) { osm_log(p_vend->p_log, OSM_LOG_DEBUG, "osm_vendor_put: " "Retiring MAD %p.\n", p_vw->p_mad_buf); } /* * We moved the removal of the transaction to immediatly after * it was looked up. */ /* free the mad but the wrapper is part of the madw object */ free(p_vw->p_mad_buf); p_vw->p_mad_buf = NULL; p_madw = PARENT_STRUCT(p_vw, osm_madw_t, vend_wrap); p_madw->p_mad = NULL; OSM_LOG_EXIT(p_vend->p_log); }
// reaper callback static void ReapTrapReference(LIST_ITEM *pItem) { // Reaper uses QListObj, so we must use PARENT_STRUCT TRAP_REFERENCE *pTrapReference = PARENT_STRUCT(pItem, TRAP_REFERENCE, ListItem); TimerDestroy(&pTrapReference->Timer); MemoryDeallocate(pTrapReference); }
static int MemoryTrackerTrackDeallocate( IN void *pMemory ) { MEM_ALLOC_HDR *pHdr; LIST_ITEM *pListItem; int result = 0; if( pMemTracker ) { SpinLockAcquire( &pMemTracker->Lock ); // Removes an item from the allocation tracking list given a pointer // To the user's data and returns the pointer to header referencing the // allocated memory block. pListItem = QListFindFromTail( &pMemTracker->AllocList, NULL, pMemory ); if( pListItem ) { // Get the pointer to the header. pHdr = PARENT_STRUCT( pListItem, MEM_ALLOC_HDR, ListItem ); #ifdef MEM_TRACK_FTR MemoryTrackerCheckOverrun(pHdr); #endif // MEM_TRACK_FTR if (pHdr->displaying) { pHdr->deallocate = TRUE; } else { // Remove the item from the list. MemoryTrackerUnlink(pHdr); } } else { int ii; for (ii=0; ii<unTindex; ii++) { if (unTAddr[ii] == pMemory) { unTAddr[ii] = 0; /* found it */ break; } } if (ii == unTindex) { result = 1; #if defined(VXWORKS) MsgOut( "UNMATCHED FREE %p ra=%p\n", pMemory, __builtin_return_address(0)); #else MsgOut( "BAD FREE %p\n", pMemory); #endif DumpStack(); } } SpinLockRelease( &pMemTracker->Lock ); } return result; }
/* Dump out the complete state of the event wheel */ void __cl_event_wheel_dump(IN cl_event_wheel_t * const p_event_wheel) { cl_list_item_t *p_list_item; cl_map_item_t *p_map_item; cl_event_wheel_reg_info_t *p_event; printf("************** Event Wheel Dump ***********************\n"); printf("Event Wheel List has %u items:\n", cl_qlist_count(&p_event_wheel->events_wheel)); p_list_item = cl_qlist_head(&p_event_wheel->events_wheel); while (p_list_item != cl_qlist_end(&p_event_wheel->events_wheel)) { p_event = PARENT_STRUCT(p_list_item, cl_event_wheel_reg_info_t, list_item); printf("Event key:0x%" PRIx64 " Context:%s NumRegs:%u\n", p_event->key, (char *)p_event->context, p_event->num_regs); /* next */ p_list_item = cl_qlist_next(p_list_item); } printf("Event Map has %u items:\n", cl_qmap_count(&p_event_wheel->events_map)); p_map_item = cl_qmap_head(&p_event_wheel->events_map); while (p_map_item != cl_qmap_end(&p_event_wheel->events_map)) { p_event = PARENT_STRUCT(p_map_item, cl_event_wheel_reg_info_t, map_item); printf("Event key:0x%" PRIx64 " Context:%s NumRegs:%u\n", p_event->key, (char *)p_event->context, p_event->num_regs); /* next */ p_map_item = cl_qmap_next(p_map_item); } }
// // Clean up memory tracking. // static __inline void MemoryTrackStop( void ) { #if defined(MEM_TRACK_ON) LIST_ITEM *pListItem; if( !pMemTracker ) return; if( QListCount( &pMemTracker->AllocList ) ) { // There are still items in the list. Print them out. MemoryDisplayUsage(1, 0, 0); } else { MsgOut( "\n*** Memory tracker stopped, no leaks detected ***\n" ); MsgOut("IbAccess max allocations=%u bytes=%u\n", max_allocations, max_allocated); } // Free all allocated headers. SpinLockAcquire( &pMemTracker->Lock ); while( (pListItem = QListRemoveHead( &pMemTracker->AllocList )) != NULL ) { SpinLockRelease( &pMemTracker->Lock ); MEMORY_DEALLOCATE_PRIV( PARENT_STRUCT( pListItem, MEM_ALLOC_HDR, ListItem ) ); SpinLockAcquire( &pMemTracker->Lock ); } while( (pListItem = QListRemoveHead( &pMemTracker->FreeHrdList )) != NULL ) { SpinLockRelease( &pMemTracker->Lock ); MEMORY_DEALLOCATE_PRIV( PARENT_STRUCT( pListItem, MEM_ALLOC_HDR, ListItem ) ); SpinLockAcquire( &pMemTracker->Lock ); } SpinLockRelease( &pMemTracker->Lock ); DestroyMemTracker(); #endif // MEM_TRACK_ON }
static cl_status_t __event_will_age_before(IN const cl_list_item_t * const p_list_item, IN void *context) { uint64_t aging_time = *((uint64_t *) context); cl_event_wheel_reg_info_t *p_event; p_event = PARENT_STRUCT(p_list_item, cl_event_wheel_reg_info_t, list_item); if (p_event->aging_time < aging_time) return CL_SUCCESS; else return CL_NOT_FOUND; }
ib_api_status_t osm_transaction_mgr_get_madw_for_tid(IN osm_vendor_t * const p_vend, IN ib_mad_t * const p_mad, OUT osm_madw_t ** req_madw_p) { osm_transaction_mgr_t *trans_mgr_p; osm_madw_req_t *osm_madw_req_p; cl_map_item_t *p_map_item; uint64_t key; OSM_LOG_ENTER(p_vend->p_log); trans_mgr_p = (osm_transaction_mgr_t *) p_vend->p_transaction_mgr; *req_madw_p = NULL; osm_log(p_vend->p_log, OSM_LOG_DEBUG, "osm_transaction_mgr_get_madw_for_tid: " "Looking for TID:<0x%" PRIx64 ">.\n", p_mad->trans_id); key = (uint64_t) p_mad->trans_id; cl_spinlock_acquire(&(trans_mgr_p->transaction_mgr_lock)); p_map_item = cl_qmap_get(trans_mgr_p->madw_by_tid_map_p, key); if (p_map_item != cl_qmap_end(trans_mgr_p->madw_by_tid_map_p)) { /* we found such an item. */ /* get the osm_madw_req_p */ osm_madw_req_p = PARENT_STRUCT(p_map_item, osm_madw_req_t, map_item); /* Since the Transaction was looked up and provided for */ /* processing we retire it */ cl_qlist_remove_item(trans_mgr_p->madw_reqs_list_p, &(osm_madw_req_p->list_item)); /* remove the item from the qmap */ cl_qmap_remove_item(trans_mgr_p->madw_by_tid_map_p, &(osm_madw_req_p->map_item)); osm_log(p_vend->p_log, OSM_LOG_DEBUG, "osm_transaction_mgr_get_madw_for_tid: " "Removed TID:<0x%" PRIx64 ">.\n", p_mad->trans_id); *req_madw_p = osm_madw_req_p->p_madw; } cl_spinlock_release(&(trans_mgr_p->transaction_mgr_lock)); osm_log(p_vend->p_log, OSM_LOG_DEBUG, "osm_transaction_mgr_get_madw_for_tid: " "Got MADW:%p.\n", *req_madw_p); OSM_LOG_EXIT(p_vend->p_log); return (IB_SUCCESS); }
ib_api_status_t osm_transaction_mgr_erase_madw(IN osm_vendor_t * const p_vend, IN ib_mad_t * p_mad) { osm_transaction_mgr_t *trans_mgr_p; osm_madw_req_t *osm_madw_req_p; uint64_t key; cl_map_item_t *p_map_item; OSM_LOG_ENTER(p_vend->p_log); trans_mgr_p = (osm_transaction_mgr_t *) p_vend->p_transaction_mgr; key = (uint64_t) p_mad->trans_id; osm_log(p_vend->p_log, OSM_LOG_DEBUG, "osm_transaction_mgr_erase_madw: " "Removing TID:<0x%" PRIx64 ">.\n", p_mad->trans_id); cl_spinlock_acquire(&trans_mgr_p->transaction_mgr_lock); p_map_item = cl_qmap_get(trans_mgr_p->madw_by_tid_map_p, key); if (p_map_item != cl_qmap_end(trans_mgr_p->madw_by_tid_map_p)) { /* we found such an item. */ /* get the osm_madw_req_p */ osm_madw_req_p = PARENT_STRUCT(p_map_item, osm_madw_req_t, map_item); /* remove the item from the qlist */ cl_qlist_remove_item(trans_mgr_p->madw_reqs_list_p, &(osm_madw_req_p->list_item)); /* remove the item from the qmap */ cl_qmap_remove_item(trans_mgr_p->madw_by_tid_map_p, &(osm_madw_req_p->map_item)); osm_log(p_vend->p_log, OSM_LOG_DEBUG, "osm_transaction_mgr_erase_madw: " "Removed TID:<0x%" PRIx64 ">.\n", p_mad->trans_id); /* free the item */ free(osm_madw_req_p); } else { osm_log(p_vend->p_log, OSM_LOG_DEBUG, "osm_transaction_mgr_erase_madw: " "osm_transaction_mgr_erase_madw:<0x%" PRIx64 "> NOT FOUND.\n", p_mad->trans_id); } cl_spinlock_release(&trans_mgr_p->transaction_mgr_lock); OSM_LOG_EXIT(p_vend->p_log); return (IB_SUCCESS); }
void cl_event_wheel_dump(IN cl_event_wheel_t * const p_event_wheel) { cl_list_item_t *p_list_item; cl_event_wheel_reg_info_t __attribute__((__unused__)) *p_event; p_list_item = cl_qlist_head(&p_event_wheel->events_wheel); while (p_list_item != cl_qlist_end(&p_event_wheel->events_wheel)) { p_event = PARENT_STRUCT(p_list_item, cl_event_wheel_reg_info_t, list_item); CL_DBG("cl_event_wheel_dump: Found event key:<0x%" PRIx64 ">, num_regs:%d, aging time:%" PRIu64 "\n", p_event->key, p_event->num_regs, p_event->aging_time); p_list_item = cl_qlist_next(p_list_item); } }
void osm_vendor_delete(IN osm_vendor_t ** const pp_vend) { cl_list_item_t *p_item; cl_list_obj_t *p_obj; osm_bind_handle_t bind_h; osm_log_t *p_log; OSM_LOG_ENTER((*pp_vend)->p_log); p_log = (*pp_vend)->p_log; /* go over the bind handles , unbind them and remove from list */ p_item = cl_qlist_remove_head(&((*pp_vend)->bind_handles)); while (p_item != cl_qlist_end(&((*pp_vend)->bind_handles))) { p_obj = PARENT_STRUCT(p_item, cl_list_obj_t, list_item); bind_h = (osm_bind_handle_t *) cl_qlist_obj(p_obj); osm_log(p_log, OSM_LOG_DEBUG, "osm_vendor_delete: unbinding bind_h:%p \n", bind_h); __osm_vendor_internal_unbind(bind_h); free(p_obj); /*removing from list */ p_item = cl_qlist_remove_head(&((*pp_vend)->bind_handles)); } if (NULL != ((*pp_vend)->p_transport_info)) { free((*pp_vend)->p_transport_info); (*pp_vend)->p_transport_info = NULL; } /* remove the packet randomizer object */ if ((*pp_vend)->run_randomizer == TRUE) osm_pkt_randomizer_destroy(&((*pp_vend)->p_pkt_randomizer), p_log); free(*pp_vend); *pp_vend = NULL; OSM_LOG_EXIT(p_log); }
ib_api_status_t __osmv_txnmgr_lookup(IN osmv_txn_mgr_t * p_tx_mgr, IN uint64_t key, OUT osmv_txn_ctx_t ** pp_txn) { ib_api_status_t status = IB_SUCCESS; cl_map_item_t *p_item; cl_map_obj_t *p_obj; uint64_t tmp_key; OSM_LOG_ENTER(p_tx_mgr->p_log); CL_ASSERT(p_tx_mgr); CL_ASSERT(pp_txn); osm_log(p_tx_mgr->p_log, OSM_LOG_DEBUG, "__osmv_txnmgr_lookup: " "Looking for key: 0x%llX in map ptr:%p\n", key, p_tx_mgr->p_txn_map); p_item = cl_qmap_head(p_tx_mgr->p_txn_map); while (p_item != cl_qmap_end(p_tx_mgr->p_txn_map)) { tmp_key = cl_qmap_key(p_item); osm_log(p_tx_mgr->p_log, OSM_LOG_DEBUG, "__osmv_txnmgr_lookup: " "Found key 0x%llX \n", tmp_key); p_item = cl_qmap_next(p_item); } p_item = cl_qmap_get(p_tx_mgr->p_txn_map, key); if (cl_qmap_end(p_tx_mgr->p_txn_map) == p_item) { status = IB_NOT_FOUND; } else { p_obj = PARENT_STRUCT(p_item, cl_map_obj_t, item); *pp_txn = cl_qmap_obj(p_obj); } OSM_LOG_EXIT(p_tx_mgr->p_log); return status; }
void __osmv_txn_all_done(osm_bind_handle_t h_bind) { osmv_bind_obj_t *p_bo = (osmv_bind_obj_t *) h_bind; cl_map_item_t *p_item; cl_map_obj_t *p_obj; osmv_txn_ctx_t *p_txn; OSM_LOG_ENTER(p_bo->p_vendor->p_log); p_item = cl_qmap_head(p_bo->txn_mgr.p_txn_map); while (p_item != cl_qmap_end(p_bo->txn_mgr.p_txn_map)) { p_obj = PARENT_STRUCT(p_item, cl_map_obj_t, item); p_txn = (osmv_txn_ctx_t *) cl_qmap_obj(p_obj); osmv_txn_done(h_bind, osmv_txn_get_key(p_txn), FALSE); free(p_obj); /* assuming osmv_txn_done has removed the txn from the map */ p_item = cl_qmap_head(p_bo->txn_mgr.p_txn_map); } OSM_LOG_EXIT(p_bo->p_vendor->p_log); }
void cl_event_wheel_destroy(IN cl_event_wheel_t * const p_event_wheel) { cl_list_item_t *p_list_item; cl_map_item_t *p_map_item; cl_event_wheel_reg_info_t *p_event; /* we need to get a lock */ cl_spinlock_acquire(&p_event_wheel->lock); cl_event_wheel_dump(p_event_wheel); /* go over all the items in the list and remove them */ p_list_item = cl_qlist_remove_head(&p_event_wheel->events_wheel); while (p_list_item != cl_qlist_end(&p_event_wheel->events_wheel)) { p_event = PARENT_STRUCT(p_list_item, cl_event_wheel_reg_info_t, list_item); CL_DBG("cl_event_wheel_destroy: Found outstanding event" " key:<0x%" PRIx64 ">\n", p_event->key); /* remove it from the map */ p_map_item = &(p_event->map_item); cl_qmap_remove_item(&p_event_wheel->events_map, p_map_item); free(p_event); /* allocated by cl_event_wheel_reg */ p_list_item = cl_qlist_remove_head(&p_event_wheel->events_wheel); } /* destroy the timer */ cl_timer_destroy(&p_event_wheel->timer); /* destroy the lock (this should be done without releasing - we don't want any other run to grab the lock at this point. */ cl_spinlock_release(&p_event_wheel->lock); cl_spinlock_destroy(&(p_event_wheel->lock)); }
uint32_t cl_event_wheel_num_regs(IN cl_event_wheel_t * const p_event_wheel, IN uint64_t key) { cl_event_wheel_reg_info_t *p_event; cl_map_item_t *p_map_item; uint32_t num_regs = 0; /* try to find the key in the map */ CL_DBG("cl_event_wheel_num_regs: Looking for key:0x%" PRIx64 "\n", key); cl_spinlock_acquire(&p_event_wheel->lock); p_map_item = cl_qmap_get(&p_event_wheel->events_map, key); if (p_map_item != cl_qmap_end(&p_event_wheel->events_map)) { /* ok so we can simply return it's num_regs */ p_event = PARENT_STRUCT(p_map_item, cl_event_wheel_reg_info_t, map_item); num_regs = p_event->num_regs; } cl_spinlock_release(&p_event_wheel->lock); return (num_regs); }
cl_status_t cl_event_wheel_reg(IN cl_event_wheel_t * const p_event_wheel, IN const uint64_t key, IN const uint64_t aging_time_usec, IN cl_pfn_event_aged_cb_t pfn_callback, IN void *const context) { cl_event_wheel_reg_info_t *p_event; uint64_t timeout; uint32_t to; cl_status_t cl_status = CL_SUCCESS; cl_list_item_t *prev_event_list_item; cl_map_item_t *p_map_item; /* Get the lock on the manager */ cl_spinlock_acquire(&(p_event_wheel->lock)); cl_event_wheel_dump(p_event_wheel); /* Make sure such a key does not exists */ p_map_item = cl_qmap_get(&p_event_wheel->events_map, key); if (p_map_item != cl_qmap_end(&p_event_wheel->events_map)) { CL_DBG("cl_event_wheel_reg: Already exists key:0x%" PRIx64 "\n", key); /* already there - remove it from the list as it is getting a new time */ p_event = PARENT_STRUCT(p_map_item, cl_event_wheel_reg_info_t, map_item); /* remove the item from the qlist */ cl_qlist_remove_item(&p_event_wheel->events_wheel, &p_event->list_item); /* and the qmap */ cl_qmap_remove_item(&p_event_wheel->events_map, &p_event->map_item); } else { /* make a new one */ p_event = (cl_event_wheel_reg_info_t *) malloc(sizeof(cl_event_wheel_reg_info_t)); p_event->num_regs = 0; } p_event->key = key; p_event->aging_time = aging_time_usec; p_event->pfn_aged_callback = pfn_callback; p_event->context = context; p_event->num_regs++; CL_DBG("cl_event_wheel_reg: Registering event key:0x%" PRIx64 " aging in %u [msec]\n", p_event->key, (uint32_t) ((p_event->aging_time - cl_get_time_stamp()) / 1000)); /* If the list is empty - need to start the timer */ if (cl_is_qlist_empty(&p_event_wheel->events_wheel)) { /* Edward Bortnikov 03/29/2003 * ++TBD Consider moving the timer manipulation behind the list manipulation. */ /* calculate the new timeout */ timeout = (p_event->aging_time - cl_get_time_stamp() + 500) / 1000; /* stop the timer if it is running */ /* Edward Bortnikov 03/29/2003 * Don't call cl_timer_stop() because it spins forever. * cl_timer_start() will invoke cl_timer_stop() by itself. * * The problematic scenario is when __cl_event_wheel_callback() * is in race condition with this code. It sets timer.in_timer_cb * to TRUE and then blocks on p_event_wheel->lock. Following this, * the call to cl_timer_stop() hangs. Following this, the whole system * enters into a deadlock. * * cl_timer_stop(&p_event_wheel->timer); */ /* The timeout for the cl_timer_start should be given as uint32_t. if there is an overflow - warn about it. */ to = (uint32_t) timeout; if (timeout > (uint32_t) timeout) { to = 0xffffffff; /* max 32 bit timer */ CL_DBG("cl_event_wheel_reg: timeout requested is " "too large. Using timeout: %u\n", to); } /* start the timer to the timeout [msec] */ cl_status = cl_timer_start(&p_event_wheel->timer, to); if (cl_status != CL_SUCCESS) { CL_DBG("cl_event_wheel_reg : ERR 6203: " "Failed to start timer\n"); goto Exit; } } /* insert the object to the qlist and the qmap */ /* BUT WE MUST INSERT IT IN A SORTED MANNER */ prev_event_list_item = cl_qlist_find_from_tail(&p_event_wheel->events_wheel, __event_will_age_before, &p_event->aging_time); cl_qlist_insert_next(&p_event_wheel->events_wheel, prev_event_list_item, &p_event->list_item); cl_qmap_insert(&p_event_wheel->events_map, key, &(p_event->map_item)); Exit: cl_spinlock_release(&p_event_wheel->lock); return cl_status; }
static void __cl_event_wheel_callback(IN void *context) { cl_event_wheel_t *p_event_wheel = (cl_event_wheel_t *) context; cl_list_item_t *p_list_item, *p_prev_event_list_item; cl_list_item_t *p_list_next_item; cl_event_wheel_reg_info_t *p_event; uint64_t current_time; uint64_t next_aging_time; uint32_t new_timeout; cl_status_t cl_status; /* might be during closing ... */ if (p_event_wheel->closing) return; current_time = cl_get_time_stamp(); if (NULL != p_event_wheel->p_external_lock) /* Take care of the order of acquiring locks to avoid the deadlock! * The external lock goes first. */ cl_spinlock_acquire(p_event_wheel->p_external_lock); cl_spinlock_acquire(&p_event_wheel->lock); p_list_item = cl_qlist_head(&p_event_wheel->events_wheel); if (p_list_item == cl_qlist_end(&p_event_wheel->events_wheel)) /* the list is empty - nothing to do */ goto Exit; /* we found such an item. get the p_event */ p_event = PARENT_STRUCT(p_list_item, cl_event_wheel_reg_info_t, list_item); while (p_event->aging_time <= current_time) { /* this object has aged - invoke it's callback */ if (p_event->pfn_aged_callback) next_aging_time = p_event->pfn_aged_callback(p_event->key, p_event->num_regs, p_event->context); else next_aging_time = 0; /* point to the next object in the wheel */ p_list_next_item = cl_qlist_next(p_list_item); /* We need to retire the event if the next aging time passed */ if (next_aging_time < current_time) { /* remove it from the map */ cl_qmap_remove_item(&p_event_wheel->events_map, &(p_event->map_item)); /* pop p_event from the wheel */ cl_qlist_remove_head(&p_event_wheel->events_wheel); /* delete the event info object - allocated by cl_event_wheel_reg */ free(p_event); } else { /* update the required aging time */ p_event->aging_time = next_aging_time; p_event->num_regs++; /* do not remove from the map - but remove from the list head and place in the correct position */ /* pop p_event from the wheel */ cl_qlist_remove_head(&p_event_wheel->events_wheel); /* find the event that ages just before */ p_prev_event_list_item = cl_qlist_find_from_tail(&p_event_wheel-> events_wheel, __event_will_age_before, &p_event->aging_time); /* insert just after */ cl_qlist_insert_next(&p_event_wheel->events_wheel, p_prev_event_list_item, &p_event->list_item); /* as we have modified the list - restart from first item: */ p_list_next_item = cl_qlist_head(&p_event_wheel->events_wheel); } /* advance to next event */ p_list_item = p_list_next_item; if (p_list_item == cl_qlist_end(&p_event_wheel->events_wheel)) /* the list is empty - nothing to do */ break; /* get the p_event */ p_event = PARENT_STRUCT(p_list_item, cl_event_wheel_reg_info_t, list_item); } /* We need to restart the timer only if the list is not empty now */ if (p_list_item != cl_qlist_end(&p_event_wheel->events_wheel)) { /* get the p_event */ p_event = PARENT_STRUCT(p_list_item, cl_event_wheel_reg_info_t, list_item); /* start the timer to the timeout [msec] */ new_timeout = (uint32_t) ((p_event->aging_time - current_time + 500) / 1000); CL_DBG("__cl_event_wheel_callback: Restart timer in: " "%u [msec]\n", new_timeout); cl_status = cl_timer_start(&p_event_wheel->timer, new_timeout); if (cl_status != CL_SUCCESS) { CL_DBG("__cl_event_wheel_callback : ERR 6200: " "Failed to start timer\n"); } } /* release the lock */ Exit: cl_spinlock_release(&p_event_wheel->lock); if (NULL != p_event_wheel->p_external_lock) cl_spinlock_release(p_event_wheel->p_external_lock); }
static void MemoryTrackerTrackAllocation( IN const char *pFileName, IN int32 nLine, IN uint32 Bytes, IN uint32 flags, IN void *pMem, IN MEM_ALLOC_FTR *pFtr) { MEM_ALLOC_HDR *pHdr; LIST_ITEM *pListItem; #ifdef MEM_TRACK_FTR if (pFtr) pFtr->OutOfBound = TRK_TAG; #endif // MEM_TRACK_FTR if( !pMemTracker ) { if (unTindex < 5000) unTAddr[unTindex++] = pMem; return; } // Get a header from the free header list. SpinLockAcquire( &pMemTracker->Lock ); pListItem = QListRemoveHead( &pMemTracker->FreeHrdList ); SpinLockRelease( &pMemTracker->Lock ); if( pListItem ) { // Set the header pointer to the header retrieved from the list. pHdr = PARENT_STRUCT( pListItem, MEM_ALLOC_HDR, ListItem ); } else { // We failed to get a free header. Allocate one. // we can prempt if caller allows it, however we do not want // pageable, nor short duration memory pHdr = (MEM_ALLOC_HDR*)MEMORY_ALLOCATE_PRIV( sizeof( MEM_ALLOC_HDR ), flags & IBA_MEM_FLAG_PREMPTABLE, TRK_TAG ); if( !pHdr ) { // We failed to allocate the header, don't track this allocate return; } } pHdr->LineNum = nLine; pHdr->tick = TICK; pHdr->Bytes = Bytes; pHdr->reported = 0; pHdr->displaying = FALSE; pHdr->deallocate = FALSE; // We store the pointer to the memory returned to the user. This allows // searching the list of allocated memory even if the buffer allocated is // not in the list without dereferencing memory we do not own. pHdr->ListItem.pObject = pMem; #ifdef MEM_TRACK_FTR pHdr->pFtr = pFtr; #else pHdr->pFtr = NULL; #endif // MEM_TRACK_FTR SpinLockAcquire( &pMemTracker->Lock ); pHdr->trk = MemoryTrackerReference(pFileName); ++total_allocations; if (++current_allocations > max_allocations) max_allocations = current_allocations; if ((current_allocated += pHdr->Bytes) > max_allocated) max_allocated = current_allocated; // Insert the header structure into our allocation list. QListInsertTail( &pMemTracker->AllocList, &pHdr->ListItem ); SpinLockRelease( &pMemTracker->Lock ); return; }
// // Display memory usage. // void MemoryDisplayUsage( int method, uint32 minSize, uint32 minTick ) { #if defined(MEM_TRACK_ON) uint32 allocated = 0; uint32 allocations = 0; MEM_ALLOC_HDR *pHdr; LIST_ITEM *item, *next, *tail, *head; unsigned int allocations_per_sec = 0; uint32 currentTime; boolean all = (method == 1); if( !pMemTracker ) { MsgOut( "*** IbAccess Memory Tracking is disabled ***\n" ); return; } /* "lock" present allocations by setting * displaying flag, so other allocates/frees will not affect them * This gives us a snapshot while permitting the system to run * while we perform the output (the output itself may use memory allocate) * However, our report loop below must stay within head/tail */ SpinLockAcquire( &pMemTracker->Lock ); tail = QListTail(&pMemTracker->AllocList); head = QListHead(&pMemTracker->AllocList); for(item = head; item != NULL; item = QListNext(&pMemTracker->AllocList, item)) { pHdr = PARENT_STRUCT( item, MEM_ALLOC_HDR, ListItem ); pHdr->displaying = TRUE; } SpinLockRelease (&pMemTracker->Lock); MsgOut( "*** IbAccess Memory Usage %s minSize=%d minTick=%d ***\n", all?"All":"Unreported", minSize, minTick ); if (head && tail) { item = head; do { next = QListNext(&pMemTracker->AllocList, item); pHdr = PARENT_STRUCT( item, MEM_ALLOC_HDR, ListItem ); #ifdef MEM_TRACK_FTR // Check that the user did not overrun his memory allocation. if (pHdr->deallocate == FALSE) { MemoryTrackerCheckOverrun(pHdr); } #endif // MEM_TRACK_FTR if ((pHdr->Bytes >= minSize) && (pHdr->tick >= minTick) && (all || (pHdr->reported == 0))) { // method 2 just marks all current allocations as reported, without actually reporting them // method 3 displays the items without changing their reported state (allows us to avoid the FREED messages) if (method != 2) MemoryTrackerShow("", pHdr, ""); if (method != 3) pHdr->reported = 1; } allocated += pHdr->Bytes; ++allocations; SpinLockAcquire( &pMemTracker->Lock ); pHdr->displaying = FALSE; if (pHdr->deallocate) { MemoryTrackerUnlink(pHdr); } SpinLockRelease (&pMemTracker->Lock); item = next; } while (&pHdr->ListItem != tail && item != NULL); } currentTime = GetTimeStampSec(); if (last_reported_secs && currentTime != last_reported_secs) { allocations_per_sec = (total_allocations - last_reported_allocations) / (currentTime - last_reported_secs); } last_reported_secs = currentTime; last_reported_allocations = total_allocations; MsgOut("IbAccess current allocations=%u bytes=%u max allocations=%u bytes=%u p/s=%d\n", allocations, allocated, max_allocations, max_allocated, allocations_per_sec); #endif // MEM_TRACK_ON }
/* If possible compress a point into a simpler format * This looks for lists which consist of a single entry or * lists which include all the components of a higher level type */ void PointFabricCompress(Point *point) { switch (point->Type) { case POINT_TYPE_NONE: break; case POINT_TYPE_PORT: break; case POINT_TYPE_PORT_LIST: { PortData *portp; LIST_ITERATOR head = ListHead(&point->u.portList); ASSERT(head); ASSERT(ListCount(&point->u.portList) >= 1); portp = (PortData*)ListObj(head); if (ListCount(&point->u.portList) == 1) { /* degenerate case, simplify as a single port */ PointFabricDestroy(point); PointInitSimple(point, POINT_TYPE_PORT, portp); } else if (ListCount(&point->u.portList) == cl_qmap_count(&portp->nodep->Ports)) { /* maybe we can consolidate to a single node */ LIST_ITERATOR i; DLIST *pList = &point->u.portList; for (i=ListHead(pList); portp && i != NULL; i = ListNext(pList, i)) { if (portp->nodep != ((PortData*)ListObj(i))->nodep) portp = NULL; /* not in same node, flag for below */ } if (portp) { /* degenerate case, simplify as a single node */ PointFabricDestroy(point); PointInitSimple(point, POINT_TYPE_NODE, portp->nodep); } #if 0 } else { // the likelihood of this is low for port oriented searches // and it would present just the system image guide in the summary // and may be less obvious to the user than a list of ports /* maybe we can consolidate to a single system */ LIST_ITERATOR i; DLIST *pList = &point->u.portList; for (i=ListHead(pList); portp && i != NULL; i = ListNext(pList, i)) { if (portp->nodep->systemp != ((PortData*)ListObj(i))->nodep->systemp) portp = NULL; /* not in same system, flag for below */ } if (portp) { /* all ports are in same system. is it a complete list? */ /* count ports in the system */ uint32 count = 0; cl_map_item_t *p; for (p=cl_qmap_head(&portp->nodep->systemp->Nodes); p != cl_qmap_end(&portp->nodep->systemp->Nodes); p = cl_qmap_next(p)) { NodeData *nodep = PARENT_STRUCT(p, NodeData, SystemNodesEntry); count += cl_qmap_count(&nodep->Ports); } if (ListCount(&point->u.portList) != count) portp = NULL; /* incomplete list, flag for below */ } if (portp) { /* degenerate case, simplify as a single system */ PointFabricDestroy(point); PointInitSimple(point, POINT_TYPE_SYSTEM, portp->nodep->systemp); } #endif } break; } case POINT_TYPE_NODE: break; case POINT_TYPE_NODE_LIST: { NodeData *nodep; LIST_ITERATOR head = ListHead(&point->u.nodeList); ASSERT(head); ASSERT(ListCount(&point->u.nodeList) >= 1); nodep = (NodeData*)ListObj(head); if (ListCount(&point->u.nodeList) == 1) { /* degenerate case, simplify as a single node */ PointFabricDestroy(point); PointInitSimple(point, POINT_TYPE_NODE, nodep); } else if (ListCount(&point->u.nodeList) == cl_qmap_count(&nodep->systemp->Nodes)) { /* maybe we can consolidate to a single system */ LIST_ITERATOR i; DLIST *pList = &point->u.nodeList; for (i=ListHead(pList); nodep && i != NULL; i = ListNext(pList, i)) { if (nodep->systemp != ((NodeData*)ListObj(i))->systemp) nodep = NULL; /* not in same system, flag for below */ } if (nodep) { /* degenerate case, simplify as a single system */ PointFabricDestroy(point); PointInitSimple(point, POINT_TYPE_SYSTEM, nodep->systemp); } } break; } #if !defined(VXWORKS) || defined(BUILD_DMC) case POINT_TYPE_IOC: break; case POINT_TYPE_IOC_LIST: { IocData *iocp; LIST_ITERATOR head = ListHead(&point->u.iocList); ASSERT(head); ASSERT(ListCount(&point->u.iocList) >= 1); iocp = (IocData*)ListObj(head); if (ListCount(&point->u.iocList) == 1) { /* degenerate case, simplify as a single IOC */ PointFabricDestroy(point); PointInitSimple(point, POINT_TYPE_IOC, iocp); } else if (ListCount(&point->u.iocList) == QListCount(&iocp->ioup->Iocs)) { /* maybe we can consolidate to a single node */ LIST_ITERATOR i; DLIST *pList = &point->u.iocList; for (i=ListHead(pList); iocp && i != NULL; i = ListNext(pList, i)) { if (iocp->ioup != ((IocData*)ListObj(i))->ioup) iocp = NULL; /* not in same iou, flag for below */ } if (iocp) { /* degenerate case, simplify as a single node */ PointFabricDestroy(point); PointInitSimple(point, POINT_TYPE_NODE, iocp->ioup->nodep); } #if 0 } else { // the likelihood of this is low for ioc oriented searches // and it would present just the system image guide in the summary // and may be less obvious to the user than a list of iocs /* maybe we can consolidate to a single system */ LIST_ITERATOR i; DLIST *pList = &point->u.iocList; for (i=ListHead(pList); iocp && i != NULL; i = ListNext(pList, i)) { if (iocp->ioup->nodep->systemp != ((IocData*)ListObj(i))->ioup->nodep->systemp) iocp = NULL; /* not in same system, flag for below */ } if (iocp) { /* all IOCs are in same system. is it a complete list? */ /* count IOCs in the system */ uint32 count = 0; cl_map_item_t *p; for (p=cl_qmap_head(&iocp->ioup->nodep->systemp->Nodes); p != cl_qmap_end(&iocp->ioup->nodep->systemp->Nodes); p = cl_qmap_next(p)) { NodeData *nodep = PARENT_STRUCT(p, NodeData, SystemNodesEntry); if (nodep->ioup) count += QListCount(&nodep->ioup->Iocs); } if (ListCount(&point->u.iocList) != count) iocp = NULL; /* incomplete list, flag for below */ } if (iocp) { /* degenerate case, simplify as a single system */ PointFabricDestroy(point); PointInitSimple(point, POINT_TYPE_SYSTEM, iocp->ioup->nodep->systemp); } #endif } break; } #endif case POINT_TYPE_SYSTEM: break; } }
/* this is the callback function of the timer */ void __osm_transaction_mgr_callback(IN void *context) { osm_transaction_mgr_t *trans_mgr_p; osm_vendor_t *p_vend = (osm_vendor_t *) context; cl_list_item_t *p_list_item; cl_list_item_t *p_list_next_item; osm_madw_req_t *osm_madw_req_p; uint64_t current_time; /* [usec] */ uint32_t new_timeout; /* [msec] */ cl_status_t cl_status; ib_mad_t *p_mad; #ifdef OSM_VENDOR_INTF_MTL osm_mtl_bind_info_t *p_bind; #else osm_ts_bind_info_t *p_bind; #endif cl_list_t tmp_madw_p_list; /* this list will include all the madw_p that should be removed. */ cl_list_t retry_madw_p_list; /* this list will include all the madw_p that were retried and need to be removed. */ osm_madw_t *madw_p; OSM_LOG_ENTER(p_vend->p_log); trans_mgr_p = (osm_transaction_mgr_t *) p_vend->p_transaction_mgr; /* initialize the tmp_madw_p_list */ cl_list_construct(&tmp_madw_p_list); cl_status = cl_list_init(&tmp_madw_p_list, 50); if (cl_status != CL_SUCCESS) { osm_log(p_vend->p_log, OSM_LOG_ERROR, "__osm_transaction_mgr_callback : ERROR 1000: " "Failed to create tmp_madw_p_list\n"); } cl_list_construct(&retry_madw_p_list); cl_status = cl_list_init(&retry_madw_p_list, 50); if (cl_status != CL_SUCCESS) { osm_log(p_vend->p_log, OSM_LOG_ERROR, "__osm_transaction_mgr_callback : ERROR 1000: " "Failed to create retry_madw_p_list\n"); } current_time = cl_get_time_stamp(); cl_spinlock_acquire(&(trans_mgr_p->transaction_mgr_lock)); p_list_item = cl_qlist_head(trans_mgr_p->madw_reqs_list_p); if (p_list_item == cl_qlist_end(trans_mgr_p->madw_reqs_list_p)) { /* the list is empty - nothing to do */ cl_spinlock_release(&trans_mgr_p->transaction_mgr_lock); osm_log(p_vend->p_log, OSM_LOG_DEBUG, "__osm_transaction_mgr_callback : Nothing to do\n"); goto Exit; } /* non empty list: */ /* get the osm_madw_req_p */ osm_madw_req_p = PARENT_STRUCT(p_list_item, osm_madw_req_t, list_item); while (osm_madw_req_p->waking_time <= current_time) { /* this object was supposed to have gotten a response */ /* we need to decide if we need to retry or done with it. */ if (osm_madw_req_p->retry_cnt > 0) { /* add to the list of the retrys : */ cl_list_insert_tail(&retry_madw_p_list, osm_madw_req_p); /* update wakeup time and retry count */ osm_madw_req_p->waking_time = p_vend->timeout * 1000 + cl_get_time_stamp(); osm_madw_req_p->retry_cnt--; /* make sure we will get some timer call if not earlier */ osm_log(p_vend->p_log, OSM_LOG_DEBUG, "__osm_transaction_mgr_callback : Timer restart:%u\n", p_vend->timeout); cl_status = cl_timer_start(&trans_mgr_p->madw_list_timer, p_vend->timeout); /* go to the next object and check if it also needs to be removed - didn't receive response */ /* we need to do it before we move current item to the end of the list */ p_list_next_item = cl_qlist_next(p_list_item); /* remove from the head */ cl_qlist_remove_item(trans_mgr_p->madw_reqs_list_p, &(osm_madw_req_p->list_item)); /* insert the object to the qlist and the qmap */ cl_qlist_insert_tail(trans_mgr_p->madw_reqs_list_p, &(osm_madw_req_p->list_item)); } else { /* go to the next object and check if it also needs to be removed - didn't receive response */ p_list_next_item = cl_qlist_next(p_list_item); /* remove from the head */ cl_qlist_remove_item(trans_mgr_p->madw_reqs_list_p, &(osm_madw_req_p->list_item)); /* add it to the tmp_madw_p_list to be removed */ cl_list_insert_tail(&tmp_madw_p_list, osm_madw_req_p->p_madw); osm_log(p_vend->p_log, OSM_LOG_DEBUG, "__osm_transaction_mgr_callback : Found failed transaction madw: %p\n", osm_madw_req_p->p_madw); } /* Advance */ p_list_item = p_list_next_item; if (p_list_item == cl_qlist_end(trans_mgr_p->madw_reqs_list_p)) { /* the list is empty - nothing to do */ break; } /* get the osm_madw_req_p */ osm_madw_req_p = PARENT_STRUCT(p_list_item, osm_madw_req_t, list_item); } /* look at the current p_list_item. If it is not the end item - then we need to */ /* re-start the timer */ if (p_list_item != cl_qlist_end(trans_mgr_p->madw_reqs_list_p)) { /* get the osm_madw_req_p */ osm_madw_req_p = PARENT_STRUCT(p_list_item, osm_madw_req_t, list_item); /* we have the object that still didn't get response - re-start the timer */ /* start the timer to the timeout (in miliseconds) */ new_timeout = (osm_madw_req_p->waking_time - cl_get_time_stamp()) / 1000 + 1; cl_status = cl_timer_start(&trans_mgr_p->madw_list_timer, new_timeout); osm_log(p_vend->p_log, OSM_LOG_DEBUG, "__osm_transaction_mgr_callback : Timer restart:%u\n", new_timeout); if (cl_status != CL_SUCCESS) { osm_log(p_vend->p_log, OSM_LOG_ERROR, "__osm_transaction_mgr_callback : ERROR 1000: " "Failed to start timer\n"); } } /* if not empty - retry on retry list: */ if (!cl_is_list_empty(&retry_madw_p_list)) { /* remove all elements that were retried: */ osm_madw_req_p = (osm_madw_req_t *) (cl_list_remove_head(&retry_madw_p_list)); while (osm_madw_req_p != NULL) { /* resend: */ osm_log(p_vend->p_log, OSM_LOG_DEBUG, "__osm_transaction_mgr_callback : " "Retry %d of madw %p\n", OSM_DEFAULT_RETRY_COUNT - osm_madw_req_p->retry_cnt, osm_madw_req_p->p_madw); /* actually send it */ #ifdef OSM_VENDOR_INTF_MTL osm_mtl_send_mad((osm_mtl_bind_info_t *) osm_madw_req_p->p_bind, osm_madw_req_p->p_madw); #else ib_api_status_t osm_ts_send_mad(osm_ts_bind_info_t * p_bind, osm_madw_t * const p_madw); osm_ts_send_mad((osm_ts_bind_info_t *) osm_madw_req_p-> p_bind, osm_madw_req_p->p_madw); #endif /* next one */ osm_madw_req_p = (osm_madw_req_t *) (cl_list_remove_head(&retry_madw_p_list)); } } /* if the tmp_madw_p_list has elements - need to call the send_err_callback */ madw_p = (osm_madw_t *) (cl_list_remove_head(&tmp_madw_p_list)); while (madw_p != NULL) { /* need to remove it from pool */ /* obtain the madw_p stored as the wrid in the send call */ p_mad = osm_madw_get_mad_ptr(madw_p); p_bind = madw_p->h_bind; /* Return any wrappers to the pool that may have been pre-emptively allocated to handle a receive. */ if (madw_p->vend_wrap.p_resp_madw) { #ifdef OSM_VENDOR_INTF_MTL osm_mad_pool_put(p_bind->p_osm_pool, madw_p->vend_wrap.p_resp_madw); #else osm_mad_pool_put(p_bind->p_osm_pool, madw_p->vend_wrap.p_resp_madw); #endif madw_p->vend_wrap.p_resp_madw = NULL; } /* invoke the CB */ (*(osm_vend_mad_send_err_callback_t) (p_bind->send_err_callback)) (p_bind->client_context, madw_p); madw_p = (osm_madw_t *) (cl_list_remove_head(&tmp_madw_p_list)); } Exit: OSM_LOG_EXIT(p_vend->p_log); }