From patchwork Thu Oct 20 08:52:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Binoy Jayan X-Patchwork-Id: 78455 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp668134qge; Thu, 20 Oct 2016 01:52:50 -0700 (PDT) X-Received: by 10.98.147.218 with SMTP id r87mr19511377pfk.108.1476953570546; Thu, 20 Oct 2016 01:52:50 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r2si5156157pab.142.2016.10.20.01.52.50; Thu, 20 Oct 2016 01:52:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935082AbcJTIwr (ORCPT + 27 others); Thu, 20 Oct 2016 04:52:47 -0400 Received: from mail-pf0-f176.google.com ([209.85.192.176]:36597 "EHLO mail-pf0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934942AbcJTIwZ (ORCPT ); Thu, 20 Oct 2016 04:52:25 -0400 Received: by mail-pf0-f176.google.com with SMTP id e6so32627329pfk.3 for ; Thu, 20 Oct 2016 01:52:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=F+k5nz4XJB8awis37RBl10jxhQk1a0qWcgr6GYk5SBw=; b=CMl+oHR8R3b6wEc5yl/x0WKVTepTbEfbBSHWfbmTXTirVl42v0vxaw82LQZHVax7FJ LuWf31guxDPvJjF/MdKvkfiqowJBa+mlsIE82Q4egkMFLkkmjVgJUz6wKFS5wWu+ffeD Horx9jF84/IjMkzT5gXU2aDiSYyqt7UOTtGrE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=F+k5nz4XJB8awis37RBl10jxhQk1a0qWcgr6GYk5SBw=; b=CPzH2W4t2DV/JPXXPIXlbgcFjV+zebCZDpYR8SK8qt8lSIxQYw/eLrg2Fl5kezfkjk g9+AhiURJ2QDytizJFTipHN/hW/FzE5HkWfwyDHny+gKaOYTWjjR+ykEhkrAdm8bvO51 YwRDJlVecgUo8c+Obpnd8NuJ9S+Fgj2Tf45TGl3FhkKcGjntDC2NbrpxXViOFu+ZoyR2 FuGjYI3q0Fr3CjWtoTuSi6+mxa9o0sUDEfJ8mFD+gr0bdeeednotxEf2Ks+SRDqyuYp7 QcWePHcJ60L57Zo/xRsLGgN5Rh4UcramRgchCWSYA9crBmM6kU/Epm/0u2TG6Zy9SXve bSQg== X-Gm-Message-State: AA6/9Rlc0ET89GV/nKi9B6hyXd5EiaFLhhz0CeZZo2Qp1O9KX2XjbK8VmnGwI34g/aV/a1wj X-Received: by 10.99.126.11 with SMTP id z11mr16149253pgc.46.1476953544913; Thu, 20 Oct 2016 01:52:24 -0700 (PDT) Received: from blr-ubuntu-59.ap.qualcomm.com ([202.46.23.61]) by smtp.gmail.com with ESMTPSA id d142sm10311699pfd.33.2016.10.20.01.52.22 (version=TLS1_1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 20 Oct 2016 01:52:24 -0700 (PDT) From: Binoy Jayan To: Ariel Elior Cc: Arnd Bergmann , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Binoy Jayan Subject: [PATCH] bnx2x: Replace semaphore stats_lock with mutex Date: Thu, 20 Oct 2016 14:22:12 +0530 Message-Id: <1476953532-2019-1-git-send-email-binoy.jayan@linaro.org> X-Mailer: git-send-email 1.8.2.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org stats_lock is used as a simple mutex, so replace it with a mutex. Semaphores are going away in the future. Signed-off-by: Binoy Jayan --- They following is a patch which removes semaphores from bnx2x. Its part of a bigger effort to eliminate all semaphores from the linux kernel. drivers/net/ethernet/broadcom/bnx2x/bnx2x.h | 3 ++- drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c | 6 +++--- drivers/net/ethernet/broadcom/bnx2x/bnx2x_stats.c | 17 +++++++---------- 3 files changed, 12 insertions(+), 14 deletions(-) -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h index 7dd7490..fd5e5b8 100644 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h @@ -25,6 +25,7 @@ #include #include #include +#include /* compilation time flags */ @@ -1698,7 +1699,7 @@ struct bnx2x { int stats_state; /* used for synchronization of concurrent threads statistics handling */ - struct semaphore stats_lock; + struct mutex stats_lock; /* used by dmae command loader */ struct dmae_command stats_dmae; diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c index 20fe6a8..b323d69 100644 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c @@ -12340,7 +12340,7 @@ static int bnx2x_init_bp(struct bnx2x *bp) mutex_init(&bp->port.phy_mutex); mutex_init(&bp->fw_mb_mutex); mutex_init(&bp->drv_info_mutex); - sema_init(&bp->stats_lock, 1); + mutex_init(&bp->stats_lock); bp->drv_info_mng_owner = false; INIT_LIST_HEAD(&bp->vlan_reg); @@ -14205,9 +14205,9 @@ static int bnx2x_eeh_nic_unload(struct bnx2x *bp) cancel_delayed_work_sync(&bp->sp_task); cancel_delayed_work_sync(&bp->period_task); - if (!down_timeout(&bp->stats_lock, HZ / 10)) { + if (mutex_trylock(&bp->stats_lock)) { bp->stats_state = STATS_STATE_DISABLED; - up(&bp->stats_lock); + mutex_unlock(&bp->stats_lock); } bnx2x_save_statistics(bp); diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_stats.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_stats.c index 7e0919a..ee6ffd8 100644 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_stats.c +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_stats.c @@ -1374,23 +1374,20 @@ void bnx2x_stats_handle(struct bnx2x *bp, enum bnx2x_stats_event event) * that context in case someone is in the middle of a transition. * For other events, wait a bit until lock is taken. */ - if (down_trylock(&bp->stats_lock)) { + if (!mutex_trylock(&bp->stats_lock)) { if (event == STATS_EVENT_UPDATE) return; DP(BNX2X_MSG_STATS, "Unlikely stats' lock contention [event %d]\n", event); - if (unlikely(down_timeout(&bp->stats_lock, HZ / 10))) { - BNX2X_ERR("Failed to take stats lock [event %d]\n", - event); - return; - } + BNX2X_ERR("Failed to take stats lock [event %d]\n", event); + return; } bnx2x_stats_stm[state][event].action(bp); bp->stats_state = bnx2x_stats_stm[state][event].next_state; - up(&bp->stats_lock); + mutex_unlock(&bp->stats_lock); if ((event != STATS_EVENT_UPDATE) || netif_msg_timer(bp)) DP(BNX2X_MSG_STATS, "state %d -> event %d -> state %d\n", @@ -1976,8 +1973,8 @@ int bnx2x_stats_safe_exec(struct bnx2x *bp, /* Wait for statistics to end [while blocking further requests], * then run supplied function 'safely'. */ - rc = down_timeout(&bp->stats_lock, HZ / 10); - if (unlikely(rc)) { + rc = mutex_trylock(&bp->stats_lock); + if (unlikely(!rc)) { BNX2X_ERR("Failed to take statistics lock for safe execution\n"); goto out_no_lock; } @@ -1998,7 +1995,7 @@ int bnx2x_stats_safe_exec(struct bnx2x *bp, /* No need to restart statistics - if they're enabled, the timer * will restart the statistics. */ - up(&bp->stats_lock); + mutex_unlock(&bp->stats_lock); out_no_lock: return rc; }