Lines 9-39
Link Here
|
9 |
#include <rte_string_fns.h> |
9 |
#include <rte_string_fns.h> |
10 |
#include <rte_mempool.h> |
10 |
#include <rte_mempool.h> |
11 |
#include <rte_errno.h> |
11 |
#include <rte_errno.h> |
12 |
#include <rte_dev.h> |
|
|
13 |
|
12 |
|
14 |
#include "rte_mempool_trace.h" |
13 |
#include "rte_mempool_trace.h" |
15 |
|
14 |
|
|
|
15 |
#define RTE_MEMPOOL_OPS_MZNAME "rte_mempool_ops" |
16 |
|
16 |
/* indirect jump table to support external memory pools. */ |
17 |
/* indirect jump table to support external memory pools. */ |
17 |
struct rte_mempool_ops_table rte_mempool_ops_table = { |
18 |
struct rte_mempool_ops_table rte_mempool_ops_table = { |
18 |
.sl = RTE_SPINLOCK_INITIALIZER, |
19 |
.sl = RTE_SPINLOCK_INITIALIZER, |
19 |
.num_ops = 0 |
20 |
.num_ops = 0 |
20 |
}; |
21 |
}; |
21 |
|
22 |
|
|
|
23 |
/* shared mempool ops table, for multiprocess support */ |
24 |
struct rte_mempool_shared_ops_table { |
25 |
size_t count; |
26 |
struct { |
27 |
char name[RTE_MEMPOOL_OPS_NAMESIZE]; |
28 |
} ops[RTE_MEMPOOL_MAX_OPS_IDX]; |
29 |
}; |
30 |
static struct rte_mempool_shared_ops_table *shared_ops_table; |
31 |
|
32 |
/* Allocate and initialize the shared memory. */ |
33 |
static int |
34 |
rte_mempool_ops_shm_init(void) |
35 |
{ |
36 |
const struct rte_memzone *mz; |
37 |
static int saved_ret = -EAGAIN; |
38 |
|
39 |
if (saved_ret != -EAGAIN) |
40 |
return saved_ret; |
41 |
|
42 |
if (rte_eal_process_type() == RTE_PROC_PRIMARY) { |
43 |
mz = rte_memzone_reserve(RTE_MEMPOOL_OPS_MZNAME, |
44 |
sizeof(*shared_ops_table), |
45 |
SOCKET_ID_ANY, 0); |
46 |
if (mz == NULL) { |
47 |
saved_ret = -rte_errno; |
48 |
return saved_ret; |
49 |
} |
50 |
shared_ops_table = mz->addr; |
51 |
memset(shared_ops_table, 0, sizeof(*shared_ops_table)); |
52 |
} else { |
53 |
mz = rte_memzone_lookup(RTE_MEMPOOL_OPS_MZNAME); |
54 |
if (mz == NULL) { |
55 |
saved_ret = -ENOENT; |
56 |
return saved_ret; |
57 |
} |
58 |
shared_ops_table = mz->addr; |
59 |
} |
60 |
|
61 |
saved_ret = 0; |
62 |
return saved_ret; |
63 |
} |
64 |
|
22 |
/* add a new ops struct in rte_mempool_ops_table, return its index. */ |
65 |
/* add a new ops struct in rte_mempool_ops_table, return its index. */ |
23 |
int |
66 |
int |
24 |
rte_mempool_register_ops(const struct rte_mempool_ops *h) |
67 |
rte_mempool_register_ops(const struct rte_mempool_ops *h) |
25 |
{ |
68 |
{ |
26 |
struct rte_mempool_ops *ops; |
69 |
struct rte_mempool_ops *ops; |
27 |
int16_t ops_index; |
70 |
int16_t ops_index; |
|
|
71 |
unsigned int i; |
72 |
int ret; |
28 |
|
73 |
|
29 |
rte_spinlock_lock(&rte_mempool_ops_table.sl); |
74 |
rte_spinlock_lock(&rte_mempool_ops_table.sl); |
30 |
|
75 |
|
31 |
if (rte_mempool_ops_table.num_ops >= |
76 |
ret = rte_mempool_ops_shm_init(); |
32 |
RTE_MEMPOOL_MAX_OPS_IDX) { |
77 |
if (ret < 0) { |
33 |
rte_spinlock_unlock(&rte_mempool_ops_table.sl); |
78 |
rte_spinlock_unlock(&rte_mempool_ops_table.sl); |
34 |
RTE_LOG(ERR, MEMPOOL, |
79 |
RTE_LOG(ERR, MEMPOOL, |
35 |
"Maximum number of mempool ops structs exceeded\n"); |
80 |
"Failed to register shared memzone for mempool ops: %s\n", |
36 |
return -ENOSPC; |
81 |
strerror(-ret)); |
|
|
82 |
return ret; |
37 |
} |
83 |
} |
38 |
|
84 |
|
39 |
if (h->alloc == NULL || h->enqueue == NULL || |
85 |
if (h->alloc == NULL || h->enqueue == NULL || |
Lines 46-58
rte_mempool_register_ops(const struct rte_mempool_ops *h)
Link Here
|
46 |
|
92 |
|
47 |
if (strlen(h->name) >= sizeof(ops->name) - 1) { |
93 |
if (strlen(h->name) >= sizeof(ops->name) - 1) { |
48 |
rte_spinlock_unlock(&rte_mempool_ops_table.sl); |
94 |
rte_spinlock_unlock(&rte_mempool_ops_table.sl); |
49 |
RTE_LOG(DEBUG, EAL, "%s(): mempool_ops <%s>: name too long\n", |
95 |
RTE_LOG(ERR, MEMPOOL, "%s(): mempool_ops <%s>: name too long\n", |
50 |
__func__, h->name); |
96 |
__func__, h->name); |
51 |
rte_errno = EEXIST; |
97 |
rte_errno = ENAMETOOLONG; |
52 |
return -EEXIST; |
98 |
return -ENAMETOOLONG; |
|
|
99 |
} |
100 |
|
101 |
/* lookup for ops in shared memory */ |
102 |
for (i = 0; i < RTE_MEMPOOL_MAX_OPS_IDX; i++) { |
103 |
if (!strcmp(h->name, shared_ops_table->ops[i].name)) |
104 |
break; |
105 |
} |
106 |
|
107 |
if (rte_eal_process_type() == RTE_PROC_PRIMARY) { |
108 |
if (i < RTE_MEMPOOL_MAX_OPS_IDX) { |
109 |
rte_spinlock_unlock(&rte_mempool_ops_table.sl); |
110 |
RTE_LOG(ERR, MEMPOOL, |
111 |
"%s(): mempool_ops <%s>: already registered\n", |
112 |
__func__, h->name); |
113 |
rte_errno = EEXIST; |
114 |
return -EEXIST; |
115 |
} |
116 |
ops_index = shared_ops_table->count; |
117 |
} else { |
118 |
if (i == RTE_MEMPOOL_MAX_OPS_IDX) { |
119 |
rte_spinlock_unlock(&rte_mempool_ops_table.sl); |
120 |
RTE_LOG(ERR, MEMPOOL, |
121 |
"%s(): mempool_ops <%s>: not registered in primary process\n", |
122 |
__func__, h->name); |
123 |
rte_errno = ENOENT; |
124 |
return -ENOENT; |
125 |
} |
126 |
ops_index = i; |
53 |
} |
127 |
} |
54 |
|
128 |
|
55 |
ops_index = rte_mempool_ops_table.num_ops++; |
129 |
if (ops_index >= RTE_MEMPOOL_MAX_OPS_IDX) { |
|
|
130 |
rte_spinlock_unlock(&rte_mempool_ops_table.sl); |
131 |
RTE_LOG(ERR, MEMPOOL, |
132 |
"Maximum number of mempool ops structs exceeded\n"); |
133 |
rte_errno = ENOSPC; |
134 |
return -ENOSPC; |
135 |
} |
136 |
|
137 |
/* update local table */ |
138 |
rte_mempool_ops_table.num_ops++; |
56 |
ops = &rte_mempool_ops_table.ops[ops_index]; |
139 |
ops = &rte_mempool_ops_table.ops[ops_index]; |
57 |
strlcpy(ops->name, h->name, sizeof(ops->name)); |
140 |
strlcpy(ops->name, h->name, sizeof(ops->name)); |
58 |
ops->alloc = h->alloc; |
141 |
ops->alloc = h->alloc; |
Lines 65-70
rte_mempool_register_ops(const struct rte_mempool_ops *h)
Link Here
|
65 |
ops->get_info = h->get_info; |
148 |
ops->get_info = h->get_info; |
66 |
ops->dequeue_contig_blocks = h->dequeue_contig_blocks; |
149 |
ops->dequeue_contig_blocks = h->dequeue_contig_blocks; |
67 |
|
150 |
|
|
|
151 |
/* update shared memory on primary process */ |
152 |
if (rte_eal_process_type() == RTE_PROC_PRIMARY) { |
153 |
strlcpy(shared_ops_table->ops[ops_index].name, h->name, |
154 |
sizeof(ops->name)); |
155 |
shared_ops_table->count++; |
156 |
} |
157 |
|
68 |
rte_spinlock_unlock(&rte_mempool_ops_table.sl); |
158 |
rte_spinlock_unlock(&rte_mempool_ops_table.sl); |
69 |
|
159 |
|
70 |
return ops_index; |
160 |
return ops_index; |
Lines 171-179
rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name,
Link Here
|
171 |
if (mp->flags & RTE_MEMPOOL_F_POOL_CREATED) |
261 |
if (mp->flags & RTE_MEMPOOL_F_POOL_CREATED) |
172 |
return -EEXIST; |
262 |
return -EEXIST; |
173 |
|
263 |
|
174 |
for (i = 0; i < rte_mempool_ops_table.num_ops; i++) { |
264 |
for (i = 0; i < RTE_MEMPOOL_MAX_OPS_IDX; i++) { |
175 |
if (!strcmp(name, |
265 |
if (!strcmp(name, rte_mempool_ops_table.ops[i].name)) { |
176 |
rte_mempool_ops_table.ops[i].name)) { |
|
|
177 |
ops = &rte_mempool_ops_table.ops[i]; |
266 |
ops = &rte_mempool_ops_table.ops[i]; |
178 |
break; |
267 |
break; |
179 |
} |
268 |
} |