lib: update tailq api

Signed-off-by: Intel
This commit is contained in:
Intel 2012-12-20 00:00:00 +01:00 committed by Thomas Monjalon
parent dd1a95f295
commit 30a37273c1
14 changed files with 426 additions and 170 deletions

@ -40,6 +40,8 @@
#include <cmdline_parse.h>
#include <rte_eal.h>
#include <rte_eal_memconfig.h>
#include <rte_string_fns.h>
#include <rte_tailq.h>
@ -51,7 +53,7 @@
return 1; \
} while (0)
#define DEFAULT_TAILQ "dummy_q0"
#define DEFAULT_TAILQ (RTE_TAILQ_NUM)
static struct rte_dummy d_elem;
@ -59,33 +61,31 @@ static int
test_tailq_create(void)
{
struct rte_dummy_head *d_head;
char name[RTE_TAILQ_NAMESIZE];
unsigned i;
/* create a first tailq and check its non-null */
d_head = RTE_TAILQ_RESERVE(DEFAULT_TAILQ, rte_dummy_head);
d_head = RTE_TAILQ_RESERVE_BY_IDX(DEFAULT_TAILQ, rte_dummy_head);
if (d_head == NULL)
do_return("Error allocating "DEFAULT_TAILQ"\n");
do_return("Error allocating dummy_q0\n");
/* check we can add an item to it
*/
TAILQ_INSERT_TAIL(d_head, &d_elem, next);
/* try allocating dummy_q0 again, and check for failure */
if (RTE_TAILQ_RESERVE(DEFAULT_TAILQ, rte_dummy_head) != NULL)
if (RTE_TAILQ_RESERVE_BY_IDX(DEFAULT_TAILQ, rte_dummy_head) == NULL)
do_return("Error, non-null result returned when attemption to "
"re-allocate a tailq\n");
/* now fill up the tailq slots available and check we get an error */
for (i = 1; i < RTE_MAX_TAILQ; i++){
rte_snprintf(name, sizeof(name), "dummy_q%u", i);
if ((d_head = RTE_TAILQ_RESERVE(name, rte_dummy_head)) == NULL)
for (i = RTE_TAILQ_NUM; i < RTE_MAX_TAILQ; i++){
if ((d_head = RTE_TAILQ_RESERVE_BY_IDX(i, rte_dummy_head)) == NULL)
break;
}
/* check that we had an error return before RTE_MAX_TAILQ */
if (i == RTE_MAX_TAILQ)
do_return("Error, we did not have a reservation failure as expected\n");
if (i != RTE_MAX_TAILQ)
do_return("Error, we did not have a reservation as expected\n");
return 0;
}
@ -97,7 +97,7 @@ test_tailq_lookup(void)
struct rte_dummy_head *d_head;
struct rte_dummy *d_ptr;
d_head = RTE_TAILQ_LOOKUP(DEFAULT_TAILQ, rte_dummy_head);
d_head = RTE_TAILQ_LOOKUP_BY_IDX(DEFAULT_TAILQ, rte_dummy_head);
if (d_head == NULL)
do_return("Error with tailq lookup\n");
@ -107,7 +107,7 @@ test_tailq_lookup(void)
"expected element not found\n");
/* now try a bad/error lookup */
d_head = RTE_TAILQ_LOOKUP("does_not_exist_queue", rte_dummy_head);
d_head = RTE_TAILQ_LOOKUP_BY_IDX(RTE_MAX_TAILQ, rte_dummy_head);
if (d_head != NULL)
do_return("Error, lookup does not return NULL for bad tailq name\n");

@ -37,7 +37,7 @@ INC += rte_cycles.h rte_debug.h rte_eal.h rte_errno.h rte_launch.h rte_lcore.h
INC += rte_log.h rte_memcpy.h rte_memory.h rte_memzone.h rte_pci.h
INC += rte_pci_dev_ids.h rte_per_lcore.h rte_prefetch.h rte_random.h
INC += rte_rwlock.h rte_spinlock.h rte_tailq.h rte_interrupts.h rte_alarm.h
INC += rte_string_fns.h rte_cpuflags.h rte_version.h
INC += rte_string_fns.h rte_cpuflags.h rte_version.h rte_tailq_elem.h
INC += rte_eal_memconfig.h
ifeq ($(CONFIG_RTE_INSECURE_FUNCTION_WARNING),y)

