From 4dfd44d350717476f435a0c49bd41c61ccc4bc1b Mon Sep 17 00:00:00 2001 From: Lukas Sismis Date: Sat, 26 Apr 2025 15:00:58 +0200 Subject: [PATCH] dpdk: update types to avoid type-warnings --- src/runmode-dpdk.c | 63 ++++++++++++++++++++++++------------------- src/source-dpdk.c | 14 +++++----- src/source-dpdk.h | 4 +-- src/util-dpdk-i40e.c | 2 +- src/util-dpdk-i40e.h | 2 +- src/util-dpdk-ice.c | 2 +- src/util-dpdk-ice.h | 2 +- src/util-dpdk-ixgbe.c | 2 +- src/util-dpdk-ixgbe.h | 2 +- src/util-dpdk-mlx5.c | 2 +- src/util-dpdk-mlx5.h | 2 +- src/util-memcmp.h | 4 +-- src/util-time.h | 2 +- 13 files changed, 56 insertions(+), 47 deletions(-) diff --git a/src/runmode-dpdk.c b/src/runmode-dpdk.c index 154e41b02d..04eae0138c 100644 --- a/src/runmode-dpdk.c +++ b/src/runmode-dpdk.c @@ -70,7 +70,7 @@ static char *AllocArgument(size_t arg_len); static char *AllocAndSetArgument(const char *arg); static char *AllocAndSetOption(const char *arg); -static void ArgumentsInit(struct Arguments *args, unsigned capacity); +static void ArgumentsInit(struct Arguments *args, uint16_t capacity); static void ArgumentsCleanup(struct Arguments *args); static void ArgumentsAdd(struct Arguments *args, char *value); static void ArgumentsAddOptionAndArgument(struct Arguments *args, const char *opt, const char *arg); @@ -148,9 +148,9 @@ DPDKIfaceConfigAttributes dpdk_yaml = { * \brief Input is a number of which we want to find the greatest divisor up to max_num (inclusive). * The divisor is returned. */ -static int GreatestDivisorUpTo(uint32_t num, uint32_t max_num) +static uint32_t GreatestDivisorUpTo(uint32_t num, uint32_t max_num) { - for (int i = max_num; i >= 2; i--) { + for (uint32_t i = max_num; i >= 2; i--) { if (num % i == 0) { return i; } @@ -225,12 +225,12 @@ static char *AllocAndSetOption(const char *arg) size_t full_len = arg_len + strlen(dash_prefix); ptr = AllocArgument(full_len); - strlcpy(ptr, dash_prefix, strlen(dash_prefix) + 1); - strlcat(ptr, arg, full_len + 1); + strlcpy(ptr, dash_prefix, full_len); + strlcat(ptr, arg, full_len); SCReturnPtr(ptr, "char *"); } -static void ArgumentsInit(struct Arguments *args, unsigned capacity) +static void ArgumentsInit(struct Arguments *args, uint16_t capacity) { SCEnter(); args->argv = SCCalloc(capacity, sizeof(*args->argv)); // alloc array of pointers @@ -352,7 +352,7 @@ static void ConfigInit(DPDKIfaceConfig **iconf) if (ptr == NULL) FatalError("Could not allocate memory for DPDKIfaceConfig"); - ptr->out_port_id = -1; // make sure no port is set + ptr->out_port_id = UINT16_MAX; // make sure no port is set SC_ATOMIC_INIT(ptr->ref); (void)SC_ATOMIC_ADD(ptr->ref, 1); ptr->DerefFunc = DPDKDerefConfig; @@ -381,7 +381,7 @@ static void ConfigSetIface(DPDKIfaceConfig *iconf, const char *entry_str) static int ConfigSetThreads(DPDKIfaceConfig *iconf, const char *entry_str) { SCEnter(); - static int32_t remaining_auto_cpus = -1; + static uint16_t remaining_auto_cpus = UINT16_MAX; // uninitialized if (!threading_set_cpu_affinity) { SCLogError("DPDK runmode requires configured thread affinity"); SCReturnInt(-EINVAL); @@ -397,7 +397,7 @@ static int ConfigSetThreads(DPDKIfaceConfig *iconf, const char *entry_str) SCLogError("Specify management-cpu-set list in the threading section"); SCReturnInt(-EINVAL); } - uint32_t sched_cpus = UtilAffinityGetAffinedCPUNum(wtaf); + uint16_t sched_cpus = UtilAffinityGetAffinedCPUNum(wtaf); if (sched_cpus == UtilCpuGetNumProcessorsOnline()) { SCLogWarning( "\"all\" specified in worker CPU cores affinity, excluding management threads"); @@ -425,7 +425,12 @@ static int ConfigSetThreads(DPDKIfaceConfig *iconf, const char *entry_str) } if (strcmp(entry_str, "auto") == 0) { - iconf->threads = (uint16_t)sched_cpus / LiveGetDeviceCount(); + uint16_t live_dev_count = (uint16_t)LiveGetDeviceCount(); + if (live_dev_count == 0) { + SCLogError("No live devices found, cannot auto-assign threads"); + SCReturnInt(-EINVAL); + } + iconf->threads = sched_cpus / live_dev_count; if (iconf->threads == 0) { SCLogError("Not enough worker CPU cores with affinity were configured"); SCReturnInt(-ERANGE); @@ -434,8 +439,9 @@ static int ConfigSetThreads(DPDKIfaceConfig *iconf, const char *entry_str) if (remaining_auto_cpus > 0) { iconf->threads++; remaining_auto_cpus--; - } else if (remaining_auto_cpus == -1) { - remaining_auto_cpus = (int32_t)sched_cpus % LiveGetDeviceCount(); + } else if (remaining_auto_cpus == UINT16_MAX) { + // first time auto-assignment + remaining_auto_cpus = sched_cpus % live_dev_count; if (remaining_auto_cpus > 0) { iconf->threads++; remaining_auto_cpus--; @@ -582,7 +588,7 @@ static uint32_t MempoolCacheSizeCalculate(uint32_t mp_sz) // It is advised to have mempool cache size lower or equal to: // RTE_MEMPOOL_CACHE_MAX_SIZE (by default 512) and "mempool-size / 1.5" // and at the same time "mempool-size modulo cache_size == 0". - uint32_t max_cache_size = MIN(RTE_MEMPOOL_CACHE_MAX_SIZE, mp_sz / 1.5); + uint32_t max_cache_size = MIN(RTE_MEMPOOL_CACHE_MAX_SIZE, (uint32_t)(mp_sz / 1.5)); return GreatestDivisorUpTo(mp_sz, max_cache_size); } @@ -626,7 +632,7 @@ static int ConfigSetRxDescriptors(DPDKIfaceConfig *iconf, const char *entry_str, } if (strcmp(entry_str, "auto") == 0) { - iconf->nb_rx_desc = GreatestPowOf2UpTo(max_desc); + iconf->nb_rx_desc = (uint16_t)GreatestPowOf2UpTo(max_desc); SCReturnInt(0); } @@ -659,7 +665,7 @@ static int ConfigSetTxDescriptors( if (strcmp(entry_str, "auto") == 0) { if (iface_sends_pkts) { - iconf->nb_tx_desc = GreatestPowOf2UpTo(max_desc); + iconf->nb_tx_desc = (uint16_t)GreatestPowOf2UpTo(max_desc); } else { iconf->nb_tx_desc = 0; } @@ -709,20 +715,21 @@ static int ConfigSetMtu(DPDKIfaceConfig *iconf, intmax_t entry_int) SCReturnInt(-ERANGE); } - iconf->mtu = entry_int; + iconf->mtu = (uint16_t)entry_int; SCReturnInt(0); } static int ConfigSetLinkupTimeout(DPDKIfaceConfig *iconf, intmax_t entry_int) { SCEnter(); - if (entry_int < 0) { - SCLogError("%s: Link-up waiting timeout needs to be a positive number or 0 to disable", - iconf->iface); + if (entry_int < 0 || entry_int > UINT16_MAX) { + SCLogError("%s: Link-up waiting timeout needs to be a positive number (up to %u) or 0 to " + "disable", + iconf->iface, UINT16_MAX); SCReturnInt(-ERANGE); } - iconf->linkup_timeout = entry_int; + iconf->linkup_timeout = (uint16_t)entry_int; SCReturnInt(0); } @@ -913,7 +920,7 @@ static int ConfigLoad(DPDKIfaceConfig *iconf, const char *iface) SCReturnInt(retval); // currently only mapping "1 thread == 1 RX (and 1 TX queue in IPS mode)" is supported - retval = ConfigSetRxQueues(iconf, (uint16_t)iconf->threads, dev_info.max_rx_queues); + retval = ConfigSetRxQueues(iconf, iconf->threads, dev_info.max_rx_queues); if (retval < 0) { SCLogError("%s: too many threads configured - reduce thread count to: %" PRIu16, iconf->iface, dev_info.max_rx_queues); @@ -921,7 +928,7 @@ static int ConfigLoad(DPDKIfaceConfig *iconf, const char *iface) } // currently only mapping "1 thread == 1 RX (and 1 TX queue in IPS mode)" is supported - uint16_t tx_queues = iconf->nb_tx_desc > 0 ? (uint16_t)iconf->threads : 0; + uint16_t tx_queues = iconf->nb_tx_desc > 0 ? iconf->threads : 0; retval = ConfigSetTxQueues(iconf, tx_queues, dev_info.max_tx_queues, iface_sends_pkts); if (retval < 0) { SCLogError("%s: too many threads configured - reduce thread count to: %" PRIu16, @@ -1062,9 +1069,9 @@ static void DeviceSetPMDSpecificRSS(struct rte_eth_rss_conf *rss_conf, const cha } // Returns -1 if no bit is set -static int GetFirstSetBitPosition(uint64_t bits) +static int32_t GetFirstSetBitPosition(uint64_t bits) { - for (uint64_t i = 0; i < 64; i++) { + for (int32_t i = 0; i < 64; i++) { if (bits & BIT_U64(i)) return i; } @@ -1467,7 +1474,7 @@ static int DeviceConfigureQueues(DPDKIfaceConfig *iconf, const struct rte_eth_de rxq_conf.rx_free_thresh, rxq_conf.rx_drop_en); retval = rte_eth_rx_queue_setup(iconf->port_id, queue_id, iconf->nb_rx_desc, - iconf->socket_id, &rxq_conf, iconf->pkt_mempools->pkt_mp[queue_id]); + (unsigned int)iconf->socket_id, &rxq_conf, iconf->pkt_mempools->pkt_mp[queue_id]); if (retval < 0) { SCLogError("%s: failed to setup RX queue %u: %s", iconf->iface, queue_id, rte_strerror(-retval)); @@ -1485,8 +1492,8 @@ static int DeviceConfigureQueues(DPDKIfaceConfig *iconf, const struct rte_eth_de iconf->iface, queue_id, iconf->nb_tx_desc, txq_conf.offloads, txq_conf.tx_thresh.hthresh, txq_conf.tx_thresh.pthresh, txq_conf.tx_thresh.wthresh, txq_conf.tx_free_thresh, txq_conf.tx_rs_thresh, txq_conf.tx_deferred_start); - retval = rte_eth_tx_queue_setup( - iconf->port_id, queue_id, iconf->nb_tx_desc, iconf->socket_id, &txq_conf); + retval = rte_eth_tx_queue_setup(iconf->port_id, queue_id, iconf->nb_tx_desc, + (unsigned int)iconf->socket_id, &txq_conf); if (retval < 0) { SCLogError("%s: failed to setup TX queue %u: %s", iconf->iface, queue_id, rte_strerror(-retval)); @@ -1815,7 +1822,7 @@ static void *ParseDpdkConfigAndConfigureDevice(const char *iface) if (ldev_instance == NULL) { FatalError("Device %s is not registered as a live device", iface); } - for (int32_t i = 0; i < iconf->threads; i++) { + for (uint16_t i = 0; i < iconf->threads; i++) { ldev_instance->dpdk_vars = iconf->pkt_mempools; iconf->pkt_mempools = NULL; } diff --git a/src/source-dpdk.c b/src/source-dpdk.c index 62e3dccce5..6977300336 100644 --- a/src/source-dpdk.c +++ b/src/source-dpdk.c @@ -151,7 +151,7 @@ static TmEcode DecodeDPDK(ThreadVars *, Packet *, void *); static void DPDKFreeMbufArray(struct rte_mbuf **mbuf_array, uint16_t mbuf_cnt, uint16_t offset); static bool InterruptsRXEnable(uint16_t port_id, uint16_t queue_id) { - uint32_t event_data = port_id << UINT16_WIDTH | queue_id; + uint32_t event_data = (uint32_t)port_id << UINT16_WIDTH | queue_id; int32_t ret = rte_eth_dev_rx_intr_ctl_q(port_id, queue_id, RTE_EPOLL_PER_THREAD, RTE_INTR_EVENT_ADD, (void *)((uintptr_t)event_data)); @@ -707,21 +707,23 @@ fail: SCReturnInt(TM_ECODE_FAILED); } -static void PrintDPDKPortXstats(uint32_t port_id, const char *port_name) +static void PrintDPDKPortXstats(uint16_t port_id, const char *port_name) { struct rte_eth_xstat *xstats; struct rte_eth_xstat_name *xstats_names; - int32_t len = rte_eth_xstats_get(port_id, NULL, 0); - if (len < 0) + int32_t ret = rte_eth_xstats_get(port_id, NULL, 0); + if (ret < 0) { FatalError("Error (%s) getting count of rte_eth_xstats failed on port %s", - rte_strerror(-len), port_name); + rte_strerror(-ret), port_name); + } + uint16_t len = (uint16_t)ret; xstats = SCCalloc(len, sizeof(*xstats)); if (xstats == NULL) FatalError("Failed to allocate memory for the rte_eth_xstat structure"); - int32_t ret = rte_eth_xstats_get(port_id, xstats, len); + ret = rte_eth_xstats_get(port_id, xstats, len); if (ret < 0 || ret > len) { SCFree(xstats); FatalError("Error (%s) getting rte_eth_xstats failed on port %s", rte_strerror(-ret), diff --git a/src/source-dpdk.h b/src/source-dpdk.h index 350a5a164a..7c2e980343 100644 --- a/src/source-dpdk.h +++ b/src/source-dpdk.h @@ -76,7 +76,7 @@ typedef struct DPDKIfaceConfig_ { uint32_t mempool_cache_size; DPDKDeviceResources *pkt_mempools; uint16_t linkup_timeout; // in seconds how long to wait for link to come up - SC_ATOMIC_DECLARE(unsigned int, ref); + SC_ATOMIC_DECLARE(uint16_t, ref); /* threads bind queue id one by one */ SC_ATOMIC_DECLARE(uint16_t, queue_id); SC_ATOMIC_DECLARE(uint16_t, inconsistent_numa_cnt); @@ -96,7 +96,7 @@ typedef struct DPDKPacketVars_ { struct rte_mbuf *mbuf; uint16_t out_port_id; uint16_t out_queue_id; - uint8_t copy_mode; + DpdkCopyModeEnum copy_mode; } DPDKPacketVars; void TmModuleReceiveDPDKRegister(void); diff --git a/src/util-dpdk-i40e.c b/src/util-dpdk-i40e.c index 8879e27484..18aed1e030 100644 --- a/src/util-dpdk-i40e.c +++ b/src/util-dpdk-i40e.c @@ -299,7 +299,7 @@ static int i40eDeviceSetRSSWithFlows(int port_id, const char *port_name, int nb_ #endif /* RTE_VERSION < RTE_VERSION_NUM(20,0,0,0) */ -int i40eDeviceSetRSS(int port_id, int nb_rx_queues, char *port_name) +int i40eDeviceSetRSS(int port_id, uint16_t nb_rx_queues, char *port_name) { (void)nb_rx_queues; // avoid unused variable warnings diff --git a/src/util-dpdk-i40e.h b/src/util-dpdk-i40e.h index cbec290d8c..3a61d53d09 100644 --- a/src/util-dpdk-i40e.h +++ b/src/util-dpdk-i40e.h @@ -30,7 +30,7 @@ #include "util-dpdk.h" -int i40eDeviceSetRSS(int port_id, int nb_rx_queues, char *port_name); +int i40eDeviceSetRSS(int port_id, uint16_t nb_rx_queues, char *port_name); void i40eDeviceSetRSSConf(struct rte_eth_rss_conf *rss_conf); #endif /* HAVE_DPDK */ diff --git a/src/util-dpdk-ice.c b/src/util-dpdk-ice.c index 47e01c92db..f1b9e965d5 100644 --- a/src/util-dpdk-ice.c +++ b/src/util-dpdk-ice.c @@ -90,7 +90,7 @@ static int iceDeviceSetRSSFlowIPv6( return DPDKCreateRSSFlow(port_id, port_name, rss_conf, RTE_ETH_RSS_IPV6, pattern); } -int iceDeviceSetRSS(int port_id, int nb_rx_queues, char *port_name) +int iceDeviceSetRSS(int port_id, uint16_t nb_rx_queues, char *port_name) { uint16_t queues[RTE_MAX_QUEUES_PER_PORT]; struct rte_flow_error flush_error = { 0 }; diff --git a/src/util-dpdk-ice.h b/src/util-dpdk-ice.h index ca7c3cee18..049f6a4d84 100644 --- a/src/util-dpdk-ice.h +++ b/src/util-dpdk-ice.h @@ -30,7 +30,7 @@ #include "util-dpdk.h" -int iceDeviceSetRSS(int port_id, int nb_rx_queues, char *port_name); +int iceDeviceSetRSS(int port_id, uint16_t nb_rx_queues, char *port_name); void iceDeviceSetRSSConf(struct rte_eth_rss_conf *rss_conf); #endif /* HAVE_DPDK */ diff --git a/src/util-dpdk-ixgbe.c b/src/util-dpdk-ixgbe.c index 7fb43ec2bf..b2db54675c 100644 --- a/src/util-dpdk-ixgbe.c +++ b/src/util-dpdk-ixgbe.c @@ -45,7 +45,7 @@ void ixgbeDeviceSetRSSHashFunction(uint64_t *rss_hf) *rss_hf = RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_IPV6_EX; } -int ixgbeDeviceSetRSS(int port_id, int nb_rx_queues, char *port_name) +int ixgbeDeviceSetRSS(int port_id, uint16_t nb_rx_queues, char *port_name) { uint16_t queues[RTE_MAX_QUEUES_PER_PORT]; struct rte_flow_error flush_error = { 0 }; diff --git a/src/util-dpdk-ixgbe.h b/src/util-dpdk-ixgbe.h index 79d3881397..14b46e8df9 100644 --- a/src/util-dpdk-ixgbe.h +++ b/src/util-dpdk-ixgbe.h @@ -28,7 +28,7 @@ #ifdef HAVE_DPDK -int ixgbeDeviceSetRSS(int port_id, int nb_rx_queues, char *port_name); +int ixgbeDeviceSetRSS(int port_id, uint16_t nb_rx_queues, char *port_name); void ixgbeDeviceSetRSSHashFunction(uint64_t *rss_conf); #endif /* HAVE_DPDK */ diff --git a/src/util-dpdk-mlx5.c b/src/util-dpdk-mlx5.c index 2009af4f4f..bc5061a539 100644 --- a/src/util-dpdk-mlx5.c +++ b/src/util-dpdk-mlx5.c @@ -40,7 +40,7 @@ #define MLX5_RSS_HKEY_LEN 40 -int mlx5DeviceSetRSS(int port_id, int nb_rx_queues, char *port_name) +int mlx5DeviceSetRSS(int port_id, uint16_t nb_rx_queues, char *port_name) { uint16_t queues[RTE_MAX_QUEUES_PER_PORT]; struct rte_flow_error flush_error = { 0 }; diff --git a/src/util-dpdk-mlx5.h b/src/util-dpdk-mlx5.h index e51593a223..2ef2e5bf9e 100644 --- a/src/util-dpdk-mlx5.h +++ b/src/util-dpdk-mlx5.h @@ -28,7 +28,7 @@ #ifdef HAVE_DPDK -int mlx5DeviceSetRSS(int port_id, int nb_rx_queues, char *port_name); +int mlx5DeviceSetRSS(int port_id, uint16_t nb_rx_queues, char *port_name); #endif /* HAVE_DPDK */ diff --git a/src/util-memcmp.h b/src/util-memcmp.h index f9fc75357c..4356e2d2e4 100644 --- a/src/util-memcmp.h +++ b/src/util-memcmp.h @@ -71,7 +71,7 @@ static inline int SCMemcmp(const void *s1, const void *s2, size_t n) /* do the actual compare: _mm_cmpestri() returns the number of matching bytes */ r = _mm_cmpestri(b1, SCMEMCMP_BYTES, b2, SCMEMCMP_BYTES, _SIDD_CMP_EQUAL_EACH | _SIDD_MASKED_NEGATIVE_POLARITY); - m += r; + m += (size_t)r; s1 += SCMEMCMP_BYTES; s2 += SCMEMCMP_BYTES; } while (r == SCMEMCMP_BYTES); @@ -116,7 +116,7 @@ static inline int SCMemcmpLowercase(const void *s1, const void *s2, size_t n) /* search using our converted buffer, return number of matching bytes */ r = _mm_cmpestri(b1, SCMEMCMP_BYTES, b2, SCMEMCMP_BYTES, _SIDD_CMP_EQUAL_EACH | _SIDD_MASKED_NEGATIVE_POLARITY); - m += r; + m += (size_t)r; s1 += SCMEMCMP_BYTES; s2 += SCMEMCMP_BYTES; } while (r == SCMEMCMP_BYTES); diff --git a/src/util-time.h b/src/util-time.h index 1b428a9098..d978b5d5a7 100644 --- a/src/util-time.h +++ b/src/util-time.h @@ -79,7 +79,7 @@ typedef struct { #define SCTIME_FROM_TIMEVAL(tv) \ (SCTime_t) \ { \ - .secs = (tv)->tv_sec, .usecs = (tv)->tv_usec \ + .secs = (uint64_t)(tv)->tv_sec, .usecs = (uint32_t)(tv)->tv_usec \ } /** \brief variant to deal with potentially bad timestamps, like from pcap files */ #define SCTIME_FROM_TIMEVAL_UNTRUSTED(tv) \ -- 2.47.2