#include <cmdline_parse.h>
+#include <rte_eal.h>
+#include <rte_eal_memconfig.h>
#include <rte_string_fns.h>
#include <rte_tailq.h>
return 1; \
} while (0)
-#define DEFAULT_TAILQ "dummy_q0"
+#define DEFAULT_TAILQ (RTE_TAILQ_NUM)
static struct rte_dummy d_elem;
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;
}
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");
"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");
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)
#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>
#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)
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;
}
-struct rte_tailq_head *
-rte_eal_tailq_reserve(const char *name)
+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 (rte_eal_process_type() == RTE_PROC_SECONDARY)
- return rte_eal_tailq_lookup(name);
-
- if (tailq_idx == RTE_MAX_TAILQ){
+ if (tailq_idx >= RTE_MAX_TAILQ) {
RTE_LOG(ERR, EAL, "%s(): No more room in config\n", __func__);
return NULL;
}
- /* zone already exist */
- if (rte_eal_tailq_lookup(name) != NULL) {
- RTE_LOG(DEBUG, EAL, "%s(): tailq <%s> already exists\n",
- __func__, name);
- return NULL;
- }
+ return &mcfg->tailq_head[tailq_idx];
+}
+
+struct rte_tailq_head *
+rte_eal_tailq_reserve(const char *name)
+{
+ return rte_eal_tailq_lookup(name);
+}
- rte_snprintf(mcfg->tailq_head[tailq_idx].qname, RTE_TAILQ_NAMESIZE,
- "%.*s", (int)(RTE_TAILQ_NAMESIZE - 1), 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);
+}
+
+void
+rte_dump_tailq(void)
+{
+ struct rte_mem_config *mcfg;
+ unsigned i = 0;
- return &mcfg->tailq_head[tailq_idx++];
+ 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);
+ }
}
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;
}
+
*/
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
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
/**
* @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 */
*/
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.
#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
#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,
*/
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.
*
*/
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
--- /dev/null
+/*-
+ * 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
#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. */
#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>
{
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)
#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>
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.
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)
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)) ||
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;
{
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);
#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>
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 { \
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)
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) ||
/* 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;
{
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 */
#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>
#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 {
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)
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);
/* 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;
/* 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);
}
}
#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>
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)
{
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;
#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;
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;
}
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);
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)
#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>
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)
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) &
#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)) {
* 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) {
- RTE_LOG(ERR, RING, "Cannot reserve memory\n");
- return NULL;
- }
-
- r = mz->addr;
+ 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.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;
+ /* 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);
+ TAILQ_INSERT_TAIL(ring_list, r, next);
+ } else {
+ r = NULL;
+ RTE_LOG(ERR, RING, "Cannot reserve memory\n");
+ }
+
return r;
}
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);
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)