@ -38,12 +38,14 @@
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <inttypes.h>
#include <rte_memory.h>
#include <rte_memzone.h>
#include <rte_launch.h>
#include <rte_tailq.h>
#include <rte_eal.h>
#include <rte_eal_memconfig.h>
#include <rte_per_lcore.h>
#include <rte_lcore.h>
#include <rte_memory.h>
@ -51,9 +53,16 @@
#include <rte_branch_prediction.h>
#include <rte_log.h>
#include <rte_string_fns.h>
#include "eal_private.h"
static unsigned tailq_idx = 0;
/**
* Name of tailq_head
*/
const char* rte_tailq_names[RTE_MAX_TAILQ] = {
#define rte_tailq_elem(idx, name) name,
#include <rte_tailq_elem.h>
};
struct rte_tailq_head *
rte_eal_tailq_lookup(const char *name)
@ -61,52 +70,76 @@ rte_eal_tailq_lookup(const char *name)
unsigned i;
struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
/*
* the algorithm is not optimal (linear), but there are few
* tailq's and this function should be called at init only
*/
if (name == NULL)
return NULL;
for (i = 0; i < RTE_MAX_TAILQ; i++) {
if (!strncmp(name, mcfg->tailq_head[i].qname, RTE_TAILQ_NAMESIZE-1))
if (rte_tailq_names[i] == NULL)
continue;
if (!strncmp(name, rte_tailq_names[i], RTE_TAILQ_NAMESIZE-1))
return &mcfg->tailq_head[i];
}
return NULL;
}
inline struct rte_tailq_head *
rte_eal_tailq_lookup_by_idx(const unsigned tailq_idx)
{
struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
if (tailq_idx >= RTE_MAX_TAILQ) {
RTE_LOG(ERR, EAL, "%s(): No more room in config\n", __func__);
return NULL;
}
return &mcfg->tailq_head[tailq_idx];
}
struct rte_tailq_head *
rte_eal_tailq_reserve(const char *name)
{
struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
return rte_eal_tailq_lookup(name);
}
if (rte_eal_process_type() == RTE_PROC_SECONDARY)
return rte_eal_tailq_lookup(name);
inline struct rte_tailq_head *
rte_eal_tailq_reserve_by_idx(const unsigned tailq_idx)
{
return rte_eal_tailq_lookup_by_idx(tailq_idx);
}
if (tailq_idx == RTE_MAX_TAILQ){
RTE_LOG(ERR, EAL, "%s(): No more room in config\n", __func__);
return NULL;
void
rte_dump_tailq(void)
{
struct rte_mem_config *mcfg;
unsigned i = 0;
mcfg = rte_eal_get_configuration()->mem_config;
for (i=0; i < RTE_MAX_TAILQ; i++) {
const struct rte_tailq_head *tailq = &mcfg->tailq_head[i];
const struct rte_dummy_head *head = &tailq->tailq_head;
printf("Tailq %o: qname:<%s>, tqh_first:%p, tqh_last:%p\n", i,
(rte_tailq_names[i] != NULL ? rte_tailq_names[i]:"nil"),
head->tqh_first, head->tqh_last);
}
/* zone already exist */
if (rte_eal_tailq_lookup(name) != NULL) {
RTE_LOG(DEBUG, EAL, "%s(): tailq <%s> already exists\n",
__func__, name);
return NULL;
}
rte_snprintf(mcfg->tailq_head[tailq_idx].qname, RTE_TAILQ_NAMESIZE,
"%.*s", (int)(RTE_TAILQ_NAMESIZE - 1), name);
return &mcfg->tailq_head[tailq_idx++];
}
int
rte_eal_tailqs_init(void)
{
unsigned i;
struct rte_config *cfg = rte_eal_get_configuration();
struct rte_mem_config *mcfg = NULL;
if (rte_eal_process_type() == RTE_PROC_PRIMARY)
RTE_BUILD_BUG_ON(RTE_MAX_TAILQ < RTE_TAILQ_NUM);
if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
mcfg = rte_eal_get_configuration()->mem_config;
for (i = 0; i < RTE_MAX_TAILQ; i++)
TAILQ_INIT(&cfg->mem_config->tailq_head[i].tailq_head);
TAILQ_INIT(&mcfg->tailq_head[i].tailq_head);
}
return 0;
}

@ -147,6 +147,60 @@ enum rte_proc_type_t rte_eal_process_type(void);
*/
int rte_eal_init(int argc, char **argv);
/**
* Utility macro to do a tailq 'INSERT' of rte_mem_config
*
* @param idx
* a kind of tailq define in enum rte_tailq_t
*
* @param type
* type of list(tailq head)
*
* @param elm
* The element will be added into the list
*
*/
#define RTE_EAL_TAILQ_INSERT_TAIL(idx, type, elm) do { \
struct type *list; \
list = RTE_TAILQ_LOOKUP_BY_IDX(idx, type); \
TAILQ_INSERT_TAIL(list, elm, next); \
} while (0)
/**
* Utility macro to do a tailq 'REMOVE' of rte_mem_config
*
* @param idx
* a kind of tailq define in enum rte_tailq_t
*
* @param type
* type of list(tailq head)
*
* @param elm
* The element will be remove from the list
*
*/
#define RTE_EAL_TAILQ_REMOVE(idx, type, elm) do { \
struct type *list; \
list = RTE_TAILQ_LOOKUP_BY_IDX(idx, type); \
TAILQ_REMOVE(list, elm, next); \
} while (0) \
/**
* macro to check TAILQ exist
*
* @param idx
* a kind of tailq define in enum rte_tailq_t
*
*/
#define RTE_EAL_TAILQ_EXIST_CHECK(idx) do { \
if (RTE_TAILQ_LOOKUP_BY_IDX(idx, rte_tailq_head) == NULL){ \
rte_errno = E_RTE_NO_TAILQ; \
return NULL; \
} \
} while(0)
#ifdef __cplusplus
}
#endif

