4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/queue.h>
42 #include <rte_memory.h>
43 #include <rte_memzone.h>
44 #include <rte_launch.h>
46 #include <rte_eal_memconfig.h>
47 #include <rte_per_lcore.h>
48 #include <rte_lcore.h>
49 #include <rte_atomic.h>
50 #include <rte_branch_prediction.h>
52 #include <rte_string_fns.h>
53 #include <rte_debug.h>
55 #include "eal_private.h"
57 TAILQ_HEAD(rte_tailq_elem_head, rte_tailq_elem);
58 /* local tailq list */
59 static struct rte_tailq_elem_head rte_tailq_elem_head =
60 TAILQ_HEAD_INITIALIZER(rte_tailq_elem_head);
62 /* number of tailqs registered, -1 before call to rte_eal_tailqs_init */
63 static int rte_tailqs_count = -1;
65 struct rte_tailq_head *
66 rte_eal_tailq_lookup(const char *name)
69 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
74 for (i = 0; i < RTE_MAX_TAILQ; i++) {
75 if (!strncmp(name, mcfg->tailq_head[i].name,
76 RTE_TAILQ_NAMESIZE-1))
77 return &mcfg->tailq_head[i];
84 rte_dump_tailq(FILE *f)
86 struct rte_mem_config *mcfg;
89 mcfg = rte_eal_get_configuration()->mem_config;
91 rte_rwlock_read_lock(&mcfg->qlock);
92 for (i = 0; i < RTE_MAX_TAILQ; i++) {
93 const struct rte_tailq_head *tailq = &mcfg->tailq_head[i];
94 const struct rte_tailq_entry_head *head = &tailq->tailq_head;
96 fprintf(f, "Tailq %u: qname:<%s>, tqh_first:%p, tqh_last:%p\n",
97 i, tailq->name, head->tqh_first, head->tqh_last);
99 rte_rwlock_read_unlock(&mcfg->qlock);
102 static struct rte_tailq_head *
103 rte_eal_tailq_create(const char *name)
105 struct rte_tailq_head *head = NULL;
107 if (!rte_eal_tailq_lookup(name) &&
108 (rte_tailqs_count + 1 < RTE_MAX_TAILQ)) {
109 struct rte_mem_config *mcfg;
111 mcfg = rte_eal_get_configuration()->mem_config;
112 head = &mcfg->tailq_head[rte_tailqs_count];
113 snprintf(head->name, sizeof(head->name) - 1, "%s", name);
114 TAILQ_INIT(&head->tailq_head);
121 /* local register, used to store "early" tailqs before rte_eal_init() and to
122 * ensure secondary process only registers tailqs once. */
124 rte_eal_tailq_local_register(struct rte_tailq_elem *t)
126 struct rte_tailq_elem *temp;
128 TAILQ_FOREACH(temp, &rte_tailq_elem_head, next) {
129 if (!strncmp(t->name, temp->name, sizeof(temp->name)))
133 TAILQ_INSERT_TAIL(&rte_tailq_elem_head, t, next);
138 rte_eal_tailq_update(struct rte_tailq_elem *t)
140 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
141 /* primary process is the only one that creates */
142 t->head = rte_eal_tailq_create(t->name);
144 t->head = rte_eal_tailq_lookup(t->name);
149 rte_eal_tailq_register(struct rte_tailq_elem *t)
151 if (rte_eal_tailq_local_register(t) < 0) {
153 "%s tailq is already registered\n", t->name);
157 /* if a register happens after rte_eal_tailqs_init(), then we can update
159 if (rte_tailqs_count >= 0) {
160 rte_eal_tailq_update(t);
161 if (t->head == NULL) {
163 "Cannot initialize tailq: %s\n", t->name);
164 TAILQ_REMOVE(&rte_tailq_elem_head, t, next);
177 rte_eal_tailqs_init(void)
179 struct rte_tailq_elem *t;
181 rte_tailqs_count = 0;
183 TAILQ_FOREACH(t, &rte_tailq_elem_head, next) {
184 /* second part of register job for "early" tailqs, see
185 * rte_eal_tailq_register and EAL_REGISTER_TAILQ */
186 rte_eal_tailq_update(t);
187 if (t->head == NULL) {
189 "Cannot initialize tailq: %s\n", t->name);
190 /* TAILQ_REMOVE not needed, error is already fatal */
198 rte_dump_tailq(stderr);