View | Details | Raw Unified | Return to bug 1073
Collapse All | Expand All

(-)a/drivers/mempool/bucket/rte_mempool_bucket.c (+1 lines)
Lines 14-19 Link Here
14
#include <rte_errno.h>
14
#include <rte_errno.h>
15
#include <rte_ring.h>
15
#include <rte_ring.h>
16
#include <rte_mempool.h>
16
#include <rte_mempool.h>
17
#include <rte_mempool_driver.h>
17
#include <rte_malloc.h>
18
#include <rte_malloc.h>
18
19
19
/*
20
/*
(-)a/drivers/mempool/cnxk/cn10k_mempool_ops.c (+1 lines)
Lines 3-8 Link Here
3
 */
3
 */
4
4
5
#include <rte_mempool.h>
5
#include <rte_mempool.h>
6
#include <rte_mempool_driver.h>
6
7
7
#include "roc_api.h"
8
#include "roc_api.h"
8
#include "cnxk_mempool.h"
9
#include "cnxk_mempool.h"
(-)a/drivers/mempool/cnxk/cn9k_mempool_ops.c (+1 lines)
Lines 3-8 Link Here
3
 */
3
 */
4
4
5
#include <rte_mempool.h>
5
#include <rte_mempool.h>
6
#include <rte_mempool_driver.h>
6
7
7
#include "roc_api.h"
8
#include "roc_api.h"
8
#include "cnxk_mempool.h"
9
#include "cnxk_mempool.h"
(-)a/drivers/mempool/dpaa/dpaa_mempool.c (+1 lines)
Lines 24-29 Link Here
24
#include <rte_eal.h>
24
#include <rte_eal.h>
25
#include <rte_malloc.h>
25
#include <rte_malloc.h>
26
#include <rte_ring.h>
26
#include <rte_ring.h>
27
#include <rte_mempool_driver.h>
27
28
28
#include <dpaa_mempool.h>
29
#include <dpaa_mempool.h>
29
#include <dpaax_iova_table.h>
30
#include <dpaax_iova_table.h>
(-)a/drivers/mempool/dpaa2/dpaa2_hw_mempool.c (+1 lines)
Lines 22-27 Link Here
22
#include <rte_kvargs.h>
22
#include <rte_kvargs.h>
23
#include <rte_dev.h>
23
#include <rte_dev.h>
24
#include "rte_dpaa2_mempool.h"
24
#include "rte_dpaa2_mempool.h"
25
#include <rte_mempool_driver.h>
25
26
26
#include "fslmc_vfio.h"
27
#include "fslmc_vfio.h"
27
#include <fslmc_logs.h>
28
#include <fslmc_logs.h>
(-)a/drivers/mempool/meson.build (-1 / +1 lines)
Lines 11-16 drivers = [ Link Here
11
        'stack',
11
        'stack',
12
]
12
]
13
13
14
std_deps = ['mempool']
14
std_deps = ['mempool', 'bus_vdev']
15
15
16
log_prefix = 'mempool'
16
log_prefix = 'mempool'
(-)a/drivers/mempool/octeontx/rte_mempool_octeontx.c (+1 lines)
Lines 4-9 Link Here
4
4
5
#include <stdio.h>
5
#include <stdio.h>
6
#include <rte_mempool.h>
6
#include <rte_mempool.h>
7
#include <rte_mempool_driver.h>
7
#include <rte_malloc.h>
8
#include <rte_malloc.h>
8
#include <rte_mbuf.h>
9
#include <rte_mbuf.h>
9
10
(-)a/drivers/mempool/ring/rte_mempool_ring.c (+1 lines)
Lines 8-13 Link Here
8
#include <rte_errno.h>
8
#include <rte_errno.h>
9
#include <rte_ring.h>
9
#include <rte_ring.h>
10
#include <rte_mempool.h>
10
#include <rte_mempool.h>
11
#include <rte_mempool_driver.h>
11
12
12
static int
13
static int
13
common_ring_mp_enqueue(struct rte_mempool *mp, void * const *obj_table,
14
common_ring_mp_enqueue(struct rte_mempool *mp, void * const *obj_table,
(-)a/drivers/mempool/stack/rte_mempool_stack.c (+1 lines)
Lines 4-9 Link Here
4
4
5
#include <stdio.h>
5
#include <stdio.h>
6
#include <rte_mempool.h>
6
#include <rte_mempool.h>
7
#include <rte_mempool_driver.h>
7
#include <rte_stack.h>
8
#include <rte_stack.h>
8
9
9
static int
10
static int
(-)a/lib/mempool/meson.build (+4 lines)
Lines 20-23 headers = files( Link Here
20
        'rte_mempool_trace.h',
20
        'rte_mempool_trace.h',
21
        'rte_mempool_trace_fp.h',
21
        'rte_mempool_trace_fp.h',
22
)
22
)
23
driver_sdk_headers += files(
24
        'rte_mempool_driver.h',
25
)
26
23
deps += ['ring', 'telemetry']
27
deps += ['ring', 'telemetry']
(-)a/lib/mempool/rte_mempool.h (-3 / +13 lines)
Lines 684-690 struct rte_mempool_ops { Link Here
684
 */
684
 */
685
struct rte_mempool_ops_table {
685
struct rte_mempool_ops_table {
686
	rte_spinlock_t sl;     /**< Spinlock for add/delete. */
686
	rte_spinlock_t sl;     /**< Spinlock for add/delete. */
687
	uint32_t num_ops;      /**< Number of used ops structs in the table. */
687
	/**
688
	 * Number of used ops structs in the table. Note: in a secondary
689
	 * process, some ops_index can be higher than num_ops.
690
	 */
691
	uint32_t num_ops;
688
	/**
692
	/**
689
	 * Storage for all possible ops structs.
693
	 * Storage for all possible ops structs.
690
	 */
694
	 */
Lines 918-925 rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name, Link Here
918
 *   Pointer to an ops structure to register.
922
 *   Pointer to an ops structure to register.
919
 * @return
923
 * @return
920
 *   - >=0: Success; return the index of the ops struct in the table.
924
 *   - >=0: Success; return the index of the ops struct in the table.
921
 *   - -EINVAL - some missing callbacks while registering ops struct.
925
 *   - -EINVAL: some missing callbacks while registering ops struct.
922
 *   - -ENOSPC - the maximum number of ops structs has been reached.
926
 *   - -ENOSPC: the maximum number of ops structs has been reached, or
927
 *              the maximum number of memzones has already been allocated
928
 *   - -ENOMEM: no appropriate memory area found in which to create memzone
929
 *   - -EXISTS: the mempool ops are already registered (primary process only)
930
 *   - -ENOENT: the mempool ops are not registered on primary process
931
 *              (secondary process only)
932
 *   - -ENAMETOOLONG: the name of the mempool ops is too long
923
 */
933
 */
924
int rte_mempool_register_ops(const struct rte_mempool_ops *ops);
934
int rte_mempool_register_ops(const struct rte_mempool_ops *ops);
925
935
(-)a/lib/mempool/rte_mempool_driver.h (+32 lines)
Line 0 Link Here
1
/* SPDX-License-Identifier: BSD-3-Clause
2
 * Copyright(c) 2022 6WIND S.A.
3
 */
4
5
#ifndef _RTE_MEMPOOL_DRIVER_H_
6
#define _RTE_MEMPOOL_DRIVER_H_
7
8
#include <rte_mempool.h>
9
#include <rte_dev.h>
10
#include <rte_bus_vdev.h>
11
12
/**
13
 * Macro to statically register the ops of a mempool handler.
14
 * Note that the rte_mempool_register_ops fails silently here when
15
 * more than RTE_MEMPOOL_MAX_OPS_IDX is registered.
16
 */
17
#define RTE_MEMPOOL_REGISTER_OPS(name)					\
18
	static int							\
19
	mempool_ops_probe_##name(struct rte_vdev_device *vdev)		\
20
	{								\
21
		RTE_SET_USED(vdev);					\
22
		rte_mempool_register_ops(&name);			\
23
		return 0;						\
24
	}								\
25
	static struct rte_vdev_driver drv_##name = {			\
26
		.probe = mempool_ops_probe_##name,			\
27
		.remove = NULL,						\
28
	};								\
29
	RTE_PMD_REGISTER_VDEV(mempool_##name, drv_##name);		\
30
	RTE_PMD_AUTOLOAD_VDEV(mempool_##name##0)
31
32
#endif /* _RTE_MEMPOOL_DRIVER_H_ */
(-)a/lib/mempool/rte_mempool_ops.c (-12 / +101 lines)
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
		}
(-)a/lib/mempool/version.map (-1 / +3 lines)
Lines 71-74 INTERNAL { Link Here
71
	# added in 21.11
71
	# added in 21.11
72
	rte_mempool_event_callback_register;
72
	rte_mempool_event_callback_register;
73
	rte_mempool_event_callback_unregister;
73
	rte_mempool_event_callback_unregister;
74
75
	# added in 22.03
76
	rte_mempool_ops_shm_init;
74
};
77
};
75
- 

Return to bug 1073