@ -43,6 +43,15 @@
extern "C" {
#endif
/**
* Index type of tailq_head
*/
enum rte_tailq_t {
#define rte_tailq_elem(idx, name) idx,
#define rte_tailq_end(idx) idx
#include <rte_tailq_elem.h>
};
/**
* the structure for the memory configuration for the RTE.
* Used by the rte_config structure. It is separated out, as for multi-process

@ -37,17 +37,16 @@
/**
* @file
* Here defines rte_tailq APIs for only internal use
*
*/
#ifdef __cplusplus
extern "C" {
#endif
#include <sys/queue.h>
#ifndef __KERNEL__
/** dummy structure type used by the rte_tailq APIs */
struct rte_dummy {
TAILQ_ENTRY(rte_dummy) next; /**< Pointer entries for a tailq list */
@ -67,11 +66,7 @@ TAILQ_HEAD(rte_dummy_head, rte_dummy);
*/
struct rte_tailq_head {
struct rte_dummy_head tailq_head; /**< NOTE: must be first element */
char qname[RTE_TAILQ_NAMESIZE]; /**< Queue name */
};
#else
struct rte_tailq_head {};
#endif
/**
* Utility macro to make reserving a tailqueue for a particular struct easier.
@ -92,11 +87,31 @@ struct rte_tailq_head {};
#define RTE_TAILQ_RESERVE(name, struct_name) \
(struct struct_name *)(&rte_eal_tailq_reserve(name)->tailq_head)
/**
* Utility macro to make reserving a tailqueue for a particular struct easier.
*
* @param idx
* The tailq idx defined in rte_tail_t to be given to the tail queue.
* - used by lookup to find it later
*
* @param struct_name
* The name of the list type we are using. (Generally this is the same as the
* first parameter passed to TAILQ_HEAD macro)
*
* @return
* The return value from rte_eal_tailq_reserve, typecast to the appropriate
* structure pointer type.
* NULL on error, since the tailq_head is the first
* element in the rte_tailq_head structure.
*/
#define RTE_TAILQ_RESERVE_BY_IDX(idx, struct_name) \
(struct struct_name *)(&rte_eal_tailq_reserve_by_idx(idx)->tailq_head)
/**
* Utility macro to make looking up a tailqueue for a particular struct easier.
*
* @param name
* The name of the tailq
* The name of tailq
*
* @param struct_name
* The name of the list type we are using. (Generally this is the same as the
@ -111,6 +126,25 @@ struct rte_tailq_head {};
#define RTE_TAILQ_LOOKUP(name, struct_name) \
(struct struct_name *)(&rte_eal_tailq_lookup(name)->tailq_head)
/**
* Utility macro to make looking up a tailqueue for a particular struct easier.
*
* @param idx
* The tailq idx defined in rte_tail_t to be given to the tail queue.
*
* @param struct_name
* The name of the list type we are using. (Generally this is the same as the
* first parameter passed to TAILQ_HEAD macro)
*
* @return
* The return value from rte_eal_tailq_lookup, typecast to the appropriate
* structure pointer type.
* NULL on error, since the tailq_head is the first
* element in the rte_tailq_head structure.
*/
#define RTE_TAILQ_LOOKUP_BY_IDX(idx, struct_name) \
(struct struct_name *)(&rte_eal_tailq_lookup_by_idx(idx)->tailq_head)
/**
* Reserve a slot in the tailq list for a particular tailq header
* Note: this function, along with rte_tailq_lookup, is not multi-thread safe,
@ -123,6 +157,23 @@ struct rte_tailq_head {};
*/
struct rte_tailq_head *rte_eal_tailq_reserve(const char *name);
/**
* Reserve a slot in the tailq list for a particular tailq header
* Note: this function, along with rte_tailq_lookup, is not multi-thread safe,
* and both these functions should only be called from a single thread at a time
*
* @param idx
* The tailq idx defined in rte_tail_t to be given to the tail queue.
* @return
* A pointer to the newly reserved tailq entry
*/
struct rte_tailq_head *rte_eal_tailq_reserve_by_idx(const unsigned idx);
/**
* Dump tail queues to the console.
*/
void rte_dump_tailq(void);
/**
* Lookup for a tail queue.
*
@ -138,6 +189,21 @@ struct rte_tailq_head *rte_eal_tailq_reserve(const char *name);
*/
struct rte_tailq_head *rte_eal_tailq_lookup(const char *name);
/**
* Lookup for a tail queue.
*
* Get a pointer to a tail queue header of an already reserved tail
* queue identified by the name given as an argument.
* Note: this function, along with rte_tailq_reserve, is not multi-thread safe,
* and both these functions should only be called from a single thread at a time
*
* @param idx
* The tailq idx defined in rte_tail_t to be given to the tail queue.
* @return
* A pointer to the tail queue head structure.
*/
struct rte_tailq_head *rte_eal_tailq_lookup_by_idx(const unsigned idx);
#ifdef __cplusplus
}
#endif

@ -0,0 +1,83 @@
/*-
* BSD LICENSE
*
* Copyright(c) 2010-2012 Intel Corporation. All rights reserved.
* All rights reserved.
*
* 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.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/**
* @file
*
* This file contains the type of the tailq elem recognised by DPDK, which
* can be used to fill out an array of structures describing the tailq.
*
* In order to populate an array, the user of this file must define this macro:
* rte_tailq_elem(idx, name). For example:
*
* @code
* enum rte_tailq_t {
* #define rte_tailq_elem(idx, name) idx,
* #define rte_tailq_end(idx) idx
* #include <rte_tailq_elem.h>
* };
*
* const char* rte_tailq_names[RTE_MAX_TAILQ] = {
* #define rte_tailq_elem(idx, name) name,
* #include <rte_tailq_elem.h>
* };
* @endcode
*
* Note that this file can be included multiple times within the same file.
*/
#ifndef rte_tailq_elem
#define rte_tailq_elem(idx, name)
#endif /* rte_tailq_elem */
#ifndef rte_tailq_end
#define rte_tailq_end(idx)
#endif /* rte_tailq_end */
rte_tailq_elem(RTE_TAILQ_PCI, "PCI_RESOURCE_LIST")
rte_tailq_elem(RTE_TAILQ_MEMPOOL, "RTE_MEMPOOL")
rte_tailq_elem(RTE_TAILQ_RING, "RTE_RING")
rte_tailq_elem(RTE_TAILQ_HASH, "RTE_HASH")
rte_tailq_elem(RTE_TAILQ_FBK_HASH, "RTE_FBK_HASH")
rte_tailq_elem(RTE_TAILQ_LPM, "RTE_LPM")
rte_tailq_end(RTE_TAILQ_NUM)
#undef rte_tailq_elem
#undef rte_tailq_end

@ -49,9 +49,11 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <stdarg.h>
#include <errno.h>
#ifdef RTE_LIBRTE_EAL_LINUXAPP
#include <dirent.h>
#endif
/* rte_snprintf uses snprintf, so include its definition before we poison the
* functions, otherwise we'll get an error in it. */

@ -59,6 +59,7 @@
#include <rte_memzone.h>
#include <rte_tailq.h>
#include <rte_eal.h>
#include <rte_eal_memconfig.h>
#include <rte_per_lcore.h>
#include <rte_lcore.h>
#include <rte_malloc.h>
@ -724,7 +725,7 @@ rte_eal_pci_init(void)
{
TAILQ_INIT(&driver_list);
TAILQ_INIT(&device_list);
uio_res_list = RTE_TAILQ_RESERVE("PCI_RESOURCE_LIST", uio_res_list);
uio_res_list = RTE_TAILQ_RESERVE_BY_IDX(RTE_TAILQ_PCI, uio_res_list);
/* for debug purposes, PCI can be disabled */
if (internal_config.no_pci)

@ -44,6 +44,7 @@
#include <rte_tailq.h>
#include <rte_eal.h>
#include <rte_hash_crc.h>
#include <rte_eal_memconfig.h>
#include <rte_malloc.h>
#include <rte_common.h>
#include <rte_per_lcore.h>
@ -58,20 +59,6 @@
TAILQ_HEAD(rte_fbk_hash_list, rte_fbk_hash_table);
/* global list of fbk_hashes (used for debug/dump) */
static struct rte_fbk_hash_list *fbk_hash_list = NULL;
/* macro to prevent duplication of list creation check code */
#define CHECK_FBK_HASH_LIST_CREATED() do { \
if (fbk_hash_list == NULL) \
if ((fbk_hash_list = RTE_TAILQ_RESERVE("RTE_FBK_HASH", \
rte_fbk_hash_list)) == NULL){ \
rte_errno = E_RTE_NO_TAILQ; \
return NULL; \
} \
} while (0)
/**
* Performs a lookup for an existing hash table, and returns a pointer to
* the table if found.
@ -86,9 +73,14 @@ struct rte_fbk_hash_table *
rte_fbk_hash_find_existing(const char *name)
{
struct rte_fbk_hash_table *h;
struct rte_fbk_hash_list *fbk_hash_list;
/* check that we have an initialised tail queue */
CHECK_FBK_HASH_LIST_CREATED();
if ((fbk_hash_list =
RTE_TAILQ_LOOKUP_BY_IDX(RTE_TAILQ_FBK_HASH, rte_fbk_hash_list)) == NULL) {
rte_errno = E_RTE_NO_TAILQ;
return NULL;
}
TAILQ_FOREACH(h, fbk_hash_list, next) {
if (strncmp(name, h->name, RTE_FBK_HASH_NAMESIZE) == 0)
@ -112,20 +104,19 @@ rte_fbk_hash_find_existing(const char *name)
struct rte_fbk_hash_table *
rte_fbk_hash_create(const struct rte_fbk_hash_params *params)
{
struct rte_fbk_hash_table *ht;
struct rte_fbk_hash_table *ht = NULL;
char hash_name[RTE_FBK_HASH_NAMESIZE];
const uint32_t mem_size =
sizeof(*ht) + (sizeof(ht->t[0]) * params->entries);
uint32_t i;
/* check that we have access to create things in shared memory. */
if (rte_eal_process_type() == RTE_PROC_SECONDARY){
rte_errno = E_RTE_SECONDARY;
return NULL;
}
struct rte_fbk_hash_list *fbk_hash_list;
/* check that we have an initialised tail queue */
CHECK_FBK_HASH_LIST_CREATED();
if ((fbk_hash_list =
RTE_TAILQ_LOOKUP_BY_IDX(RTE_TAILQ_FBK_HASH, rte_fbk_hash_list)) == NULL) {
rte_errno = E_RTE_NO_TAILQ;
return NULL;
}
/* Error checking of parameters. */
if ((!rte_is_power_of_2(params->entries)) ||
@ -141,6 +132,14 @@ rte_fbk_hash_create(const struct rte_fbk_hash_params *params)
rte_snprintf(hash_name, sizeof(hash_name), "FBK_%s", params->name);
/* guarantee there's no existing */
TAILQ_FOREACH(ht, fbk_hash_list, next) {
if (strncmp(params->name, ht->name, RTE_FBK_HASH_NAMESIZE) == 0)
break;
}
if (ht != NULL)
return NULL;
/* Allocate memory for table. */
#if defined(RTE_LIBRTE_HASH_USE_MEMZONE)
const struct rte_memzone *mz;
@ -198,9 +197,10 @@ rte_fbk_hash_free(struct rte_fbk_hash_table *ht)
{
if (ht == NULL)
return;
/* No way to deallocate memzones - but can de-allocate from malloc */
#if !defined(RTE_LIBRTE_HASH_USE_MEMZONE)
TAILQ_REMOVE(fbk_hash_list, ht, next);
RTE_EAL_TAILQ_REMOVE(RTE_TAILQ_FBK_HASH, rte_fbk_hash_list, ht);
rte_free(ht);
#endif
RTE_SET_USED(ht);

@ -49,6 +49,7 @@
#include <rte_malloc.h>
#include <rte_tailq.h>
#include <rte_eal.h>
#include <rte_eal_memconfig.h>
#include <rte_per_lcore.h>
#include <rte_errno.h>
#include <rte_string_fns.h>
@ -62,18 +63,6 @@
TAILQ_HEAD(rte_hash_list, rte_hash);
/* global list of hashes (used for debug/dump) */
static struct rte_hash_list *hash_list;
/* macro to prevent duplication of list creation check code */
#define CHECK_HASH_LIST_CREATED() do { \
if (hash_list == NULL) \
if ((hash_list = RTE_TAILQ_RESERVE("RTE_HASH", rte_hash_list)) == NULL){ \
rte_errno = E_RTE_NO_TAILQ; \
return NULL; \
} \
} while (0)
/* Macro to enable/disable run-time checking of function parameters */
#if defined(RTE_LIBRTE_HASH_DEBUG)
#define RETURN_IF_TRUE(cond, retval) do { \
@ -148,9 +137,13 @@ struct rte_hash *
rte_hash_find_existing(const char *name)
{
struct rte_hash *h;
struct rte_hash_list *hash_list;
/* check that we have an initialised tail queue */
CHECK_HASH_LIST_CREATED();
if ((hash_list = RTE_TAILQ_LOOKUP_BY_IDX(RTE_TAILQ_HASH, rte_hash_list)) == NULL) {
rte_errno = E_RTE_NO_TAILQ;
return NULL;
}
TAILQ_FOREACH(h, hash_list, next) {
if (strncmp(name, h->name, RTE_HASH_NAMESIZE) == 0)
@ -168,14 +161,14 @@ rte_hash_create(const struct rte_hash_parameters *params)
uint32_t num_buckets, sig_bucket_size, key_size,
hash_tbl_size, sig_tbl_size, key_tbl_size, mem_size;
char hash_name[RTE_HASH_NAMESIZE];
if (rte_eal_process_type() == RTE_PROC_SECONDARY){
rte_errno = E_RTE_SECONDARY;
return NULL;
}
struct rte_hash_list *hash_list;
/* check that we have an initialised tail queue */
CHECK_HASH_LIST_CREATED();
if ((hash_list =
RTE_TAILQ_LOOKUP_BY_IDX(RTE_TAILQ_HASH, rte_hash_list)) == NULL) {
rte_errno = E_RTE_NO_TAILQ;
return NULL;
}
/* Check for valid parameters */
if ((params == NULL) ||
@ -208,6 +201,14 @@ rte_hash_create(const struct rte_hash_parameters *params)
/* Total memory required for hash context */
mem_size = hash_tbl_size + sig_tbl_size + key_tbl_size;
/* guarantee there's no existing */
TAILQ_FOREACH(h, hash_list, next) {
if (strncmp(params->name, h->name, RTE_HASH_NAMESIZE) == 0)
break;
}
if (h != NULL)
return NULL;
/* Allocate as a memzone, or in normal memory space */
#if defined(RTE_LIBRTE_HASH_USE_MEMZONE)
const struct rte_memzone *mz;
@ -260,8 +261,9 @@ rte_hash_free(struct rte_hash *h)
{
if (h == NULL)
return;
#if !defined(RTE_LIBRTE_HASH_USE_MEMZONE)
TAILQ_REMOVE(hash_list, h, next);
RTE_EAL_TAILQ_REMOVE(RTE_TAILQ_HASH, rte_hash_list, h);
rte_free(h);
#endif
/* No way to deallocate memzones */

@ -48,6 +48,7 @@
#include <rte_memzone.h>
#include <rte_tailq.h>
#include <rte_eal.h>
#include <rte_eal_memconfig.h>
#include <rte_per_lcore.h>
#include <rte_string_fns.h>
#include <rte_errno.h>
@ -55,18 +56,7 @@
#include "rte_lpm.h"
TAILQ_HEAD(rte_lpm_list, rte_lpm);
/* global list of ring (used for debug/dump) */
static struct rte_lpm_list *lpm_list;
#define CHECK_LPM_LIST_CREATED() do { \
if (lpm_list == NULL) \
if ((lpm_list = RTE_TAILQ_RESERVE("RTE_LPM", rte_lpm_list)) == NULL){ \
rte_errno = E_RTE_NO_TAILQ; \
return NULL; \
} \
} while (0)
#define MAX_DEPTH_TBL24 24
enum valid_flag {
@ -132,9 +122,13 @@ struct rte_lpm *
rte_lpm_find_existing(const char *name)
{
struct rte_lpm *l;
struct rte_lpm_list *lpm_list;
/* check that we have an initialised tail queue */
CHECK_LPM_LIST_CREATED();
if ((lpm_list = RTE_TAILQ_LOOKUP_BY_IDX(RTE_TAILQ_LPM, rte_lpm_list)) == NULL) {
rte_errno = E_RTE_NO_TAILQ;
return NULL;
}
TAILQ_FOREACH(l, lpm_list, next) {
if (strncmp(name, l->name, RTE_LPM_NAMESIZE) == 0)
@ -160,15 +154,14 @@ rte_lpm_create(const char *name, int socket_id, int max_rules,
char mem_name[RTE_LPM_NAMESIZE];
struct rte_lpm *lpm = NULL;
uint32_t mem_size;
/* check that we have access to create things in shared memory. */
if (rte_eal_process_type() == RTE_PROC_SECONDARY){
rte_errno = E_RTE_SECONDARY;
return NULL;
}
struct rte_lpm_list *lpm_list;
/* check that we have an initialised tail queue */
CHECK_LPM_LIST_CREATED();
if ((lpm_list =
RTE_TAILQ_LOOKUP_BY_IDX(RTE_TAILQ_LPM, rte_lpm_list)) == NULL) {
rte_errno = E_RTE_NO_TAILQ;
return NULL;
}
RTE_BUILD_BUG_ON(sizeof(struct rte_lpm_tbl24_entry) != 2);
RTE_BUILD_BUG_ON(sizeof(struct rte_lpm_tbl8_entry) != 2);
@ -195,6 +188,14 @@ rte_lpm_create(const char *name, int socket_id, int max_rules,
/* Determine the amount of memory to allocate. */
mem_size = sizeof(*lpm) + (sizeof(lpm->rules_tbl[0]) * max_rules);
/* guarantee there's no existing */
TAILQ_FOREACH(lpm, lpm_list, next) {
if (strncmp(name, lpm->name, RTE_LPM_NAMESIZE) == 0)
break;
}
if (lpm != NULL)
return NULL;
/* Allocate memory to store the LPM data structures. */
if (mem_location == RTE_LPM_MEMZONE) {
const struct rte_memzone *mz;
@ -243,7 +244,7 @@ rte_lpm_free(struct rte_lpm *lpm)
/* Note: Its is currently not possible to free a memzone. */
if (lpm->mem_location == RTE_LPM_HEAP){
TAILQ_REMOVE(lpm_list, lpm, next);
RTE_EAL_TAILQ_REMOVE(RTE_TAILQ_LPM, rte_lpm_list, lpm);
rte_free(lpm);
}
}

@ -49,6 +49,7 @@
#include <rte_launch.h>
#include <rte_tailq.h>
#include <rte_eal.h>
#include <rte_eal_memconfig.h>
#include <rte_per_lcore.h>
#include <rte_lcore.h>
#include <rte_branch_prediction.h>
@ -60,8 +61,6 @@
TAILQ_HEAD(rte_mempool_list, rte_mempool);
/* global list of mempool (used for debug/dump) */
static struct rte_mempool_list *mempool_list;
/*
* return the greatest common divisor between a and b (fast algorithm)
@ -129,7 +128,7 @@ rte_mempool_create(const char *name, unsigned n, unsigned elt_size,
{
char mz_name[RTE_MEMZONE_NAMESIZE];
char rg_name[RTE_RING_NAMESIZE];
struct rte_mempool *mp;
struct rte_mempool *mp = NULL;
struct rte_ring *r;
const struct rte_memzone *mz;
size_t mempool_size;
@ -157,13 +156,11 @@ rte_mempool_create(const char *name, unsigned n, unsigned elt_size,
#endif
/* check that we have an initialised tail queue */
if (mempool_list == NULL)
if ((mempool_list = RTE_TAILQ_RESERVE("RTE_MEMPOOL", \
rte_mempool_list)) == NULL){
rte_errno = E_RTE_NO_TAILQ;
return NULL;
}
if (RTE_TAILQ_LOOKUP_BY_IDX(RTE_TAILQ_MEMPOOL, rte_mempool_list) == NULL) {
rte_errno = E_RTE_NO_TAILQ;
return NULL;
}
/* asked cache too big */
if (cache_size > RTE_MEMPOOL_CACHE_MAX_SIZE){
rte_errno = EINVAL;
@ -289,7 +286,8 @@ rte_mempool_create(const char *name, unsigned n, unsigned elt_size,
obj = (char *)obj + elt_size + trailer_size;
}
TAILQ_INSERT_TAIL(mempool_list, mp, next);
RTE_EAL_TAILQ_INSERT_TAIL(RTE_TAILQ_MEMPOOL, rte_mempool_list, mp);
return mp;
}
@ -459,6 +457,13 @@ void
rte_mempool_list_dump(void)
{
const struct rte_mempool *mp = NULL;
struct rte_mempool_list *mempool_list;
if ((mempool_list =
RTE_TAILQ_LOOKUP_BY_IDX(RTE_TAILQ_MEMPOOL, rte_mempool_list)) == NULL) {
rte_errno = E_RTE_NO_TAILQ;
return;
}
TAILQ_FOREACH(mp, mempool_list, next) {
rte_mempool_dump(mp);
@ -470,14 +475,13 @@ struct rte_mempool *
rte_mempool_lookup(const char *name)
{
struct rte_mempool *mp = NULL;
struct rte_mempool_list *mempool_list;
/* check that we have an initialised tail queue */
if (mempool_list == NULL)
if ((mempool_list = RTE_TAILQ_RESERVE("RTE_MEMPOOL", \
rte_mempool_list)) == NULL){
rte_errno = E_RTE_NO_TAILQ;
return NULL;
}
if ((mempool_list =
RTE_TAILQ_LOOKUP_BY_IDX(RTE_TAILQ_MEMPOOL, rte_mempool_list)) == NULL) {
rte_errno = E_RTE_NO_TAILQ;
return NULL;
}
TAILQ_FOREACH(mp, mempool_list, next) {
if (strncmp(name, mp->name, RTE_MEMPOOL_NAMESIZE) == 0)

@ -79,6 +79,7 @@
#include <rte_launch.h>
#include <rte_tailq.h>
#include <rte_eal.h>
#include <rte_eal_memconfig.h>
#include <rte_atomic.h>
#include <rte_per_lcore.h>
#include <rte_lcore.h>
@ -90,9 +91,6 @@
TAILQ_HEAD(rte_ring_list, rte_ring);
/* global list of ring (used for debug/dump) */
static struct rte_ring_list *ring_list = NULL;
/* true if x is a power of 2 */
#define POWEROF2(x) ((((x)-1) & (x)) == 0)
@ -106,6 +104,7 @@ rte_ring_create(const char *name, unsigned count, int socket_id,
const struct rte_memzone *mz;
size_t ring_size;
int mz_flags = 0;
struct rte_ring_list* ring_list = NULL;
/* compilation-time checks */
RTE_BUILD_BUG_ON((sizeof(struct rte_ring) &
@ -122,11 +121,11 @@ rte_ring_create(const char *name, unsigned count, int socket_id,
#endif
/* check that we have an initialised tail queue */
if (ring_list == NULL)
if ((ring_list = RTE_TAILQ_RESERVE("RTE_RING", rte_ring_list)) == NULL){
rte_errno = E_RTE_NO_TAILQ;
return NULL;
}
if ((ring_list =
RTE_TAILQ_LOOKUP_BY_IDX(RTE_TAILQ_RING, rte_ring_list)) == NULL) {
rte_errno = E_RTE_NO_TAILQ;
return NULL;
}
/* count must be a power of 2 */
if (!POWEROF2(count)) {
@ -142,27 +141,27 @@ rte_ring_create(const char *name, unsigned count, int socket_id,
* we are secondary process, the memzone_reserve function will set
* rte_errno for us appropriately - hence no check in this this function */
mz = rte_memzone_reserve(mz_name, ring_size, socket_id, mz_flags);
if (mz == NULL) {
if (mz != NULL) {
r = mz->addr;
/* init the ring structure */
memset(r, 0, sizeof(*r));
rte_snprintf(r->name, sizeof(r->name), "%s", name);
r->flags = flags;
r->prod.watermark = count;
r->prod.sp_enqueue = !!(flags & RING_F_SP_ENQ);
r->cons.sc_dequeue = !!(flags & RING_F_SC_DEQ);
r->prod.size = r->cons.size = count;
r->prod.mask = r->cons.mask = count-1;
r->prod.head = r->cons.head = 0;
r->prod.tail = r->cons.tail = 0;
TAILQ_INSERT_TAIL(ring_list, r, next);
} else {
r = NULL;
RTE_LOG(ERR, RING, "Cannot reserve memory\n");
return NULL;
}
r = mz->addr;
/* init the ring structure */
memset(r, 0, sizeof(*r));
rte_snprintf(r->name, sizeof(r->name), "%s", name);
r->flags = flags;
r->prod.bulk_default = r->cons.bulk_default = 1;
r->prod.watermark = count;
r->prod.sp_enqueue = !!(flags & RING_F_SP_ENQ);
r->cons.sc_dequeue = !!(flags & RING_F_SC_DEQ);
r->prod.size = r->cons.size = count;
r->prod.mask = r->cons.mask = count-1;
r->prod.head = r->cons.head = 0;
r->prod.tail = r->cons.tail = 0;
TAILQ_INSERT_TAIL(ring_list, r, next);
return r;
}
@ -244,13 +243,14 @@ void
rte_ring_list_dump(void)
{
const struct rte_ring *mp;
struct rte_ring_list *ring_list;
/* check that we have an initialised tail queue */
if (ring_list == NULL)
if ((ring_list = RTE_TAILQ_RESERVE("RTE_RING", rte_ring_list)) == NULL){
rte_errno = E_RTE_NO_TAILQ;
return;
}
if ((ring_list =
RTE_TAILQ_LOOKUP_BY_IDX(RTE_TAILQ_RING, rte_ring_list)) == NULL) {
rte_errno = E_RTE_NO_TAILQ;
return;
}
TAILQ_FOREACH(mp, ring_list, next) {
rte_ring_dump(mp);
@ -262,13 +262,14 @@ struct rte_ring *
rte_ring_lookup(const char *name)
{
struct rte_ring *r;
struct rte_ring_list *ring_list;
/* check that we have an initialised tail queue */
if (ring_list == NULL)
if ((ring_list = RTE_TAILQ_RESERVE("RTE_RING", rte_ring_list)) == NULL){
rte_errno = E_RTE_NO_TAILQ;
return NULL;
}
/* check that we have an initialized tail queue */
if ((ring_list =
RTE_TAILQ_LOOKUP_BY_IDX(RTE_TAILQ_RING, rte_ring_list)) == NULL) {
rte_errno = E_RTE_NO_TAILQ;
return NULL;
}
TAILQ_FOREACH(r, ring_list, next) {
if (strncmp(name, r->name, RTE_RING_NAMESIZE) == 0)