From patchwork Thu Jun 2 11:04:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi He X-Patchwork-Id: 69149 Delivered-To: patch@linaro.org Received: by 10.140.106.246 with SMTP id e109csp53865qgf; Thu, 2 Jun 2016 04:05:29 -0700 (PDT) X-Received: by 10.140.128.77 with SMTP id 74mr40677708qha.67.1464865529653; Thu, 02 Jun 2016 04:05:29 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id b23si29521929qkh.75.2016.06.02.04.05.29; Thu, 02 Jun 2016 04:05:29 -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 54CDB6173A; Thu, 2 Jun 2016 11:05:29 +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_H3, RCVD_IN_MSPIKE_WL, 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 8845E61775; Thu, 2 Jun 2016 11:05:06 +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 BF7BC61766; Thu, 2 Jun 2016 11:05:00 +0000 (UTC) Received: from mail-pa0-f42.google.com (mail-pa0-f42.google.com [209.85.220.42]) by lists.linaro.org (Postfix) with ESMTPS id BC45861740 for ; Thu, 2 Jun 2016 11:04:43 +0000 (UTC) Received: by mail-pa0-f42.google.com with SMTP id um11so5123298pab.0 for ; Thu, 02 Jun 2016 04:04:43 -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:in-reply-to :references; bh=njmhYgfe6LTt1h3MFMuEhdj7llVGOnSJTeaNJofJ8Qc=; b=TD98YGeBafRsU8hLV3K1NrKx748JSaXZXiGzleTLM/byBishyP2nIC3AdsiJjEoK4f yLrubz4UOEBCA35vKNgErHHPlpbnTfbz/9nIIeuIE5HsA3KDwzpRdMN5mfKM6qQTDQHr 16B2uMX21fqShMO2q1CzEYiRj0bmDKQTUMpBvYjvHXpWkTnj5IvxWwSgSF4nOx9mSly+ S3iUb4m92yVC4Xfnmc9qnZL4KTezX5lz6WhUnVf1qTB4gMk/60UAVh2aZ713HM89sU4j ITxwJHjISibCFrXIsucPJaJ0tHyPZkabEXG0pbj5BCfEZPG4XswQ8kr/7DC9UJ+SsXka zYmQ== X-Gm-Message-State: ALyK8tKHmtAbDGaSaSOgBK51OQYbFj7lpE5Dm9szST/Ns+fVQmZAEzFswecl6FWjZmYvQnjb90A= X-Received: by 10.66.255.102 with SMTP id ap6mr4707369pad.2.1464865482925; Thu, 02 Jun 2016 04:04:42 -0700 (PDT) Received: from ubuntu.heyii.co (ubuntu.heyii.co. [45.32.66.203]) by smtp.googlemail.com with ESMTPSA id lg17sm69402351pab.36.2016.06.02.04.04.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 02 Jun 2016 04:04:42 -0700 (PDT) From: Yi He To: lng-odp@lists.linaro.org Date: Thu, 2 Jun 2016 11:04:16 +0000 Message-Id: <1464865456-29702-3-git-send-email-yi.he@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1464865456-29702-1-git-send-email-yi.he@linaro.org> References: <1464865456-29702-1-git-send-email-yi.he@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH 3/3] 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 | 17 +++++++++++ platform/linux-generic/test/ring/ring_basic.c | 3 ++ platform/linux-generic/test/ring/ring_stress.c | 1 + 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 90d2216..f1188c3 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 e11da86..0845f41 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..ec27f2c 100644 --- a/platform/linux-generic/pktio/ring.c +++ b/platform/linux-generic/pktio/ring.c @@ -209,6 +209,23 @@ _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); + if (!(r->flags & _RING_NO_LIST)) + 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 8287d35..bc61c3e 100644 --- a/platform/linux-generic/test/ring/ring_stress.c +++ b/platform/linux-generic/test/ring/ring_stress.c @@ -75,6 +75,7 @@ int ring_test_stress_start(void) int ring_test_stress_end(void) { + _ring_destroy(ring_name); return 0; }