diff --git a/src/runmode-dpdk.c b/src/runmode-dpdk.c index 7b0b7552e6d..0a5ffff53f4 100644 --- a/src/runmode-dpdk.c +++ b/src/runmode-dpdk.c @@ -1363,6 +1363,10 @@ static void *ParseDpdkConfigAndConfigureDevice(const char *iface) // This counter is increased by worker threads that individually pick queue IDs. SC_ATOMIC_RESET(iconf->queue_id); SC_ATOMIC_RESET(iconf->inconsitent_numa_cnt); + + // initialize LiveDev DPDK values + LiveDevice *ldev_instance = LiveGetDevice(iface); + ldev_instance->dpdk_vars.pkt_mp = iconf->pkt_mempool; return iconf; } diff --git a/src/source-dpdk.c b/src/source-dpdk.c index f207ef7c6d6..51f82c56552 100644 --- a/src/source-dpdk.c +++ b/src/source-dpdk.c @@ -646,10 +646,7 @@ static TmEcode ReceiveDPDKThreadDeinit(ThreadVars *tv, void *data) rte_eth_dev_stop(ptv->out_port_id); } - if (ptv->queue_id == 0 && ptv->pkt_mempool != NULL) { - rte_mempool_free(ptv->pkt_mempool); - ptv->pkt_mempool = NULL; - } + ptv->pkt_mempool = NULL; // MP is released when device is closed SCFree(ptv); SCReturnInt(TM_ECODE_OK); diff --git a/src/util-device.h b/src/util-device.h index 1837915145d..ae9ec97c08b 100644 --- a/src/util-device.h +++ b/src/util-device.h @@ -18,6 +18,10 @@ #ifndef __UTIL_DEVICE_H__ #define __UTIL_DEVICE_H__ +#ifdef HAVE_DPDK +#include +#endif /* HAVE_DPDK */ + #include "queue.h" #define OFFLOAD_FLAG_SG (1<<0) @@ -35,6 +39,12 @@ int LiveGetOffload(void); #define MAX_DEVNAME 10 +#ifdef HAVE_DPDK +typedef struct { + struct rte_mempool *pkt_mp; +} DPDKDeviceResources; +#endif /* HAVE_DPDK */ + /** storage for live device names */ typedef struct LiveDevice_ { char *dev; /**< the device (e.g. "eth0") */ @@ -51,6 +61,10 @@ typedef struct LiveDevice_ { uint32_t tenant_id; /**< tenant id in multi-tenancy */ uint32_t offload_orig; /**< original offload settings to restore @exit */ +#ifdef HAVE_DPDK + // DPDK resources that needs to be cleaned after workers are stopped and devices closed + DPDKDeviceResources dpdk_vars; +#endif } LiveDevice; typedef struct LiveDeviceName_ { diff --git a/src/util-dpdk.c b/src/util-dpdk.c index e6f56e5ccd4..83284411fe2 100644 --- a/src/util-dpdk.c +++ b/src/util-dpdk.c @@ -51,6 +51,9 @@ void DPDKCloseDevice(LiveDevice *ldev) SCLogInfo("%s: closing device", ldev->dev); rte_eth_dev_close(port_id); + + SCLogInfo("%s: releasing packet mempool", ldev->dev); + rte_mempool_free(ldev->dpdk_vars.pkt_mp); } #endif }