From patchwork Thu Feb 21 21:33:55 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Weiny X-Patchwork-Id: 2173251 X-Patchwork-Delegate: hal@mellanox.com Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 4200FDF215 for ; Thu, 21 Feb 2013 21:33:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754133Ab3BUVdz (ORCPT ); Thu, 21 Feb 2013 16:33:55 -0500 Received: from prdiron-2.llnl.gov ([128.15.143.172]:32556 "EHLO prdiron-2.llnl.gov" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753709Ab3BUVdz (ORCPT ); Thu, 21 Feb 2013 16:33:55 -0500 X-Attachments: Received: from eris.llnl.gov (HELO trebuchet.chaos) ([128.115.7.7]) by prdiron-2.llnl.gov with SMTP; 21 Feb 2013 13:33:55 -0800 Date: Thu, 21 Feb 2013 13:33:55 -0800 From: Ira Weiny To: Hal Rosenstock Cc: "linux-rdma@vger.kernel.org" Subject: [PATCH 06/06] opensm/perfmgr: fix access to shared sweep_state variable Message-Id: <20130221133355.158ee182f61e6f0c55683328@llnl.gov> X-Mailer: Sylpheed 3.3.0 (GTK+ 2.18.9; x86_64-unknown-linux-gnu) Mime-Version: 1.0 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Signed-off-by: Ira Weiny --- include/opensm/osm_perfmgr.h | 1 + opensm/osm_perfmgr.c | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/include/opensm/osm_perfmgr.h b/include/opensm/osm_perfmgr.h index 3fa42d5..947a3db 100644 --- a/include/opensm/osm_perfmgr.h +++ b/include/opensm/osm_perfmgr.h @@ -137,6 +137,7 @@ typedef struct osm_perfmgr { cl_disp_reg_handle_t pc_disp_h; osm_perfmgr_state_t state; osm_perfmgr_sweep_state_t sweep_state; + cl_spinlock_t lock; uint16_t sweep_time_s; perfmgr_db_t *db; atomic32_t outstanding_queries; /* this along with sig_query */ diff --git a/opensm/osm_perfmgr.c b/opensm/osm_perfmgr.c index eb0c4f9..45ce219 100644 --- a/opensm/osm_perfmgr.c +++ b/opensm/osm_perfmgr.c @@ -433,11 +433,22 @@ static ib_api_status_t perfmgr_send_mad(osm_perfmgr_t *perfmgr, cl_atomic_inc(&(perfmgr->outstanding_queries)); while (perfmgr->outstanding_queries > (int32_t)perfmgr->max_outstanding_queries) { + cl_spinlock_acquire(&perfmgr->lock); perfmgr->sweep_state = PERFMGR_SWEEP_SUSPENDED; + cl_spinlock_release(&perfmgr->lock); cl_event_wait_on(&perfmgr->sig_query, EVENT_NO_TIMEOUT, TRUE); + + cl_spinlock_acquire(&perfmgr->lock); + if (perfmgr->sweep_state == PERFMGR_SWEEP_SUSPENDED) { + perfmgr->sweep_state = PERFMGR_SWEEP_ACTIVE; + cl_spinlock_release(&perfmgr->lock); + } else { + cl_spinlock_release(&perfmgr->lock); + OSM_LOG(perfmgr->log, OSM_LOG_ERROR, "ERR 54FF: " + "PM was NOT in Suspended state???\n"); + } } - perfmgr->sweep_state = PERFMGR_SWEEP_ACTIVE; } return (status); } @@ -982,11 +993,15 @@ void osm_perfmgr_process(osm_perfmgr_t * pm) if (pm->state != PERFMGR_STATE_ENABLED) return; + cl_spinlock_acquire(&pm->lock); if (pm->sweep_state == PERFMGR_SWEEP_ACTIVE || - pm->sweep_state == PERFMGR_SWEEP_SUSPENDED) + pm->sweep_state == PERFMGR_SWEEP_SUSPENDED) { + cl_spinlock_release(&pm->lock); return; + } pm->sweep_state = PERFMGR_SWEEP_ACTIVE; + cl_spinlock_release(&pm->lock); if (pm->subn->sm_state == IB_SMINFO_STATE_STANDBY || pm->subn->sm_state == IB_SMINFO_STATE_NOTACTIVE) @@ -1045,7 +1060,9 @@ void osm_perfmgr_process(osm_perfmgr_t * pm) clear_mad_stats(); #endif + cl_spinlock_acquire(&pm->lock); pm->sweep_state = PERFMGR_SWEEP_SLEEP; + cl_spinlock_release(&pm->lock); } /********************************************************************** @@ -1777,6 +1794,8 @@ ib_api_status_t osm_perfmgr_init(osm_perfmgr_t * pm, osm_opensm_t * osm, pm->trans_id = PERFMGR_INITIAL_TID_VALUE; pm->state = p_opt->perfmgr ? PERFMGR_STATE_ENABLED : PERFMGR_STATE_DISABLE; + pm->sweep_state = PERFMGR_SWEEP_SLEEP; + cl_spinlock_init(&pm->lock); pm->sweep_time_s = p_opt->perfmgr_sweep_time_s; pm->max_outstanding_queries = p_opt->perfmgr_max_outstanding_queries; pm->ignore_cas = p_opt->perfmgr_ignore_cas;