From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 9F8FF2A7 for ; Tue, 17 Jun 2014 17:35:56 +0200 (CEST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP; 17 Jun 2014 08:30:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.01,494,1400050800"; d="scan'208";a="558929101" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga002.jf.intel.com with ESMTP; 17 Jun 2014 08:36:09 -0700 Received: from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com [10.237.217.45]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id s5HFa8To019339; Tue, 17 Jun 2014 16:36:08 +0100 Received: from sivswdev01.ir.intel.com (localhost [127.0.0.1]) by sivswdev01.ir.intel.com with ESMTP id s5HFa8Es031887; Tue, 17 Jun 2014 16:36:08 +0100 Received: (from aburakov@localhost) by sivswdev01.ir.intel.com with id s5HFa8aL031881; Tue, 17 Jun 2014 16:36:08 +0100 From: Anatoly Burakov To: dev@dpdk.org Date: Tue, 17 Jun 2014 16:36:07 +0100 Message-Id: X-Mailer: git-send-email 1.7.0.7 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH 9/9] rte_acl: make acl tailq fully local X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 17 Jun 2014 15:35:57 -0000 Signed-off-by: Anatoly Burakov --- lib/librte_acl/acl.h | 1 - lib/librte_acl/rte_acl.c | 74 +++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 60 insertions(+), 15 deletions(-) diff --git a/lib/librte_acl/acl.h b/lib/librte_acl/acl.h index e6d7985..b9d63fd 100644 --- a/lib/librte_acl/acl.h +++ b/lib/librte_acl/acl.h @@ -149,7 +149,6 @@ struct rte_acl_bld_trie { }; struct rte_acl_ctx { - TAILQ_ENTRY(rte_acl_ctx) next; /**< Next in list. */ char name[RTE_ACL_NAMESIZE]; /** Name of the ACL context. */ int32_t socket_id; diff --git a/lib/librte_acl/rte_acl.c b/lib/librte_acl/rte_acl.c index 129a41f..3b47ab6 100644 --- a/lib/librte_acl/rte_acl.c +++ b/lib/librte_acl/rte_acl.c @@ -36,13 +36,14 @@ #define BIT_SIZEOF(x) (sizeof(x) * CHAR_BIT) -TAILQ_HEAD(rte_acl_list, rte_acl_ctx); +TAILQ_HEAD(rte_acl_list, rte_tailq_entry); struct rte_acl_ctx * rte_acl_find_existing(const char *name) { - struct rte_acl_ctx *ctx; + struct rte_acl_ctx *ctx = NULL; struct rte_acl_list *acl_list; + struct rte_tailq_entry *te; /* check that we have an initialised tail queue */ acl_list = RTE_TAILQ_LOOKUP_BY_IDX(RTE_TAILQ_ACL, rte_acl_list); @@ -52,27 +53,55 @@ rte_acl_find_existing(const char *name) } rte_rwlock_read_lock(RTE_EAL_TAILQ_RWLOCK); - TAILQ_FOREACH(ctx, acl_list, next) { + TAILQ_FOREACH(te, acl_list, next) { + ctx = (struct rte_acl_ctx*) te->data; if (strncmp(name, ctx->name, sizeof(ctx->name)) == 0) break; } rte_rwlock_read_unlock(RTE_EAL_TAILQ_RWLOCK); - if (ctx == NULL) + if (te == NULL) { rte_errno = ENOENT; + return NULL; + } return ctx; } void rte_acl_free(struct rte_acl_ctx *ctx) { + struct rte_acl_list *acl_list; + struct rte_tailq_entry *te; + if (ctx == NULL) return; - RTE_EAL_TAILQ_REMOVE(RTE_TAILQ_ACL, rte_acl_list, ctx); + /* check that we have an initialised tail queue */ + acl_list = RTE_TAILQ_LOOKUP_BY_IDX(RTE_TAILQ_ACL, rte_acl_list); + if (acl_list == NULL) { + rte_errno = E_RTE_NO_TAILQ; + return; + } + + rte_rwlock_write_lock(RTE_EAL_TAILQ_RWLOCK); + + /* find our tailq entry */ + TAILQ_FOREACH(te, acl_list, next) { + if (te->data == (void *) ctx) + break; + } + if (te == NULL) { + rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK); + return; + } + + TAILQ_REMOVE(acl_list, te, next); + + rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK); rte_free(ctx->mem); rte_free(ctx); + rte_free(te); } struct rte_acl_ctx * @@ -81,6 +110,7 @@ rte_acl_create(const struct rte_acl_param *param) size_t sz; struct rte_acl_ctx *ctx; struct rte_acl_list *acl_list; + struct rte_tailq_entry *te; char name[sizeof(ctx->name)]; /* check that we have an initialised tail queue */ @@ -105,15 +135,31 @@ rte_acl_create(const struct rte_acl_param *param) rte_rwlock_write_lock(RTE_EAL_TAILQ_RWLOCK); /* if we already have one with that name */ - TAILQ_FOREACH(ctx, acl_list, next) { + TAILQ_FOREACH(te, acl_list, next) { + ctx = (struct rte_acl_ctx*) te->data; if (strncmp(param->name, ctx->name, sizeof(ctx->name)) == 0) break; } /* if ACL with such name doesn't exist, then create a new one. */ - if (ctx == NULL && (ctx = rte_zmalloc_socket(name, sz, CACHE_LINE_SIZE, - param->socket_id)) != NULL) { + if (te == NULL) { + ctx = NULL; + te = rte_zmalloc("ACL_TAILQ_ENTRY", sizeof(*te), 0); + + if (te == NULL) { + RTE_LOG(ERR, ACL, "Cannot allocate tailq entry!\n"); + goto exit; + } + + ctx = rte_zmalloc_socket(name, sz, CACHE_LINE_SIZE, param->socket_id); + if (ctx == NULL) { + RTE_LOG(ERR, ACL, + "allocation of %zu bytes on socket %d for %s failed\n", + sz, param->socket_id, name); + rte_free(te); + goto exit; + } /* init new allocated context. */ ctx->rules = ctx + 1; ctx->max_rules = param->max_rule_num; @@ -121,14 +167,12 @@ rte_acl_create(const struct rte_acl_param *param) ctx->socket_id = param->socket_id; rte_snprintf(ctx->name, sizeof(ctx->name), "%s", param->name); - TAILQ_INSERT_TAIL(acl_list, ctx, next); + te->data = (void *) ctx; - } else if (ctx == NULL) { - RTE_LOG(ERR, ACL, - "allocation of %zu bytes on socket %d for %s failed\n", - sz, param->socket_id, name); + TAILQ_INSERT_TAIL(acl_list, te, next); } +exit: rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK); return ctx; } @@ -232,6 +276,7 @@ rte_acl_list_dump(void) { struct rte_acl_ctx *ctx; struct rte_acl_list *acl_list; + struct rte_tailq_entry *te; /* check that we have an initialised tail queue */ acl_list = RTE_TAILQ_LOOKUP_BY_IDX(RTE_TAILQ_ACL, rte_acl_list); @@ -241,7 +286,8 @@ rte_acl_list_dump(void) } rte_rwlock_read_lock(RTE_EAL_TAILQ_RWLOCK); - TAILQ_FOREACH(ctx, acl_list, next) { + TAILQ_FOREACH(te, acl_list, next) { + ctx = (struct rte_acl_ctx *) te->data; rte_acl_dump(ctx); } rte_rwlock_read_unlock(RTE_EAL_TAILQ_RWLOCK); -- 1.8.1.4