From patchwork Mon Oct 17 19:11:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 9380297 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DBCD460487 for ; Mon, 17 Oct 2016 19:12:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF90C28567 for ; Mon, 17 Oct 2016 19:12:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B434D28FE7; Mon, 17 Oct 2016 19:12:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD43D28567 for ; Mon, 17 Oct 2016 19:11:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964854AbcJQTL7 (ORCPT ); Mon, 17 Oct 2016 15:11:59 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:56918 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964808AbcJQTL6 (ORCPT ); Mon, 17 Oct 2016 15:11:58 -0400 Received: from [83.175.99.196] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.85_2 #1 (Red Hat Linux)) id 1bwDKH-0006aK-Cx for linux-rdma@vger.kernel.org; Mon, 17 Oct 2016 19:11:57 +0000 From: Christoph Hellwig To: linux-rdma@vger.kernel.org Subject: [PATCH 10/13] ibacm: cleanup "lock" Date: Mon, 17 Oct 2016 21:11:19 +0200 Message-Id: <1476731482-26491-11-git-send-email-hch@lst.de> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1476731482-26491-1-git-send-email-hch@lst.de> References: <1476731482-26491-1-git-send-email-hch@lst.de> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Make it static to libacm.c, give it a more reasonable name and initialize it at compile time. Note tha the critical sections for this lock could be reduced easily, but that's a different project if someone cares enough.. Signed-off-by: Christoph Hellwig --- ibacm/CMakeLists.txt | 1 - ibacm/linux/libacm_linux.c | 37 ------------------------------------- ibacm/src/libacm.c | 22 +++++++++++----------- 3 files changed, 11 insertions(+), 49 deletions(-) delete mode 100644 ibacm/linux/libacm_linux.c diff --git a/ibacm/CMakeLists.txt b/ibacm/CMakeLists.txt index 7ed8fd5..505fba3 100644 --- a/ibacm/CMakeLists.txt +++ b/ibacm/CMakeLists.txt @@ -38,7 +38,6 @@ set_target_properties(ibacmp PROPERTIES install(TARGETS ibacmp DESTINATION "${ACM_PROVIDER_DIR}") rdma_executable(ib_acme - linux/libacm_linux.c src/acme.c src/libacm.c src/parse.c diff --git a/ibacm/linux/libacm_linux.c b/ibacm/linux/libacm_linux.c deleted file mode 100644 index 2b8a910..0000000 --- a/ibacm/linux/libacm_linux.c +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2009 Intel Corporation. All rights reserved. - * - * This software is available to you under the OpenIB.org BSD license - * below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AWV - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -pthread_mutex_t lock; - -static void __attribute__((constructor)) lib_init(void) -{ - pthread_mutex_init(&lock, NULL); -} diff --git a/ibacm/src/libacm.c b/ibacm/src/libacm.c index 4273dfe..1980919 100644 --- a/ibacm/src/libacm.c +++ b/ibacm/src/libacm.c @@ -38,7 +38,7 @@ #include #include -extern pthread_mutex_t lock; +static pthread_mutex_t acm_lock = PTHREAD_MUTEX_INITIALIZER; static int sock = -1; static short server_port = 6125; @@ -212,7 +212,7 @@ static int acm_resolve(uint8_t *src, uint8_t *dest, uint8_t type, struct acm_msg msg; int ret, cnt = 0; - pthread_mutex_lock(&lock); + pthread_mutex_lock(&acm_lock); memset(&msg, 0, sizeof msg); msg.hdr.version = ACM_VERSION; msg.hdr.opcode = ACM_OP_RESOLVE; @@ -246,7 +246,7 @@ static int acm_resolve(uint8_t *src, uint8_t *dest, uint8_t type, ret = acm_format_resp(&msg, paths, count, print); out: - pthread_mutex_unlock(&lock); + pthread_mutex_unlock(&acm_lock); return ret; } @@ -275,7 +275,7 @@ int ib_acm_resolve_path(struct ibv_path_record *path, uint32_t flags) struct acm_ep_addr_data *data; int ret; - pthread_mutex_lock(&lock); + pthread_mutex_lock(&acm_lock); memset(&msg, 0, sizeof msg); msg.hdr.version = ACM_VERSION; msg.hdr.opcode = ACM_OP_RESOLVE; @@ -299,7 +299,7 @@ int ib_acm_resolve_path(struct ibv_path_record *path, uint32_t flags) *path = data->info.path; out: - pthread_mutex_unlock(&lock); + pthread_mutex_unlock(&acm_lock); return ret; } @@ -308,7 +308,7 @@ int ib_acm_query_perf(int index, uint64_t **counters, int *count) struct acm_msg msg; int ret, i; - pthread_mutex_lock(&lock); + pthread_mutex_lock(&acm_lock); memset(&msg, 0, sizeof msg); msg.hdr.version = ACM_VERSION; msg.hdr.opcode = ACM_OP_PERF_QUERY; @@ -341,7 +341,7 @@ int ib_acm_query_perf(int index, uint64_t **counters, int *count) (*counters)[i] = ntohll(msg.perf_data[i]); ret = 0; out: - pthread_mutex_unlock(&lock); + pthread_mutex_unlock(&acm_lock); return ret; } @@ -353,7 +353,7 @@ int ib_acm_enum_ep(int index, struct acm_ep_config_data **data) int cnt; struct acm_ep_config_data *edata; - pthread_mutex_lock(&lock); + pthread_mutex_lock(&acm_lock); memset(&msg, 0, sizeof msg); msg.hdr.version = ACM_VERSION; msg.hdr.opcode = ACM_OP_EP_QUERY; @@ -391,7 +391,7 @@ int ib_acm_enum_ep(int index, struct acm_ep_config_data **data) *data = edata; ret = 0; out: - pthread_mutex_unlock(&lock); + pthread_mutex_unlock(&acm_lock); return ret; } @@ -404,7 +404,7 @@ int ib_acm_query_perf_ep_addr(uint8_t *src, uint8_t type, if (!src) return -1; - pthread_mutex_lock(&lock); + pthread_mutex_lock(&acm_lock); memset(&msg, 0, sizeof msg); msg.hdr.version = ACM_VERSION; msg.hdr.opcode = ACM_OP_PERF_QUERY; @@ -444,7 +444,7 @@ int ib_acm_query_perf_ep_addr(uint8_t *src, uint8_t type, ret = 0; out: - pthread_mutex_unlock(&lock); + pthread_mutex_unlock(&acm_lock); return ret; }