runmodes: let thread count callback return uint16_t

It will be a long time before we need more than 64k threads.

Update capture methods.
pull/13926/head
Victor Julien 2 months ago committed by Victor Julien
parent 5817afa356
commit fbf75f2e7d

@ -253,7 +253,7 @@ static void *ParseAFPConfig(const char *iface)
if (strcmp(threadsstr, "auto") == 0) { if (strcmp(threadsstr, "auto") == 0) {
aconf->threads = 0; aconf->threads = 0;
} else { } else {
if (StringParseInt32(&aconf->threads, 10, 0, (const char *)threadsstr) < 0) { if (StringParseUint16(&aconf->threads, 10, 0, (const char *)threadsstr) < 0) {
SCLogWarning("%s: invalid number of " SCLogWarning("%s: invalid number of "
"threads, resetting to default", "threads, resetting to default",
iface); iface);
@ -668,15 +668,15 @@ finalize:
if (aconf->threads == 0) { if (aconf->threads == 0) {
/* for cluster_flow use core count */ /* for cluster_flow use core count */
if (cluster_type == PACKET_FANOUT_HASH) { if (cluster_type == PACKET_FANOUT_HASH) {
aconf->threads = (int)UtilCpuGetNumProcessorsOnline(); aconf->threads = UtilCpuGetNumProcessorsOnline();
SCLogPerf("%s: cluster_flow: %u cores, using %u threads", iface, aconf->threads, SCLogPerf("%s: cluster_flow: %u cores, using %u threads", iface, aconf->threads,
aconf->threads); aconf->threads);
/* for cluster_qm use RSS queue count */ /* for cluster_qm use RSS queue count */
} else if (cluster_type == PACKET_FANOUT_QM) { } else if (cluster_type == PACKET_FANOUT_QM) {
int rss_queues = GetIfaceRSSQueuesNum(iface); int rss_queues = GetIfaceRSSQueuesNum(iface);
if (rss_queues > 0) { if (rss_queues > 0 && rss_queues <= UINT16_MAX) {
aconf->threads = rss_queues; aconf->threads = (uint16_t)rss_queues;
SCLogPerf("%s: cluster_qm: %d RSS queues, using %u threads", iface, rss_queues, SCLogPerf("%s: cluster_qm: %d RSS queues, using %u threads", iface, rss_queues,
aconf->threads); aconf->threads);
} }
@ -771,7 +771,7 @@ finalize:
return aconf; return aconf;
} }
static int AFPConfigGeThreadsCount(void *conf) static uint16_t AFPConfigGeThreadsCount(void *conf)
{ {
AFPIfaceConfig *afp = (AFPIfaceConfig *)conf; AFPIfaceConfig *afp = (AFPIfaceConfig *)conf;
return afp->threads; return afp->threads;

@ -123,17 +123,12 @@ static TmEcode ConfigSetThreads(AFXDPIfaceConfig *aconf, const char *entry_str)
SCReturnInt(TM_ECODE_OK); SCReturnInt(TM_ECODE_OK);
} }
if (StringParseInt32(&aconf->threads, 10, 0, entry_str) < 0) { if (StringParseUint16(&aconf->threads, 10, 0, entry_str) < 0) {
SCLogError("Threads entry for interface %s contain non-numerical characters - \"%s\"", SCLogError("Threads entry for interface %s contain non-numerical characters - \"%s\"",
aconf->iface, entry_str); aconf->iface, entry_str);
SCReturnInt(TM_ECODE_FAILED); SCReturnInt(TM_ECODE_FAILED);
} }
if (aconf->threads < 0) {
SCLogError("Interface %s has a negative number of threads", aconf->iface);
SCReturnInt(TM_ECODE_FAILED);
}
if (aconf->threads > nr_queues) { if (aconf->threads > nr_queues) {
SCLogWarning( SCLogWarning(
"Selected threads greater than configured queues, using: %d thread(s)", nr_queues); "Selected threads greater than configured queues, using: %d thread(s)", nr_queues);
@ -306,7 +301,7 @@ finalize:
return aconf; return aconf;
} }
static int AFXDPConfigGetThreadsCount(void *conf) static uint16_t AFXDPConfigGetThreadsCount(void *conf)
{ {
if (conf == NULL) if (conf == NULL)
FatalError("Configuration file is NULL"); FatalError("Configuration file is NULL");

@ -1853,7 +1853,7 @@ static void *ParseDpdkConfigAndConfigureDevice(const char *iface)
* \return a DPDKIfaceConfig corresponding to the interface name * \return a DPDKIfaceConfig corresponding to the interface name
*/ */
static int DPDKConfigGetThreadsCount(void *conf) static uint16_t DPDKConfigGetThreadsCount(void *conf)
{ {
if (conf == NULL) if (conf == NULL)
FatalError("Configuration file is NULL"); FatalError("Configuration file is NULL");

@ -30,7 +30,7 @@
#include "util-affinity.h" #include "util-affinity.h"
#include "util-runmodes.h" #include "util-runmodes.h"
static int DagConfigGetThreadCount(void *conf) static uint16_t DagConfigGetThreadCount(void *conf)
{ {
return 1; return 1;
} }

@ -357,13 +357,13 @@ static void *ParseNetmapConfig(const char *iface_name)
SC_ATOMIC_RESET(aconf->ref); SC_ATOMIC_RESET(aconf->ref);
(void) SC_ATOMIC_ADD(aconf->ref, aconf->in.threads); (void) SC_ATOMIC_ADD(aconf->ref, aconf->in.threads);
SCLogPerf("%s: using %d threads", aconf->iface_name, aconf->in.threads); SCLogPerf("%s: using %u threads", aconf->iface_name, aconf->in.threads);
LiveDeviceHasNoStats(); LiveDeviceHasNoStats();
return aconf; return aconf;
} }
static int NetmapConfigGeThreadsCount(void *conf) static uint16_t NetmapConfigGeThreadsCount(void *conf)
{ {
NetmapIfaceConfig *aconf = (NetmapIfaceConfig *)conf; NetmapIfaceConfig *aconf = (NetmapIfaceConfig *)conf;
return aconf->in.threads; return aconf->in.threads;

@ -139,7 +139,7 @@ static void *ParseNflogConfig(const char *group)
return nflogconf; return nflogconf;
} }
static int NflogConfigGeThreadsCount(void *conf) static uint16_t NflogConfigGeThreadsCount(void *conf)
{ {
/* for each nflog group there is no reason to use more than 1 thread */ /* for each nflog group there is no reason to use more than 1 thread */
return 1; return 1;

@ -136,7 +136,7 @@ static void *ParsePcapConfig(const char *iface)
aconf->threads = 1; aconf->threads = 1;
} else { } else {
if (threadsstr != NULL) { if (threadsstr != NULL) {
if (StringParseInt32(&aconf->threads, 10, 0, (const char *)threadsstr) < 0) { if (StringParseUint16(&aconf->threads, 10, 0, (const char *)threadsstr) < 0) {
SCLogWarning("Invalid value for " SCLogWarning("Invalid value for "
"pcap.threads: %s, resetting to 1", "pcap.threads: %s, resetting to 1",
threadsstr); threadsstr);
@ -216,7 +216,7 @@ static void *ParsePcapConfig(const char *iface)
return aconf; return aconf;
} }
static int PcapConfigGeThreadsCount(void *conf) static uint16_t PcapConfigGeThreadsCount(void *conf)
{ {
PcapIfaceConfig *pfp = (PcapIfaceConfig *)conf; PcapIfaceConfig *pfp = (PcapIfaceConfig *)conf;
return pfp->threads; return pfp->threads;

@ -89,7 +89,7 @@ typedef struct AFPIfaceConfig_
{ {
char iface[AFP_IFACE_NAME_LENGTH]; char iface[AFP_IFACE_NAME_LENGTH];
/* number of threads */ /* number of threads */
int threads; uint16_t threads;
/* socket buffer size */ /* socket buffer size */
int buffer_size; int buffer_size;
/* ring size in number of packets */ /* ring size in number of packets */

@ -29,7 +29,7 @@
typedef struct AFXDPIfaceConfig { typedef struct AFXDPIfaceConfig {
char iface[AFXDP_IFACE_NAME_LENGTH]; char iface[AFXDP_IFACE_NAME_LENGTH];
/* number of threads */ /* number of threads */
int threads; uint16_t threads;
int promisc; int promisc;
/* misc use flags */ /* misc use flags */

@ -45,7 +45,7 @@ typedef struct PcapIfaceConfig_
{ {
char iface[PCAP_IFACE_NAME_LENGTH]; char iface[PCAP_IFACE_NAME_LENGTH];
/* number of threads */ /* number of threads */
int threads; uint16_t threads;
/* socket buffer size */ /* socket buffer size */
int buffer_size; int buffer_size;
/* snapshot length */ /* snapshot length */

@ -25,7 +25,7 @@
typedef void *(*ConfigIfaceParserFunc) (const char *); typedef void *(*ConfigIfaceParserFunc) (const char *);
typedef void *(*ConfigIPSParserFunc) (int); typedef void *(*ConfigIPSParserFunc) (int);
typedef int (*ConfigIfaceThreadsCountFunc) (void *); typedef uint16_t (*ConfigIfaceThreadsCountFunc)(void *);
int RunModeSetLiveCaptureAuto(ConfigIfaceParserFunc configparser, int RunModeSetLiveCaptureAuto(ConfigIfaceParserFunc configparser,
ConfigIfaceThreadsCountFunc ModThreadsCount, ConfigIfaceThreadsCountFunc ModThreadsCount,

Loading…
Cancel
Save