From patchwork Fri May 27 08:53:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi He X-Patchwork-Id: 68729 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp824307qge; Fri, 27 May 2016 01:53:58 -0700 (PDT) X-Received: by 10.55.3.7 with SMTP id 7mr13155446qkd.154.1464339238199; Fri, 27 May 2016 01:53:58 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id n5si16731336qhc.47.2016.05.27.01.53.57; Fri, 27 May 2016 01:53:58 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 683A661722; Fri, 27 May 2016 08:53:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 34909615CC; Fri, 27 May 2016 08:53:55 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 3497B61615; Fri, 27 May 2016 08:53:52 +0000 (UTC) Received: from mail-pf0-f180.google.com (mail-pf0-f180.google.com [209.85.192.180]) by lists.linaro.org (Postfix) with ESMTPS id 02D526156A for ; Fri, 27 May 2016 08:53:51 +0000 (UTC) Received: by mail-pf0-f180.google.com with SMTP id f144so26805510pfa.3 for ; Fri, 27 May 2016 01:53:50 -0700 (PDT) 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=UDFMRiZ0dDG/ZWd5NW5lQ4adoYnfKOly9CMXClLJuuE=; b=KD5rRvPV5fvMin87o8rudob+5p/qVhYVsH5fBnWFlw8orAxS/vVPCWsHKCLEcJmold kgzVHSDxcXNYS1zpR7fXWPdi+965YxqdkgH8+FdaVsYBOR7xcK4uwJoGtVegcbDi51LU AOBey0dwVvpnkWb63c0kktifUId0nmH3avnNTHBiUe3Yj+upOa5BQJ2bP8SVbxjXMPSn BL+ELFkVV/jmVtY1uVj9rVklowz/br5WHfaAq6FcGPVOFW0RH86k03vDI+QZsbyRtpew libJrvvvpbfZX445MfKxfwlgnLcihvW2tv+Z/ag90fhJS+mdj7JMlf9TAGynqTX6tg3P dl+w== X-Gm-Message-State: ALyK8tLWzJubLj2TJy6UuKLRZaBFPJPGrUER5C3Z/6xeLkdV0TubCTV0WU/K0bg3n6LbEocI9C8= X-Received: by 10.98.69.197 with SMTP id n66mr20771513pfi.75.1464339230194; Fri, 27 May 2016 01:53:50 -0700 (PDT) Received: from ubuntu.heyii.co (ubuntu.heyii.co. [45.32.66.203]) by smtp.googlemail.com with ESMTPSA id 141sm11777630pfx.68.2016.05.27.01.53.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 27 May 2016 01:53:49 -0700 (PDT) From: Yi He To: lng-odp@lists.linaro.org Date: Fri, 27 May 2016 08:53:31 +0000 Message-Id: <1464339211-3770-1-git-send-email-yi.he@linaro.org> X-Mailer: git-send-email 1.9.1 X-Topics: patch Subject: [lng-odp] [PATCH] linux-generic: pktio: ring: add _ring_destroy() X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Add _ring_destroy() to release shared memory allocated by _ring_create() calls. previously this was accomplished by manually odp_shm_lookup() and odp_shm_free(). Signed-off-by: Yi He --- .../include/odp_packet_io_ring_internal.h | 8 +++++ platform/linux-generic/pktio/ipc.c | 34 +++++++++++++--------- platform/linux-generic/pktio/ring.c | 16 ++++++++++ platform/linux-generic/test/ring/ring_basic.c | 3 ++ platform/linux-generic/test/ring/ring_stress.c | 2 ++ 5 files changed, 49 insertions(+), 14 deletions(-) diff --git a/platform/linux-generic/include/odp_packet_io_ring_internal.h b/platform/linux-generic/include/odp_packet_io_ring_internal.h index 413787a..a599a26 100644 --- a/platform/linux-generic/include/odp_packet_io_ring_internal.h +++ b/platform/linux-generic/include/odp_packet_io_ring_internal.h @@ -201,6 +201,14 @@ _ring_t *_ring_create(const char *name, unsigned count, unsigned flags); /** + * Destroy the ring created with *name*. + * + * @param name name of the ring to be destroyed. + * @return 0 on success and negative value on error. + */ +int _ring_destroy(const char *name); + +/** * Change the high water mark. * * If *count* is 0, water marking is disabled. Otherwise, it is set to the diff --git a/platform/linux-generic/pktio/ipc.c b/platform/linux-generic/pktio/ipc.c index b8a075c..23e89c4 100644 --- a/platform/linux-generic/pktio/ipc.c +++ b/platform/linux-generic/pktio/ipc.c @@ -141,7 +141,6 @@ static int _ipc_init_master(pktio_entry_t *pktio_entry, uint32_t pool_id; struct pktio_info *pinfo; const char *pool_name; - odp_shm_t shm; pool_id = pool_handle_to_index(pool); pool_entry = get_pool_entry(pool_id); @@ -230,16 +229,13 @@ static int _ipc_init_master(pktio_entry_t *pktio_entry, free_s_prod: snprintf(ipc_shm_name, sizeof(ipc_shm_name), "%s_s_prod", dev); - shm = odp_shm_lookup(ipc_shm_name); - odp_shm_free(shm); + _ring_destroy(ipc_shm_name); free_m_cons: snprintf(ipc_shm_name, sizeof(ipc_shm_name), "%s_m_cons", dev); - shm = odp_shm_lookup(ipc_shm_name); - odp_shm_free(shm); + _ring_destroy(ipc_shm_name); free_m_prod: snprintf(ipc_shm_name, sizeof(ipc_shm_name), "%s_m_prod", dev); - shm = odp_shm_lookup(ipc_shm_name); - odp_shm_free(shm); + _ring_destroy(ipc_shm_name); return -1; } @@ -709,16 +705,26 @@ static int ipc_stop(pktio_entry_t *pktio_entry) static int ipc_close(pktio_entry_t *pktio_entry) { - ipc_stop(pktio_entry); + odp_shm_t shm; + char ipc_shm_name[ODP_POOL_NAME_LEN + sizeof("_m_prod")]; + char *dev = pktio_entry->s.name; - if (pktio_entry->s.ipc.type == PKTIO_TYPE_IPC_MASTER) { - char ipc_shm_name[ODP_POOL_NAME_LEN + sizeof("_m_prod")]; - char *dev = pktio_entry->s.name; - odp_shm_t shm; + ipc_stop(pktio_entry); - /* unlink this pktio info */ - odp_shm_free(pktio_entry->s.ipc.pinfo_shm); + /* unlink this pktio info for both master and slave */ + odp_shm_free(pktio_entry->s.ipc.pinfo_shm); + if (pktio_entry->s.ipc.type == PKTIO_TYPE_IPC_MASTER) { + /* destroy rings */ + snprintf(ipc_shm_name, sizeof(ipc_shm_name), "%s_s_cons", dev); + _ring_destroy(ipc_shm_name); + snprintf(ipc_shm_name, sizeof(ipc_shm_name), "%s_s_prod", dev); + _ring_destroy(ipc_shm_name); + snprintf(ipc_shm_name, sizeof(ipc_shm_name), "%s_m_cons", dev); + _ring_destroy(ipc_shm_name); + snprintf(ipc_shm_name, sizeof(ipc_shm_name), "%s_m_prod", dev); + _ring_destroy(ipc_shm_name); + } else { /* unlink rings */ snprintf(ipc_shm_name, sizeof(ipc_shm_name), "%s_s_cons", dev); shm = odp_shm_lookup(ipc_shm_name); diff --git a/platform/linux-generic/pktio/ring.c b/platform/linux-generic/pktio/ring.c index d2f16a5..af24779 100644 --- a/platform/linux-generic/pktio/ring.c +++ b/platform/linux-generic/pktio/ring.c @@ -209,6 +209,22 @@ _ring_create(const char *name, unsigned count, unsigned flags) return r; } +int _ring_destroy(const char *name) +{ + odp_shm_t shm = odp_shm_lookup(name); + + if (shm != ODP_SHM_INVALID) { + _ring_t *r = odp_shm_addr(shm); + + odp_rwlock_write_lock(&qlock); + TAILQ_REMOVE(&odp_ring_list, r, next); + odp_rwlock_write_unlock(&qlock); + + return odp_shm_free(shm); + } + return 0; +} + /* * change the high water mark. If *count* is 0, water marking is * disabled diff --git a/platform/linux-generic/test/ring/ring_basic.c b/platform/linux-generic/test/ring/ring_basic.c index 19e24f1..926dc46 100644 --- a/platform/linux-generic/test/ring/ring_basic.c +++ b/platform/linux-generic/test/ring/ring_basic.c @@ -66,6 +66,9 @@ int ring_test_basic_start(void) int ring_test_basic_end(void) { + _ring_destroy(st_ring_name); + _ring_destroy(mt_ring_name); + free(test_enq_data); free(test_deq_data); return 0; diff --git a/platform/linux-generic/test/ring/ring_stress.c b/platform/linux-generic/test/ring/ring_stress.c index c68419f..af7d23d 100644 --- a/platform/linux-generic/test/ring/ring_stress.c +++ b/platform/linux-generic/test/ring/ring_stress.c @@ -84,6 +84,8 @@ int ring_test_stress_end(void) { odp_shm_t shared; + _ring_destroy(ring_name); + /* release consume atomic count */ shared = odp_shm_lookup(consume_count_name); if (shared != ODP_SHM_INVALID)