+
+ /* external mbuf support */
+ if (mem->decomp_memzones != NULL) {
+ for (i = 0; i < test_data->total_segs; i++)
+ rte_memzone_free(mem->decomp_memzones[i]);
+ rte_free(mem->decomp_memzones);
+ }
+ if (mem->comp_memzones != NULL) {
+ for (i = 0; i < test_data->total_segs; i++)
+ rte_memzone_free(mem->comp_memzones[i]);
+ rte_free(mem->comp_memzones);
+ }
+ rte_free(mem->decomp_buf_infos);
+ rte_free(mem->comp_buf_infos);
+}
+
+static void
+comp_perf_extbuf_free_cb(void *addr __rte_unused, void *opaque __rte_unused)
+{
+}
+
+static const struct rte_memzone *
+comp_perf_make_memzone(const char *name, struct cperf_mem_resources *mem,
+ unsigned int number, size_t size)
+{
+ unsigned int socket_id = rte_socket_id();
+ char mz_name[RTE_MEMZONE_NAMESIZE];
+ const struct rte_memzone *memzone;
+
+ snprintf(mz_name, RTE_MEMZONE_NAMESIZE, "%s_s%u_d%u_q%u_%d", name,
+ socket_id, mem->dev_id, mem->qp_id, number);
+ memzone = rte_memzone_lookup(mz_name);
+ if (memzone != NULL && memzone->len != size) {
+ rte_memzone_free(memzone);
+ memzone = NULL;
+ }
+ if (memzone == NULL) {
+ memzone = rte_memzone_reserve_aligned(mz_name, size, socket_id,
+ RTE_MEMZONE_IOVA_CONTIG, RTE_CACHE_LINE_SIZE);
+ if (memzone == NULL)
+ RTE_LOG(ERR, USER1, "Can't allocate memory zone %s\n",
+ mz_name);
+ }
+ return memzone;
+}
+
+static int
+comp_perf_allocate_external_mbufs(struct comp_test_data *test_data,
+ struct cperf_mem_resources *mem)
+{
+ uint32_t i;
+
+ mem->comp_memzones = rte_zmalloc_socket(NULL,
+ test_data->total_segs * sizeof(struct rte_memzone *),
+ 0, rte_socket_id());
+
+ if (mem->comp_memzones == NULL) {
+ RTE_LOG(ERR, USER1,
+ "Memory to hold the compression memzones could not be allocated\n");
+ return -1;
+ }
+
+ mem->decomp_memzones = rte_zmalloc_socket(NULL,
+ test_data->total_segs * sizeof(struct rte_memzone *),
+ 0, rte_socket_id());
+
+ if (mem->decomp_memzones == NULL) {
+ RTE_LOG(ERR, USER1,
+ "Memory to hold the decompression memzones could not be allocated\n");
+ return -1;
+ }
+
+ mem->comp_buf_infos = rte_zmalloc_socket(NULL,
+ test_data->total_segs * sizeof(struct rte_mbuf_ext_shared_info),
+ 0, rte_socket_id());
+
+ if (mem->comp_buf_infos == NULL) {
+ RTE_LOG(ERR, USER1,
+ "Memory to hold the compression buf infos could not be allocated\n");
+ return -1;
+ }
+
+ mem->decomp_buf_infos = rte_zmalloc_socket(NULL,
+ test_data->total_segs * sizeof(struct rte_mbuf_ext_shared_info),
+ 0, rte_socket_id());
+
+ if (mem->decomp_buf_infos == NULL) {
+ RTE_LOG(ERR, USER1,
+ "Memory to hold the decompression buf infos could not be allocated\n");
+ return -1;
+ }
+
+ for (i = 0; i < test_data->total_segs; i++) {
+ mem->comp_memzones[i] = comp_perf_make_memzone("comp", mem,
+ i, test_data->out_seg_sz);
+ if (mem->comp_memzones[i] == NULL) {
+ RTE_LOG(ERR, USER1,
+ "Memory to hold the compression memzone could not be allocated\n");
+ return -1;
+ }
+
+ mem->decomp_memzones[i] = comp_perf_make_memzone("decomp", mem,
+ i, test_data->seg_sz);
+ if (mem->decomp_memzones[i] == NULL) {
+ RTE_LOG(ERR, USER1,
+ "Memory to hold the decompression memzone could not be allocated\n");
+ return -1;
+ }
+
+ mem->comp_buf_infos[i].free_cb =
+ comp_perf_extbuf_free_cb;
+ mem->comp_buf_infos[i].fcb_opaque = NULL;
+ rte_mbuf_ext_refcnt_set(&mem->comp_buf_infos[i], 1);
+
+ mem->decomp_buf_infos[i].free_cb =
+ comp_perf_extbuf_free_cb;
+ mem->decomp_buf_infos[i].fcb_opaque = NULL;
+ rte_mbuf_ext_refcnt_set(&mem->decomp_buf_infos[i], 1);
+ }
+
+ return 0;